@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/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.30.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
|
*
|
|
@@ -284,7 +347,7 @@ function createIngestionClient({
|
|
|
284
347
|
/**
|
|
285
348
|
* This method lets you send requests to the Algolia REST API.
|
|
286
349
|
* @param customDelete - The customDelete object.
|
|
287
|
-
* @param customDelete.path - Path of the endpoint,
|
|
350
|
+
* @param customDelete.path - Path of the endpoint, for example `1/newFeature`.
|
|
288
351
|
* @param customDelete.parameters - Query parameters to apply to the current query.
|
|
289
352
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
290
353
|
*/
|
|
@@ -306,7 +369,7 @@ function createIngestionClient({
|
|
|
306
369
|
/**
|
|
307
370
|
* This method lets you send requests to the Algolia REST API.
|
|
308
371
|
* @param customGet - The customGet object.
|
|
309
|
-
* @param customGet.path - Path of the endpoint,
|
|
372
|
+
* @param customGet.path - Path of the endpoint, for example `1/newFeature`.
|
|
310
373
|
* @param customGet.parameters - Query parameters to apply to the current query.
|
|
311
374
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
312
375
|
*/
|
|
@@ -328,7 +391,7 @@ function createIngestionClient({
|
|
|
328
391
|
/**
|
|
329
392
|
* This method lets you send requests to the Algolia REST API.
|
|
330
393
|
* @param customPost - The customPost object.
|
|
331
|
-
* @param customPost.path - Path of the endpoint,
|
|
394
|
+
* @param customPost.path - Path of the endpoint, for example `1/newFeature`.
|
|
332
395
|
* @param customPost.parameters - Query parameters to apply to the current query.
|
|
333
396
|
* @param customPost.body - Parameters to send with the custom request.
|
|
334
397
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
@@ -352,7 +415,7 @@ function createIngestionClient({
|
|
|
352
415
|
/**
|
|
353
416
|
* This method lets you send requests to the Algolia REST API.
|
|
354
417
|
* @param customPut - The customPut object.
|
|
355
|
-
* @param customPut.path - Path of the endpoint,
|
|
418
|
+
* @param customPut.path - Path of the endpoint, for example `1/newFeature`.
|
|
356
419
|
* @param customPut.parameters - Query parameters to apply to the current query.
|
|
357
420
|
* @param customPut.body - Parameters to send with the custom request.
|
|
358
421
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|