@algolia/ingestion 1.34.0 → 1.35.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.
@@ -1,6 +1,6 @@
1
1
  // src/ingestionClient.ts
2
2
  import { createAuth, createIterablePromise, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
3
- var apiClientVersion = "1.34.0";
3
+ var apiClientVersion = "1.35.0";
4
4
  var REGIONS = ["eu", "us"];
5
5
  function getDefaultHosts(region) {
6
6
  const url = "data.{region}.algolia.com".replace("{region}", region);
@@ -108,7 +108,9 @@ function createIngestionClient({
108
108
  referenceIndexName
109
109
  }, requestOptions) {
110
110
  let records = [];
111
+ let offset = 0;
111
112
  const responses = [];
113
+ const waitBatchSize = Math.floor(batchSize / 10) || batchSize;
112
114
  const objectEntries = objects.entries();
113
115
  for (const [i, obj] of objectEntries) {
114
116
  records.push(obj);
@@ -118,33 +120,34 @@ function createIngestionClient({
118
120
  );
119
121
  records = [];
120
122
  }
121
- }
122
- let retryCount = 0;
123
- if (waitForTasks) {
124
- for (const resp of responses) {
125
- if (!resp.eventID) {
126
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
127
- }
128
- await createIterablePromise({
129
- func: async () => {
130
- if (resp.eventID === void 0 || !resp.eventID) {
131
- throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
132
- }
133
- return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
134
- if (error.status === 404) {
135
- return void 0;
123
+ if (waitForTasks && responses.length > 0 && (responses.length % waitBatchSize === 0 || i === objects.length - 1)) {
124
+ for (const resp of responses.slice(offset, offset + waitBatchSize)) {
125
+ if (!resp.eventID) {
126
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
127
+ }
128
+ let retryCount = 0;
129
+ await createIterablePromise({
130
+ func: async () => {
131
+ if (resp.eventID === void 0 || !resp.eventID) {
132
+ throw new Error("received unexpected response from the push endpoint, eventID must not be undefined");
136
133
  }
137
- throw error;
138
- });
139
- },
140
- validate: (response) => response !== void 0,
141
- aggregator: () => retryCount += 1,
142
- error: {
143
- validate: () => retryCount >= 50,
144
- message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
145
- },
146
- timeout: () => Math.min(retryCount * 500, 5e3)
147
- });
134
+ return this.getEvent({ runID: resp.runID, eventID: resp.eventID }).catch((error) => {
135
+ if (error.status === 404) {
136
+ return void 0;
137
+ }
138
+ throw error;
139
+ });
140
+ },
141
+ validate: (response) => response !== void 0,
142
+ aggregator: () => retryCount += 1,
143
+ error: {
144
+ validate: () => retryCount >= 50,
145
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${50})`
146
+ },
147
+ timeout: () => Math.min(retryCount * 500, 5e3)
148
+ });
149
+ }
150
+ offset += waitBatchSize;
148
151
  }
149
152
  }
150
153
  return responses;