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