<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Documentation** - Updated the "Supported Versions" section in the SECURITY.md file to reflect that security updates are now provided for versions 3.0.0 and above. - Minor formatting adjustments made in the "Disclosure Policy" section for consistency. - **Chores** - Simplified debugger configurations by removing explicit protocol and port settings from the `.vscode/launch.json` file. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: elrrrrrrr <elrrrrrrr@gmail.com>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { SingletonProto, AccessLevel, Inject } from '@eggjs/tegg';
|
|
import { SearchAdapter } from '../common/typing';
|
|
import { AuthorType, CnpmcorePatchInfo, PackageManifestType } from './PackageRepository';
|
|
import { estypes } from '@elastic/elasticsearch';
|
|
|
|
export type SearchJSONPickKey = '_rev' | 'name' | 'description' | 'keywords' | 'license' | 'maintainers' | 'dist-tags' | '_source_registry_name';
|
|
|
|
export type SearchMappingType = Pick<PackageManifestType, SearchJSONPickKey> & CnpmcorePatchInfo & {
|
|
scope: string;
|
|
version: string;
|
|
versions: string[];
|
|
date: Date;
|
|
created: Date;
|
|
modified: Date;
|
|
author?: AuthorType | undefined;
|
|
_npmUser?: {
|
|
name: string;
|
|
email: string;
|
|
}
|
|
};
|
|
|
|
|
|
export type SearchManifestType = {
|
|
package: SearchMappingType;
|
|
downloads: {
|
|
all: number;
|
|
};
|
|
};
|
|
|
|
@SingletonProto({
|
|
accessLevel: AccessLevel.PUBLIC,
|
|
})
|
|
export class SearchRepository {
|
|
@Inject()
|
|
private readonly searchAdapter: SearchAdapter;
|
|
|
|
|
|
async searchPackage(query): Promise<estypes.SearchHitsMetadata<SearchManifestType>> {
|
|
return await this.searchAdapter.search<SearchManifestType>(query);
|
|
}
|
|
|
|
async upsertPackage(document: SearchManifestType) {
|
|
return await this.searchAdapter.upsert(document.package.name, document);
|
|
}
|
|
|
|
async removePackage(fullname: string) {
|
|
return await this.searchAdapter.delete(fullname);
|
|
}
|
|
}
|