@tinacms/search 1.0.1 → 1.0.3
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/dist/client/index.d.ts +18 -25
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -34
- package/package.json +5 -6
package/dist/client/index.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import type { SearchClient } from '../types';
|
|
2
|
+
import { MemoryLevel } from 'memory-level';
|
|
3
|
+
declare type TinaSearchIndexerClientOptions = {
|
|
4
|
+
stopwordLanguages?: string[];
|
|
5
|
+
tokenSplitRegex?: string;
|
|
6
|
+
};
|
|
7
|
+
declare type TinaCloudSearchIndexerClientOptions = {
|
|
8
|
+
apiUrl: string;
|
|
9
|
+
branch: string;
|
|
10
|
+
indexerToken: string;
|
|
11
|
+
} & TinaSearchIndexerClientOptions;
|
|
2
12
|
export declare class LocalSearchIndexClient implements SearchClient {
|
|
3
|
-
|
|
4
|
-
|
|
13
|
+
searchIndex: any;
|
|
14
|
+
protected readonly memoryLevel: MemoryLevel;
|
|
15
|
+
private readonly stopwords;
|
|
16
|
+
private readonly tokenSplitRegex;
|
|
17
|
+
constructor(options: TinaSearchIndexerClientOptions);
|
|
18
|
+
onStartIndexing(): Promise<void>;
|
|
5
19
|
put(docs: any[]): Promise<any>;
|
|
6
20
|
del(ids: string[]): Promise<any>;
|
|
7
21
|
query(query: string, options: {
|
|
@@ -13,34 +27,13 @@ export declare class LocalSearchIndexClient implements SearchClient {
|
|
|
13
27
|
nextCursor: string | null;
|
|
14
28
|
prevCursor: string | null;
|
|
15
29
|
}>;
|
|
30
|
+
export(filename: string): Promise<void>;
|
|
16
31
|
}
|
|
17
|
-
declare
|
|
18
|
-
apiUrl: string;
|
|
19
|
-
branch: string;
|
|
20
|
-
indexerToken: string;
|
|
21
|
-
stopwordLanguages?: string[];
|
|
22
|
-
};
|
|
23
|
-
export declare class TinaCMSSearchIndexClient implements SearchClient {
|
|
24
|
-
private memoryLevel;
|
|
25
|
-
private searchIndex;
|
|
32
|
+
export declare class TinaCMSSearchIndexClient extends LocalSearchIndexClient {
|
|
26
33
|
private readonly apiUrl;
|
|
27
34
|
private readonly branch;
|
|
28
35
|
private readonly indexerToken;
|
|
29
|
-
private readonly stopwordLanguages;
|
|
30
36
|
constructor(options: TinaCloudSearchIndexerClientOptions);
|
|
31
|
-
put(docs: any[]): Promise<void>;
|
|
32
|
-
del(ids: string[]): Promise<void>;
|
|
33
|
-
onStartIndexing(): Promise<void>;
|
|
34
37
|
onFinishIndexing(): Promise<void>;
|
|
35
|
-
getSearchIndex(): any;
|
|
36
|
-
query(query: string, options: {
|
|
37
|
-
cursor?: string;
|
|
38
|
-
limit?: number;
|
|
39
|
-
} | undefined): Promise<{
|
|
40
|
-
results: any[];
|
|
41
|
-
total: number;
|
|
42
|
-
nextCursor: string | null;
|
|
43
|
-
prevCursor: string | null;
|
|
44
|
-
}>;
|
|
45
38
|
}
|
|
46
39
|
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
var sw = __toESM(require("stopword"));
|
|
37
|
-
var import_search_index2 = __toESM(require("
|
|
37
|
+
var import_search_index2 = __toESM(require("search-index"));
|
|
38
38
|
|
|
39
39
|
// src/indexer/index.ts
|
|
40
40
|
var import_graphql = require("@tinacms/graphql");
|
|
@@ -253,17 +253,33 @@ var SearchIndexer = class {
|
|
|
253
253
|
// src/client/index.ts
|
|
254
254
|
var import_sqlite_level = require("sqlite-level");
|
|
255
255
|
var zlib = __toESM(require("zlib"));
|
|
256
|
-
var import_search_index = __toESM(require("
|
|
256
|
+
var import_search_index = __toESM(require("search-index"));
|
|
257
257
|
var import_memory_level = require("memory-level");
|
|
258
258
|
var import_node_fetch = __toESM(require("node-fetch"));
|
|
259
|
+
var DEFAULT_TOKEN_SPLIT_REGEX = /[\p{L}\d_]+/gu;
|
|
259
260
|
var LocalSearchIndexClient = class {
|
|
260
|
-
constructor(
|
|
261
|
-
this.
|
|
261
|
+
constructor(options) {
|
|
262
|
+
this.memoryLevel = new import_memory_level.MemoryLevel();
|
|
263
|
+
this.stopwords = lookupStopwords(options.stopwordLanguages);
|
|
264
|
+
this.tokenSplitRegex = options.tokenSplitRegex ? new RegExp(options.tokenSplitRegex, "gu") : DEFAULT_TOKEN_SPLIT_REGEX;
|
|
265
|
+
}
|
|
266
|
+
async onStartIndexing() {
|
|
267
|
+
this.searchIndex = await (0, import_search_index.default)({
|
|
268
|
+
db: this.memoryLevel,
|
|
269
|
+
stopwords: this.stopwords,
|
|
270
|
+
tokenSplitRegex: this.tokenSplitRegex
|
|
271
|
+
});
|
|
262
272
|
}
|
|
263
273
|
async put(docs) {
|
|
274
|
+
if (!this.searchIndex) {
|
|
275
|
+
throw new Error("onStartIndexing must be called first");
|
|
276
|
+
}
|
|
264
277
|
return this.searchIndex.PUT(docs);
|
|
265
278
|
}
|
|
266
279
|
async del(ids) {
|
|
280
|
+
if (!this.searchIndex) {
|
|
281
|
+
throw new Error("onStartIndexing must be called first");
|
|
282
|
+
}
|
|
267
283
|
return this.searchIndex.DELETE(ids);
|
|
268
284
|
}
|
|
269
285
|
query(query, options) {
|
|
@@ -274,30 +290,21 @@ var LocalSearchIndexClient = class {
|
|
|
274
290
|
total: 0
|
|
275
291
|
});
|
|
276
292
|
}
|
|
293
|
+
async export(filename) {
|
|
294
|
+
const sqliteLevel = new import_sqlite_level.SqliteLevel({ filename });
|
|
295
|
+
const iterator = this.memoryLevel.iterator();
|
|
296
|
+
for await (const [key, value] of iterator) {
|
|
297
|
+
await sqliteLevel.put(key, value);
|
|
298
|
+
}
|
|
299
|
+
await sqliteLevel.close();
|
|
300
|
+
}
|
|
277
301
|
};
|
|
278
|
-
var TinaCMSSearchIndexClient = class {
|
|
302
|
+
var TinaCMSSearchIndexClient = class extends LocalSearchIndexClient {
|
|
279
303
|
constructor(options) {
|
|
304
|
+
super(options);
|
|
280
305
|
this.apiUrl = options.apiUrl;
|
|
281
306
|
this.branch = options.branch;
|
|
282
307
|
this.indexerToken = options.indexerToken;
|
|
283
|
-
this.stopwordLanguages = options.stopwordLanguages;
|
|
284
|
-
}
|
|
285
|
-
async put(docs) {
|
|
286
|
-
if (this.searchIndex) {
|
|
287
|
-
await this.searchIndex.PUT(docs);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
async del(ids) {
|
|
291
|
-
if (this.searchIndex) {
|
|
292
|
-
await this.searchIndex.DELETE(ids);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
async onStartIndexing() {
|
|
296
|
-
this.memoryLevel = new import_memory_level.MemoryLevel();
|
|
297
|
-
this.searchIndex = await (0, import_search_index.default)({
|
|
298
|
-
db: this.memoryLevel,
|
|
299
|
-
stopwords: lookupStopwords(this.stopwordLanguages)
|
|
300
|
-
});
|
|
301
308
|
}
|
|
302
309
|
async onFinishIndexing() {
|
|
303
310
|
const headers = new import_node_fetch.Headers();
|
|
@@ -337,17 +344,6 @@ ${await res.text()}`
|
|
|
337
344
|
);
|
|
338
345
|
}
|
|
339
346
|
}
|
|
340
|
-
getSearchIndex() {
|
|
341
|
-
return this.searchIndex;
|
|
342
|
-
}
|
|
343
|
-
query(query, options) {
|
|
344
|
-
return Promise.resolve({
|
|
345
|
-
nextCursor: void 0,
|
|
346
|
-
prevCursor: void 0,
|
|
347
|
-
results: [],
|
|
348
|
-
total: 0
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
347
|
};
|
|
352
348
|
|
|
353
349
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/search",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index-client.es.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -29,16 +29,15 @@
|
|
|
29
29
|
]
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tinacms/graphql": "1.4.
|
|
33
|
-
"@tinacms/schema-tools": "1.4.
|
|
32
|
+
"@tinacms/graphql": "1.4.18",
|
|
33
|
+
"@tinacms/schema-tools": "1.4.7",
|
|
34
34
|
"abstract-level": "^1.0.3",
|
|
35
|
-
"classic-level": "^1.3.0",
|
|
36
35
|
"memory-level": "^1.0.0",
|
|
37
36
|
"module-error": "^1.0.2",
|
|
38
37
|
"node-fetch": "2",
|
|
39
|
-
"
|
|
38
|
+
"search-index": "4.0.0",
|
|
40
39
|
"stopword": "^2.0.8",
|
|
41
|
-
"sqlite-level": "^1.0.
|
|
40
|
+
"sqlite-level": "^1.0.1"
|
|
42
41
|
},
|
|
43
42
|
"publishConfig": {
|
|
44
43
|
"registry": "https://registry.npmjs.org"
|