@algolia/ingestion 1.55.0 → 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 +42 -33
- 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
|
/**
|
|
@@ -1342,7 +1351,7 @@ function createIngestionClient({
|
|
|
1342
1351
|
connect: 18e4,
|
|
1343
1352
|
read: 18e4,
|
|
1344
1353
|
write: 18e4,
|
|
1345
|
-
...requestOptions
|
|
1354
|
+
...requestOptions == null ? void 0 : requestOptions.timeouts
|
|
1346
1355
|
}
|
|
1347
1356
|
};
|
|
1348
1357
|
return transporter.request(request, requestOptions);
|
|
@@ -1383,7 +1392,7 @@ function createIngestionClient({
|
|
|
1383
1392
|
connect: 18e4,
|
|
1384
1393
|
read: 18e4,
|
|
1385
1394
|
write: 18e4,
|
|
1386
|
-
...requestOptions
|
|
1395
|
+
...requestOptions == null ? void 0 : requestOptions.timeouts
|
|
1387
1396
|
}
|
|
1388
1397
|
};
|
|
1389
1398
|
return transporter.request(request, requestOptions);
|
|
@@ -1684,7 +1693,7 @@ function createIngestionClient({
|
|
|
1684
1693
|
connect: 18e4,
|
|
1685
1694
|
read: 18e4,
|
|
1686
1695
|
write: 18e4,
|
|
1687
|
-
...requestOptions
|
|
1696
|
+
...requestOptions == null ? void 0 : requestOptions.timeouts
|
|
1688
1697
|
}
|
|
1689
1698
|
};
|
|
1690
1699
|
return transporter.request(request, requestOptions);
|
|
@@ -1949,7 +1958,7 @@ function createIngestionClient({
|
|
|
1949
1958
|
connect: 18e4,
|
|
1950
1959
|
read: 18e4,
|
|
1951
1960
|
write: 18e4,
|
|
1952
|
-
...requestOptions
|
|
1961
|
+
...requestOptions == null ? void 0 : requestOptions.timeouts
|
|
1953
1962
|
}
|
|
1954
1963
|
};
|
|
1955
1964
|
return transporter.request(request, requestOptions);
|
|
@@ -1984,7 +1993,7 @@ function createIngestionClient({
|
|
|
1984
1993
|
connect: 18e4,
|
|
1985
1994
|
read: 18e4,
|
|
1986
1995
|
write: 18e4,
|
|
1987
|
-
...requestOptions
|
|
1996
|
+
...requestOptions == null ? void 0 : requestOptions.timeouts
|
|
1988
1997
|
}
|
|
1989
1998
|
};
|
|
1990
1999
|
return transporter.request(request, requestOptions);
|