@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.
@@ -30,7 +30,7 @@ var import_client_common2 = require("@algolia/client-common");
30
30
 
31
31
  // src/searchClient.ts
32
32
  var import_client_common = require("@algolia/client-common");
33
- var apiClientVersion = "5.18.0";
33
+ var apiClientVersion = "5.19.0";
34
34
  function getDefaultHosts(appId) {
35
35
  return [
36
36
  {
@@ -95,6 +95,10 @@ function createSearchClient({
95
95
  * The `appId` currently in use.
96
96
  */
97
97
  appId: appIdOption,
98
+ /**
99
+ * The `apiKey` currently in use.
100
+ */
101
+ apiKey: apiKeyOption,
98
102
  /**
99
103
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
100
104
  */
@@ -453,57 +457,66 @@ function createSearchClient({
453
457
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
454
458
  * @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
455
459
  * @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.
460
+ * @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
456
461
  * @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.
457
462
  */
458
- async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
463
+ async replaceAllObjects({ indexName, objects, batchSize, scopes }, requestOptions) {
459
464
  const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
460
465
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
461
- let 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
- const batchResponses = await this.chunkedBatch(
473
- { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
474
- requestOptions
475
- );
476
- await this.waitForTask({
477
- indexName: tmpIndexName,
478
- taskID: copyOperationResponse.taskID
479
- });
480
- copyOperationResponse = await this.operationIndex(
481
- {
482
- indexName,
483
- operationIndexParams: {
484
- operation: "copy",
485
- destination: tmpIndexName,
486
- scope: ["settings", "rules", "synonyms"]
487
- }
488
- },
489
- requestOptions
490
- );
491
- await this.waitForTask({
492
- indexName: tmpIndexName,
493
- taskID: copyOperationResponse.taskID
494
- });
495
- const moveOperationResponse = await this.operationIndex(
496
- {
466
+ if (scopes === void 0) {
467
+ scopes = ["settings", "rules", "synonyms"];
468
+ }
469
+ try {
470
+ let copyOperationResponse = await this.operationIndex(
471
+ {
472
+ indexName,
473
+ operationIndexParams: {
474
+ operation: "copy",
475
+ destination: tmpIndexName,
476
+ scope: scopes
477
+ }
478
+ },
479
+ requestOptions
480
+ );
481
+ const batchResponses = await this.chunkedBatch(
482
+ { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
483
+ requestOptions
484
+ );
485
+ await this.waitForTask({
497
486
  indexName: tmpIndexName,
498
- operationIndexParams: { operation: "move", destination: indexName }
499
- },
500
- requestOptions
501
- );
502
- await this.waitForTask({
503
- indexName: tmpIndexName,
504
- taskID: moveOperationResponse.taskID
505
- });
506
- return { copyOperationResponse, batchResponses, moveOperationResponse };
487
+ taskID: copyOperationResponse.taskID
488
+ });
489
+ copyOperationResponse = await this.operationIndex(
490
+ {
491
+ indexName,
492
+ operationIndexParams: {
493
+ operation: "copy",
494
+ destination: tmpIndexName,
495
+ scope: scopes
496
+ }
497
+ },
498
+ requestOptions
499
+ );
500
+ await this.waitForTask({
501
+ indexName: tmpIndexName,
502
+ taskID: copyOperationResponse.taskID
503
+ });
504
+ const moveOperationResponse = await this.operationIndex(
505
+ {
506
+ indexName: tmpIndexName,
507
+ operationIndexParams: { operation: "move", destination: indexName }
508
+ },
509
+ requestOptions
510
+ );
511
+ await this.waitForTask({
512
+ indexName: tmpIndexName,
513
+ taskID: moveOperationResponse.taskID
514
+ });
515
+ return { copyOperationResponse, batchResponses, moveOperationResponse };
516
+ } catch (error) {
517
+ await this.deleteIndex({ indexName: tmpIndexName });
518
+ throw error;
519
+ }
507
520
  },
508
521
  async indexExists({ indexName }) {
509
522
  try {