@algolia/ingestion 1.55.0 → 1.55.2

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 CHANGED
@@ -40,11 +40,11 @@ All of our clients comes with type definition, and are available for both browse
40
40
  ### With a package manager
41
41
 
42
42
  ```bash
43
- yarn add @algolia/ingestion@1.55.0
43
+ yarn add @algolia/ingestion@1.55.2
44
44
  # or
45
- npm install @algolia/ingestion@1.55.0
45
+ npm install @algolia/ingestion@1.55.2
46
46
  # or
47
- pnpm add @algolia/ingestion@1.55.0
47
+ pnpm add @algolia/ingestion@1.55.2
48
48
  ```
49
49
 
50
50
  ### Without a package manager
@@ -52,7 +52,7 @@ pnpm add @algolia/ingestion@1.55.0
52
52
  Add the following JavaScript snippet to the <head> of your website:
53
53
 
54
54
  ```html
55
- <script src="https://cdn.jsdelivr.net/npm/@algolia/ingestion@1.55.0/dist/builds/browser.umd.js"></script>
55
+ <script src="https://cdn.jsdelivr.net/npm/@algolia/ingestion@1.55.2/dist/builds/browser.umd.js"></script>
56
56
  ```
57
57
 
58
58
  ### Usage
package/dist/browser.d.ts CHANGED
@@ -2540,7 +2540,7 @@ type ChunkedPushOptions = ChunkedHelperOptions & {
2540
2540
  objects: Array<Record<string, unknown>>;
2541
2541
  };
2542
2542
 
2543
- declare const apiClientVersion = "1.55.0";
2543
+ declare const apiClientVersion = "1.55.2";
2544
2544
  declare const REGIONS: readonly ["eu", "us"];
2545
2545
  type Region = (typeof REGIONS)[number];
2546
2546
  type RegionOptions = {
@@ -15,7 +15,7 @@ import {
15
15
  getAlgoliaAgent,
16
16
  validateRequired
17
17
  } from "@algolia/client-common";
18
- var apiClientVersion = "1.55.0";
18
+ var apiClientVersion = "1.55.2";
19
19
  var REGIONS = ["eu", "us"];
20
20
  function getDefaultHosts(region) {
21
21
  const url = "data.{region}.algolia.com".replace("{region}", region);
@@ -124,10 +124,41 @@ function createIngestionClient({
124
124
  referenceIndexName,
125
125
  maxRetries = 100
126
126
  }, requestOptions) {
127
+ if (batchSize < 1) {
128
+ throw new Error("`batchSize` must be at least 1.");
129
+ }
127
130
  let records = [];
128
131
  let offset = 0;
129
132
  const responses = [];
130
133
  const waitBatchSize = Math.floor(batchSize / 10) || batchSize;
134
+ const waitForBatch = async (start, end) => {
135
+ for (const resp of responses.slice(start, end)) {
136
+ if (!resp.eventID) {
137
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
138
+ }
139
+ let retryCount = 0;
140
+ await createIterablePromise({
141
+ func: async () => {
142
+ if (resp.eventID === void 0 || !resp.eventID) {
143
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
144
+ }
145
+ return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
146
+ if (error.status === 404) {
147
+ return void 0;
148
+ }
149
+ throw error;
150
+ });
151
+ },
152
+ validate: (response) => response !== void 0,
153
+ aggregator: () => retryCount += 1,
154
+ error: {
155
+ validate: () => retryCount >= maxRetries,
156
+ message: () => `Stopped waiting for the task after ${maxRetries} retries. This does not mean the operation failed; it may still complete. If you need to keep polling, retry with a higher maxRetries.`
157
+ },
158
+ timeout: () => Math.min(retryCount * 1500, 5e3)
159
+ });
160
+ }
161
+ };
131
162
  const objectEntries = objects.entries();
132
163
  for (const [i, obj] of objectEntries) {
133
164
  records.push(obj);
@@ -137,36 +168,14 @@ function createIngestionClient({
137
168
  );
138
169
  records = [];
139
170
  }
140
- if (waitForTasks && responses.length > 0 && (responses.length % waitBatchSize === 0 || i === objects.length - 1)) {
141
- for (const resp of responses.slice(offset, offset + waitBatchSize)) {
142
- if (!resp.eventID) {
143
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
144
- }
145
- let retryCount = 0;
146
- await createIterablePromise({
147
- func: async () => {
148
- if (resp.eventID === void 0 || !resp.eventID) {
149
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
150
- }
151
- return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
152
- if (error.status === 404) {
153
- return void 0;
154
- }
155
- throw error;
156
- });
157
- },
158
- validate: (response) => response !== void 0,
159
- aggregator: () => retryCount += 1,
160
- error: {
161
- validate: () => retryCount >= maxRetries,
162
- message: () => `Stopped waiting for the task after ${maxRetries} retries. This does not mean the operation failed; it may still complete. If you need to keep polling, retry with a higher maxRetries.`
163
- },
164
- timeout: () => Math.min(retryCount * 1500, 5e3)
165
- });
166
- }
171
+ if (waitForTasks && responses.length - offset >= waitBatchSize) {
172
+ await waitForBatch(offset, offset + waitBatchSize);
167
173
  offset += waitBatchSize;
168
174
  }
169
175
  }
176
+ if (waitForTasks) {
177
+ await waitForBatch(offset, responses.length);
178
+ }
170
179
  return responses;
171
180
  },
172
181
  /**