From 2abf1d56f69c8dae9251bbcc61212a670306d3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Thu, 29 Jan 2026 12:28:35 +0100 Subject: [PATCH 1/9] :recycle: rename client methods --- src/v2/cli.ts | 2 +- src/v2/client.ts | 20 ++++++++++---------- tests/data | 2 +- tests/v2/client.integration.ts | 14 +++++++------- tests/v2/client.spec.ts | 8 ++++---- tests/v2/client/inferenceParameter.spec.ts | 4 +++- tests/v2/parsing/localResponse.spec.ts | 2 +- 7 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/v2/cli.ts b/src/v2/cli.ts index af9c5b8e..1fc52b44 100644 --- a/src/v2/cli.ts +++ b/src/v2/cli.ts @@ -33,7 +33,7 @@ async function enqueueAndGetInference( ): Promise { const mindeeClient = initClient(options); const inputSource = new PathInput({ inputPath: inputPath }); - const response = await mindeeClient.enqueueAndGetInference( + const response = await mindeeClient.enqueueAndGetResult( responseType, inputSource, { diff --git a/src/v2/client.ts b/src/v2/client.ts index aebad4e6..0da31477 100644 --- a/src/v2/client.ts +++ b/src/v2/client.ts @@ -94,7 +94,7 @@ export class Client { } } - async enqueueInference( + async enqueue( responseType: InferenceResponseConstructor, inputSource: InputSource, params: InferenceParameters, @@ -120,7 +120,7 @@ export class Client { } /** - * Retrieves an inference. + * Retrieves the result of a previously enqueued request. * * @param responseType class of the inference to retrieve. * @param inferenceId id of the queue to poll. @@ -128,7 +128,7 @@ export class Client { * @category Asynchronous * @returns a `Promise` containing the inference. */ - async getInference( + async getResult( responseType: InferenceResponseConstructor, inferenceId: string ): Promise> { @@ -139,7 +139,7 @@ export class Client { } /** - * Get the status of an inference that was previously enqueued. + * Get the processing status of a previously enqueued request. * Can be used for polling. * * @param jobId id of the queue to poll. @@ -153,7 +153,7 @@ export class Client { } /** - * Send a document to an endpoint and poll the server until the result is sent or + * Enqueue a request and poll the server until the result is sent or * until the maximum number of tries is reached. * * @param responseType class of the inference to retrieve. @@ -164,7 +164,7 @@ export class Client { * @category Synchronous * @returns a `Promise` containing parsing results. */ - async enqueueAndGetInference( + async enqueueAndGetResult( responseType: InferenceResponseConstructor, inputSource: InputSource, params: InferenceParameters @@ -175,10 +175,10 @@ export class Client { const pollingOptions = paramsInstance.getValidatedPollingOptions(); - const jobResponse: JobResponse = await this.enqueueInference( + const jobResponse: JobResponse = await this.enqueue( responseType, inputSource, paramsInstance ); - return await this.pollForInference( + return await this.pollForResult( responseType, pollingOptions, jobResponse.job.id ); } @@ -188,7 +188,7 @@ export class Client { * until the maximum number of tries is reached. * @protected */ - protected async pollForInference( + protected async pollForResult( responseType: InferenceResponseConstructor, pollingOptions: ValidatedPollingOptions, queueId: string, @@ -220,7 +220,7 @@ export class Client { break; } if (pollResults.job.status === "Processed") { - return this.getInference(responseType, pollResults.job.id); + return this.getResult(responseType, pollResults.job.id); } await setTimeout( pollingOptions.delaySec * 1000, diff --git a/tests/data b/tests/data index 7bed8f9b..7d470a0c 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 7bed8f9b059f6ba3debc31e71375ea8437b6fbe2 +Subproject commit 7d470a0c49c1b7cc7b635ae63d3ffea81ef6f323 diff --git a/tests/v2/client.integration.ts b/tests/v2/client.integration.ts index 4cde80e8..07750e0b 100644 --- a/tests/v2/client.integration.ts +++ b/tests/v2/client.integration.ts @@ -80,7 +80,7 @@ describe("MindeeV2 – Client Integration Tests", () => { webhookIds: [], alias: "ts_integration_empty_multiple" }; - const response = await client.enqueueAndGetInference( + const response = await client.enqueueAndGetResult( ExtractionInference, source, params ); expect(response).to.exist; @@ -109,7 +109,7 @@ describe("MindeeV2 – Client Integration Tests", () => { alias: "ts_integration_binary_filled_single" }; - const response = await client.enqueueAndGetInference( + const response = await client.enqueueAndGetResult( ExtractionInference, source, params ); expect(response.inference).to.be.instanceOf(ExtractionInference); @@ -148,7 +148,7 @@ describe("MindeeV2 – Client Integration Tests", () => { alias: "ts_integration_base64_filled_single" }); - const response = await client.enqueueAndGetInference( + const response = await client.enqueueAndGetResult( ExtractionInference, source, params ); expect(response.inference).to.be.instanceOf(ExtractionInference); @@ -171,7 +171,7 @@ describe("MindeeV2 – Client Integration Tests", () => { const badParams = { modelId: "00000000-0000-0000-0000-000000000000" }; try { - await client.enqueueInference(ExtractionInference, source, badParams); + await client.enqueue(ExtractionInference, source, badParams); expect.fail("Expected the call to throw, but it succeeded."); } catch (err) { check422(err); @@ -180,7 +180,7 @@ describe("MindeeV2 – Client Integration Tests", () => { it("Invalid job ID – getInference must raise 422", async () => { try { - await client.getInference( + await client.getResult( ExtractionInference, "00000000-0000-0000-0000-000000000000" ); @@ -202,7 +202,7 @@ describe("MindeeV2 – Client Integration Tests", () => { webhookIds: [], alias: "ts_integration_url_source" }); - const response: ExtractionResponse = await client.enqueueAndGetInference( + const response: ExtractionResponse = await client.enqueueAndGetResult( ExtractionInference, source, params ); expect(response).to.exist; @@ -221,7 +221,7 @@ describe("MindeeV2 – Client Integration Tests", () => { dataSchema: dataSchemaReplace, alias: "ts_integration_data_schema_replace" }); - const response = await client.enqueueAndGetInference( + const response = await client.enqueueAndGetResult( ExtractionInference, source, params ); expect(response).to.exist; diff --git a/tests/v2/client.spec.ts b/tests/v2/client.spec.ts index 6eeab60e..0512077b 100644 --- a/tests/v2/client.spec.ts +++ b/tests/v2/client.spec.ts @@ -74,7 +74,7 @@ describe("MindeeV2 - ClientV2", () => { const inputDoc = new PathInput({ inputPath: filePath }); await assert.rejects( - client.enqueueInference(ExtractionInference, inputDoc, { modelId: "dummy-model", textContext: "hello" }), + client.enqueue(ExtractionInference, inputDoc, { modelId: "dummy-model", textContext: "hello" }), (error: any) => { assert.strictEqual(error instanceof MindeeHttpErrorV2, true); assert.strictEqual(error.status, 400); @@ -88,7 +88,7 @@ describe("MindeeV2 - ClientV2", () => { const inputDoc = new PathInput({ inputPath: filePath }); await assert.rejects( - client.enqueueInference(CropInference, inputDoc, { modelId: "dummy-model" }), + client.enqueue(CropInference, inputDoc, { modelId: "dummy-model" }), (error: any) => { assert.strictEqual(error instanceof MindeeHttpErrorV2, true); assert.strictEqual(error.status, 400); @@ -101,7 +101,7 @@ describe("MindeeV2 - ClientV2", () => { const filePath = path.join(fileTypesDir, "receipt.jpg"); const inputDoc = new PathInput({ inputPath: filePath }); await assert.rejects( - client.enqueueAndGetInference( + client.enqueueAndGetResult( ExtractionInference, inputDoc, { modelId: "dummy-model", rag: false } @@ -124,7 +124,7 @@ describe("MindeeV2 - ClientV2", () => { ), }); await assert.rejects( - client.enqueueInference(ExtractionInference, input, { modelId: "dummy-model" }), + client.enqueue(ExtractionInference, input, { modelId: "dummy-model" }), (error: any) => { expect(error).to.be.instanceOf(MindeeHttpErrorV2); expect(error.status).to.equal(400); diff --git a/tests/v2/client/inferenceParameter.spec.ts b/tests/v2/client/inferenceParameter.spec.ts index 8d3e6b4c..fa3a6a3a 100644 --- a/tests/v2/client/inferenceParameter.spec.ts +++ b/tests/v2/client/inferenceParameter.spec.ts @@ -30,7 +30,9 @@ describe("MindeeV2 - Inference Parameter", () => { describe("Data Schema", () => { before(async () => { - const fileContents = await fs.readFile(path.join(V2_RESOURCE_PATH, "inference/data_schema_replace_param.json")); + const fileContents = await fs.readFile( + path.join(V2_RESOURCE_PATH, "inference/data_schema_replace_param.json") + ); expectedDataSchemaDict = JSON.parse(fileContents.toString()); expectedDataSchemaString = JSON.stringify(expectedDataSchemaDict); expectedDataSchemaObject = new DataSchema(expectedDataSchemaDict); diff --git a/tests/v2/parsing/localResponse.spec.ts b/tests/v2/parsing/localResponse.spec.ts index a91f6089..f60ce32a 100644 --- a/tests/v2/parsing/localResponse.spec.ts +++ b/tests/v2/parsing/localResponse.spec.ts @@ -6,7 +6,7 @@ import path from "path"; import { V2_RESOURCE_PATH } from "../../index.js"; import { Buffer } from "node:buffer"; -const signature: string = "1df388c992d87897fe61dfc56c444c58fc3c7369c31e2b5fd20d867695e93e85"; +const signature: string = "f390d9f7f57ac04f47b6309d8a40236b0182610804fc20e91b1f6028aaca07a7"; const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; const filePath: string = path.join(V2_RESOURCE_PATH, "inference/standard_field_types.json"); From 8d75fdd63fb7890d95fe187bcb7eb6fd79bd8189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Thu, 29 Jan 2026 15:54:31 +0100 Subject: [PATCH 2/9] reorganize parsing --- src/input/localInputSource.ts | 2 +- src/input/urlInput.ts | 1 + src/v2/cli.ts | 2 +- src/v2/client.ts | 35 ++++++++++++------- src/v2/client/baseParameters.ts | 1 + src/v2/client/cropParameters.ts | 27 ++++++++++++++ src/v2/client/extractionParameters.ts | 2 ++ src/v2/client/index.ts | 5 ++- ...{utilityParameters.ts => ocrParameters.ts} | 4 ++- src/v2/client/splitParameters.ts | 27 ++++++++++++++ src/v2/http/mindeeApiV2.ts | 8 ++--- src/v2/parsing/index.ts | 6 ++-- .../{inference => result}/baseInference.ts | 2 +- .../baseInferenceResponse.ts | 0 .../classification/classificationInference.ts | 2 +- .../classification/classificationResponse.ts | 2 +- .../crop/cropInference.ts | 4 +-- .../{inference => result}/crop/cropItem.ts | 4 +-- .../crop/cropResponse.ts | 2 +- .../{inference => result}/crop/cropResult.ts | 5 +-- .../extraction/dataSchemaActiveOption.ts | 0 .../extraction/extractionActiveOptions.ts | 0 .../extraction/extractionInference.ts | 2 +- .../extraction/extractionResponse.ts | 2 +- .../extraction/extractionResult.ts | 2 +- .../{inference => result}/field/baseField.ts | 0 .../field/fieldConfidence.ts | 0 .../field/fieldFactory.ts | 0 .../field/fieldLocation.ts | 0 .../{inference => result}/field/index.ts | 0 .../field/inferenceFields.ts | 0 .../{inference => result}/field/listField.ts | 0 .../field/objectField.ts | 0 .../field/ragMetadata.ts | 0 .../{inference => result}/field/rawText.ts | 0 .../field/rawTextPage.ts | 0 .../field/simpleField.ts | 0 src/v2/parsing/{inference => result}/index.ts | 0 .../{inference => result}/inferenceFile.ts | 0 .../{inference => result}/inferenceModel.ts | 0 .../{inference => result}/ocr/ocrInference.ts | 2 +- .../{inference => result}/ocr/ocrResponse.ts | 2 +- .../split/splitInference.ts | 2 +- .../split/splitResponse.ts | 2 +- tests/v2/client.integration.ts | 2 +- tests/v2/client.spec.ts | 6 ++-- tests/v2/parsing/inference.spec.ts | 2 +- 47 files changed, 120 insertions(+), 45 deletions(-) create mode 100644 src/v2/client/cropParameters.ts rename src/v2/client/{utilityParameters.ts => ocrParameters.ts} (80%) create mode 100644 src/v2/client/splitParameters.ts rename src/v2/parsing/{inference => result}/baseInference.ts (88%) rename src/v2/parsing/{inference => result}/baseInferenceResponse.ts (100%) rename src/v2/parsing/{inference => result}/classification/classificationInference.ts (87%) rename src/v2/parsing/{inference => result}/classification/classificationResponse.ts (83%) rename src/v2/parsing/{inference => result}/crop/cropInference.ts (78%) rename src/v2/parsing/{inference => result}/crop/cropItem.ts (72%) rename src/v2/parsing/{inference => result}/crop/cropResponse.ts (77%) rename src/v2/parsing/{inference => result}/crop/cropResult.ts (66%) rename src/v2/parsing/{inference => result}/extraction/dataSchemaActiveOption.ts (100%) rename src/v2/parsing/{inference => result}/extraction/extractionActiveOptions.ts (100%) rename src/v2/parsing/{inference => result}/extraction/extractionInference.ts (92%) rename src/v2/parsing/{inference => result}/extraction/extractionResponse.ts (79%) rename src/v2/parsing/{inference => result}/extraction/extractionResult.ts (91%) rename src/v2/parsing/{inference => result}/field/baseField.ts (100%) rename src/v2/parsing/{inference => result}/field/fieldConfidence.ts (100%) rename src/v2/parsing/{inference => result}/field/fieldFactory.ts (100%) rename src/v2/parsing/{inference => result}/field/fieldLocation.ts (100%) rename src/v2/parsing/{inference => result}/field/index.ts (100%) rename src/v2/parsing/{inference => result}/field/inferenceFields.ts (100%) rename src/v2/parsing/{inference => result}/field/listField.ts (100%) rename src/v2/parsing/{inference => result}/field/objectField.ts (100%) rename src/v2/parsing/{inference => result}/field/ragMetadata.ts (100%) rename src/v2/parsing/{inference => result}/field/rawText.ts (100%) rename src/v2/parsing/{inference => result}/field/rawTextPage.ts (100%) rename src/v2/parsing/{inference => result}/field/simpleField.ts (100%) rename src/v2/parsing/{inference => result}/index.ts (100%) rename src/v2/parsing/{inference => result}/inferenceFile.ts (100%) rename src/v2/parsing/{inference => result}/inferenceModel.ts (100%) rename src/v2/parsing/{inference => result}/ocr/ocrInference.ts (86%) rename src/v2/parsing/{inference => result}/ocr/ocrResponse.ts (76%) rename src/v2/parsing/{inference => result}/split/splitInference.ts (86%) rename src/v2/parsing/{inference => result}/split/splitResponse.ts (77%) diff --git a/src/input/localInputSource.ts b/src/input/localInputSource.ts index cf18216a..2a0e0dea 100644 --- a/src/input/localInputSource.ts +++ b/src/input/localInputSource.ts @@ -54,7 +54,7 @@ export abstract class LocalInputSource extends InputSource { ); } this.inputType = inputType; - logger.debug(`New local input source of type: ${inputType}`); + logger.debug(`Initialized local input source of type: ${inputType}`); } protected async checkMimetype(): Promise { diff --git a/src/input/urlInput.ts b/src/input/urlInput.ts index 20e2a3d9..1b33ed0a 100644 --- a/src/input/urlInput.ts +++ b/src/input/urlInput.ts @@ -15,6 +15,7 @@ export class UrlInput extends InputSource { super(); this.url = url; this.dispatcher = dispatcher ?? getGlobalDispatcher(); + logger.debug("Initialized URL input source."); } async init() { diff --git a/src/v2/cli.ts b/src/v2/cli.ts index 1fc52b44..0dd3292a 100644 --- a/src/v2/cli.ts +++ b/src/v2/cli.ts @@ -10,7 +10,7 @@ import { OcrInference, SplitInference, InferenceResponseConstructor, -} from "@/v2/parsing/inference/index.js"; +} from "@/v2/parsing/result/index.js"; const program = new Command(); diff --git a/src/v2/client.ts b/src/v2/client.ts index 0da31477..3c9b2ee9 100644 --- a/src/v2/client.ts +++ b/src/v2/client.ts @@ -17,7 +17,14 @@ import { } from "./parsing/index.js"; import { MindeeApiV2 } from "./http/mindeeApiV2.js"; import { MindeeHttpErrorV2 } from "./http/errors.js"; -import { ExtractionParameters, UtilityParameters, ValidatedPollingOptions } from "./client/index.js"; +import { + BaseParameters, + ExtractionParameters, + CropParameters, + OcrParameters, + SplitParameters, + ValidatedPollingOptions +} from "./client/index.js"; /** * Options for the V2 Mindee Client. @@ -39,10 +46,14 @@ export interface ClientOptions { dispatcher?: Dispatcher; } -type InferenceParameters = - | UtilityParameters +type EnqueueParameters = + | CropParameters + | ConstructorParameters[0] + | OcrParameters + | ConstructorParameters[0] + | SplitParameters + | ConstructorParameters[0] | ExtractionParameters - | ConstructorParameters[0] | ConstructorParameters[0]; /** @@ -75,18 +86,18 @@ export class Client { #getParametersClassFromInference( inferenceClass: InferenceResponseConstructor, - params: any, - ): ExtractionParameters | UtilityParameters { - if (params instanceof ExtractionParameters || params instanceof UtilityParameters) { + params: EnqueueParameters, + ): BaseParameters { + if (params instanceof BaseParameters) { return params; } switch (inferenceClass as any) { case CropInference: - return new UtilityParameters(params); + return new CropParameters(params); case OcrInference: - return new UtilityParameters(params); + return new OcrParameters(params); case SplitInference: - return new UtilityParameters(params); + return new SplitParameters(params); case ExtractionInference: return new ExtractionParameters(params); default: @@ -97,7 +108,7 @@ export class Client { async enqueue( responseType: InferenceResponseConstructor, inputSource: InputSource, - params: InferenceParameters, + params: EnqueueParameters, ): Promise { if (inputSource === undefined) { throw new MindeeError("An input document is required."); @@ -167,7 +178,7 @@ export class Client { async enqueueAndGetResult( responseType: InferenceResponseConstructor, inputSource: InputSource, - params: InferenceParameters + params: EnqueueParameters ): Promise> { const paramsInstance = this.#getParametersClassFromInference( responseType, params diff --git a/src/v2/client/baseParameters.ts b/src/v2/client/baseParameters.ts index e2f3263c..7811e218 100644 --- a/src/v2/client/baseParameters.ts +++ b/src/v2/client/baseParameters.ts @@ -1,6 +1,7 @@ import { ValidatedPollingOptions } from "@/v2/client/pollingOptions.js"; import { PollingOptions } from "@/v2/index.js"; import { MindeeConfigurationError } from "@/errors/index.js"; +import { logger } from "@/logger.js"; /** * Constructor parameters for BaseParameters and its subclasses. diff --git a/src/v2/client/cropParameters.ts b/src/v2/client/cropParameters.ts new file mode 100644 index 00000000..184b7b30 --- /dev/null +++ b/src/v2/client/cropParameters.ts @@ -0,0 +1,27 @@ +import { BaseParameters, BaseParametersConstructor } from "@/v2/client/baseParameters.js"; +import { logger } from "@/logger.js"; + +/** + * Parameters accepted by the asynchronous **inference** v2 endpoint. + * + * All fields are optional except `modelId`. + * + * @category ClientV2 + * @example + * const params = { + * modelId: "YOUR_MODEL_ID", + * alias: "YOUR_ALIAS", + * webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"], + * pollingOptions: { + * initialDelaySec: 2, + * delaySec: 1.5, + * } + * }; + */ +export class CropParameters extends BaseParameters { + + constructor(params: BaseParametersConstructor & {}) { + super({ ...params }); + logger.debug("Crop parameters initialized."); + } +} diff --git a/src/v2/client/extractionParameters.ts b/src/v2/client/extractionParameters.ts index b63f83be..fe3b8f1c 100644 --- a/src/v2/client/extractionParameters.ts +++ b/src/v2/client/extractionParameters.ts @@ -1,6 +1,7 @@ import { StringDict } from "@/parsing/stringDict.js"; import { DataSchema } from "./dataSchema.js"; import { BaseParameters, BaseParametersConstructor } from "@/v2/client/baseParameters.js"; +import { logger } from "@/logger.js"; /** * Parameters accepted by the asynchronous **inference** v2 endpoint. @@ -71,6 +72,7 @@ export class ExtractionParameters extends BaseParameters { this.dataSchema = params.dataSchema; } } + logger.debug("Extraction parameters initialized."); } getFormData(): FormData { diff --git a/src/v2/client/index.ts b/src/v2/client/index.ts index d64ca2b3..f2f75ee2 100644 --- a/src/v2/client/index.ts +++ b/src/v2/client/index.ts @@ -1,4 +1,7 @@ export { DataSchema } from "./dataSchema.js"; export type { PollingOptions, ValidatedPollingOptions } from "./pollingOptions.js"; export { ExtractionParameters } from "./extractionParameters.js"; -export { UtilityParameters } from "./utilityParameters.js"; +export { BaseParameters } from "./baseParameters.js"; +export { CropParameters } from "./cropParameters.js"; +export { OcrParameters } from "./ocrParameters.js"; +export { SplitParameters } from "./splitParameters.js"; diff --git a/src/v2/client/utilityParameters.ts b/src/v2/client/ocrParameters.ts similarity index 80% rename from src/v2/client/utilityParameters.ts rename to src/v2/client/ocrParameters.ts index b46676f0..a88ed7a7 100644 --- a/src/v2/client/utilityParameters.ts +++ b/src/v2/client/ocrParameters.ts @@ -1,4 +1,5 @@ import { BaseParameters, BaseParametersConstructor } from "@/v2/client/baseParameters.js"; +import { logger } from "@/logger.js"; /** * Parameters accepted by the asynchronous **inference** v2 endpoint. @@ -17,9 +18,10 @@ import { BaseParameters, BaseParametersConstructor } from "@/v2/client/baseParam * } * }; */ -export class UtilityParameters extends BaseParameters { +export class OcrParameters extends BaseParameters { constructor(params: BaseParametersConstructor & {}) { super({ ...params }); + logger.debug("Ocr parameters initialized."); } } diff --git a/src/v2/client/splitParameters.ts b/src/v2/client/splitParameters.ts new file mode 100644 index 00000000..48a4e2c4 --- /dev/null +++ b/src/v2/client/splitParameters.ts @@ -0,0 +1,27 @@ +import { BaseParameters, BaseParametersConstructor } from "@/v2/client/baseParameters.js"; +import { logger } from "@/logger.js"; + +/** + * Parameters accepted by the asynchronous **inference** v2 endpoint. + * + * All fields are optional except `modelId`. + * + * @category ClientV2 + * @example + * const params = { + * modelId: "YOUR_MODEL_ID", + * alias: "YOUR_ALIAS", + * webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"], + * pollingOptions: { + * initialDelaySec: 2, + * delaySec: 1.5, + * } + * }; + */ +export class SplitParameters extends BaseParameters { + + constructor(params: BaseParametersConstructor & {}) { + super({ ...params }); + logger.debug("Split parameters initialized."); + } +} diff --git a/src/v2/http/mindeeApiV2.ts b/src/v2/http/mindeeApiV2.ts index 72f5f509..36c7d04d 100644 --- a/src/v2/http/mindeeApiV2.ts +++ b/src/v2/http/mindeeApiV2.ts @@ -1,6 +1,6 @@ import { ApiSettingsV2 } from "./apiSettingsV2.js"; import { Dispatcher } from "undici"; -import { ExtractionParameters, UtilityParameters } from "@/v2/client/index.js"; +import { ExtractionParameters, SplitParameters } from "@/v2/client/index.js"; import { BaseResponse, ErrorResponse, @@ -23,7 +23,7 @@ import { CropInference, OcrInference, SplitInference -} from "@/v2/parsing/inference/index.js"; +} from "@/v2/parsing/result/index.js"; export class MindeeApiV2 { @@ -79,7 +79,7 @@ export class MindeeApiV2 { async reqPostInferenceEnqueue( responseClass: InferenceResponseConstructor, inputSource: InputSource, - params: ExtractionParameters | UtilityParameters + params: ExtractionParameters | SplitParameters ): Promise { await inputSource.init(); const slug = this.#getSlugFromInference(responseClass); @@ -159,7 +159,7 @@ export class MindeeApiV2 { async #inferenceEnqueuePost( inputSource: InputSource, slug: string, - params: ExtractionParameters | UtilityParameters + params: ExtractionParameters | SplitParameters ): Promise { const form = params.getFormData(); if (inputSource instanceof LocalInputSource) { diff --git a/src/v2/parsing/index.ts b/src/v2/parsing/index.ts index ffb759ef..6a55fc64 100644 --- a/src/v2/parsing/index.ts +++ b/src/v2/parsing/index.ts @@ -25,8 +25,8 @@ export { OcrInference, SplitResponse, SplitInference, -} from "./inference/index.js"; +} from "./result/index.js"; export { LocalResponse } from "./localResponse.js"; -export { RawText, RagMetadata } from "./inference/field/index.js"; +export { RawText, RagMetadata } from "./result/field/index.js"; export type { ResponseConstructor, BaseResponse } from "./baseResponse.js"; -export type { InferenceResponseConstructor } from "./inference/index.js"; +export type { InferenceResponseConstructor } from "./result/index.js"; diff --git a/src/v2/parsing/inference/baseInference.ts b/src/v2/parsing/result/baseInference.ts similarity index 88% rename from src/v2/parsing/inference/baseInference.ts rename to src/v2/parsing/result/baseInference.ts index ab44a6ca..76c3731f 100644 --- a/src/v2/parsing/inference/baseInference.ts +++ b/src/v2/parsing/result/baseInference.ts @@ -1,4 +1,4 @@ -import { InferenceModel } from "@/v2/parsing/inference/inferenceModel.js"; +import { InferenceModel } from "@/v2/parsing/result/inferenceModel.js"; import { InferenceFile } from "@/v2/index.js"; import { StringDict } from "@/parsing/index.js"; diff --git a/src/v2/parsing/inference/baseInferenceResponse.ts b/src/v2/parsing/result/baseInferenceResponse.ts similarity index 100% rename from src/v2/parsing/inference/baseInferenceResponse.ts rename to src/v2/parsing/result/baseInferenceResponse.ts diff --git a/src/v2/parsing/inference/classification/classificationInference.ts b/src/v2/parsing/result/classification/classificationInference.ts similarity index 87% rename from src/v2/parsing/inference/classification/classificationInference.ts rename to src/v2/parsing/result/classification/classificationInference.ts index 916c71dd..4ac7b754 100644 --- a/src/v2/parsing/inference/classification/classificationInference.ts +++ b/src/v2/parsing/result/classification/classificationInference.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/index.js"; -import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; +import { BaseInference } from "@/v2/parsing/result/baseInference.js"; export class ClassificationInference extends BaseInference { /** diff --git a/src/v2/parsing/inference/classification/classificationResponse.ts b/src/v2/parsing/result/classification/classificationResponse.ts similarity index 83% rename from src/v2/parsing/inference/classification/classificationResponse.ts rename to src/v2/parsing/result/classification/classificationResponse.ts index e348e76e..2e370ab0 100644 --- a/src/v2/parsing/inference/classification/classificationResponse.ts +++ b/src/v2/parsing/result/classification/classificationResponse.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/stringDict.js"; -import { BaseInferenceResponse } from "@/v2/parsing/inference/index.js"; +import { BaseInferenceResponse } from "@/v2/parsing/result/index.js"; import { ClassificationInference } from "./classificationInference.js"; export class ClassificationResponse extends BaseInferenceResponse { diff --git a/src/v2/parsing/inference/crop/cropInference.ts b/src/v2/parsing/result/crop/cropInference.ts similarity index 78% rename from src/v2/parsing/inference/crop/cropInference.ts rename to src/v2/parsing/result/crop/cropInference.ts index 19e68c98..a0ba38ac 100644 --- a/src/v2/parsing/inference/crop/cropInference.ts +++ b/src/v2/parsing/result/crop/cropInference.ts @@ -1,6 +1,6 @@ import { StringDict } from "@/parsing/index.js"; -import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; -import { CropResult } from "@/v2/parsing/inference/crop/cropResult.js"; +import { BaseInference } from "@/v2/parsing/result/baseInference.js"; +import { CropResult } from "@/v2/parsing/result/crop/cropResult.js"; export class CropInference extends BaseInference { /** diff --git a/src/v2/parsing/inference/crop/cropItem.ts b/src/v2/parsing/result/crop/cropItem.ts similarity index 72% rename from src/v2/parsing/inference/crop/cropItem.ts rename to src/v2/parsing/result/crop/cropItem.ts index c1481a07..ab0d921e 100644 --- a/src/v2/parsing/inference/crop/cropItem.ts +++ b/src/v2/parsing/result/crop/cropItem.ts @@ -1,4 +1,4 @@ -import { FieldLocation } from "@/v2/parsing/inference/field/index.js"; +import { FieldLocation } from "@/v2/parsing/result/field/index.js"; import { StringDict } from "@/parsing/index.js"; export class CropItem { @@ -11,6 +11,6 @@ export class CropItem { } toString(): string { - return `${this.objectType} :: ${this.location}`; + return `${this.objectType}: ${this.location}`; } } diff --git a/src/v2/parsing/inference/crop/cropResponse.ts b/src/v2/parsing/result/crop/cropResponse.ts similarity index 77% rename from src/v2/parsing/inference/crop/cropResponse.ts rename to src/v2/parsing/result/crop/cropResponse.ts index 3f8f1941..31a6ca34 100644 --- a/src/v2/parsing/inference/crop/cropResponse.ts +++ b/src/v2/parsing/result/crop/cropResponse.ts @@ -1,6 +1,6 @@ import { StringDict } from "@/parsing/stringDict.js"; import { CropInference } from "./cropInference.js"; -import { BaseInferenceResponse } from "@/v2/parsing/inference/baseInferenceResponse.js"; +import { BaseInferenceResponse } from "@/v2/parsing/result/baseInferenceResponse.js"; export class CropResponse extends BaseInferenceResponse { diff --git a/src/v2/parsing/inference/crop/cropResult.ts b/src/v2/parsing/result/crop/cropResult.ts similarity index 66% rename from src/v2/parsing/inference/crop/cropResult.ts rename to src/v2/parsing/result/crop/cropResult.ts index b2bcb51a..60e876b2 100644 --- a/src/v2/parsing/inference/crop/cropResult.ts +++ b/src/v2/parsing/result/crop/cropResult.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/stringDict.js"; -import { CropItem } from "@/v2/parsing/inference/crop/cropItem.js"; +import { CropItem } from "@/v2/parsing/result/crop/cropItem.js"; export class CropResult { /** @@ -12,6 +12,7 @@ export class CropResult { } toString(): string { - return `Crop\n====\n${this.crop}`; + const crop = this.crop.map(item => item.toString()).join("\n * "); + return `Crop\n====\n * ${crop}`; } } diff --git a/src/v2/parsing/inference/extraction/dataSchemaActiveOption.ts b/src/v2/parsing/result/extraction/dataSchemaActiveOption.ts similarity index 100% rename from src/v2/parsing/inference/extraction/dataSchemaActiveOption.ts rename to src/v2/parsing/result/extraction/dataSchemaActiveOption.ts diff --git a/src/v2/parsing/inference/extraction/extractionActiveOptions.ts b/src/v2/parsing/result/extraction/extractionActiveOptions.ts similarity index 100% rename from src/v2/parsing/inference/extraction/extractionActiveOptions.ts rename to src/v2/parsing/result/extraction/extractionActiveOptions.ts diff --git a/src/v2/parsing/inference/extraction/extractionInference.ts b/src/v2/parsing/result/extraction/extractionInference.ts similarity index 92% rename from src/v2/parsing/inference/extraction/extractionInference.ts rename to src/v2/parsing/result/extraction/extractionInference.ts index 7db6d240..91d77f2d 100644 --- a/src/v2/parsing/inference/extraction/extractionInference.ts +++ b/src/v2/parsing/result/extraction/extractionInference.ts @@ -1,7 +1,7 @@ import { StringDict } from "@/parsing/stringDict.js"; import { ExtractionResult } from "./extractionResult.js"; import { ExtractionActiveOptions } from "./extractionActiveOptions.js"; -import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; +import { BaseInference } from "@/v2/parsing/result/baseInference.js"; export class ExtractionInference extends BaseInference { /** diff --git a/src/v2/parsing/inference/extraction/extractionResponse.ts b/src/v2/parsing/result/extraction/extractionResponse.ts similarity index 79% rename from src/v2/parsing/inference/extraction/extractionResponse.ts rename to src/v2/parsing/result/extraction/extractionResponse.ts index e61e836c..12c38ac6 100644 --- a/src/v2/parsing/inference/extraction/extractionResponse.ts +++ b/src/v2/parsing/result/extraction/extractionResponse.ts @@ -1,6 +1,6 @@ import { ExtractionInference } from "./extractionInference.js"; import { StringDict } from "@/parsing/stringDict.js"; -import { BaseInferenceResponse } from "@/v2/parsing/inference/baseInferenceResponse.js"; +import { BaseInferenceResponse } from "@/v2/parsing/result/baseInferenceResponse.js"; export class ExtractionResponse extends BaseInferenceResponse { diff --git a/src/v2/parsing/inference/extraction/extractionResult.ts b/src/v2/parsing/result/extraction/extractionResult.ts similarity index 91% rename from src/v2/parsing/inference/extraction/extractionResult.ts rename to src/v2/parsing/result/extraction/extractionResult.ts index e1a89d50..4e1ebbb0 100644 --- a/src/v2/parsing/inference/extraction/extractionResult.ts +++ b/src/v2/parsing/result/extraction/extractionResult.ts @@ -1,4 +1,4 @@ -import { InferenceFields } from "@/v2/parsing/inference/field/index.js"; +import { InferenceFields } from "@/v2/parsing/result/field/index.js"; import { StringDict } from "@/parsing/stringDict.js"; import { RawText } from "../field/rawText.js"; import { RagMetadata } from "../field/ragMetadata.js"; diff --git a/src/v2/parsing/inference/field/baseField.ts b/src/v2/parsing/result/field/baseField.ts similarity index 100% rename from src/v2/parsing/inference/field/baseField.ts rename to src/v2/parsing/result/field/baseField.ts diff --git a/src/v2/parsing/inference/field/fieldConfidence.ts b/src/v2/parsing/result/field/fieldConfidence.ts similarity index 100% rename from src/v2/parsing/inference/field/fieldConfidence.ts rename to src/v2/parsing/result/field/fieldConfidence.ts diff --git a/src/v2/parsing/inference/field/fieldFactory.ts b/src/v2/parsing/result/field/fieldFactory.ts similarity index 100% rename from src/v2/parsing/inference/field/fieldFactory.ts rename to src/v2/parsing/result/field/fieldFactory.ts diff --git a/src/v2/parsing/inference/field/fieldLocation.ts b/src/v2/parsing/result/field/fieldLocation.ts similarity index 100% rename from src/v2/parsing/inference/field/fieldLocation.ts rename to src/v2/parsing/result/field/fieldLocation.ts diff --git a/src/v2/parsing/inference/field/index.ts b/src/v2/parsing/result/field/index.ts similarity index 100% rename from src/v2/parsing/inference/field/index.ts rename to src/v2/parsing/result/field/index.ts diff --git a/src/v2/parsing/inference/field/inferenceFields.ts b/src/v2/parsing/result/field/inferenceFields.ts similarity index 100% rename from src/v2/parsing/inference/field/inferenceFields.ts rename to src/v2/parsing/result/field/inferenceFields.ts diff --git a/src/v2/parsing/inference/field/listField.ts b/src/v2/parsing/result/field/listField.ts similarity index 100% rename from src/v2/parsing/inference/field/listField.ts rename to src/v2/parsing/result/field/listField.ts diff --git a/src/v2/parsing/inference/field/objectField.ts b/src/v2/parsing/result/field/objectField.ts similarity index 100% rename from src/v2/parsing/inference/field/objectField.ts rename to src/v2/parsing/result/field/objectField.ts diff --git a/src/v2/parsing/inference/field/ragMetadata.ts b/src/v2/parsing/result/field/ragMetadata.ts similarity index 100% rename from src/v2/parsing/inference/field/ragMetadata.ts rename to src/v2/parsing/result/field/ragMetadata.ts diff --git a/src/v2/parsing/inference/field/rawText.ts b/src/v2/parsing/result/field/rawText.ts similarity index 100% rename from src/v2/parsing/inference/field/rawText.ts rename to src/v2/parsing/result/field/rawText.ts diff --git a/src/v2/parsing/inference/field/rawTextPage.ts b/src/v2/parsing/result/field/rawTextPage.ts similarity index 100% rename from src/v2/parsing/inference/field/rawTextPage.ts rename to src/v2/parsing/result/field/rawTextPage.ts diff --git a/src/v2/parsing/inference/field/simpleField.ts b/src/v2/parsing/result/field/simpleField.ts similarity index 100% rename from src/v2/parsing/inference/field/simpleField.ts rename to src/v2/parsing/result/field/simpleField.ts diff --git a/src/v2/parsing/inference/index.ts b/src/v2/parsing/result/index.ts similarity index 100% rename from src/v2/parsing/inference/index.ts rename to src/v2/parsing/result/index.ts diff --git a/src/v2/parsing/inference/inferenceFile.ts b/src/v2/parsing/result/inferenceFile.ts similarity index 100% rename from src/v2/parsing/inference/inferenceFile.ts rename to src/v2/parsing/result/inferenceFile.ts diff --git a/src/v2/parsing/inference/inferenceModel.ts b/src/v2/parsing/result/inferenceModel.ts similarity index 100% rename from src/v2/parsing/inference/inferenceModel.ts rename to src/v2/parsing/result/inferenceModel.ts diff --git a/src/v2/parsing/inference/ocr/ocrInference.ts b/src/v2/parsing/result/ocr/ocrInference.ts similarity index 86% rename from src/v2/parsing/inference/ocr/ocrInference.ts rename to src/v2/parsing/result/ocr/ocrInference.ts index c767fccf..2af66d3a 100644 --- a/src/v2/parsing/inference/ocr/ocrInference.ts +++ b/src/v2/parsing/result/ocr/ocrInference.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/index.js"; -import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; +import { BaseInference } from "@/v2/parsing/result/baseInference.js"; export class OcrInference extends BaseInference { /** diff --git a/src/v2/parsing/inference/ocr/ocrResponse.ts b/src/v2/parsing/result/ocr/ocrResponse.ts similarity index 76% rename from src/v2/parsing/inference/ocr/ocrResponse.ts rename to src/v2/parsing/result/ocr/ocrResponse.ts index f0c8e452..c3b627e5 100644 --- a/src/v2/parsing/inference/ocr/ocrResponse.ts +++ b/src/v2/parsing/result/ocr/ocrResponse.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/stringDict.js"; -import { BaseInferenceResponse } from "@/v2/parsing/inference/baseInferenceResponse.js"; +import { BaseInferenceResponse } from "@/v2/parsing/result/baseInferenceResponse.js"; import { OcrInference } from "./ocrInference.js"; export class OcrResponse extends BaseInferenceResponse { diff --git a/src/v2/parsing/inference/split/splitInference.ts b/src/v2/parsing/result/split/splitInference.ts similarity index 86% rename from src/v2/parsing/inference/split/splitInference.ts rename to src/v2/parsing/result/split/splitInference.ts index a195a9b9..1ba8e513 100644 --- a/src/v2/parsing/inference/split/splitInference.ts +++ b/src/v2/parsing/result/split/splitInference.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/index.js"; -import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; +import { BaseInference } from "@/v2/parsing/result/baseInference.js"; export class SplitInference extends BaseInference { /** diff --git a/src/v2/parsing/inference/split/splitResponse.ts b/src/v2/parsing/result/split/splitResponse.ts similarity index 77% rename from src/v2/parsing/inference/split/splitResponse.ts rename to src/v2/parsing/result/split/splitResponse.ts index 3336d93a..b84d1522 100644 --- a/src/v2/parsing/inference/split/splitResponse.ts +++ b/src/v2/parsing/result/split/splitResponse.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/stringDict.js"; -import { BaseInferenceResponse } from "@/v2/parsing/inference/baseInferenceResponse.js"; +import { BaseInferenceResponse } from "@/v2/parsing/result/baseInferenceResponse.js"; import { SplitInference } from "./splitInference.js"; export class SplitResponse extends BaseInferenceResponse { diff --git a/tests/v2/client.integration.ts b/tests/v2/client.integration.ts index 07750e0b..38d7700e 100644 --- a/tests/v2/client.integration.ts +++ b/tests/v2/client.integration.ts @@ -10,7 +10,7 @@ import { ExtractionResponse, } from "@/index.js"; import { ExtractionInference } from "@/v2/parsing/index.js"; -import { SimpleField } from "@/v2/parsing/inference/field/index.js"; +import { SimpleField } from "@/v2/parsing/result/field/index.js"; import { MindeeHttpErrorV2 } from "@/v2/http/index.js"; import * as fs from "node:fs"; import { RESOURCE_PATH, V2_PRODUCT_PATH, V2_RESOURCE_PATH } from "../index.js"; diff --git a/tests/v2/client.spec.ts b/tests/v2/client.spec.ts index 0512077b..5aa0cd75 100644 --- a/tests/v2/client.spec.ts +++ b/tests/v2/client.spec.ts @@ -69,7 +69,7 @@ describe("MindeeV2 - ClientV2", () => { expect(api.settings.baseHeaders["User-Agent"]).to.match(/mindee/i); }); - it("enqueueInference(path) rejects with MindeeHttpErrorV2 on 400", async () => { + it("enqueue(path) on extraction rejects with MindeeHttpErrorV2 on 400", async () => { const filePath = path.join(fileTypesDir, "receipt.jpg"); const inputDoc = new PathInput({ inputPath: filePath }); @@ -83,7 +83,7 @@ describe("MindeeV2 - ClientV2", () => { ); }); - it("enqueueUtility(path) rejects with MindeeHttpErrorV2 on 400", async () => { + it("enqueue(path) on crop rejects with MindeeHttpErrorV2 on 400", async () => { const filePath = path.join(fileTypesDir, "receipt.jpg"); const inputDoc = new PathInput({ inputPath: filePath }); @@ -97,7 +97,7 @@ describe("MindeeV2 - ClientV2", () => { ); }); - it("enqueueAndGetInference(path) rejects with MindeeHttpErrorV2 on 400", async () => { + it("enqueueAndGetResult(path) on extraction rejects with MindeeHttpErrorV2 on 400", async () => { const filePath = path.join(fileTypesDir, "receipt.jpg"); const inputDoc = new PathInput({ inputPath: filePath }); await assert.rejects( diff --git a/tests/v2/parsing/inference.spec.ts b/tests/v2/parsing/inference.spec.ts index 86a29069..5ed6d732 100644 --- a/tests/v2/parsing/inference.spec.ts +++ b/tests/v2/parsing/inference.spec.ts @@ -7,7 +7,7 @@ import { ListField, ObjectField, SimpleField, -} from "@/v2/parsing/inference/field/index.js"; +} from "@/v2/parsing/result/field/index.js"; import { LocalResponse, ExtractionResponse, From dcc0c29d93819ff5888d1f3048d9d8a8cce08220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Wed, 4 Feb 2026 12:31:34 +0100 Subject: [PATCH 3/9] error response should inherit from base response --- src/v2/parsing/error/errorResponse.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/v2/parsing/error/errorResponse.ts b/src/v2/parsing/error/errorResponse.ts index f32ab273..a2df695b 100644 --- a/src/v2/parsing/error/errorResponse.ts +++ b/src/v2/parsing/error/errorResponse.ts @@ -1,11 +1,12 @@ import { StringDict } from "@/parsing/stringDict.js"; import { ErrorItem } from "./errorItem.js"; import { ErrorDetails } from "./errorDetails.js"; +import { BaseResponse } from "@/v2/parsing/baseResponse.js"; /** * Error response detailing a problem. The format adheres to RFC 9457. */ -export class ErrorResponse implements ErrorDetails { +export class ErrorResponse extends BaseResponse implements ErrorDetails { status: number; detail: string; title: string; @@ -16,6 +17,7 @@ export class ErrorResponse implements ErrorDetails { * @param serverResponse JSON response from the server. */ constructor(serverResponse: StringDict) { + super(serverResponse); this.status = serverResponse["status"]; this.detail = serverResponse["detail"]; this.title = serverResponse["title"]; From 8455860e27780b64e0d3eede06622b1d317d83e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Wed, 4 Feb 2026 15:47:49 +0100 Subject: [PATCH 4/9] put post slug in params class --- src/v2/client/baseParameters.ts | 3 ++- src/v2/client/cropParameters.ts | 1 + src/v2/client/extractionParameters.ts | 2 ++ src/v2/client/ocrParameters.ts | 1 + src/v2/client/splitParameters.ts | 1 + src/v2/http/mindeeApiV2.ts | 7 ++----- src/v2/parsing/result/crop/cropResult.ts | 8 ++++---- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/v2/client/baseParameters.ts b/src/v2/client/baseParameters.ts index 7811e218..41bfae00 100644 --- a/src/v2/client/baseParameters.ts +++ b/src/v2/client/baseParameters.ts @@ -1,7 +1,6 @@ import { ValidatedPollingOptions } from "@/v2/client/pollingOptions.js"; import { PollingOptions } from "@/v2/index.js"; import { MindeeConfigurationError } from "@/errors/index.js"; -import { logger } from "@/logger.js"; /** * Constructor parameters for BaseParameters and its subclasses. @@ -57,6 +56,8 @@ export abstract class BaseParameters { */ closeFile?: boolean; + abstract readonly slug: string; + protected constructor(params: BaseParametersConstructor) { if (params.modelId === undefined || params.modelId === null || params.modelId === "") { throw new MindeeConfigurationError("Model ID must be provided"); diff --git a/src/v2/client/cropParameters.ts b/src/v2/client/cropParameters.ts index 184b7b30..740b8c26 100644 --- a/src/v2/client/cropParameters.ts +++ b/src/v2/client/cropParameters.ts @@ -19,6 +19,7 @@ import { logger } from "@/logger.js"; * }; */ export class CropParameters extends BaseParameters { + slug = "utilities/crop"; constructor(params: BaseParametersConstructor & {}) { super({ ...params }); diff --git a/src/v2/client/extractionParameters.ts b/src/v2/client/extractionParameters.ts index fe3b8f1c..0578242c 100644 --- a/src/v2/client/extractionParameters.ts +++ b/src/v2/client/extractionParameters.ts @@ -22,6 +22,8 @@ import { logger } from "@/logger.js"; * }; */ export class ExtractionParameters extends BaseParameters { + slug = "inferences"; + /** * Use Retrieval-Augmented Generation during inference. */ diff --git a/src/v2/client/ocrParameters.ts b/src/v2/client/ocrParameters.ts index a88ed7a7..20ecf6dd 100644 --- a/src/v2/client/ocrParameters.ts +++ b/src/v2/client/ocrParameters.ts @@ -19,6 +19,7 @@ import { logger } from "@/logger.js"; * }; */ export class OcrParameters extends BaseParameters { + slug = "utilities/ocr"; constructor(params: BaseParametersConstructor & {}) { super({ ...params }); diff --git a/src/v2/client/splitParameters.ts b/src/v2/client/splitParameters.ts index 48a4e2c4..137d3659 100644 --- a/src/v2/client/splitParameters.ts +++ b/src/v2/client/splitParameters.ts @@ -19,6 +19,7 @@ import { logger } from "@/logger.js"; * }; */ export class SplitParameters extends BaseParameters { + slug = "utilities/split"; constructor(params: BaseParametersConstructor & {}) { super({ ...params }); diff --git a/src/v2/http/mindeeApiV2.ts b/src/v2/http/mindeeApiV2.ts index 36c7d04d..facdbfd0 100644 --- a/src/v2/http/mindeeApiV2.ts +++ b/src/v2/http/mindeeApiV2.ts @@ -82,9 +82,8 @@ export class MindeeApiV2 { params: ExtractionParameters | SplitParameters ): Promise { await inputSource.init(); - const slug = this.#getSlugFromInference(responseClass); const result: BaseHttpResponse = await this.#inferenceEnqueuePost( - inputSource, slug, params + inputSource, params ); if (result.data.error !== undefined) { throw new MindeeHttpErrorV2(result.data.error); @@ -153,12 +152,10 @@ export class MindeeApiV2 { * Sends a document to the inference queue. * * @param inputSource Local or remote file as an input. - * @param slug Slug of the inference to enqueue. * @param params {ExtractionParameters} parameters relating to the enqueueing options. */ async #inferenceEnqueuePost( inputSource: InputSource, - slug: string, params: ExtractionParameters | SplitParameters ): Promise { const form = params.getFormData(); @@ -167,7 +164,7 @@ export class MindeeApiV2 { } else { form.set("url", (inputSource as UrlInput).url); } - const path = `/v2/${slug}/enqueue`; + const path = `/v2/${params.slug}/enqueue`; const options = { method: "POST", headers: this.settings.baseHeaders, diff --git a/src/v2/parsing/result/crop/cropResult.ts b/src/v2/parsing/result/crop/cropResult.ts index 60e876b2..fef55ca8 100644 --- a/src/v2/parsing/result/crop/cropResult.ts +++ b/src/v2/parsing/result/crop/cropResult.ts @@ -5,14 +5,14 @@ export class CropResult { /** * Fields contained in the inference. */ - public crop: CropItem[] = []; + public crops: CropItem[] = []; constructor(serverResponse: StringDict) { - this.crop = serverResponse["crop"].map((cropItem: StringDict) => new CropItem(cropItem)); + this.crops = serverResponse["crops"].map((cropItem: StringDict) => new CropItem(cropItem)); } toString(): string { - const crop = this.crop.map(item => item.toString()).join("\n * "); - return `Crop\n====\n * ${crop}`; + const crops = this.crops.map(item => item.toString()).join("\n * "); + return `Crop\n====\n * ${crops}`; } } From 83255c9c8740384b43bf0b0ac1fafc7671def2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Thu, 5 Feb 2026 19:02:08 +0100 Subject: [PATCH 5/9] better enqueue --- docs/code_samples/{default_v2.txt => v2_default.txt} | 7 +++---- src/v2/client.ts | 2 +- src/v2/http/mindeeApiV2.ts | 10 ++++------ 3 files changed, 8 insertions(+), 11 deletions(-) rename docs/code_samples/{default_v2.txt => v2_default.txt} (88%) diff --git a/docs/code_samples/default_v2.txt b/docs/code_samples/v2_default.txt similarity index 88% rename from docs/code_samples/default_v2.txt rename to docs/code_samples/v2_default.txt index d909f3a0..e49f74a4 100644 --- a/docs/code_samples/default_v2.txt +++ b/docs/code_samples/v2_default.txt @@ -12,7 +12,7 @@ const mindeeClient = new mindee.Client( ); // Set inference parameters -const inferenceParams = { +const extractionParams = { modelId: modelId, // Options: set to `true` or `false` to override defaults @@ -32,10 +32,9 @@ const inferenceParams = { const inputSource = new mindee.PathInput({ inputPath: filePath }); // Send for processing -const response = mindeeClient.enqueueAndGetInference( - mindee.v2.ExtractionInference, +const response = mindeeClient.enqueueAndGetResult( inputSource, - inferenceParams + extractionParams ); // Handle the response Promise diff --git a/src/v2/client.ts b/src/v2/client.ts index 3c9b2ee9..8b40f500 100644 --- a/src/v2/client.ts +++ b/src/v2/client.ts @@ -118,7 +118,7 @@ export class Client { ); await inputSource.init(); const jobResponse = await this.mindeeApi.reqPostInferenceEnqueue( - responseType, inputSource, paramsInstance + inputSource, paramsInstance ); if (jobResponse.job.id === undefined || jobResponse.job.id.length === 0) { logger.error(`Failed enqueueing:\n${jobResponse.getRawHttp()}`); diff --git a/src/v2/http/mindeeApiV2.ts b/src/v2/http/mindeeApiV2.ts index facdbfd0..8014dd39 100644 --- a/src/v2/http/mindeeApiV2.ts +++ b/src/v2/http/mindeeApiV2.ts @@ -1,6 +1,6 @@ import { ApiSettingsV2 } from "./apiSettingsV2.js"; import { Dispatcher } from "undici"; -import { ExtractionParameters, SplitParameters } from "@/v2/client/index.js"; +import { BaseParameters } from "@/v2/client/index.js"; import { BaseResponse, ErrorResponse, @@ -69,17 +69,15 @@ export class MindeeApiV2 { /** * Sends a file to the extraction inference queue. - * @param responseClass Class of the inference to enqueue. * @param inputSource Local file loaded as an input. * @param params {ExtractionParameters} parameters relating to the enqueueing options. * @category V2 * @throws Error if the server's response contains one. * @returns a `Promise` containing a job response. */ - async reqPostInferenceEnqueue( - responseClass: InferenceResponseConstructor, + async reqPostInferenceEnqueue( inputSource: InputSource, - params: ExtractionParameters | SplitParameters + params: BaseParameters ): Promise { await inputSource.init(); const result: BaseHttpResponse = await this.#inferenceEnqueuePost( @@ -156,7 +154,7 @@ export class MindeeApiV2 { */ async #inferenceEnqueuePost( inputSource: InputSource, - params: ExtractionParameters | SplitParameters + params: BaseParameters ): Promise { const form = params.getFormData(); if (inputSource instanceof LocalInputSource) { From 55e6a7f68090c64129262fc70ea6f363768f9b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 6 Feb 2026 12:08:08 +0100 Subject: [PATCH 6/9] cli works --- src/v2/cli.ts | 32 +++++----- src/v2/client.ts | 66 ++++++--------------- src/v2/client/classificationParameters.ts | 28 +++++++++ src/v2/client/index.ts | 1 + src/v2/http/mindeeApiV2.ts | 71 +++++------------------ src/v2/product/baseProduct.ts | 19 ++++++ src/v2/product/classification.ts | 18 ++++++ src/v2/product/crop.ts | 18 ++++++ src/v2/product/extraction.ts | 18 ++++++ src/v2/product/index.ts | 5 ++ src/v2/product/ocr.ts | 18 ++++++ src/v2/product/split.ts | 18 ++++++ tests/v2/client.integration.ts | 19 +++--- tests/v2/client.spec.ts | 10 ++-- 14 files changed, 209 insertions(+), 132 deletions(-) create mode 100644 src/v2/client/classificationParameters.ts create mode 100644 src/v2/product/baseProduct.ts create mode 100644 src/v2/product/classification.ts create mode 100644 src/v2/product/crop.ts create mode 100644 src/v2/product/extraction.ts create mode 100644 src/v2/product/index.ts create mode 100644 src/v2/product/ocr.ts create mode 100644 src/v2/product/split.ts diff --git a/src/v2/cli.ts b/src/v2/cli.ts index 0dd3292a..14403896 100644 --- a/src/v2/cli.ts +++ b/src/v2/cli.ts @@ -2,15 +2,15 @@ import { Command, OptionValues } from "commander"; import { Client } from "./client.js"; import { PathInput } from "../input/index.js"; import * as console from "console"; +import { BaseInference } from "@/v2/parsing/result/index.js"; +import { BaseProduct } from "@/v2/product/baseProduct.js"; import { - BaseInference, - ClassificationInference, - CropInference, - ExtractionInference, - OcrInference, - SplitInference, - InferenceResponseConstructor, -} from "@/v2/parsing/result/index.js"; + Classification, + Crop, + Extraction, + Ocr, + Split, +} from "@/v2/product/index.js"; const program = new Command(); @@ -27,14 +27,14 @@ function initClient(options: OptionValues): Client { } async function enqueueAndGetInference( - responseType: InferenceResponseConstructor, + product: typeof BaseProduct, inputPath: string, options: OptionValues ): Promise { const mindeeClient = initClient(options); const inputSource = new PathInput({ inputPath: inputPath }); const response = await mindeeClient.enqueueAndGetResult( - responseType, + product, inputSource, { modelId: options.model, @@ -78,11 +78,11 @@ export function cli() { .option("-k, --api-key ", "your Mindee API key"); const inferenceTypes = [ - { name: "extract", description: "Extract data from a document.", responseType: ExtractionInference }, - { name: "crop", description: "Crop a document.", responseType: CropInference }, - { name: "split", description: "Split a document into pages.", responseType: SplitInference }, - { name: "ocr", description: "Read text from a document.", responseType: OcrInference }, - { name: "classify", description: "Classify a document.", responseType: ClassificationInference }, + { name: "extract", description: "Extract data from a document.", product: Extraction }, + { name: "crop", description: "Crop a document.", product: Crop }, + { name: "split", description: "Split a document into pages.", product: Split }, + { name: "ocr", description: "Read text from a document.", product: Ocr }, + { name: "classify", description: "Classify a document.", product: Classification }, ]; for (const inference of inferenceTypes) { @@ -96,7 +96,7 @@ export function cli() { options: OptionValues, ) { const allOptions = { ...program.opts(), ...options }; - return enqueueAndGetInference(inference.responseType, inputPath, allOptions); + return enqueueAndGetInference(inference.product, inputPath, allOptions); }); } diff --git a/src/v2/client.ts b/src/v2/client.ts index 8b40f500..2654a7e4 100644 --- a/src/v2/client.ts +++ b/src/v2/client.ts @@ -7,24 +7,19 @@ import { LOG_LEVELS, logger } from "@/logger.js"; import { ErrorResponse, JobResponse, - InferenceResponseConstructor, BaseInference, BaseInferenceResponse, - CropInference, - OcrInference, - SplitInference, - ExtractionInference, } from "./parsing/index.js"; import { MindeeApiV2 } from "./http/mindeeApiV2.js"; import { MindeeHttpErrorV2 } from "./http/errors.js"; import { - BaseParameters, ExtractionParameters, CropParameters, OcrParameters, SplitParameters, ValidatedPollingOptions } from "./client/index.js"; +import { BaseProduct } from "@/v2/product/baseProduct.js"; /** * Options for the V2 Mindee Client. @@ -84,41 +79,20 @@ export class Client { logger.debug("Client V2 Initialized"); } - #getParametersClassFromInference( - inferenceClass: InferenceResponseConstructor, - params: EnqueueParameters, - ): BaseParameters { - if (params instanceof BaseParameters) { - return params; - } - switch (inferenceClass as any) { - case CropInference: - return new CropParameters(params); - case OcrInference: - return new OcrParameters(params); - case SplitInference: - return new SplitParameters(params); - case ExtractionInference: - return new ExtractionParameters(params); - default: - throw new Error("Unsupported inference class."); - } - } - - async enqueue( - responseType: InferenceResponseConstructor, + async enqueue( + product: typeof BaseProduct, inputSource: InputSource, params: EnqueueParameters, ): Promise { if (inputSource === undefined) { throw new MindeeError("An input document is required."); } - const paramsInstance = this.#getParametersClassFromInference( - responseType, params - ); + const paramsInstance = params instanceof product.parameters + ? params + : new product.parameters(params); await inputSource.init(); - const jobResponse = await this.mindeeApi.reqPostInferenceEnqueue( - inputSource, paramsInstance + const jobResponse = await this.mindeeApi.reqPostProductEnqueue( + product, inputSource, paramsInstance ); if (jobResponse.job.id === undefined || jobResponse.job.id.length === 0) { logger.error(`Failed enqueueing:\n${jobResponse.getRawHttp()}`); @@ -133,20 +107,20 @@ export class Client { /** * Retrieves the result of a previously enqueued request. * - * @param responseType class of the inference to retrieve. + * @param product the product to retrieve. * @param inferenceId id of the queue to poll. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @category Asynchronous * @returns a `Promise` containing the inference. */ async getResult( - responseType: InferenceResponseConstructor, + product: typeof BaseProduct, inferenceId: string ): Promise> { logger.debug( - `Attempting to get inference with ID: ${inferenceId} using response type: ${responseType.name}` + `Attempting to get inference with ID: ${inferenceId} using response type: ${product.name}` ); - return await this.mindeeApi.reqGetInference(responseType, inferenceId); + return await this.mindeeApi.reqGetResult(product, inferenceId); } /** @@ -167,7 +141,7 @@ export class Client { * Enqueue a request and poll the server until the result is sent or * until the maximum number of tries is reached. * - * @param responseType class of the inference to retrieve. + * @param product the product to retrieve. * @param inputSource file or URL to parse. * @param params parameters relating to prediction options. * @@ -176,21 +150,19 @@ export class Client { * @returns a `Promise` containing parsing results. */ async enqueueAndGetResult( - responseType: InferenceResponseConstructor, + product: typeof BaseProduct, inputSource: InputSource, params: EnqueueParameters ): Promise> { - const paramsInstance = this.#getParametersClassFromInference( - responseType, params - ); + const paramsInstance = new product.parameters(params); const pollingOptions = paramsInstance.getValidatedPollingOptions(); const jobResponse: JobResponse = await this.enqueue( - responseType, inputSource, paramsInstance + product, inputSource, paramsInstance ); return await this.pollForResult( - responseType, pollingOptions, jobResponse.job.id + product, pollingOptions, jobResponse.job.id ); } @@ -200,7 +172,7 @@ export class Client { * @protected */ protected async pollForResult( - responseType: InferenceResponseConstructor, + product: typeof BaseProduct, pollingOptions: ValidatedPollingOptions, queueId: string, ): Promise> { @@ -231,7 +203,7 @@ export class Client { break; } if (pollResults.job.status === "Processed") { - return this.getResult(responseType, pollResults.job.id); + return this.getResult(product, pollResults.job.id); } await setTimeout( pollingOptions.delaySec * 1000, diff --git a/src/v2/client/classificationParameters.ts b/src/v2/client/classificationParameters.ts new file mode 100644 index 00000000..ace9b0b9 --- /dev/null +++ b/src/v2/client/classificationParameters.ts @@ -0,0 +1,28 @@ +import { BaseParameters, BaseParametersConstructor } from "@/v2/client/baseParameters.js"; +import { logger } from "@/logger.js"; + +/** + * Parameters accepted by the asynchronous **inference** v2 endpoint. + * + * All fields are optional except `modelId`. + * + * @category ClientV2 + * @example + * const params = { + * modelId: "YOUR_MODEL_ID", + * alias: "YOUR_ALIAS", + * webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"], + * pollingOptions: { + * initialDelaySec: 2, + * delaySec: 1.5, + * } + * }; + */ +export class ClassificationParameters extends BaseParameters { + slug = "utilities/crop"; + + constructor(params: BaseParametersConstructor & {}) { + super({ ...params }); + logger.debug("Classification parameters initialized."); + } +} diff --git a/src/v2/client/index.ts b/src/v2/client/index.ts index f2f75ee2..815840ae 100644 --- a/src/v2/client/index.ts +++ b/src/v2/client/index.ts @@ -1,5 +1,6 @@ export { DataSchema } from "./dataSchema.js"; export type { PollingOptions, ValidatedPollingOptions } from "./pollingOptions.js"; +export { ClassificationParameters } from "./classificationParameters.js"; export { ExtractionParameters } from "./extractionParameters.js"; export { BaseParameters } from "./baseParameters.js"; export { CropParameters } from "./cropParameters.js"; diff --git a/src/v2/http/mindeeApiV2.ts b/src/v2/http/mindeeApiV2.ts index 8014dd39..6e68be61 100644 --- a/src/v2/http/mindeeApiV2.ts +++ b/src/v2/http/mindeeApiV2.ts @@ -5,13 +5,8 @@ import { BaseResponse, ErrorResponse, ResponseConstructor, - InferenceResponseConstructor, JobResponse, - CropResponse, - OcrResponse, - SplitResponse, - ExtractionResponse, - BaseInference, ExtractionInference, + BaseInference, } from "@/v2/parsing/index.js"; import { sendRequestAndReadResponse, BaseHttpResponse } from "@/http/apiCore.js"; import { InputSource, LocalInputSource, UrlInput } from "@/input/index.js"; @@ -20,10 +15,8 @@ import { MindeeHttpErrorV2 } from "./errors.js"; import { logger } from "@/logger.js"; import { BaseInferenceResponse, - CropInference, - OcrInference, - SplitInference } from "@/v2/parsing/result/index.js"; +import { BaseProduct } from "@/v2/product/baseProduct.js"; export class MindeeApiV2 { @@ -33,40 +26,6 @@ export class MindeeApiV2 { this.settings = new ApiSettingsV2({ dispatcher: dispatcher, apiKey: apiKey }); } - #getSlugFromInference( - responseClass: InferenceResponseConstructor - ): string { - switch (responseClass as any) { - case CropInference: - return "utilities/crop"; - case OcrInference: - return "utilities/ocr"; - case SplitInference: - return "utilities/split"; - case ExtractionInference: - return "inferences"; - default: - throw new Error("Unsupported response class."); - } - } - - #getResponseClassFromInference( - inferenceClass: InferenceResponseConstructor - ): ResponseConstructor> { - switch (inferenceClass as any) { - case CropInference: - return CropResponse as any; - case OcrInference: - return OcrResponse as any; - case SplitInference: - return SplitResponse as any; - case ExtractionInference: - return ExtractionResponse as any; - default: - throw new Error("Unsupported inference class."); - } - } - /** * Sends a file to the extraction inference queue. * @param inputSource Local file loaded as an input. @@ -75,13 +34,14 @@ export class MindeeApiV2 { * @throws Error if the server's response contains one. * @returns a `Promise` containing a job response. */ - async reqPostInferenceEnqueue( + async reqPostProductEnqueue( + product: typeof BaseProduct, inputSource: InputSource, params: BaseParameters ): Promise { await inputSource.init(); - const result: BaseHttpResponse = await this.#inferenceEnqueuePost( - inputSource, params + const result: BaseHttpResponse = await this.#productEnqueuePost( + product, inputSource, params ); if (result.data.error !== undefined) { throw new MindeeHttpErrorV2(result.data.error); @@ -92,19 +52,19 @@ export class MindeeApiV2 { /** * Requests the job of a queued document from the API. * Throws an error if the server's response contains one. - * @param responseClass + * @param product * @param inferenceId The document's ID in the queue. * @category Asynchronous * @returns a `Promise` containing either the parsed result, or information on the queue. */ - async reqGetInference( - responseClass: InferenceResponseConstructor, + async reqGetResult( + product: typeof BaseProduct, inferenceId: string, ): Promise> { - const slug = this.#getSlugFromInference(responseClass); - const queueResponse: BaseHttpResponse = await this.#inferenceResultReqGet(inferenceId, slug); - const actualResponseClass = this.#getResponseClassFromInference(responseClass); - return this.#processResponse(queueResponse, actualResponseClass) as BaseInferenceResponse; + const queueResponse: BaseHttpResponse = await this.#inferenceResultReqGet( + inferenceId, product.getResultSlug + ); + return this.#processResponse(queueResponse, product.response) as BaseInferenceResponse; } /** @@ -152,7 +112,8 @@ export class MindeeApiV2 { * @param inputSource Local or remote file as an input. * @param params {ExtractionParameters} parameters relating to the enqueueing options. */ - async #inferenceEnqueuePost( + async #productEnqueuePost( + product: typeof BaseProduct, inputSource: InputSource, params: BaseParameters ): Promise { @@ -162,7 +123,7 @@ export class MindeeApiV2 { } else { form.set("url", (inputSource as UrlInput).url); } - const path = `/v2/${params.slug}/enqueue`; + const path = `/v2/${product.enqueueSlug}/enqueue`; const options = { method: "POST", headers: this.settings.baseHeaders, diff --git a/src/v2/product/baseProduct.ts b/src/v2/product/baseProduct.ts new file mode 100644 index 00000000..1ae2a68e --- /dev/null +++ b/src/v2/product/baseProduct.ts @@ -0,0 +1,19 @@ +import { BaseParameters } from "@/v2/client/index.js"; +import { ResponseConstructor } from "@/v2/parsing/index.js"; + +export abstract class BaseProduct { + static get parameters(): new (...args: any[]) => BaseParameters { + throw new Error("Must define static parameters property"); + } + static get response(): ResponseConstructor { + throw new Error("Must define static response property"); + } + + static get enqueueSlug(): string { + throw new Error("Must define static enqueueSlug property"); + } + + static get getResultSlug(): string { + throw new Error("Must define static getResultSlug property"); + } +} diff --git a/src/v2/product/classification.ts b/src/v2/product/classification.ts new file mode 100644 index 00000000..8eea6577 --- /dev/null +++ b/src/v2/product/classification.ts @@ -0,0 +1,18 @@ +import { ClassificationResponse } from "@/v2/parsing/index.js"; +import { ClassificationParameters } from "@/v2/client/index.js"; +import { BaseProduct } from "@/v2/product/baseProduct.js"; + +export class Classification extends BaseProduct { + static get parameters() { + return ClassificationParameters; + } + static get response() { + return ClassificationResponse; + } + static get enqueueSlug() { + return "utilities/classification"; + } + static get getResultSlug() { + return "utilities/classification"; + } +} diff --git a/src/v2/product/crop.ts b/src/v2/product/crop.ts new file mode 100644 index 00000000..f54c1b08 --- /dev/null +++ b/src/v2/product/crop.ts @@ -0,0 +1,18 @@ +import { CropResponse } from "@/v2/parsing/index.js"; +import { CropParameters } from "@/v2/client/index.js"; +import { BaseProduct } from "@/v2/product/baseProduct.js"; + +export class Crop extends BaseProduct { + static get parameters() { + return CropParameters; + } + static get response() { + return CropResponse; + } + static get enqueueSlug() { + return "utilities/crop"; + } + static get getResultSlug() { + return "utilities/crop"; + } +} diff --git a/src/v2/product/extraction.ts b/src/v2/product/extraction.ts new file mode 100644 index 00000000..83cca173 --- /dev/null +++ b/src/v2/product/extraction.ts @@ -0,0 +1,18 @@ +import { ExtractionResponse } from "@/v2/parsing/index.js"; +import { ExtractionParameters } from "@/v2/client/index.js"; +import { BaseProduct } from "@/v2/product/baseProduct.js"; + +export class Extraction extends BaseProduct { + static get parameters() { + return ExtractionParameters; + } + static get response() { + return ExtractionResponse; + } + static get enqueueSlug() { + return "inferences"; + } + static get getResultSlug() { + return "inferences"; + } +} diff --git a/src/v2/product/index.ts b/src/v2/product/index.ts new file mode 100644 index 00000000..888a41c8 --- /dev/null +++ b/src/v2/product/index.ts @@ -0,0 +1,5 @@ +export { Classification } from "./classification.js"; +export { Crop } from "./crop.js"; +export { Extraction } from "./extraction.js"; +export { Ocr } from "./ocr.js"; +export { Split } from "./split.js"; diff --git a/src/v2/product/ocr.ts b/src/v2/product/ocr.ts new file mode 100644 index 00000000..c7b5a481 --- /dev/null +++ b/src/v2/product/ocr.ts @@ -0,0 +1,18 @@ +import { OcrResponse } from "@/v2/parsing/index.js"; +import { OcrParameters } from "@/v2/client/index.js"; +import { BaseProduct } from "@/v2/product/baseProduct.js"; + +export class Ocr extends BaseProduct { + static get parameters() { + return OcrParameters; + } + static get response() { + return OcrResponse; + } + static get enqueueSlug() { + return "utilities/ocr"; + } + static get getResultSlug() { + return "utilities/ocr"; + } +} diff --git a/src/v2/product/split.ts b/src/v2/product/split.ts new file mode 100644 index 00000000..60db3223 --- /dev/null +++ b/src/v2/product/split.ts @@ -0,0 +1,18 @@ +import { SplitResponse } from "@/v2/parsing/index.js"; +import { SplitParameters } from "@/v2/client/index.js"; +import { BaseProduct } from "@/v2/product/baseProduct.js"; + +export class Split extends BaseProduct { + static get parameters() { + return SplitParameters; + } + static get response() { + return SplitResponse; + } + static get enqueueSlug() { + return "utilities/split"; + } + static get getResultSlug() { + return "utilities/split"; + } +} diff --git a/tests/v2/client.integration.ts b/tests/v2/client.integration.ts index 38d7700e..c367fb6a 100644 --- a/tests/v2/client.integration.ts +++ b/tests/v2/client.integration.ts @@ -14,6 +14,7 @@ import { SimpleField } from "@/v2/parsing/result/field/index.js"; import { MindeeHttpErrorV2 } from "@/v2/http/index.js"; import * as fs from "node:fs"; import { RESOURCE_PATH, V2_PRODUCT_PATH, V2_RESOURCE_PATH } from "../index.js"; +import { Extraction } from "@/v2/product/index.js"; function check422(err: unknown) { expect(err).to.be.instanceOf(MindeeHttpErrorV2); @@ -81,7 +82,7 @@ describe("MindeeV2 – Client Integration Tests", () => { alias: "ts_integration_empty_multiple" }; const response = await client.enqueueAndGetResult( - ExtractionInference, source, params + Extraction, source, params ); expect(response).to.exist; expect(response.inference).to.be.instanceOf(ExtractionInference); @@ -110,7 +111,7 @@ describe("MindeeV2 – Client Integration Tests", () => { }; const response = await client.enqueueAndGetResult( - ExtractionInference, source, params + Extraction, source, params ); expect(response.inference).to.be.instanceOf(ExtractionInference); const inference: ExtractionInference = response.inference; @@ -138,7 +139,7 @@ describe("MindeeV2 – Client Integration Tests", () => { it("Filled, single-page image – Base64Input - enqueueAndGetInference must succeed", async () => { const data = fs.readFileSync(sampleBase64Path, "utf8"); const source = new Base64Input({ inputString: data, filename: "receipt.jpg" }); - const params = new ExtractionParameters({ + const params = { modelId, rag: false, rawText: false, @@ -146,10 +147,10 @@ describe("MindeeV2 – Client Integration Tests", () => { confidence: false, webhookIds: [], alias: "ts_integration_base64_filled_single" - }); + }; const response = await client.enqueueAndGetResult( - ExtractionInference, source, params + Extraction, source, params ); expect(response.inference).to.be.instanceOf(ExtractionInference); const inference: ExtractionInference = response.inference; @@ -171,7 +172,7 @@ describe("MindeeV2 – Client Integration Tests", () => { const badParams = { modelId: "00000000-0000-0000-0000-000000000000" }; try { - await client.enqueue(ExtractionInference, source, badParams); + await client.enqueue(Extraction, source, badParams); expect.fail("Expected the call to throw, but it succeeded."); } catch (err) { check422(err); @@ -181,7 +182,7 @@ describe("MindeeV2 – Client Integration Tests", () => { it("Invalid job ID – getInference must raise 422", async () => { try { await client.getResult( - ExtractionInference, + Extraction, "00000000-0000-0000-0000-000000000000" ); expect.fail("Expected the call to throw, but it succeeded."); @@ -203,7 +204,7 @@ describe("MindeeV2 – Client Integration Tests", () => { alias: "ts_integration_url_source" }); const response: ExtractionResponse = await client.enqueueAndGetResult( - ExtractionInference, source, params + Extraction, source, params ); expect(response).to.exist; expect(response.inference).to.be.instanceOf(ExtractionInference); @@ -222,7 +223,7 @@ describe("MindeeV2 – Client Integration Tests", () => { alias: "ts_integration_data_schema_replace" }); const response = await client.enqueueAndGetResult( - ExtractionInference, source, params + Extraction, source, params ); expect(response).to.exist; expect(response.inference).to.be.instanceOf(ExtractionInference); diff --git a/tests/v2/client.spec.ts b/tests/v2/client.spec.ts index 5aa0cd75..31d7ca61 100644 --- a/tests/v2/client.spec.ts +++ b/tests/v2/client.spec.ts @@ -6,7 +6,7 @@ import { MindeeHttpErrorV2 } from "@/v2/http/index.js"; import assert from "node:assert/strict"; import { RESOURCE_PATH, V2_RESOURCE_PATH } from "../index.js"; import fs from "node:fs/promises"; -import { CropInference, ExtractionInference } from "@/v2/parsing/index.js"; +import { Crop, Extraction } from "@/v2/product/index.js"; const mockAgent = new MockAgent(); setGlobalDispatcher(mockAgent); @@ -74,7 +74,7 @@ describe("MindeeV2 - ClientV2", () => { const inputDoc = new PathInput({ inputPath: filePath }); await assert.rejects( - client.enqueue(ExtractionInference, inputDoc, { modelId: "dummy-model", textContext: "hello" }), + client.enqueue(Extraction, inputDoc, { modelId: "dummy-model", textContext: "hello" }), (error: any) => { assert.strictEqual(error instanceof MindeeHttpErrorV2, true); assert.strictEqual(error.status, 400); @@ -88,7 +88,7 @@ describe("MindeeV2 - ClientV2", () => { const inputDoc = new PathInput({ inputPath: filePath }); await assert.rejects( - client.enqueue(CropInference, inputDoc, { modelId: "dummy-model" }), + client.enqueue(Crop, inputDoc, { modelId: "dummy-model" }), (error: any) => { assert.strictEqual(error instanceof MindeeHttpErrorV2, true); assert.strictEqual(error.status, 400); @@ -102,7 +102,7 @@ describe("MindeeV2 - ClientV2", () => { const inputDoc = new PathInput({ inputPath: filePath }); await assert.rejects( client.enqueueAndGetResult( - ExtractionInference, + Extraction, inputDoc, { modelId: "dummy-model", rag: false } ), @@ -124,7 +124,7 @@ describe("MindeeV2 - ClientV2", () => { ), }); await assert.rejects( - client.enqueue(ExtractionInference, input, { modelId: "dummy-model" }), + client.enqueue(Extraction, input, { modelId: "dummy-model" }), (error: any) => { expect(error).to.be.instanceOf(MindeeHttpErrorV2); expect(error.status).to.equal(400); From 26dee1ecd590e1c5767ecf3bb96ce239c95dd58c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 6 Feb 2026 12:45:42 +0100 Subject: [PATCH 7/9] finalize methods --- docs/code_samples/v2_default.txt | 3 ++- src/v2/client.ts | 18 ++++++++---------- src/v2/http/mindeeApiV2.ts | 14 ++++++-------- src/v2/index.ts | 1 + 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/docs/code_samples/v2_default.txt b/docs/code_samples/v2_default.txt index e49f74a4..d7f41d0e 100644 --- a/docs/code_samples/v2_default.txt +++ b/docs/code_samples/v2_default.txt @@ -32,7 +32,8 @@ const extractionParams = { const inputSource = new mindee.PathInput({ inputPath: filePath }); // Send for processing -const response = mindeeClient.enqueueAndGetResult( +const response = mindeeClient.enqueueAndGetResult( + mindee.v2.product.Extraction, inputSource, extractionParams ); diff --git a/src/v2/client.ts b/src/v2/client.ts index 2654a7e4..07ae255c 100644 --- a/src/v2/client.ts +++ b/src/v2/client.ts @@ -7,8 +7,6 @@ import { LOG_LEVELS, logger } from "@/logger.js"; import { ErrorResponse, JobResponse, - BaseInference, - BaseInferenceResponse, } from "./parsing/index.js"; import { MindeeApiV2 } from "./http/mindeeApiV2.js"; import { MindeeHttpErrorV2 } from "./http/errors.js"; @@ -113,10 +111,10 @@ export class Client { * @category Asynchronous * @returns a `Promise` containing the inference. */ - async getResult( - product: typeof BaseProduct, + async getResult

( + product: P, inferenceId: string - ): Promise> { + ): Promise> { logger.debug( `Attempting to get inference with ID: ${inferenceId} using response type: ${product.name}` ); @@ -149,11 +147,11 @@ export class Client { * @category Synchronous * @returns a `Promise` containing parsing results. */ - async enqueueAndGetResult( - product: typeof BaseProduct, + async enqueueAndGetResult

( + product: P, inputSource: InputSource, params: EnqueueParameters - ): Promise> { + ): Promise> { const paramsInstance = new product.parameters(params); const pollingOptions = paramsInstance.getValidatedPollingOptions(); @@ -171,11 +169,11 @@ export class Client { * until the maximum number of tries is reached. * @protected */ - protected async pollForResult( + protected async pollForResult

( product: typeof BaseProduct, pollingOptions: ValidatedPollingOptions, queueId: string, - ): Promise> { + ): Promise> { logger.debug( `Waiting ${pollingOptions.initialDelaySec} seconds before polling.` ); diff --git a/src/v2/http/mindeeApiV2.ts b/src/v2/http/mindeeApiV2.ts index 6e68be61..b731a1fc 100644 --- a/src/v2/http/mindeeApiV2.ts +++ b/src/v2/http/mindeeApiV2.ts @@ -6,16 +6,12 @@ import { ErrorResponse, ResponseConstructor, JobResponse, - BaseInference, } from "@/v2/parsing/index.js"; import { sendRequestAndReadResponse, BaseHttpResponse } from "@/http/apiCore.js"; import { InputSource, LocalInputSource, UrlInput } from "@/input/index.js"; import { MindeeDeserializationError } from "@/errors/index.js"; import { MindeeHttpErrorV2 } from "./errors.js"; import { logger } from "@/logger.js"; -import { - BaseInferenceResponse, -} from "@/v2/parsing/result/index.js"; import { BaseProduct } from "@/v2/product/baseProduct.js"; @@ -28,6 +24,7 @@ export class MindeeApiV2 { /** * Sends a file to the extraction inference queue. + * @param product product to enqueue. * @param inputSource Local file loaded as an input. * @param params {ExtractionParameters} parameters relating to the enqueueing options. * @category V2 @@ -57,14 +54,14 @@ export class MindeeApiV2 { * @category Asynchronous * @returns a `Promise` containing either the parsed result, or information on the queue. */ - async reqGetResult( - product: typeof BaseProduct, + async reqGetResult

( + product: P, inferenceId: string, - ): Promise> { + ): Promise> { const queueResponse: BaseHttpResponse = await this.#inferenceResultReqGet( inferenceId, product.getResultSlug ); - return this.#processResponse(queueResponse, product.response) as BaseInferenceResponse; + return this.#processResponse(queueResponse, product.response) as InstanceType; } /** @@ -109,6 +106,7 @@ export class MindeeApiV2 { /** * Sends a document to the inference queue. * + * @param product Product to enqueue. * @param inputSource Local or remote file as an input. * @param params {ExtractionParameters} parameters relating to the enqueueing options. */ diff --git a/src/v2/index.ts b/src/v2/index.ts index b8bc8608..362a24b3 100644 --- a/src/v2/index.ts +++ b/src/v2/index.ts @@ -1,5 +1,6 @@ export * as http from "./http/index.js"; export * as parsing from "./parsing/index.js"; +export * as product from "./product/index.js"; export { LocalResponse } from "./parsing/localResponse.js"; export { Client } from "./client.js"; export { From ad1b2a5e26d0a861074fd63f9c5c023f65b363a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 6 Feb 2026 13:13:31 +0100 Subject: [PATCH 8/9] rework dir structure --- src/index.ts | 12 ------- src/v2/cli.ts | 2 +- src/v2/client.ts | 31 ++++------------- src/v2/client/baseParameters.ts | 2 -- src/v2/client/index.ts | 6 ---- src/v2/index.ts | 11 ------ src/v2/parsing/baseResponse.ts | 1 - src/v2/parsing/index.ts | 21 +++--------- .../{result => inference}/baseInference.ts | 2 +- .../{result => inference}/field/baseField.ts | 0 .../field/fieldConfidence.ts | 0 .../field/fieldFactory.ts | 0 .../field/fieldLocation.ts | 0 .../{result => inference}/field/index.ts | 0 .../field/inferenceFields.ts | 0 .../{result => inference}/field/listField.ts | 0 .../field/objectField.ts | 0 .../field/ragMetadata.ts | 0 .../{result => inference}/field/rawText.ts | 0 .../field/rawTextPage.ts | 0 .../field/simpleField.ts | 0 src/v2/parsing/inference/index.ts | 7 ++++ .../{result => inference}/inferenceFile.ts | 0 .../{result => inference}/inferenceModel.ts | 0 .../parsing/result/baseInferenceResponse.ts | 22 ------------ .../classification/classificationResponse.ts | 10 ------ src/v2/parsing/result/crop/cropResponse.ts | 10 ------ .../result/extraction/extractionResponse.ts | 10 ------ src/v2/parsing/result/index.ts | 34 ------------------- src/v2/parsing/result/ocr/ocrResponse.ts | 10 ------ src/v2/parsing/result/split/splitResponse.ts | 10 ------ .../{ => classification}/classification.ts | 4 +-- .../classification/classificationInference.ts | 2 +- .../classificationParameters.ts | 2 -- .../classification/classificationResponse.ts | 18 ++++++++++ src/v2/product/classification/index.ts | 4 +++ src/v2/product/{ => crop}/crop.ts | 4 +-- .../result => product}/crop/cropInference.ts | 4 +-- .../result => product}/crop/cropItem.ts | 2 +- .../crop}/cropParameters.ts | 2 -- src/v2/product/crop/cropResponse.ts | 18 ++++++++++ .../result => product}/crop/cropResult.ts | 2 +- src/v2/product/crop/index.ts | 6 ++++ .../extraction}/dataSchema.ts | 0 .../extraction/dataSchemaActiveOption.ts | 0 src/v2/product/{ => extraction}/extraction.ts | 4 +-- .../extraction/extractionActiveOptions.ts | 0 .../extraction/extractionInference.ts | 2 +- .../extraction}/extractionParameters.ts | 2 -- .../product/extraction/extractionResponse.ts | 19 +++++++++++ .../extraction/extractionResult.ts | 6 ++-- src/v2/product/extraction/index.ts | 8 +++++ src/v2/product/index.ts | 10 +++--- src/v2/product/ocr/index.ts | 4 +++ src/v2/product/{ => ocr}/ocr.ts | 4 +-- .../result => product}/ocr/ocrInference.ts | 2 +- .../{client => product/ocr}/ocrParameters.ts | 2 -- src/v2/product/ocr/ocrResponse.ts | 18 ++++++++++ src/v2/product/split/index.ts | 4 +++ src/v2/product/{ => split}/split.ts | 4 +-- .../split/splitInference.ts | 2 +- .../split}/splitParameters.ts | 7 ++-- src/v2/product/split/splitResponse.ts | 18 ++++++++++ tests/data | 2 +- tests/test_code_samples.sh | 2 +- tests/v2/client.integration.ts | 10 +++--- tests/v2/client/inferenceParameter.spec.ts | 3 +- tests/v2/parsing/inference.spec.ts | 4 +-- tests/v2/parsing/localResponse.spec.ts | 3 +- 69 files changed, 179 insertions(+), 230 deletions(-) rename src/v2/parsing/{result => inference}/baseInference.ts (88%) rename src/v2/parsing/{result => inference}/field/baseField.ts (100%) rename src/v2/parsing/{result => inference}/field/fieldConfidence.ts (100%) rename src/v2/parsing/{result => inference}/field/fieldFactory.ts (100%) rename src/v2/parsing/{result => inference}/field/fieldLocation.ts (100%) rename src/v2/parsing/{result => inference}/field/index.ts (100%) rename src/v2/parsing/{result => inference}/field/inferenceFields.ts (100%) rename src/v2/parsing/{result => inference}/field/listField.ts (100%) rename src/v2/parsing/{result => inference}/field/objectField.ts (100%) rename src/v2/parsing/{result => inference}/field/ragMetadata.ts (100%) rename src/v2/parsing/{result => inference}/field/rawText.ts (100%) rename src/v2/parsing/{result => inference}/field/rawTextPage.ts (100%) rename src/v2/parsing/{result => inference}/field/simpleField.ts (100%) create mode 100644 src/v2/parsing/inference/index.ts rename src/v2/parsing/{result => inference}/inferenceFile.ts (100%) rename src/v2/parsing/{result => inference}/inferenceModel.ts (100%) delete mode 100644 src/v2/parsing/result/baseInferenceResponse.ts delete mode 100644 src/v2/parsing/result/classification/classificationResponse.ts delete mode 100644 src/v2/parsing/result/crop/cropResponse.ts delete mode 100644 src/v2/parsing/result/extraction/extractionResponse.ts delete mode 100644 src/v2/parsing/result/index.ts delete mode 100644 src/v2/parsing/result/ocr/ocrResponse.ts delete mode 100644 src/v2/parsing/result/split/splitResponse.ts rename src/v2/product/{ => classification}/classification.ts (73%) rename src/v2/{parsing/result => product}/classification/classificationInference.ts (87%) rename src/v2/{client => product/classification}/classificationParameters.ts (96%) create mode 100644 src/v2/product/classification/classificationResponse.ts create mode 100644 src/v2/product/classification/index.ts rename src/v2/product/{ => crop}/crop.ts (75%) rename src/v2/{parsing/result => product}/crop/cropInference.ts (78%) rename src/v2/{parsing/result => product}/crop/cropItem.ts (83%) rename src/v2/{client => product/crop}/cropParameters.ts (96%) create mode 100644 src/v2/product/crop/cropResponse.ts rename src/v2/{parsing/result => product}/crop/cropResult.ts (87%) create mode 100644 src/v2/product/crop/index.ts rename src/v2/{client => product/extraction}/dataSchema.ts (100%) rename src/v2/{parsing/result => product}/extraction/dataSchemaActiveOption.ts (100%) rename src/v2/product/{ => extraction}/extraction.ts (73%) rename src/v2/{parsing/result => product}/extraction/extractionActiveOptions.ts (100%) rename src/v2/{parsing/result => product}/extraction/extractionInference.ts (92%) rename src/v2/{client => product/extraction}/extractionParameters.ts (99%) create mode 100644 src/v2/product/extraction/extractionResponse.ts rename src/v2/{parsing/result => product}/extraction/extractionResult.ts (76%) create mode 100644 src/v2/product/extraction/index.ts create mode 100644 src/v2/product/ocr/index.ts rename src/v2/product/{ => ocr}/ocr.ts (75%) rename src/v2/{parsing/result => product}/ocr/ocrInference.ts (86%) rename src/v2/{client => product/ocr}/ocrParameters.ts (96%) create mode 100644 src/v2/product/ocr/ocrResponse.ts create mode 100644 src/v2/product/split/index.ts rename src/v2/product/{ => split}/split.ts (75%) rename src/v2/{parsing/result => product}/split/splitInference.ts (86%) rename src/v2/{client => product/split}/splitParameters.ts (83%) create mode 100644 src/v2/product/split/splitResponse.ts diff --git a/src/index.ts b/src/index.ts index cbcf42fd..f39c7949 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,20 +18,8 @@ export * as v1 from "./v1/index.js"; export * as v2 from "./v2/index.js"; export { Client, - ExtractionParameters, - DataSchema, InferenceFile, InferenceModel, - ClassificationInference, - ClassificationResponse, - CropInference, - CropResponse, - ExtractionInference, - ExtractionResponse, - OcrInference, - OcrResponse, - SplitInference, - SplitResponse, JobResponse, ErrorResponse, } from "./v2/index.js"; diff --git a/src/v2/cli.ts b/src/v2/cli.ts index 14403896..c3c34c41 100644 --- a/src/v2/cli.ts +++ b/src/v2/cli.ts @@ -2,7 +2,7 @@ import { Command, OptionValues } from "commander"; import { Client } from "./client.js"; import { PathInput } from "../input/index.js"; import * as console from "console"; -import { BaseInference } from "@/v2/parsing/result/index.js"; +import { BaseInference } from "@/v2/parsing/inference/index.js"; import { BaseProduct } from "@/v2/product/baseProduct.js"; import { Classification, diff --git a/src/v2/client.ts b/src/v2/client.ts index 07ae255c..01accf0a 100644 --- a/src/v2/client.ts +++ b/src/v2/client.ts @@ -4,19 +4,10 @@ import { InputSource } from "@/input/index.js"; import { MindeeError } from "@/errors/index.js"; import { errorHandler } from "@/errors/handler.js"; import { LOG_LEVELS, logger } from "@/logger.js"; -import { - ErrorResponse, - JobResponse, -} from "./parsing/index.js"; +import { ErrorResponse, JobResponse } from "./parsing/index.js"; import { MindeeApiV2 } from "./http/mindeeApiV2.js"; import { MindeeHttpErrorV2 } from "./http/errors.js"; -import { - ExtractionParameters, - CropParameters, - OcrParameters, - SplitParameters, - ValidatedPollingOptions -} from "./client/index.js"; +import { ValidatedPollingOptions } from "./client/index.js"; import { BaseProduct } from "@/v2/product/baseProduct.js"; /** @@ -39,16 +30,6 @@ export interface ClientOptions { dispatcher?: Dispatcher; } -type EnqueueParameters = - | CropParameters - | ConstructorParameters[0] - | OcrParameters - | ConstructorParameters[0] - | SplitParameters - | ConstructorParameters[0] - | ExtractionParameters - | ConstructorParameters[0]; - /** * Mindee Client V2 class that centralizes most basic operations. * @@ -77,10 +58,10 @@ export class Client { logger.debug("Client V2 Initialized"); } - async enqueue( - product: typeof BaseProduct, + async enqueue

( + product: P, inputSource: InputSource, - params: EnqueueParameters, + params: InstanceType | ConstructorParameters[0], ): Promise { if (inputSource === undefined) { throw new MindeeError("An input document is required."); @@ -150,7 +131,7 @@ export class Client { async enqueueAndGetResult

( product: P, inputSource: InputSource, - params: EnqueueParameters + params: InstanceType | ConstructorParameters[0], ): Promise> { const paramsInstance = new product.parameters(params); diff --git a/src/v2/client/baseParameters.ts b/src/v2/client/baseParameters.ts index 41bfae00..e2f3263c 100644 --- a/src/v2/client/baseParameters.ts +++ b/src/v2/client/baseParameters.ts @@ -56,8 +56,6 @@ export abstract class BaseParameters { */ closeFile?: boolean; - abstract readonly slug: string; - protected constructor(params: BaseParametersConstructor) { if (params.modelId === undefined || params.modelId === null || params.modelId === "") { throw new MindeeConfigurationError("Model ID must be provided"); diff --git a/src/v2/client/index.ts b/src/v2/client/index.ts index 815840ae..a625efc0 100644 --- a/src/v2/client/index.ts +++ b/src/v2/client/index.ts @@ -1,8 +1,2 @@ -export { DataSchema } from "./dataSchema.js"; export type { PollingOptions, ValidatedPollingOptions } from "./pollingOptions.js"; -export { ClassificationParameters } from "./classificationParameters.js"; -export { ExtractionParameters } from "./extractionParameters.js"; export { BaseParameters } from "./baseParameters.js"; -export { CropParameters } from "./cropParameters.js"; -export { OcrParameters } from "./ocrParameters.js"; -export { SplitParameters } from "./splitParameters.js"; diff --git a/src/v2/index.ts b/src/v2/index.ts index 362a24b3..384491f1 100644 --- a/src/v2/index.ts +++ b/src/v2/index.ts @@ -6,18 +6,7 @@ export { Client } from "./client.js"; export { InferenceFile, InferenceModel, - ClassificationInference, - ClassificationResponse, - CropInference, - CropResponse, - ExtractionInference, - ExtractionResponse, - OcrInference, - OcrResponse, - SplitInference, - SplitResponse, JobResponse, ErrorResponse, } from "./parsing/index.js"; -export { ExtractionParameters, DataSchema } from "./client/index.js"; export type { PollingOptions } from "./client/index.js"; diff --git a/src/v2/parsing/baseResponse.ts b/src/v2/parsing/baseResponse.ts index b2068107..994e3a2f 100644 --- a/src/v2/parsing/baseResponse.ts +++ b/src/v2/parsing/baseResponse.ts @@ -1,7 +1,6 @@ import { StringDict } from "@/parsing/stringDict.js"; import { logger } from "@/logger.js"; - export abstract class BaseResponse { /** * Raw text representation of the API's response. diff --git a/src/v2/parsing/index.ts b/src/v2/parsing/index.ts index 6a55fc64..b5260f9a 100644 --- a/src/v2/parsing/index.ts +++ b/src/v2/parsing/index.ts @@ -10,23 +10,10 @@ export { } from "./job/index.js"; export { BaseInference, - BaseInferenceResponse, InferenceFile, InferenceModel, - ExtractionInference, - ExtractionActiveOptions, - ExtractionResponse, - ExtractionResult, - ClassificationResponse, - ClassificationInference, - CropResponse, - CropInference, - OcrResponse, - OcrInference, - SplitResponse, - SplitInference, -} from "./result/index.js"; +} from "./inference/index.js"; export { LocalResponse } from "./localResponse.js"; -export { RawText, RagMetadata } from "./result/field/index.js"; -export type { ResponseConstructor, BaseResponse } from "./baseResponse.js"; -export type { InferenceResponseConstructor } from "./result/index.js"; +export { BaseResponse } from "./baseResponse.js"; +export type { ResponseConstructor } from "./baseResponse.js"; +export { RawText, RagMetadata } from "./inference/field/index.js"; diff --git a/src/v2/parsing/result/baseInference.ts b/src/v2/parsing/inference/baseInference.ts similarity index 88% rename from src/v2/parsing/result/baseInference.ts rename to src/v2/parsing/inference/baseInference.ts index 76c3731f..6552a368 100644 --- a/src/v2/parsing/result/baseInference.ts +++ b/src/v2/parsing/inference/baseInference.ts @@ -1,4 +1,4 @@ -import { InferenceModel } from "@/v2/parsing/result/inferenceModel.js"; +import { InferenceModel } from "./inferenceModel.js"; import { InferenceFile } from "@/v2/index.js"; import { StringDict } from "@/parsing/index.js"; diff --git a/src/v2/parsing/result/field/baseField.ts b/src/v2/parsing/inference/field/baseField.ts similarity index 100% rename from src/v2/parsing/result/field/baseField.ts rename to src/v2/parsing/inference/field/baseField.ts diff --git a/src/v2/parsing/result/field/fieldConfidence.ts b/src/v2/parsing/inference/field/fieldConfidence.ts similarity index 100% rename from src/v2/parsing/result/field/fieldConfidence.ts rename to src/v2/parsing/inference/field/fieldConfidence.ts diff --git a/src/v2/parsing/result/field/fieldFactory.ts b/src/v2/parsing/inference/field/fieldFactory.ts similarity index 100% rename from src/v2/parsing/result/field/fieldFactory.ts rename to src/v2/parsing/inference/field/fieldFactory.ts diff --git a/src/v2/parsing/result/field/fieldLocation.ts b/src/v2/parsing/inference/field/fieldLocation.ts similarity index 100% rename from src/v2/parsing/result/field/fieldLocation.ts rename to src/v2/parsing/inference/field/fieldLocation.ts diff --git a/src/v2/parsing/result/field/index.ts b/src/v2/parsing/inference/field/index.ts similarity index 100% rename from src/v2/parsing/result/field/index.ts rename to src/v2/parsing/inference/field/index.ts diff --git a/src/v2/parsing/result/field/inferenceFields.ts b/src/v2/parsing/inference/field/inferenceFields.ts similarity index 100% rename from src/v2/parsing/result/field/inferenceFields.ts rename to src/v2/parsing/inference/field/inferenceFields.ts diff --git a/src/v2/parsing/result/field/listField.ts b/src/v2/parsing/inference/field/listField.ts similarity index 100% rename from src/v2/parsing/result/field/listField.ts rename to src/v2/parsing/inference/field/listField.ts diff --git a/src/v2/parsing/result/field/objectField.ts b/src/v2/parsing/inference/field/objectField.ts similarity index 100% rename from src/v2/parsing/result/field/objectField.ts rename to src/v2/parsing/inference/field/objectField.ts diff --git a/src/v2/parsing/result/field/ragMetadata.ts b/src/v2/parsing/inference/field/ragMetadata.ts similarity index 100% rename from src/v2/parsing/result/field/ragMetadata.ts rename to src/v2/parsing/inference/field/ragMetadata.ts diff --git a/src/v2/parsing/result/field/rawText.ts b/src/v2/parsing/inference/field/rawText.ts similarity index 100% rename from src/v2/parsing/result/field/rawText.ts rename to src/v2/parsing/inference/field/rawText.ts diff --git a/src/v2/parsing/result/field/rawTextPage.ts b/src/v2/parsing/inference/field/rawTextPage.ts similarity index 100% rename from src/v2/parsing/result/field/rawTextPage.ts rename to src/v2/parsing/inference/field/rawTextPage.ts diff --git a/src/v2/parsing/result/field/simpleField.ts b/src/v2/parsing/inference/field/simpleField.ts similarity index 100% rename from src/v2/parsing/result/field/simpleField.ts rename to src/v2/parsing/inference/field/simpleField.ts diff --git a/src/v2/parsing/inference/index.ts b/src/v2/parsing/inference/index.ts new file mode 100644 index 00000000..df0e9b36 --- /dev/null +++ b/src/v2/parsing/inference/index.ts @@ -0,0 +1,7 @@ +// Inference +export { InferenceFile } from "./inferenceFile.js"; +export { InferenceModel } from "./inferenceModel.js"; +export { BaseInference } from "./baseInference.js"; + +// Fields +export * as field from "./field/index.js"; diff --git a/src/v2/parsing/result/inferenceFile.ts b/src/v2/parsing/inference/inferenceFile.ts similarity index 100% rename from src/v2/parsing/result/inferenceFile.ts rename to src/v2/parsing/inference/inferenceFile.ts diff --git a/src/v2/parsing/result/inferenceModel.ts b/src/v2/parsing/inference/inferenceModel.ts similarity index 100% rename from src/v2/parsing/result/inferenceModel.ts rename to src/v2/parsing/inference/inferenceModel.ts diff --git a/src/v2/parsing/result/baseInferenceResponse.ts b/src/v2/parsing/result/baseInferenceResponse.ts deleted file mode 100644 index 766fdd2c..00000000 --- a/src/v2/parsing/result/baseInferenceResponse.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { StringDict } from "@/parsing/stringDict.js"; -import { BaseResponse } from "@/v2/parsing/baseResponse.js"; -import { BaseInference } from "./baseInference.js"; - -export abstract class BaseInferenceResponse extends BaseResponse { - /** - * The inference result of the request. - */ - public inference: T; - - /** - * @param serverResponse JSON response from the server. - */ - constructor(serverResponse: StringDict) { - super(serverResponse); - this.inference = this.setInferenceType(serverResponse["inference"]); - } - - public abstract setInferenceType(inferenceResponse: StringDict): T; -} - -export type InferenceResponseConstructor = new (serverResponse: StringDict) => T; diff --git a/src/v2/parsing/result/classification/classificationResponse.ts b/src/v2/parsing/result/classification/classificationResponse.ts deleted file mode 100644 index 2e370ab0..00000000 --- a/src/v2/parsing/result/classification/classificationResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { StringDict } from "@/parsing/stringDict.js"; -import { BaseInferenceResponse } from "@/v2/parsing/result/index.js"; -import { ClassificationInference } from "./classificationInference.js"; - -export class ClassificationResponse extends BaseInferenceResponse { - - setInferenceType(inferenceResponse: StringDict): ClassificationInference { - return new ClassificationInference(inferenceResponse); - } -} diff --git a/src/v2/parsing/result/crop/cropResponse.ts b/src/v2/parsing/result/crop/cropResponse.ts deleted file mode 100644 index 31a6ca34..00000000 --- a/src/v2/parsing/result/crop/cropResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { StringDict } from "@/parsing/stringDict.js"; -import { CropInference } from "./cropInference.js"; -import { BaseInferenceResponse } from "@/v2/parsing/result/baseInferenceResponse.js"; - -export class CropResponse extends BaseInferenceResponse { - - setInferenceType(inferenceResponse: StringDict): CropInference { - return new CropInference(inferenceResponse); - } -} diff --git a/src/v2/parsing/result/extraction/extractionResponse.ts b/src/v2/parsing/result/extraction/extractionResponse.ts deleted file mode 100644 index 12c38ac6..00000000 --- a/src/v2/parsing/result/extraction/extractionResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ExtractionInference } from "./extractionInference.js"; -import { StringDict } from "@/parsing/stringDict.js"; -import { BaseInferenceResponse } from "@/v2/parsing/result/baseInferenceResponse.js"; - -export class ExtractionResponse extends BaseInferenceResponse { - - setInferenceType(inferenceResponse: StringDict): ExtractionInference { - return new ExtractionInference(inferenceResponse); - } -} diff --git a/src/v2/parsing/result/index.ts b/src/v2/parsing/result/index.ts deleted file mode 100644 index ee712816..00000000 --- a/src/v2/parsing/result/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Inference -export { InferenceFile } from "./inferenceFile.js"; -export { InferenceModel } from "./inferenceModel.js"; -export { BaseInference } from "./baseInference.js"; -export { BaseInferenceResponse } from "./baseInferenceResponse.js"; -export type { InferenceResponseConstructor } from "./baseInferenceResponse.js"; - -// Fields -export * as field from "./field/index.js"; - -// Extraction -export { ExtractionInference } from "./extraction/extractionInference.js"; -export { ExtractionActiveOptions } from "./extraction/extractionActiveOptions.js"; -export { ExtractionResponse } from "./extraction/extractionResponse.js"; -export { ExtractionResult } from "./extraction/extractionResult.js"; - -// Classification -export { ClassificationResponse } from "./classification/classificationResponse.js"; -export { ClassificationInference } from "./classification/classificationInference.js"; - -// Crop -export { CropInference } from "./crop/cropInference.js"; -export { CropItem } from "./crop/cropItem.js"; -export { CropResponse } from "./crop/cropResponse.js"; -export { CropResult } from "./crop/cropResult.js"; - -// OCR -export { OcrResponse } from "./ocr/ocrResponse.js"; -export { OcrInference } from "./ocr/ocrInference.js"; - -// Split -export { SplitResponse } from "./split/splitResponse.js"; -export { SplitInference } from "./split/splitInference.js"; - diff --git a/src/v2/parsing/result/ocr/ocrResponse.ts b/src/v2/parsing/result/ocr/ocrResponse.ts deleted file mode 100644 index c3b627e5..00000000 --- a/src/v2/parsing/result/ocr/ocrResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { StringDict } from "@/parsing/stringDict.js"; -import { BaseInferenceResponse } from "@/v2/parsing/result/baseInferenceResponse.js"; -import { OcrInference } from "./ocrInference.js"; - -export class OcrResponse extends BaseInferenceResponse { - - setInferenceType(inferenceResponse: StringDict): OcrInference { - return new OcrInference(inferenceResponse); - } -} diff --git a/src/v2/parsing/result/split/splitResponse.ts b/src/v2/parsing/result/split/splitResponse.ts deleted file mode 100644 index b84d1522..00000000 --- a/src/v2/parsing/result/split/splitResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { StringDict } from "@/parsing/stringDict.js"; -import { BaseInferenceResponse } from "@/v2/parsing/result/baseInferenceResponse.js"; -import { SplitInference } from "./splitInference.js"; - -export class SplitResponse extends BaseInferenceResponse { - - setInferenceType(inferenceResponse: StringDict): SplitInference { - return new SplitInference(inferenceResponse); - } -} diff --git a/src/v2/product/classification.ts b/src/v2/product/classification/classification.ts similarity index 73% rename from src/v2/product/classification.ts rename to src/v2/product/classification/classification.ts index 8eea6577..65f8c85b 100644 --- a/src/v2/product/classification.ts +++ b/src/v2/product/classification/classification.ts @@ -1,5 +1,5 @@ -import { ClassificationResponse } from "@/v2/parsing/index.js"; -import { ClassificationParameters } from "@/v2/client/index.js"; +import { ClassificationResponse } from "./classificationResponse.js"; +import { ClassificationParameters } from "./classificationParameters.js"; import { BaseProduct } from "@/v2/product/baseProduct.js"; export class Classification extends BaseProduct { diff --git a/src/v2/parsing/result/classification/classificationInference.ts b/src/v2/product/classification/classificationInference.ts similarity index 87% rename from src/v2/parsing/result/classification/classificationInference.ts rename to src/v2/product/classification/classificationInference.ts index 4ac7b754..916c71dd 100644 --- a/src/v2/parsing/result/classification/classificationInference.ts +++ b/src/v2/product/classification/classificationInference.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/index.js"; -import { BaseInference } from "@/v2/parsing/result/baseInference.js"; +import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; export class ClassificationInference extends BaseInference { /** diff --git a/src/v2/client/classificationParameters.ts b/src/v2/product/classification/classificationParameters.ts similarity index 96% rename from src/v2/client/classificationParameters.ts rename to src/v2/product/classification/classificationParameters.ts index ace9b0b9..41021cc3 100644 --- a/src/v2/client/classificationParameters.ts +++ b/src/v2/product/classification/classificationParameters.ts @@ -19,8 +19,6 @@ import { logger } from "@/logger.js"; * }; */ export class ClassificationParameters extends BaseParameters { - slug = "utilities/crop"; - constructor(params: BaseParametersConstructor & {}) { super({ ...params }); logger.debug("Classification parameters initialized."); diff --git a/src/v2/product/classification/classificationResponse.ts b/src/v2/product/classification/classificationResponse.ts new file mode 100644 index 00000000..f1195ea2 --- /dev/null +++ b/src/v2/product/classification/classificationResponse.ts @@ -0,0 +1,18 @@ +import { StringDict } from "@/parsing/stringDict.js"; +import { ClassificationInference } from "./classificationInference.js"; +import { BaseResponse } from "@/v2/parsing/index.js"; + +export class ClassificationResponse extends BaseResponse { + /** + * The inference result for a classification utility request. + */ + inference: ClassificationInference; + + /** + * @param serverResponse JSON response from the server. + */ + constructor(serverResponse: StringDict) { + super(serverResponse); + this.inference = new ClassificationInference(serverResponse["inference"]); + } +} diff --git a/src/v2/product/classification/index.ts b/src/v2/product/classification/index.ts new file mode 100644 index 00000000..5c34b115 --- /dev/null +++ b/src/v2/product/classification/index.ts @@ -0,0 +1,4 @@ +export { Classification } from "./classification.js"; +export { ClassificationParameters } from "./classificationParameters.js"; +export { ClassificationResponse } from "./classificationResponse.js"; +export { ClassificationInference } from "./classificationInference.js"; diff --git a/src/v2/product/crop.ts b/src/v2/product/crop/crop.ts similarity index 75% rename from src/v2/product/crop.ts rename to src/v2/product/crop/crop.ts index f54c1b08..63f8a5d6 100644 --- a/src/v2/product/crop.ts +++ b/src/v2/product/crop/crop.ts @@ -1,5 +1,5 @@ -import { CropResponse } from "@/v2/parsing/index.js"; -import { CropParameters } from "@/v2/client/index.js"; +import { CropResponse } from "./cropResponse.js"; +import { CropParameters } from "./cropParameters.js"; import { BaseProduct } from "@/v2/product/baseProduct.js"; export class Crop extends BaseProduct { diff --git a/src/v2/parsing/result/crop/cropInference.ts b/src/v2/product/crop/cropInference.ts similarity index 78% rename from src/v2/parsing/result/crop/cropInference.ts rename to src/v2/product/crop/cropInference.ts index a0ba38ac..6b35c269 100644 --- a/src/v2/parsing/result/crop/cropInference.ts +++ b/src/v2/product/crop/cropInference.ts @@ -1,6 +1,6 @@ import { StringDict } from "@/parsing/index.js"; -import { BaseInference } from "@/v2/parsing/result/baseInference.js"; -import { CropResult } from "@/v2/parsing/result/crop/cropResult.js"; +import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; +import { CropResult } from "@/v2/product/crop/cropResult.js"; export class CropInference extends BaseInference { /** diff --git a/src/v2/parsing/result/crop/cropItem.ts b/src/v2/product/crop/cropItem.ts similarity index 83% rename from src/v2/parsing/result/crop/cropItem.ts rename to src/v2/product/crop/cropItem.ts index ab0d921e..470042b0 100644 --- a/src/v2/parsing/result/crop/cropItem.ts +++ b/src/v2/product/crop/cropItem.ts @@ -1,4 +1,4 @@ -import { FieldLocation } from "@/v2/parsing/result/field/index.js"; +import { FieldLocation } from "@/v2/parsing/inference/field/index.js"; import { StringDict } from "@/parsing/index.js"; export class CropItem { diff --git a/src/v2/client/cropParameters.ts b/src/v2/product/crop/cropParameters.ts similarity index 96% rename from src/v2/client/cropParameters.ts rename to src/v2/product/crop/cropParameters.ts index 740b8c26..ba53eb1f 100644 --- a/src/v2/client/cropParameters.ts +++ b/src/v2/product/crop/cropParameters.ts @@ -19,8 +19,6 @@ import { logger } from "@/logger.js"; * }; */ export class CropParameters extends BaseParameters { - slug = "utilities/crop"; - constructor(params: BaseParametersConstructor & {}) { super({ ...params }); logger.debug("Crop parameters initialized."); diff --git a/src/v2/product/crop/cropResponse.ts b/src/v2/product/crop/cropResponse.ts new file mode 100644 index 00000000..c50b2518 --- /dev/null +++ b/src/v2/product/crop/cropResponse.ts @@ -0,0 +1,18 @@ +import { StringDict } from "@/parsing/stringDict.js"; +import { CropInference } from "./cropInference.js"; +import { BaseResponse } from "@/v2/parsing/index.js"; + +export class CropResponse extends BaseResponse { + /** + * Response for a crop utility inference. + */ + inference: CropInference; + + /** + * @param serverResponse JSON response from the server. + */ + constructor(serverResponse: StringDict) { + super(serverResponse); + this.inference = new CropInference(serverResponse["inference"]); + } +} diff --git a/src/v2/parsing/result/crop/cropResult.ts b/src/v2/product/crop/cropResult.ts similarity index 87% rename from src/v2/parsing/result/crop/cropResult.ts rename to src/v2/product/crop/cropResult.ts index fef55ca8..e15dc527 100644 --- a/src/v2/parsing/result/crop/cropResult.ts +++ b/src/v2/product/crop/cropResult.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/stringDict.js"; -import { CropItem } from "@/v2/parsing/result/crop/cropItem.js"; +import { CropItem } from "@/v2/product/crop/cropItem.js"; export class CropResult { /** diff --git a/src/v2/product/crop/index.ts b/src/v2/product/crop/index.ts new file mode 100644 index 00000000..7d3b2527 --- /dev/null +++ b/src/v2/product/crop/index.ts @@ -0,0 +1,6 @@ +export { Crop } from "./crop.js"; +export { CropParameters } from "./cropParameters.js"; +export { CropInference } from "./cropInference.js"; +export { CropItem } from "./cropItem.js"; +export { CropResponse } from "./cropResponse.js"; +export { CropResult } from "./cropResult.js"; diff --git a/src/v2/client/dataSchema.ts b/src/v2/product/extraction/dataSchema.ts similarity index 100% rename from src/v2/client/dataSchema.ts rename to src/v2/product/extraction/dataSchema.ts diff --git a/src/v2/parsing/result/extraction/dataSchemaActiveOption.ts b/src/v2/product/extraction/dataSchemaActiveOption.ts similarity index 100% rename from src/v2/parsing/result/extraction/dataSchemaActiveOption.ts rename to src/v2/product/extraction/dataSchemaActiveOption.ts diff --git a/src/v2/product/extraction.ts b/src/v2/product/extraction/extraction.ts similarity index 73% rename from src/v2/product/extraction.ts rename to src/v2/product/extraction/extraction.ts index 83cca173..39ca3992 100644 --- a/src/v2/product/extraction.ts +++ b/src/v2/product/extraction/extraction.ts @@ -1,5 +1,5 @@ -import { ExtractionResponse } from "@/v2/parsing/index.js"; -import { ExtractionParameters } from "@/v2/client/index.js"; +import { ExtractionResponse } from "./extractionResponse.js"; +import { ExtractionParameters } from "./extractionParameters.js"; import { BaseProduct } from "@/v2/product/baseProduct.js"; export class Extraction extends BaseProduct { diff --git a/src/v2/parsing/result/extraction/extractionActiveOptions.ts b/src/v2/product/extraction/extractionActiveOptions.ts similarity index 100% rename from src/v2/parsing/result/extraction/extractionActiveOptions.ts rename to src/v2/product/extraction/extractionActiveOptions.ts diff --git a/src/v2/parsing/result/extraction/extractionInference.ts b/src/v2/product/extraction/extractionInference.ts similarity index 92% rename from src/v2/parsing/result/extraction/extractionInference.ts rename to src/v2/product/extraction/extractionInference.ts index 91d77f2d..7db6d240 100644 --- a/src/v2/parsing/result/extraction/extractionInference.ts +++ b/src/v2/product/extraction/extractionInference.ts @@ -1,7 +1,7 @@ import { StringDict } from "@/parsing/stringDict.js"; import { ExtractionResult } from "./extractionResult.js"; import { ExtractionActiveOptions } from "./extractionActiveOptions.js"; -import { BaseInference } from "@/v2/parsing/result/baseInference.js"; +import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; export class ExtractionInference extends BaseInference { /** diff --git a/src/v2/client/extractionParameters.ts b/src/v2/product/extraction/extractionParameters.ts similarity index 99% rename from src/v2/client/extractionParameters.ts rename to src/v2/product/extraction/extractionParameters.ts index 0578242c..fe3b8f1c 100644 --- a/src/v2/client/extractionParameters.ts +++ b/src/v2/product/extraction/extractionParameters.ts @@ -22,8 +22,6 @@ import { logger } from "@/logger.js"; * }; */ export class ExtractionParameters extends BaseParameters { - slug = "inferences"; - /** * Use Retrieval-Augmented Generation during inference. */ diff --git a/src/v2/product/extraction/extractionResponse.ts b/src/v2/product/extraction/extractionResponse.ts new file mode 100644 index 00000000..8a568f30 --- /dev/null +++ b/src/v2/product/extraction/extractionResponse.ts @@ -0,0 +1,19 @@ +import { ExtractionInference } from "./extractionInference.js"; +import { StringDict } from "@/parsing/stringDict.js"; +import { BaseResponse } from "@/v2/parsing/index.js"; + +export class ExtractionResponse extends BaseResponse { + + /** + * The inference result for an extraction request. + */ + inference: ExtractionInference; + + /** + * @param serverResponse JSON response from the server. + */ + constructor(serverResponse: StringDict) { + super(serverResponse); + this.inference = new ExtractionInference(serverResponse["inference"]); + } +} diff --git a/src/v2/parsing/result/extraction/extractionResult.ts b/src/v2/product/extraction/extractionResult.ts similarity index 76% rename from src/v2/parsing/result/extraction/extractionResult.ts rename to src/v2/product/extraction/extractionResult.ts index 4e1ebbb0..8e3ce1b0 100644 --- a/src/v2/parsing/result/extraction/extractionResult.ts +++ b/src/v2/product/extraction/extractionResult.ts @@ -1,7 +1,7 @@ -import { InferenceFields } from "@/v2/parsing/result/field/index.js"; +import { InferenceFields } from "@/v2/parsing/inference/field/index.js"; import { StringDict } from "@/parsing/stringDict.js"; -import { RawText } from "../field/rawText.js"; -import { RagMetadata } from "../field/ragMetadata.js"; +import { RawText } from "@/v2/parsing/inference/field/rawText.js"; +import { RagMetadata } from "@/v2/parsing/inference/field/ragMetadata.js"; export class ExtractionResult { /** diff --git a/src/v2/product/extraction/index.ts b/src/v2/product/extraction/index.ts new file mode 100644 index 00000000..d6cb61bd --- /dev/null +++ b/src/v2/product/extraction/index.ts @@ -0,0 +1,8 @@ +export { Extraction } from "./extraction.js"; +export { ExtractionParameters } from "./extractionParameters.js"; +export { DataSchema } from "./dataSchema.js"; +export { ExtractionInference } from "./extractionInference.js"; +export { ExtractionActiveOptions } from "./extractionActiveOptions.js"; +export { ExtractionResponse } from "./extractionResponse.js"; +export { ExtractionResult } from "./extractionResult.js"; +export { DataSchemaActiveOption } from "./dataSchemaActiveOption.js"; diff --git a/src/v2/product/index.ts b/src/v2/product/index.ts index 888a41c8..5fc60b74 100644 --- a/src/v2/product/index.ts +++ b/src/v2/product/index.ts @@ -1,5 +1,5 @@ -export { Classification } from "./classification.js"; -export { Crop } from "./crop.js"; -export { Extraction } from "./extraction.js"; -export { Ocr } from "./ocr.js"; -export { Split } from "./split.js"; +export { Classification } from "./classification/index.js"; +export { Crop } from "./crop/index.js"; +export { Extraction, ExtractionResponse } from "./extraction/index.js"; +export { Ocr } from "./ocr/index.js"; +export { Split } from "./split/index.js"; diff --git a/src/v2/product/ocr/index.ts b/src/v2/product/ocr/index.ts new file mode 100644 index 00000000..78caefa2 --- /dev/null +++ b/src/v2/product/ocr/index.ts @@ -0,0 +1,4 @@ +export { Ocr } from "./ocr.js"; +export { OcrParameters } from "./ocrParameters.js"; +export { OcrResponse } from "./ocrResponse.js"; +export { OcrInference } from "./ocrInference.js"; diff --git a/src/v2/product/ocr.ts b/src/v2/product/ocr/ocr.ts similarity index 75% rename from src/v2/product/ocr.ts rename to src/v2/product/ocr/ocr.ts index c7b5a481..e82945cd 100644 --- a/src/v2/product/ocr.ts +++ b/src/v2/product/ocr/ocr.ts @@ -1,5 +1,5 @@ -import { OcrResponse } from "@/v2/parsing/index.js"; -import { OcrParameters } from "@/v2/client/index.js"; +import { OcrResponse } from "./ocrResponse.js"; +import { OcrParameters } from "./ocrParameters.js"; import { BaseProduct } from "@/v2/product/baseProduct.js"; export class Ocr extends BaseProduct { diff --git a/src/v2/parsing/result/ocr/ocrInference.ts b/src/v2/product/ocr/ocrInference.ts similarity index 86% rename from src/v2/parsing/result/ocr/ocrInference.ts rename to src/v2/product/ocr/ocrInference.ts index 2af66d3a..c767fccf 100644 --- a/src/v2/parsing/result/ocr/ocrInference.ts +++ b/src/v2/product/ocr/ocrInference.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/index.js"; -import { BaseInference } from "@/v2/parsing/result/baseInference.js"; +import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; export class OcrInference extends BaseInference { /** diff --git a/src/v2/client/ocrParameters.ts b/src/v2/product/ocr/ocrParameters.ts similarity index 96% rename from src/v2/client/ocrParameters.ts rename to src/v2/product/ocr/ocrParameters.ts index 20ecf6dd..8a17ac48 100644 --- a/src/v2/client/ocrParameters.ts +++ b/src/v2/product/ocr/ocrParameters.ts @@ -19,8 +19,6 @@ import { logger } from "@/logger.js"; * }; */ export class OcrParameters extends BaseParameters { - slug = "utilities/ocr"; - constructor(params: BaseParametersConstructor & {}) { super({ ...params }); logger.debug("Ocr parameters initialized."); diff --git a/src/v2/product/ocr/ocrResponse.ts b/src/v2/product/ocr/ocrResponse.ts new file mode 100644 index 00000000..2e6ddb3d --- /dev/null +++ b/src/v2/product/ocr/ocrResponse.ts @@ -0,0 +1,18 @@ +import { StringDict } from "@/parsing/stringDict.js"; +import { OcrInference } from "./ocrInference.js"; +import { BaseResponse } from "@/v2/parsing/index.js"; + +export class OcrResponse extends BaseResponse { + /** + * Response for an OCR utility inference. + */ + inference: OcrInference; + + /** + * @param serverResponse JSON response from the server. + */ + constructor(serverResponse: StringDict) { + super(serverResponse); + this.inference = new OcrInference(serverResponse["inference"]); + } +} diff --git a/src/v2/product/split/index.ts b/src/v2/product/split/index.ts new file mode 100644 index 00000000..10477bb7 --- /dev/null +++ b/src/v2/product/split/index.ts @@ -0,0 +1,4 @@ +export { Split } from "./split.js"; +export { SplitParameters } from "./splitParameters.js"; +export { SplitResponse } from "./splitResponse.js"; +export { SplitInference } from "./splitInference.js"; diff --git a/src/v2/product/split.ts b/src/v2/product/split/split.ts similarity index 75% rename from src/v2/product/split.ts rename to src/v2/product/split/split.ts index 60db3223..9b5a47c5 100644 --- a/src/v2/product/split.ts +++ b/src/v2/product/split/split.ts @@ -1,5 +1,5 @@ -import { SplitResponse } from "@/v2/parsing/index.js"; -import { SplitParameters } from "@/v2/client/index.js"; +import { SplitResponse } from "./splitResponse.js"; +import { SplitParameters } from "./splitParameters.js"; import { BaseProduct } from "@/v2/product/baseProduct.js"; export class Split extends BaseProduct { diff --git a/src/v2/parsing/result/split/splitInference.ts b/src/v2/product/split/splitInference.ts similarity index 86% rename from src/v2/parsing/result/split/splitInference.ts rename to src/v2/product/split/splitInference.ts index 1ba8e513..a195a9b9 100644 --- a/src/v2/parsing/result/split/splitInference.ts +++ b/src/v2/product/split/splitInference.ts @@ -1,5 +1,5 @@ import { StringDict } from "@/parsing/index.js"; -import { BaseInference } from "@/v2/parsing/result/baseInference.js"; +import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; export class SplitInference extends BaseInference { /** diff --git a/src/v2/client/splitParameters.ts b/src/v2/product/split/splitParameters.ts similarity index 83% rename from src/v2/client/splitParameters.ts rename to src/v2/product/split/splitParameters.ts index 137d3659..71cc146e 100644 --- a/src/v2/client/splitParameters.ts +++ b/src/v2/product/split/splitParameters.ts @@ -1,4 +1,7 @@ -import { BaseParameters, BaseParametersConstructor } from "@/v2/client/baseParameters.js"; +import { + BaseParameters, + BaseParametersConstructor, +} from "@/v2/client/baseParameters.js"; import { logger } from "@/logger.js"; /** @@ -19,8 +22,6 @@ import { logger } from "@/logger.js"; * }; */ export class SplitParameters extends BaseParameters { - slug = "utilities/split"; - constructor(params: BaseParametersConstructor & {}) { super({ ...params }); logger.debug("Split parameters initialized."); diff --git a/src/v2/product/split/splitResponse.ts b/src/v2/product/split/splitResponse.ts new file mode 100644 index 00000000..891cb30d --- /dev/null +++ b/src/v2/product/split/splitResponse.ts @@ -0,0 +1,18 @@ +import { StringDict } from "@/parsing/stringDict.js"; +import { SplitInference } from "./splitInference.js"; +import { BaseResponse } from "@/v2/parsing/index.js"; + +export class SplitResponse extends BaseResponse { + /** + * Response for an OCR utility inference. + */ + inference: SplitInference; + + /** + * @param serverResponse JSON response from the server. + */ + constructor(serverResponse: StringDict) { + super(serverResponse); + this.inference = new SplitInference(serverResponse["inference"]); + } +} diff --git a/tests/data b/tests/data index 7d470a0c..67ccc1d9 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 7d470a0c49c1b7cc7b635ae63d3ffea81ef6f323 +Subproject commit 67ccc1d9cf8b6263860f79eafbaa2e8b8dd7ac3f diff --git a/tests/test_code_samples.sh b/tests/test_code_samples.sh index a3529d7a..69528399 100755 --- a/tests/test_code_samples.sh +++ b/tests/test_code_samples.sh @@ -33,7 +33,7 @@ do sed "s/my-api-key/$API_KEY/" "${f}" > $OUTPUT_FILE sed -i "s/\/path\/to\/the\/file.ext/..\/mindee-api-nodejs\/tests\/data\/file_types\/pdf\/blank_1.pdf/" $OUTPUT_FILE - if echo "${f}" | grep -q "default_v2.txt" + if echo "${f}" | grep -q "v2_default.txt" then sed -i "s/MY_API_KEY/$API_KEY_V2/" $OUTPUT_FILE sed -i "s/MY_MODEL_ID/$MODEL_ID/" $OUTPUT_FILE diff --git a/tests/v2/client.integration.ts b/tests/v2/client.integration.ts index c367fb6a..bc760d42 100644 --- a/tests/v2/client.integration.ts +++ b/tests/v2/client.integration.ts @@ -3,14 +3,16 @@ import path from "node:path"; import { Client, - ExtractionParameters, PathInput, UrlInput, Base64Input, - ExtractionResponse, } from "@/index.js"; -import { ExtractionInference } from "@/v2/parsing/index.js"; -import { SimpleField } from "@/v2/parsing/result/field/index.js"; +import { + ExtractionInference, + ExtractionParameters, + ExtractionResponse, +} from "@/v2/product/extraction/index.js"; +import { SimpleField } from "@/v2/parsing/inference/field/index.js"; import { MindeeHttpErrorV2 } from "@/v2/http/index.js"; import * as fs from "node:fs"; import { RESOURCE_PATH, V2_PRODUCT_PATH, V2_RESOURCE_PATH } from "../index.js"; diff --git a/tests/v2/client/inferenceParameter.spec.ts b/tests/v2/client/inferenceParameter.spec.ts index fa3a6a3a..00907884 100644 --- a/tests/v2/client/inferenceParameter.spec.ts +++ b/tests/v2/client/inferenceParameter.spec.ts @@ -1,10 +1,9 @@ import { StringDict } from "@/parsing/index.js"; import path from "path"; import { V2_RESOURCE_PATH } from "../../index.js"; -import { ExtractionParameters } from "@/index.js"; import { expect } from "chai"; -import { DataSchema } from "@/index.js"; import { promises as fs } from "fs"; +import { ExtractionParameters, DataSchema } from "@/v2/product/extraction/index.js"; let expectedDataSchemaDict: StringDict; let expectedDataSchemaString: string; diff --git a/tests/v2/parsing/inference.spec.ts b/tests/v2/parsing/inference.spec.ts index 5ed6d732..a9ec5234 100644 --- a/tests/v2/parsing/inference.spec.ts +++ b/tests/v2/parsing/inference.spec.ts @@ -7,14 +7,14 @@ import { ListField, ObjectField, SimpleField, -} from "@/v2/parsing/result/field/index.js"; +} from "@/v2/parsing/inference/field/index.js"; import { LocalResponse, - ExtractionResponse, RagMetadata, RawText, } from "@/v2/parsing/index.js"; import { V2_RESOURCE_PATH } from "../../index.js"; +import { ExtractionResponse } from "@/v2/product/index.js"; const findocPath = path.join(V2_RESOURCE_PATH, "products", "financial_document"); const inferencePath = path.join(V2_RESOURCE_PATH, "inference"); diff --git a/tests/v2/parsing/localResponse.spec.ts b/tests/v2/parsing/localResponse.spec.ts index f60ce32a..cad36ad9 100644 --- a/tests/v2/parsing/localResponse.spec.ts +++ b/tests/v2/parsing/localResponse.spec.ts @@ -1,10 +1,11 @@ import * as fs from "node:fs/promises"; import { expect } from "chai"; -import { ExtractionResponse, LocalResponse } from "@/v2/index.js"; +import { LocalResponse } from "@/v2/index.js"; import path from "path"; import { V2_RESOURCE_PATH } from "../../index.js"; import { Buffer } from "node:buffer"; +import { ExtractionResponse } from "@/v2/product/index.js"; const signature: string = "f390d9f7f57ac04f47b6309d8a40236b0182610804fc20e91b1f6028aaca07a7"; const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; From df553a710061e4454b07e58a4989e4b2d1f079c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 6 Feb 2026 16:39:21 +0100 Subject: [PATCH 9/9] update test libs --- tests/data | 2 +- tests/v2/parsing/localResponse.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/data b/tests/data index 67ccc1d9..ed58a9d5 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 67ccc1d9cf8b6263860f79eafbaa2e8b8dd7ac3f +Subproject commit ed58a9d57a31294fef0b8554388db287335e3b79 diff --git a/tests/v2/parsing/localResponse.spec.ts b/tests/v2/parsing/localResponse.spec.ts index cad36ad9..2fda9a8c 100644 --- a/tests/v2/parsing/localResponse.spec.ts +++ b/tests/v2/parsing/localResponse.spec.ts @@ -7,7 +7,7 @@ import { V2_RESOURCE_PATH } from "../../index.js"; import { Buffer } from "node:buffer"; import { ExtractionResponse } from "@/v2/product/index.js"; -const signature: string = "f390d9f7f57ac04f47b6309d8a40236b0182610804fc20e91b1f6028aaca07a7"; +const signature: string = "e51bdf80f1a08ed44ee161100fc30a25cb35b4ede671b0a575dc9064a3f5dbf1"; const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; const filePath: string = path.join(V2_RESOURCE_PATH, "inference/standard_field_types.json");