Skip to content

Commit

Permalink
refactor: export type in repository
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Apr 25, 2023
1 parent dd42eff commit f4e2a7d
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 135 deletions.
130 changes: 1 addition & 129 deletions app/core/service/PackageManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { calculateIntegrity, detectInstallScript, formatTarball, getFullname, ge
import { AbstractService } from '../../common/AbstractService';
import { BugVersionStore } from '../../common/adapter/BugVersionStore';
import { BUG_VERSIONS, LATEST_TAG } from '../../common/constants';
import { PackageRepository } from '../../repository/PackageRepository';
import { AbbreviatedPackageJSONType, AbbreviatedPackageManifestType, PackageJSONType, PackageManifestType, PackageRepository } from '../../repository/PackageRepository';
import { PackageVersionBlockRepository } from '../../repository/PackageVersionBlockRepository';
import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository';
import { DistRepository } from '../../repository/DistRepository';
Expand Down Expand Up @@ -40,134 +40,6 @@ import { BugVersion } from '../entity/BugVersion';
import { RegistryManagerService } from './RegistryManagerService';
import { Registry } from '../entity/Registry';

type PackageJSONPickKey = 'name' | 'author' | 'bugs' | 'description' | 'homepage' | 'keywords' | 'license' | 'readme' | 'readmeFilename' | 'repository' | 'versions';

export type PackageManifestType = Pick<PackageJSONType, PackageJSONPickKey> & {
_id: string;
_rev: string;
'dist-tags': Record<string, string>;
versions: Record<string, PackageJSONType | undefined>;
maintainers: AuthorType[];
time: {
created: Date;
modified: Date;
[key: string]: Date;
};
} & CnpmcorePatchInfo;

export type AbbreviatedPackageManifestType = Pick<PackageManifestType, 'dist-tags' | 'name'> & {
modified: Date;
versions: Record<string, AbbreviatedPackageJSONType | undefined>;
time?: PackageManifestType['time'];
} & CnpmcorePatchInfo;


type CnpmcorePatchInfo = {
_cnpmcore_publish_time?: Date;
publish_time?: number;
_source_registry_name?: string;
block?: string;
};

export type PackageJSONType = CnpmcorePatchInfo & {
name: string;
version: string;
readme?: string;
description?: string;
keywords?: string[];
homepage?: string;
bugs?: {
url?: string;
email?: string;
};
license?: string;
author?: AuthorType | string;
contributors?: ContributorType[] | string[];
maintainers?: ContributorType[] | string[];
files?: string[];
main?: string;
bin?: string | {
[key: string]: string;
};
man?: string | string[];
directories?: DirectoriesType;
repository?: RepositoryType;
scripts?: Record<string, string>;
config?: Record<string, unknown>;
dependencies?: DepInfo;
devDependencies?: DepInfo;
peerDependencies?: DepInfo;
peerDependenciesMeta?: {
[key: string]: {
optional?: boolean;
required?: string;
version?: string;
[key: string]: unknown;
};
};
bundleDependencies?: string[];
bundledDependencies?: string[];
optionalDependencies?: DepInfo;
engines?: {
node?: string;
npm?: string;
[key: string]: string | undefined;
};
os?: string[];
cpu?: string[];
preferGlobal?: boolean;
private?: boolean;
publishConfig?: {
access?: 'public' | 'restricted';
[key: string]: unknown;
};
_hasShrinkwrap?: boolean;
hasInstallScript?: boolean;
dist?: DistType;
workspace?: string[];
[key: string]: unknown;
};

type AbbreviatedKey = 'name' | 'version' | 'deprecated' | 'dependencies' | 'optionalDependencies' | 'devDependencies' | 'bundleDependencies' | 'peerDependencies' | 'peerDependenciesMeta' | 'bin' | 'os' | 'cpu' | 'libc' | 'workspaces' | 'directories' | 'dist' | 'engines' | 'hasInstallScript' | 'publish_time' | 'block' | '_hasShrinkwrap';
export type AbbreviatedPackageJSONType = Pick<PackageJSONType, AbbreviatedKey> & CnpmcorePatchInfo;

type DistType = {
tarball: string,
size: number,
shasum: string,
integrity: string,
[key: string]: unknown,
};

type AuthorType = {
name: string;
email?: string;
url?: string;
};

type ContributorType = {
name?: string;
email?: string;
url?: string;
[key: string]: unknown;
};

type DirectoriesType = {
lib?: string;
bin?: string;
man?: string;
test?: string;
[key: string]: string | undefined;
};

type RepositoryType = {
type: string;
url: string;
[key: string]: unknown;
};

type DepInfo = Record<string, string>;


export interface PublishPackageCmd {
// maintainer: Maintainer;
Expand Down
3 changes: 2 additions & 1 deletion app/port/controller/package/SavePackageVersionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import validateNpmPackageName from 'validate-npm-package-name';
import { Static, Type } from '@sinclair/typebox';
import { AbstractController } from '../AbstractController';
import { getScopeAndName, FULLNAME_REG_STRING } from '../../../common/PackageUtil';
import { PackageJSONType, PackageManagerService } from '../../../core/service/PackageManagerService';
import { PackageManagerService } from '../../../core/service/PackageManagerService';
import {
VersionRule,
TagWithVersionRule,
Name as NameType,
Description as DescriptionType,
} from '../../typebox';
import { RegistryManagerService } from '../../../core/service/RegistryManagerService';
import { PackageJSONType } from '../../../repository/PackageRepository';

type PackageVersion = Simplify<PackageJson.PackageJsonStandard & {
name: 'string';
Expand Down
3 changes: 1 addition & 2 deletions app/repository/DistRepository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AccessLevel, SingletonProto, Inject } from '@eggjs/tegg';
import { NFSAdapter } from '../common/adapter/NFSAdapter';
import { PackageRepository } from './PackageRepository';
import { PackageJSONType, PackageRepository } from './PackageRepository';
import { Dist } from '../core/entity/Dist';
import { PackageJSONType } from 'app/core/service/PackageManagerService';

@SingletonProto({
accessLevel: AccessLevel.PUBLIC,
Expand Down
128 changes: 128 additions & 0 deletions app/repository/PackageRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,134 @@ import { AbstractRepository } from './AbstractRepository';
import { EggAppConfig } from 'egg';
import { Bone } from 'leoric';

export type PackageManifestType = Pick<PackageJSONType, PackageJSONPickKey> & {
_id: string;
_rev: string;
'dist-tags': Record<string, string>;
versions: Record<string, PackageJSONType | undefined>;
maintainers: AuthorType[];
time: {
created: Date;
modified: Date;
[key: string]: Date;
};
} & CnpmcorePatchInfo;

export type AbbreviatedPackageJSONType = Pick<PackageJSONType, AbbreviatedKey> & CnpmcorePatchInfo;

export type AbbreviatedPackageManifestType = Pick<PackageManifestType, 'dist-tags' | 'name'> & {
modified: Date;
versions: Record<string, AbbreviatedPackageJSONType | undefined>;
time?: PackageManifestType['time'];
} & CnpmcorePatchInfo;

export type PackageJSONType = CnpmcorePatchInfo & {
name: string;
version: string;
readme?: string;
description?: string;
keywords?: string[];
homepage?: string;
bugs?: {
url?: string;
email?: string;
};
license?: string;
author?: AuthorType | string;
contributors?: ContributorType[] | string[];
maintainers?: ContributorType[] | string[];
files?: string[];
main?: string;
bin?: string | {
[key: string]: string;
};
man?: string | string[];
directories?: DirectoriesType;
repository?: RepositoryType;
scripts?: Record<string, string>;
config?: Record<string, unknown>;
dependencies?: DepInfo;
devDependencies?: DepInfo;
peerDependencies?: DepInfo;
peerDependenciesMeta?: {
[key: string]: {
optional?: boolean;
required?: string;
version?: string;
[key: string]: unknown;
};
};
bundleDependencies?: string[];
bundledDependencies?: string[];
optionalDependencies?: DepInfo;
engines?: {
node?: string;
npm?: string;
[key: string]: string | undefined;
};
os?: string[];
cpu?: string[];
preferGlobal?: boolean;
private?: boolean;
publishConfig?: {
access?: 'public' | 'restricted';
[key: string]: unknown;
};
_hasShrinkwrap?: boolean;
hasInstallScript?: boolean;
dist?: DistType;
workspace?: string[];
[key: string]: unknown;
};

type PackageJSONPickKey = 'name' | 'author' | 'bugs' | 'description' | 'homepage' | 'keywords' | 'license' | 'readme' | 'readmeFilename' | 'repository' | 'versions';

type CnpmcorePatchInfo = {
_cnpmcore_publish_time?: Date;
publish_time?: number;
_source_registry_name?: string;
block?: string;
};

type AbbreviatedKey = 'name' | 'version' | 'deprecated' | 'dependencies' | 'optionalDependencies' | 'devDependencies' | 'bundleDependencies' | 'peerDependencies' | 'peerDependenciesMeta' | 'bin' | 'os' | 'cpu' | 'libc' | 'workspaces' | 'directories' | 'dist' | 'engines' | 'hasInstallScript' | 'publish_time' | 'block' | '_hasShrinkwrap';

type DistType = {
tarball: string,
size: number,
shasum: string,
integrity: string,
[key: string]: unknown,
};

type AuthorType = {
name: string;
email?: string;
url?: string;
};

type ContributorType = {
name?: string;
email?: string;
url?: string;
[key: string]: unknown;
};

type DirectoriesType = {
lib?: string;
bin?: string;
man?: string;
test?: string;
[key: string]: string | undefined;
};

type RepositoryType = {
type: string;
url: string;
[key: string]: unknown;
};

type DepInfo = Record<string, string>;

@SingletonProto({
accessLevel: AccessLevel.PUBLIC,
})
Expand Down
2 changes: 1 addition & 1 deletion test/TestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from 'path';
import crypto from 'crypto';
import { getScopeAndName } from '../app/common/PackageUtil';
import semver from 'semver';
import { PackageJSONType } from 'app/core/service/PackageManagerService';
import { PackageJSONType } from '../app/repository/PackageRepository';

type PackageOptions = {
name?: string;
Expand Down
4 changes: 2 additions & 2 deletions test/port/controller/package/ShowPackageController.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import assert from 'assert';
import { app, mock } from 'egg-mock/bootstrap';
import { TestUtil } from 'test/TestUtil';
import { PackageRepository } from '../../../../app/repository/PackageRepository';
import { PackageManifestType, PackageRepository } from '../../../../app/repository/PackageRepository';
import { BugVersion } from '../../../../app/core/entity/BugVersion';
import { PackageManagerService, PackageManifestType } from '../../../../app/core/service/PackageManagerService';
import { PackageManagerService } from '../../../../app/core/service/PackageManagerService';
import { CacheService } from '../../../../app/core/service/CacheService';
import { DistRepository } from '../../../../app/repository/DistRepository';

Expand Down

0 comments on commit f4e2a7d

Please sign in to comment.