@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.
@@ -10,7 +10,7 @@ import {
10
10
  getAlgoliaAgent,
11
11
  validateRequired
12
12
  } from "@algolia/client-common";
13
- var apiClientVersion = "1.55.1";
13
+ var apiClientVersion = "1.55.2";
14
14
  var REGIONS = ["eu", "us"];
15
15
  function getDefaultHosts(region) {
16
16
  const url = "data.{region}.algolia.com".replace("{region}", region);
@@ -119,10 +119,41 @@ function createIngestionClient({
119
119
  referenceIndexName,
120
120
  maxRetries = 100
121
121
  }, requestOptions) {
122
+ if (batchSize < 1) {
123
+ throw new Error("`batchSize` must be at least 1.");
124
+ }
122
125
  let records = [];
123
126
  let offset = 0;
124
127
  const responses = [];
125
128
  const waitBatchSize = Math.floor(batchSize / 10) || batchSize;
129
+ const waitForBatch = async (start, end) => {
130
+ for (const resp of responses.slice(start, end)) {
131
+ if (!resp.eventID) {
132
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
133
+ }
134
+ let retryCount = 0;
135
+ await createIterablePromise({
136
+ func: async () => {
137
+ if (resp.eventID === void 0 || !resp.eventID) {
138
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
139
+ }
140
+ return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
141
+ if (error.status === 404) {
142
+ return void 0;
143
+ }
144
+ throw error;
145
+ });
146
+ },
147
+ validate: (response) => response !== void 0,
148
+ aggregator: () => retryCount += 1,
149
+ error: {
150
+ validate: () => retryCount >= maxRetries,
151
+ 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.`
152
+ },
153
+ timeout: () => Math.min(retryCount * 1500, 5e3)
154
+ });
155
+ }
156
+ };
126
157
  const objectEntries = objects.entries();
127
158
  for (const [i, obj] of objectEntries) {
128
159
  records.push(obj);
@@ -132,36 +163,14 @@ function createIngestionClient({
132
163
  );
133
164
  records = [];
134
165
  }
135
- if (waitForTasks && responses.length > 0 && (responses.length % waitBatchSize === 0 || i === objects.length - 1)) {
136
- for (const resp of responses.slice(offset, offset + waitBatchSize)) {
137
- if (!resp.eventID) {
138
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
139
- }
140
- let retryCount = 0;
141
- await createIterablePromise({
142
- func: async () => {
143
- if (resp.eventID === void 0 || !resp.eventID) {
144
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
145
- }
146
- return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
147
- if (error.status === 404) {
148
- return void 0;
149
- }
150
- throw error;
151
- });
152
- },
153
- validate: (response) => response !== void 0,
154
- aggregator: () => retryCount += 1,
155
- error: {
156
- validate: () => retryCount >= maxRetries,
157
- 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.`
158
- },
159
- timeout: () => Math.min(retryCount * 1500, 5e3)
160
- });
161
- }
166
+ if (waitForTasks && responses.length - offset >= waitBatchSize) {
167
+ await waitForBatch(offset, offset + waitBatchSize);
162
168
  offset += waitBatchSize;
163
169
  }
164
170
  }
171
+ if (waitForTasks) {
172
+ await waitForBatch(offset, responses.length);
173
+ }
165
174
  return responses;
166
175
  },
167
176
  /**