1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ScopeSearchIndexManager = void 0;
|
4 | const utilities_1 = require("./utilities");
|
5 | const bindingutilities_1 = require("./bindingutilities");
|
6 | const searchindexmanager_1 = require("./searchindexmanager");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class ScopeSearchIndexManager {
|
14 | |
15 |
|
16 |
|
17 | constructor(cluster, bucketName, scopeName) {
|
18 | this._cluster = cluster;
|
19 | this._bucketName = bucketName;
|
20 | this._scopeName = scopeName;
|
21 | }
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | async getIndex(indexName, options, callback) {
|
30 | if (options instanceof Function) {
|
31 | callback = arguments[1];
|
32 | options = undefined;
|
33 | }
|
34 | if (!options) {
|
35 | options = {};
|
36 | }
|
37 | const timeout = options.timeout || this._cluster.managementTimeout;
|
38 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
39 | this._cluster.conn.managementSearchIndexGet({
|
40 | index_name: indexName,
|
41 | timeout: timeout,
|
42 | bucket_name: this._bucketName,
|
43 | scope_name: this._scopeName,
|
44 | }, (cppErr, resp) => {
|
45 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
46 | if (err) {
|
47 | return wrapCallback(err, null);
|
48 | }
|
49 | const index = searchindexmanager_1.SearchIndex._fromCppData(resp.index);
|
50 | wrapCallback(null, index);
|
51 | });
|
52 | }, callback);
|
53 | }
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | async getAllIndexes(options, callback) {
|
61 | if (options instanceof Function) {
|
62 | callback = arguments[0];
|
63 | options = undefined;
|
64 | }
|
65 | if (!options) {
|
66 | options = {};
|
67 | }
|
68 | const timeout = options.timeout || this._cluster.managementTimeout;
|
69 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
70 | this._cluster.conn.managementSearchIndexGetAll({
|
71 | timeout: timeout,
|
72 | bucket_name: this._bucketName,
|
73 | scope_name: this._scopeName,
|
74 | }, (cppErr, resp) => {
|
75 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
76 | if (err) {
|
77 | return wrapCallback(err, null);
|
78 | }
|
79 | const indexes = resp.indexes.map((indexData) => searchindexmanager_1.SearchIndex._fromCppData(indexData));
|
80 | wrapCallback(null, indexes);
|
81 | });
|
82 | }, callback);
|
83 | }
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | async upsertIndex(indexDefinition, options, callback) {
|
92 | if (options instanceof Function) {
|
93 | callback = arguments[1];
|
94 | options = undefined;
|
95 | }
|
96 | if (!options) {
|
97 | options = {};
|
98 | }
|
99 | const timeout = options.timeout || this._cluster.managementTimeout;
|
100 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
101 | this._cluster.conn.managementSearchIndexUpsert({
|
102 | index: searchindexmanager_1.SearchIndex._toCppData(indexDefinition),
|
103 | timeout: timeout,
|
104 | bucket_name: this._bucketName,
|
105 | scope_name: this._scopeName,
|
106 | }, (cppErr) => {
|
107 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
108 | if (err) {
|
109 | return wrapCallback(err, null);
|
110 | }
|
111 | wrapCallback(err);
|
112 | });
|
113 | }, callback);
|
114 | }
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | async dropIndex(indexName, options, callback) {
|
123 | if (options instanceof Function) {
|
124 | callback = arguments[1];
|
125 | options = undefined;
|
126 | }
|
127 | if (!options) {
|
128 | options = {};
|
129 | }
|
130 | const timeout = options.timeout || this._cluster.managementTimeout;
|
131 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
132 | this._cluster.conn.managementSearchIndexDrop({
|
133 | index_name: indexName,
|
134 | timeout: timeout,
|
135 | bucket_name: this._bucketName,
|
136 | scope_name: this._scopeName,
|
137 | }, (cppErr) => {
|
138 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
139 | if (err) {
|
140 | return wrapCallback(err, null);
|
141 | }
|
142 | wrapCallback(err);
|
143 | });
|
144 | }, callback);
|
145 | }
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | async getIndexedDocumentsCount(indexName, options, callback) {
|
154 | if (options instanceof Function) {
|
155 | callback = arguments[1];
|
156 | options = undefined;
|
157 | }
|
158 | if (!options) {
|
159 | options = {};
|
160 | }
|
161 | const timeout = options.timeout || this._cluster.managementTimeout;
|
162 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
163 | this._cluster.conn.managementSearchIndexGetDocumentsCount({
|
164 | index_name: indexName,
|
165 | timeout: timeout,
|
166 | bucket_name: this._bucketName,
|
167 | scope_name: this._scopeName,
|
168 | }, (cppErr, resp) => {
|
169 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
170 | if (err) {
|
171 | return wrapCallback(err, null);
|
172 | }
|
173 | wrapCallback(null, resp.count);
|
174 | });
|
175 | }, callback);
|
176 | }
|
177 | |
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | async pauseIngest(indexName, options, callback) {
|
185 | if (options instanceof Function) {
|
186 | callback = arguments[1];
|
187 | options = undefined;
|
188 | }
|
189 | if (!options) {
|
190 | options = {};
|
191 | }
|
192 | const timeout = options.timeout || this._cluster.managementTimeout;
|
193 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
194 | this._cluster.conn.managementSearchIndexControlIngest({
|
195 | index_name: indexName,
|
196 | pause: true,
|
197 | timeout: timeout,
|
198 | bucket_name: this._bucketName,
|
199 | scope_name: this._scopeName,
|
200 | }, (cppErr) => {
|
201 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
202 | if (err) {
|
203 | return wrapCallback(err, null);
|
204 | }
|
205 | wrapCallback(err);
|
206 | });
|
207 | }, callback);
|
208 | }
|
209 | |
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | async resumeIngest(indexName, options, callback) {
|
217 | if (options instanceof Function) {
|
218 | callback = arguments[1];
|
219 | options = undefined;
|
220 | }
|
221 | if (!options) {
|
222 | options = {};
|
223 | }
|
224 | const timeout = options.timeout || this._cluster.managementTimeout;
|
225 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
226 | this._cluster.conn.managementSearchIndexControlIngest({
|
227 | index_name: indexName,
|
228 | pause: false,
|
229 | timeout: timeout,
|
230 | bucket_name: this._bucketName,
|
231 | scope_name: this._scopeName,
|
232 | }, (cppErr) => {
|
233 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
234 | if (err) {
|
235 | return wrapCallback(err, null);
|
236 | }
|
237 | wrapCallback(err);
|
238 | });
|
239 | }, callback);
|
240 | }
|
241 | |
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | async allowQuerying(indexName, options, callback) {
|
249 | if (options instanceof Function) {
|
250 | callback = arguments[1];
|
251 | options = undefined;
|
252 | }
|
253 | if (!options) {
|
254 | options = {};
|
255 | }
|
256 | const timeout = options.timeout || this._cluster.managementTimeout;
|
257 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
258 | this._cluster.conn.managementSearchIndexControlQuery({
|
259 | index_name: indexName,
|
260 | allow: true,
|
261 | timeout: timeout,
|
262 | bucket_name: this._bucketName,
|
263 | scope_name: this._scopeName,
|
264 | }, (cppErr) => {
|
265 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
266 | if (err) {
|
267 | return wrapCallback(err, null);
|
268 | }
|
269 | wrapCallback(err);
|
270 | });
|
271 | }, callback);
|
272 | }
|
273 | |
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | async disallowQuerying(indexName, options, callback) {
|
281 | if (options instanceof Function) {
|
282 | callback = arguments[1];
|
283 | options = undefined;
|
284 | }
|
285 | if (!options) {
|
286 | options = {};
|
287 | }
|
288 | const timeout = options.timeout || this._cluster.managementTimeout;
|
289 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
290 | this._cluster.conn.managementSearchIndexControlQuery({
|
291 | index_name: indexName,
|
292 | allow: false,
|
293 | timeout: timeout,
|
294 | bucket_name: this._bucketName,
|
295 | scope_name: this._scopeName,
|
296 | }, (cppErr) => {
|
297 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
298 | if (err) {
|
299 | return wrapCallback(err, null);
|
300 | }
|
301 | wrapCallback(err);
|
302 | });
|
303 | }, callback);
|
304 | }
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 | async freezePlan(indexName, options, callback) {
|
313 | if (options instanceof Function) {
|
314 | callback = arguments[1];
|
315 | options = undefined;
|
316 | }
|
317 | if (!options) {
|
318 | options = {};
|
319 | }
|
320 | const timeout = options.timeout || this._cluster.managementTimeout;
|
321 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
322 | this._cluster.conn.managementSearchIndexControlPlanFreeze({
|
323 | index_name: indexName,
|
324 | freeze: true,
|
325 | timeout: timeout,
|
326 | bucket_name: this._bucketName,
|
327 | scope_name: this._scopeName,
|
328 | }, (cppErr) => {
|
329 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
330 | if (err) {
|
331 | return wrapCallback(err, null);
|
332 | }
|
333 | wrapCallback(err);
|
334 | });
|
335 | }, callback);
|
336 | }
|
337 | |
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 | async unfreezePlan(indexName, options, callback) {
|
345 | if (options instanceof Function) {
|
346 | callback = arguments[1];
|
347 | options = undefined;
|
348 | }
|
349 | if (!options) {
|
350 | options = {};
|
351 | }
|
352 | const timeout = options.timeout || this._cluster.managementTimeout;
|
353 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
354 | this._cluster.conn.managementSearchIndexControlPlanFreeze({
|
355 | index_name: indexName,
|
356 | freeze: false,
|
357 | timeout: timeout,
|
358 | bucket_name: this._bucketName,
|
359 | scope_name: this._scopeName,
|
360 | }, (cppErr) => {
|
361 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
362 | if (err) {
|
363 | return wrapCallback(err, null);
|
364 | }
|
365 | wrapCallback(err);
|
366 | });
|
367 | }, callback);
|
368 | }
|
369 | |
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 | async analyzeDocument(indexName, document, options, callback) {
|
378 | if (options instanceof Function) {
|
379 | callback = arguments[2];
|
380 | options = undefined;
|
381 | }
|
382 | if (!options) {
|
383 | options = {};
|
384 | }
|
385 | const timeout = options.timeout || this._cluster.managementTimeout;
|
386 | return utilities_1.PromiseHelper.wrap((wrapCallback) => {
|
387 | this._cluster.conn.managementSearchIndexAnalyzeDocument({
|
388 | index_name: indexName,
|
389 | encoded_document: JSON.stringify(document),
|
390 | timeout: timeout,
|
391 | bucket_name: this._bucketName,
|
392 | scope_name: this._scopeName,
|
393 | }, (cppErr, resp) => {
|
394 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
395 | if (err) {
|
396 | return wrapCallback(err, null);
|
397 | }
|
398 | const result = JSON.parse(resp.analysis);
|
399 | wrapCallback(result, null);
|
400 | });
|
401 | }, callback);
|
402 | }
|
403 | }
|
404 | exports.ScopeSearchIndexManager = ScopeSearchIndexManager;
|