@algolia/ingestion 1.33.0 → 1.34.1

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.
package/README.md CHANGED
@@ -41,11 +41,11 @@ All of our clients comes with type definition, and are available for both browse
41
41
  ### With a package manager
42
42
 
43
43
  ```bash
44
- yarn add @algolia/ingestion@1.33.0
44
+ yarn add @algolia/ingestion@1.34.1
45
45
  # or
46
- npm install @algolia/ingestion@1.33.0
46
+ npm install @algolia/ingestion@1.34.1
47
47
  # or
48
- pnpm add @algolia/ingestion@1.33.0
48
+ pnpm add @algolia/ingestion@1.34.1
49
49
  ```
50
50
 
51
51
  ### Without a package manager
@@ -53,7 +53,7 @@ pnpm add @algolia/ingestion@1.33.0
53
53
  Add the following JavaScript snippet to the <head> of your website:
54
54
 
55
55
  ```html
56
- <script src="https://cdn.jsdelivr.net/npm/@algolia/ingestion@1.33.0/dist/builds/browser.umd.js"></script>
56
+ <script src="https://cdn.jsdelivr.net/npm/@algolia/ingestion@1.34.1/dist/builds/browser.umd.js"></script>
57
57
  ```
58
58
 
59
59
  ### Usage
package/dist/browser.d.ts CHANGED
@@ -2412,7 +2412,7 @@ type ChunkedPushOptions = {
2412
2412
  objects: Array<Record<string, unknown>>;
2413
2413
  };
2414
2414
 
2415
- declare const apiClientVersion = "1.33.0";
2415
+ declare const apiClientVersion = "1.34.1";
2416
2416
  declare const REGIONS: readonly ["eu", "us"];
2417
2417
  type Region = (typeof REGIONS)[number];
2418
2418
  type RegionOptions = {
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  // src/ingestionClient.ts
11
11
  import { createAuth, createIterablePromise, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
12
- var apiClientVersion = "1.33.0";
12
+ var apiClientVersion = "1.34.1";
13
13
  var REGIONS = ["eu", "us"];
14
14
  function getDefaultHosts(region) {
15
15
  const url = "data.{region}.algolia.com".replace("{region}", region);
@@ -117,7 +117,9 @@ function createIngestionClient({
117
117
  referenceIndexName
118
118
  }, requestOptions) {
119
119
  let records = [];
120
+ let offset = 0;
120
121
  const responses = [];
122
+ const waitBatchSize = Math.floor(batchSize / 10) || batchSize;
121
123
  const objectEntries = objects.entries();
122
124
  for (const [i, obj] of objectEntries) {
123
125
  records.push(obj);
@@ -127,33 +129,34 @@ function createIngestionClient({
127
129
  );
128
130
  records = [];
129
131
  }
130
- }
131
- let retryCount = 0;
132
- if (waitForTasks) {
133
- for (const resp of responses) {
134
- if (!resp.eventID) {
135
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
136
- }
137
- await createIterablePromise({
138
- func: async () => {
139
- if (resp.eventID === void 0 || !resp.eventID) {
140
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
141
- }
142
- return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
143
- if (error.status === 404) {
144
- return void 0;
132
+ if (waitForTasks && responses.length > 0 && (responses.length % waitBatchSize === 0 || i === objects.length - 1)) {
133
+ for (const resp of responses.slice(offset, offset + waitBatchSize)) {
134
+ if (!resp.eventID) {
135
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
136
+ }
137
+ let retryCount = 0;
138
+ await createIterablePromise({
139
+ func: async () => {
140
+ if (resp.eventID === void 0 || !resp.eventID) {
141
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
145
142
  }
146
- throw error;
147
- });
148
- },
149
- validate: (response) => response !== void 0,
150
- aggregator: () => retryCount += 1,
151
- error: {
152
- validate: () => retryCount >= 50,
153
- message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
154
- },
155
- timeout: () => Math.min(retryCount * 500, 5e3)
156
- });
143
+ return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
144
+ if (error.status === 404) {
145
+ return void 0;
146
+ }
147
+ throw error;
148
+ });
149
+ },
150
+ validate: (response) => response !== void 0,
151
+ aggregator: () => retryCount += 1,
152
+ error: {
153
+ validate: () => retryCount >= 50,
154
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
155
+ },
156
+ timeout: () => Math.min(retryCount * 500, 5e3)
157
+ });
158
+ }
159
+ offset += waitBatchSize;
157
160
  }
158
161
  }
159
162
  return responses;