@verdaccio/search 7.0.0-next.2 → 8.0.0-next-8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,39 +0,0 @@
1
- import { Logger, Version } from '@verdaccio/types';
2
- type Results = any;
3
- declare class SearchMemoryIndexer {
4
- private database;
5
- private storage;
6
- private logger;
7
- /**
8
- * Set up the {Storage}
9
- * @param {*} storage An storage reference.
10
- */
11
- configureStorage(storage: any): void;
12
- /**
13
- * Performs a query to the indexer.
14
- * If the keyword is a * it returns all local elements
15
- * otherwise performs a search
16
- * @param {*} q the keyword
17
- * @return {Array} list of results.
18
- */
19
- query(term: string): Promise<Results | void>;
20
- private prepareKeywords;
21
- /**
22
- * Add a new element to index
23
- * @param {*} pkg the package
24
- */
25
- add(pkg: Version): Promise<void>;
26
- /**
27
- * Remove an element from the index.
28
- * @param {*} name the id element
29
- */
30
- remove(name: string): Promise<void>;
31
- /**
32
- * Force a re-index.
33
- */
34
- reindex(): Promise<void>;
35
- init(logger: Logger): Promise<void>;
36
- }
37
- declare const _default: SearchMemoryIndexer;
38
- export default _default;
39
- export { Results };
package/jest.config.js DELETED
@@ -1,12 +0,0 @@
1
- const config = require('../../jest/config');
2
-
3
- module.exports = Object.assign({}, config, {
4
- coverageThreshold: {
5
- global: {
6
- branches: 79,
7
- functions: 94,
8
- lines: 87,
9
- statements: 87,
10
- },
11
- },
12
- });
package/src/indexer.ts DELETED
@@ -1,128 +0,0 @@
1
- import { create, insert, remove, search } from '@orama/orama';
2
- import buildDebug from 'debug';
3
-
4
- import { Logger, Version } from '@verdaccio/types';
5
-
6
- const debug = buildDebug('verdaccio:search:indexer');
7
-
8
- type Results = any;
9
-
10
- class SearchMemoryIndexer {
11
- private database: any | undefined;
12
- private storage: any;
13
- private logger: Logger | undefined;
14
-
15
- /**
16
- * Set up the {Storage}
17
- * @param {*} storage An storage reference.
18
- */
19
- public configureStorage(storage): void {
20
- this.storage = storage;
21
- }
22
-
23
- /**
24
- * Performs a query to the indexer.
25
- * If the keyword is a * it returns all local elements
26
- * otherwise performs a search
27
- * @param {*} q the keyword
28
- * @return {Array} list of results.
29
- */
30
- public async query(term: string): Promise<Results | void> {
31
- if (this.database) {
32
- debug('searching %s at indexer', term);
33
- const searchResult = await search(this.database, {
34
- term,
35
- });
36
-
37
- return searchResult;
38
- }
39
- }
40
-
41
- private prepareKeywords(keywords?: string[] | string): string {
42
- if (typeof keywords === 'undefined') {
43
- return '';
44
- } else if (typeof keywords === 'string') {
45
- return keywords;
46
- }
47
- return keywords.join(',');
48
- }
49
-
50
- /**
51
- * Add a new element to index
52
- * @param {*} pkg the package
53
- */
54
- public async add(pkg: Version): Promise<void> {
55
- if (this.database) {
56
- const name = pkg.name;
57
- debug('adding item %s to the indexer', name);
58
- const item = {
59
- id: name,
60
- name: name,
61
- description: pkg.description,
62
- version: pkg.version,
63
- keywords: this.prepareKeywords(pkg.keywords),
64
- author: pkg._npmUser ? pkg._npmUser.name : '',
65
- };
66
- await insert(this.database, item);
67
- }
68
- }
69
-
70
- /**
71
- * Remove an element from the index.
72
- * @param {*} name the id element
73
- */
74
- public async remove(name: string): Promise<void> {
75
- if (this.database) {
76
- debug('removing item %s to the indexer', name);
77
- await remove(this.database, name);
78
- }
79
- }
80
-
81
- /**
82
- * Force a re-index.
83
- */
84
- public async reindex(): Promise<void> {
85
- debug('reindexing search indexer');
86
- this.storage?.getLocalDatabase(async (error, packages): Promise<void> => {
87
- if (error) {
88
- // that function shouldn't produce any
89
- throw error;
90
- }
91
- let i = packages.length;
92
- if (i === 0) {
93
- debug('no packages to index');
94
- }
95
-
96
- while (i--) {
97
- const pkg = packages[i];
98
- debug('indexing package %s', pkg?.name);
99
- try {
100
- await this.add(pkg);
101
- } catch (err: any) {
102
- this.logger?.error({ err: err.message }, 'error @{err} indexing package');
103
- }
104
- }
105
- debug('reindexed search indexer');
106
- });
107
- }
108
-
109
- public async init(logger: Logger) {
110
- this.logger = logger;
111
- this.database = await create({
112
- schema: {
113
- id: 'string',
114
- name: 'string',
115
- description: 'string',
116
- keywords: 'string',
117
- version: 'string',
118
- readme: 'string',
119
- },
120
- });
121
-
122
- this.reindex();
123
- }
124
- }
125
-
126
- export default new SearchMemoryIndexer();
127
-
128
- export { Results };
@@ -1,47 +0,0 @@
1
- import { expect, test } from 'vitest';
2
-
3
- import { Logger } from '@verdaccio/types';
4
-
5
- import { SearchMemoryIndexer } from '../src';
6
-
7
- class MockStore {
8
- getLocalDatabase(cb) {
9
- return cb(null, [
10
- {
11
- name: 'verdaccio-search',
12
- version: '1.0.0',
13
- readme: 'foo',
14
- description: 'foo',
15
- keywords: ['foo', 'bar'],
16
- },
17
- {
18
- name: 'verdaccio-utils',
19
- version: '2.0.0',
20
- readme: 'foo',
21
- description: 'foo',
22
- keywords: 'some',
23
- },
24
- ]);
25
- }
26
- }
27
-
28
- const logger = {
29
- // eslint-disable-next-line no-console
30
- error: (...arg) => console.error(...arg),
31
- } as Logger;
32
-
33
- test('should search', async () => {
34
- const store = new MockStore();
35
-
36
- SearchMemoryIndexer.configureStorage(store);
37
- await SearchMemoryIndexer.init(logger);
38
- // @ts-expect-error
39
- await SearchMemoryIndexer.add({
40
- name: 'verdaccio',
41
- version: '2.0.0',
42
- readme: 'foo',
43
- description: '',
44
- });
45
- const query = await SearchMemoryIndexer.query('verdaccio');
46
- expect(query.hits.map((item) => item.id)).toEqual(['verdaccio', 'verdaccio-utils']);
47
- });
package/types/patch.d.ts DELETED
@@ -1,10 +0,0 @@
1
- declare module 'jest-matcher-utils';
2
- declare module 'pretty-format' {
3
- export type Plugin = any;
4
- export type CompareKeys = any;
5
- }
6
- declare module '@jest/schemas' {
7
- export type SnapshotFormat = any;
8
- }
9
-
10
- declare module '@szmarczak/http-timer';