@algolia/client-search 5.56.0 → 5.57.0
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 +4 -4
- package/dist/browser.d.ts +4 -2
- package/dist/builds/browser.js +49 -21
- package/dist/builds/browser.js.map +1 -1
- package/dist/builds/browser.min.js +5 -5
- package/dist/builds/browser.min.js.map +1 -1
- package/dist/builds/browser.umd.js +7 -7
- package/dist/builds/fetch.js +102 -60
- package/dist/builds/fetch.js.map +1 -1
- package/dist/builds/node.cjs +97 -58
- package/dist/builds/node.cjs.map +1 -1
- package/dist/builds/node.js +102 -60
- package/dist/builds/node.js.map +1 -1
- package/dist/builds/worker.js +49 -21
- package/dist/builds/worker.js.map +1 -1
- package/dist/fetch.d.ts +4 -2
- package/dist/node.d.cts +4 -2
- package/dist/node.d.ts +4 -2
- package/dist/src/searchClient.cjs +45 -20
- package/dist/src/searchClient.cjs.map +1 -1
- package/dist/src/searchClient.js +53 -23
- package/dist/src/searchClient.js.map +1 -1
- package/dist/worker.d.ts +4 -2
- package/package.json +9 -9
package/dist/builds/node.cjs
CHANGED
|
@@ -31,7 +31,7 @@ var import_requester_node_http = require("@algolia/requester-node-http");
|
|
|
31
31
|
|
|
32
32
|
// src/searchClient.ts
|
|
33
33
|
var import_client_common = require("@algolia/client-common");
|
|
34
|
-
var apiClientVersion = "5.
|
|
34
|
+
var apiClientVersion = "5.57.0";
|
|
35
35
|
function getDefaultHosts(appId) {
|
|
36
36
|
return [
|
|
37
37
|
{
|
|
@@ -151,6 +151,7 @@ function createSearchClient({
|
|
|
151
151
|
maxRetries = 100,
|
|
152
152
|
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
|
|
153
153
|
}, requestOptions) {
|
|
154
|
+
requestOptions = (0, import_client_common.withRequestId)(transporter, requestOptions);
|
|
154
155
|
let retryCount = 0;
|
|
155
156
|
return (0, import_client_common.createIterablePromise)({
|
|
156
157
|
func: () => this.getTask({ indexName, taskID }, requestOptions),
|
|
@@ -178,6 +179,7 @@ function createSearchClient({
|
|
|
178
179
|
maxRetries = 100,
|
|
179
180
|
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
|
|
180
181
|
}, requestOptions) {
|
|
182
|
+
requestOptions = (0, import_client_common.withRequestId)(transporter, requestOptions);
|
|
181
183
|
let retryCount = 0;
|
|
182
184
|
return (0, import_client_common.createIterablePromise)({
|
|
183
185
|
func: () => this.getAppTask({ taskID }, requestOptions),
|
|
@@ -209,6 +211,7 @@ function createSearchClient({
|
|
|
209
211
|
maxRetries = 100,
|
|
210
212
|
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
|
|
211
213
|
}, requestOptions) {
|
|
214
|
+
requestOptions = (0, import_client_common.withRequestId)(transporter, requestOptions);
|
|
212
215
|
let retryCount = 0;
|
|
213
216
|
const baseIteratorOptions = {
|
|
214
217
|
aggregator: () => retryCount += 1,
|
|
@@ -264,6 +267,7 @@ function createSearchClient({
|
|
|
264
267
|
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
|
|
265
268
|
*/
|
|
266
269
|
browseObjects({ indexName, browseParams, ...browseObjectsOptions }, requestOptions) {
|
|
270
|
+
requestOptions = (0, import_client_common.withRequestId)(transporter, requestOptions);
|
|
267
271
|
return (0, import_client_common.createIterablePromise)({
|
|
268
272
|
func: (previousResponse) => {
|
|
269
273
|
return this.browse(
|
|
@@ -294,6 +298,7 @@ function createSearchClient({
|
|
|
294
298
|
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
|
|
295
299
|
*/
|
|
296
300
|
browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
|
|
301
|
+
requestOptions = (0, import_client_common.withRequestId)(transporter, requestOptions);
|
|
297
302
|
const params = {
|
|
298
303
|
...searchRulesParams,
|
|
299
304
|
hitsPerPage: (searchRulesParams == null ? void 0 : searchRulesParams.hitsPerPage) || 1e3
|
|
@@ -331,6 +336,7 @@ function createSearchClient({
|
|
|
331
336
|
searchSynonymsParams,
|
|
332
337
|
...browseSynonymsOptions
|
|
333
338
|
}, requestOptions) {
|
|
339
|
+
requestOptions = (0, import_client_common.withRequestId)(transporter, requestOptions);
|
|
334
340
|
const params = {
|
|
335
341
|
...searchSynonymsParams,
|
|
336
342
|
page: (searchSynonymsParams == null ? void 0 : searchSynonymsParams.page) || 0,
|
|
@@ -376,6 +382,7 @@ function createSearchClient({
|
|
|
376
382
|
batchSize = 1e3,
|
|
377
383
|
maxRetries = 100
|
|
378
384
|
}, requestOptions) {
|
|
385
|
+
requestOptions = (0, import_client_common.withRequestId)(transporter, requestOptions);
|
|
379
386
|
let requests = [];
|
|
380
387
|
const responses = [];
|
|
381
388
|
const objectEntries = objects.entries();
|
|
@@ -388,7 +395,7 @@ function createSearchClient({
|
|
|
388
395
|
}
|
|
389
396
|
if (waitForTasks) {
|
|
390
397
|
for (const resp of responses) {
|
|
391
|
-
await this.waitForTask({ indexName, taskID: resp.taskID, maxRetries });
|
|
398
|
+
await this.waitForTask({ indexName, taskID: resp.taskID, maxRetries }, requestOptions);
|
|
392
399
|
}
|
|
393
400
|
}
|
|
394
401
|
return responses;
|
|
@@ -466,6 +473,8 @@ function createSearchClient({
|
|
|
466
473
|
* Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
|
|
467
474
|
* See https://api-clients-automation.netlify.app/docs/custom-helpers/#replaceallobjects for implementation details.
|
|
468
475
|
*
|
|
476
|
+
* Warning: calling this method with an empty `objects` list replaces the index with an empty one, deleting all existing records.
|
|
477
|
+
*
|
|
469
478
|
* @summary Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
|
|
470
479
|
* @param replaceAllObjects - The `replaceAllObjects` object.
|
|
471
480
|
* @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
|
|
@@ -482,6 +491,13 @@ function createSearchClient({
|
|
|
482
491
|
scopes,
|
|
483
492
|
maxRetries = import_client_common.DEFAULT_REPLACE_ALL_OBJECTS_MAX_RETRIES
|
|
484
493
|
}, requestOptions) {
|
|
494
|
+
requestOptions = (0, import_client_common.withRequestId)(transporter, requestOptions);
|
|
495
|
+
if (objects.length === 0) {
|
|
496
|
+
(0, import_client_common.logWarning)(
|
|
497
|
+
transporter.logger,
|
|
498
|
+
`replaceAllObjects was called with an empty list of objects, which will delete all records currently in the "${indexName}" index.`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
485
501
|
const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
|
|
486
502
|
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
|
|
487
503
|
if (scopes === void 0) {
|
|
@@ -503,11 +519,14 @@ function createSearchClient({
|
|
|
503
519
|
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize, maxRetries },
|
|
504
520
|
requestOptions
|
|
505
521
|
);
|
|
506
|
-
await this.waitForTask(
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
522
|
+
await this.waitForTask(
|
|
523
|
+
{
|
|
524
|
+
indexName: tmpIndexName,
|
|
525
|
+
taskID: copyOperationResponse.taskID,
|
|
526
|
+
maxRetries
|
|
527
|
+
},
|
|
528
|
+
requestOptions
|
|
529
|
+
);
|
|
511
530
|
copyOperationResponse = await this.operationIndex(
|
|
512
531
|
{
|
|
513
532
|
indexName,
|
|
@@ -519,11 +538,14 @@ function createSearchClient({
|
|
|
519
538
|
},
|
|
520
539
|
requestOptions
|
|
521
540
|
);
|
|
522
|
-
await this.waitForTask(
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
541
|
+
await this.waitForTask(
|
|
542
|
+
{
|
|
543
|
+
indexName: tmpIndexName,
|
|
544
|
+
taskID: copyOperationResponse.taskID,
|
|
545
|
+
maxRetries
|
|
546
|
+
},
|
|
547
|
+
requestOptions
|
|
548
|
+
);
|
|
527
549
|
const moveOperationResponse = await this.operationIndex(
|
|
528
550
|
{
|
|
529
551
|
indexName: tmpIndexName,
|
|
@@ -531,20 +553,23 @@ function createSearchClient({
|
|
|
531
553
|
},
|
|
532
554
|
requestOptions
|
|
533
555
|
);
|
|
534
|
-
await this.waitForTask(
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
556
|
+
await this.waitForTask(
|
|
557
|
+
{
|
|
558
|
+
indexName: tmpIndexName,
|
|
559
|
+
taskID: moveOperationResponse.taskID,
|
|
560
|
+
maxRetries
|
|
561
|
+
},
|
|
562
|
+
requestOptions
|
|
563
|
+
);
|
|
539
564
|
return { copyOperationResponse, batchResponses, moveOperationResponse };
|
|
540
565
|
} catch (error) {
|
|
541
|
-
await this.deleteIndex({ indexName: tmpIndexName });
|
|
566
|
+
await this.deleteIndex({ indexName: tmpIndexName }, requestOptions);
|
|
542
567
|
throw error;
|
|
543
568
|
}
|
|
544
569
|
},
|
|
545
|
-
async indexExists({ indexName }) {
|
|
570
|
+
async indexExists({ indexName }, requestOptions) {
|
|
546
571
|
try {
|
|
547
|
-
await this.getSettings({ indexName });
|
|
572
|
+
await this.getSettings({ indexName }, requestOptions);
|
|
548
573
|
} catch (error) {
|
|
549
574
|
if (error instanceof import_client_common.ApiError && error.status === 404) {
|
|
550
575
|
return false;
|
|
@@ -4028,6 +4053,7 @@ function searchClient(appId, apiKey, options) {
|
|
|
4028
4053
|
logger: (0, import_client_common2.createNullLogger)(),
|
|
4029
4054
|
requester: (0, import_requester_node_http.createHttpRequester)(),
|
|
4030
4055
|
algoliaAgents: [{ segment: "Node.js", version: process.versions.node }],
|
|
4056
|
+
requestIdChannel: "headers",
|
|
4031
4057
|
responsesCache: (0, import_client_common2.createNullCache)(),
|
|
4032
4058
|
requestsCache: (0, import_client_common2.createNullCache)(),
|
|
4033
4059
|
hostsCache: (0, import_client_common2.createMemoryCache)(),
|
|
@@ -4085,11 +4111,12 @@ function searchClient(appId, apiKey, options) {
|
|
|
4085
4111
|
batchSize,
|
|
4086
4112
|
maxRetries = 100
|
|
4087
4113
|
}, requestOptions) {
|
|
4114
|
+
requestOptions = (0, import_client_common2.withRequestId)(this.transporter, requestOptions);
|
|
4088
4115
|
const responses = [];
|
|
4089
4116
|
if (this.appId === destinationAppID) {
|
|
4090
4117
|
throw new import_client_common2.IndicesInSameAppError();
|
|
4091
4118
|
}
|
|
4092
|
-
if (!await this.indexExists({ indexName: sourceIndexName })) {
|
|
4119
|
+
if (!await this.indexExists({ indexName: sourceIndexName }, requestOptions)) {
|
|
4093
4120
|
throw new import_client_common2.IndexNotFoundError(sourceIndexName);
|
|
4094
4121
|
}
|
|
4095
4122
|
const destinationClient = createSearchClient({
|
|
@@ -4108,54 +4135,66 @@ function searchClient(appId, apiKey, options) {
|
|
|
4108
4135
|
hostsCache: (0, import_client_common2.createMemoryCache)(),
|
|
4109
4136
|
...options
|
|
4110
4137
|
});
|
|
4111
|
-
if (await destinationClient.indexExists({ indexName: destinationIndexName })) {
|
|
4138
|
+
if (await destinationClient.indexExists({ indexName: destinationIndexName }, requestOptions)) {
|
|
4112
4139
|
throw new import_client_common2.IndexAlreadyExistsError(destinationIndexName);
|
|
4113
4140
|
}
|
|
4114
4141
|
responses.push(
|
|
4115
4142
|
await destinationClient.setSettings(
|
|
4116
4143
|
{
|
|
4117
4144
|
indexName: destinationIndexName,
|
|
4118
|
-
indexSettings: await this.getSettings({ indexName: sourceIndexName })
|
|
4145
|
+
indexSettings: await this.getSettings({ indexName: sourceIndexName }, requestOptions)
|
|
4119
4146
|
},
|
|
4120
4147
|
requestOptions
|
|
4121
4148
|
)
|
|
4122
4149
|
);
|
|
4123
|
-
await this.browseRules(
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4150
|
+
await this.browseRules(
|
|
4151
|
+
{
|
|
4152
|
+
indexName: sourceIndexName,
|
|
4153
|
+
async aggregator(response) {
|
|
4154
|
+
responses.push(
|
|
4155
|
+
await destinationClient.saveRules(
|
|
4156
|
+
{ indexName: destinationIndexName, rules: response.hits },
|
|
4157
|
+
requestOptions
|
|
4158
|
+
)
|
|
4159
|
+
);
|
|
4160
|
+
}
|
|
4161
|
+
},
|
|
4162
|
+
requestOptions
|
|
4163
|
+
);
|
|
4164
|
+
await this.browseSynonyms(
|
|
4165
|
+
{
|
|
4166
|
+
indexName: sourceIndexName,
|
|
4167
|
+
async aggregator(response) {
|
|
4168
|
+
responses.push(
|
|
4169
|
+
await destinationClient.saveSynonyms(
|
|
4170
|
+
{ indexName: destinationIndexName, synonymHit: response.hits },
|
|
4171
|
+
requestOptions
|
|
4172
|
+
)
|
|
4173
|
+
);
|
|
4174
|
+
}
|
|
4175
|
+
},
|
|
4176
|
+
requestOptions
|
|
4177
|
+
);
|
|
4178
|
+
await this.browseObjects(
|
|
4179
|
+
{
|
|
4180
|
+
indexName: sourceIndexName,
|
|
4181
|
+
browseParams: batchSize ? { hitsPerPage: batchSize } : void 0,
|
|
4182
|
+
async aggregator(response) {
|
|
4183
|
+
responses.push(
|
|
4184
|
+
...await destinationClient.saveObjects(
|
|
4185
|
+
{ indexName: destinationIndexName, objects: response.hits, batchSize },
|
|
4186
|
+
requestOptions
|
|
4187
|
+
)
|
|
4188
|
+
);
|
|
4189
|
+
}
|
|
4190
|
+
},
|
|
4191
|
+
requestOptions
|
|
4192
|
+
);
|
|
4157
4193
|
for (const response of responses) {
|
|
4158
|
-
await destinationClient.waitForTask(
|
|
4194
|
+
await destinationClient.waitForTask(
|
|
4195
|
+
{ indexName: destinationIndexName, taskID: response.taskID, maxRetries },
|
|
4196
|
+
requestOptions
|
|
4197
|
+
);
|
|
4159
4198
|
}
|
|
4160
4199
|
},
|
|
4161
4200
|
/**
|