@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
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.29.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
|
*
|
|
@@ -297,12 +360,6 @@ function createIngestionClient({
|
|
|
297
360
|
if (!transformationCreate.name) {
|
|
298
361
|
throw new Error("Parameter `transformationCreate.name` is required when calling `createTransformation`.");
|
|
299
362
|
}
|
|
300
|
-
if (!transformationCreate.type) {
|
|
301
|
-
throw new Error("Parameter `transformationCreate.type` is required when calling `createTransformation`.");
|
|
302
|
-
}
|
|
303
|
-
if (!transformationCreate.input) {
|
|
304
|
-
throw new Error("Parameter `transformationCreate.input` is required when calling `createTransformation`.");
|
|
305
|
-
}
|
|
306
363
|
const requestPath = "/1/transformations";
|
|
307
364
|
const headers = {};
|
|
308
365
|
const queryParameters = {};
|
|
@@ -318,7 +375,7 @@ function createIngestionClient({
|
|
|
318
375
|
/**
|
|
319
376
|
* This method lets you send requests to the Algolia REST API.
|
|
320
377
|
* @param customDelete - The customDelete object.
|
|
321
|
-
* @param customDelete.path - Path of the endpoint,
|
|
378
|
+
* @param customDelete.path - Path of the endpoint, for example `1/newFeature`.
|
|
322
379
|
* @param customDelete.parameters - Query parameters to apply to the current query.
|
|
323
380
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
324
381
|
*/
|
|
@@ -340,7 +397,7 @@ function createIngestionClient({
|
|
|
340
397
|
/**
|
|
341
398
|
* This method lets you send requests to the Algolia REST API.
|
|
342
399
|
* @param customGet - The customGet object.
|
|
343
|
-
* @param customGet.path - Path of the endpoint,
|
|
400
|
+
* @param customGet.path - Path of the endpoint, for example `1/newFeature`.
|
|
344
401
|
* @param customGet.parameters - Query parameters to apply to the current query.
|
|
345
402
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
346
403
|
*/
|
|
@@ -362,7 +419,7 @@ function createIngestionClient({
|
|
|
362
419
|
/**
|
|
363
420
|
* This method lets you send requests to the Algolia REST API.
|
|
364
421
|
* @param customPost - The customPost object.
|
|
365
|
-
* @param customPost.path - Path of the endpoint,
|
|
422
|
+
* @param customPost.path - Path of the endpoint, for example `1/newFeature`.
|
|
366
423
|
* @param customPost.parameters - Query parameters to apply to the current query.
|
|
367
424
|
* @param customPost.body - Parameters to send with the custom request.
|
|
368
425
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -386,7 +443,7 @@ function createIngestionClient({
|
|
|
386
443
|
/**
|
|
387
444
|
* This method lets you send requests to the Algolia REST API.
|
|
388
445
|
* @param customPut - The customPut object.
|
|
389
|
-
* @param customPut.path - Path of the endpoint,
|
|
446
|
+
* @param customPut.path - Path of the endpoint, for example `1/newFeature`.
|
|
390
447
|
* @param customPut.parameters - Query parameters to apply to the current query.
|
|
391
448
|
* @param customPut.body - Parameters to send with the custom request.
|
|
392
449
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -1335,9 +1392,10 @@ function createIngestionClient({
|
|
|
1335
1392
|
* @param push.indexName - Name of the index on which to perform the operation.
|
|
1336
1393
|
* @param push.pushTaskPayload - The pushTaskPayload object.
|
|
1337
1394
|
* @param push.watch - When provided, the push operation will be synchronous and the API will wait for the ingestion to be finished before responding.
|
|
1395
|
+
* @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).
|
|
1338
1396
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1339
1397
|
*/
|
|
1340
|
-
push({ indexName, pushTaskPayload, watch }, requestOptions) {
|
|
1398
|
+
push({ indexName, pushTaskPayload, watch, referenceIndexName }, requestOptions) {
|
|
1341
1399
|
if (!indexName) {
|
|
1342
1400
|
throw new Error("Parameter `indexName` is required when calling `push`.");
|
|
1343
1401
|
}
|
|
@@ -1356,6 +1414,9 @@ function createIngestionClient({
|
|
|
1356
1414
|
if (watch !== void 0) {
|
|
1357
1415
|
queryParameters["watch"] = watch.toString();
|
|
1358
1416
|
}
|
|
1417
|
+
if (referenceIndexName !== void 0) {
|
|
1418
|
+
queryParameters["referenceIndexName"] = referenceIndexName.toString();
|
|
1419
|
+
}
|
|
1359
1420
|
const request = {
|
|
1360
1421
|
method: "POST",
|
|
1361
1422
|
path: requestPath,
|
|
@@ -1732,9 +1793,6 @@ function createIngestionClient({
|
|
|
1732
1793
|
if (!transformationTry) {
|
|
1733
1794
|
throw new Error("Parameter `transformationTry` is required when calling `tryTransformation`.");
|
|
1734
1795
|
}
|
|
1735
|
-
if (!transformationTry.code) {
|
|
1736
|
-
throw new Error("Parameter `transformationTry.code` is required when calling `tryTransformation`.");
|
|
1737
|
-
}
|
|
1738
1796
|
if (!transformationTry.sampleRecord) {
|
|
1739
1797
|
throw new Error("Parameter `transformationTry.sampleRecord` is required when calling `tryTransformation`.");
|
|
1740
1798
|
}
|
|
@@ -1769,9 +1827,6 @@ function createIngestionClient({
|
|
|
1769
1827
|
if (!transformationTry) {
|
|
1770
1828
|
throw new Error("Parameter `transformationTry` is required when calling `tryTransformationBeforeUpdate`.");
|
|
1771
1829
|
}
|
|
1772
|
-
if (!transformationTry.code) {
|
|
1773
|
-
throw new Error("Parameter `transformationTry.code` is required when calling `tryTransformationBeforeUpdate`.");
|
|
1774
|
-
}
|
|
1775
1830
|
if (!transformationTry.sampleRecord) {
|
|
1776
1831
|
throw new Error(
|
|
1777
1832
|
"Parameter `transformationTry.sampleRecord` is required when calling `tryTransformationBeforeUpdate`."
|
|
@@ -1962,12 +2017,6 @@ function createIngestionClient({
|
|
|
1962
2017
|
if (!transformationCreate.name) {
|
|
1963
2018
|
throw new Error("Parameter `transformationCreate.name` is required when calling `updateTransformation`.");
|
|
1964
2019
|
}
|
|
1965
|
-
if (!transformationCreate.type) {
|
|
1966
|
-
throw new Error("Parameter `transformationCreate.type` is required when calling `updateTransformation`.");
|
|
1967
|
-
}
|
|
1968
|
-
if (!transformationCreate.input) {
|
|
1969
|
-
throw new Error("Parameter `transformationCreate.input` is required when calling `updateTransformation`.");
|
|
1970
|
-
}
|
|
1971
2020
|
const requestPath = "/1/transformations/{transformationID}".replace(
|
|
1972
2021
|
"{transformationID}",
|
|
1973
2022
|
encodeURIComponent(transformationID)
|