@algolia/ingestion 1.27.0 → 1.29.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 +287 -240
- package/dist/builds/browser.js +74 -25
- 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 +74 -25
- package/dist/builds/fetch.js.map +1 -1
- package/dist/builds/node.cjs +73 -24
- package/dist/builds/node.cjs.map +1 -1
- package/dist/builds/node.js +74 -25
- package/dist/builds/node.js.map +1 -1
- package/dist/builds/worker.js +74 -25
- package/dist/builds/worker.js.map +1 -1
- package/dist/fetch.d.ts +287 -240
- package/dist/node.d.cts +287 -240
- package/dist/node.d.ts +287 -240
- package/dist/src/ingestionClient.cjs +73 -24
- package/dist/src/ingestionClient.cjs.map +1 -1
- package/dist/src/ingestionClient.js +79 -30
- package/dist/src/ingestionClient.js.map +1 -1
- package/dist/worker.d.ts +287 -240
- package/package.json +7 -7
|
@@ -29,7 +29,7 @@ __export(ingestionClient_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(ingestionClient_exports);
|
|
31
31
|
var import_client_common = require("@algolia/client-common");
|
|
32
|
-
var apiClientVersion = "1.
|
|
32
|
+
var apiClientVersion = "1.29.0";
|
|
33
33
|
var REGIONS = ["eu", "us"];
|
|
34
34
|
function getDefaultHosts(region) {
|
|
35
35
|
const url = "data.{region}.algolia.com".replace("{region}", region);
|
|
@@ -115,6 +115,69 @@ function createIngestionClient({
|
|
|
115
115
|
transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
|
|
116
116
|
}
|
|
117
117
|
},
|
|
118
|
+
/**
|
|
119
|
+
* 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/).
|
|
120
|
+
*
|
|
121
|
+
* @summary Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
|
|
122
|
+
* @param chunkedPush - The `chunkedPush` object.
|
|
123
|
+
* @param chunkedPush.indexName - The `indexName` to replace `objects` in.
|
|
124
|
+
* @param chunkedPush.objects - The array of `objects` to store in the given Algolia `indexName`.
|
|
125
|
+
* @param chunkedPush.action - The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`.
|
|
126
|
+
* @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.
|
|
127
|
+
* @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.
|
|
128
|
+
* @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).
|
|
129
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getEvent` method and merged with the transporter requestOptions.
|
|
130
|
+
*/
|
|
131
|
+
async chunkedPush({
|
|
132
|
+
indexName,
|
|
133
|
+
objects,
|
|
134
|
+
action = "addObject",
|
|
135
|
+
waitForTasks,
|
|
136
|
+
batchSize = 1e3,
|
|
137
|
+
referenceIndexName
|
|
138
|
+
}, requestOptions) {
|
|
139
|
+
let records = [];
|
|
140
|
+
const responses = [];
|
|
141
|
+
const objectEntries = objects.entries();
|
|
142
|
+
for (const [i, obj] of objectEntries) {
|
|
143
|
+
records.push(obj);
|
|
144
|
+
if (records.length === batchSize || i === objects.length - 1) {
|
|
145
|
+
responses.push(
|
|
146
|
+
await this.push({ indexName, pushTaskPayload: { action, records }, referenceIndexName }, requestOptions)
|
|
147
|
+
);
|
|
148
|
+
records = [];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
let retryCount = 0;
|
|
152
|
+
if (waitForTasks) {
|
|
153
|
+
for (const resp of responses) {
|
|
154
|
+
if (!resp.eventID) {
|
|
155
|
+
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
156
|
+
}
|
|
157
|
+
await (0, import_client_common.createIterablePromise)({
|
|
158
|
+
func: async () => {
|
|
159
|
+
if (resp.eventID === void 0 || !resp.eventID) {
|
|
160
|
+
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
161
|
+
}
|
|
162
|
+
return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
|
|
163
|
+
if (error.status === 404) {
|
|
164
|
+
return void 0;
|
|
165
|
+
}
|
|
166
|
+
throw error;
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
validate: (response) => response !== void 0,
|
|
170
|
+
aggregator: () => retryCount += 1,
|
|
171
|
+
error: {
|
|
172
|
+
validate: () => retryCount >= 50,
|
|
173
|
+
message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
|
|
174
|
+
},
|
|
175
|
+
timeout: () => Math.min(retryCount * 500, 5e3)
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return responses;
|
|
180
|
+
},
|
|
118
181
|
/**
|
|
119
182
|
* Creates a new authentication resource.
|
|
120
183
|
*
|
|
@@ -294,12 +357,6 @@ function createIngestionClient({
|
|
|
294
357
|
if (!transformationCreate.name) {
|
|
295
358
|
throw new Error("Parameter `transformationCreate.name` is required when calling `createTransformation`.");
|
|
296
359
|
}
|
|
297
|
-
if (!transformationCreate.type) {
|
|
298
|
-
throw new Error("Parameter `transformationCreate.type` is required when calling `createTransformation`.");
|
|
299
|
-
}
|
|
300
|
-
if (!transformationCreate.input) {
|
|
301
|
-
throw new Error("Parameter `transformationCreate.input` is required when calling `createTransformation`.");
|
|
302
|
-
}
|
|
303
360
|
const requestPath = "/1/transformations";
|
|
304
361
|
const headers = {};
|
|
305
362
|
const queryParameters = {};
|
|
@@ -315,7 +372,7 @@ function createIngestionClient({
|
|
|
315
372
|
/**
|
|
316
373
|
* This method lets you send requests to the Algolia REST API.
|
|
317
374
|
* @param customDelete - The customDelete object.
|
|
318
|
-
* @param customDelete.path - Path of the endpoint,
|
|
375
|
+
* @param customDelete.path - Path of the endpoint, for example `1/newFeature`.
|
|
319
376
|
* @param customDelete.parameters - Query parameters to apply to the current query.
|
|
320
377
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
321
378
|
*/
|
|
@@ -337,7 +394,7 @@ function createIngestionClient({
|
|
|
337
394
|
/**
|
|
338
395
|
* This method lets you send requests to the Algolia REST API.
|
|
339
396
|
* @param customGet - The customGet object.
|
|
340
|
-
* @param customGet.path - Path of the endpoint,
|
|
397
|
+
* @param customGet.path - Path of the endpoint, for example `1/newFeature`.
|
|
341
398
|
* @param customGet.parameters - Query parameters to apply to the current query.
|
|
342
399
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
343
400
|
*/
|
|
@@ -359,7 +416,7 @@ function createIngestionClient({
|
|
|
359
416
|
/**
|
|
360
417
|
* This method lets you send requests to the Algolia REST API.
|
|
361
418
|
* @param customPost - The customPost object.
|
|
362
|
-
* @param customPost.path - Path of the endpoint,
|
|
419
|
+
* @param customPost.path - Path of the endpoint, for example `1/newFeature`.
|
|
363
420
|
* @param customPost.parameters - Query parameters to apply to the current query.
|
|
364
421
|
* @param customPost.body - Parameters to send with the custom request.
|
|
365
422
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -383,7 +440,7 @@ function createIngestionClient({
|
|
|
383
440
|
/**
|
|
384
441
|
* This method lets you send requests to the Algolia REST API.
|
|
385
442
|
* @param customPut - The customPut object.
|
|
386
|
-
* @param customPut.path - Path of the endpoint,
|
|
443
|
+
* @param customPut.path - Path of the endpoint, for example `1/newFeature`.
|
|
387
444
|
* @param customPut.parameters - Query parameters to apply to the current query.
|
|
388
445
|
* @param customPut.body - Parameters to send with the custom request.
|
|
389
446
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -1332,9 +1389,10 @@ function createIngestionClient({
|
|
|
1332
1389
|
* @param push.indexName - Name of the index on which to perform the operation.
|
|
1333
1390
|
* @param push.pushTaskPayload - The pushTaskPayload object.
|
|
1334
1391
|
* @param push.watch - When provided, the push operation will be synchronous and the API will wait for the ingestion to be finished before responding.
|
|
1392
|
+
* @param push.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).
|
|
1335
1393
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1336
1394
|
*/
|
|
1337
|
-
push({ indexName, pushTaskPayload, watch }, requestOptions) {
|
|
1395
|
+
push({ indexName, pushTaskPayload, watch, referenceIndexName }, requestOptions) {
|
|
1338
1396
|
if (!indexName) {
|
|
1339
1397
|
throw new Error("Parameter `indexName` is required when calling `push`.");
|
|
1340
1398
|
}
|
|
@@ -1353,6 +1411,9 @@ function createIngestionClient({
|
|
|
1353
1411
|
if (watch !== void 0) {
|
|
1354
1412
|
queryParameters["watch"] = watch.toString();
|
|
1355
1413
|
}
|
|
1414
|
+
if (referenceIndexName !== void 0) {
|
|
1415
|
+
queryParameters["referenceIndexName"] = referenceIndexName.toString();
|
|
1416
|
+
}
|
|
1356
1417
|
const request = {
|
|
1357
1418
|
method: "POST",
|
|
1358
1419
|
path: requestPath,
|
|
@@ -1729,9 +1790,6 @@ function createIngestionClient({
|
|
|
1729
1790
|
if (!transformationTry) {
|
|
1730
1791
|
throw new Error("Parameter `transformationTry` is required when calling `tryTransformation`.");
|
|
1731
1792
|
}
|
|
1732
|
-
if (!transformationTry.code) {
|
|
1733
|
-
throw new Error("Parameter `transformationTry.code` is required when calling `tryTransformation`.");
|
|
1734
|
-
}
|
|
1735
1793
|
if (!transformationTry.sampleRecord) {
|
|
1736
1794
|
throw new Error("Parameter `transformationTry.sampleRecord` is required when calling `tryTransformation`.");
|
|
1737
1795
|
}
|
|
@@ -1766,9 +1824,6 @@ function createIngestionClient({
|
|
|
1766
1824
|
if (!transformationTry) {
|
|
1767
1825
|
throw new Error("Parameter `transformationTry` is required when calling `tryTransformationBeforeUpdate`.");
|
|
1768
1826
|
}
|
|
1769
|
-
if (!transformationTry.code) {
|
|
1770
|
-
throw new Error("Parameter `transformationTry.code` is required when calling `tryTransformationBeforeUpdate`.");
|
|
1771
|
-
}
|
|
1772
1827
|
if (!transformationTry.sampleRecord) {
|
|
1773
1828
|
throw new Error(
|
|
1774
1829
|
"Parameter `transformationTry.sampleRecord` is required when calling `tryTransformationBeforeUpdate`."
|
|
@@ -1959,12 +2014,6 @@ function createIngestionClient({
|
|
|
1959
2014
|
if (!transformationCreate.name) {
|
|
1960
2015
|
throw new Error("Parameter `transformationCreate.name` is required when calling `updateTransformation`.");
|
|
1961
2016
|
}
|
|
1962
|
-
if (!transformationCreate.type) {
|
|
1963
|
-
throw new Error("Parameter `transformationCreate.type` is required when calling `updateTransformation`.");
|
|
1964
|
-
}
|
|
1965
|
-
if (!transformationCreate.input) {
|
|
1966
|
-
throw new Error("Parameter `transformationCreate.input` is required when calling `updateTransformation`.");
|
|
1967
|
-
}
|
|
1968
2017
|
const requestPath = "/1/transformations/{transformationID}".replace(
|
|
1969
2018
|
"{transformationID}",
|
|
1970
2019
|
encodeURIComponent(transformationID)
|