@algolia/client-search 5.18.0 → 5.20.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.
@@ -11,7 +11,7 @@ import {
11
11
  getAlgoliaAgent,
12
12
  shuffle
13
13
  } from "@algolia/client-common";
14
- var apiClientVersion = "5.18.0";
14
+ var apiClientVersion = "5.20.0";
15
15
  function getDefaultHosts(appId) {
16
16
  return [
17
17
  {
@@ -76,6 +76,10 @@ function createSearchClient({
76
76
  * The `appId` currently in use.
77
77
  */
78
78
  appId: appIdOption,
79
+ /**
80
+ * The `apiKey` currently in use.
81
+ */
82
+ apiKey: apiKeyOption,
79
83
  /**
80
84
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
81
85
  */
@@ -434,57 +438,66 @@ function createSearchClient({
434
438
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
435
439
  * @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
436
440
  * @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.
441
+ * @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
437
442
  * @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.
438
443
  */
439
- async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
444
+ async replaceAllObjects({ indexName, objects, batchSize, scopes }, requestOptions) {
440
445
  const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
441
446
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
442
- let copyOperationResponse = await this.operationIndex(
443
- {
444
- indexName,
445
- operationIndexParams: {
446
- operation: "copy",
447
- destination: tmpIndexName,
448
- scope: ["settings", "rules", "synonyms"]
449
- }
450
- },
451
- requestOptions
452
- );
453
- const batchResponses = await this.chunkedBatch(
454
- { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
455
- requestOptions
456
- );
457
- await this.waitForTask({
458
- indexName: tmpIndexName,
459
- taskID: copyOperationResponse.taskID
460
- });
461
- copyOperationResponse = await this.operationIndex(
462
- {
463
- indexName,
464
- operationIndexParams: {
465
- operation: "copy",
466
- destination: tmpIndexName,
467
- scope: ["settings", "rules", "synonyms"]
468
- }
469
- },
470
- requestOptions
471
- );
472
- await this.waitForTask({
473
- indexName: tmpIndexName,
474
- taskID: copyOperationResponse.taskID
475
- });
476
- const moveOperationResponse = await this.operationIndex(
477
- {
447
+ if (scopes === void 0) {
448
+ scopes = ["settings", "rules", "synonyms"];
449
+ }
450
+ try {
451
+ let copyOperationResponse = await this.operationIndex(
452
+ {
453
+ indexName,
454
+ operationIndexParams: {
455
+ operation: "copy",
456
+ destination: tmpIndexName,
457
+ scope: scopes
458
+ }
459
+ },
460
+ requestOptions
461
+ );
462
+ const batchResponses = await this.chunkedBatch(
463
+ { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
464
+ requestOptions
465
+ );
466
+ await this.waitForTask({
478
467
  indexName: tmpIndexName,
479
- operationIndexParams: { operation: "move", destination: indexName }
480
- },
481
- requestOptions
482
- );
483
- await this.waitForTask({
484
- indexName: tmpIndexName,
485
- taskID: moveOperationResponse.taskID
486
- });
487
- return { copyOperationResponse, batchResponses, moveOperationResponse };
468
+ taskID: copyOperationResponse.taskID
469
+ });
470
+ copyOperationResponse = await this.operationIndex(
471
+ {
472
+ indexName,
473
+ operationIndexParams: {
474
+ operation: "copy",
475
+ destination: tmpIndexName,
476
+ scope: scopes
477
+ }
478
+ },
479
+ requestOptions
480
+ );
481
+ await this.waitForTask({
482
+ indexName: tmpIndexName,
483
+ taskID: copyOperationResponse.taskID
484
+ });
485
+ const moveOperationResponse = await this.operationIndex(
486
+ {
487
+ indexName: tmpIndexName,
488
+ operationIndexParams: { operation: "move", destination: indexName }
489
+ },
490
+ requestOptions
491
+ );
492
+ await this.waitForTask({
493
+ indexName: tmpIndexName,
494
+ taskID: moveOperationResponse.taskID
495
+ });
496
+ return { copyOperationResponse, batchResponses, moveOperationResponse };
497
+ } catch (error) {
498
+ await this.deleteIndex({ indexName: tmpIndexName });
499
+ throw error;
500
+ }
488
501
  },
489
502
  async indexExists({ indexName }) {
490
503
  try {