@algolia/ingestion 1.34.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.
@@ -32,7 +32,7 @@ var import_client_common2 = require("@algolia/client-common");
32
32
 
33
33
  // src/ingestionClient.ts
34
34
  var import_client_common = require("@algolia/client-common");
35
- var apiClientVersion = "1.34.0";
35
+ var apiClientVersion = "1.34.1";
36
36
  var REGIONS = ["eu", "us"];
37
37
  function getDefaultHosts(region) {
38
38
  const url = "data.{region}.algolia.com".replace("{region}", region);
@@ -140,7 +140,9 @@ function createIngestionClient({
140
140
  referenceIndexName
141
141
  }, requestOptions) {
142
142
  let records = [];
143
+ let offset = 0;
143
144
  const responses = [];
145
+ const waitBatchSize = Math.floor(batchSize / 10) || batchSize;
144
146
  const objectEntries = objects.entries();
145
147
  for (const [i, obj] of objectEntries) {
146
148
  records.push(obj);
@@ -150,33 +152,34 @@ function createIngestionClient({
150
152
  );
151
153
  records = [];
152
154
  }
153
- }
154
- let retryCount = 0;
155
- if (waitForTasks) {
156
- for (const resp of responses) {
157
- if (!resp.eventID) {
158
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
159
- }
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;
155
+ if (waitForTasks && responses.length > 0 && (responses.length % waitBatchSize === 0 || i === objects.length - 1)) {
156
+ for (const resp of responses.slice(offset, offset + waitBatchSize)) {
157
+ if (!resp.eventID) {
158
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
159
+ }
160
+ let retryCount = 0;
161
+ await (0, import_client_common.createIterablePromise)({
162
+ func: async () => {
163
+ if (resp.eventID === void 0 || !resp.eventID) {
164
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
168
165
  }
169
- throw error;
170
- });
171
- },
172
- validate: (response) => response !== void 0,
173
- aggregator: () => retryCount += 1,
174
- error: {
175
- validate: () => retryCount >= 50,
176
- message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
177
- },
178
- timeout: () => Math.min(retryCount * 500, 5e3)
179
- });
166
+ return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
167
+ if (error.status === 404) {
168
+ return void 0;
169
+ }
170
+ throw error;
171
+ });
172
+ },
173
+ validate: (response) => response !== void 0,
174
+ aggregator: () => retryCount += 1,
175
+ error: {
176
+ validate: () => retryCount >= 50,
177
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
178
+ },
179
+ timeout: () => Math.min(retryCount * 500, 5e3)
180
+ });
181
+ }
182
+ offset += waitBatchSize;
180
183
  }
181
184
  }
182
185
  return responses;