@azure/ai-form-recognizer 5.1.0-alpha.20250619.1 → 5.1.0-alpha.20250729.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/dist/browser/bin/defaultFields.js +14 -13
- package/dist/browser/bin/defaultFields.js.map +1 -1
- package/dist/browser/bin/writeModelCode.js +19 -19
- package/dist/browser/bin/writeModelCode.js.map +1 -1
- package/dist/browser/documentAnalysisClient.js +29 -13
- package/dist/browser/documentAnalysisClient.js.map +1 -1
- package/dist/browser/documentModel.js +20 -10
- package/dist/browser/documentModel.js.map +1 -1
- package/dist/browser/documentModelAdministrationClient.js +33 -10
- package/dist/browser/documentModelAdministrationClient.js.map +1 -1
- package/dist/browser/error.js +15 -2
- package/dist/browser/error.js.map +1 -1
- package/dist/browser/generated/generatedClient.js +14 -4
- package/dist/browser/generated/generatedClient.js.map +1 -1
- package/dist/browser/generated/models/mappers.js +20 -8
- package/dist/browser/generated/models/mappers.js.map +1 -1
- package/dist/browser/generated/operations/documentClassifiers.js +14 -31
- package/dist/browser/generated/operations/documentClassifiers.js.map +1 -1
- package/dist/browser/generated/operations/documentModels.js +14 -31
- package/dist/browser/generated/operations/documentModels.js.map +1 -1
- package/dist/browser/generated/operations/miscellaneous.js +14 -31
- package/dist/browser/generated/operations/miscellaneous.js.map +1 -1
- package/dist/browser/lro/administration.js +1 -2
- package/dist/browser/lro/administration.js.map +1 -1
- package/dist/browser/lro/analysis.js +37 -17
- package/dist/browser/lro/analysis.js.map +1 -1
- package/dist/browser/lro/util/delayMs.js +3 -3
- package/dist/browser/lro/util/delayMs.js.map +1 -1
- package/dist/browser/lro/util/poller.js +7 -7
- package/dist/browser/lro/util/poller.js.map +1 -1
- package/dist/browser/models/fields.js +11 -5
- package/dist/browser/models/fields.js.map +1 -1
- package/dist/browser/transforms/polygon.js +16 -5
- package/dist/browser/transforms/polygon.js.map +1 -1
- package/dist/browser/util.js +6 -3
- package/dist/browser/util.js.map +1 -1
- package/dist/commonjs/bin/defaultFields.js +14 -13
- package/dist/commonjs/bin/defaultFields.js.map +1 -1
- package/dist/commonjs/bin/writeModelCode.js +19 -19
- package/dist/commonjs/bin/writeModelCode.js.map +1 -1
- package/dist/commonjs/documentAnalysisClient.js +29 -13
- package/dist/commonjs/documentAnalysisClient.js.map +1 -1
- package/dist/commonjs/documentModel.js +20 -10
- package/dist/commonjs/documentModel.js.map +1 -1
- package/dist/commonjs/documentModelAdministrationClient.js +33 -10
- package/dist/commonjs/documentModelAdministrationClient.js.map +1 -1
- package/dist/commonjs/error.js +15 -2
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/generated/generatedClient.js +14 -4
- package/dist/commonjs/generated/generatedClient.js.map +1 -1
- package/dist/commonjs/generated/models/mappers.js +20 -8
- package/dist/commonjs/generated/models/mappers.js.map +1 -1
- package/dist/commonjs/generated/operations/documentClassifiers.js +14 -30
- package/dist/commonjs/generated/operations/documentClassifiers.js.map +1 -1
- package/dist/commonjs/generated/operations/documentModels.js +14 -30
- package/dist/commonjs/generated/operations/documentModels.js.map +1 -1
- package/dist/commonjs/generated/operations/miscellaneous.js +14 -30
- package/dist/commonjs/generated/operations/miscellaneous.js.map +1 -1
- package/dist/commonjs/lro/administration.js +1 -2
- package/dist/commonjs/lro/administration.js.map +1 -1
- package/dist/commonjs/lro/analysis.js +37 -17
- package/dist/commonjs/lro/analysis.js.map +1 -1
- package/dist/commonjs/lro/util/delayMs.js +3 -3
- package/dist/commonjs/lro/util/delayMs.js.map +1 -1
- package/dist/commonjs/lro/util/poller.js +7 -7
- package/dist/commonjs/lro/util/poller.js.map +1 -1
- package/dist/commonjs/models/fields.js +11 -5
- package/dist/commonjs/models/fields.js.map +1 -1
- package/dist/commonjs/transforms/polygon.js +16 -5
- package/dist/commonjs/transforms/polygon.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/util.js +6 -3
- package/dist/commonjs/util.js.map +1 -1
- package/dist/esm/bin/defaultFields.js +14 -13
- package/dist/esm/bin/defaultFields.js.map +1 -1
- package/dist/esm/bin/writeModelCode.js +19 -19
- package/dist/esm/bin/writeModelCode.js.map +1 -1
- package/dist/esm/documentAnalysisClient.js +29 -13
- package/dist/esm/documentAnalysisClient.js.map +1 -1
- package/dist/esm/documentModel.js +20 -10
- package/dist/esm/documentModel.js.map +1 -1
- package/dist/esm/documentModelAdministrationClient.js +33 -10
- package/dist/esm/documentModelAdministrationClient.js.map +1 -1
- package/dist/esm/error.js +15 -2
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/generated/generatedClient.js +14 -4
- package/dist/esm/generated/generatedClient.js.map +1 -1
- package/dist/esm/generated/models/mappers.js +20 -8
- package/dist/esm/generated/models/mappers.js.map +1 -1
- package/dist/esm/generated/operations/documentClassifiers.js +14 -31
- package/dist/esm/generated/operations/documentClassifiers.js.map +1 -1
- package/dist/esm/generated/operations/documentModels.js +14 -31
- package/dist/esm/generated/operations/documentModels.js.map +1 -1
- package/dist/esm/generated/operations/miscellaneous.js +14 -31
- package/dist/esm/generated/operations/miscellaneous.js.map +1 -1
- package/dist/esm/lro/administration.js +1 -2
- package/dist/esm/lro/administration.js.map +1 -1
- package/dist/esm/lro/analysis.js +37 -17
- package/dist/esm/lro/analysis.js.map +1 -1
- package/dist/esm/lro/util/delayMs.js +3 -3
- package/dist/esm/lro/util/delayMs.js.map +1 -1
- package/dist/esm/lro/util/poller.js +7 -7
- package/dist/esm/lro/util/poller.js.map +1 -1
- package/dist/esm/models/fields.js +11 -5
- package/dist/esm/models/fields.js.map +1 -1
- package/dist/esm/transforms/polygon.js +16 -5
- package/dist/esm/transforms/polygon.js.map +1 -1
- package/dist/esm/util.js +6 -3
- package/dist/esm/util.js.map +1 -1
- package/dist/react-native/bin/defaultFields.js +14 -13
- package/dist/react-native/bin/defaultFields.js.map +1 -1
- package/dist/react-native/bin/writeModelCode.js +19 -19
- package/dist/react-native/bin/writeModelCode.js.map +1 -1
- package/dist/react-native/documentAnalysisClient.js +29 -13
- package/dist/react-native/documentAnalysisClient.js.map +1 -1
- package/dist/react-native/documentModel.js +20 -10
- package/dist/react-native/documentModel.js.map +1 -1
- package/dist/react-native/documentModelAdministrationClient.js +33 -10
- package/dist/react-native/documentModelAdministrationClient.js.map +1 -1
- package/dist/react-native/error.js +15 -2
- package/dist/react-native/error.js.map +1 -1
- package/dist/react-native/generated/generatedClient.js +14 -4
- package/dist/react-native/generated/generatedClient.js.map +1 -1
- package/dist/react-native/generated/models/mappers.js +20 -8
- package/dist/react-native/generated/models/mappers.js.map +1 -1
- package/dist/react-native/generated/operations/documentClassifiers.js +14 -31
- package/dist/react-native/generated/operations/documentClassifiers.js.map +1 -1
- package/dist/react-native/generated/operations/documentModels.js +14 -31
- package/dist/react-native/generated/operations/documentModels.js.map +1 -1
- package/dist/react-native/generated/operations/miscellaneous.js +14 -31
- package/dist/react-native/generated/operations/miscellaneous.js.map +1 -1
- package/dist/react-native/lro/administration.js +1 -2
- package/dist/react-native/lro/administration.js.map +1 -1
- package/dist/react-native/lro/analysis.js +37 -17
- package/dist/react-native/lro/analysis.js.map +1 -1
- package/dist/react-native/lro/util/delayMs.js +3 -3
- package/dist/react-native/lro/util/delayMs.js.map +1 -1
- package/dist/react-native/lro/util/poller.js +7 -7
- package/dist/react-native/lro/util/poller.js.map +1 -1
- package/dist/react-native/models/fields.js +11 -5
- package/dist/react-native/models/fields.js.map +1 -1
- package/dist/react-native/transforms/polygon.js +16 -5
- package/dist/react-native/transforms/polygon.js.map +1 -1
- package/dist/react-native/util.js +6 -3
- package/dist/react-native/util.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analysis.js","sourceRoot":"","sources":["../../../src/lro/analysis.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAUlD,OAAO,EAAE,qCAAqC,EAAE,MAAM,q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oft Corporation.\n// Licensed under the MIT License.\n\nimport type { PollOperationState, PollerLike } from \"@azure/core-lro\";\nimport { FormRecognizerError } from \"../error.js\";\nimport type {\n AnalyzeResult as GeneratedAnalyzeResult,\n AnalyzeResultOperation,\n AnalyzeResultOperationStatus as AnalyzeOperationStatus,\n DocumentLanguage,\n DocumentSpan,\n DocumentStyle,\n} from \"../generated/index.js\";\nimport type { DocumentField } from \"../models/fields.js\";\nimport { toAnalyzedDocumentFieldsFromGenerated } from \"../models/fields.js\";\nimport type { PollerOptions } from \"../options/index.js\";\nimport type { AnalyzeDocumentOptions } from \"../options/AnalyzeDocumentOptions.js\";\nimport {\n toBoundingPolygon,\n toBoundingRegions,\n toDocumentTableFromGenerated,\n toKeyValuePairFromGenerated,\n} from \"../transforms/polygon.js\";\nimport type {\n BoundingRegion,\n DocumentTable,\n DocumentKeyValuePair,\n DocumentPage,\n DocumentLine,\n DocumentParagraph,\n DocumentFormula,\n} from \"../models/documentElements.js\";\nimport type {\n Document as GeneratedDocument,\n DocumentPage as GeneratedDocumentPage,\n DocumentLine as GeneratedDocumentLine,\n} from \"../generated/index.js\";\n\n/**\n * A request input that can be uploaded as binary data to the Form Recognizer service. Form Recognizer treats `string`\n * inputs as URLs, so to send a string as a _binary_ input, first convert the string to one of the following input\n * types.\n */\nexport type FormRecognizerRequestBody =\n | NodeJS.ReadableStream\n | Blob\n | ArrayBuffer\n | ArrayBufferView;\n\n/**\n * An extracted document object.\n *\n * An AnalyzedDocument is an instance of one of the document types within a model. Its fields correspond to the field\n * schema of the document type.\n */\nexport interface AnalyzedDocument {\n /**\n * The type of the document that was extracted. A model can have multiple document types (for example, in a composed\n * model), so this property indicates which document type the fields of this document correspond to.\n */\n docType: string;\n\n /**\n * The extracted fields, which correspond to the document type's field schema.\n */\n fields: { [field: string]: DocumentField };\n\n /**\n * Bounding regions covering the document.\n */\n boundingRegions?: BoundingRegion[];\n\n /**\n * Locations of the document's elements in the `content` text (reading-order-concatenated content).\n */\n spans: DocumentSpan[];\n\n /**\n * The service's confidence that it has correctly extracted the document.\n */\n confidence: number;\n}\n\n/**\n * Transform a REST-level Document response object into the more strongly-typed AnalyzedDocument.\n *\n * @internal\n * @param document - a REST-level document response object\n * @returns an AnalyzedDocument (which has had its fields mapped to stronger DocumentField types)\n */\nexport function toAnalyzedDocumentFromGenerated(document: GeneratedDocument): AnalyzedDocument {\n return {\n ...document,\n boundingRegions: toBoundingRegions(document.boundingRegions),\n fields: toAnalyzedDocumentFieldsFromGenerated(document.fields ?? {}),\n };\n}\n\n/**\n * The common fields of all AnalyzeResult-like types, such as LayoutResult, ReadResult, and GeneralDocumentResult.\n */\nexport interface AnalyzeResultCommon {\n /**\n * The service API version used to produce this result.\n */\n apiVersion: string;\n\n /**\n * The unique ID of the model that was used to produce this result.\n */\n modelId: string;\n\n /**\n * A string representation of all textual and visual elements in the input, concatenated by reading order (the order\n * in which the service \"reads\" or extracts the textual and visual content from the document).\n */\n content: string;\n}\n\n/**\n * The result of an analysis operation. The type of the Document may be determined by the model used to perform the\n * analysis.\n */\nexport interface AnalyzeResult<Document = AnalyzedDocument> extends AnalyzeResultCommon {\n /**\n * Extracted pages.\n */\n pages?: DocumentPage[];\n\n /**\n * Extracted tables.\n */\n tables?: DocumentTable[];\n\n /**\n * Extracted key-value pairs.\n */\n keyValuePairs?: DocumentKeyValuePair[];\n\n /**\n * Extracted text languages.\n */\n languages?: DocumentLanguage[];\n\n /**\n * Extracted font styles.\n */\n styles?: DocumentStyle[];\n\n /**\n * Extracted documents (instances of any of the model's document types and corresponding field schemas).\n */\n documents?: Document[];\n\n /**\n * Extracted document paragraphs.\n */\n paragraphs?: DocumentParagraph[];\n}\n\n/**\n * Tests if one span contains another, by testing that the outer span starts before or at the same character as the\n * inner span, and that the end position of the outer span is greater than or equal to the end position of the inner\n * span.\n *\n * @internal\n * @param outer - the outer (potentially containing) span\n * @param inner - the span to test if `outer` contains\n * @returns true if `inner` is contained inside of `outer`.\n */\nexport function contains(outer: DocumentSpan, inner: DocumentSpan): boolean {\n return outer.offset <= inner.offset && outer.offset + outer.length >= inner.offset + inner.length;\n}\n\n/**\n * Make an empty generator. This might seem silly, but it's useful for satisfying invariants.\n */\nfunction* empty(): Generator<never> {\n /* intentionally empty */\n}\n\n/**\n * Produces an iterator of the given items starting from the given index.\n *\n * @param items - the items to iterate over\n * @param idx - the index of the first item to begin iterating from\n */\nexport function* iterFrom<T>(items: T[], idx: number): Generator<T> {\n let i = idx;\n\n while (i < items.length) {\n yield items[i++];\n }\n}\n\nexport function toDocumentLineFromGenerated(\n generated: GeneratedDocumentLine,\n page: GeneratedDocumentPage,\n): DocumentLine {\n (generated as DocumentLine).words = () =>\n fastGetChildren(\n iterFrom(generated.spans, 0),\n page.words?.map((word) => {\n return { ...word, polygon: toBoundingPolygon(word.polygon) };\n }) ?? [],\n );\n\n (generated as DocumentLine).polygon = toBoundingPolygon(generated.polygon);\n\n Object.defineProperty(generated, \"words\", {\n enumerable: false,\n });\n\n return generated as DocumentLine;\n}\n\nexport function toDocumentPageFromGenerated(generated: GeneratedDocumentPage): DocumentPage {\n return {\n ...generated,\n lines: generated.lines?.map((line) => toDocumentLineFromGenerated(line, generated)),\n selectionMarks: generated.selectionMarks?.map((mark) => ({\n ...mark,\n polygon: toBoundingPolygon(mark.polygon),\n })),\n words: generated.words?.map((word) => ({\n ...word,\n polygon: toBoundingPolygon(word.polygon),\n })),\n barcodes: generated.barcodes?.map((barcode) => ({\n ...barcode,\n polygon: toBoundingPolygon(barcode.polygon),\n })),\n formulas: generated.formulas?.map(\n (formula): DocumentFormula => ({\n ...formula,\n polygon: toBoundingPolygon(formula.polygon),\n }),\n ),\n };\n}\n\n/**\n * Binary search through an array of items to find the first item that could possibly be contained by the given span,\n * then return an iterator beginning from that item.\n *\n * This allows a program to quickly find the first relevant item in the array for consideration when testing for span\n * inclusion.\n *\n * @internal\n * @param span - the span to use when testing each individual item\n * @param items - an array of items to binary search through\n * @returns an iterator beginning from the item identified by the search\n */\nexport function iteratorFromFirstMatchBinarySearch<Spanned extends { span: DocumentSpan }>(\n span: DocumentSpan,\n items: Spanned[],\n): IterableIterator<Spanned> {\n let idx = Math.floor(items.length / 2);\n let prevIdx = idx;\n let min = 0;\n let max = items.length;\n\n const found = (): boolean =>\n // The item is found if it starts after the current span and the item before it does not. That means it is the first\n // item in the array that could be a child if the spans are sorted.\n items[idx].span.offset >= span.offset && (items[idx - 1]?.span?.offset ?? -1) < span.offset;\n\n // Binary search to find the first element that could be a child\n do {\n if (found()) {\n return iterFrom(items, idx);\n } else if (span.offset > items[idx].span.offset) {\n min = prevIdx = idx;\n idx = Math.floor(idx + (max - idx) / 2);\n } else {\n max = prevIdx = idx;\n idx = Math.floor(idx - (idx - min) / 2);\n }\n } while (idx !== prevIdx);\n\n // This might seem weird, but it's a simple way to make the types a little more elegant.\n return empty();\n}\n\n/**\n * This fast algorithm tests the elements of `childArray` for inclusion in any of the given `spans`, assuming that both\n * the spans and child items are sorted.\n *\n * INVARIANT: the items in both the `spans` iterator and `childrenArray` MUST BE SORTED INCREASING by span _offset_.\n *\n * @internal\n * @param spans - the spans that contain the child elements\n * @param childrenArray - an array of child items (items that have spans) to test for inclusion in the spans\n * @returns - an IterableIterator of child items that are included in any span in the `spans` iterator\n */\nexport function* fastGetChildren<Spanned extends { span: DocumentSpan }>(\n spans: Iterator<DocumentSpan>,\n childrenArray: Spanned[],\n): Generator<Spanned> {\n let curSpan = spans.next();\n\n // Need to exit early if there are no spans.\n if (curSpan.done) {\n return;\n }\n\n const children = iteratorFromFirstMatchBinarySearch(curSpan.value as DocumentSpan, childrenArray);\n let curChild = children.next();\n\n while (!(curChild.done || curSpan.done)) {\n if (contains(curSpan.value, curChild.value.span)) {\n // The span is contained, so yield the current child and advance it.\n yield curChild.value;\n curChild = children.next();\n } else if (curSpan.value.offset + curSpan.value.length < curChild.value.span.offset) {\n // The current span ends before the next potential child starts, so advance the span\n curSpan = spans.next();\n } else {\n // The current child was not contained in the current span, so advance to the next child.\n curChild = children.next();\n }\n }\n}\n\n/**\n * The state of an analysis operation, which will eventually produce the result type that corresponds to the model.\n */\nexport interface DocumentAnalysisPollOperationState<Result = AnalyzeResult<AnalyzedDocument>>\n extends PollOperationState<Result> {\n /**\n * The status of the operation. One of:\n *\n * - \"notStarted\"\n * - \"running\"\n * - \"succeeded\"\n * - \"failed\"\n */\n status: AnalyzeOperationStatus;\n\n /**\n * The model ID that the analysis operation will use to produce the result.\n */\n modelId: string;\n\n /**\n * The URL to the operation.\n */\n operationLocation: string;\n\n /**\n * The Date and Time that the operation was created.\n */\n createdOn: Date;\n\n /**\n * The date & time that the operation state was last modified.\n */\n lastUpdatedOn: Date;\n}\n\n/**\n * A long-running operation (poller) that tracks the state of an analysis operation, eventually producing the result\n * type that corresponds to the model.\n */\nexport type AnalysisPoller<Result = AnalyzeResult<AnalyzedDocument>> = PollerLike<\n DocumentAnalysisPollOperationState<Result>,\n Result\n>;\n\n/**\n * Convert a generated AnalyzeResult into a convenience layer AnalyzeResult.\n * @internal\n */\nexport function toAnalyzeResultFromGenerated(result: GeneratedAnalyzeResult): AnalyzeResult {\n return {\n apiVersion: result.apiVersion,\n modelId: result.modelId,\n content: result.content,\n pages: result.pages.map((page) => toDocumentPageFromGenerated(page)),\n tables: result.tables?.map((table) => toDocumentTableFromGenerated(table)),\n keyValuePairs: result.keyValuePairs?.map((pair) => toKeyValuePairFromGenerated(pair)),\n languages: result.languages,\n styles: result.styles,\n paragraphs: result.paragraphs?.map((para) => ({\n ...para,\n boundingRegions: toBoundingRegions(para.boundingRegions),\n })),\n documents: result.documents?.map(toAnalyzedDocumentFromGenerated),\n };\n}\n\n/**\n * Defines an analysis operation by the initial request model ID, poller options, and a transform to apply to the\n * eventual result,\n *\n * @internal\n */\nexport interface AnalysisOperationDefinition<Result = AnalyzeResult> {\n transformResult: (primitiveResult: GeneratedAnalyzeResult) => Result;\n initialModelId: string;\n options: PollerOptions<DocumentAnalysisPollOperationState<Result>> &\n AnalyzeDocumentOptions<Result>;\n}\n\n/**\n * Converts an AnalyzeResultOperation (LRO response) to a DocumentAnalysisPollOperationState\n * @internal\n */\nexport function toDocumentAnalysisPollOperationState<Result>(\n definition: AnalysisOperationDefinition<Result>,\n modelId: string,\n operationLocation: string,\n response: AnalyzeResultOperation,\n): DocumentAnalysisPollOperationState<Result> {\n return {\n status: response.status,\n modelId: modelId,\n lastUpdatedOn: response.lastUpdatedOn,\n createdOn: response.createdOn,\n operationLocation,\n result: response.analyzeResult && definition.transformResult(response.analyzeResult),\n error: response.error && new FormRecognizerError(response.error),\n isCancelled: false, // Not supported\n isStarted: response.status !== \"notStarted\",\n isCompleted: response.status === \"succeeded\",\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"analysis.js","sourceRoot":"","sources":["../../../src/lro/analysis.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAUlD,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAG5E,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AA6DlC;;;;;;GAMG;AACH,MAAM,UAAU,+BAA+B,CAAC,QAA2B;IACzE,OAAO;QACL,GAAG,QAAQ;QACX,eAAe,EAAE,iBAAiB,CAAC,QAAQ,CAAC,eAAe,CAAC;QAC5D,MAAM,EAAE,qCAAqC,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC;KACrE,CAAC;AACJ,CAAC;AAgED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAmB,EAAE,KAAmB;IAC/D,OAAO,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;AACpG,CAAC;AAED;;GAE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;GAGG;AACH,MAAM,UAAU,oCAAoC,CAClD,UAA+C,EAC/C,OAAe,EACf,iBAAyB,EACzB,QAAgC;IAEhC,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,OAAO;QAChB,aAAa,EAAE,QAAQ,CAAC,aAAa;QACrC,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,iBAAiB;QACjB,MAAM,EAAE,QAAQ,CAAC,aAAa,IAAI,UAAU,CAAC,eAAe,CAAC,QAAQ,CAAC,aAAa,CAAC;QACpF,KAAK,EAAE,QAAQ,CAAC,KAAK,IAAI,IAAI,mBAAmB,CAAC,QAAQ,CAAC,KAAK,CAAC;QAChE,WAAW,EAAE,KAAK,EAAE,gBAAgB;QACpC,SAAS,EAAE,QAAQ,CAAC,MAAM,KAAK,YAAY;QAC3C,WAAW,EAAE,QAAQ,CAAC,MAAM,KAAK,WAAW;KAC7C,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PollOperationState, PollerLike } from \"@azure/core-lro\";\nimport { FormRecognizerError } from \"../error.js\";\nimport type {\n AnalyzeResult as GeneratedAnalyzeResult,\n AnalyzeResultOperation,\n AnalyzeResultOperationStatus as AnalyzeOperationStatus,\n DocumentLanguage,\n DocumentSpan,\n DocumentStyle,\n} from \"../generated/index.js\";\nimport type { DocumentField } from \"../models/fields.js\";\nimport { toAnalyzedDocumentFieldsFromGenerated } from \"../models/fields.js\";\nimport type { PollerOptions } from \"../options/index.js\";\nimport type { AnalyzeDocumentOptions } from \"../options/AnalyzeDocumentOptions.js\";\nimport {\n toBoundingPolygon,\n toBoundingRegions,\n toDocumentTableFromGenerated,\n toKeyValuePairFromGenerated,\n} from \"../transforms/polygon.js\";\nimport type {\n BoundingRegion,\n DocumentTable,\n DocumentKeyValuePair,\n DocumentPage,\n DocumentLine,\n DocumentParagraph,\n DocumentFormula,\n} from \"../models/documentElements.js\";\nimport type {\n Document as GeneratedDocument,\n DocumentPage as GeneratedDocumentPage,\n DocumentLine as GeneratedDocumentLine,\n} from \"../generated/index.js\";\n\n/**\n * A request input that can be uploaded as binary data to the Form Recognizer service. Form Recognizer treats `string`\n * inputs as URLs, so to send a string as a _binary_ input, first convert the string to one of the following input\n * types.\n */\nexport type FormRecognizerRequestBody =\n | NodeJS.ReadableStream\n | Blob\n | ArrayBuffer\n | ArrayBufferView;\n\n/**\n * An extracted document object.\n *\n * An AnalyzedDocument is an instance of one of the document types within a model. Its fields correspond to the field\n * schema of the document type.\n */\nexport interface AnalyzedDocument {\n /**\n * The type of the document that was extracted. A model can have multiple document types (for example, in a composed\n * model), so this property indicates which document type the fields of this document correspond to.\n */\n docType: string;\n\n /**\n * The extracted fields, which correspond to the document type's field schema.\n */\n fields: { [field: string]: DocumentField };\n\n /**\n * Bounding regions covering the document.\n */\n boundingRegions?: BoundingRegion[];\n\n /**\n * Locations of the document's elements in the `content` text (reading-order-concatenated content).\n */\n spans: DocumentSpan[];\n\n /**\n * The service's confidence that it has correctly extracted the document.\n */\n confidence: number;\n}\n\n/**\n * Transform a REST-level Document response object into the more strongly-typed AnalyzedDocument.\n *\n * @internal\n * @param document - a REST-level document response object\n * @returns an AnalyzedDocument (which has had its fields mapped to stronger DocumentField types)\n */\nexport function toAnalyzedDocumentFromGenerated(document: GeneratedDocument): AnalyzedDocument {\n return {\n ...document,\n boundingRegions: toBoundingRegions(document.boundingRegions),\n fields: toAnalyzedDocumentFieldsFromGenerated(document.fields ?? {}),\n };\n}\n\n/**\n * The common fields of all AnalyzeResult-like types, such as LayoutResult, ReadResult, and GeneralDocumentResult.\n */\nexport interface AnalyzeResultCommon {\n /**\n * The service API version used to produce this result.\n */\n apiVersion: string;\n\n /**\n * The unique ID of the model that was used to produce this result.\n */\n modelId: string;\n\n /**\n * A string representation of all textual and visual elements in the input, concatenated by reading order (the order\n * in which the service \"reads\" or extracts the textual and visual content from the document).\n */\n content: string;\n}\n\n/**\n * The result of an analysis operation. The type of the Document may be determined by the model used to perform the\n * analysis.\n */\nexport interface AnalyzeResult<Document = AnalyzedDocument> extends AnalyzeResultCommon {\n /**\n * Extracted pages.\n */\n pages?: DocumentPage[];\n\n /**\n * Extracted tables.\n */\n tables?: DocumentTable[];\n\n /**\n * Extracted key-value pairs.\n */\n keyValuePairs?: DocumentKeyValuePair[];\n\n /**\n * Extracted text languages.\n */\n languages?: DocumentLanguage[];\n\n /**\n * Extracted font styles.\n */\n styles?: DocumentStyle[];\n\n /**\n * Extracted documents (instances of any of the model's document types and corresponding field schemas).\n */\n documents?: Document[];\n\n /**\n * Extracted document paragraphs.\n */\n paragraphs?: DocumentParagraph[];\n}\n\n/**\n * Tests if one span contains another, by testing that the outer span starts before or at the same character as the\n * inner span, and that the end position of the outer span is greater than or equal to the end position of the inner\n * span.\n *\n * @internal\n * @param outer - the outer (potentially containing) span\n * @param inner - the span to test if `outer` contains\n * @returns true if `inner` is contained inside of `outer`.\n */\nexport function contains(outer: DocumentSpan, inner: DocumentSpan): boolean {\n return outer.offset <= inner.offset && outer.offset + outer.length >= inner.offset + inner.length;\n}\n\n/**\n * Make an empty generator. This might seem silly, but it's useful for satisfying invariants.\n */\nfunction* empty(): Generator<never> {\n /* intentionally empty */\n}\n\n/**\n * Produces an iterator of the given items starting from the given index.\n *\n * @param items - the items to iterate over\n * @param idx - the index of the first item to begin iterating from\n */\nexport function* iterFrom<T>(items: T[], idx: number): Generator<T> {\n let i = idx;\n\n while (i < items.length) {\n yield items[i++];\n }\n}\n\nexport function toDocumentLineFromGenerated(\n generated: GeneratedDocumentLine,\n page: GeneratedDocumentPage,\n): DocumentLine {\n (generated as DocumentLine).words = () =>\n fastGetChildren(\n iterFrom(generated.spans, 0),\n page.words?.map((word) => {\n return { ...word, polygon: toBoundingPolygon(word.polygon) };\n }) ?? [],\n );\n\n (generated as DocumentLine).polygon = toBoundingPolygon(generated.polygon);\n\n Object.defineProperty(generated, \"words\", {\n enumerable: false,\n });\n\n return generated as DocumentLine;\n}\n\nexport function toDocumentPageFromGenerated(generated: GeneratedDocumentPage): DocumentPage {\n return {\n ...generated,\n lines: generated.lines?.map((line) => toDocumentLineFromGenerated(line, generated)),\n selectionMarks: generated.selectionMarks?.map((mark) => ({\n ...mark,\n polygon: toBoundingPolygon(mark.polygon),\n })),\n words: generated.words?.map((word) => ({\n ...word,\n polygon: toBoundingPolygon(word.polygon),\n })),\n barcodes: generated.barcodes?.map((barcode) => ({\n ...barcode,\n polygon: toBoundingPolygon(barcode.polygon),\n })),\n formulas: generated.formulas?.map(\n (formula): DocumentFormula => ({\n ...formula,\n polygon: toBoundingPolygon(formula.polygon),\n }),\n ),\n };\n}\n\n/**\n * Binary search through an array of items to find the first item that could possibly be contained by the given span,\n * then return an iterator beginning from that item.\n *\n * This allows a program to quickly find the first relevant item in the array for consideration when testing for span\n * inclusion.\n *\n * @internal\n * @param span - the span to use when testing each individual item\n * @param items - an array of items to binary search through\n * @returns an iterator beginning from the item identified by the search\n */\nexport function iteratorFromFirstMatchBinarySearch<Spanned extends { span: DocumentSpan }>(\n span: DocumentSpan,\n items: Spanned[],\n): IterableIterator<Spanned> {\n let idx = Math.floor(items.length / 2);\n let prevIdx = idx;\n let min = 0;\n let max = items.length;\n\n const found = (): boolean =>\n // The item is found if it starts after the current span and the item before it does not. That means it is the first\n // item in the array that could be a child if the spans are sorted.\n items[idx].span.offset >= span.offset && (items[idx - 1]?.span?.offset ?? -1) < span.offset;\n\n // Binary search to find the first element that could be a child\n do {\n if (found()) {\n return iterFrom(items, idx);\n } else if (span.offset > items[idx].span.offset) {\n min = prevIdx = idx;\n idx = Math.floor(idx + (max - idx) / 2);\n } else {\n max = prevIdx = idx;\n idx = Math.floor(idx - (idx - min) / 2);\n }\n } while (idx !== prevIdx);\n\n // This might seem weird, but it's a simple way to make the types a little more elegant.\n return empty();\n}\n\n/**\n * This fast algorithm tests the elements of `childArray` for inclusion in any of the given `spans`, assuming that both\n * the spans and child items are sorted.\n *\n * INVARIANT: the items in both the `spans` iterator and `childrenArray` MUST BE SORTED INCREASING by span _offset_.\n *\n * @internal\n * @param spans - the spans that contain the child elements\n * @param childrenArray - an array of child items (items that have spans) to test for inclusion in the spans\n * @returns - an IterableIterator of child items that are included in any span in the `spans` iterator\n */\nexport function* fastGetChildren<Spanned extends { span: DocumentSpan }>(\n spans: Iterator<DocumentSpan>,\n childrenArray: Spanned[],\n): Generator<Spanned> {\n let curSpan = spans.next();\n\n // Need to exit early if there are no spans.\n if (curSpan.done) {\n return;\n }\n\n const children = iteratorFromFirstMatchBinarySearch(curSpan.value as DocumentSpan, childrenArray);\n let curChild = children.next();\n\n while (!(curChild.done || curSpan.done)) {\n if (contains(curSpan.value, curChild.value.span)) {\n // The span is contained, so yield the current child and advance it.\n yield curChild.value;\n curChild = children.next();\n } else if (curSpan.value.offset + curSpan.value.length < curChild.value.span.offset) {\n // The current span ends before the next potential child starts, so advance the span\n curSpan = spans.next();\n } else {\n // The current child was not contained in the current span, so advance to the next child.\n curChild = children.next();\n }\n }\n}\n\n/**\n * The state of an analysis operation, which will eventually produce the result type that corresponds to the model.\n */\nexport interface DocumentAnalysisPollOperationState<Result = AnalyzeResult<AnalyzedDocument>>\n extends PollOperationState<Result> {\n /**\n * The status of the operation. One of:\n *\n * - \"notStarted\"\n * - \"running\"\n * - \"succeeded\"\n * - \"failed\"\n */\n status: AnalyzeOperationStatus;\n\n /**\n * The model ID that the analysis operation will use to produce the result.\n */\n modelId: string;\n\n /**\n * The URL to the operation.\n */\n operationLocation: string;\n\n /**\n * The Date and Time that the operation was created.\n */\n createdOn: Date;\n\n /**\n * The date & time that the operation state was last modified.\n */\n lastUpdatedOn: Date;\n}\n\n/**\n * A long-running operation (poller) that tracks the state of an analysis operation, eventually producing the result\n * type that corresponds to the model.\n */\nexport type AnalysisPoller<Result = AnalyzeResult<AnalyzedDocument>> = PollerLike<\n DocumentAnalysisPollOperationState<Result>,\n Result\n>;\n\n/**\n * Convert a generated AnalyzeResult into a convenience layer AnalyzeResult.\n * @internal\n */\nexport function toAnalyzeResultFromGenerated(result: GeneratedAnalyzeResult): AnalyzeResult {\n return {\n apiVersion: result.apiVersion,\n modelId: result.modelId,\n content: result.content,\n pages: result.pages.map((page) => toDocumentPageFromGenerated(page)),\n tables: result.tables?.map((table) => toDocumentTableFromGenerated(table)),\n keyValuePairs: result.keyValuePairs?.map((pair) => toKeyValuePairFromGenerated(pair)),\n languages: result.languages,\n styles: result.styles,\n paragraphs: result.paragraphs?.map((para) => ({\n ...para,\n boundingRegions: toBoundingRegions(para.boundingRegions),\n })),\n documents: result.documents?.map(toAnalyzedDocumentFromGenerated),\n };\n}\n\n/**\n * Defines an analysis operation by the initial request model ID, poller options, and a transform to apply to the\n * eventual result,\n *\n * @internal\n */\nexport interface AnalysisOperationDefinition<Result = AnalyzeResult> {\n transformResult: (primitiveResult: GeneratedAnalyzeResult) => Result;\n initialModelId: string;\n options: PollerOptions<DocumentAnalysisPollOperationState<Result>> &\n AnalyzeDocumentOptions<Result>;\n}\n\n/**\n * Converts an AnalyzeResultOperation (LRO response) to a DocumentAnalysisPollOperationState\n * @internal\n */\nexport function toDocumentAnalysisPollOperationState<Result>(\n definition: AnalysisOperationDefinition<Result>,\n modelId: string,\n operationLocation: string,\n response: AnalyzeResultOperation,\n): DocumentAnalysisPollOperationState<Result> {\n return {\n status: response.status,\n modelId: modelId,\n lastUpdatedOn: response.lastUpdatedOn,\n createdOn: response.createdOn,\n operationLocation,\n result: response.analyzeResult && definition.transformResult(response.analyzeResult),\n error: response.error && new FormRecognizerError(response.error),\n isCancelled: false, // Not supported\n isStarted: response.status !== \"notStarted\",\n isCompleted: response.status === \"succeeded\",\n };\n}\n"]}
|
|
@@ -24,9 +24,9 @@ import { maybemap } from "../../util.js";
|
|
|
24
24
|
export function delayMs(ms, abortSignal) {
|
|
25
25
|
let aborted = false;
|
|
26
26
|
let toReject;
|
|
27
|
-
abortSignal
|
|
27
|
+
abortSignal?.addEventListener("abort", () => {
|
|
28
28
|
aborted = true;
|
|
29
|
-
toReject
|
|
29
|
+
toReject?.(new AbortError("The operation was aborted."));
|
|
30
30
|
});
|
|
31
31
|
return Object.assign(new Promise((resolve, reject) => {
|
|
32
32
|
let token;
|
|
@@ -45,7 +45,7 @@ export function delayMs(ms, abortSignal) {
|
|
|
45
45
|
}), {
|
|
46
46
|
cancel: () => {
|
|
47
47
|
aborted = true;
|
|
48
|
-
toReject
|
|
48
|
+
toReject?.(new Error("The operation was cancelled."));
|
|
49
49
|
},
|
|
50
50
|
});
|
|
51
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delayMs.js","sourceRoot":"","sources":["../../../../src/lro/util/delayMs.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAezC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,OAAO,CACrB,EAAU,EACV,WAAwC;IAExC,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,QAA0C,CAAC;IAE/C,WAAW,
|
|
1
|
+
{"version":3,"file":"delayMs.js","sourceRoot":"","sources":["../../../../src/lro/util/delayMs.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAezC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,OAAO,CACrB,EAAU,EACV,WAAwC;IAExC,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,QAA0C,CAAC;IAE/C,WAAW,EAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;QAC1C,OAAO,GAAG,IAAI,CAAC;QACf,QAAQ,EAAE,CAAC,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,MAAM,CAClB,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACpC,IAAI,KAAoC,CAAC;QACzC,QAAQ,GAAG,CAAC,CAAC,EAAE,EAAE;YACf,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAC9B,MAAM,CAAC,CAAC,CAAC,CAAC;QACZ,CAAC,CAAC;QAEF,6GAA6G;QAC7G,+FAA+F;QAC/F,IAAI,OAAO,EAAE,CAAC;YACZ,QAAQ,CAAC,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC,CAAC;QAClE,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC;IACH,CAAC,CAAC,EACF;QACE,MAAM,EAAE,GAAG,EAAE;YACX,OAAO,GAAG,IAAI,CAAC;YACf,QAAQ,EAAE,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;QACxD,CAAC;KACF,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { AbortError } from \"@azure/abort-controller\";\nimport { maybemap } from \"../../util.js\";\n\ntype CancellationToken = Parameters<typeof clearTimeout>[0];\n\n/**\n * A PromiseLike object that supports cancellation.\n * @internal\n */\nexport interface CancelablePromiseLike<T> extends PromiseLike<T> {\n /**\n * Cancel the promise (cause it to reject).\n */\n cancel(): void;\n}\n\n/**\n * A promise that delays resolution until a certain amount of time (in milliseconds) has passed, with facilities for\n * robust cancellation.\n *\n * ### Example:\n *\n * ```ts snippet:ignore\n * let toCancel;\n *\n * // Wait 20 seconds, and optionally allow the function to be cancelled.\n * await delayMs(20000, (cancel) => { toCancel = cancel });\n *\n * // ... if `toCancel` is called before the 20 second timer expires, then the delayMs promise will reject.\n * ```\n *\n * @internal\n * @param ms - the number of milliseconds to wait before resolving\n * @param cb - a callback that can provide the caller with a cancellation function\n */\nexport function delayMs(\n ms: number,\n abortSignal: AbortSignalLike | undefined,\n): CancelablePromiseLike<void> {\n let aborted = false;\n let toReject: ((e: Error) => void) | undefined;\n\n abortSignal?.addEventListener(\"abort\", () => {\n aborted = true;\n toReject?.(new AbortError(\"The operation was aborted.\"));\n });\n\n return Object.assign(\n new Promise<void>((resolve, reject) => {\n let token: CancellationToken | undefined;\n toReject = (e) => {\n maybemap(token, clearTimeout);\n reject(e);\n };\n\n // In the rare case that the operation is _already_ aborted, we will reject instantly. This could happen, for\n // example, if the user calls the cancellation function immediately without yielding execution.\n if (aborted) {\n toReject(new Error(\"The operation was cancelled prematurely.\"));\n } else {\n token = setTimeout(resolve, ms);\n }\n }),\n {\n cancel: () => {\n aborted = true;\n toReject?.(new Error(\"The operation was cancelled.\"));\n },\n },\n );\n}\n"]}
|
|
@@ -16,7 +16,7 @@ export async function lro(spec, pollingInterval, initAbortSignal) {
|
|
|
16
16
|
serverDrivenDelay = interval;
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
|
-
if (initAbortSignal
|
|
19
|
+
if (initAbortSignal?.aborted) {
|
|
20
20
|
throw new AbortError("The operation was aborted.");
|
|
21
21
|
}
|
|
22
22
|
let state = await spec.init(initContext);
|
|
@@ -32,24 +32,24 @@ export async function lro(spec, pollingInterval, initAbortSignal) {
|
|
|
32
32
|
handlers.set(s, callback);
|
|
33
33
|
return () => handlers.delete(s);
|
|
34
34
|
},
|
|
35
|
-
stopPolling: () => cancelJob
|
|
35
|
+
stopPolling: () => cancelJob?.(),
|
|
36
36
|
poll: async (options) => {
|
|
37
37
|
state = await spec.poll({
|
|
38
|
-
abortSignal: options
|
|
38
|
+
abortSignal: options?.abortSignal,
|
|
39
39
|
updateDelay: (interval) => {
|
|
40
40
|
serverDrivenDelay = interval;
|
|
41
41
|
},
|
|
42
42
|
}, state);
|
|
43
43
|
handleProgressEvents();
|
|
44
44
|
},
|
|
45
|
-
pollUntilDone: (options) => (job
|
|
45
|
+
pollUntilDone: (options) => (job ??= (async () => {
|
|
46
46
|
// Technically, the poller could complete during initialization
|
|
47
47
|
if (!self.isDone()) {
|
|
48
48
|
// Poll once to get the ball rolling, this avoids a delay if the operation completes immediately
|
|
49
49
|
await self.poll(options);
|
|
50
50
|
while (!self.isDone()) {
|
|
51
|
-
const finalPollingInterval = Math.max(serverDrivenDelay
|
|
52
|
-
const delay = delayMs(finalPollingInterval, options
|
|
51
|
+
const finalPollingInterval = Math.max(serverDrivenDelay ?? 0, pollingInterval ?? DEFAULT_POLLING_INTERVAL);
|
|
52
|
+
const delay = delayMs(finalPollingInterval, options?.abortSignal);
|
|
53
53
|
cancelJob = delay.cancel;
|
|
54
54
|
await delay.then(() => self.poll());
|
|
55
55
|
}
|
|
@@ -66,7 +66,7 @@ export async function lro(spec, pollingInterval, initAbortSignal) {
|
|
|
66
66
|
}
|
|
67
67
|
})().finally(() => {
|
|
68
68
|
job = undefined;
|
|
69
|
-
}))
|
|
69
|
+
})),
|
|
70
70
|
// The poller is stopped if there is no job running
|
|
71
71
|
isStopped: () => !!job,
|
|
72
72
|
// The operation is complete if either a result or error is produced
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../../src/lro/util/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAqCtC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CACvB,IAA2B,EAC3B,eAAmC,EACnC,eAA4C;IAE5C,IAAI,iBAAqC,CAAC;IAE1C,MAAM,WAAW,GAAqB;QACpC,WAAW,EAAE,eAAe;QAC5B,WAAW,EA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K,CAAC,KAAK,KAAK,SAAS;gBAAE,MAAM,KAAK,CAAC,KAAK,CAAC;YACtD,cAAc;iBACT,CAAC;gBACJ,MAAM,IAAI,KAAK,CACb,8EAA8E,KAAK,EAAE,CACtF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;YAChB,GAAG,GAAG,SAAS,CAAC;QAClB,CAAC,CAAC,CAAC;QACL,mDAAmD;QACnD,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG;QACtB,oEAAoE;QACpE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK;QAC7C,0CAA0C;QAC1C,eAAe;YACb,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;QAChG,CAAC;QACD,iBAAiB,EAAE,GAAG,EAAE,CAAC,KAAK;QAC9B,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM;QAC7B,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;KACtC,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PollOperationState, PollerLike } from \"@azure/core-lro\";\nimport { delayMs } from \"./delayMs.js\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport { AbortError } from \"@azure/abort-controller\";\n\nconst DEFAULT_POLLING_INTERVAL = 5000;\n\n/**\n * Information about the Long-Running Operation (LRO) that is being performed.\n */\nexport interface OperationContext {\n /**\n * An AbortSignal that can be used to cancel the operation.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Sets the server's preferred polling interval in milliseconds. To clear the server's preferred polling interval,\n * pass `undefined`.\n */\n updateDelay: (interval: number | undefined) => void;\n}\n\n/**\n * A specification for a long-running operation, which defines the poller flow.\n * @internal\n */\nexport interface OperationSpec<TState extends PollOperationState<unknown>> {\n /**\n * A function that produces the first operation state for this LRO.\n */\n init: (ctx: OperationContext) => Promise<TState>;\n /**\n * A function that consumes the existing state of the poller and produces the next state.\n */\n poll: (ctx: OperationContext, state: TState) => Promise<TState>;\n /**\n * A function that serializes the state into a string.\n */\n serialize: (state: TState) => string;\n}\n\n/**\n * Uniform poller implementation, creates a poller based on a PollerSpec.\n *\n * @internal\n */\nexport async function lro<TResult, TState extends PollOperationState<TResult>>(\n spec: OperationSpec<TState>,\n pollingInterval: number | undefined,\n initAbortSignal: AbortSignalLike | undefined,\n): Promise<PollerLike<TState, TResult>> {\n let serverDrivenDelay: number | undefined;\n\n const initContext: OperationContext = {\n abortSignal: initAbortSignal,\n updateDelay: (interval) => {\n serverDrivenDelay = interval;\n },\n };\n\n if (initAbortSignal?.aborted) {\n throw new AbortError(\"The operation was aborted.\");\n }\n\n let state = await spec.init(initContext);\n\n type ThisPoller = PollerLike<TState, TResult>;\n\n // Job handling. If `job` is defined, then there is an active `pollUntilDone` call on this poller.\n // Call `cancelJob` to interrupt the polling loop (awaiters will throw).\n let job: Promise<TResult> | undefined;\n let cancelJob: (() => void) | undefined;\n\n // Progress handlers\n type Handler = (state: TState) => void;\n const handlers = new Map<symbol, Handler>();\n const handleProgressEvents = async (): Promise<void> => handlers.forEach((h) => h(state));\n\n const self: ThisPoller = {\n onProgress: (callback: (state: TState) => void) => {\n const s = Symbol();\n handlers.set(s, callback);\n return () => handlers.delete(s);\n },\n stopPolling: () => cancelJob?.(),\n poll: async (options) => {\n state = await spec.poll(\n {\n abortSignal: options?.abortSignal,\n updateDelay: (interval) => {\n serverDrivenDelay = interval;\n },\n },\n state,\n );\n handleProgressEvents();\n },\n pollUntilDone: (options) =>\n (job ??= (async () => {\n // Technically, the poller could complete during initialization\n if (!self.isDone()) {\n // Poll once to get the ball rolling, this avoids a delay if the operation completes immediately\n await self.poll(options);\n while (!self.isDone()) {\n const finalPollingInterval = Math.max(\n serverDrivenDelay ?? 0,\n pollingInterval ?? DEFAULT_POLLING_INTERVAL,\n );\n const delay = delayMs(finalPollingInterval, options?.abortSignal);\n cancelJob = delay.cancel;\n await delay.then(() => self.poll());\n }\n }\n const result = self.getResult();\n\n // The state says it's done, so we know we are in either a success case, an error case, or an _internal_ error.\n if (result !== undefined) return result;\n else if (state.error !== undefined) throw state.error;\n // Unreachable\n else {\n throw new Error(\n `Internal Client Error: analysis poller completed without success or error: ${state}`,\n );\n }\n })().finally(() => {\n job = undefined;\n })),\n // The poller is stopped if there is no job running\n isStopped: () => !!job,\n // The operation is complete if either a result or error is produced\n isDone: () => !!state.result || !!state.error,\n // In FR, all operations run to completion\n cancelOperation() {\n throw new Error(\"The Azure Form Recognizer service does not support operation cancellation.\");\n },\n getOperationState: () => state,\n getResult: () => state.result,\n toString: () => spec.serialize(state),\n };\n\n return self;\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import { capitalize } from "../util.js";
|
|
|
9
9
|
* @returns - an object with the same keys, where all values have been mapped to DocumentFields
|
|
10
10
|
*/
|
|
11
11
|
export function toAnalyzedDocumentFieldsFromGenerated(fields) {
|
|
12
|
-
return Object.entries(fields
|
|
12
|
+
return Object.entries(fields ?? {}).reduce((transformedFields, [name, value]) => {
|
|
13
13
|
transformedFields[name] = toDocumentField(value);
|
|
14
14
|
return transformedFields;
|
|
15
15
|
}, {});
|
|
@@ -21,7 +21,6 @@ export function toAnalyzedDocumentFieldsFromGenerated(fields) {
|
|
|
21
21
|
export function toDocumentField(field) {
|
|
22
22
|
const kind = field.type;
|
|
23
23
|
const value = (() => {
|
|
24
|
-
var _a, _b;
|
|
25
24
|
switch (kind) {
|
|
26
25
|
// Almost all value kinds are represented as simple elemental values
|
|
27
26
|
case "string":
|
|
@@ -40,9 +39,9 @@ export function toDocumentField(field) {
|
|
|
40
39
|
value: field[("value" + capitalize(kind))],
|
|
41
40
|
};
|
|
42
41
|
case "array":
|
|
43
|
-
return { values:
|
|
42
|
+
return { values: field.valueArray?.map((v) => toDocumentField(v) ?? []) };
|
|
44
43
|
case "object":
|
|
45
|
-
return { properties: toAnalyzedDocumentFieldsFromGenerated(
|
|
44
|
+
return { properties: toAnalyzedDocumentFieldsFromGenerated(field.valueObject ?? {}) };
|
|
46
45
|
default:
|
|
47
46
|
// Exhaustiveness check
|
|
48
47
|
// eslint-disable-next-line no-case-declarations
|
|
@@ -50,6 +49,13 @@ export function toDocumentField(field) {
|
|
|
50
49
|
throw new Error(`Unrecognized DocumentField type: ${__exhaust}`);
|
|
51
50
|
}
|
|
52
51
|
})();
|
|
53
|
-
return
|
|
52
|
+
return {
|
|
53
|
+
kind,
|
|
54
|
+
...value,
|
|
55
|
+
boundingRegions: toBoundingRegions(field.boundingRegions),
|
|
56
|
+
content: field.content,
|
|
57
|
+
spans: field.spans,
|
|
58
|
+
confidence: field.confidence,
|
|
59
|
+
};
|
|
54
60
|
}
|
|
55
61
|
//# sourceMappingURL=fields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/models/fields.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAkOxC;;;;;GAKG;AACH,MAAM,UAAU,qCAAqC,CAAC,MAErD;IACC,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAC,MAAM,CACxC,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;QACnC,iBAAiB,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EACD,EAAoC,CACrC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KA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U,GACZ,CAAC;AACrB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { DocumentSpan } from \"../index.js\";\n\nimport type {\n AddressValue,\n CurrencyValue,\n DocumentField as GeneratedDocumentField,\n} from \"../generated/index.js\";\nimport { toBoundingRegions } from \"../transforms/polygon.js\";\nimport { capitalize } from \"../util.js\";\nimport type { BoundingRegion } from \"./documentElements.js\";\n\n/**\n * Fields that are common to all DocumentField variants.\n */\nexport interface DocumentFieldCommon {\n /**\n * The verbatim extracted text content of the field.\n */\n content?: string;\n\n /**\n * Bounding regions covering the field.\n */\n boundingRegions?: BoundingRegion[];\n\n /**\n * Confidence of correctly extracting the field.\n */\n confidence?: number;\n\n /**\n * Location of the field in the reading order concatenated content.\n */\n spans?: DocumentSpan[];\n}\n\n/**\n * A simple field that has a primitive value, such as a string, number etc.\n */\nexport interface DocumentValueField<T> extends DocumentFieldCommon {\n /**\n * The field's value, which has the type specified in the field's schema.\n */\n value?: T;\n}\n\n/**\n * An extracted field. The `kind` property identifies (discriminates) the type of the `DocumentField`.\n */\nexport type DocumentField =\n | DocumentStringField\n | DocumentDateField\n | DocumentTimeField\n | DocumentPhoneNumberField\n | DocumentNumberField\n | DocumentIntegerField\n | DocumentBooleanField\n | DocumentSelectionMarkField\n | DocumentCountryRegionField\n | DocumentSignatureField\n | DocumentCurrencyField\n | DocumentAddressField\n | DocumentArrayField\n | DocumentObjectField;\n\n/**\n * A DocumentField that has a string value.\n */\nexport interface DocumentStringField<Value extends string = string>\n extends DocumentValueField<Value> {\n /** Field kind: \"string\". */\n kind: \"string\";\n}\n\n/**\n * A DocumentField that has a Date value.\n */\nexport interface DocumentDateField extends DocumentValueField<Date> {\n /** Field kind: \"date\". */\n kind: \"date\";\n}\n\n/**\n * A DocumentField that has a time value, represented as a string.\n */\nexport interface DocumentTimeField extends DocumentFieldCommon {\n /** Field kind: \"time\". */\n kind: \"time\";\n /**\n * The field's value, which is a time in \"HH:MM:SS\" (ISO 8601) format.\n */\n value?: string;\n}\n\n/**\n * A DocumentField that has a phone number value, represented as a string.\n */\nexport interface DocumentPhoneNumberField extends DocumentFieldCommon {\n /** Field kind: \"phoneNumber\". */\n kind: \"phoneNumber\";\n /**\n * The field's value, which is a string containing the phone number.\n *\n * The phone number value is normalized to a standard format. If the value could not be normalized, this value may be\n * undefined, and the `content` property will contain the verbatim text of the DocumentField as it appeared in the\n * input.\n */\n value?: string;\n}\n\n/**\n * A DocumentField that has a number value.\n */\nexport interface DocumentNumberField extends DocumentValueField<number> {\n /** Field kind: \"number\". */\n kind: \"number\";\n}\n\n/**\n * A DocumentField that has an integer value.\n */\nexport interface DocumentIntegerField extends DocumentValueField<number> {\n /** Field kind: \"integer\". */\n kind: \"integer\";\n}\n\n/**\n * A DocumentField that is has a value indicating a selection mark state (such as a checkbox or radio button),\n * represented as a string.\n */\nexport interface DocumentSelectionMarkField extends DocumentFieldCommon {\n /** Field kind: \"selectionMark\". */\n kind: \"selectionMark\";\n /**\n * The state of the selection mark. One of:\n *\n * - \"selected\"\n * - \"unselected\"\n *\n * This value may be undefined, and other variants may be introduced in the future.\n */\n value?: string;\n}\n\n/**\n * A DocumentField that has a value indicating a country or region, represented as a string.\n */\nexport interface DocumentCountryRegionField extends DocumentFieldCommon {\n /** Field kind: \"countryRegion\". */\n kind: \"countryRegion\";\n /**\n * The 3-letter country/region code (ISO 3166-1 alpha-3) of the extracted country or region.\n */\n value?: string;\n}\n\n/**\n * A DocumentField that indicates the state of a signature, represented as a string.\n */\nexport interface DocumentSignatureField extends DocumentFieldCommon {\n /** Field kind: \"signature\". */\n kind: \"signature\";\n /**\n * The state of the signature field. One of:\n *\n * - \"unsigned\"\n * - \"signed\"\n *\n * This value may be undefined, and other variants may be introduced in the future.\n */\n value: \"signed\" | \"unsigned\";\n}\n\n/**\n * A DocumentField that consists of an array of nested fields. All fields in the array will have the same type.\n */\nexport interface DocumentArrayField<T = DocumentField> extends DocumentFieldCommon {\n /** Field kind: \"array\". */\n kind: \"array\";\n\n /**\n * The extracted members of the array field.\n */\n values: T[];\n}\n\n/**\n * A DocumentField that describes an amount of a certain currency.\n */\nexport interface DocumentCurrencyField extends DocumentFieldCommon {\n /** Field kind: \"currency\". */\n kind: \"currency\";\n\n /**\n * The properties of the extracted currency.\n */\n value?: CurrencyValue;\n}\n\n/**\n * A document field that describes a structured physical address.\n */\nexport interface DocumentAddressField extends DocumentFieldCommon {\n /** Field kind: \"address\". */\n kind: \"address\";\n\n /**\n * The properties of the extracted address.\n */\n value?: AddressValue;\n}\n\n/**\n * A DocumentField that has a boolean value.\n */\nexport interface DocumentBooleanField extends DocumentValueField<boolean> {\n /** Field kind: \"boolean\". */\n kind: \"boolean\";\n}\n\n/**\n * A DocumentField that consists of several named properties that have their own DocumentField values.\n */\nexport interface DocumentObjectField<Properties = { [k: string]: DocumentField | undefined }>\n extends DocumentFieldCommon {\n /** Field kind: \"object\". */\n kind: \"object\";\n\n /**\n * The extracted object properties. Each property of this object is, itself, a nested DocumentField.\n */\n properties: Properties;\n}\n\n/**\n * Convert a record of generated fields to a record of strongly-typed fields.\n * @internal\n * @param fields - a map of field names to generated field values\n * @returns - an object with the same keys, where all values have been mapped to DocumentFields\n */\nexport function toAnalyzedDocumentFieldsFromGenerated(fields: {\n [k: string]: GeneratedDocumentField;\n}): { [k: string]: DocumentField } {\n return Object.entries(fields ?? {}).reduce(\n (transformedFields, [name, value]) => {\n transformedFields[name] = toDocumentField(value);\n return transformedFields;\n },\n {} as { [k: string]: DocumentField },\n );\n}\n\n/**\n * Convert a generated document field into a strong TypeScriptified document field.\n * @internal\n */\nexport function toDocumentField(field: GeneratedDocumentField): DocumentField {\n const kind = field.type as DocumentField[\"kind\"];\n\n const value: Omit<DocumentField, keyof DocumentFieldCommon | \"kind\"> = (() => {\n switch (kind) {\n // Almost all value kinds are represented as simple elemental values\n case \"string\":\n case \"date\":\n case \"time\":\n case \"phoneNumber\":\n case \"number\":\n case \"boolean\":\n case \"integer\":\n case \"selectionMark\":\n case \"countryRegion\":\n case \"signature\":\n case \"currency\":\n case \"address\":\n return {\n value:\n field[\n (\"value\" + capitalize(kind)) as Extract<\n keyof GeneratedDocumentField,\n `value${string}`\n >\n ],\n };\n case \"array\":\n return { values: field.valueArray?.map((v) => toDocumentField(v) ?? []) };\n case \"object\":\n return { properties: toAnalyzedDocumentFieldsFromGenerated(field.valueObject ?? {}) };\n default:\n // Exhaustiveness check\n // eslint-disable-next-line no-case-declarations\n const __exhaust: never = kind;\n throw new Error(`Unrecognized DocumentField type: ${__exhaust}`);\n }\n })();\n\n return {\n kind,\n ...value,\n boundingRegions: toBoundingRegions(field.boundingRegions),\n content: field.content,\n spans: field.spans,\n confidence: field.confidence,\n } as DocumentField;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/models/fields.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAkOxC;;;;;GAKG;AACH,MAAM,UAAU,qCAAqC,CAAC,MAErD;IACC,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,MAAM,CACxC,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;QACnC,iBAAiB,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EACD,EAAoC,CACrC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAA6B;IAC3D,MAAM,IAAI,GAAG,KAAK,CAAC,IAA6B,CAAC;IAEjD,MAAM,KAAK,GAA4D,CAAC,GAAG,EAAE;QAC3E,QAAQ,IAAI,EAAE,CAAC;YACb,oEAAoE;YACpE,KAAK,QAAQ,CAAC;YACd,KAAK,MAAM,CAAC;YACZ,KAAK,MAAM,CAAC;YACZ,KAAK,aAAa,CAAC;YACnB,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,SAAS,CAAC;YACf,KAAK,eAAe,CAAC;YACrB,KAAK,eAAe,CAAC;YACrB,KAAK,WAAW,CAAC;YACjB,KAAK,UAAU,CAAC;YAChB,KAAK,SAAS;gBACZ,OAAO;oBACL,KAAK,EACH,KAAK,CACH,CAAC,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAG1B,CACF;iBACJ,CAAC;YACJ,KAAK,OAAO;gBACV,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YAC5E,KAAK,QAAQ;gBACX,OAAO,EAAE,UAAU,EAAE,qCAAqC,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,CAAC;YACxF;gBACE,uBAAuB;gBACvB,gDAAgD;gBAChD,MAAM,SAAS,GAAU,IAAI,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,oCAAoC,SAAS,EAAE,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO;QACL,IAAI;QACJ,GAAG,KAAK;QACR,eAAe,EAAE,iBAAiB,CAAC,KAAK,CAAC,eAAe,CAAC;QACzD,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,UAAU,EAAE,KAAK,CAAC,UAAU;KACZ,CAAC;AACrB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { DocumentSpan } from \"../index.js\";\n\nimport type {\n AddressValue,\n CurrencyValue,\n DocumentField as GeneratedDocumentField,\n} from \"../generated/index.js\";\nimport { toBoundingRegions } from \"../transforms/polygon.js\";\nimport { capitalize } from \"../util.js\";\nimport type { BoundingRegion } from \"./documentElements.js\";\n\n/**\n * Fields that are common to all DocumentField variants.\n */\nexport interface DocumentFieldCommon {\n /**\n * The verbatim extracted text content of the field.\n */\n content?: string;\n\n /**\n * Bounding regions covering the field.\n */\n boundingRegions?: BoundingRegion[];\n\n /**\n * Confidence of correctly extracting the field.\n */\n confidence?: number;\n\n /**\n * Location of the field in the reading order concatenated content.\n */\n spans?: DocumentSpan[];\n}\n\n/**\n * A simple field that has a primitive value, such as a string, number etc.\n */\nexport interface DocumentValueField<T> extends DocumentFieldCommon {\n /**\n * The field's value, which has the type specified in the field's schema.\n */\n value?: T;\n}\n\n/**\n * An extracted field. The `kind` property identifies (discriminates) the type of the `DocumentField`.\n */\nexport type DocumentField =\n | DocumentStringField\n | DocumentDateField\n | DocumentTimeField\n | DocumentPhoneNumberField\n | DocumentNumberField\n | DocumentIntegerField\n | DocumentBooleanField\n | DocumentSelectionMarkField\n | DocumentCountryRegionField\n | DocumentSignatureField\n | DocumentCurrencyField\n | DocumentAddressField\n | DocumentArrayField\n | DocumentObjectField;\n\n/**\n * A DocumentField that has a string value.\n */\nexport interface DocumentStringField<Value extends string = string>\n extends DocumentValueField<Value> {\n /** Field kind: \"string\". */\n kind: \"string\";\n}\n\n/**\n * A DocumentField that has a Date value.\n */\nexport interface DocumentDateField extends DocumentValueField<Date> {\n /** Field kind: \"date\". */\n kind: \"date\";\n}\n\n/**\n * A DocumentField that has a time value, represented as a string.\n */\nexport interface DocumentTimeField extends DocumentFieldCommon {\n /** Field kind: \"time\". */\n kind: \"time\";\n /**\n * The field's value, which is a time in \"HH:MM:SS\" (ISO 8601) format.\n */\n value?: string;\n}\n\n/**\n * A DocumentField that has a phone number value, represented as a string.\n */\nexport interface DocumentPhoneNumberField extends DocumentFieldCommon {\n /** Field kind: \"phoneNumber\". */\n kind: \"phoneNumber\";\n /**\n * The field's value, which is a string containing the phone number.\n *\n * The phone number value is normalized to a standard format. If the value could not be normalized, this value may be\n * undefined, and the `content` property will contain the verbatim text of the DocumentField as it appeared in the\n * input.\n */\n value?: string;\n}\n\n/**\n * A DocumentField that has a number value.\n */\nexport interface DocumentNumberField extends DocumentValueField<number> {\n /** Field kind: \"number\". */\n kind: \"number\";\n}\n\n/**\n * A DocumentField that has an integer value.\n */\nexport interface DocumentIntegerField extends DocumentValueField<number> {\n /** Field kind: \"integer\". */\n kind: \"integer\";\n}\n\n/**\n * A DocumentField that is has a value indicating a selection mark state (such as a checkbox or radio button),\n * represented as a string.\n */\nexport interface DocumentSelectionMarkField extends DocumentFieldCommon {\n /** Field kind: \"selectionMark\". */\n kind: \"selectionMark\";\n /**\n * The state of the selection mark. One of:\n *\n * - \"selected\"\n * - \"unselected\"\n *\n * This value may be undefined, and other variants may be introduced in the future.\n */\n value?: string;\n}\n\n/**\n * A DocumentField that has a value indicating a country or region, represented as a string.\n */\nexport interface DocumentCountryRegionField extends DocumentFieldCommon {\n /** Field kind: \"countryRegion\". */\n kind: \"countryRegion\";\n /**\n * The 3-letter country/region code (ISO 3166-1 alpha-3) of the extracted country or region.\n */\n value?: string;\n}\n\n/**\n * A DocumentField that indicates the state of a signature, represented as a string.\n */\nexport interface DocumentSignatureField extends DocumentFieldCommon {\n /** Field kind: \"signature\". */\n kind: \"signature\";\n /**\n * The state of the signature field. One of:\n *\n * - \"unsigned\"\n * - \"signed\"\n *\n * This value may be undefined, and other variants may be introduced in the future.\n */\n value: \"signed\" | \"unsigned\";\n}\n\n/**\n * A DocumentField that consists of an array of nested fields. All fields in the array will have the same type.\n */\nexport interface DocumentArrayField<T = DocumentField> extends DocumentFieldCommon {\n /** Field kind: \"array\". */\n kind: \"array\";\n\n /**\n * The extracted members of the array field.\n */\n values: T[];\n}\n\n/**\n * A DocumentField that describes an amount of a certain currency.\n */\nexport interface DocumentCurrencyField extends DocumentFieldCommon {\n /** Field kind: \"currency\". */\n kind: \"currency\";\n\n /**\n * The properties of the extracted currency.\n */\n value?: CurrencyValue;\n}\n\n/**\n * A document field that describes a structured physical address.\n */\nexport interface DocumentAddressField extends DocumentFieldCommon {\n /** Field kind: \"address\". */\n kind: \"address\";\n\n /**\n * The properties of the extracted address.\n */\n value?: AddressValue;\n}\n\n/**\n * A DocumentField that has a boolean value.\n */\nexport interface DocumentBooleanField extends DocumentValueField<boolean> {\n /** Field kind: \"boolean\". */\n kind: \"boolean\";\n}\n\n/**\n * A DocumentField that consists of several named properties that have their own DocumentField values.\n */\nexport interface DocumentObjectField<Properties = { [k: string]: DocumentField | undefined }>\n extends DocumentFieldCommon {\n /** Field kind: \"object\". */\n kind: \"object\";\n\n /**\n * The extracted object properties. Each property of this object is, itself, a nested DocumentField.\n */\n properties: Properties;\n}\n\n/**\n * Convert a record of generated fields to a record of strongly-typed fields.\n * @internal\n * @param fields - a map of field names to generated field values\n * @returns - an object with the same keys, where all values have been mapped to DocumentFields\n */\nexport function toAnalyzedDocumentFieldsFromGenerated(fields: {\n [k: string]: GeneratedDocumentField;\n}): { [k: string]: DocumentField } {\n return Object.entries(fields ?? {}).reduce(\n (transformedFields, [name, value]) => {\n transformedFields[name] = toDocumentField(value);\n return transformedFields;\n },\n {} as { [k: string]: DocumentField },\n );\n}\n\n/**\n * Convert a generated document field into a strong TypeScriptified document field.\n * @internal\n */\nexport function toDocumentField(field: GeneratedDocumentField): DocumentField {\n const kind = field.type as DocumentField[\"kind\"];\n\n const value: Omit<DocumentField, keyof DocumentFieldCommon | \"kind\"> = (() => {\n switch (kind) {\n // Almost all value kinds are represented as simple elemental values\n case \"string\":\n case \"date\":\n case \"time\":\n case \"phoneNumber\":\n case \"number\":\n case \"boolean\":\n case \"integer\":\n case \"selectionMark\":\n case \"countryRegion\":\n case \"signature\":\n case \"currency\":\n case \"address\":\n return {\n value:\n field[\n (\"value\" + capitalize(kind)) as Extract<\n keyof GeneratedDocumentField,\n `value${string}`\n >\n ],\n };\n case \"array\":\n return { values: field.valueArray?.map((v) => toDocumentField(v) ?? []) };\n case \"object\":\n return { properties: toAnalyzedDocumentFieldsFromGenerated(field.valueObject ?? {}) };\n default:\n // Exhaustiveness check\n // eslint-disable-next-line no-case-declarations\n const __exhaust: never = kind;\n throw new Error(`Unrecognized DocumentField type: ${__exhaust}`);\n }\n })();\n\n return {\n kind,\n ...value,\n boundingRegions: toBoundingRegions(field.boundingRegions),\n content: field.content,\n spans: field.spans,\n confidence: field.confidence,\n } as DocumentField;\n}\n"]}
|
|
@@ -13,14 +13,25 @@ export function toBoundingPolygon(original) {
|
|
|
13
13
|
return points;
|
|
14
14
|
}
|
|
15
15
|
export function toBoundingRegions(original) {
|
|
16
|
-
return original
|
|
16
|
+
return original?.map((region) => ({ ...region, polygon: toBoundingPolygon(region.polygon) }));
|
|
17
17
|
}
|
|
18
18
|
export function toDocumentTableFromGenerated(table) {
|
|
19
|
-
return
|
|
19
|
+
return {
|
|
20
|
+
...table,
|
|
21
|
+
boundingRegions: toBoundingRegions(table.boundingRegions),
|
|
22
|
+
cells: table.cells.map((cell) => ({
|
|
23
|
+
...cell,
|
|
24
|
+
boundingRegions: toBoundingRegions(cell.boundingRegions),
|
|
25
|
+
})),
|
|
26
|
+
};
|
|
20
27
|
}
|
|
21
28
|
export function toKeyValuePairFromGenerated(pair) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
return {
|
|
30
|
+
...pair,
|
|
31
|
+
key: { ...pair.key, boundingRegions: toBoundingRegions(pair.key.boundingRegions) },
|
|
32
|
+
value: pair.value
|
|
33
|
+
? { ...pair.value, boundingRegions: toBoundingRegions(pair.value?.boundingRegions) }
|
|
34
|
+
: undefined,
|
|
35
|
+
};
|
|
25
36
|
}
|
|
26
37
|
//# sourceMappingURL=polygon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polygon.js","sourceRoot":"","sources":["../../../src/transforms/polygon.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AA2BlC,MAAM,UAAU,iBAAiB,CAAC,QAA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AAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,QAA+C;IAE/C,OAAO,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;AAChG,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,KAA6B;IACxE,OAAO;QACL,GAAG,KAAK;QACR,eAAe,EAAE,iBAAiB,CAAC,KAAK,CAAC,eAAe,CAAC;QACzD,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAChC,GAAG,IAAI;YACP,eAAe,EAAE,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC;SACzD,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,IAAmC;IAEnC,OAAO;QACL,GAAG,IAAI;QACP,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,eAAe,EAAE,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE;QAClF,KAAK,EAAE,IAAI,CAAC,KAAK;YACf,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE,iBAAiB,CAAC,IAAI,CAAC,KAAK,EAAE,eAAe,CAAC,EAAE;YACpF,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n BoundingRegion as GeneratedBoundingRegion,\n DocumentKeyValuePair as GeneratedDocumentKeyValuePair,\n DocumentTable as GeneratedDocumentTable,\n} from \"../generated/index.js\";\nimport type {\n BoundingRegion,\n DocumentKeyValuePair,\n DocumentTable,\n} from \"../models/documentElements.js\";\n\n/**\n * Represents a point used to define bounding polygons. The unit is either 'pixel' or 'inch' (See {@link LengthUnit}).\n */\nexport interface Point2D {\n /**\n * x coordinate - relative from the left side of the page\n */\n x: number;\n /**\n * y coordinate - relative from the top of the page\n */\n y: number;\n}\n\nexport function toBoundingPolygon(original: number[] | undefined): Point2D[] | undefined {\n const points: Point2D[] = [];\n if (!original) return;\n\n if (original.length % 2 !== 0) {\n throw new Error(\n \"Unexpected number of points in the response, unable to translate as 2D points\",\n );\n }\n\n for (let i = 0; i < original.length; i += 2) {\n points.push({ x: original[i], y: original[i + 1] });\n }\n\n return points;\n}\n\nexport function toBoundingRegions(\n original: GeneratedBoundingRegion[] | undefined,\n): BoundingRegion[] | undefined {\n return original?.map((region) => ({ ...region, polygon: toBoundingPolygon(region.polygon) }));\n}\n\nexport function toDocumentTableFromGenerated(table: GeneratedDocumentTable): DocumentTable {\n return {\n ...table,\n boundingRegions: toBoundingRegions(table.boundingRegions),\n cells: table.cells.map((cell) => ({\n ...cell,\n boundingRegions: toBoundingRegions(cell.boundingRegions),\n })),\n };\n}\n\nexport function toKeyValuePairFromGenerated(\n pair: GeneratedDocumentKeyValuePair,\n): DocumentKeyValuePair {\n return {\n ...pair,\n key: { ...pair.key, boundingRegions: toBoundingRegions(pair.key.boundingRegions) },\n value: pair.value\n ? { ...pair.value, boundingRegions: toBoundingRegions(pair.value?.boundingRegions) }\n : undefined,\n };\n}\n"]}
|
package/dist/esm/util.js
CHANGED
|
@@ -38,12 +38,15 @@ export const maybemap = (value, f) => value === undefined ? undefined : f(value)
|
|
|
38
38
|
* @internal
|
|
39
39
|
*/
|
|
40
40
|
export function makeServiceClient(endpoint, credential, options) {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const client = new GeneratedClient(endpoint?.replace(/\/$/, ""), {
|
|
42
|
+
...DEFAULT_GENERATED_CLIENT_OPTIONS,
|
|
43
|
+
...options,
|
|
44
|
+
apiVersion: FORM_RECOGNIZER_API_VERSION,
|
|
45
|
+
});
|
|
43
46
|
const authPolicy = isTokenCredential(credential)
|
|
44
47
|
? bearerTokenAuthenticationPolicy({
|
|
45
48
|
credential,
|
|
46
|
-
scopes: [
|
|
49
|
+
scopes: [options.audience ?? DEFAULT_COGNITIVE_SCOPE].map((scope) => {
|
|
47
50
|
if (scope.endsWith("/.default"))
|
|
48
51
|
return scope;
|
|
49
52
|
return `${scope}/.default`;
|
package/dist/esm/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,4CAA4C,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,gCAAgC,GAEjC,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,2CAA2C;AAC3C,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAA4B,CAAS,EAAmB,EAAE,CACpF,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAoB,CAAC;AAExE;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAA4B,CAAI,EAAiB,EAAE,CAC3E,CAAC,CAAC,CAAC,SAAS,CAA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AAO,KAAK,CAAC;gBAC9C,OAAO,GAAG,KAAK,WAAW,CAAC;YAC7B,CAAC,CAAC;SACH,CAAC;QACJ,CAAC,CAAC,4CAA4C,CAAC,UAAU,CAAC,CAAC;IAE7D,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAEtC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isTokenCredential } from \"@azure/core-auth\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\nimport { createFormRecognizerAzureKeyCredentialPolicy } from \"./azureKeyCredentialPolicy.js\";\nimport { DEFAULT_COGNITIVE_SCOPE, FORM_RECOGNIZER_API_VERSION } from \"./constants.js\";\nimport type { GeneratedClientOptionalParams } from \"./generated/index.js\";\nimport { GeneratedClient } from \"./generated/index.js\";\nimport {\n DEFAULT_GENERATED_CLIENT_OPTIONS,\n type DocumentAnalysisClientOptions,\n} from \"./options/FormRecognizerClientOptions.js\";\n\nimport * as Mappers from \"./generated/models/mappers.js\";\nimport { createSerializer } from \"@azure/core-client\";\nexport { Mappers };\n\n// This is used for URL request processing.\nexport const SERIALIZER = createSerializer(Mappers, false);\n\n/**\n * Type-strong uncapitalization.\n * @internal\n */\nexport const uncapitalize = <S extends string = string>(s: string): Uncapitalize<S> =>\n (s.substring(0, 1).toLowerCase() + s.substring(1)) as Uncapitalize<S>;\n\n/**\n * Type-strong capitalization\n * @internal\n */\nexport const capitalize = <S extends string = string>(s: S): Capitalize<S> =>\n (s.substring(0, 1).toUpperCase() + s.substring(1)) as Capitalize<S>;\n\n/**\n * Tests if a string looks like it begins with an acronym, i.e. it starts with two capital letters.\n * @internal\n */\nexport const isAcronymic = (s: string): boolean => {\n return /^[A-Z][A-Z]/.test(s);\n};\n\n/**\n * Map an optional value through a function\n * @internal\n */\nexport const maybemap = <T1, T2>(value: T1 | undefined, f: (v: T1) => T2): T2 | undefined =>\n value === undefined ? undefined : f(value);\n\n/**\n * Create a GeneratedClient.\n * @internal\n */\nexport function makeServiceClient(\n endpoint: string,\n credential: KeyCredential | TokenCredential,\n options: GeneratedClientOptionalParams & Pick<DocumentAnalysisClientOptions, \"audience\">,\n): GeneratedClient {\n const client = new GeneratedClient(endpoint?.replace(/\\/$/, \"\"), {\n ...DEFAULT_GENERATED_CLIENT_OPTIONS,\n ...options,\n apiVersion: FORM_RECOGNIZER_API_VERSION,\n });\n\n const authPolicy = isTokenCredential(credential)\n ? bearerTokenAuthenticationPolicy({\n credential,\n scopes: [options.audience ?? DEFAULT_COGNITIVE_SCOPE].map((scope) => {\n if (scope.endsWith(\"/.default\")) return scope;\n return `${scope}/.default`;\n }),\n })\n : createFormRecognizerAzureKeyCredentialPolicy(credential);\n\n client.pipeline.addPolicy(authPolicy);\n\n return client;\n}\n"]}
|
|
@@ -66,18 +66,19 @@ const documentFeatures = [...layoutFeatures, "keyValuePairs"];
|
|
|
66
66
|
* @returns the list of features supported by the model
|
|
67
67
|
*/
|
|
68
68
|
export function getFeatures(model) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
return (model.features ??
|
|
70
|
+
{
|
|
71
|
+
"prebuilt-read": [...textFeatures, "languages"],
|
|
72
|
+
"prebuilt-layout": layoutFeatures,
|
|
73
|
+
"prebuilt-document": [...documentFeatures, "unconstrainedDocuments"],
|
|
74
|
+
"prebuilt-receipt": [...textFeatures, "keyValuePairs", "_documents"],
|
|
75
|
+
"prebuilt-invoice": [...layoutFeatures, "keyValuePairs", "_documents"],
|
|
76
|
+
"prebuilt-idDocument": [...textFeatures, "keyValuePairs", "_documents"],
|
|
77
|
+
"prebuilt-businessCard": [...textFeatures, "keyValuePairs", "_documents"],
|
|
78
|
+
"prebuilt-tax.us.w2": [...textFeatures, "keyValuePairs", "_documents"],
|
|
79
|
+
"prebuilt-vaccinationCard": [...textFeatures, "keyValuePairs", "_documents"],
|
|
80
|
+
"prebuilt-healthInsuranceCard.us": [...textFeatures, "keyValuePairs", "_documents"],
|
|
81
|
+
}[model.modelId] ??
|
|
82
|
+
(model.modelId.startsWith("prebuilt-") ? allFeatures : [...documentFeatures, "_documents"]));
|
|
82
83
|
}
|
|
83
84
|
//# sourceMappingURL=defaultFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultFields.js","sourceRoot":"","sources":["../../../src/bin/defaultFields.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAKlC;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA0B;IACxD,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,kBAAkB;QAC/B,IAAI,EAAE,mBAAmB;QACzB,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,mBAAmB;QAChC,IAAI,EAAE,oBAAoB;QAC1B,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,4BAA4B;QACzC,IAAI,EAAE,2BAA2B;QACjC,QAAQ,EAAE,IAAI;KACf;IACD,SAAS,EAAE;QACT,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,2BAA2B;QACxC,IAAI,EAAE,uBAAuB;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,wBAAwB;QACrC,IAAI,EAAE,oBAAoB;QAC1B,QAAQ,EAAE,IAAI;KACf;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,sDAAsD;QACnE,IAAI,EA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CAAC,GAAG,YAAY,EAAE,eAAe,EAAE,YAAY,CAAC;YACtE,0BAA0B,EAAE,CAAC,GAAG,YAAY,EAAE,eAAe,EAAE,YAAY,CAAC;YAC5E,iCAAiC,EAAE,CAAC,GAAG,YAAY,EAAE,eAAe,EAAE,YAAY,CAAC;SACpF,CAAC,KAAK,CAAC,OAAO,CAAC;QAChB,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAC5F,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { DocumentModelDetails } from \"../index.js\";\nimport type { Field } from \"./utils.js\";\n\n/**\n * @internal\n * Field information for the top level fields of `AnalyzeResult`.\n */\nexport const defaultResultFields: Record<string, Field> = {\n pages: {\n name: \"pages\",\n docContents: \"Extracted pages.\",\n type: \"fr.DocumentPage[]\",\n optional: true,\n },\n tables: {\n name: \"tables\",\n docContents: \"Extracted tables.\",\n type: \"fr.DocumentTable[]\",\n optional: true,\n },\n keyValuePairs: {\n name: \"keyValuePairs\",\n docContents: \"Extracted key-value pairs.\",\n type: \"fr.DocumentKeyValuePair[]\",\n optional: true,\n },\n languages: {\n name: \"languages\",\n docContents: \"Extracted text languages.\",\n type: \"fr.DocumentLanguage[]\",\n optional: true,\n },\n styles: {\n name: \"styles\",\n docContents: \"Extracted font styles.\",\n type: \"fr.DocumentStyle[]\",\n optional: true,\n },\n unconstrainedDocuments: {\n name: \"documents\",\n docContents: \"Extracted documents containing any extracted fields.\",\n type: \"fr.AnalyzedDocument[]\",\n optional: true,\n },\n paragraphs: {\n name: \"paragraphs\",\n docContents: \"Extracted document paragraphs.\",\n type: \"fr.DocumentParagraph[]\",\n optional: true,\n },\n} as const;\n\nconst allFeatures = [\n \"pages\",\n \"tables\",\n \"keyValuePairs\",\n \"languages\",\n \"styles\",\n \"paragraphs\",\n \"_documents\",\n];\n\nconst textFeatures = [\"pages\", \"paragraphs\", \"styles\"];\nconst layoutFeatures = [...textFeatures, \"tables\"];\nconst documentFeatures = [...layoutFeatures, \"keyValuePairs\"];\n\n/**\n * @internal\n * @param model - the model to get the features of\n * @returns the list of features supported by the model\n */\nexport function getFeatures(model: DocumentModelDetails): string[] {\n return (\n (model as any).features ??\n {\n \"prebuilt-read\": [...textFeatures, \"languages\"],\n \"prebuilt-layout\": layoutFeatures,\n \"prebuilt-document\": [...documentFeatures, \"unconstrainedDocuments\"],\n \"prebuilt-receipt\": [...textFeatures, \"keyValuePairs\", \"_documents\"],\n \"prebuilt-invoice\": [...layoutFeatures, \"keyValuePairs\", \"_documents\"],\n \"prebuilt-idDocument\": [...textFeatures, \"keyValuePairs\", \"_documents\"],\n \"prebuilt-businessCard\": [...textFeatures, \"keyValuePairs\", \"_documents\"],\n \"prebuilt-tax.us.w2\": [...textFeatures, \"keyValuePairs\", \"_documents\"],\n \"prebuilt-vaccinationCard\": [...textFeatures, \"keyValuePairs\", \"_documents\"],\n \"prebuilt-healthInsuranceCard.us\": [...textFeatures, \"keyValuePairs\", \"_documents\"],\n }[model.modelId] ??\n (model.modelId.startsWith(\"prebuilt-\") ? allFeatures : [...documentFeatures, \"_documents\"])\n );\n}\n"]}
|
|
@@ -116,12 +116,16 @@ export async function writeModelCode(model, test) {
|
|
|
116
116
|
}
|
|
117
117
|
// Get the doc type variants of a model.
|
|
118
118
|
function extractModelVariants(model, _rootSlug) {
|
|
119
|
-
var _a;
|
|
120
119
|
const result = {};
|
|
121
|
-
for (const [docType, info] of Object.entries(
|
|
120
|
+
for (const [docType, info] of Object.entries(model.docTypes ?? {})) {
|
|
122
121
|
const slug = docType.split(".");
|
|
123
122
|
const docTypeName = camelCase(slug);
|
|
124
|
-
result[docTypeName] =
|
|
123
|
+
result[docTypeName] = {
|
|
124
|
+
...info,
|
|
125
|
+
name: docTypeName,
|
|
126
|
+
originalDocType: docType,
|
|
127
|
+
slug,
|
|
128
|
+
};
|
|
125
129
|
}
|
|
126
130
|
return result;
|
|
127
131
|
}
|
|
@@ -183,22 +187,21 @@ function* writeFieldsInterfaces(docType) {
|
|
|
183
187
|
yield* writeInterfaceDeclaration(name, docType.description, docType.fieldSchema);
|
|
184
188
|
// Recursively visit all child interfaces and write them.
|
|
185
189
|
yield* (function* collectNestedInterfaces(fields, namingContext) {
|
|
186
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
187
190
|
for (const [fieldName, schema] of Object.entries(fields)) {
|
|
188
|
-
if (schema.type === "array" &&
|
|
191
|
+
if (schema.type === "array" && schema.items?.type === "object") {
|
|
189
192
|
// Generate element interface and recur if the nested type is an object
|
|
190
193
|
const nextNamingContext = namingContext + fieldName + "Element";
|
|
191
194
|
yield "";
|
|
192
195
|
yield "";
|
|
193
|
-
yield* writeInterfaceDeclaration(nextNamingContext, schema.description,
|
|
194
|
-
yield* collectNestedInterfaces(
|
|
196
|
+
yield* writeInterfaceDeclaration(nextNamingContext, schema.description, schema.items?.properties ?? {});
|
|
197
|
+
yield* collectNestedInterfaces(schema.items?.properties ?? {}, nextNamingContext);
|
|
195
198
|
}
|
|
196
199
|
else if (schema.type === "object") {
|
|
197
200
|
// Generate named interface and recur
|
|
198
201
|
yield "";
|
|
199
202
|
yield "";
|
|
200
|
-
yield* writeInterfaceDeclaration(namingContext + fieldName, schema.description,
|
|
201
|
-
yield* collectNestedInterfaces(
|
|
203
|
+
yield* writeInterfaceDeclaration(namingContext + fieldName, schema.description, schema.properties ?? {});
|
|
204
|
+
yield* collectNestedInterfaces(schema.properties ?? {}, namingContext + fieldName);
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
207
|
})(docType.fieldSchema, docType.name);
|
|
@@ -225,16 +228,13 @@ function* writeFieldsInterfaces(docType) {
|
|
|
225
228
|
}
|
|
226
229
|
else {
|
|
227
230
|
yield prefix;
|
|
228
|
-
yield* indent(flatMap(fieldEntries.map(([fieldName, schema]) => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
optional: true,
|
|
236
|
-
});
|
|
237
|
-
}), writeField));
|
|
231
|
+
yield* indent(flatMap(fieldEntries.map(([fieldName, schema]) => ({
|
|
232
|
+
// Uncapitalize the field name and remove all whitespace
|
|
233
|
+
name: uncapitalize(fieldName).replace(/\s/g, ""),
|
|
234
|
+
type: writeType(schema, fieldName, docType.slug),
|
|
235
|
+
docContents: schema.description ?? `\`${docType.name}\` "${fieldName}" field`,
|
|
236
|
+
optional: true,
|
|
237
|
+
})), writeField));
|
|
238
238
|
yield suffix;
|
|
239
239
|
}
|
|
240
240
|
}
|