@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/worker.js
CHANGED
|
@@ -3,8 +3,8 @@ import { createMemoryCache, createNullCache, createNullLogger } from "@algolia/c
|
|
|
3
3
|
import { createFetchRequester } from "@algolia/requester-fetch";
|
|
4
4
|
|
|
5
5
|
// src/ingestionClient.ts
|
|
6
|
-
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
|
|
7
|
-
var apiClientVersion = "1.
|
|
6
|
+
import { createAuth, createIterablePromise, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
|
|
7
|
+
var apiClientVersion = "1.29.0";
|
|
8
8
|
var REGIONS = ["eu", "us"];
|
|
9
9
|
function getDefaultHosts(region) {
|
|
10
10
|
const url = "data.{region}.algolia.com".replace("{region}", region);
|
|
@@ -90,6 +90,69 @@ function createIngestionClient({
|
|
|
90
90
|
transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
|
+
/**
|
|
94
|
+
* 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/).
|
|
95
|
+
*
|
|
96
|
+
* @summary Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
|
|
97
|
+
* @param chunkedPush - The `chunkedPush` object.
|
|
98
|
+
* @param chunkedPush.indexName - The `indexName` to replace `objects` in.
|
|
99
|
+
* @param chunkedPush.objects - The array of `objects` to store in the given Algolia `indexName`.
|
|
100
|
+
* @param chunkedPush.action - The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`.
|
|
101
|
+
* @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.
|
|
102
|
+
* @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.
|
|
103
|
+
* @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).
|
|
104
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getEvent` method and merged with the transporter requestOptions.
|
|
105
|
+
*/
|
|
106
|
+
async chunkedPush({
|
|
107
|
+
indexName,
|
|
108
|
+
objects,
|
|
109
|
+
action = "addObject",
|
|
110
|
+
waitForTasks,
|
|
111
|
+
batchSize = 1e3,
|
|
112
|
+
referenceIndexName
|
|
113
|
+
}, requestOptions) {
|
|
114
|
+
let records = [];
|
|
115
|
+
const responses = [];
|
|
116
|
+
const objectEntries = objects.entries();
|
|
117
|
+
for (const [i, obj] of objectEntries) {
|
|
118
|
+
records.push(obj);
|
|
119
|
+
if (records.length === batchSize || i === objects.length - 1) {
|
|
120
|
+
responses.push(
|
|
121
|
+
await this.push({ indexName, pushTaskPayload: { action, records }, referenceIndexName }, requestOptions)
|
|
122
|
+
);
|
|
123
|
+
records = [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
let retryCount = 0;
|
|
127
|
+
if (waitForTasks) {
|
|
128
|
+
for (const resp of responses) {
|
|
129
|
+
if (!resp.eventID) {
|
|
130
|
+
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
131
|
+
}
|
|
132
|
+
await createIterablePromise({
|
|
133
|
+
func: async () => {
|
|
134
|
+
if (resp.eventID === void 0 || !resp.eventID) {
|
|
135
|
+
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
136
|
+
}
|
|
137
|
+
return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
|
|
138
|
+
if (error.status === 404) {
|
|
139
|
+
return void 0;
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
validate: (response) => response !== void 0,
|
|
145
|
+
aggregator: () => retryCount += 1,
|
|
146
|
+
error: {
|
|
147
|
+
validate: () => retryCount >= 50,
|
|
148
|
+
message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
|
|
149
|
+
},
|
|
150
|
+
timeout: () => Math.min(retryCount * 500, 5e3)
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return responses;
|
|
155
|
+
},
|
|
93
156
|
/**
|
|
94
157
|
* Creates a new authentication resource.
|
|
95
158
|
*
|
|
@@ -269,12 +332,6 @@ function createIngestionClient({
|
|
|
269
332
|
if (!transformationCreate.name) {
|
|
270
333
|
throw new Error("Parameter `transformationCreate.name` is required when calling `createTransformation`.");
|
|
271
334
|
}
|
|
272
|
-
if (!transformationCreate.type) {
|
|
273
|
-
throw new Error("Parameter `transformationCreate.type` is required when calling `createTransformation`.");
|
|
274
|
-
}
|
|
275
|
-
if (!transformationCreate.input) {
|
|
276
|
-
throw new Error("Parameter `transformationCreate.input` is required when calling `createTransformation`.");
|
|
277
|
-
}
|
|
278
335
|
const requestPath = "/1/transformations";
|
|
279
336
|
const headers = {};
|
|
280
337
|
const queryParameters = {};
|
|
@@ -290,7 +347,7 @@ function createIngestionClient({
|
|
|
290
347
|
/**
|
|
291
348
|
* This method lets you send requests to the Algolia REST API.
|
|
292
349
|
* @param customDelete - The customDelete object.
|
|
293
|
-
* @param customDelete.path - Path of the endpoint,
|
|
350
|
+
* @param customDelete.path - Path of the endpoint, for example `1/newFeature`.
|
|
294
351
|
* @param customDelete.parameters - Query parameters to apply to the current query.
|
|
295
352
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
296
353
|
*/
|
|
@@ -312,7 +369,7 @@ function createIngestionClient({
|
|
|
312
369
|
/**
|
|
313
370
|
* This method lets you send requests to the Algolia REST API.
|
|
314
371
|
* @param customGet - The customGet object.
|
|
315
|
-
* @param customGet.path - Path of the endpoint,
|
|
372
|
+
* @param customGet.path - Path of the endpoint, for example `1/newFeature`.
|
|
316
373
|
* @param customGet.parameters - Query parameters to apply to the current query.
|
|
317
374
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
318
375
|
*/
|
|
@@ -334,7 +391,7 @@ function createIngestionClient({
|
|
|
334
391
|
/**
|
|
335
392
|
* This method lets you send requests to the Algolia REST API.
|
|
336
393
|
* @param customPost - The customPost object.
|
|
337
|
-
* @param customPost.path - Path of the endpoint,
|
|
394
|
+
* @param customPost.path - Path of the endpoint, for example `1/newFeature`.
|
|
338
395
|
* @param customPost.parameters - Query parameters to apply to the current query.
|
|
339
396
|
* @param customPost.body - Parameters to send with the custom request.
|
|
340
397
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -358,7 +415,7 @@ function createIngestionClient({
|
|
|
358
415
|
/**
|
|
359
416
|
* This method lets you send requests to the Algolia REST API.
|
|
360
417
|
* @param customPut - The customPut object.
|
|
361
|
-
* @param customPut.path - Path of the endpoint,
|
|
418
|
+
* @param customPut.path - Path of the endpoint, for example `1/newFeature`.
|
|
362
419
|
* @param customPut.parameters - Query parameters to apply to the current query.
|
|
363
420
|
* @param customPut.body - Parameters to send with the custom request.
|
|
364
421
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -1307,9 +1364,10 @@ function createIngestionClient({
|
|
|
1307
1364
|
* @param push.indexName - Name of the index on which to perform the operation.
|
|
1308
1365
|
* @param push.pushTaskPayload - The pushTaskPayload object.
|
|
1309
1366
|
* @param push.watch - When provided, the push operation will be synchronous and the API will wait for the ingestion to be finished before responding.
|
|
1367
|
+
* @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).
|
|
1310
1368
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1311
1369
|
*/
|
|
1312
|
-
push({ indexName, pushTaskPayload, watch }, requestOptions) {
|
|
1370
|
+
push({ indexName, pushTaskPayload, watch, referenceIndexName }, requestOptions) {
|
|
1313
1371
|
if (!indexName) {
|
|
1314
1372
|
throw new Error("Parameter `indexName` is required when calling `push`.");
|
|
1315
1373
|
}
|
|
@@ -1328,6 +1386,9 @@ function createIngestionClient({
|
|
|
1328
1386
|
if (watch !== void 0) {
|
|
1329
1387
|
queryParameters["watch"] = watch.toString();
|
|
1330
1388
|
}
|
|
1389
|
+
if (referenceIndexName !== void 0) {
|
|
1390
|
+
queryParameters["referenceIndexName"] = referenceIndexName.toString();
|
|
1391
|
+
}
|
|
1331
1392
|
const request = {
|
|
1332
1393
|
method: "POST",
|
|
1333
1394
|
path: requestPath,
|
|
@@ -1704,9 +1765,6 @@ function createIngestionClient({
|
|
|
1704
1765
|
if (!transformationTry) {
|
|
1705
1766
|
throw new Error("Parameter `transformationTry` is required when calling `tryTransformation`.");
|
|
1706
1767
|
}
|
|
1707
|
-
if (!transformationTry.code) {
|
|
1708
|
-
throw new Error("Parameter `transformationTry.code` is required when calling `tryTransformation`.");
|
|
1709
|
-
}
|
|
1710
1768
|
if (!transformationTry.sampleRecord) {
|
|
1711
1769
|
throw new Error("Parameter `transformationTry.sampleRecord` is required when calling `tryTransformation`.");
|
|
1712
1770
|
}
|
|
@@ -1741,9 +1799,6 @@ function createIngestionClient({
|
|
|
1741
1799
|
if (!transformationTry) {
|
|
1742
1800
|
throw new Error("Parameter `transformationTry` is required when calling `tryTransformationBeforeUpdate`.");
|
|
1743
1801
|
}
|
|
1744
|
-
if (!transformationTry.code) {
|
|
1745
|
-
throw new Error("Parameter `transformationTry.code` is required when calling `tryTransformationBeforeUpdate`.");
|
|
1746
|
-
}
|
|
1747
1802
|
if (!transformationTry.sampleRecord) {
|
|
1748
1803
|
throw new Error(
|
|
1749
1804
|
"Parameter `transformationTry.sampleRecord` is required when calling `tryTransformationBeforeUpdate`."
|
|
@@ -1934,12 +1989,6 @@ function createIngestionClient({
|
|
|
1934
1989
|
if (!transformationCreate.name) {
|
|
1935
1990
|
throw new Error("Parameter `transformationCreate.name` is required when calling `updateTransformation`.");
|
|
1936
1991
|
}
|
|
1937
|
-
if (!transformationCreate.type) {
|
|
1938
|
-
throw new Error("Parameter `transformationCreate.type` is required when calling `updateTransformation`.");
|
|
1939
|
-
}
|
|
1940
|
-
if (!transformationCreate.input) {
|
|
1941
|
-
throw new Error("Parameter `transformationCreate.input` is required when calling `updateTransformation`.");
|
|
1942
|
-
}
|
|
1943
1992
|
const requestPath = "/1/transformations/{transformationID}".replace(
|
|
1944
1993
|
"{transformationID}",
|
|
1945
1994
|
encodeURIComponent(transformationID)
|