From 52a6aff554952d00ac2d29cdc919e2f8eea225fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Thu, 20 Aug 2026 18:41:48 +0200 Subject: [PATCH] :recycle: misc improvements --- src/v2/clientOptions/baseProductParameters.ts | 13 +---- src/v2/http/mindeeApiV2.ts | 54 +++++++++---------- .../params/classificationParameters.ts | 16 +----- src/v2/product/crop/params/cropParameters.ts | 16 +----- .../extraction/params/extractionParameters.ts | 17 +----- src/v2/product/ocr/params/ocrParameters.ts | 16 +----- .../product/split/params/splitParameters.ts | 16 +----- .../ragDocumentSearchParameters.ts | 17 +++--- 8 files changed, 42 insertions(+), 123 deletions(-) diff --git a/src/v2/clientOptions/baseProductParameters.ts b/src/v2/clientOptions/baseProductParameters.ts index b258101a..96c205e3 100644 --- a/src/v2/clientOptions/baseProductParameters.ts +++ b/src/v2/clientOptions/baseProductParameters.ts @@ -11,18 +11,7 @@ export interface BaseProductParametersConstructor { } /** - * Parameters accepted by all v2 products. - * - * All fields are optional except `modelId`. - * - * @category ClientV2 - * @example - * const params = { - * modelId: "YOUR_MODEL_ID", - * rag: true, - * alias: "YOUR_ALIAS", - * webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"], - * }; + * Base parameters for sending a file to a Mindee V2 product. */ export abstract class BaseProductParameters { /** diff --git a/src/v2/http/mindeeApiV2.ts b/src/v2/http/mindeeApiV2.ts index 81942753..3b9b81bd 100644 --- a/src/v2/http/mindeeApiV2.ts +++ b/src/v2/http/mindeeApiV2.ts @@ -32,29 +32,7 @@ export class MindeeApiV2 { } /** - * Searches for resources matching the given criteria. - * @param search - * @param parameters Search parameters. - * @returns a `Promise` containing the search response. - */ - async reqGetSearch( - search: S, - parameters: BaseSearchParameters - ): Promise> { - const options: RequestOptions = { - method: "GET", - headers: this.settings.baseHeaders, - hostname: this.settings.hostname, - path: `/v2/search/${search.slug}`, - queryParams: parameters.getRequestParameters(), - timeoutSecs: this.settings.timeoutSecs, - }; - const response: BaseHttpResponse = await sendRequestAndReadResponse(this.settings.dispatcher, options); - return this.#processResponse(response, search.responseClass) as InstanceType; - } - - /** - * Sends a document to the inference queue. + * Send a file to the asynchronous processing queue for inference processing. * @param product Product to enqueue. * @param inputSource Local or remote file as an input. * @param params {ExtractionParameters} parameters relating to the enqueueing options. @@ -89,7 +67,7 @@ export class MindeeApiV2 { } /** - * Get the specified Job by its ID. + * Get the status of an inference that was previously enqueued. * Throws an error if the server's response contains an error. * @param jobId The Job ID as returned by the enqueue request. * @returns a `Promise` containing the job response. @@ -101,7 +79,7 @@ export class MindeeApiV2 { } /** - * Get the specified Job from a polling URL. + * Get the status of an inference that was previously enqueued. * Throws an error if the server's response contains an error. * @param pollingUrl The polling URL as returned by a Job's pollingUrl property. * @returns a `Promise` containing the job response. @@ -120,7 +98,7 @@ export class MindeeApiV2 { } /** - * Get the result of a queued document from the API. + * Get the result of an inference that was previously enqueued. * Throws an error if the server's response contains an error. * @param product * @param inferenceId The inference ID for the result. @@ -137,7 +115,7 @@ export class MindeeApiV2 { } /** - * Get the result of a queued document from the API. + * Get the result of an inference that was previously enqueued. * Throws an error if the server's response contains an error. * @param product * @param url The URL as returned by a Job's resultUrl property. @@ -160,6 +138,28 @@ export class MindeeApiV2 { return this.#processResponse(response, product.responseClass) as InstanceType; } + /** + * Searches for resources matching the given criteria. + * @param search + * @param parameters Search parameters. + * @returns a `Promise` containing the search response. + */ + async reqGetSearch( + search: S, + parameters: BaseSearchParameters + ): Promise> { + const options: RequestOptions = { + method: "GET", + headers: this.settings.baseHeaders, + hostname: this.settings.hostname, + path: `/v2/search/${search.slug}`, + queryParams: parameters.getRequestParameters(), + timeoutSecs: this.settings.timeoutSecs, + }; + const response: BaseHttpResponse = await sendRequestAndReadResponse(this.settings.dispatcher, options); + return this.#processResponse(response, search.responseClass) as InstanceType; + } + #paramsToFormData(params: Record): FormData { const form = new FormData(); for (const [key, value] of Object.entries(params)) { diff --git a/src/v2/product/classification/params/classificationParameters.ts b/src/v2/product/classification/params/classificationParameters.ts index 16c5f47f..0cccad0b 100644 --- a/src/v2/product/classification/params/classificationParameters.ts +++ b/src/v2/product/classification/params/classificationParameters.ts @@ -2,21 +2,7 @@ import { BaseProductParameters, BaseProductParametersConstructor } from "@/v2/cl 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, - * } - * }; + * Parameters for sending a file to a Classification product. */ export class ClassificationParameters extends BaseProductParameters { constructor(params: BaseProductParametersConstructor & {}) { diff --git a/src/v2/product/crop/params/cropParameters.ts b/src/v2/product/crop/params/cropParameters.ts index 33cfeb3a..ad2c39b3 100644 --- a/src/v2/product/crop/params/cropParameters.ts +++ b/src/v2/product/crop/params/cropParameters.ts @@ -2,21 +2,7 @@ import { BaseProductParameters, BaseProductParametersConstructor } from "@/v2/cl 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, - * } - * }; + * Parameters for sending a file to a Crop product. */ export class CropParameters extends BaseProductParameters { constructor(params: BaseProductParametersConstructor & {}) { diff --git a/src/v2/product/extraction/params/extractionParameters.ts b/src/v2/product/extraction/params/extractionParameters.ts index adce2738..9e102610 100644 --- a/src/v2/product/extraction/params/extractionParameters.ts +++ b/src/v2/product/extraction/params/extractionParameters.ts @@ -4,22 +4,7 @@ import { BaseProductParameters, BaseProductParametersConstructor } from "@/v2/cl 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", - * rag: true, - * alias: "YOUR_ALIAS", - * webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"], - * pollingOptions: { - * initialDelaySec: 2, - * delaySec: 1.5, - * } - * }; + * Parameters for sending a file to an Extraction product. */ export class ExtractionParameters extends BaseProductParameters { /** diff --git a/src/v2/product/ocr/params/ocrParameters.ts b/src/v2/product/ocr/params/ocrParameters.ts index 2c408c32..3127f8fc 100644 --- a/src/v2/product/ocr/params/ocrParameters.ts +++ b/src/v2/product/ocr/params/ocrParameters.ts @@ -2,21 +2,7 @@ import { BaseProductParameters, BaseProductParametersConstructor } from "@/v2/cl 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, - * } - * }; + * Parameters for sending a file to a Raw Text (OCR) product. */ export class OcrParameters extends BaseProductParameters { constructor(params: BaseProductParametersConstructor & {}) { diff --git a/src/v2/product/split/params/splitParameters.ts b/src/v2/product/split/params/splitParameters.ts index fd90ae29..19ddc80f 100644 --- a/src/v2/product/split/params/splitParameters.ts +++ b/src/v2/product/split/params/splitParameters.ts @@ -5,21 +5,7 @@ import { 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, - * } - * }; + * Parameters for sending a file to a Split product. */ export class SplitParameters extends BaseProductParameters { constructor(params: BaseProductParametersConstructor & {}) { diff --git a/src/v2/search/ragDocuments/ragDocumentSearchParameters.ts b/src/v2/search/ragDocuments/ragDocumentSearchParameters.ts index 6e78eab2..3cc35ca3 100644 --- a/src/v2/search/ragDocuments/ragDocumentSearchParameters.ts +++ b/src/v2/search/ragDocuments/ragDocumentSearchParameters.ts @@ -5,7 +5,7 @@ import { BaseSearchParameters, BaseSearchParametersConstructor } from "@/v2/clie * Constructor parameters for RagDocumentSearchParameters. */ export interface RagDocumentSearchParametersConstructor extends BaseSearchParametersConstructor { - modelId?: string; + modelId: string; filename?: string; } @@ -16,14 +16,17 @@ export class RagDocumentSearchParameters extends BaseSearchParameters { /** * Model identifier to search in. */ - modelId?: string; + modelId: string; /** * Case-insensitive substring search on filename. */ filename?: string; - constructor(params: RagDocumentSearchParametersConstructor = {}) { + constructor(params: RagDocumentSearchParametersConstructor) { + if (!params.modelId) { + throw new MindeeConfigurationError("ModelId is required in RagDocumentSearchParameters"); + } super(params); this.modelId = params.modelId; this.filename = params.filename; @@ -32,11 +35,9 @@ export class RagDocumentSearchParameters extends BaseSearchParameters { /** @inheritdoc */ getRequestParameters(): Record { const parameters = super.getRequestParameters(); - if (this.modelId) { - parameters["model_id"] = this.modelId; - } else { - throw new MindeeConfigurationError("ModelId is required in RagDocumentSearchParameters"); - } + + parameters["model_id"] = this.modelId; + if (this.filename) { parameters["filename"] = this.filename; }