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