mindee 4.7.0 → 4.8.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -0
  3. package/package.json +1 -1
  4. package/src/cli.js +15 -4
  5. package/src/index.d.ts +1 -1
  6. package/src/index.js +3 -1
  7. package/src/parsing/generated/generatedList.d.ts +31 -0
  8. package/src/parsing/generated/generatedList.js +52 -0
  9. package/src/parsing/generated/generatedObject.d.ts +32 -0
  10. package/src/parsing/generated/generatedObject.js +88 -0
  11. package/src/parsing/generated/index.d.ts +2 -0
  12. package/src/parsing/generated/index.js +8 -0
  13. package/src/parsing/index.d.ts +1 -0
  14. package/src/parsing/index.js +2 -1
  15. package/src/product/custom/customV1Document.d.ts +2 -2
  16. package/src/product/custom/customV1Document.js +2 -2
  17. package/src/product/custom/customV1Page.d.ts +1 -1
  18. package/src/product/custom/customV1Page.js +1 -1
  19. package/src/product/generated/generatedV1.d.ts +17 -0
  20. package/src/product/generated/generatedV1.js +23 -0
  21. package/src/product/generated/generatedV1Document.d.ts +8 -0
  22. package/src/product/generated/generatedV1Document.js +30 -0
  23. package/src/product/generated/generatedV1Page.d.ts +8 -0
  24. package/src/product/generated/generatedV1Page.js +30 -0
  25. package/src/product/generated/generatedV1Prediction.d.ts +25 -0
  26. package/src/product/generated/generatedV1Prediction.js +84 -0
  27. package/src/product/generated/internal.d.ts +4 -0
  28. package/src/product/generated/internal.js +11 -0
  29. package/src/product/index.d.ts +1 -0
  30. package/src/product/index.js +3 -1
  31. package/src/product/internal.d.ts +1 -0
  32. package/src/product/internal.js +2 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.8.1 - 2024-02-06
4
+ ### Fixes
5
+ * :bug: fixed invalid code samples for generated & async generic APIs
6
+ * :memo: fix corresponding docs
7
+
8
+
9
+ ## v4.8.0 - 2024-02-05
10
+ ### Changes
11
+ * :sparkles: add support for Generated APIs
12
+ * :sparkles: add custom GeneratedList & GeneratedObject classes linked to Generated APIs
13
+ * :arrow_up: update test lib to add testing samples for Generated APIs
14
+ * :arrow_up: upgraded dependencies & lockfile version
15
+ * :recycle: add new generated namespace & associated documentation
16
+ * :wrench: add unit tests for generated APIs
17
+ * :wrench: add code samples for generated APIs
18
+ * :recycle: add CLI entry for generated APIs
19
+ * :memo: add documentation entry for generated APIs
20
+ * :recycle: expose a bit more of our internals for easier use (#247)
21
+
22
+ ### Fixes
23
+ * :memo: fix invoice v4 md doc
24
+
25
+
3
26
  ## v4.7.0 - 2024-01-30
4
27
  ### Changes
5
28
  * :arrow_up: update invoices to 4.4
package/README.md CHANGED
@@ -144,6 +144,7 @@ const apiResponse = mindeeClient.parse(
144
144
  Complete details on the working of the library are available in the following guides:
145
145
 
146
146
  * [Node.js Getting Started](https://developers.mindee.com/docs/nodejs-getting-started)
147
+ * [Node.js Generated API](https://developers.mindee.com/docs/nodejs-generated-api)
147
148
  * [Node.js Custom OCR](https://developers.mindee.com/docs/nodejs-api-builder)
148
149
  * [Node.js Invoice OCR](https://developers.mindee.com/docs/nodejs-invoice-ocr)
149
150
  * [Node.js Receipt OCR](https://developers.mindee.com/docs/nodejs-receipt-ocr)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.7.0",
3
+ "version": "4.8.1",
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
@@ -31,6 +31,7 @@ const input_1 = require("./input");
31
31
  const console = __importStar(require("console"));
32
32
  const program = new commander_1.Command();
33
33
  const COMMAND_CUSTOM = "custom";
34
+ const COMMAND_GENERATED = "generated";
34
35
  //
35
36
  // PRODUCT CONFIGURATION
36
37
  //
@@ -47,6 +48,16 @@ const CLI_COMMAND_CONFIG = new Map([
47
48
  sync: true,
48
49
  },
49
50
  ],
51
+ [
52
+ COMMAND_GENERATED,
53
+ {
54
+ displayName: "Generated Document",
55
+ docClass: product.GeneratedV1,
56
+ allWords: true,
57
+ async: true,
58
+ sync: true,
59
+ },
60
+ ],
50
61
  [
51
62
  "cropper",
52
63
  {
@@ -197,7 +208,7 @@ async function callParse(productClass, command, inputPath, options) {
197
208
  const pageOptions = getPageOptions(options);
198
209
  const inputSource = mindeeClient.docFromPath(inputPath);
199
210
  let response;
200
- if (command === COMMAND_CUSTOM) {
211
+ if (command === COMMAND_CUSTOM || command === COMMAND_GENERATED) {
201
212
  const customEndpoint = mindeeClient.createEndpoint(options.endpoint, options.account, options.version);
202
213
  response = await mindeeClient.parse(productClass, inputSource, {
203
214
  endpoint: customEndpoint,
@@ -221,7 +232,7 @@ async function callEnqueueAndParse(productClass, command, inputPath, options) {
221
232
  const pageOptions = getPageOptions(options);
222
233
  const inputSource = mindeeClient.docFromPath(inputPath);
223
234
  let response;
224
- if (command === COMMAND_CUSTOM) {
235
+ if (command === COMMAND_CUSTOM || command === COMMAND_GENERATED) {
225
236
  const customEndpoint = mindeeClient.createEndpoint(options.endpoint, options.account, options.version);
226
237
  response = await mindeeClient.enqueueAndParse(productClass, inputSource, {
227
238
  endpoint: customEndpoint,
@@ -308,7 +319,7 @@ function routeSwitchboard(command, inputPath, allOptions) {
308
319
  return callParse(docClass, command.name(), inputPath, allOptions);
309
320
  }
310
321
  function addPredictAction(prog) {
311
- if (prog.name() === COMMAND_CUSTOM) {
322
+ if (prog.name() === COMMAND_CUSTOM || prog.name() === COMMAND_GENERATED) {
312
323
  prog.action(function (inputPath, options, command) {
313
324
  const allOptions = {
314
325
  ...prog.parent?.parent?.opts(),
@@ -370,7 +381,7 @@ function cli() {
370
381
  }
371
382
  predictProductCmd.addOption(asyncOpt);
372
383
  }
373
- if (name === COMMAND_CUSTOM) {
384
+ if (name === COMMAND_CUSTOM || name === COMMAND_GENERATED) {
374
385
  addCustomPostOptions(predictProductCmd);
375
386
  }
376
387
  addMainOptions(predictProductCmd);
package/src/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * as product from "./product";
2
2
  export { Client, PredictOptions } from "./client";
3
- export { AsyncPredictResponse, PredictResponse, Document, Page, } from "./parsing/common";
3
+ export { AsyncPredictResponse, PredictResponse, Inference, Prediction, Document, Page, } from "./parsing/common";
4
4
  export { InputSource, PageOptionsOperation } from "./input";
5
5
  export * as internal from "./internal";
6
6
  export * as imageOperations from "./imageOperations";
package/src/index.js CHANGED
@@ -23,13 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.imageOperations = exports.internal = exports.PageOptionsOperation = exports.InputSource = exports.Page = exports.Document = exports.PredictResponse = exports.AsyncPredictResponse = exports.Client = exports.product = void 0;
26
+ exports.imageOperations = exports.internal = exports.PageOptionsOperation = exports.InputSource = exports.Page = exports.Document = exports.Prediction = exports.Inference = exports.PredictResponse = exports.AsyncPredictResponse = exports.Client = exports.product = void 0;
27
27
  exports.product = __importStar(require("./product"));
28
28
  var client_1 = require("./client");
29
29
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
30
30
  var common_1 = require("./parsing/common");
31
31
  Object.defineProperty(exports, "AsyncPredictResponse", { enumerable: true, get: function () { return common_1.AsyncPredictResponse; } });
32
32
  Object.defineProperty(exports, "PredictResponse", { enumerable: true, get: function () { return common_1.PredictResponse; } });
33
+ Object.defineProperty(exports, "Inference", { enumerable: true, get: function () { return common_1.Inference; } });
34
+ Object.defineProperty(exports, "Prediction", { enumerable: true, get: function () { return common_1.Prediction; } });
33
35
  Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return common_1.Document; } });
34
36
  Object.defineProperty(exports, "Page", { enumerable: true, get: function () { return common_1.Page; } });
35
37
  var input_1 = require("./input");
@@ -0,0 +1,31 @@
1
+ import { StringDict } from "../common";
2
+ import { StringField } from "../standard";
3
+ import { GeneratedObjectField } from "./generatedObject";
4
+ export interface GeneratedListFieldConstructor {
5
+ prediction: StringDict[];
6
+ pageId?: number;
7
+ }
8
+ /**
9
+ * A list of values or objects, used in generated APIs.
10
+ */
11
+ export declare class GeneratedListField {
12
+ /** Id of the page the object was found on. */
13
+ pageId?: number;
14
+ /** List of word values. */
15
+ values: Array<GeneratedObjectField | StringField>;
16
+ constructor({ prediction, pageId, }: GeneratedListFieldConstructor);
17
+ /**
18
+ * Returns an array of the contents of all values.
19
+ */
20
+ contentsList(): string[];
21
+ /**
22
+ * Return a string representation of all values.
23
+ * @param separator Character(s) to use when concatenating fields.
24
+ * @returns string representation.
25
+ */
26
+ contentsString(separator?: string): string;
27
+ /**
28
+ * Default string representation.
29
+ */
30
+ toString(): string;
31
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratedListField = void 0;
4
+ const standard_1 = require("../standard");
5
+ const generatedObject_1 = require("./generatedObject");
6
+ /**
7
+ * A list of values or objects, used in generated APIs.
8
+ */
9
+ class GeneratedListField {
10
+ constructor({ prediction = [], pageId = undefined, }) {
11
+ this.values = [];
12
+ for (const value of prediction) {
13
+ if (value["page_id"] !== undefined && value["page_id"] !== null) {
14
+ this.pageId = value["page_id"];
15
+ }
16
+ if ((0, generatedObject_1.isGeneratedObject)(value)) {
17
+ this.values.push(new generatedObject_1.GeneratedObjectField({ prediction: value, pageId }));
18
+ }
19
+ else {
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) {
25
+ valueStr["value"] = value["value"].toString();
26
+ }
27
+ this.values.push(new standard_1.StringField({ prediction: valueStr, pageId: pageId }));
28
+ }
29
+ }
30
+ }
31
+ /**
32
+ * Returns an array of the contents of all values.
33
+ */
34
+ contentsList() {
35
+ return this.values.map((item) => item.toString());
36
+ }
37
+ /**
38
+ * Return a string representation of all values.
39
+ * @param separator Character(s) to use when concatenating fields.
40
+ * @returns string representation.
41
+ */
42
+ contentsString(separator = " ") {
43
+ return this.contentsList().map((item) => `${item.toString()}`).join(separator);
44
+ }
45
+ /**
46
+ * Default string representation.
47
+ */
48
+ toString() {
49
+ return this.contentsString();
50
+ }
51
+ }
52
+ exports.GeneratedListField = GeneratedListField;
@@ -0,0 +1,32 @@
1
+ import { StringDict } from "../common";
2
+ import { BaseFieldConstructor } from "../standard";
3
+ /** A JSON-like object, with miscellaneous values. */
4
+ export declare class GeneratedObjectField {
5
+ /** The document page on which the information was found. */
6
+ pageId?: number;
7
+ /** Confidence with which the value was assessed. */
8
+ confidence?: number;
9
+ /** Raw unprocessed value, as it was sent by the server. */
10
+ rawValue?: string;
11
+ /** List of all printable field names. */
12
+ private printableValues;
13
+ constructor({ prediction, pageId, }: BaseFieldConstructor);
14
+ /**
15
+ * ReSTructured-compliant string representation.
16
+ Takes into account level of indentation & displays elements as list elements.
17
+ * @param level Lvel of indentation. 0 by default.
18
+ */
19
+ toStringLevel(level?: number): string;
20
+ /**
21
+ * Formats a float number to have at least one decimal place.
22
+ * @param n Input number.
23
+ * @returns
24
+ */
25
+ private toNumberString;
26
+ toString(): string;
27
+ }
28
+ /**
29
+ * Checks whether an field is a custom object or not.
30
+ * @param strDict input dictionary to check.
31
+ */
32
+ export declare function isGeneratedObject(strDict: StringDict): boolean;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGeneratedObject = exports.GeneratedObjectField = void 0;
4
+ const standard_1 = require("../standard");
5
+ /** A JSON-like object, with miscellaneous values. */
6
+ class GeneratedObjectField {
7
+ constructor({ prediction = {}, pageId, }) {
8
+ let itemPageId = null;
9
+ this.printableValues = [];
10
+ for (const [fieldName, fieldValue] of Object.entries(prediction)) {
11
+ if (fieldName === "page_id") {
12
+ itemPageId = fieldValue;
13
+ }
14
+ else if (["polygon", "rectangle", "quadrangle", "bounding_box"].includes(fieldName)) {
15
+ Object.assign(this, { [fieldName]: new standard_1.PositionField({ prediction: { [fieldName]: fieldValue }, valueKey: fieldName, pageId: pageId }) });
16
+ this.printableValues.push(fieldName);
17
+ }
18
+ else if (fieldName === "confidence") {
19
+ this.confidence = fieldValue;
20
+ }
21
+ else if (fieldName === "raw_value") {
22
+ this.rawValue = fieldValue;
23
+ }
24
+ else {
25
+ if (fieldValue !== null && fieldValue !== undefined && !isNaN(fieldValue) && fieldName !== "degrees") {
26
+ Object.assign(this, { [fieldName]: this.toNumberString(fieldValue) });
27
+ }
28
+ else {
29
+ Object.assign(this, { [fieldName]: (fieldValue !== undefined && fieldValue !== null) ? String(fieldValue) : null });
30
+ }
31
+ this.printableValues.push(fieldName);
32
+ }
33
+ this.pageId = pageId ?? itemPageId;
34
+ }
35
+ }
36
+ /**
37
+ * ReSTructured-compliant string representation.
38
+ Takes into account level of indentation & displays elements as list elements.
39
+ * @param level Lvel of indentation. 0 by default.
40
+ */
41
+ toStringLevel(level = 0) {
42
+ const indent = " " + " ".repeat(level);
43
+ let outStr = "";
44
+ this.printableValues.forEach((printableValue) => {
45
+ const strValue = this[printableValue];
46
+ outStr += `\n${indent}:${printableValue}: ${strValue !== null && strValue !== undefined ? strValue : ""}`;
47
+ });
48
+ return `\n${indent}${outStr.trim()}`;
49
+ }
50
+ /**
51
+ * Formats a float number to have at least one decimal place.
52
+ * @param n Input number.
53
+ * @returns
54
+ */
55
+ toNumberString(n) {
56
+ if (Number.isInteger(n)) {
57
+ return n + ".0";
58
+ }
59
+ return n.toString();
60
+ }
61
+ toString() {
62
+ return this.toStringLevel();
63
+ }
64
+ }
65
+ exports.GeneratedObjectField = GeneratedObjectField;
66
+ /**
67
+ * Checks whether an field is a custom object or not.
68
+ * @param strDict input dictionary to check.
69
+ */
70
+ function isGeneratedObject(strDict) {
71
+ const commonKeys = [
72
+ "value",
73
+ "polygon",
74
+ "rectangle",
75
+ "page_id",
76
+ "confidence",
77
+ "quadrangle",
78
+ "values",
79
+ "raw_value",
80
+ ];
81
+ for (const key in strDict) {
82
+ if (Object.prototype.hasOwnProperty.call(strDict, key) && !commonKeys.includes(key)) {
83
+ return true;
84
+ }
85
+ }
86
+ return false;
87
+ }
88
+ exports.isGeneratedObject = isGeneratedObject;
@@ -0,0 +1,2 @@
1
+ export { GeneratedObjectField, isGeneratedObject } from "./generatedObject";
2
+ export { GeneratedListField } from "./generatedList";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratedListField = exports.isGeneratedObject = exports.GeneratedObjectField = void 0;
4
+ var generatedObject_1 = require("./generatedObject");
5
+ Object.defineProperty(exports, "GeneratedObjectField", { enumerable: true, get: function () { return generatedObject_1.GeneratedObjectField; } });
6
+ Object.defineProperty(exports, "isGeneratedObject", { enumerable: true, get: function () { return generatedObject_1.isGeneratedObject; } });
7
+ var generatedList_1 = require("./generatedList");
8
+ Object.defineProperty(exports, "GeneratedListField", { enumerable: true, get: function () { return generatedList_1.GeneratedListField; } });
@@ -1,3 +1,4 @@
1
1
  export * as common from "./common";
2
2
  export * as custom from "./custom";
3
3
  export * as standard from "./standard";
4
+ export * as generated from "./generated";
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.standard = exports.custom = exports.common = void 0;
26
+ exports.generated = exports.standard = exports.custom = exports.common = void 0;
27
27
  exports.common = __importStar(require("./common"));
28
28
  exports.custom = __importStar(require("./custom"));
29
29
  exports.standard = __importStar(require("./standard"));
30
+ exports.generated = __importStar(require("./generated"));
@@ -4,9 +4,9 @@ import { ClassificationField, ListField, CustomLines } from "../../parsing/custo
4
4
  * Document data for Custom builds.
5
5
  */
6
6
  export declare class CustomV1Document implements Prediction {
7
- /** List of fields for a Custom build. */
7
+ /** Map of fields for a Custom build. */
8
8
  fields: Map<string, ListField>;
9
- /** List of classification fields for a Custom build. */
9
+ /** Map of classification fields for a Custom build. */
10
10
  classifications: Map<string, ClassificationField>;
11
11
  constructor(rawPrediction: StringDict, pageId?: number);
12
12
  /**
@@ -8,9 +8,9 @@ const custom_1 = require("../../parsing/custom");
8
8
  */
9
9
  class CustomV1Document {
10
10
  constructor(rawPrediction, pageId) {
11
- /** List of fields for a Custom build. */
11
+ /** Map of fields for a Custom build. */
12
12
  this.fields = new Map();
13
- /** List of classification fields for a Custom build. */
13
+ /** Map of classification fields for a Custom build. */
14
14
  this.classifications = new Map();
15
15
  Object.entries(rawPrediction).forEach(([fieldName, fieldValue]) => {
16
16
  this.setField(fieldName, fieldValue, pageId);
@@ -4,7 +4,7 @@ import { ListField, CustomLines } from "../../parsing/custom";
4
4
  * Page data for Custom builds.
5
5
  */
6
6
  export declare class CustomV1Page implements Prediction {
7
- /** List of page-specific fields for a Custom build. Cannot include Classification fields. */
7
+ /** Map of page-specific fields for a Custom build. Cannot include Classification fields. */
8
8
  fields: Map<string, ListField>;
9
9
  constructor(rawPrediction: StringDict, pageId?: number);
10
10
  /**
@@ -8,7 +8,7 @@ const custom_1 = require("../../parsing/custom");
8
8
  */
9
9
  class CustomV1Page {
10
10
  constructor(rawPrediction, pageId) {
11
- /** List of page-specific fields for a Custom build. Cannot include Classification fields. */
11
+ /** Map of page-specific fields for a Custom build. Cannot include Classification fields. */
12
12
  this.fields = new Map();
13
13
  Object.entries(rawPrediction).forEach(([fieldName, fieldValue]) => {
14
14
  this.fields.set(fieldName, new custom_1.ListField({
@@ -0,0 +1,17 @@
1
+ import { Inference, Page, StringDict } from "../../../src/parsing/common";
2
+ import { GeneratedV1Document } from "./generatedV1Document";
3
+ import { GeneratedV1Page } from "./generatedV1Page";
4
+ /**
5
+ * Generated API V1 inference results.
6
+ */
7
+ export declare class GeneratedV1 extends Inference {
8
+ /** The endpoint's name. Note: placeholder for custom APIs. */
9
+ endpointName: string;
10
+ /** The endpoint's version. Note: placeholder for custom APIs. */
11
+ endpointVersion: string;
12
+ /** The document-level prediction. */
13
+ prediction: GeneratedV1Document;
14
+ /** The document's pages. */
15
+ pages: Page<GeneratedV1Page>[];
16
+ constructor(rawPrediction: StringDict);
17
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratedV1 = void 0;
4
+ const common_1 = require("../../../src/parsing/common");
5
+ const generatedV1Document_1 = require("./generatedV1Document");
6
+ const generatedV1Page_1 = require("./generatedV1Page");
7
+ /**
8
+ * Generated API V1 inference results.
9
+ */
10
+ class GeneratedV1 extends common_1.Inference {
11
+ constructor(rawPrediction) {
12
+ super(rawPrediction);
13
+ /** The endpoint's name. Note: placeholder for custom APIs. */
14
+ this.endpointName = "custom";
15
+ /** The endpoint's version. Note: placeholder for custom APIs. */
16
+ this.endpointVersion = "1";
17
+ /** The document's pages. */
18
+ this.pages = [];
19
+ this.prediction = new generatedV1Document_1.GeneratedV1Document(rawPrediction["prediction"]);
20
+ this.pages = rawPrediction["pages"].length > 0 && Object.keys(rawPrediction["pages"][0]["prediction"]).length > 0 ? rawPrediction["pages"].map((page) => new common_1.Page(generatedV1Page_1.GeneratedV1Page, page, page["id"])) : [];
21
+ }
22
+ }
23
+ exports.GeneratedV1 = GeneratedV1;
@@ -0,0 +1,8 @@
1
+ import { StringDict } from "../../../src/parsing/common";
2
+ import { GeneratedV1Prediction } from "./generatedV1Prediction";
3
+ /**
4
+ * Generated V1 document prediction results.
5
+ */
6
+ export declare class GeneratedV1Document extends GeneratedV1Prediction {
7
+ constructor(rawPrediction: StringDict);
8
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratedV1Document = void 0;
4
+ const generated_1 = require("../../../src/parsing/generated");
5
+ const standard_1 = require("../../../src/parsing/standard");
6
+ const generatedV1Prediction_1 = require("./generatedV1Prediction");
7
+ /**
8
+ * Generated V1 document prediction results.
9
+ */
10
+ class GeneratedV1Document extends generatedV1Prediction_1.GeneratedV1Prediction {
11
+ constructor(rawPrediction) {
12
+ super();
13
+ Object.entries(rawPrediction).forEach(([fieldName, fieldValue]) => {
14
+ if (Array.isArray(fieldValue)) {
15
+ this.fields.set(fieldName, new generated_1.GeneratedListField({ prediction: fieldValue }));
16
+ }
17
+ else if (typeof fieldValue === "object" && fieldValue !== null && (0, generated_1.isGeneratedObject)(fieldValue)) {
18
+ this.fields.set(fieldName, new generated_1.GeneratedObjectField({ prediction: fieldValue }));
19
+ }
20
+ else {
21
+ const fieldValueStr = fieldValue;
22
+ if (Object.prototype.hasOwnProperty.call(fieldValueStr, "value") && fieldValueStr["value"] !== null) {
23
+ fieldValueStr["value"] = fieldValueStr["value"].toString();
24
+ }
25
+ this.fields.set(fieldName, new standard_1.StringField({ prediction: fieldValueStr }));
26
+ }
27
+ });
28
+ }
29
+ }
30
+ exports.GeneratedV1Document = GeneratedV1Document;
@@ -0,0 +1,8 @@
1
+ import { StringDict } from "../../../src/parsing/common";
2
+ import { GeneratedV1Prediction } from "./generatedV1Prediction";
3
+ /**
4
+ * Generated V1 page prediction results.
5
+ */
6
+ export declare class GeneratedV1Page extends GeneratedV1Prediction {
7
+ constructor(rawPrediction: StringDict, pageId?: number);
8
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratedV1Page = void 0;
4
+ const generated_1 = require("../../../src/parsing/generated");
5
+ const standard_1 = require("../../../src/parsing/standard");
6
+ const generatedV1Prediction_1 = require("./generatedV1Prediction");
7
+ /**
8
+ * Generated V1 page prediction results.
9
+ */
10
+ class GeneratedV1Page extends generatedV1Prediction_1.GeneratedV1Prediction {
11
+ constructor(rawPrediction, pageId) {
12
+ super();
13
+ Object.entries(rawPrediction).forEach(([fieldName, fieldValue]) => {
14
+ if (Array.isArray(fieldValue)) {
15
+ this.fields.set(fieldName, new generated_1.GeneratedListField({ prediction: fieldValue, pageId: pageId }));
16
+ }
17
+ else if (typeof fieldValue === "object" && fieldValue !== null && (0, generated_1.isGeneratedObject)(fieldValue)) {
18
+ this.fields.set(fieldName, new generated_1.GeneratedObjectField({ prediction: fieldValue, pageId: pageId }));
19
+ }
20
+ else {
21
+ const fieldValueStr = fieldValue;
22
+ if (Object.prototype.hasOwnProperty.call(fieldValueStr, "value") && fieldValueStr["value"] !== null) {
23
+ fieldValueStr["value"] = fieldValueStr["value"].toString();
24
+ }
25
+ this.fields.set(fieldName, new standard_1.StringField({ prediction: fieldValueStr, pageId: pageId }));
26
+ }
27
+ });
28
+ }
29
+ }
30
+ exports.GeneratedV1Page = GeneratedV1Page;
@@ -0,0 +1,25 @@
1
+ import { Prediction } from "../../../src/parsing/common";
2
+ import { GeneratedListField } from "../../../src/parsing/generated";
3
+ import { StringField } from "../../../src/parsing/standard";
4
+ export declare class GeneratedV1Prediction implements Prediction {
5
+ /** Map of all fields in the document. */
6
+ fields: Map<string, any>;
7
+ constructor();
8
+ toString(): string;
9
+ /**
10
+ * Returns a dictionary of all fields that aren't a collection.
11
+ */
12
+ getSingleField(): Map<string, StringField>;
13
+ /**
14
+ * Returns a dictionary of all array-like fields.
15
+ */
16
+ getArrayFields(): Map<string, GeneratedListField>;
17
+ /**
18
+ * Returns a dictionary of all object-like fields.
19
+ */
20
+ getObjectFields(): Map<string, GeneratedListField>;
21
+ /**
22
+ * Lists names of all top-level field keys.
23
+ */
24
+ listFieldNames(): string[];
25
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratedV1Prediction = void 0;
4
+ const common_1 = require("../../../src/parsing/common");
5
+ const generated_1 = require("../../../src/parsing/generated");
6
+ const standard_1 = require("../../../src/parsing/standard");
7
+ class GeneratedV1Prediction {
8
+ constructor() {
9
+ this.fields = new Map();
10
+ }
11
+ toString() {
12
+ let outStr = "";
13
+ const pattern = /^(\n*[ ]*)( {2}):/;
14
+ this.fields.forEach((fieldValue, fieldName) => {
15
+ let strValue = "";
16
+ if (fieldValue instanceof generated_1.GeneratedListField &&
17
+ fieldValue.values.length > 0) {
18
+ if (fieldValue.values[0] instanceof generated_1.GeneratedObjectField) {
19
+ strValue += fieldValue.values[0].toStringLevel(1).replace(pattern, "$1* :");
20
+ }
21
+ else {
22
+ strValue += fieldValue.values[0].toString().replace(pattern, "$1* :") + "\n";
23
+ }
24
+ for (const subValue of fieldValue.values.slice(1)) {
25
+ if (subValue instanceof generated_1.GeneratedObjectField) {
26
+ strValue += subValue.toStringLevel(1).replace(pattern, "$1* :");
27
+ }
28
+ else {
29
+ strValue += ` ${" ".repeat(fieldName.length + 2)}${subValue}\n`;
30
+ }
31
+ }
32
+ strValue = strValue.trimEnd();
33
+ }
34
+ else {
35
+ strValue = fieldValue.toString();
36
+ }
37
+ outStr += `:${fieldName}: ${strValue}\n`;
38
+ });
39
+ return (0, common_1.cleanOutString)(outStr.trimEnd());
40
+ }
41
+ /**
42
+ * Returns a dictionary of all fields that aren't a collection.
43
+ */
44
+ getSingleField() {
45
+ const singleFields = new Map();
46
+ for (const [fieldName, fieldValue] of Object.entries(this.fields)) {
47
+ if (fieldValue instanceof standard_1.StringField) {
48
+ singleFields.set(fieldName, fieldValue);
49
+ }
50
+ }
51
+ return singleFields;
52
+ }
53
+ /**
54
+ * Returns a dictionary of all array-like fields.
55
+ */
56
+ getArrayFields() {
57
+ const arrayFields = new Map();
58
+ for (const [fieldName, fieldValue] of Object.entries(this.fields)) {
59
+ if (fieldValue instanceof generated_1.GeneratedListField) {
60
+ arrayFields.set(fieldName, fieldValue);
61
+ }
62
+ }
63
+ return arrayFields;
64
+ }
65
+ /**
66
+ * Returns a dictionary of all object-like fields.
67
+ */
68
+ getObjectFields() {
69
+ const objectFields = new Map();
70
+ for (const [fieldName, fieldValue] of Object.entries(this.fields)) {
71
+ if (fieldValue instanceof generated_1.GeneratedObjectField) {
72
+ objectFields.set(fieldName, fieldValue);
73
+ }
74
+ }
75
+ return objectFields;
76
+ }
77
+ /**
78
+ * Lists names of all top-level field keys.
79
+ */
80
+ listFieldNames() {
81
+ return Object.keys(this.fields);
82
+ }
83
+ }
84
+ exports.GeneratedV1Prediction = GeneratedV1Prediction;
@@ -0,0 +1,4 @@
1
+ export { GeneratedV1 } from "./generatedV1";
2
+ export { GeneratedV1Document } from "./generatedV1Document";
3
+ export { GeneratedV1Page } from "./generatedV1Page";
4
+ export { GeneratedV1Prediction } from "./generatedV1Prediction";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratedV1Prediction = exports.GeneratedV1Page = exports.GeneratedV1Document = exports.GeneratedV1 = void 0;
4
+ var generatedV1_1 = require("./generatedV1");
5
+ Object.defineProperty(exports, "GeneratedV1", { enumerable: true, get: function () { return generatedV1_1.GeneratedV1; } });
6
+ var generatedV1Document_1 = require("./generatedV1Document");
7
+ Object.defineProperty(exports, "GeneratedV1Document", { enumerable: true, get: function () { return generatedV1Document_1.GeneratedV1Document; } });
8
+ var generatedV1Page_1 = require("./generatedV1Page");
9
+ Object.defineProperty(exports, "GeneratedV1Page", { enumerable: true, get: function () { return generatedV1Page_1.GeneratedV1Page; } });
10
+ var generatedV1Prediction_1 = require("./generatedV1Prediction");
11
+ Object.defineProperty(exports, "GeneratedV1Prediction", { enumerable: true, get: function () { return generatedV1Prediction_1.GeneratedV1Prediction; } });
@@ -4,6 +4,7 @@ export { CustomV1 } from "./custom/customV1";
4
4
  export { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
5
5
  export { InvoiceV4 } from "./invoice/invoiceV4";
6
6
  export { InvoiceSplitterV1 } from "./invoiceSplitter/invoiceSplitterV1";
7
+ export { GeneratedV1 } from "./generated/generatedV1";
7
8
  export { MultiReceiptsDetectorV1 } from "./multiReceiptsDetector/multiReceiptsDetectorV1";
8
9
  export { PassportV1 } from "./passport/passportV1";
9
10
  export { ProofOfAddressV1 } from "./proofOfAddress/proofOfAddressV1";
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.us = exports.fr = exports.eu = exports.ReceiptV5 = exports.ReceiptV4 = exports.ProofOfAddressV1 = exports.PassportV1 = exports.MultiReceiptsDetectorV1 = exports.InvoiceSplitterV1 = exports.InvoiceV4 = exports.FinancialDocumentV1 = exports.CustomV1 = exports.CropperV1 = exports.BarcodeReaderV1 = void 0;
26
+ exports.us = exports.fr = exports.eu = exports.ReceiptV5 = exports.ReceiptV4 = exports.ProofOfAddressV1 = exports.PassportV1 = exports.MultiReceiptsDetectorV1 = exports.GeneratedV1 = exports.InvoiceSplitterV1 = exports.InvoiceV4 = exports.FinancialDocumentV1 = exports.CustomV1 = exports.CropperV1 = exports.BarcodeReaderV1 = void 0;
27
27
  var barcodeReaderV1_1 = require("./barcodeReader/barcodeReaderV1");
28
28
  Object.defineProperty(exports, "BarcodeReaderV1", { enumerable: true, get: function () { return barcodeReaderV1_1.BarcodeReaderV1; } });
29
29
  var cropperV1_1 = require("./cropper/cropperV1");
@@ -36,6 +36,8 @@ var invoiceV4_1 = require("./invoice/invoiceV4");
36
36
  Object.defineProperty(exports, "InvoiceV4", { enumerable: true, get: function () { return invoiceV4_1.InvoiceV4; } });
37
37
  var invoiceSplitterV1_1 = require("./invoiceSplitter/invoiceSplitterV1");
38
38
  Object.defineProperty(exports, "InvoiceSplitterV1", { enumerable: true, get: function () { return invoiceSplitterV1_1.InvoiceSplitterV1; } });
39
+ var generatedV1_1 = require("./generated/generatedV1");
40
+ Object.defineProperty(exports, "GeneratedV1", { enumerable: true, get: function () { return generatedV1_1.GeneratedV1; } });
39
41
  var multiReceiptsDetectorV1_1 = require("./multiReceiptsDetector/multiReceiptsDetectorV1");
40
42
  Object.defineProperty(exports, "MultiReceiptsDetectorV1", { enumerable: true, get: function () { return multiReceiptsDetectorV1_1.MultiReceiptsDetectorV1; } });
41
43
  var passportV1_1 = require("./passport/passportV1");
@@ -1,6 +1,7 @@
1
1
  export * as barcodeReader from "./barcodeReader/internal";
2
2
  export * as cropper from "./cropper/internal";
3
3
  export * as custom from "./custom/internal";
4
+ export * as generated from "./generated/internal";
4
5
  export * as eu from "./eu/internal";
5
6
  export * as financialDocument from "./financialDocument/internal";
6
7
  export * as fr from "./fr/internal";
@@ -23,10 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.us = exports.receipt = exports.proofOfAddress = exports.passport = exports.multiReceiptsDetector = exports.invoiceSplitter = exports.invoice = exports.fr = exports.financialDocument = exports.eu = exports.custom = exports.cropper = exports.barcodeReader = void 0;
26
+ exports.us = exports.receipt = exports.proofOfAddress = exports.passport = exports.multiReceiptsDetector = exports.invoiceSplitter = exports.invoice = exports.fr = exports.financialDocument = exports.eu = exports.generated = exports.custom = exports.cropper = exports.barcodeReader = void 0;
27
27
  exports.barcodeReader = __importStar(require("./barcodeReader/internal"));
28
28
  exports.cropper = __importStar(require("./cropper/internal"));
29
29
  exports.custom = __importStar(require("./custom/internal"));
30
+ exports.generated = __importStar(require("./generated/internal"));
30
31
  exports.eu = __importStar(require("./eu/internal"));
31
32
  exports.financialDocument = __importStar(require("./financialDocument/internal"));
32
33
  exports.fr = __importStar(require("./fr/internal"));