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