@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/browser.js
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
} from "@algolia/client-common";
|
|
9
9
|
|
|
10
10
|
// src/ingestionClient.ts
|
|
11
|
-
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
|
|
12
|
-
var apiClientVersion = "1.
|
|
11
|
+
import { createAuth, createIterablePromise, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
|
|
12
|
+
var apiClientVersion = "1.29.0";
|
|
13
13
|
var REGIONS = ["eu", "us"];
|
|
14
14
|
function getDefaultHosts(region) {
|
|
15
15
|
const url = "data.{region}.algolia.com".replace("{region}", region);
|
|
@@ -95,6 +95,69 @@ function createIngestionClient({
|
|
|
95
95
|
transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
|
+
/**
|
|
99
|
+
* 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/).
|
|
100
|
+
*
|
|
101
|
+
* @summary Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
|
|
102
|
+
* @param chunkedPush - The `chunkedPush` object.
|
|
103
|
+
* @param chunkedPush.indexName - The `indexName` to replace `objects` in.
|
|
104
|
+
* @param chunkedPush.objects - The array of `objects` to store in the given Algolia `indexName`.
|
|
105
|
+
* @param chunkedPush.action - The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`.
|
|
106
|
+
* @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.
|
|
107
|
+
* @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.
|
|
108
|
+
* @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).
|
|
109
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getEvent` method and merged with the transporter requestOptions.
|
|
110
|
+
*/
|
|
111
|
+
async chunkedPush({
|
|
112
|
+
indexName,
|
|
113
|
+
objects,
|
|
114
|
+
action = "addObject",
|
|
115
|
+
waitForTasks,
|
|
116
|
+
batchSize = 1e3,
|
|
117
|
+
referenceIndexName
|
|
118
|
+
}, requestOptions) {
|
|
119
|
+
let records = [];
|
|
120
|
+
const responses = [];
|
|
121
|
+
const objectEntries = objects.entries();
|
|
122
|
+
for (const [i, obj] of objectEntries) {
|
|
123
|
+
records.push(obj);
|
|
124
|
+
if (records.length === batchSize || i === objects.length - 1) {
|
|
125
|
+
responses.push(
|
|
126
|
+
await this.push({ indexName, pushTaskPayload: { action, records }, referenceIndexName }, requestOptions)
|
|
127
|
+
);
|
|
128
|
+
records = [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
let retryCount = 0;
|
|
132
|
+
if (waitForTasks) {
|
|
133
|
+
for (const resp of responses) {
|
|
134
|
+
if (!resp.eventID) {
|
|
135
|
+
throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
|
|
136
|
+
}
|
|
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 >= 50,
|
|
153
|
+
message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
|
|
154
|
+
},
|
|
155
|
+
timeout: () => Math.min(retryCount * 500, 5e3)
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return responses;
|
|
160
|
+
},
|
|
98
161
|
/**
|
|
99
162
|
* Creates a new authentication resource.
|
|
100
163
|
*
|
|
@@ -274,12 +337,6 @@ function createIngestionClient({
|
|
|
274
337
|
if (!transformationCreate.name) {
|
|
275
338
|
throw new Error("Parameter `transformationCreate.name` is required when calling `createTransformation`.");
|
|
276
339
|
}
|
|
277
|
-
if (!transformationCreate.type) {
|
|
278
|
-
throw new Error("Parameter `transformationCreate.type` is required when calling `createTransformation`.");
|
|
279
|
-
}
|
|
280
|
-
if (!transformationCreate.input) {
|
|
281
|
-
throw new Error("Parameter `transformationCreate.input` is required when calling `createTransformation`.");
|
|
282
|
-
}
|
|
283
340
|
const requestPath = "/1/transformations";
|
|
284
341
|
const headers = {};
|
|
285
342
|
const queryParameters = {};
|
|
@@ -295,7 +352,7 @@ function createIngestionClient({
|
|
|
295
352
|
/**
|
|
296
353
|
* This method lets you send requests to the Algolia REST API.
|
|
297
354
|
* @param customDelete - The customDelete object.
|
|
298
|
-
* @param customDelete.path - Path of the endpoint,
|
|
355
|
+
* @param customDelete.path - Path of the endpoint, for example `1/newFeature`.
|
|
299
356
|
* @param customDelete.parameters - Query parameters to apply to the current query.
|
|
300
357
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
301
358
|
*/
|
|
@@ -317,7 +374,7 @@ function createIngestionClient({
|
|
|
317
374
|
/**
|
|
318
375
|
* This method lets you send requests to the Algolia REST API.
|
|
319
376
|
* @param customGet - The customGet object.
|
|
320
|
-
* @param customGet.path - Path of the endpoint,
|
|
377
|
+
* @param customGet.path - Path of the endpoint, for example `1/newFeature`.
|
|
321
378
|
* @param customGet.parameters - Query parameters to apply to the current query.
|
|
322
379
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
323
380
|
*/
|
|
@@ -339,7 +396,7 @@ function createIngestionClient({
|
|
|
339
396
|
/**
|
|
340
397
|
* This method lets you send requests to the Algolia REST API.
|
|
341
398
|
* @param customPost - The customPost object.
|
|
342
|
-
* @param customPost.path - Path of the endpoint,
|
|
399
|
+
* @param customPost.path - Path of the endpoint, for example `1/newFeature`.
|
|
343
400
|
* @param customPost.parameters - Query parameters to apply to the current query.
|
|
344
401
|
* @param customPost.body - Parameters to send with the custom request.
|
|
345
402
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -363,7 +420,7 @@ function createIngestionClient({
|
|
|
363
420
|
/**
|
|
364
421
|
* This method lets you send requests to the Algolia REST API.
|
|
365
422
|
* @param customPut - The customPut object.
|
|
366
|
-
* @param customPut.path - Path of the endpoint,
|
|
423
|
+
* @param customPut.path - Path of the endpoint, for example `1/newFeature`.
|
|
367
424
|
* @param customPut.parameters - Query parameters to apply to the current query.
|
|
368
425
|
* @param customPut.body - Parameters to send with the custom request.
|
|
369
426
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -1312,9 +1369,10 @@ function createIngestionClient({
|
|
|
1312
1369
|
* @param push.indexName - Name of the index on which to perform the operation.
|
|
1313
1370
|
* @param push.pushTaskPayload - The pushTaskPayload object.
|
|
1314
1371
|
* @param push.watch - When provided, the push operation will be synchronous and the API will wait for the ingestion to be finished before responding.
|
|
1372
|
+
* @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).
|
|
1315
1373
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1316
1374
|
*/
|
|
1317
|
-
push({ indexName, pushTaskPayload, watch }, requestOptions) {
|
|
1375
|
+
push({ indexName, pushTaskPayload, watch, referenceIndexName }, requestOptions) {
|
|
1318
1376
|
if (!indexName) {
|
|
1319
1377
|
throw new Error("Parameter `indexName` is required when calling `push`.");
|
|
1320
1378
|
}
|
|
@@ -1333,6 +1391,9 @@ function createIngestionClient({
|
|
|
1333
1391
|
if (watch !== void 0) {
|
|
1334
1392
|
queryParameters["watch"] = watch.toString();
|
|
1335
1393
|
}
|
|
1394
|
+
if (referenceIndexName !== void 0) {
|
|
1395
|
+
queryParameters["referenceIndexName"] = referenceIndexName.toString();
|
|
1396
|
+
}
|
|
1336
1397
|
const request = {
|
|
1337
1398
|
method: "POST",
|
|
1338
1399
|
path: requestPath,
|
|
@@ -1709,9 +1770,6 @@ function createIngestionClient({
|
|
|
1709
1770
|
if (!transformationTry) {
|
|
1710
1771
|
throw new Error("Parameter `transformationTry` is required when calling `tryTransformation`.");
|
|
1711
1772
|
}
|
|
1712
|
-
if (!transformationTry.code) {
|
|
1713
|
-
throw new Error("Parameter `transformationTry.code` is required when calling `tryTransformation`.");
|
|
1714
|
-
}
|
|
1715
1773
|
if (!transformationTry.sampleRecord) {
|
|
1716
1774
|
throw new Error("Parameter `transformationTry.sampleRecord` is required when calling `tryTransformation`.");
|
|
1717
1775
|
}
|
|
@@ -1746,9 +1804,6 @@ function createIngestionClient({
|
|
|
1746
1804
|
if (!transformationTry) {
|
|
1747
1805
|
throw new Error("Parameter `transformationTry` is required when calling `tryTransformationBeforeUpdate`.");
|
|
1748
1806
|
}
|
|
1749
|
-
if (!transformationTry.code) {
|
|
1750
|
-
throw new Error("Parameter `transformationTry.code` is required when calling `tryTransformationBeforeUpdate`.");
|
|
1751
|
-
}
|
|
1752
1807
|
if (!transformationTry.sampleRecord) {
|
|
1753
1808
|
throw new Error(
|
|
1754
1809
|
"Parameter `transformationTry.sampleRecord` is required when calling `tryTransformationBeforeUpdate`."
|
|
@@ -1939,12 +1994,6 @@ function createIngestionClient({
|
|
|
1939
1994
|
if (!transformationCreate.name) {
|
|
1940
1995
|
throw new Error("Parameter `transformationCreate.name` is required when calling `updateTransformation`.");
|
|
1941
1996
|
}
|
|
1942
|
-
if (!transformationCreate.type) {
|
|
1943
|
-
throw new Error("Parameter `transformationCreate.type` is required when calling `updateTransformation`.");
|
|
1944
|
-
}
|
|
1945
|
-
if (!transformationCreate.input) {
|
|
1946
|
-
throw new Error("Parameter `transformationCreate.input` is required when calling `updateTransformation`.");
|
|
1947
|
-
}
|
|
1948
1997
|
const requestPath = "/1/transformations/{transformationID}".replace(
|
|
1949
1998
|
"{transformationID}",
|
|
1950
1999
|
encodeURIComponent(transformationID)
|