mindee 4.1.0 → 4.1.1

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,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.1.1 - 2023-09-04
4
+ ### Changes
5
+ * :recycle: tweaked timer management in async
6
+
7
+ ### Fixes
8
+ * :bug: fix ocr option not being generated as an Ocr object
9
+
10
+
3
11
  ## v4.1.0 - 2023-08-31
4
12
  ### Changes
5
13
  * :boom: remove support for node versions <16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
package/src/client.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ /// <reference types="node" />
3
4
  import { Readable } from "stream";
4
5
  import { InputSource, PageOptions } from "./input";
5
6
  import { Endpoint } from "./http";
@@ -35,6 +36,14 @@ export interface AsyncOptions extends PredictOptions {
35
36
  initialDelaySec: number;
36
37
  delaySec: number;
37
38
  maxRetries: number;
39
+ initialTimerOptions?: {
40
+ ref?: boolean;
41
+ signal?: AbortSignal;
42
+ };
43
+ recurringTimerOptions?: {
44
+ ref?: boolean;
45
+ signal?: AbortSignal;
46
+ };
38
47
  }
39
48
  export interface ClientOptions {
40
49
  /** Your API key for all endpoints. */
package/src/client.js CHANGED
@@ -122,6 +122,14 @@ class Client {
122
122
  initialDelaySec: 6,
123
123
  delaySec: 3,
124
124
  maxRetries: 10,
125
+ initialTimerOptions: {
126
+ ref: false,
127
+ signal: undefined,
128
+ },
129
+ recurringTimerOptions: {
130
+ ref: false,
131
+ signal: undefined,
132
+ },
125
133
  }) {
126
134
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_validateAsyncParams).call(this, asyncParams);
127
135
  const enqueueResponse = await this.enqueue(productClass, inputSource, asyncParams);
@@ -130,7 +138,7 @@ class Client {
130
138
  }
131
139
  const queueId = enqueueResponse.job.id;
132
140
  logger_1.logger.debug(`Successfully enqueued document with job id: ${queueId}.`);
133
- await (0, promises_1.setTimeout)(asyncParams.initialDelaySec * 1000);
141
+ await (0, promises_1.setTimeout)(asyncParams.initialDelaySec * 1000, undefined, asyncParams.initialTimerOptions);
134
142
  let retryCounter = 1;
135
143
  let pollResults;
136
144
  pollResults = await this.parseQueued(productClass, queueId, asyncParams);
@@ -141,7 +149,7 @@ Job status: ${pollResults.job.status}.`);
141
149
  if (pollResults.job.status === "completed") {
142
150
  break;
143
151
  }
144
- await (0, promises_1.setTimeout)(asyncParams.delaySec * 1000);
152
+ await (0, promises_1.setTimeout)(asyncParams.delaySec * 1000, undefined, asyncParams.recurringTimerOptions);
145
153
  pollResults = await this.parseQueued(productClass, queueId, asyncParams);
146
154
  retryCounter++;
147
155
  }
@@ -248,6 +256,9 @@ Job status: ${pollResults.job.status}.`);
248
256
  }
249
257
  exports.Client = Client;
250
258
  _Client_instances = new WeakSet(), _Client_validateAsyncParams = function _Client_validateAsyncParams(asyncParams) {
259
+ asyncParams.delaySec ?? (asyncParams.delaySec = 3);
260
+ asyncParams.initialDelaySec ?? (asyncParams.initialDelaySec = 6);
261
+ asyncParams.maxRetries ?? (asyncParams.maxRetries = 10);
251
262
  if (asyncParams.delaySec < 2) {
252
263
  throw Error("Cannot set auto-parsing delay to less than 2 seconds.");
253
264
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Document = void 0;
4
4
  const cropperExtra_1 = require("./extras/cropperExtra");
5
5
  const extras_1 = require("./extras/extras");
6
+ const ocr_1 = require("./ocr");
6
7
  /**
7
8
  * Document prediction wrapper class. Holds the results of a parsed document.
8
9
  * @typeParam T an extension of an `Inference`. Mandatory in order to properly create an inference.
@@ -16,7 +17,7 @@ class Document {
16
17
  constructor(inferenceClass, httpResponse) {
17
18
  this.id = httpResponse?.id ?? "";
18
19
  this.filename = httpResponse?.name ?? "";
19
- this.ocr = httpResponse?.ocr ?? undefined;
20
+ this.ocr = httpResponse.ocr && Object.keys(httpResponse.ocr).length > 0 ? new ocr_1.Ocr(httpResponse.ocr) : undefined;
20
21
  this.inference = new inferenceClass(httpResponse["inference"]);
21
22
  // Note: this is a convoluted but functional way of being able to implement/use Extras fields
22
23
  // as an extension of a Map object (like having an adapted toString() method, for instance).