@verdaccio/search 6.0.0-6-next.2
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.
- package/.babelrc +3 -0
- package/CHANGELOG.md +735 -0
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/build/dist.js +5246 -0
- package/build/index.d.ts +1 -0
- package/build/indexer.d.ts +37 -0
- package/jest.config.js +12 -0
- package/package.json +51 -0
- package/src/index.ts +1 -0
- package/src/indexer.ts +113 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +23 -0
- package/types/patch.d.ts +10 -0
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SearchMemoryIndexer } from './indexer';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Version } from '@verdaccio/types';
|
|
2
|
+
type Results = any;
|
|
3
|
+
declare class SearchMemoryIndexer {
|
|
4
|
+
private database;
|
|
5
|
+
private storage;
|
|
6
|
+
/**
|
|
7
|
+
* Set up the {Storage}
|
|
8
|
+
* @param {*} storage An storage reference.
|
|
9
|
+
*/
|
|
10
|
+
configureStorage(storage: any): void;
|
|
11
|
+
/**
|
|
12
|
+
* Performs a query to the indexer.
|
|
13
|
+
* If the keyword is a * it returns all local elements
|
|
14
|
+
* otherwise performs a search
|
|
15
|
+
* @param {*} q the keyword
|
|
16
|
+
* @return {Array} list of results.
|
|
17
|
+
*/
|
|
18
|
+
query(term: string): Promise<Results | void>;
|
|
19
|
+
/**
|
|
20
|
+
* Add a new element to index
|
|
21
|
+
* @param {*} pkg the package
|
|
22
|
+
*/
|
|
23
|
+
add(pkg: Version): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Remove an element from the index.
|
|
26
|
+
* @param {*} name the id element
|
|
27
|
+
*/
|
|
28
|
+
remove(name: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Force a re-index.
|
|
31
|
+
*/
|
|
32
|
+
reindex(): void;
|
|
33
|
+
init(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
declare const _default: SearchMemoryIndexer;
|
|
36
|
+
export default _default;
|
|
37
|
+
export { Results };
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@verdaccio/search",
|
|
3
|
+
"version": "6.0.0-6-next.2",
|
|
4
|
+
"description": "verdaccio search utitlity tools",
|
|
5
|
+
"main": "./build/dist.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Juan Picado",
|
|
9
|
+
"email": "juanpicado19@gmail.com"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "https",
|
|
13
|
+
"url": "https://github.com/verdaccio/verdaccio"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"homepage": "https://verdaccio.org",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"private",
|
|
19
|
+
"package",
|
|
20
|
+
"repository",
|
|
21
|
+
"registry",
|
|
22
|
+
"enterprise",
|
|
23
|
+
"modules",
|
|
24
|
+
"proxy",
|
|
25
|
+
"server",
|
|
26
|
+
"verdaccio"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=12",
|
|
30
|
+
"npm": ">=6"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "16.18.10",
|
|
34
|
+
"@verdaccio/types": "11.0.0-6-next.25",
|
|
35
|
+
"@orama/orama": "1.0.0-beta.16",
|
|
36
|
+
"debug": "4.3.4",
|
|
37
|
+
"esbuild": "0.14.10"
|
|
38
|
+
},
|
|
39
|
+
"funding": {
|
|
40
|
+
"type": "opencollective",
|
|
41
|
+
"url": "https://opencollective.com/verdaccio"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"clean": "rimraf ./build",
|
|
45
|
+
"test": "echo 1",
|
|
46
|
+
"type-check": "tsc --noEmit -p tsconfig.build.json",
|
|
47
|
+
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
|
|
48
|
+
"build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
|
|
49
|
+
"build": "esbuild src/index.ts --bundle --outfile=build/dist.js --platform=node --target=node12 && pnpm run build:types"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SearchMemoryIndexer } from './indexer';
|
package/src/indexer.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { create, insert, remove, search } from '@orama/orama';
|
|
2
|
+
import buildDebug from 'debug';
|
|
3
|
+
|
|
4
|
+
import { 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
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Set up the {Storage}
|
|
16
|
+
* @param {*} storage An storage reference.
|
|
17
|
+
*/
|
|
18
|
+
public configureStorage(storage): void {
|
|
19
|
+
this.storage = storage;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Performs a query to the indexer.
|
|
24
|
+
* If the keyword is a * it returns all local elements
|
|
25
|
+
* otherwise performs a search
|
|
26
|
+
* @param {*} q the keyword
|
|
27
|
+
* @return {Array} list of results.
|
|
28
|
+
*/
|
|
29
|
+
public async query(term: string): Promise<Results | void> {
|
|
30
|
+
if (this.database) {
|
|
31
|
+
debug('searching %s at indexer', term);
|
|
32
|
+
const searchResult = await search(this.database, {
|
|
33
|
+
term,
|
|
34
|
+
properties: '*',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return searchResult;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Add a new element to index
|
|
43
|
+
* @param {*} pkg the package
|
|
44
|
+
*/
|
|
45
|
+
public async add(pkg: Version): Promise<void> {
|
|
46
|
+
if (this.database) {
|
|
47
|
+
const name = pkg.name;
|
|
48
|
+
debug('adding item %s to the indexer', name);
|
|
49
|
+
insert(this.database, {
|
|
50
|
+
id: name,
|
|
51
|
+
name: name,
|
|
52
|
+
description: pkg.description,
|
|
53
|
+
version: `v${pkg.version}`,
|
|
54
|
+
keywords: pkg.keywords,
|
|
55
|
+
author: pkg._npmUser ? pkg._npmUser.name : '???',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Remove an element from the index.
|
|
62
|
+
* @param {*} name the id element
|
|
63
|
+
*/
|
|
64
|
+
public async remove(name: string): Promise<void> {
|
|
65
|
+
if (this.database) {
|
|
66
|
+
debug('removing item %s to the indexer', name);
|
|
67
|
+
await remove(this.database, name);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Force a re-index.
|
|
73
|
+
*/
|
|
74
|
+
public reindex(): void {
|
|
75
|
+
debug('reindexing search indexer');
|
|
76
|
+
this.storage?.getLocalDatabase((error, packages): void => {
|
|
77
|
+
if (error) {
|
|
78
|
+
// that function shouldn't produce any
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
let i = packages.length;
|
|
82
|
+
if (i === 0) {
|
|
83
|
+
debug('no packages to index');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
while (i--) {
|
|
87
|
+
const pkg = packages[i];
|
|
88
|
+
debug('indexing package %s', pkg?.name);
|
|
89
|
+
this.add(pkg);
|
|
90
|
+
}
|
|
91
|
+
debug('reindexed search indexer');
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public async init() {
|
|
96
|
+
this.database = await create({
|
|
97
|
+
schema: {
|
|
98
|
+
id: 'string',
|
|
99
|
+
name: 'string',
|
|
100
|
+
description: 'string',
|
|
101
|
+
keywords: 'string',
|
|
102
|
+
version: 'string',
|
|
103
|
+
readme: 'string',
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
this.reindex();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default new SearchMemoryIndexer();
|
|
112
|
+
|
|
113
|
+
export { Results };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.reference.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./build",
|
|
6
|
+
"noImplicitAny": false
|
|
7
|
+
},
|
|
8
|
+
"include": ["src/**/*.ts", "types/*.d.ts"],
|
|
9
|
+
"references": [
|
|
10
|
+
{
|
|
11
|
+
"path": "../config"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"path": "../core/core"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "../logger/logger"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "../utils"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
package/types/patch.d.ts
ADDED