Skip to content

Commit

Permalink
refactor: rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
hezhengxu2018 committed Jun 19, 2024
1 parent 5b8e287 commit 563a1b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions app/core/service/ProxyCacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class ProxyCacheService extends AbstractService {
return nfsPkgManifgest;
}

const manifest = await this.getSourceManifestAndCache<typeof fileType>(fullname, fileType);
const manifest = await this.rewriteManifestAndStore<typeof fileType>(fullname, fileType);
this.backgroundTaskHelper.run(async () => {
const cachedFiles = ProxyCache.create({ fullname, fileType });
await this.proxyCacheRepository.saveProxyCache(cachedFiles);
Expand All @@ -91,7 +91,7 @@ export class ProxyCacheService extends AbstractService {
const nfsString = Buffer.from(nfsBytes!).toString();
return JSON.parse(nfsString) as PackageJSONType | AbbreviatedPackageJSONType;
}
const manifest = await this.getSourceManifestAndCache(fullname, fileType, versionOrTag);
const manifest = await this.rewriteManifestAndStore(fullname, fileType, versionOrTag);
this.backgroundTaskHelper.run(async () => {
const cachedFiles = ProxyCache.create({ fullname, fileType, version });
await this.proxyCacheRepository.saveProxyCache(cachedFiles);
Expand Down Expand Up @@ -125,7 +125,7 @@ export class ProxyCacheService extends AbstractService {
if (isPkgManifest(fileType)) {
const cachedFiles = await this.proxyCacheRepository.findProxyCache(fullname, fileType);
if (!cachedFiles) throw new Error('task params error, can not found record in repo.');
cachedManifest = await this.getSourceManifestAndCache<typeof fileType>(fullname, fileType);
cachedManifest = await this.rewriteManifestAndStore<typeof fileType>(fullname, fileType);
ProxyCache.update(cachedFiles);
await this.proxyCacheRepository.saveProxyCache(cachedFiles);
} else {
Expand Down Expand Up @@ -158,7 +158,7 @@ export class ProxyCacheService extends AbstractService {
await this.taskService.finishTask(task, TaskState.Success, logs.join('\n'));
}

async getSourceManifestAndCache<T extends DIST_NAMES>(fullname:string, fileType: T, versionOrTag?:string): Promise<GetSourceManifestAndCacheReturnType<T>> {
async rewriteManifestAndStore<T extends DIST_NAMES>(fullname:string, fileType: T, versionOrTag?:string): Promise<GetSourceManifestAndCacheReturnType<T>> {
let responseResult;
switch (fileType) {
case DIST_NAMES.FULL_MANIFESTS:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"npm-package-arg": "^10.1.0",
"oss-cnpm": "^5.0.1",
"p-map": "^4.0.0",
"s3-cnpmcore": "^1.1.2",
"semver": "^7.3.5",
"ssri": "^8.0.1",
"type-fest": "^2.5.3",
Expand Down
22 changes: 11 additions & 11 deletions test/core/service/ProxyCacheService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
});

describe('getPackageManifest()', () => {
it('should invoke getSourceManifestAndCache first.', async () => {
mock(proxyCacheService, 'getSourceManifestAndCache', async () => {
it('should invoke rewriteManifestAndStore first.', async () => {
mock(proxyCacheService, 'rewriteManifestAndStore', async () => {
return { name: 'mock info' };
});
const manifest = await proxyCacheService.getPackageManifest(
Expand All @@ -31,7 +31,7 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {

it('should read data from nfs when cached.', async () => {
const nfsAdapter = await app.getEggObject(NFSAdapter);
mock(proxyCacheService, 'getSourceManifestAndCache', async () => {
mock(proxyCacheService, 'rewriteManifestAndStore', async () => {
return { name: 'foo remote mock info' };
});
await proxyCacheRepository.saveProxyCache(
Expand All @@ -52,8 +52,8 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
});

describe('getPackageVersionManifest()', () => {
it('should invoke getSourceManifestAndCache first.', async () => {
mock(proxyCacheService, 'getSourceManifestAndCache', async () => {
it('should invoke rewriteManifestAndStore first.', async () => {
mock(proxyCacheService, 'rewriteManifestAndStore', async () => {
return { name: 'mock package version info' };
});
const manifest = await proxyCacheService.getPackageVersionManifest(
Expand All @@ -66,7 +66,7 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {

it('should read data from nfs when cached.', async () => {
const nfsAdapter = await app.getEggObject(NFSAdapter);
mock(proxyCacheService, 'getSourceManifestAndCache', async () => {
mock(proxyCacheService, 'rewriteManifestAndStore', async () => {
return { name: 'foo remote mock info' };
});
await proxyCacheRepository.saveProxyCache(
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
});
});

describe('getSourceManifestAndCache()', () => {
describe('rewriteManifestAndStore()', () => {
it('should get full package manifest', async () => {
const data = await TestUtil.readJSONFile(
TestUtil.getFixtures('registry.npmjs.org/foobar.json'),
Expand All @@ -125,7 +125,7 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
data,
};
});
const manifest = await proxyCacheService.getSourceManifestAndCache(
const manifest = await proxyCacheService.rewriteManifestAndStore(
'foobar',
DIST_NAMES.FULL_MANIFESTS,
);
Expand All @@ -145,7 +145,7 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
data,
};
});
const manifest = await proxyCacheService.getSourceManifestAndCache(
const manifest = await proxyCacheService.rewriteManifestAndStore(
'foobar',
DIST_NAMES.ABBREVIATED_MANIFESTS,
);
Expand All @@ -165,7 +165,7 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
data,
};
});
const manifest = await proxyCacheService.getSourceManifestAndCache(
const manifest = await proxyCacheService.rewriteManifestAndStore(
'foobar',
DIST_NAMES.MANIFEST,
'1.0.0',
Expand All @@ -186,7 +186,7 @@ describe('test/core/service/ProxyCacheService/index.test.ts', () => {
data,
};
});
const manifest = await proxyCacheService.getSourceManifestAndCache(
const manifest = await proxyCacheService.rewriteManifestAndStore(
'foobar',
DIST_NAMES.ABBREVIATED,
'1.0.0',
Expand Down

0 comments on commit 563a1b5

Please sign in to comment.