@tinacms/search 0.0.0-c1132cd-20241024060747 → 0.0.0-c19d29e-20251224001156
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/README.md +55 -0
- package/dist/client/index.d.ts +10 -13
- package/dist/fuzzy/cache.d.ts +11 -0
- package/dist/fuzzy/distance.d.ts +8 -0
- package/dist/fuzzy/index.d.ts +4 -0
- package/dist/fuzzy/types.d.ts +19 -0
- package/dist/fuzzy-search-wrapper.d.ts +23 -0
- package/dist/index-client.d.ts +25 -13
- package/dist/index-client.js +201 -206
- package/dist/index.d.ts +8 -3
- package/dist/index.js +530 -211
- package/dist/indexer/index.d.ts +1 -0
- package/dist/indexer/utils.d.ts +1 -1
- package/dist/pagination.d.ts +16 -0
- package/dist/types.d.ts +51 -11
- package/package.json +18 -19
- package/dist/index-client.mjs +0 -195
package/dist/indexer/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class SearchIndexer {
|
|
|
15
15
|
private readonly schema;
|
|
16
16
|
private readonly textIndexLength;
|
|
17
17
|
constructor(options: SearchIndexOptions);
|
|
18
|
+
private createBatchProcessor;
|
|
18
19
|
private makeIndexerCallback;
|
|
19
20
|
indexContentByPaths(documentPaths: string[]): Promise<void>;
|
|
20
21
|
indexAllContent(): Promise<{
|
package/dist/indexer/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Collection, ObjectField } from '@tinacms/schema-tools';
|
|
2
|
-
export declare const processDocumentForIndexing: (data:
|
|
2
|
+
export declare const processDocumentForIndexing: (data: Record<string, unknown>, path: string, collection: Collection, textIndexLength: number, field?: ObjectField) => Record<string, unknown>;
|
|
3
3
|
export declare const lookupStopwords: (keys?: string[], defaultStopWords?: string[]) => string[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface PaginationOptions {
|
|
2
|
+
limit?: number;
|
|
3
|
+
cursor?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface PageOptions {
|
|
6
|
+
PAGE?: {
|
|
7
|
+
SIZE: number;
|
|
8
|
+
NUMBER: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface PaginationCursors {
|
|
12
|
+
nextCursor: string | null;
|
|
13
|
+
prevCursor: string | null;
|
|
14
|
+
}
|
|
15
|
+
export declare function buildPageOptions(options: PaginationOptions): PageOptions;
|
|
16
|
+
export declare function buildPaginationCursors(total: number, options: PaginationOptions): PaginationCursors;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,55 @@
|
|
|
1
|
+
import type { FuzzySearchOptions, FuzzyMatch } from './fuzzy';
|
|
2
|
+
export interface SearchOptions {
|
|
3
|
+
cursor?: string;
|
|
4
|
+
limit?: number;
|
|
5
|
+
fuzzy?: boolean;
|
|
6
|
+
fuzzyOptions?: FuzzySearchOptions;
|
|
7
|
+
}
|
|
8
|
+
export interface SearchResult {
|
|
9
|
+
_id: string;
|
|
10
|
+
_match: Record<string, string[]>;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface SearchQueryResponse {
|
|
14
|
+
results: SearchResult[];
|
|
15
|
+
total: number;
|
|
16
|
+
nextCursor: string | null;
|
|
17
|
+
prevCursor: string | null;
|
|
18
|
+
fuzzyMatches?: Record<string, FuzzyMatch[]>;
|
|
19
|
+
}
|
|
20
|
+
export interface IndexableDocument {
|
|
21
|
+
_id: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
export interface SearchIndexResult {
|
|
25
|
+
RESULT: SearchResult[];
|
|
26
|
+
RESULT_LENGTH: number;
|
|
27
|
+
}
|
|
28
|
+
export interface SearchIndex {
|
|
29
|
+
PUT: (docs: IndexableDocument[]) => Promise<void>;
|
|
30
|
+
DELETE: (ids: string[]) => Promise<void>;
|
|
31
|
+
QUERY: (query: {
|
|
32
|
+
AND: string[];
|
|
33
|
+
} | {
|
|
34
|
+
OR: string[];
|
|
35
|
+
} | {
|
|
36
|
+
AND: (string | {
|
|
37
|
+
OR: string[];
|
|
38
|
+
})[];
|
|
39
|
+
}, options?: {
|
|
40
|
+
PAGE?: {
|
|
41
|
+
NUMBER: number;
|
|
42
|
+
SIZE: number;
|
|
43
|
+
};
|
|
44
|
+
}) => Promise<SearchIndexResult>;
|
|
45
|
+
DICTIONARY: (token?: {
|
|
46
|
+
FIELD: string;
|
|
47
|
+
}) => Promise<unknown[]>;
|
|
48
|
+
}
|
|
1
49
|
export type SearchClient = {
|
|
2
|
-
query: (query: string, options?:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) => Promise<{
|
|
6
|
-
results: any[];
|
|
7
|
-
total: number;
|
|
8
|
-
nextCursor: string | null;
|
|
9
|
-
prevCursor: string | null;
|
|
10
|
-
}>;
|
|
11
|
-
put: (docs: any[]) => Promise<any>;
|
|
12
|
-
del: (ids: string[]) => Promise<any>;
|
|
50
|
+
query: (query: string, options?: SearchOptions) => Promise<SearchQueryResponse>;
|
|
51
|
+
put: (docs: IndexableDocument[] | Record<string, unknown>[]) => Promise<void>;
|
|
52
|
+
del: (ids: string[]) => Promise<void>;
|
|
13
53
|
onStartIndexing?: () => Promise<void>;
|
|
14
54
|
onFinishIndexing?: () => Promise<void>;
|
|
15
55
|
supportsClientSideIndexing?: () => boolean;
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/search",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0-c19d29e-20251224001156",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
|
-
"
|
|
6
|
-
"typings": "dist/index.d.ts",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"package.json",
|
|
9
8
|
"dist"
|
|
10
9
|
],
|
|
11
10
|
"exports": {
|
|
12
11
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
15
14
|
},
|
|
16
|
-
"./
|
|
17
|
-
"
|
|
18
|
-
"
|
|
15
|
+
"./index-client": {
|
|
16
|
+
"types": "./dist/index-client.d.ts",
|
|
17
|
+
"default": "./dist/index-client.js"
|
|
19
18
|
}
|
|
20
19
|
},
|
|
21
20
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -31,10 +30,10 @@
|
|
|
31
30
|
"dependencies": {
|
|
32
31
|
"memory-level": "^1.0.0",
|
|
33
32
|
"search-index": "4.0.0",
|
|
34
|
-
"sqlite-level": "^1.2.
|
|
35
|
-
"stopword": "^3.1.
|
|
36
|
-
"@tinacms/graphql": "0.0.0-
|
|
37
|
-
"@tinacms/schema-tools": "0.0.0-
|
|
33
|
+
"sqlite-level": "^1.2.1",
|
|
34
|
+
"stopword": "^3.1.4",
|
|
35
|
+
"@tinacms/graphql": "0.0.0-c19d29e-20251224001156",
|
|
36
|
+
"@tinacms/schema-tools": "0.0.0-c19d29e-20251224001156"
|
|
38
37
|
},
|
|
39
38
|
"publishConfig": {
|
|
40
39
|
"registry": "https://registry.npmjs.org"
|
|
@@ -44,23 +43,23 @@
|
|
|
44
43
|
"directory": "packages/@tinacms/search"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
|
-
"@types/jest": "^29.5.
|
|
46
|
+
"@types/jest": "^29.5.14",
|
|
48
47
|
"@types/micromatch": "^4.0.9",
|
|
49
|
-
"@types/node": "^22.
|
|
48
|
+
"@types/node": "^22.13.1",
|
|
50
49
|
"@types/search-index": "^3.2.4",
|
|
51
50
|
"jest": "^29.7.0",
|
|
52
51
|
"jest-diff": "^29.7.0",
|
|
53
52
|
"jest-file-snapshot": "^0.7.0",
|
|
54
53
|
"jest-matcher-utils": "^29.7.0",
|
|
55
|
-
"typescript": "^5.
|
|
56
|
-
"@tinacms/scripts": "1.
|
|
54
|
+
"typescript": "^5.7.3",
|
|
55
|
+
"@tinacms/scripts": "1.4.2"
|
|
57
56
|
},
|
|
58
57
|
"scripts": {
|
|
59
58
|
"types": "pnpm tsc",
|
|
60
59
|
"build": "tinacms-scripts build",
|
|
61
60
|
"docs": "pnpm typedoc",
|
|
62
61
|
"serve": "pnpm nodemon dist/server.js",
|
|
63
|
-
"test": "jest",
|
|
64
|
-
"test-watch": "jest --watch"
|
|
62
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
|
|
63
|
+
"test-watch": "NODE_OPTIONS='--experimental-vm-modules' jest --watch"
|
|
65
64
|
}
|
|
66
65
|
}
|
package/dist/index-client.mjs
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import * as sw from "stopword";
|
|
2
|
-
class StringBuilder {
|
|
3
|
-
constructor(limit) {
|
|
4
|
-
this.length = 0;
|
|
5
|
-
this.buffer = [];
|
|
6
|
-
this.limit = limit;
|
|
7
|
-
}
|
|
8
|
-
append(str) {
|
|
9
|
-
if (this.length + str.length > this.limit) {
|
|
10
|
-
return true;
|
|
11
|
-
} else {
|
|
12
|
-
this.buffer.push(str);
|
|
13
|
-
this.length += str.length;
|
|
14
|
-
if (this.length > this.limit) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
toString() {
|
|
21
|
-
return this.buffer.join(" ");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const extractText = (data, acc, indexableNodeTypes) => {
|
|
25
|
-
var _a, _b;
|
|
26
|
-
if (data) {
|
|
27
|
-
if (indexableNodeTypes.indexOf(data.type) !== -1 && (data.text || data.value)) {
|
|
28
|
-
const tokens = tokenizeString(data.text || data.value);
|
|
29
|
-
for (const token of tokens) {
|
|
30
|
-
if (acc.append(token)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
(_b = (_a = data.children) == null ? void 0 : _a.forEach) == null ? void 0 : _b.call(
|
|
36
|
-
_a,
|
|
37
|
-
(child) => extractText(child, acc, indexableNodeTypes)
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const relativePath = (path, collection) => {
|
|
42
|
-
return path.replace(/\\/g, "/").replace(collection.path, "").replace(/^\/|\/$/g, "");
|
|
43
|
-
};
|
|
44
|
-
const tokenizeString = (str) => {
|
|
45
|
-
return str.split(/[\s\.,]+/).map((s) => s.toLowerCase()).filter((s) => s);
|
|
46
|
-
};
|
|
47
|
-
const processTextFieldValue = (value, maxLen) => {
|
|
48
|
-
const tokens = tokenizeString(value);
|
|
49
|
-
const builder = new StringBuilder(maxLen);
|
|
50
|
-
for (const part of tokens) {
|
|
51
|
-
if (builder.append(part)) {
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return builder.toString();
|
|
56
|
-
};
|
|
57
|
-
const processDocumentForIndexing = (data, path, collection, textIndexLength, field) => {
|
|
58
|
-
if (!field) {
|
|
59
|
-
const relPath = relativePath(path, collection);
|
|
60
|
-
data["_id"] = `${collection.name}:${relPath}`;
|
|
61
|
-
data["_relativePath"] = relPath;
|
|
62
|
-
}
|
|
63
|
-
for (const f of (field == null ? void 0 : field.fields) || collection.fields || []) {
|
|
64
|
-
if (!f.searchable) {
|
|
65
|
-
delete data[f.name];
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
const isList = f.list;
|
|
69
|
-
if (data[f.name]) {
|
|
70
|
-
if (f.type === "object") {
|
|
71
|
-
if (isList) {
|
|
72
|
-
data[f.name] = data[f.name].map(
|
|
73
|
-
(obj) => processDocumentForIndexing(
|
|
74
|
-
obj,
|
|
75
|
-
path,
|
|
76
|
-
collection,
|
|
77
|
-
textIndexLength,
|
|
78
|
-
f
|
|
79
|
-
)
|
|
80
|
-
);
|
|
81
|
-
} else {
|
|
82
|
-
data[f.name] = processDocumentForIndexing(
|
|
83
|
-
data[f.name],
|
|
84
|
-
path,
|
|
85
|
-
collection,
|
|
86
|
-
textIndexLength,
|
|
87
|
-
f
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
} else if (f.type === "string") {
|
|
91
|
-
const fieldTextIndexLength = f.maxSearchIndexFieldLength || textIndexLength;
|
|
92
|
-
if (isList) {
|
|
93
|
-
data[f.name] = data[f.name].map(
|
|
94
|
-
(value) => processTextFieldValue(value, fieldTextIndexLength)
|
|
95
|
-
);
|
|
96
|
-
} else {
|
|
97
|
-
data[f.name] = processTextFieldValue(
|
|
98
|
-
data[f.name],
|
|
99
|
-
fieldTextIndexLength
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
} else if (f.type === "rich-text") {
|
|
103
|
-
const fieldTextIndexLength = f.maxSearchIndexFieldLength || textIndexLength;
|
|
104
|
-
if (isList) {
|
|
105
|
-
data[f.name] = data[f.name].map((value) => {
|
|
106
|
-
const acc = new StringBuilder(fieldTextIndexLength);
|
|
107
|
-
extractText(value, acc, ["text", "code_block", "html"]);
|
|
108
|
-
return acc.toString();
|
|
109
|
-
});
|
|
110
|
-
} else {
|
|
111
|
-
const acc = new StringBuilder(fieldTextIndexLength);
|
|
112
|
-
extractText(data[f.name], acc, ["text", "code_block", "html"]);
|
|
113
|
-
data[f.name] = acc.toString();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return data;
|
|
119
|
-
};
|
|
120
|
-
const memo = {};
|
|
121
|
-
const lookupStopwords = (keys, defaultStopWords = sw.eng) => {
|
|
122
|
-
let stopwords = defaultStopWords;
|
|
123
|
-
if (keys) {
|
|
124
|
-
if (memo[keys.join(",")]) {
|
|
125
|
-
return memo[keys.join(",")];
|
|
126
|
-
}
|
|
127
|
-
stopwords = [];
|
|
128
|
-
for (const key of keys) {
|
|
129
|
-
stopwords.push(...sw[key]);
|
|
130
|
-
}
|
|
131
|
-
memo[keys.join(",")] = stopwords;
|
|
132
|
-
}
|
|
133
|
-
return stopwords;
|
|
134
|
-
};
|
|
135
|
-
const queryToSearchIndexQuery = (query, stopwordLanguages) => {
|
|
136
|
-
let q;
|
|
137
|
-
const parts = query.split(" ");
|
|
138
|
-
const stopwords = lookupStopwords(stopwordLanguages);
|
|
139
|
-
if (parts.length === 1) {
|
|
140
|
-
q = { AND: [parts[0]] };
|
|
141
|
-
} else {
|
|
142
|
-
q = {
|
|
143
|
-
AND: parts.filter(
|
|
144
|
-
(part) => part.toLowerCase() !== "and" && stopwords.indexOf(part.toLowerCase()) === -1
|
|
145
|
-
)
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
return q;
|
|
149
|
-
};
|
|
150
|
-
const optionsToSearchIndexOptions = (options) => {
|
|
151
|
-
const opt = {};
|
|
152
|
-
if (options == null ? void 0 : options.limit) {
|
|
153
|
-
opt["PAGE"] = {
|
|
154
|
-
SIZE: options.limit,
|
|
155
|
-
NUMBER: (options == null ? void 0 : options.cursor) ? parseInt(options.cursor) : 0
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
return opt;
|
|
159
|
-
};
|
|
160
|
-
const parseSearchIndexResponse = (data, options) => {
|
|
161
|
-
const results = data["RESULT"];
|
|
162
|
-
const total = data["RESULT_LENGTH"];
|
|
163
|
-
if ((options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
|
|
164
|
-
const prevCursor = options.cursor === "0" ? null : (parseInt(options.cursor) - 1).toString();
|
|
165
|
-
const nextCursor = total <= (parseInt(options.cursor) + 1) * options.limit ? null : (parseInt(options.cursor) + 1).toString();
|
|
166
|
-
return {
|
|
167
|
-
results,
|
|
168
|
-
total,
|
|
169
|
-
prevCursor,
|
|
170
|
-
nextCursor
|
|
171
|
-
};
|
|
172
|
-
} else if (!(options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
|
|
173
|
-
const prevCursor = null;
|
|
174
|
-
const nextCursor = total <= options.limit ? null : "1";
|
|
175
|
-
return {
|
|
176
|
-
results,
|
|
177
|
-
total,
|
|
178
|
-
prevCursor,
|
|
179
|
-
nextCursor
|
|
180
|
-
};
|
|
181
|
-
} else {
|
|
182
|
-
return {
|
|
183
|
-
results,
|
|
184
|
-
total,
|
|
185
|
-
prevCursor: null,
|
|
186
|
-
nextCursor: null
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
export {
|
|
191
|
-
optionsToSearchIndexOptions,
|
|
192
|
-
parseSearchIndexResponse,
|
|
193
|
-
processDocumentForIndexing,
|
|
194
|
-
queryToSearchIndexQuery
|
|
195
|
-
};
|