@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/fetch.js
CHANGED
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
createMemoryCache,
|
|
9
9
|
createNullCache,
|
|
10
10
|
createNullLogger,
|
|
11
|
-
serializeQueryParameters
|
|
11
|
+
serializeQueryParameters,
|
|
12
|
+
withRequestId as withRequestId2
|
|
12
13
|
} from "@algolia/client-common";
|
|
13
14
|
import { createFetchRequester } from "@algolia/requester-fetch";
|
|
14
15
|
import { createHttpRequester } from "@algolia/requester-node-http";
|
|
@@ -21,10 +22,12 @@ import {
|
|
|
21
22
|
createIterablePromise,
|
|
22
23
|
createTransporter,
|
|
23
24
|
getAlgoliaAgent,
|
|
25
|
+
logWarning,
|
|
24
26
|
shuffle,
|
|
25
|
-
validateRequired
|
|
27
|
+
validateRequired,
|
|
28
|
+
withRequestId
|
|
26
29
|
} from "@algolia/client-common";
|
|
27
|
-
var apiClientVersion = "5.
|
|
30
|
+
var apiClientVersion = "5.57.0";
|
|
28
31
|
function getDefaultHosts(appId) {
|
|
29
32
|
return [
|
|
30
33
|
{
|
|
@@ -144,6 +147,7 @@ function createSearchClient({
|
|
|
144
147
|
maxRetries = 100,
|
|
145
148
|
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
|
|
146
149
|
}, requestOptions) {
|
|
150
|
+
requestOptions = withRequestId(transporter, requestOptions);
|
|
147
151
|
let retryCount = 0;
|
|
148
152
|
return createIterablePromise({
|
|
149
153
|
func: () => this.getTask({ indexName, taskID }, requestOptions),
|
|
@@ -171,6 +175,7 @@ function createSearchClient({
|
|
|
171
175
|
maxRetries = 100,
|
|
172
176
|
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
|
|
173
177
|
}, requestOptions) {
|
|
178
|
+
requestOptions = withRequestId(transporter, requestOptions);
|
|
174
179
|
let retryCount = 0;
|
|
175
180
|
return createIterablePromise({
|
|
176
181
|
func: () => this.getAppTask({ taskID }, requestOptions),
|
|
@@ -202,6 +207,7 @@ function createSearchClient({
|
|
|
202
207
|
maxRetries = 100,
|
|
203
208
|
timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
|
|
204
209
|
}, requestOptions) {
|
|
210
|
+
requestOptions = withRequestId(transporter, requestOptions);
|
|
205
211
|
let retryCount = 0;
|
|
206
212
|
const baseIteratorOptions = {
|
|
207
213
|
aggregator: () => retryCount += 1,
|
|
@@ -257,6 +263,7 @@ function createSearchClient({
|
|
|
257
263
|
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
|
|
258
264
|
*/
|
|
259
265
|
browseObjects({ indexName, browseParams, ...browseObjectsOptions }, requestOptions) {
|
|
266
|
+
requestOptions = withRequestId(transporter, requestOptions);
|
|
260
267
|
return createIterablePromise({
|
|
261
268
|
func: (previousResponse) => {
|
|
262
269
|
return this.browse(
|
|
@@ -287,6 +294,7 @@ function createSearchClient({
|
|
|
287
294
|
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
|
|
288
295
|
*/
|
|
289
296
|
browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
|
|
297
|
+
requestOptions = withRequestId(transporter, requestOptions);
|
|
290
298
|
const params = {
|
|
291
299
|
...searchRulesParams,
|
|
292
300
|
hitsPerPage: (searchRulesParams == null ? void 0 : searchRulesParams.hitsPerPage) || 1e3
|
|
@@ -324,6 +332,7 @@ function createSearchClient({
|
|
|
324
332
|
searchSynonymsParams,
|
|
325
333
|
...browseSynonymsOptions
|
|
326
334
|
}, requestOptions) {
|
|
335
|
+
requestOptions = withRequestId(transporter, requestOptions);
|
|
327
336
|
const params = {
|
|
328
337
|
...searchSynonymsParams,
|
|
329
338
|
page: (searchSynonymsParams == null ? void 0 : searchSynonymsParams.page) || 0,
|
|
@@ -369,6 +378,7 @@ function createSearchClient({
|
|
|
369
378
|
batchSize = 1e3,
|
|
370
379
|
maxRetries = 100
|
|
371
380
|
}, requestOptions) {
|
|
381
|
+
requestOptions = withRequestId(transporter, requestOptions);
|
|
372
382
|
let requests = [];
|
|
373
383
|
const responses = [];
|
|
374
384
|
const objectEntries = objects.entries();
|
|
@@ -381,7 +391,7 @@ function createSearchClient({
|
|
|
381
391
|
}
|
|
382
392
|
if (waitForTasks) {
|
|
383
393
|
for (const resp of responses) {
|
|
384
|
-
await this.waitForTask({ indexName, taskID: resp.taskID, maxRetries });
|
|
394
|
+
await this.waitForTask({ indexName, taskID: resp.taskID, maxRetries }, requestOptions);
|
|
385
395
|
}
|
|
386
396
|
}
|
|
387
397
|
return responses;
|
|
@@ -459,6 +469,8 @@ function createSearchClient({
|
|
|
459
469
|
* 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.
|
|
460
470
|
* See https://api-clients-automation.netlify.app/docs/custom-helpers/#replaceallobjects for implementation details.
|
|
461
471
|
*
|
|
472
|
+
* Warning: calling this method with an empty `objects` list replaces the index with an empty one, deleting all existing records.
|
|
473
|
+
*
|
|
462
474
|
* @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.
|
|
463
475
|
* @param replaceAllObjects - The `replaceAllObjects` object.
|
|
464
476
|
* @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
|
|
@@ -475,6 +487,13 @@ function createSearchClient({
|
|
|
475
487
|
scopes,
|
|
476
488
|
maxRetries = DEFAULT_REPLACE_ALL_OBJECTS_MAX_RETRIES
|
|
477
489
|
}, requestOptions) {
|
|
490
|
+
requestOptions = withRequestId(transporter, requestOptions);
|
|
491
|
+
if (objects.length === 0) {
|
|
492
|
+
logWarning(
|
|
493
|
+
transporter.logger,
|
|
494
|
+
`replaceAllObjects was called with an empty list of objects, which will delete all records currently in the "${indexName}" index.`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
478
497
|
const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
|
|
479
498
|
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
|
|
480
499
|
if (scopes === void 0) {
|
|
@@ -496,11 +515,14 @@ function createSearchClient({
|
|
|
496
515
|
{ indexName: tmpIndexName, objects, waitForTasks: true, batchSize, maxRetries },
|
|
497
516
|
requestOptions
|
|
498
517
|
);
|
|
499
|
-
await this.waitForTask(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
518
|
+
await this.waitForTask(
|
|
519
|
+
{
|
|
520
|
+
indexName: tmpIndexName,
|
|
521
|
+
taskID: copyOperationResponse.taskID,
|
|
522
|
+
maxRetries
|
|
523
|
+
},
|
|
524
|
+
requestOptions
|
|
525
|
+
);
|
|
504
526
|
copyOperationResponse = await this.operationIndex(
|
|
505
527
|
{
|
|
506
528
|
indexName,
|
|
@@ -512,11 +534,14 @@ function createSearchClient({
|
|
|
512
534
|
},
|
|
513
535
|
requestOptions
|
|
514
536
|
);
|
|
515
|
-
await this.waitForTask(
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
537
|
+
await this.waitForTask(
|
|
538
|
+
{
|
|
539
|
+
indexName: tmpIndexName,
|
|
540
|
+
taskID: copyOperationResponse.taskID,
|
|
541
|
+
maxRetries
|
|
542
|
+
},
|
|
543
|
+
requestOptions
|
|
544
|
+
);
|
|
520
545
|
const moveOperationResponse = await this.operationIndex(
|
|
521
546
|
{
|
|
522
547
|
indexName: tmpIndexName,
|
|
@@ -524,20 +549,23 @@ function createSearchClient({
|
|
|
524
549
|
},
|
|
525
550
|
requestOptions
|
|
526
551
|
);
|
|
527
|
-
await this.waitForTask(
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
552
|
+
await this.waitForTask(
|
|
553
|
+
{
|
|
554
|
+
indexName: tmpIndexName,
|
|
555
|
+
taskID: moveOperationResponse.taskID,
|
|
556
|
+
maxRetries
|
|
557
|
+
},
|
|
558
|
+
requestOptions
|
|
559
|
+
);
|
|
532
560
|
return { copyOperationResponse, batchResponses, moveOperationResponse };
|
|
533
561
|
} catch (error) {
|
|
534
|
-
await this.deleteIndex({ indexName: tmpIndexName });
|
|
562
|
+
await this.deleteIndex({ indexName: tmpIndexName }, requestOptions);
|
|
535
563
|
throw error;
|
|
536
564
|
}
|
|
537
565
|
},
|
|
538
|
-
async indexExists({ indexName }) {
|
|
566
|
+
async indexExists({ indexName }, requestOptions) {
|
|
539
567
|
try {
|
|
540
|
-
await this.getSettings({ indexName });
|
|
568
|
+
await this.getSettings({ indexName }, requestOptions);
|
|
541
569
|
} catch (error) {
|
|
542
570
|
if (error instanceof ApiError && error.status === 404) {
|
|
543
571
|
return false;
|
|
@@ -4021,6 +4049,7 @@ function searchClient(appId, apiKey, options) {
|
|
|
4021
4049
|
logger: createNullLogger(),
|
|
4022
4050
|
requester: createFetchRequester(),
|
|
4023
4051
|
algoliaAgents: [{ segment: "Fetch" }],
|
|
4052
|
+
requestIdChannel: "queryParameters",
|
|
4024
4053
|
responsesCache: createNullCache(),
|
|
4025
4054
|
requestsCache: createNullCache(),
|
|
4026
4055
|
hostsCache: createMemoryCache(),
|
|
@@ -4078,11 +4107,12 @@ function searchClient(appId, apiKey, options) {
|
|
|
4078
4107
|
batchSize,
|
|
4079
4108
|
maxRetries = 100
|
|
4080
4109
|
}, requestOptions) {
|
|
4110
|
+
requestOptions = withRequestId2(this.transporter, requestOptions);
|
|
4081
4111
|
const responses = [];
|
|
4082
4112
|
if (this.appId === destinationAppID) {
|
|
4083
4113
|
throw new IndicesInSameAppError();
|
|
4084
4114
|
}
|
|
4085
|
-
if (!await this.indexExists({ indexName: sourceIndexName })) {
|
|
4115
|
+
if (!await this.indexExists({ indexName: sourceIndexName }, requestOptions)) {
|
|
4086
4116
|
throw new IndexNotFoundError(sourceIndexName);
|
|
4087
4117
|
}
|
|
4088
4118
|
const destinationClient = createSearchClient({
|
|
@@ -4101,54 +4131,66 @@ function searchClient(appId, apiKey, options) {
|
|
|
4101
4131
|
hostsCache: createMemoryCache(),
|
|
4102
4132
|
...options
|
|
4103
4133
|
});
|
|
4104
|
-
if (await destinationClient.indexExists({ indexName: destinationIndexName })) {
|
|
4134
|
+
if (await destinationClient.indexExists({ indexName: destinationIndexName }, requestOptions)) {
|
|
4105
4135
|
throw new IndexAlreadyExistsError(destinationIndexName);
|
|
4106
4136
|
}
|
|
4107
4137
|
responses.push(
|
|
4108
4138
|
await destinationClient.setSettings(
|
|
4109
4139
|
{
|
|
4110
4140
|
indexName: destinationIndexName,
|
|
4111
|
-
indexSettings: await this.getSettings({ indexName: sourceIndexName })
|
|
4141
|
+
indexSettings: await this.getSettings({ indexName: sourceIndexName }, requestOptions)
|
|
4112
4142
|
},
|
|
4113
4143
|
requestOptions
|
|
4114
4144
|
)
|
|
4115
4145
|
);
|
|
4116
|
-
await this.browseRules(
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
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
|
-
|
|
4146
|
+
await this.browseRules(
|
|
4147
|
+
{
|
|
4148
|
+
indexName: sourceIndexName,
|
|
4149
|
+
async aggregator(response) {
|
|
4150
|
+
responses.push(
|
|
4151
|
+
await destinationClient.saveRules(
|
|
4152
|
+
{ indexName: destinationIndexName, rules: response.hits },
|
|
4153
|
+
requestOptions
|
|
4154
|
+
)
|
|
4155
|
+
);
|
|
4156
|
+
}
|
|
4157
|
+
},
|
|
4158
|
+
requestOptions
|
|
4159
|
+
);
|
|
4160
|
+
await this.browseSynonyms(
|
|
4161
|
+
{
|
|
4162
|
+
indexName: sourceIndexName,
|
|
4163
|
+
async aggregator(response) {
|
|
4164
|
+
responses.push(
|
|
4165
|
+
await destinationClient.saveSynonyms(
|
|
4166
|
+
{ indexName: destinationIndexName, synonymHit: response.hits },
|
|
4167
|
+
requestOptions
|
|
4168
|
+
)
|
|
4169
|
+
);
|
|
4170
|
+
}
|
|
4171
|
+
},
|
|
4172
|
+
requestOptions
|
|
4173
|
+
);
|
|
4174
|
+
await this.browseObjects(
|
|
4175
|
+
{
|
|
4176
|
+
indexName: sourceIndexName,
|
|
4177
|
+
browseParams: batchSize ? { hitsPerPage: batchSize } : void 0,
|
|
4178
|
+
async aggregator(response) {
|
|
4179
|
+
responses.push(
|
|
4180
|
+
...await destinationClient.saveObjects(
|
|
4181
|
+
{ indexName: destinationIndexName, objects: response.hits, batchSize },
|
|
4182
|
+
requestOptions
|
|
4183
|
+
)
|
|
4184
|
+
);
|
|
4185
|
+
}
|
|
4186
|
+
},
|
|
4187
|
+
requestOptions
|
|
4188
|
+
);
|
|
4150
4189
|
for (const response of responses) {
|
|
4151
|
-
await destinationClient.waitForTask(
|
|
4190
|
+
await destinationClient.waitForTask(
|
|
4191
|
+
{ indexName: destinationIndexName, taskID: response.taskID, maxRetries },
|
|
4192
|
+
requestOptions
|
|
4193
|
+
);
|
|
4152
4194
|
}
|
|
4153
4195
|
},
|
|
4154
4196
|
/**
|