@algolia/ingestion 1.28.0 → 1.30.0
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 +55 -15
- package/dist/builds/browser.js +69 -6
- package/dist/builds/browser.js.map +1 -1
- package/dist/builds/browser.min.js +1 -1
- package/dist/builds/browser.min.js.map +1 -1
- package/dist/builds/browser.umd.js +5 -5
- package/dist/builds/fetch.js +69 -6
- package/dist/builds/fetch.js.map +1 -1
- package/dist/builds/node.cjs +68 -5
- package/dist/builds/node.cjs.map +1 -1
- package/dist/builds/node.js +69 -6
- package/dist/builds/node.js.map +1 -1
- package/dist/builds/worker.js +69 -6
- package/dist/builds/worker.js.map +1 -1
- package/dist/fetch.d.ts +55 -15
- package/dist/node.d.cts +55 -15
- package/dist/node.d.ts +55 -15
- package/dist/src/ingestionClient.cjs +68 -5
- package/dist/src/ingestionClient.cjs.map +1 -1
- package/dist/src/ingestionClient.js +74 -11
- package/dist/src/ingestionClient.js.map +1 -1
- package/dist/worker.d.ts +55 -15
- package/package.json +6 -6
package/dist/builds/node.cjs
CHANGED
|
@@ -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.
|
|
35
|
+
var apiClientVersion = "1.30.0";
|
|
36
36
|
var REGIONS = ["eu", "us"];
|
|
37
37
|
function getDefaultHosts(region) {
|
|
38
38
|
const url = "data.{region}.algolia.com".replace("{region}", region);
|
|
@@ -118,6 +118,69 @@ function createIngestionClient({
|
|
|
118
118
|
transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
|
+
/**
|
|
122
|
+
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `push` requests by leveraging the Transformation pipeline setup in the Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/).
|
|
123
|
+
*
|
|
124
|
+
* @summary Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
|
|
125
|
+
* @param chunkedPush - The `chunkedPush` object.
|
|
126
|
+
* @param chunkedPush.indexName - The `indexName` to replace `objects` in.
|
|
127
|
+
* @param chunkedPush.objects - The array of `objects` to store in the given Algolia `indexName`.
|
|
128
|
+
* @param chunkedPush.action - The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`.
|
|
129
|
+
* @param chunkedPush.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
|
|
130
|
+
* @param chunkedPush.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
|
|
131
|
+
* @param chunkedPush.referenceIndexName - This is required when targeting an index that does not have a push connector setup (e.g. a tmp index), but you wish to attach another index's transformation to it (e.g. the source index name).
|
|
132
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getEvent` method and merged with the transporter requestOptions.
|
|
133
|
+
*/
|
|
134
|
+
async chunkedPush({
|
|
135
|
+
indexName,
|
|
136
|
+
objects,
|
|
137
|
+
action = "addObject",
|
|
138
|
+
waitForTasks,
|
|
139
|
+
batchSize = 1e3,
|
|
140
|
+
referenceIndexName
|
|
141
|
+
}, requestOptions) {
|
|
142
|
+
let records = [];
|
|
143
|
+
const responses = [];
|
|
144
|
+
const objectEntries = objects.entries();
|
|
145
|
+
for (const [i, obj] of objectEntries) {
|
|
146
|
+
records.push(obj);
|
|
147
|
+
if (records.length === batchSize || i === objects.length - 1) {
|
|
148
|
+
responses.push(
|
|
149
|
+
await this.push({ indexName, pushTaskPayload: { action, records }, referenceIndexName }, requestOptions)
|
|
150
|
+
);
|
|
151
|
+
records = [];
|
|
152
|
+
}
|
|
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;
|
|
168
|
+
}
|
|
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
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return responses;
|
|
183
|
+
},
|
|
121
184
|
/**
|
|
122
185
|
* Creates a new authentication resource.
|
|
123
186
|
*
|
|
@@ -312,7 +375,7 @@ function createIngestionClient({
|
|
|
312
375
|
/**
|
|
313
376
|
* This method lets you send requests to the Algolia REST API.
|
|
314
377
|
* @param customDelete - The customDelete object.
|
|
315
|
-
* @param customDelete.path - Path of the endpoint,
|
|
378
|
+
* @param customDelete.path - Path of the endpoint, for example `1/newFeature`.
|
|
316
379
|
* @param customDelete.parameters - Query parameters to apply to the current query.
|
|
317
380
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
318
381
|
*/
|
|
@@ -334,7 +397,7 @@ function createIngestionClient({
|
|
|
334
397
|
/**
|
|
335
398
|
* This method lets you send requests to the Algolia REST API.
|
|
336
399
|
* @param customGet - The customGet object.
|
|
337
|
-
* @param customGet.path - Path of the endpoint,
|
|
400
|
+
* @param customGet.path - Path of the endpoint, for example `1/newFeature`.
|
|
338
401
|
* @param customGet.parameters - Query parameters to apply to the current query.
|
|
339
402
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
340
403
|
*/
|
|
@@ -356,7 +419,7 @@ function createIngestionClient({
|
|
|
356
419
|
/**
|
|
357
420
|
* This method lets you send requests to the Algolia REST API.
|
|
358
421
|
* @param customPost - The customPost object.
|
|
359
|
-
* @param customPost.path - Path of the endpoint,
|
|
422
|
+
* @param customPost.path - Path of the endpoint, for example `1/newFeature`.
|
|
360
423
|
* @param customPost.parameters - Query parameters to apply to the current query.
|
|
361
424
|
* @param customPost.body - Parameters to send with the custom request.
|
|
362
425
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -380,7 +443,7 @@ function createIngestionClient({
|
|
|
380
443
|
/**
|
|
381
444
|
* This method lets you send requests to the Algolia REST API.
|
|
382
445
|
* @param customPut - The customPut object.
|
|
383
|
-
* @param customPut.path - Path of the endpoint,
|
|
446
|
+
* @param customPut.path - Path of the endpoint, for example `1/newFeature`.
|
|
384
447
|
* @param customPut.parameters - Query parameters to apply to the current query.
|
|
385
448
|
* @param customPut.body - Parameters to send with the custom request.
|
|
386
449
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|