Skip to content

Commit

Permalink
chore: extract common declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Jun 16, 2022
1 parent f06cff8 commit 3829b88
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface PackageJson {
* these help npm searches find your project
*/
keywords?: string[];
homepage?: string;
bugs?: {url: string};
/**
* "name <email> (website)" string or Maintainer object
*/
Expand All @@ -23,6 +25,7 @@ export interface PackageJson {
peerDependencies?: Dependencies;
bundleDependencies?: Dependencies;
bundledDependencies?: Dependencies;
optionalDependencies?: ObjectOfStrings;
engines?: ObjectOfStrings;
files?: string[];
bin?: {[key: string]: string};
Expand All @@ -44,28 +47,32 @@ export interface PackageJson {
}

// this is what you get from the npm api.
export interface Packument {
export type Packument = {
_id: string;
_rev: string;
name: string;
readme?: string;
description?: string;
'dist-tags': {latest?: string}&ObjectOfStrings;
versions: {[key: string]: PackumentVersion};
maintainers: Maintainer[];
time: {modified: string, created: string, [key: string]: string};
homepage?: string;
keywords?: string[];
repository?: Repository;
author?: Maintainer;
bugs?: {url: string};
license?: string;
// left out users (stars) deprecated, and attachments (does nothing)
readmeFilename?: string;
// eslint-disable-next-line @typescript-eslint/ban-types
_attachments?: object;
}

// The following fields are hoisted to the top-level of the packument from the latest version published.
} & Pick<
PackumentVersion,
| 'author'
| 'bugs'
| 'contributors'
| 'description'
| 'homepage'
| 'keywords'
| 'license'
| 'maintainers'
| 'name'
| 'readme'
| 'readmeFilename'
| 'repository'
>;

// https://docs.npmjs.com/files/package-lock.json
export interface PackageLock {
name: string;
Expand Down Expand Up @@ -103,8 +110,10 @@ export interface PackumentVersion extends PackageJson {
_npmUser: Maintainer;
maintainers: Maintainer[];
dist: Dist;
readme?: string;
readmeFilename?: string;
_hasShrinkwrap?: boolean;
types?: string;
deprecated?: string;
}

/**
Expand All @@ -114,29 +123,27 @@ export interface PackumentVersion extends PackageJson {
* returned from registry requests with accept header values conianing
* `application/vnd.npm.install-v1+json`
*/
export interface Manifest{
name:string;
export type Manifest = {
modified:string;
'dist-tags':ObjectOfStrings;
versions:{[version:string]:ManifestVersion}
}

export interface ManifestVersion{
name:string;
version:string;
dependencies?:ObjectOfStrings;
optionalDependencies?:ObjectOfStrings;
devDependencies?:ObjectOfStrings;
bundleDependencies?:ObjectOfStrings;
bundledDependencies?:ObjectOfStrings;
peerDependencies?:ObjectOfStrings;
bin?:ObjectOfStrings;
_hasShrinkwrap?:boolean;
directories?:Directories;
dist:Dist;
engines?:ObjectOfStrings;
deprecated?:string;
}
} & Pick<Packument, 'name' | 'dist-tags'>;

export type ManifestVersion = Pick<
PackumentVersion,
| 'name'
| 'version'
| 'bin'
| 'directories'
| 'dependencies'
| 'devDependencies'
| 'peerDependencies'
| 'bundledDependencies'
| 'optionalDependencies'
| 'engines'
| 'dist'
| '_hasShrinkwrap'
| 'deprecated'
>;

/**
* Dists are properties of Packument.versions
Expand Down

0 comments on commit 3829b88

Please sign in to comment.