@algolia/client-search 5.52.0 → 5.53.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.
@@ -21,7 +21,7 @@ import {
21
21
  getAlgoliaAgent,
22
22
  shuffle
23
23
  } from "@algolia/client-common";
24
- var apiClientVersion = "5.52.0";
24
+ var apiClientVersion = "5.53.0";
25
25
  function getDefaultHosts(appId) {
26
26
  return [
27
27
  {
@@ -355,9 +355,17 @@ function createSearchClient({
355
355
  * @param chunkedBatch.action - The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`.
356
356
  * @param chunkedBatch.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
357
357
  * @param chunkedBatch.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
358
+ * @param chunkedBatch.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
358
359
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
359
360
  */
360
- async chunkedBatch({ indexName, objects, action = "addObject", waitForTasks, batchSize = 1e3 }, requestOptions) {
361
+ async chunkedBatch({
362
+ indexName,
363
+ objects,
364
+ action = "addObject",
365
+ waitForTasks,
366
+ batchSize = 1e3,
367
+ maxRetries = 100
368
+ }, requestOptions) {
361
369
  let requests = [];
362
370
  const responses = [];
363
371
  const objectEntries = objects.entries();
@@ -370,7 +378,7 @@ function createSearchClient({
370
378
  }
371
379
  if (waitForTasks) {
372
380
  for (const resp of responses) {
373
- await this.waitForTask({ indexName, taskID: resp.taskID });
381
+ await this.waitForTask({ indexName, taskID: resp.taskID, maxRetries });
374
382
  }
375
383
  }
376
384
  return responses;
@@ -384,11 +392,12 @@ function createSearchClient({
384
392
  * @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
385
393
  * @param saveObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
386
394
  * @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
395
+ * @param saveObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
387
396
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
388
397
  */
389
- async saveObjects({ indexName, objects, waitForTasks, batchSize }, requestOptions) {
398
+ async saveObjects({ indexName, objects, waitForTasks, batchSize, maxRetries }, requestOptions) {
390
399
  return await this.chunkedBatch(
391
- { indexName, objects, action: "addObject", waitForTasks, batchSize },
400
+ { indexName, objects, action: "addObject", waitForTasks, batchSize, maxRetries },
392
401
  requestOptions
393
402
  );
394
403
  },
@@ -401,16 +410,18 @@ function createSearchClient({
401
410
  * @param deleteObjects.objectIDs - The objectIDs to delete.
402
411
  * @param deleteObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
403
412
  * @param deleteObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
413
+ * @param deleteObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
404
414
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
405
415
  */
406
- async deleteObjects({ indexName, objectIDs, waitForTasks, batchSize }, requestOptions) {
416
+ async deleteObjects({ indexName, objectIDs, waitForTasks, batchSize, maxRetries }, requestOptions) {
407
417
  return await this.chunkedBatch(
408
418
  {
409
419
  indexName,
410
420
  objects: objectIDs.map((objectID) => ({ objectID })),
411
421
  action: "deleteObject",
412
422
  waitForTasks,
413
- batchSize
423
+ batchSize,
424
+ maxRetries
414
425
  },
415
426
  requestOptions
416
427
  );
@@ -425,16 +436,18 @@ function createSearchClient({
425
436
  * @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail.
426
437
  * @param partialUpdateObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
427
438
  * @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
439
+ * @param partialUpdateObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
428
440
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
429
441
  */
430
- async partialUpdateObjects({ indexName, objects, createIfNotExists, waitForTasks, batchSize }, requestOptions) {
442
+ async partialUpdateObjects({ indexName, objects, createIfNotExists, waitForTasks, batchSize, maxRetries }, requestOptions) {
431
443
  return await this.chunkedBatch(
432
444
  {
433
445
  indexName,
434
446
  objects,
435
447
  action: createIfNotExists ? "partialUpdateObject" : "partialUpdateObjectNoCreate",
436
448
  batchSize,
437
- waitForTasks
449
+ waitForTasks,
450
+ maxRetries
438
451
  },
439
452
  requestOptions
440
453
  );
@@ -449,9 +462,10 @@ function createSearchClient({
449
462
  * @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
450
463
  * @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `objects.length / batchSize`. Defaults to 1000.
451
464
  * @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
465
+ * @param replaceAllObjects.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
452
466
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch`, `operationIndex` and `getTask` method and merged with the transporter requestOptions.
453
467
  */
454
- async replaceAllObjects({ indexName, objects, batchSize, scopes }, requestOptions) {
468
+ async replaceAllObjects({ indexName, objects, batchSize, scopes, maxRetries = 100 }, requestOptions) {
455
469
  const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
456
470
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
457
471
  if (scopes === void 0) {
@@ -470,12 +484,13 @@ function createSearchClient({
470
484
  requestOptions
471
485
  );
472
486
  const batchResponses = await this.chunkedBatch(
473
- { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
487
+ { indexName: tmpIndexName, objects, waitForTasks: true, batchSize, maxRetries },
474
488
  requestOptions
475
489
  );
476
490
  await this.waitForTask({
477
491
  indexName: tmpIndexName,
478
- taskID: copyOperationResponse.taskID
492
+ taskID: copyOperationResponse.taskID,
493
+ maxRetries
479
494
  });
480
495
  copyOperationResponse = await this.operationIndex(
481
496
  {
@@ -490,7 +505,8 @@ function createSearchClient({
490
505
  );
491
506
  await this.waitForTask({
492
507
  indexName: tmpIndexName,
493
- taskID: copyOperationResponse.taskID
508
+ taskID: copyOperationResponse.taskID,
509
+ maxRetries
494
510
  });
495
511
  const moveOperationResponse = await this.operationIndex(
496
512
  {
@@ -501,7 +517,8 @@ function createSearchClient({
501
517
  );
502
518
  await this.waitForTask({
503
519
  indexName: tmpIndexName,
504
- taskID: moveOperationResponse.taskID
520
+ taskID: moveOperationResponse.taskID,
521
+ maxRetries
505
522
  });
506
523
  return { copyOperationResponse, batchResponses, moveOperationResponse };
507
524
  } catch (error) {
@@ -2419,6 +2436,7 @@ function searchClient(appId, apiKey, options) {
2419
2436
  * @param accountCopyIndex.destinationApiKey - The API Key of the `destinationAppID` to write the index to, must have write ACLs.
2420
2437
  * @param accountCopyIndex.destinationIndexName - The name of the index to write the copied index to.
2421
2438
  * @param accountCopyIndex.batchSize - The size of the chunk of `objects`. Defaults to 1000.
2439
+ * @param accountCopyIndex.maxRetries - The maximum number of retries when polling for task completion. 100 by default.
2422
2440
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `setSettings`, `saveRules`, `saveSynonyms` and `saveObjects` method and merged with the transporter requestOptions.
2423
2441
  */
2424
2442
  async accountCopyIndex({
@@ -2426,7 +2444,8 @@ function searchClient(appId, apiKey, options) {
2426
2444
  destinationAppID,
2427
2445
  destinationApiKey,
2428
2446
  destinationIndexName,
2429
- batchSize
2447
+ batchSize,
2448
+ maxRetries = 100
2430
2449
  }, requestOptions) {
2431
2450
  const responses = [];
2432
2451
  if (this.appId === destinationAppID) {
@@ -2498,7 +2517,7 @@ function searchClient(appId, apiKey, options) {
2498
2517
  }
2499
2518
  });
2500
2519
  for (const response of responses) {
2501
- await destinationClient.waitForTask({ indexName: destinationIndexName, taskID: response.taskID });
2520
+ await destinationClient.waitForTask({ indexName: destinationIndexName, taskID: response.taskID, maxRetries });
2502
2521
  }
2503
2522
  },
2504
2523
  /**