@algolia/ingestion 1.55.1 → 1.55.2

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/dist/fetch.d.ts CHANGED
@@ -2540,7 +2540,7 @@ type ChunkedPushOptions = ChunkedHelperOptions & {
2540
2540
  objects: Array<Record<string, unknown>>;
2541
2541
  };
2542
2542
 
2543
- declare const apiClientVersion = "1.55.1";
2543
+ declare const apiClientVersion = "1.55.2";
2544
2544
  declare const REGIONS: readonly ["eu", "us"];
2545
2545
  type Region = (typeof REGIONS)[number];
2546
2546
  type RegionOptions = {
package/dist/node.d.cts CHANGED
@@ -2540,7 +2540,7 @@ type ChunkedPushOptions = ChunkedHelperOptions & {
2540
2540
  objects: Array<Record<string, unknown>>;
2541
2541
  };
2542
2542
 
2543
- declare const apiClientVersion = "1.55.1";
2543
+ declare const apiClientVersion = "1.55.2";
2544
2544
  declare const REGIONS: readonly ["eu", "us"];
2545
2545
  type Region = (typeof REGIONS)[number];
2546
2546
  type RegionOptions = {
package/dist/node.d.ts CHANGED
@@ -2540,7 +2540,7 @@ type ChunkedPushOptions = ChunkedHelperOptions & {
2540
2540
  objects: Array<Record<string, unknown>>;
2541
2541
  };
2542
2542
 
2543
- declare const apiClientVersion = "1.55.1";
2543
+ declare const apiClientVersion = "1.55.2";
2544
2544
  declare const REGIONS: readonly ["eu", "us"];
2545
2545
  type Region = (typeof REGIONS)[number];
2546
2546
  type RegionOptions = {
@@ -29,7 +29,7 @@ __export(ingestionClient_exports, {
29
29
  });
30
30
  module.exports = __toCommonJS(ingestionClient_exports);
31
31
  var import_client_common = require("@algolia/client-common");
32
- var apiClientVersion = "1.55.1";
32
+ var apiClientVersion = "1.55.2";
33
33
  var REGIONS = ["eu", "us"];
34
34
  function getDefaultHosts(region) {
35
35
  const url = "data.{region}.algolia.com".replace("{region}", region);
@@ -138,10 +138,41 @@ function createIngestionClient({
138
138
  referenceIndexName,
139
139
  maxRetries = 100
140
140
  }, requestOptions) {
141
+ if (batchSize < 1) {
142
+ throw new Error("`batchSize` must be at least 1.");
143
+ }
141
144
  let records = [];
142
145
  let offset = 0;
143
146
  const responses = [];
144
147
  const waitBatchSize = Math.floor(batchSize / 10) || batchSize;
148
+ const waitForBatch = async (start, end) => {
149
+ for (const resp of responses.slice(start, end)) {
150
+ if (!resp.eventID) {
151
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
152
+ }
153
+ let retryCount = 0;
154
+ await (0, import_client_common.createIterablePromise)({
155
+ func: async () => {
156
+ if (resp.eventID === void 0 || !resp.eventID) {
157
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
158
+ }
159
+ return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
160
+ if (error.status === 404) {
161
+ return void 0;
162
+ }
163
+ throw error;
164
+ });
165
+ },
166
+ validate: (response) => response !== void 0,
167
+ aggregator: () => retryCount += 1,
168
+ error: {
169
+ validate: () => retryCount >= maxRetries,
170
+ message: () => `Stopped waiting for the task after ${maxRetries} retries. This does not mean the operation failed; it may still complete. If you need to keep polling, retry with a higher maxRetries.`
171
+ },
172
+ timeout: () => Math.min(retryCount * 1500, 5e3)
173
+ });
174
+ }
175
+ };
145
176
  const objectEntries = objects.entries();
146
177
  for (const [i, obj] of objectEntries) {
147
178
  records.push(obj);
@@ -151,36 +182,14 @@ function createIngestionClient({
151
182
  );
152
183
  records = [];
153
184
  }
154
- if (waitForTasks && responses.length > 0 && (responses.length % waitBatchSize === 0 || i === objects.length - 1)) {
155
- for (const resp of responses.slice(offset, offset + waitBatchSize)) {
156
- if (!resp.eventID) {
157
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
158
- }
159
- let retryCount = 0;
160
- await (0, import_client_common.createIterablePromise)({
161
- func: async () => {
162
- if (resp.eventID === void 0 || !resp.eventID) {
163
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
164
- }
165
- return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
166
- if (error.status === 404) {
167
- return void 0;
168
- }
169
- throw error;
170
- });
171
- },
172
- validate: (response) => response !== void 0,
173
- aggregator: () => retryCount += 1,
174
- error: {
175
- validate: () => retryCount >= maxRetries,
176
- message: () => `Stopped waiting for the task after ${maxRetries} retries. This does not mean the operation failed; it may still complete. If you need to keep polling, retry with a higher maxRetries.`
177
- },
178
- timeout: () => Math.min(retryCount * 1500, 5e3)
179
- });
180
- }
185
+ if (waitForTasks && responses.length - offset >= waitBatchSize) {
186
+ await waitForBatch(offset, offset + waitBatchSize);
181
187
  offset += waitBatchSize;
182
188
  }
183
189
  }
190
+ if (waitForTasks) {
191
+ await waitForBatch(offset, responses.length);
192
+ }
184
193
  return responses;
185
194
  },
186
195
  /**