@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/README.md +4 -4
- package/dist/browser.d.ts +1 -1
- package/dist/builds/browser.js +37 -28
- package/dist/builds/browser.js.map +1 -1
- package/dist/builds/browser.min.js +4 -4
- package/dist/builds/browser.min.js.map +1 -1
- package/dist/builds/browser.umd.js +4 -4
- package/dist/builds/fetch.js +37 -28
- package/dist/builds/fetch.js.map +1 -1
- package/dist/builds/node.cjs +37 -28
- package/dist/builds/node.cjs.map +1 -1
- package/dist/builds/node.js +37 -28
- package/dist/builds/node.js.map +1 -1
- package/dist/builds/worker.js +37 -28
- package/dist/builds/worker.js.map +1 -1
- package/dist/fetch.d.ts +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/src/ingestionClient.cjs +37 -28
- package/dist/src/ingestionClient.cjs.map +1 -1
- package/dist/src/ingestionClient.js +37 -28
- package/dist/src/ingestionClient.js.map +1 -1
- package/dist/worker.d.ts +1 -1
- package/package.json +9 -9
package/dist/builds/node.cjs
CHANGED
|
@@ -33,7 +33,7 @@ var import_requester_node_http = require("@algolia/requester-node-http");
|
|
|
33
33
|
|
|
34
34
|
// src/ingestionClient.ts
|
|
35
35
|
var import_client_common = require("@algolia/client-common");
|
|
36
|
-
var apiClientVersion = "1.55.
|
|
36
|
+
var apiClientVersion = "1.55.2";
|
|
37
37
|
var REGIONS = ["eu", "us"];
|
|
38
38
|
function getDefaultHosts(region) {
|
|
39
39
|
const url = "data.{region}.algolia.com".replace("{region}", region);
|
|
@@ -142,10 +142,41 @@ function createIngestionClient({
|
|
|
142
142
|
referenceIndexName,
|
|
143
143
|
maxRetries = 100
|
|
144
144
|
}, requestOptions) {
|
|
145
|
+
if (batchSize < 1) {
|
|
146
|
+
throw new Error("`batchSize` must be at least 1.");
|
|
147
|
+
}
|
|
145
148
|
let records = [];
|
|
146
149
|
let offset = 0;
|
|
147
150
|
const responses = [];
|
|
148
151
|
const waitBatchSize = Math.floor(batchSize / 10) || batchSize;
|
|
152
|
+
const waitForBatch = async (start, end) => {
|
|
153
|
+
for (const resp of responses.slice(start, end)) {
|
|
154
|
+
if (!resp.eventID) {
|
|
155
|
+
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
156
|
+
}
|
|
157
|
+
let retryCount = 0;
|
|
158
|
+
await (0, import_client_common.createIterablePromise)({
|
|
159
|
+
func: async () => {
|
|
160
|
+
if (resp.eventID === void 0 || !resp.eventID) {
|
|
161
|
+
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
162
|
+
}
|
|
163
|
+
return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
|
|
164
|
+
if (error.status === 404) {
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
throw error;
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
validate: (response) => response !== void 0,
|
|
171
|
+
aggregator: () => retryCount += 1,
|
|
172
|
+
error: {
|
|
173
|
+
validate: () => retryCount >= maxRetries,
|
|
174
|
+
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.`
|
|
175
|
+
},
|
|
176
|
+
timeout: () => Math.min(retryCount * 1500, 5e3)
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
149
180
|
const objectEntries = objects.entries();
|
|
150
181
|
for (const [i, obj] of objectEntries) {
|
|
151
182
|
records.push(obj);
|
|
@@ -155,36 +186,14 @@ function createIngestionClient({
|
|
|
155
186
|
);
|
|
156
187
|
records = [];
|
|
157
188
|
}
|
|
158
|
-
if (waitForTasks && responses.length
|
|
159
|
-
|
|
160
|
-
if (!resp.eventID) {
|
|
161
|
-
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
162
|
-
}
|
|
163
|
-
let retryCount = 0;
|
|
164
|
-
await (0, import_client_common.createIterablePromise)({
|
|
165
|
-
func: async () => {
|
|
166
|
-
if (resp.eventID === void 0 || !resp.eventID) {
|
|
167
|
-
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
168
|
-
}
|
|
169
|
-
return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
|
|
170
|
-
if (error.status === 404) {
|
|
171
|
-
return void 0;
|
|
172
|
-
}
|
|
173
|
-
throw error;
|
|
174
|
-
});
|
|
175
|
-
},
|
|
176
|
-
validate: (response) => response !== void 0,
|
|
177
|
-
aggregator: () => retryCount += 1,
|
|
178
|
-
error: {
|
|
179
|
-
validate: () => retryCount >= maxRetries,
|
|
180
|
-
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.`
|
|
181
|
-
},
|
|
182
|
-
timeout: () => Math.min(retryCount * 1500, 5e3)
|
|
183
|
-
});
|
|
184
|
-
}
|
|
189
|
+
if (waitForTasks && responses.length - offset >= waitBatchSize) {
|
|
190
|
+
await waitForBatch(offset, offset + waitBatchSize);
|
|
185
191
|
offset += waitBatchSize;
|
|
186
192
|
}
|
|
187
193
|
}
|
|
194
|
+
if (waitForTasks) {
|
|
195
|
+
await waitForBatch(offset, responses.length);
|
|
196
|
+
}
|
|
188
197
|
return responses;
|
|
189
198
|
},
|
|
190
199
|
/**
|