mindee 4.8.1 → 4.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.8.2 - 2024-02-09
4
+ ### Changes
5
+ * :recycle: increased update time for async retries
6
+
7
+ ### Fixes
8
+ * :bug: fixed improper float parsing for Generated list objects
9
+ * :bug: typescript should now allow the use of default values for enqueueAndParse() async options
10
+
11
+
3
12
  ## v4.8.1 - 2024-02-06
4
13
  ### Fixes
5
14
  * :bug: fixed invalid code samples for generated & async generic APIs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.8.1",
3
+ "version": "4.8.2",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
package/src/cli.js CHANGED
@@ -241,7 +241,7 @@ async function callEnqueueAndParse(productClass, command, inputPath, options) {
241
241
  cropper: predictParams.cropper,
242
242
  initialDelaySec: 4,
243
243
  delaySec: 2,
244
- maxRetries: 30,
244
+ maxRetries: 60,
245
245
  });
246
246
  }
247
247
  else {
@@ -251,7 +251,7 @@ async function callEnqueueAndParse(productClass, command, inputPath, options) {
251
251
  cropper: predictParams.cropper,
252
252
  initialDelaySec: 4,
253
253
  delaySec: 2,
254
- maxRetries: 30,
254
+ maxRetries: 60,
255
255
  });
256
256
  if (!response.document) {
257
257
  throw Error("Document could not be retrieved");
package/src/client.d.ts CHANGED
@@ -32,6 +32,19 @@ export interface PredictOptions {
32
32
  /**
33
33
  * Asynchronous polling parameters.
34
34
  */
35
+ export interface OptionalAsyncOptions extends PredictOptions {
36
+ initialDelaySec?: number;
37
+ delaySec?: number;
38
+ maxRetries?: number;
39
+ initialTimerOptions?: {
40
+ ref?: boolean;
41
+ signal?: AbortSignal;
42
+ };
43
+ recurringTimerOptions?: {
44
+ ref?: boolean;
45
+ signal?: AbortSignal;
46
+ };
47
+ }
35
48
  export interface AsyncOptions extends PredictOptions {
36
49
  initialDelaySec: number;
37
50
  delaySec: number;
@@ -139,7 +152,7 @@ export declare class Client {
139
152
  * @category Synchronous
140
153
  * @returns a `Promise` containing parsing results.
141
154
  */
142
- enqueueAndParse<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, asyncParams?: AsyncOptions): Promise<AsyncPredictResponse<T>>;
155
+ enqueueAndParse<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, asyncParams?: OptionalAsyncOptions): Promise<AsyncPredictResponse<T>>;
143
156
  /**
144
157
  * Forces boolean coercion on truthy/falsy parameters.
145
158
  * @param param input parameter to check.
package/src/client.js CHANGED
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
5
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
6
  };
7
- var _Client_instances, _Client_validateAsyncParams, _Client_buildProductEndpoint, _Client_buildApiSettings, _Client_initializeOTSEndpoint, _Client_cleanAccountName, _Client_getOtsEndpoint;
7
+ var _Client_instances, _Client_setAsyncParams, _Client_buildProductEndpoint, _Client_buildApiSettings, _Client_initializeOTSEndpoint, _Client_cleanAccountName, _Client_getOtsEndpoint;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Client = void 0;
10
10
  const input_1 = require("./input");
@@ -155,34 +155,34 @@ class Client {
155
155
  pageOptions: undefined,
156
156
  initialDelaySec: 4,
157
157
  delaySec: 2,
158
- maxRetries: 30,
158
+ maxRetries: 60,
159
159
  initialTimerOptions: undefined,
160
160
  recurringTimerOptions: undefined,
161
161
  }) {
162
- __classPrivateFieldGet(this, _Client_instances, "m", _Client_validateAsyncParams).call(this, asyncParams);
162
+ const validatedAsyncParams = __classPrivateFieldGet(this, _Client_instances, "m", _Client_setAsyncParams).call(this, asyncParams);
163
163
  const enqueueResponse = await this.enqueue(productClass, inputSource, asyncParams);
164
164
  if (enqueueResponse.job.id === undefined || enqueueResponse.job.id.length === 0) {
165
165
  throw Error("Enqueueing of the document failed.");
166
166
  }
167
167
  const queueId = enqueueResponse.job.id;
168
168
  logger_1.logger.debug(`Successfully enqueued document with job id: ${queueId}.`);
169
- await (0, promises_1.setTimeout)(asyncParams.initialDelaySec * 1000, undefined, asyncParams.initialTimerOptions);
169
+ await (0, promises_1.setTimeout)(validatedAsyncParams.initialDelaySec * 1000, undefined, asyncParams.initialTimerOptions);
170
170
  let retryCounter = 1;
171
171
  let pollResults;
172
172
  pollResults = await this.parseQueued(productClass, queueId, asyncParams);
173
- while (retryCounter < asyncParams.maxRetries) {
173
+ while (retryCounter < validatedAsyncParams.maxRetries) {
174
174
  logger_1.logger.debug(`Polling server for parsing result with queueId: ${queueId}.
175
175
  Attempt n°${retryCounter}/${asyncParams.maxRetries}.
176
176
  Job status: ${pollResults.job.status}.`);
177
177
  if (pollResults.job.status === "completed") {
178
178
  break;
179
179
  }
180
- await (0, promises_1.setTimeout)(asyncParams.delaySec * 1000, undefined, asyncParams.recurringTimerOptions);
180
+ await (0, promises_1.setTimeout)(validatedAsyncParams.delaySec * 1000, undefined, asyncParams.recurringTimerOptions);
181
181
  pollResults = await this.parseQueued(productClass, queueId, asyncParams);
182
182
  retryCounter++;
183
183
  }
184
184
  if (pollResults.job.status !== "completed") {
185
- throw Error(`Asynchronous parsing request timed out after ${asyncParams.delaySec * retryCounter} seconds`);
185
+ throw Error(`Asynchronous parsing request timed out after ${validatedAsyncParams.delaySec * retryCounter} seconds`);
186
186
  }
187
187
  return pollResults;
188
188
  }
@@ -282,22 +282,24 @@ Job status: ${pollResults.job.status}.`);
282
282
  }
283
283
  }
284
284
  exports.Client = Client;
285
- _Client_instances = new WeakSet(), _Client_validateAsyncParams = function _Client_validateAsyncParams(asyncParams) {
285
+ _Client_instances = new WeakSet(), _Client_setAsyncParams = function _Client_setAsyncParams(asyncParams) {
286
286
  const minDelaySec = 1;
287
287
  const minInitialDelay = 2;
288
288
  const minRetries = 2;
289
- asyncParams.delaySec ?? (asyncParams.delaySec = 2);
290
- asyncParams.initialDelaySec ?? (asyncParams.initialDelaySec = 4);
291
- asyncParams.maxRetries ?? (asyncParams.maxRetries = 30);
292
- if (asyncParams.delaySec < minDelaySec) {
289
+ const newAsyncParams = { ...asyncParams };
290
+ newAsyncParams.delaySec ?? (newAsyncParams.delaySec = 2);
291
+ newAsyncParams.initialDelaySec ?? (newAsyncParams.initialDelaySec = 4);
292
+ newAsyncParams.maxRetries ?? (newAsyncParams.maxRetries = 60);
293
+ if (newAsyncParams.delaySec < minDelaySec) {
293
294
  throw Error(`Cannot set auto-parsing delay to less than ${minDelaySec} seconds.`);
294
295
  }
295
- if (asyncParams.initialDelaySec < minInitialDelay) {
296
+ if (newAsyncParams.initialDelaySec < minInitialDelay) {
296
297
  throw Error(`Cannot set initial parsing delay to less than ${minInitialDelay} seconds.`);
297
298
  }
298
- if (asyncParams.maxRetries < minRetries) {
299
+ if (newAsyncParams.maxRetries < minRetries) {
299
300
  throw Error(`Cannot set retry to less than ${minRetries}.`);
300
301
  }
302
+ return newAsyncParams;
301
303
  }, _Client_buildProductEndpoint = function _Client_buildProductEndpoint(endpointName, accountName, endpointVersion) {
302
304
  return new http_1.Endpoint(endpointName, accountName, endpointVersion, __classPrivateFieldGet(this, _Client_instances, "m", _Client_buildApiSettings).call(this));
303
305
  }, _Client_buildApiSettings = function _Client_buildApiSettings() {
@@ -18,10 +18,7 @@ class GeneratedListField {
18
18
  }
19
19
  else {
20
20
  const valueStr = { ...value };
21
- if (valueStr["value"] !== null && valueStr["value"] !== undefined && !isNaN(valueStr["value"])) {
22
- valueStr["value"] = value["value"].toFixed(1);
23
- }
24
- else if (value["value"] !== undefined && value["value"] !== null) {
21
+ if (valueStr["value"] !== null && valueStr["value"] !== undefined) {
25
22
  valueStr["value"] = value["value"].toString();
26
23
  }
27
24
  this.values.push(new standard_1.StringField({ prediction: valueStr, pageId: pageId }));