@tinacms/search 0.0.0-20230523214734
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/LICENSE +184 -0
- package/README.md +0 -0
- package/dist/client/index.d.ts +46 -0
- package/dist/index-client.d.ts +14 -0
- package/dist/index-client.es.js +41 -0
- package/dist/index-client.js +48 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +468 -0
- package/dist/indexer/index.d.ts +26 -0
- package/dist/sqlite-level.d.ts +97 -0
- package/dist/types.d.ts +16 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Copyright (c) 2023-present Forestry.io Holdings Inc.
|
|
2
|
+
|
|
3
|
+
Portions of the TinaCMS software are licensed as follows:
|
|
4
|
+
|
|
5
|
+
* All software that resides under the "packages/@tinacms/datalayer/" and the "packages/@tinacms/graphql/" directories (the "Tina Data Layer"), is licensed under the license defined in "packages/@tinacms/datalayer/LICENSE".
|
|
6
|
+
|
|
7
|
+
* All software outside of the above-mentioned directories is available under the "Apache 2.0" license as set forth below.
|
|
8
|
+
|
|
9
|
+
Apache License
|
|
10
|
+
Version 2.0, January 2004
|
|
11
|
+
http://www.apache.org/licenses/
|
|
12
|
+
|
|
13
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
14
|
+
|
|
15
|
+
1. Definitions.
|
|
16
|
+
|
|
17
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
18
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
19
|
+
|
|
20
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
21
|
+
the copyright owner that is granting the License.
|
|
22
|
+
|
|
23
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
24
|
+
other entities that control, are controlled by, or are under common
|
|
25
|
+
control with that entity. For the purposes of this definition,
|
|
26
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
27
|
+
direction or management of such entity, whether by contract or
|
|
28
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
29
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
30
|
+
|
|
31
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
32
|
+
exercising permissions granted by this License.
|
|
33
|
+
|
|
34
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
35
|
+
including but not limited to software source code, documentation
|
|
36
|
+
source, and configuration files.
|
|
37
|
+
|
|
38
|
+
"Object" form shall mean any form resulting from mechanical
|
|
39
|
+
transformation or translation of a Source form, including but
|
|
40
|
+
not limited to compiled object code, generated documentation,
|
|
41
|
+
and conversions to other media types.
|
|
42
|
+
|
|
43
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
44
|
+
Object form, made available under the License, as indicated by a
|
|
45
|
+
copyright notice that is included in or attached to the work
|
|
46
|
+
(an example is provided in the Appendix below).
|
|
47
|
+
|
|
48
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
49
|
+
form, that is based on (or derived from) the Work and for which the
|
|
50
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
51
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
52
|
+
of this License, Derivative Works shall not include works that remain
|
|
53
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
54
|
+
the Work and Derivative Works thereof.
|
|
55
|
+
|
|
56
|
+
"Contribution" shall mean any work of authorship, including
|
|
57
|
+
the original version of the Work and any modifications or additions
|
|
58
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
59
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
60
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
61
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
62
|
+
means any form of electronic, verbal, or written communication sent
|
|
63
|
+
to the Licensor or its representatives, including but not limited to
|
|
64
|
+
communication on electronic mailing lists, source code control systems,
|
|
65
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
66
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
67
|
+
excluding communication that is conspicuously marked or otherwise
|
|
68
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
69
|
+
|
|
70
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
71
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
72
|
+
subsequently incorporated within the Work.
|
|
73
|
+
|
|
74
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
78
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
79
|
+
Work and such Derivative Works in Source or Object form.
|
|
80
|
+
|
|
81
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
82
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
83
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
84
|
+
(except as stated in this section) patent license to make, have made,
|
|
85
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
86
|
+
where such license applies only to those patent claims licensable
|
|
87
|
+
by such Contributor that are necessarily infringed by their
|
|
88
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
89
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
90
|
+
institute patent litigation against any entity (including a
|
|
91
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
92
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
93
|
+
or contributory patent infringement, then any patent licenses
|
|
94
|
+
granted to You under this License for that Work shall terminate
|
|
95
|
+
as of the date such litigation is filed.
|
|
96
|
+
|
|
97
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
98
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
99
|
+
modifications, and in Source or Object form, provided that You
|
|
100
|
+
meet the following conditions:
|
|
101
|
+
|
|
102
|
+
(a) You must give any other recipients of the Work or
|
|
103
|
+
Derivative Works a copy of this License; and
|
|
104
|
+
|
|
105
|
+
(b) You must cause any modified files to carry prominent notices
|
|
106
|
+
stating that You changed the files; and
|
|
107
|
+
|
|
108
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
109
|
+
that You distribute, all copyright, patent, trademark, and
|
|
110
|
+
attribution notices from the Source form of the Work,
|
|
111
|
+
excluding those notices that do not pertain to any part of
|
|
112
|
+
the Derivative Works; and
|
|
113
|
+
|
|
114
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
115
|
+
distribution, then any Derivative Works that You distribute must
|
|
116
|
+
include a readable copy of the attribution notices contained
|
|
117
|
+
within such NOTICE file, excluding those notices that do not
|
|
118
|
+
pertain to any part of the Derivative Works, in at least one
|
|
119
|
+
of the following places: within a NOTICE text file distributed
|
|
120
|
+
as part of the Derivative Works; within the Source form or
|
|
121
|
+
documentation, if provided along with the Derivative Works; or,
|
|
122
|
+
within a display generated by the Derivative Works, if and
|
|
123
|
+
wherever such third-party notices normally appear. The contents
|
|
124
|
+
of the NOTICE file are for informational purposes only and
|
|
125
|
+
do not modify the License. You may add Your own attribution
|
|
126
|
+
notices within Derivative Works that You distribute, alongside
|
|
127
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
128
|
+
that such additional attribution notices cannot be construed
|
|
129
|
+
as modifying the License.
|
|
130
|
+
|
|
131
|
+
You may add Your own copyright statement to Your modifications and
|
|
132
|
+
may provide additional or different license terms and conditions
|
|
133
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
134
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
135
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
136
|
+
the conditions stated in this License.
|
|
137
|
+
|
|
138
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
139
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
140
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
141
|
+
this License, without any additional terms or conditions.
|
|
142
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
143
|
+
the terms of any separate license agreement you may have executed
|
|
144
|
+
with Licensor regarding such Contributions.
|
|
145
|
+
|
|
146
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
147
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
148
|
+
except as required for reasonable and customary use in describing the
|
|
149
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
150
|
+
|
|
151
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
152
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
153
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
154
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
155
|
+
implied, including, without limitation, any warranties or conditions
|
|
156
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
157
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
158
|
+
appropriateness of using or redistributing the Work and assume any
|
|
159
|
+
risks associated with Your exercise of permissions under this License.
|
|
160
|
+
|
|
161
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
162
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
163
|
+
unless required by applicable law (such as deliberate and grossly
|
|
164
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
165
|
+
liable to You for damages, including any direct, indirect, special,
|
|
166
|
+
incidental, or consequential damages of any character arising as a
|
|
167
|
+
result of this License or out of the use or inability to use the
|
|
168
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
169
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
170
|
+
other commercial damages or losses), even if such Contributor
|
|
171
|
+
has been advised of the possibility of such damages.
|
|
172
|
+
|
|
173
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
174
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
175
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
176
|
+
or other liability obligations and/or rights consistent with this
|
|
177
|
+
License. However, in accepting such obligations, You may act only
|
|
178
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
179
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
180
|
+
defend, and hold each Contributor harmless for any liability
|
|
181
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
182
|
+
of your accepting any such warranty or additional liability.
|
|
183
|
+
|
|
184
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SearchClient } from '../types';
|
|
2
|
+
export declare class LocalSearchIndexClient implements SearchClient {
|
|
3
|
+
protected searchIndex: any;
|
|
4
|
+
constructor(searchIndex: any);
|
|
5
|
+
put(docs: any[]): Promise<any>;
|
|
6
|
+
del(ids: string[]): Promise<any>;
|
|
7
|
+
query(query: string, options: {
|
|
8
|
+
cursor?: string;
|
|
9
|
+
limit?: number;
|
|
10
|
+
} | undefined): Promise<{
|
|
11
|
+
results: any[];
|
|
12
|
+
total: number;
|
|
13
|
+
nextCursor: string | null;
|
|
14
|
+
prevCursor: string | null;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
declare type TinaCloudSearchIndexerClientOptions = {
|
|
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;
|
|
26
|
+
private readonly apiUrl;
|
|
27
|
+
private readonly branch;
|
|
28
|
+
private readonly indexerToken;
|
|
29
|
+
private readonly stopwordLanguages;
|
|
30
|
+
constructor(options: TinaCloudSearchIndexerClientOptions);
|
|
31
|
+
put(docs: any[]): Promise<void>;
|
|
32
|
+
del(ids: string[]): Promise<void>;
|
|
33
|
+
onStartIndexing(): Promise<void>;
|
|
34
|
+
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
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { SearchClient } from './types';
|
|
2
|
+
export declare const optionsToSearchIndexOptions: (options?: {
|
|
3
|
+
limit?: number;
|
|
4
|
+
cursor?: string;
|
|
5
|
+
}) => {};
|
|
6
|
+
export declare const parseSearchIndexResponse: (data: any, options?: {
|
|
7
|
+
limit?: number;
|
|
8
|
+
cursor?: string;
|
|
9
|
+
}) => {
|
|
10
|
+
results: any;
|
|
11
|
+
total: any;
|
|
12
|
+
prevCursor: any;
|
|
13
|
+
nextCursor: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const optionsToSearchIndexOptions = (options) => {
|
|
2
|
+
const opt = {};
|
|
3
|
+
if (options == null ? void 0 : options.limit) {
|
|
4
|
+
opt["PAGE"] = {
|
|
5
|
+
SIZE: options.limit,
|
|
6
|
+
NUMBER: (options == null ? void 0 : options.cursor) ? parseInt(options.cursor) : 0
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
return opt;
|
|
10
|
+
};
|
|
11
|
+
const parseSearchIndexResponse = (data, options) => {
|
|
12
|
+
const results = data["RESULT"];
|
|
13
|
+
const total = data["RESULT_LENGTH"];
|
|
14
|
+
if ((options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
|
|
15
|
+
const prevCursor = options.cursor === "0" ? null : (parseInt(options.cursor) - 1).toString();
|
|
16
|
+
const nextCursor = total <= (parseInt(options.cursor) + 1) * options.limit ? null : (parseInt(options.cursor) + 1).toString();
|
|
17
|
+
return {
|
|
18
|
+
results,
|
|
19
|
+
total,
|
|
20
|
+
prevCursor,
|
|
21
|
+
nextCursor
|
|
22
|
+
};
|
|
23
|
+
} else if (!(options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
|
|
24
|
+
const prevCursor = null;
|
|
25
|
+
const nextCursor = total <= options.limit ? null : "1";
|
|
26
|
+
return {
|
|
27
|
+
results,
|
|
28
|
+
total,
|
|
29
|
+
prevCursor,
|
|
30
|
+
nextCursor
|
|
31
|
+
};
|
|
32
|
+
} else {
|
|
33
|
+
return {
|
|
34
|
+
results,
|
|
35
|
+
total,
|
|
36
|
+
prevCursor: null,
|
|
37
|
+
nextCursor: null
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export { optionsToSearchIndexOptions, parseSearchIndexResponse };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@tinacms/search"] = {}));
|
|
3
|
+
})(this, function(exports2) {
|
|
4
|
+
"use strict";
|
|
5
|
+
const optionsToSearchIndexOptions = (options) => {
|
|
6
|
+
const opt = {};
|
|
7
|
+
if (options == null ? void 0 : options.limit) {
|
|
8
|
+
opt["PAGE"] = {
|
|
9
|
+
SIZE: options.limit,
|
|
10
|
+
NUMBER: (options == null ? void 0 : options.cursor) ? parseInt(options.cursor) : 0
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return opt;
|
|
14
|
+
};
|
|
15
|
+
const parseSearchIndexResponse = (data, options) => {
|
|
16
|
+
const results = data["RESULT"];
|
|
17
|
+
const total = data["RESULT_LENGTH"];
|
|
18
|
+
if ((options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
|
|
19
|
+
const prevCursor = options.cursor === "0" ? null : (parseInt(options.cursor) - 1).toString();
|
|
20
|
+
const nextCursor = total <= (parseInt(options.cursor) + 1) * options.limit ? null : (parseInt(options.cursor) + 1).toString();
|
|
21
|
+
return {
|
|
22
|
+
results,
|
|
23
|
+
total,
|
|
24
|
+
prevCursor,
|
|
25
|
+
nextCursor
|
|
26
|
+
};
|
|
27
|
+
} else if (!(options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
|
|
28
|
+
const prevCursor = null;
|
|
29
|
+
const nextCursor = total <= options.limit ? null : "1";
|
|
30
|
+
return {
|
|
31
|
+
results,
|
|
32
|
+
total,
|
|
33
|
+
prevCursor,
|
|
34
|
+
nextCursor
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
return {
|
|
38
|
+
results,
|
|
39
|
+
total,
|
|
40
|
+
prevCursor: null,
|
|
41
|
+
nextCursor: null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports2.optionsToSearchIndexOptions = optionsToSearchIndexOptions;
|
|
46
|
+
exports2.parseSearchIndexResponse = parseSearchIndexResponse;
|
|
47
|
+
Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
48
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { SearchIndexer } from './indexer';
|
|
2
|
+
export { LocalSearchIndexClient, TinaCMSSearchIndexClient } from './client';
|
|
3
|
+
export type { SearchClient } from './types';
|
|
4
|
+
export { default as sw } from 'stopword';
|
|
5
|
+
export declare const lookupStopwords: (keys?: string[], defaultStopWords?: string[]) => string[];
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/index.ts
|
|
26
|
+
var src_exports = {};
|
|
27
|
+
__export(src_exports, {
|
|
28
|
+
LocalSearchIndexClient: () => LocalSearchIndexClient,
|
|
29
|
+
SearchIndexer: () => SearchIndexer,
|
|
30
|
+
TinaCMSSearchIndexClient: () => TinaCMSSearchIndexClient,
|
|
31
|
+
lookupStopwords: () => lookupStopwords,
|
|
32
|
+
sw: () => import_stopword.default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var sw = __toESM(require("stopword"));
|
|
36
|
+
|
|
37
|
+
// src/indexer/index.ts
|
|
38
|
+
var import_graphql = require("@tinacms/graphql");
|
|
39
|
+
var SearchIndexer = class {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.client = options.client;
|
|
42
|
+
this.bridge = options.bridge;
|
|
43
|
+
this.schema = options.schema;
|
|
44
|
+
this.batchSize = options.batchSize || 100;
|
|
45
|
+
this.textIndexLength = options.textIndexLength || 500;
|
|
46
|
+
}
|
|
47
|
+
relativePath(path, collection) {
|
|
48
|
+
return path.replace(/\\/g, "/").replace(collection.path, "").replace(/^\/|\/$/g, "");
|
|
49
|
+
}
|
|
50
|
+
processDocumentForIndexing(data, path, collection, field) {
|
|
51
|
+
if (!field) {
|
|
52
|
+
data["_id"] = `${collection.name}:${this.relativePath(path, collection)}`;
|
|
53
|
+
}
|
|
54
|
+
for (const f of collection.fields || (field == null ? void 0 : field.fields) || []) {
|
|
55
|
+
const isList = f.list;
|
|
56
|
+
if (data[f.name]) {
|
|
57
|
+
if (f.type === "object") {
|
|
58
|
+
if (isList) {
|
|
59
|
+
data[f.name] = data[f.name].map(
|
|
60
|
+
(obj) => this.processDocumentForIndexing(obj, path, collection, f)
|
|
61
|
+
);
|
|
62
|
+
} else {
|
|
63
|
+
data[f.name] = this.processDocumentForIndexing(
|
|
64
|
+
data[f.name],
|
|
65
|
+
path,
|
|
66
|
+
collection,
|
|
67
|
+
f
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
} else if (f.type === "image") {
|
|
71
|
+
delete data[f.name];
|
|
72
|
+
} else if (f.type === "string" || f.type === "rich-text") {
|
|
73
|
+
if (isList) {
|
|
74
|
+
data[f.name] = data[f.name].map(
|
|
75
|
+
(value) => value.substring(0, this.textIndexLength)
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
data[f.name] = data[f.name].substring(0, this.textIndexLength);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
async indexContentByPaths(documentPaths) {
|
|
86
|
+
var _a, _b, _c, _d;
|
|
87
|
+
let batch = [];
|
|
88
|
+
await ((_b = (_a = this.client).onStartIndexing) == null ? void 0 : _b.call(_a));
|
|
89
|
+
await (0, import_graphql.scanContentByPaths)(
|
|
90
|
+
this.schema,
|
|
91
|
+
documentPaths,
|
|
92
|
+
async (collection, contentPaths) => {
|
|
93
|
+
await (0, import_graphql.sequential)(contentPaths, async (path) => {
|
|
94
|
+
const data = (0, import_graphql.transformDocument)(
|
|
95
|
+
path,
|
|
96
|
+
JSON.parse(await this.bridge.get(path)),
|
|
97
|
+
this.schema
|
|
98
|
+
);
|
|
99
|
+
batch.push(this.processDocumentForIndexing(data, path, collection));
|
|
100
|
+
if (batch.length > this.batchSize) {
|
|
101
|
+
await this.client.put(batch);
|
|
102
|
+
batch = [];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
if (batch.length > 0) {
|
|
108
|
+
await this.client.put(batch);
|
|
109
|
+
}
|
|
110
|
+
await ((_d = (_c = this.client).onFinishIndexing) == null ? void 0 : _d.call(_c));
|
|
111
|
+
}
|
|
112
|
+
async indexAllContent() {
|
|
113
|
+
var _a, _b, _c, _d;
|
|
114
|
+
await ((_b = (_a = this.client).onStartIndexing) == null ? void 0 : _b.call(_a));
|
|
115
|
+
let batch = [];
|
|
116
|
+
const warnings = await (0, import_graphql.scanAllContent)(
|
|
117
|
+
this.schema,
|
|
118
|
+
this.bridge,
|
|
119
|
+
async (collection, contentPaths) => {
|
|
120
|
+
const templateInfo = await this.schema.getTemplatesForCollectable(
|
|
121
|
+
collection
|
|
122
|
+
);
|
|
123
|
+
await (0, import_graphql.sequential)(contentPaths, async (path) => {
|
|
124
|
+
const data = (0, import_graphql.transformDocument)(
|
|
125
|
+
path,
|
|
126
|
+
await (0, import_graphql.loadAndParseWithAliases)(
|
|
127
|
+
this.bridge,
|
|
128
|
+
path,
|
|
129
|
+
collection,
|
|
130
|
+
templateInfo
|
|
131
|
+
),
|
|
132
|
+
this.schema
|
|
133
|
+
);
|
|
134
|
+
batch.push(this.processDocumentForIndexing(data, path, collection));
|
|
135
|
+
if (batch.length > this.batchSize) {
|
|
136
|
+
await this.client.put(batch);
|
|
137
|
+
batch = [];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
if (batch.length > 0) {
|
|
143
|
+
await this.client.put(batch);
|
|
144
|
+
}
|
|
145
|
+
await ((_d = (_c = this.client).onFinishIndexing) == null ? void 0 : _d.call(_c));
|
|
146
|
+
return { warnings };
|
|
147
|
+
}
|
|
148
|
+
async deleteIndexContent(documentPaths) {
|
|
149
|
+
var _a, _b, _c, _d;
|
|
150
|
+
await ((_b = (_a = this.client).onStartIndexing) == null ? void 0 : _b.call(_a));
|
|
151
|
+
await this.client.del(documentPaths);
|
|
152
|
+
await ((_d = (_c = this.client).onFinishIndexing) == null ? void 0 : _d.call(_c));
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/sqlite-level.ts
|
|
157
|
+
var import_abstract_level = require("abstract-level");
|
|
158
|
+
var import_module_error = __toESM(require("module-error"));
|
|
159
|
+
var import_better_sqlite3 = __toESM(require("better-sqlite3"));
|
|
160
|
+
var queryFromOptions = (options) => {
|
|
161
|
+
let query = "SELECT key, value FROM kv";
|
|
162
|
+
const params = [];
|
|
163
|
+
if (options.gt) {
|
|
164
|
+
query += ` WHERE key > ?`;
|
|
165
|
+
params.push(options.gt);
|
|
166
|
+
} else if (options.gte) {
|
|
167
|
+
query += ` WHERE key >= ?`;
|
|
168
|
+
params.push(options.gte);
|
|
169
|
+
}
|
|
170
|
+
if (options.lt) {
|
|
171
|
+
query += ` ${options.gt || options.gte ? "AND" : "WHERE"} key < ?`;
|
|
172
|
+
params.push(options.lt);
|
|
173
|
+
} else if (options.lte) {
|
|
174
|
+
query += ` ${options.gt || options.gte ? "AND" : "WHERE"} key <= ?`;
|
|
175
|
+
params.push(options.lte);
|
|
176
|
+
}
|
|
177
|
+
if (options.reverse) {
|
|
178
|
+
query += " ORDER BY key DESC";
|
|
179
|
+
} else {
|
|
180
|
+
query += " ORDER BY key ASC";
|
|
181
|
+
}
|
|
182
|
+
if (options.limit) {
|
|
183
|
+
query += ` LIMIT ${options.limit}`;
|
|
184
|
+
}
|
|
185
|
+
return { query, params };
|
|
186
|
+
};
|
|
187
|
+
var SqliteIterator = class extends import_abstract_level.AbstractIterator {
|
|
188
|
+
constructor(db, options, client) {
|
|
189
|
+
super(db, options);
|
|
190
|
+
this.client = client;
|
|
191
|
+
const { query, params } = queryFromOptions(options);
|
|
192
|
+
const stmt = this.client.prepare(query);
|
|
193
|
+
this.iterator = stmt.iterate(params);
|
|
194
|
+
}
|
|
195
|
+
async _next(callback) {
|
|
196
|
+
const result = this.iterator.next();
|
|
197
|
+
if (!result.done) {
|
|
198
|
+
return this.db.nextTick(
|
|
199
|
+
callback,
|
|
200
|
+
null,
|
|
201
|
+
result.value.key,
|
|
202
|
+
result.value.value
|
|
203
|
+
);
|
|
204
|
+
} else {
|
|
205
|
+
return this.db.nextTick(callback, null, void 0, void 0);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
var SqliteKeyIterator = class extends import_abstract_level.AbstractKeyIterator {
|
|
210
|
+
constructor(db, options, client) {
|
|
211
|
+
super(db, options);
|
|
212
|
+
this.client = client;
|
|
213
|
+
const { query, params } = queryFromOptions(options);
|
|
214
|
+
const stmt = this.client.prepare(query);
|
|
215
|
+
this.iterator = stmt.iterate(params);
|
|
216
|
+
}
|
|
217
|
+
async _next(callback) {
|
|
218
|
+
const result = this.iterator.next();
|
|
219
|
+
if (!result.done) {
|
|
220
|
+
return this.db.nextTick(callback, null, result.value.key);
|
|
221
|
+
} else {
|
|
222
|
+
return this.db.nextTick(callback, null, void 0);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var SqliteValueIterator = class extends import_abstract_level.AbstractValueIterator {
|
|
227
|
+
constructor(db, options, client) {
|
|
228
|
+
super(db, options);
|
|
229
|
+
this.client = client;
|
|
230
|
+
const { query, params } = queryFromOptions(options);
|
|
231
|
+
const stmt = this.client.prepare(query);
|
|
232
|
+
this.iterator = stmt.iterate(params);
|
|
233
|
+
}
|
|
234
|
+
async _next(callback) {
|
|
235
|
+
const result = this.iterator.next();
|
|
236
|
+
if (!result.done) {
|
|
237
|
+
return this.db.nextTick(callback, null, result.value.value);
|
|
238
|
+
} else {
|
|
239
|
+
return this.db.nextTick(callback, null, void 0);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var SqliteLevel = class extends import_abstract_level.AbstractLevel {
|
|
244
|
+
constructor(options) {
|
|
245
|
+
super({ encodings: { utf8: true } }, options);
|
|
246
|
+
this.readOnly = false;
|
|
247
|
+
this.db = new import_better_sqlite3.default(options.filename);
|
|
248
|
+
this.db.pragma("journal_mode = WAL");
|
|
249
|
+
if (options.readOnly !== void 0) {
|
|
250
|
+
this.readOnly = options.readOnly;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
get type() {
|
|
254
|
+
return "sqlite3";
|
|
255
|
+
}
|
|
256
|
+
async _open(options, callback) {
|
|
257
|
+
this.db.exec("CREATE TABLE IF NOT EXISTS kv (key TEXT, value TEXT)");
|
|
258
|
+
this.nextTick(callback);
|
|
259
|
+
}
|
|
260
|
+
async _close(callback) {
|
|
261
|
+
this.db.close();
|
|
262
|
+
this.nextTick(callback);
|
|
263
|
+
}
|
|
264
|
+
async _get(key, options, callback) {
|
|
265
|
+
const stmt = this.db.prepare("SELECT value FROM kv WHERE key = ?");
|
|
266
|
+
const row = stmt.get(key.toString());
|
|
267
|
+
if (row) {
|
|
268
|
+
return this.nextTick(callback, null, row.value);
|
|
269
|
+
} else {
|
|
270
|
+
return this.nextTick(
|
|
271
|
+
callback,
|
|
272
|
+
new import_module_error.default(`Key ${key} was not found`, {
|
|
273
|
+
code: "LEVEL_NOT_FOUND"
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
async _put(key, value, options, callback) {
|
|
279
|
+
if (this.readOnly) {
|
|
280
|
+
return this.nextTick(
|
|
281
|
+
callback,
|
|
282
|
+
new import_module_error.default("not authorized to write to branch", {
|
|
283
|
+
code: "LEVEL_READ_ONLY"
|
|
284
|
+
})
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const stmt = this.db.prepare("INSERT INTO kv (key, value) VALUES (?, ?)");
|
|
288
|
+
stmt.run(key.toString(), value.toString());
|
|
289
|
+
this.nextTick(callback);
|
|
290
|
+
}
|
|
291
|
+
async _del(key, options, callback) {
|
|
292
|
+
if (this.readOnly) {
|
|
293
|
+
return this.nextTick(
|
|
294
|
+
callback,
|
|
295
|
+
new import_module_error.default("not authorized to write to branch", {
|
|
296
|
+
code: "LEVEL_READ_ONLY"
|
|
297
|
+
})
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
const stmt = this.db.prepare("DELETE FROM kv WHERE key = ?");
|
|
301
|
+
stmt.run(key.toString());
|
|
302
|
+
this.nextTick(callback);
|
|
303
|
+
}
|
|
304
|
+
async _batch(batch, options, callback) {
|
|
305
|
+
if (this.readOnly) {
|
|
306
|
+
return this.nextTick(
|
|
307
|
+
callback,
|
|
308
|
+
new import_module_error.default("not authorized to write to branch", {
|
|
309
|
+
code: "LEVEL_READ_ONLY"
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
let batches = [];
|
|
314
|
+
let curBatch = [];
|
|
315
|
+
let curType = void 0;
|
|
316
|
+
for (const op of batch) {
|
|
317
|
+
if (curType === void 0) {
|
|
318
|
+
curType = op.type;
|
|
319
|
+
} else if (curType !== op.type) {
|
|
320
|
+
if (curType === "put") {
|
|
321
|
+
batches.push(
|
|
322
|
+
`INSERT INTO kv (key, value) VALUES ${curBatch.join(",")}`
|
|
323
|
+
);
|
|
324
|
+
} else if (curType === "del") {
|
|
325
|
+
batches.push(`DELETE FROM kv WHERE key IN (${curBatch.join(",")})`);
|
|
326
|
+
}
|
|
327
|
+
curBatch = [];
|
|
328
|
+
curType = op.type;
|
|
329
|
+
}
|
|
330
|
+
if (op.type === "put") {
|
|
331
|
+
curBatch.push(`('${op.key.toString()}', '${op.value.toString()}')`);
|
|
332
|
+
} else if (op.type === "del") {
|
|
333
|
+
curBatch.push(`'${op.key.toString()}'`);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (curBatch.length > 0) {
|
|
337
|
+
if (curType === "put") {
|
|
338
|
+
batches.push(`INSERT INTO kv (key, value) VALUES ${curBatch.join(",")}`);
|
|
339
|
+
} else if (curType === "del") {
|
|
340
|
+
batches.push(`DELETE FROM kv WHERE key IN (${curBatch.join(",")})`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
for (const batch2 of batches) {
|
|
344
|
+
this.db.exec(batch2);
|
|
345
|
+
}
|
|
346
|
+
this.nextTick(callback);
|
|
347
|
+
}
|
|
348
|
+
async _clear(options, callback) {
|
|
349
|
+
this.db.exec(`DELETE FROM kv WHERE key like '${options.gte}%'`);
|
|
350
|
+
this.nextTick(callback);
|
|
351
|
+
}
|
|
352
|
+
_iterator(options) {
|
|
353
|
+
return new SqliteIterator(this, options, this.db);
|
|
354
|
+
}
|
|
355
|
+
_keys(options) {
|
|
356
|
+
return new SqliteKeyIterator(this, options, this.db);
|
|
357
|
+
}
|
|
358
|
+
_values(options) {
|
|
359
|
+
return new SqliteValueIterator(this, options, this.db);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// src/client/index.ts
|
|
364
|
+
var zlib = __toESM(require("zlib"));
|
|
365
|
+
var import_search_index = __toESM(require("@kldavis4/search-index"));
|
|
366
|
+
var import_memory_level = require("memory-level");
|
|
367
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
368
|
+
var LocalSearchIndexClient = class {
|
|
369
|
+
constructor(searchIndex) {
|
|
370
|
+
this.searchIndex = searchIndex;
|
|
371
|
+
}
|
|
372
|
+
async put(docs) {
|
|
373
|
+
return this.searchIndex.PUT(docs);
|
|
374
|
+
}
|
|
375
|
+
async del(ids) {
|
|
376
|
+
return this.searchIndex.DELETE(ids);
|
|
377
|
+
}
|
|
378
|
+
query(query, options) {
|
|
379
|
+
return Promise.resolve({
|
|
380
|
+
nextCursor: void 0,
|
|
381
|
+
prevCursor: void 0,
|
|
382
|
+
results: [],
|
|
383
|
+
total: 0
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
var TinaCMSSearchIndexClient = class {
|
|
388
|
+
constructor(options) {
|
|
389
|
+
this.apiUrl = options.apiUrl;
|
|
390
|
+
this.branch = options.branch;
|
|
391
|
+
this.indexerToken = options.indexerToken;
|
|
392
|
+
this.stopwordLanguages = options.stopwordLanguages;
|
|
393
|
+
}
|
|
394
|
+
async put(docs) {
|
|
395
|
+
if (this.searchIndex) {
|
|
396
|
+
await this.searchIndex.PUT(docs);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
async del(ids) {
|
|
400
|
+
if (this.searchIndex) {
|
|
401
|
+
await this.searchIndex.DELETE(ids);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async onStartIndexing() {
|
|
405
|
+
this.memoryLevel = new import_memory_level.MemoryLevel();
|
|
406
|
+
this.searchIndex = await (0, import_search_index.default)({
|
|
407
|
+
db: this.memoryLevel,
|
|
408
|
+
stopwords: lookupStopwords(this.stopwordLanguages)
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
async onFinishIndexing() {
|
|
412
|
+
const headers = new import_node_fetch.Headers();
|
|
413
|
+
headers.append("x-api-key", this.indexerToken || "bogus");
|
|
414
|
+
headers.append("Content-Type", "application/json");
|
|
415
|
+
const res = await (0, import_node_fetch.default)(`${this.apiUrl}/upload/${this.branch}`, {
|
|
416
|
+
method: "GET",
|
|
417
|
+
headers
|
|
418
|
+
});
|
|
419
|
+
const { signedUrl } = await res.json();
|
|
420
|
+
console.log("onFinishIndexing");
|
|
421
|
+
const sqliteLevel = new SqliteLevel({ filename: ":memory:" });
|
|
422
|
+
console.log("dumping to sqlite");
|
|
423
|
+
const iterator = this.memoryLevel.iterator();
|
|
424
|
+
for await (const [key, value] of iterator) {
|
|
425
|
+
await sqliteLevel.put(key, value);
|
|
426
|
+
}
|
|
427
|
+
const buffer = sqliteLevel.db.serialize();
|
|
428
|
+
console.log(buffer.byteLength);
|
|
429
|
+
await sqliteLevel.close();
|
|
430
|
+
await (0, import_node_fetch.default)(signedUrl, {
|
|
431
|
+
method: "PUT",
|
|
432
|
+
body: zlib.gzipSync(buffer)
|
|
433
|
+
});
|
|
434
|
+
console.log("done onFinishIndexing");
|
|
435
|
+
}
|
|
436
|
+
getSearchIndex() {
|
|
437
|
+
return this.searchIndex;
|
|
438
|
+
}
|
|
439
|
+
query(query, options) {
|
|
440
|
+
return Promise.resolve({
|
|
441
|
+
nextCursor: void 0,
|
|
442
|
+
prevCursor: void 0,
|
|
443
|
+
results: [],
|
|
444
|
+
total: 0
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// src/index.ts
|
|
450
|
+
var import_stopword = __toESM(require("stopword"));
|
|
451
|
+
var lookupStopwords = (keys, defaultStopWords = sw.eng) => {
|
|
452
|
+
let stopwords = defaultStopWords;
|
|
453
|
+
if (keys) {
|
|
454
|
+
stopwords = [];
|
|
455
|
+
for (const key of keys) {
|
|
456
|
+
stopwords.push(...sw[key]);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return stopwords;
|
|
460
|
+
};
|
|
461
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
462
|
+
0 && (module.exports = {
|
|
463
|
+
LocalSearchIndexClient,
|
|
464
|
+
SearchIndexer,
|
|
465
|
+
TinaCMSSearchIndexClient,
|
|
466
|
+
lookupStopwords,
|
|
467
|
+
sw
|
|
468
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TinaSchema } from '@tinacms/schema-tools';
|
|
2
|
+
import { Bridge } from '@tinacms/graphql';
|
|
3
|
+
import { SearchClient } from '../types';
|
|
4
|
+
declare type SearchIndexOptions = {
|
|
5
|
+
batchSize?: number;
|
|
6
|
+
bridge: Bridge;
|
|
7
|
+
client: SearchClient;
|
|
8
|
+
schema: TinaSchema;
|
|
9
|
+
textIndexLength?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare class SearchIndexer {
|
|
12
|
+
private readonly batchSize;
|
|
13
|
+
private readonly client;
|
|
14
|
+
private readonly bridge;
|
|
15
|
+
private readonly schema;
|
|
16
|
+
private readonly textIndexLength;
|
|
17
|
+
constructor(options: SearchIndexOptions);
|
|
18
|
+
private relativePath;
|
|
19
|
+
private processDocumentForIndexing;
|
|
20
|
+
indexContentByPaths(documentPaths: string[]): Promise<void>;
|
|
21
|
+
indexAllContent(): Promise<{
|
|
22
|
+
warnings: string[];
|
|
23
|
+
}>;
|
|
24
|
+
deleteIndexContent(documentPaths: string[]): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
Copyright 2023 Forestry.io Holdings, Inc.
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
See the License for the specific language governing permissions and
|
|
12
|
+
limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
import { AbstractDatabaseOptions, AbstractIterator, AbstractKeyIterator, AbstractLevel, AbstractOpenOptions, AbstractValueIterator } from 'abstract-level';
|
|
15
|
+
import { NextCallback } from 'abstract-level/types/abstract-iterator';
|
|
16
|
+
export declare type SqliteLevelOptions<K, V> = {
|
|
17
|
+
filename: string;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
} & AbstractDatabaseOptions<K, V>;
|
|
20
|
+
declare type BatchOperation = BatchPutOperation | BatchDelOperation;
|
|
21
|
+
/**
|
|
22
|
+
* A _put_ operation to be committed by a {@link SqliteLevel}.
|
|
23
|
+
*/
|
|
24
|
+
declare interface BatchPutOperation {
|
|
25
|
+
/**
|
|
26
|
+
* Type of operation.
|
|
27
|
+
*/
|
|
28
|
+
type: 'put';
|
|
29
|
+
/**
|
|
30
|
+
* Key of the entry to be added to the database.
|
|
31
|
+
*/
|
|
32
|
+
key: Buffer;
|
|
33
|
+
/**
|
|
34
|
+
* Value of the entry to be added to the database.
|
|
35
|
+
*/
|
|
36
|
+
value: Buffer;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A _del_ operation to be committed by a {@link SqliteLevel}.
|
|
40
|
+
*/
|
|
41
|
+
declare interface BatchDelOperation {
|
|
42
|
+
/**
|
|
43
|
+
* Type of operation.
|
|
44
|
+
*/
|
|
45
|
+
type: 'del';
|
|
46
|
+
/**
|
|
47
|
+
* Key of the entry to be deleted from the database.
|
|
48
|
+
*/
|
|
49
|
+
key: Buffer;
|
|
50
|
+
}
|
|
51
|
+
declare interface IteratorOptions<KDefault> {
|
|
52
|
+
limit?: number;
|
|
53
|
+
keyEncoding: string;
|
|
54
|
+
valueEncoding: string;
|
|
55
|
+
reverse: boolean;
|
|
56
|
+
keys: boolean;
|
|
57
|
+
values: boolean;
|
|
58
|
+
gt?: KDefault;
|
|
59
|
+
gte?: KDefault;
|
|
60
|
+
lt?: KDefault;
|
|
61
|
+
lte?: KDefault;
|
|
62
|
+
}
|
|
63
|
+
declare class SqliteIterator<KDefault, VDefault> extends AbstractIterator<SqliteLevel<KDefault, VDefault>, KDefault, VDefault> {
|
|
64
|
+
private client;
|
|
65
|
+
private iterator;
|
|
66
|
+
constructor(db: SqliteLevel<KDefault, VDefault>, options: IteratorOptions<KDefault>, client: any);
|
|
67
|
+
_next(callback: NextCallback<KDefault, VDefault>): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
declare class SqliteKeyIterator<KDefault, VDefault> extends AbstractKeyIterator<SqliteLevel<KDefault, VDefault>, KDefault> {
|
|
70
|
+
private client;
|
|
71
|
+
private iterator;
|
|
72
|
+
constructor(db: SqliteLevel<KDefault, VDefault>, options: IteratorOptions<KDefault>, client: any);
|
|
73
|
+
_next(callback: NextCallback<KDefault, VDefault>): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
declare class SqliteValueIterator<KDefault, VDefault> extends AbstractValueIterator<SqliteLevel<KDefault, VDefault>, KDefault, VDefault> {
|
|
76
|
+
private client;
|
|
77
|
+
private iterator;
|
|
78
|
+
constructor(db: SqliteLevel<KDefault, VDefault>, options: IteratorOptions<KDefault>, client: any);
|
|
79
|
+
_next(callback: NextCallback<KDefault, VDefault>): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
export declare class SqliteLevel<KDefault = string, VDefault = string> extends AbstractLevel<Buffer | Uint8Array | string, KDefault, VDefault> {
|
|
82
|
+
db: any;
|
|
83
|
+
private readOnly;
|
|
84
|
+
constructor(options: SqliteLevelOptions<KDefault, VDefault>);
|
|
85
|
+
get type(): string;
|
|
86
|
+
_open(options: AbstractOpenOptions, callback: (error?: Error) => void): Promise<void>;
|
|
87
|
+
_close(callback: (error?: Error) => void): Promise<void>;
|
|
88
|
+
_get(key: Buffer, options: any, callback: (error?: Error, value?: Buffer) => void): Promise<void>;
|
|
89
|
+
_put(key: Buffer, value: Buffer, options: any, callback: (error?: Error) => void): Promise<void>;
|
|
90
|
+
_del(key: Buffer, options: any, callback: (error?: Error) => void): Promise<void>;
|
|
91
|
+
_batch(batch: BatchOperation[], options: any, callback: (error?: Error) => void): Promise<void>;
|
|
92
|
+
_clear(options: any, callback: (error?: Error) => void): Promise<void>;
|
|
93
|
+
_iterator(options: IteratorOptions<KDefault>): SqliteIterator<KDefault, VDefault>;
|
|
94
|
+
_keys(options: IteratorOptions<KDefault>): SqliteKeyIterator<KDefault, VDefault>;
|
|
95
|
+
_values(options: IteratorOptions<KDefault>): SqliteValueIterator<KDefault, VDefault>;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare type SearchClient = {
|
|
2
|
+
query: (query: string, options?: {
|
|
3
|
+
cursor?: string;
|
|
4
|
+
limit?: number;
|
|
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>;
|
|
13
|
+
onStartIndexing?: () => Promise<void>;
|
|
14
|
+
onFinishIndexing?: () => Promise<void>;
|
|
15
|
+
supportsClientSideIndexing?: () => boolean;
|
|
16
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tinacms/search",
|
|
3
|
+
"version": "0.0.0-20230523214734",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index-client.es.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"package.json",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
"import": "./dist/index-client.es.js",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
16
|
+
"buildConfig": {
|
|
17
|
+
"entryPoints": [
|
|
18
|
+
{
|
|
19
|
+
"name": "src/index.ts",
|
|
20
|
+
"target": "node"
|
|
21
|
+
},
|
|
22
|
+
"src/index-client.ts"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@tinacms/graphql": "0.0.0-20230523214734",
|
|
27
|
+
"@tinacms/schema-tools": "0.0.0-20230523214734",
|
|
28
|
+
"abstract-level": "^1.0.3",
|
|
29
|
+
"better-sqlite3": "^7.4.2",
|
|
30
|
+
"classic-level": "^1.3.0",
|
|
31
|
+
"memory-level": "^1.0.0",
|
|
32
|
+
"module-error": "^1.0.2",
|
|
33
|
+
"node-fetch": "2",
|
|
34
|
+
"@kldavis4/search-index": "4.4.1",
|
|
35
|
+
"stopword": "^2.0.8"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"registry": "https://registry.npmjs.org"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"url": "https://github.com/tinacms/tinacms.git",
|
|
42
|
+
"directory": "packages/@tinacms/search"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@tinacms/scripts": "1.1.0",
|
|
46
|
+
"@types/jest": "^26.0.4",
|
|
47
|
+
"@types/micromatch": "^4.0.2",
|
|
48
|
+
"@types/search-index": "^3.2.0",
|
|
49
|
+
"jest": "27.0.6",
|
|
50
|
+
"jest-diff": "27.0.6",
|
|
51
|
+
"jest-file-snapshot": "^0.5.0",
|
|
52
|
+
"jest-matcher-utils": "27.0.6",
|
|
53
|
+
"typescript": "4.3.5"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"types": "pnpm tsc",
|
|
57
|
+
"build": "tinacms-scripts build",
|
|
58
|
+
"docs": "yarn typedoc",
|
|
59
|
+
"serve": "yarn nodemon dist/server.js",
|
|
60
|
+
"test": "jest",
|
|
61
|
+
"test-watch": "jest --watch"
|
|
62
|
+
}
|
|
63
|
+
}
|