UNPKG

mindee

Version:

Mindee Client Library for Node.js

92 lines (91 loc) 4.33 kB
import { Dispatcher } from "undici"; import { InputSource } from "../input/index.js"; import { JobResponse } from "./parsing/index.js"; import { SearchResponse } from "./parsing/search/index.js"; import { MindeeApiV2 } from "./http/mindeeApiV2.js"; import { PollingOptions, PollingOptionsConstructor } from "./clientOptions/index.js"; import { BaseProduct } from "../v2/product/baseProduct.js"; /** * Options for the V2 Mindee Client. * @example * const client = new MindeeClientV2({ * apiKey: "YOUR_API_KEY", * throwOnError: true, * debug: false * }); */ export interface ClientOptions { /** Your API key for all endpoints. */ apiKey?: string; /** Log debug messages. */ debug?: boolean; /** Custom Dispatcher instance for the HTTP requests. */ dispatcher?: Dispatcher; } /** * Mindee Client V2 class that centralizes most basic operations. */ export declare class Client { /** Mindee V2 API handler. */ protected mindeeApi: MindeeApiV2; /** * @param {ClientOptions} options options for the initialization of a client. */ constructor({ apiKey, debug, dispatcher }?: ClientOptions); /** * Search for models available to the account. * @param name Optional name filter. * @param modelType Optional model type filter. * @returns a `Promise` containing the search response. */ searchModels(name?: string, modelType?: string): Promise<SearchResponse>; enqueue<P extends typeof BaseProduct>(product: P, inputSource: InputSource, params: InstanceType<P["parametersClass"]> | ConstructorParameters<P["parametersClass"]>[0]): Promise<JobResponse>; /** * Retrieves the result of a previously enqueued request. * * @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`. * @returns a `Promise` containing the inference. */ getResult<P extends typeof BaseProduct>(product: P, inferenceId: string): Promise<InstanceType<P["responseClass"]>>; /** * Retrieves the result of a previously enqueued request. * This method is used when manually polling the server for the result URL. * * @param product the product to retrieve. * @param url URL as given in the `getJob()` response. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @returns a `Promise` containing the inference. */ getResultByUrl<P extends typeof BaseProduct>(product: P, url: string): Promise<InstanceType<P["responseClass"]>>; /** * Get the processing status of a previously enqueued request. * Can be used for polling. * * @param jobId id of the queue to poll. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @returns a `Promise` containing a `Job`, which also contains a `Document` if the * parsing is complete. */ getJob(jobId: string): Promise<JobResponse>; /** * Enqueue a request and poll the server until the result is sent or * until the maximum number of tries is reached. * * @param product the product to retrieve. * @param inputSource file or URL to parse. * @param params parameters relating to prediction options. * * @param pollingOptions options for the polling loop, see {@link PollingOptions}. * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`. * @returns a `Promise` containing parsing results. */ enqueueAndGetResult<P extends typeof BaseProduct>(product: P, inputSource: InputSource, params: InstanceType<P["parametersClass"]> | ConstructorParameters<P["parametersClass"]>[0], pollingOptions?: PollingOptionsConstructor): Promise<InstanceType<P["responseClass"]>>; /** * Send a document to an endpoint and poll the server until the result is sent or * until the maximum number of tries is reached. * @protected */ protected pollForResult<P extends typeof BaseProduct>(product: typeof BaseProduct, pollingOptions: PollingOptions, jobResponse: JobResponse): Promise<InstanceType<P["responseClass"]>>; }