UNPKG

capacitor-plugin-scanbot-sdk

Version:

Scanbot Document and Barcode Scanner SDK for Capacitor

397 lines (393 loc) 12.9 kB
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten. /// Generated from core/schemas/GenericDocument.yaml import { CommonFieldTypeValues } from '../documents/CommonFieldType'; import { ImageRef } from '../imageRef/image'; import { ToJsonConfiguration } from '../utils/json/JsonSerializationTypes'; import { PartiallyConstructible } from '../utils/utils'; /** Result of OCR text recognition. */ export class OcrResult extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<OcrResult>`} */ constructor(source = {}) { super(); if (source.text !== undefined) { this.text = source.text; } else { throw new Error('text must be present in constructor argument'); } if (source.confidence !== undefined) { this.confidence = source.confidence; } else { throw new Error('confidence must be present in constructor argument'); } } serialize(config = new ToJsonConfiguration()) { return { text: this.text, confidence: this.confidence, }; } } export const FieldValidationStatusValues = [ 'INVALID', 'NONE', 'CONFIRMED', 'INFERRED', 'VALID', 'IGNORED', ]; export const FieldDataFormatValues = [ 'ISO_DATE', 'ISO_COUNTRY_ALPHA_2', 'ISO_COUNTRY_ALPHA_3', 'ISO_COUNTRY_NUMERIC', 'ISO_COUNTRY_NAME', 'GENDER', ]; /** Parsed data. */ export class FieldParsedData extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<FieldParsedData>`} */ constructor(source = {}) { super(); if (source.type !== undefined) { this.type = source.type; } else { throw new Error('type must be present in constructor argument'); } if (source.value !== undefined) { this.value = source.value; } else { throw new Error('value must be present in constructor argument'); } } serialize(config = new ToJsonConfiguration()) { return { type: this.type, value: this.value, }; } } /** Generic Document Type. */ export class FieldType extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<FieldType>`} */ constructor(source = {}) { super(); /** A document can contain multiple fields of the same name, the property serves for storing natural order of such fields, null if multiple entries aren't allowed for this field. */ this.listIndex = null; if (source.name !== undefined) { this.name = source.name; } else { throw new Error('name must be present in constructor argument'); } if (source.fullName !== undefined) { this.fullName = source.fullName; } else { throw new Error('fullName must be present in constructor argument'); } if (source.normalizedName !== undefined) { this.normalizedName = source.normalizedName; } else { throw new Error('normalizedName must be present in constructor argument'); } if (source.commonType !== undefined) { this.commonType = source.commonType != null ? CommonFieldTypeValues.includes(source.commonType) ? source.commonType : null : null; } else { throw new Error('commonType must be present in constructor argument'); } if (source.listIndex !== undefined) { this.listIndex = source.listIndex != null ? source.listIndex : null; } } serialize(config = new ToJsonConfiguration()) { return { name: this.name, fullName: this.fullName, normalizedName: this.normalizedName, commonType: this.commonType != null ? this.commonType : null, listIndex: this.listIndex != null ? this.listIndex : null, }; } } /** Generic document field. */ export class Field extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<Field>`} */ constructor(source = {}) { super(); /** Confidence weight. Default is 1.0 */ this.confidenceWeight = 1.0; /** Crop of the field. */ this.image = null; /** Field validation status. Applicable only to fields that support some kind of validation. Default is NONE */ this.validationStatus = 'NONE'; /** Parsed data. */ this.parsedData = []; this._released = false; if (source.type !== undefined) { this.type = new FieldType(source.type); } else { throw new Error('type must be present in constructor argument'); } if (source.value !== undefined) { this.value = source.value != null ? new OcrResult(source.value) : null; } else { throw new Error('value must be present in constructor argument'); } if (source.confidenceWeight !== undefined) { this.confidenceWeight = source.confidenceWeight; } if (source.image !== undefined) { this.image = source.image != null ? ImageRef.From(source.image) : null; } if (source.polygonInRoot !== undefined) { this.polygonInRoot = source.polygonInRoot.map((it) => { return { x: it.x, y: it.y }; }); } else { throw new Error('polygonInRoot must be present in constructor argument'); } if (source.validationStatus !== undefined) { this.validationStatus = source.validationStatus; } if (source.parsedData !== undefined) { this.parsedData = source.parsedData.map((it) => { return new FieldParsedData(it); }); } } async serialize(config = new ToJsonConfiguration()) { return { type: this.type.serialize(config), value: this.value != null ? this.value.serialize(config) : null, confidenceWeight: this.confidenceWeight, image: config.serializeImages ? this.image != null ? await this.image.serialize(config.imageSerializationMode) : null : undefined, polygonInRoot: this.polygonInRoot.map((it) => { return it; }), validationStatus: this.validationStatus, parsedData: this.parsedData.map((it) => { return it.serialize(config); }), }; } release() { if (this._released) { return; } { if (this.image != null) { this.image.release(); } } this._released = true; } async encodeImages() { if (this.image != null) { await this.image.encodeInPlace(); } } } /** Generic Document Type. */ export class GenericDocumentType extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<GenericDocumentType>`} */ constructor(source = {}) { super(); /** A document can contain multiple fields of the same name, the property serves for storing natural order of such fields, null if multiple entries aren't allowed for this field. */ this.listIndex = null; if (source.name !== undefined) { this.name = source.name; } else { throw new Error('name must be present in constructor argument'); } if (source.fullName !== undefined) { this.fullName = source.fullName; } else { throw new Error('fullName must be present in constructor argument'); } if (source.normalizedName !== undefined) { this.normalizedName = source.normalizedName; } else { throw new Error('normalizedName must be present in constructor argument'); } if (source.listIndex !== undefined) { this.listIndex = source.listIndex != null ? source.listIndex : null; } } serialize(config = new ToJsonConfiguration()) { return { name: this.name, fullName: this.fullName, normalizedName: this.normalizedName, listIndex: this.listIndex != null ? this.listIndex : null, }; } } /** Generic document. */ export class GenericDocument extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<GenericDocument>`} */ constructor(source = {}) { super(); /** Image crop of the document. */ this.crop = null; /** The average confidence in the accuracy of the document recognition result. Default is 0 */ this.confidence = 0.0; /** The weight of the confidence. Can be used to calculate the weighted average confidence of two documents. Default is 0 */ this.confidenceWeight = 0.0; this._released = false; if (source.type !== undefined) { this.type = new GenericDocumentType(source.type); } else { throw new Error('type must be present in constructor argument'); } if (source.fields !== undefined) { this.fields = source.fields.map((it) => { return new Field(it); }); } else { throw new Error('fields must be present in constructor argument'); } if (source.children !== undefined) { this.children = source.children.map((it) => { return new GenericDocument(it); }); } else { throw new Error('children must be present in constructor argument'); } if (source.quad !== undefined) { this.quad = source.quad.map((it) => { return { x: it.x, y: it.y }; }); } else { throw new Error('quad must be present in constructor argument'); } if (source.quadInRoot !== undefined) { this.quadInRoot = source.quadInRoot.map((it) => { return { x: it.x, y: it.y }; }); } else { throw new Error('quadInRoot must be present in constructor argument'); } if (source.crop !== undefined) { this.crop = source.crop != null ? ImageRef.From(source.crop) : null; } if (source.confidence !== undefined) { this.confidence = source.confidence; } if (source.confidenceWeight !== undefined) { this.confidenceWeight = source.confidenceWeight; } } async serialize(config = new ToJsonConfiguration()) { return { type: this.type.serialize(config), fields: await Promise.all(this.fields.map(async (it) => { return await it.serialize(config); })), children: await Promise.all(this.children.map(async (it) => { return await it.serialize(config); })), quad: this.quad.map((it) => { return it; }), quadInRoot: this.quadInRoot.map((it) => { return it; }), crop: config.serializeImages ? this.crop != null ? await this.crop.serialize(config.imageSerializationMode) : null : undefined, confidence: this.confidence, confidenceWeight: this.confidenceWeight, }; } release() { if (this._released) { return; } this.fields.forEach((it) => { it.release(); }); this.children.forEach((it) => { it.release(); }); { if (this.crop != null) { this.crop.release(); } } this._released = true; } async encodeImages() { await Promise.all(this.fields.map(async (it) => { await it.encodeImages(); })); await Promise.all(this.children.map(async (it) => { await it.encodeImages(); })); if (this.crop != null) { await this.crop.encodeInPlace(); } } } //# sourceMappingURL=GenericDocument.js.map