Skip to content

harmonize with other libs #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/code_samples/default_v2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";

// Init a new client
const mindeeClient = new mindee.ClientV2({ apiKey: "MY_API_KEY" });
const apiKey = "MY_API_KEY";
const filePath = "/path/to/the/file.ext";
const modelId = "MY_MODEL_ID";

// Init a new client
const mindeeClient = new mindee.ClientV2({ apiKey: apiKey });

// Load a file from disk
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");
const inputSource = mindeeClient.sourceFromPath(filePath);
const params = {
modelId: modelId,
// If set to `true`, will enable Retrieval-Augmented Generation.
Expand Down
73 changes: 0 additions & 73 deletions src/baseClient.ts

This file was deleted.

74 changes: 71 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { setTimeout } from "node:timers/promises";
import { MindeeError } from "./errors";
import { WorkflowResponse } from "./parsing/common/workflowResponse";
import { WorkflowEndpoint } from "./http/workflowEndpoint";
import { BaseClient } from "./baseClient";
import { Base64Input, BufferInput, BytesInput, PathInput, StreamInput, UrlInput } from "./input";
import { Readable } from "stream";

/**
* Common options for workflows & predictions.
Expand Down Expand Up @@ -129,7 +130,7 @@ export interface ClientOptions {
*
* @category Client
*/
export class Client extends BaseClient {
export class Client {
/** Key of the API. */
protected apiKey: string;

Expand All @@ -143,7 +144,6 @@ export class Client extends BaseClient {
debug: false,
}
) {
super();
this.apiKey = apiKey ? apiKey : "";
errorHandler.throwOnError = throwOnError ?? true;
logger.level =
Expand Down Expand Up @@ -565,4 +565,72 @@ Job status: ${pollResults.job.status}.`
InferenceFactory.getEndpoint(productClass);
return [endpointName, endpointVersion];
}

/**
* Load an input document from a local path.
* @param inputPath
*/
docFromPath(inputPath: string): PathInput {
return new PathInput({
inputPath: inputPath,
});
}

/**
* Load an input document from a base64 encoded string.
* @param inputString input content, as a string.
* @param filename file name.
*/
docFromBase64(inputString: string, filename: string): Base64Input {
return new Base64Input({
inputString: inputString,
filename: filename,
});
}

/**
* Load an input document from a `stream.Readable` object.
* @param inputStream input content, as a readable stream.
* @param filename file name.
*/
docFromStream(inputStream: Readable, filename: string): StreamInput {
return new StreamInput({
inputStream: inputStream,
filename: filename,
});
}

/**
* Load an input document from bytes.
* @param inputBytes input content, as a Uint8Array or Buffer.
* @param filename file name.
*/
docFromBytes(inputBytes: Uint8Array, filename: string): BytesInput {
return new BytesInput({
inputBytes: inputBytes,
filename: filename,
});
}

/**
* Load an input document from a URL.
* @param url input url. Must be HTTPS.
*/
docFromUrl(url: string): UrlInput {
return new UrlInput({
url: url,
});
}

/**
* Load an input document from a Buffer.
* @param buffer input content, as a buffer.
* @param filename file name.
*/
docFromBuffer(buffer: Buffer, filename: string): BufferInput {
return new BufferInput({
buffer: buffer,
filename: filename,
});
}
}
76 changes: 72 additions & 4 deletions src/clientV2.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {
LocalInputSource,
Base64Input, BufferInput, BytesInput,
LocalInputSource, PathInput, StreamInput, UrlInput,
} from "./input";
import { errorHandler } from "./errors/handler";
import { LOG_LEVELS, logger } from "./logger";

import { setTimeout } from "node:timers/promises";
import { ErrorResponse, InferenceResponse, JobResponse } from "./parsing/v2";
import { MindeeApiV2 } from "./http/mindeeApiV2";
import { BaseClient } from "./baseClient";
import { MindeeHttpErrorV2 } from "./errors/mindeeError";
import { Readable } from "stream";

/**
* Parameters for the internal polling loop in {@link ClientV2.enqueueAndGetInference | enqueueAndGetInference()} .
Expand Down Expand Up @@ -122,7 +123,7 @@ export interface ClientOptions {
*
* @category ClientV2
*/
export class ClientV2 extends BaseClient {
export class ClientV2 {
/** Key of the API. */
protected mindeeApi: MindeeApiV2;

Expand All @@ -136,7 +137,6 @@ export class ClientV2 extends BaseClient {
debug: false,
}
) {
super();
this.mindeeApi = new MindeeApiV2(apiKey);
errorHandler.throwOnError = throwOnError ?? true;
logger.level =
Expand Down Expand Up @@ -283,4 +283,72 @@ Job status: ${pollResults.job.status}.`
" seconds"
);
}

/**
* Load an input source from a local path.
* @param inputPath
*/
sourceFromPath(inputPath: string): PathInput {
return new PathInput({
inputPath: inputPath,
});
}

/**
* Load an input source from a base64 encoded string.
* @param inputString input content, as a string.
* @param filename file name.
*/
sourceFromBase64(inputString: string, filename: string): Base64Input {
return new Base64Input({
inputString: inputString,
filename: filename,
});
}

/**
* Load an input source from a `stream.Readable` object.
* @param inputStream input content, as a readable stream.
* @param filename file name.
*/
sourceFromStream(inputStream: Readable, filename: string): StreamInput {
return new StreamInput({
inputStream: inputStream,
filename: filename,
});
}

/**
* Load an input source from bytes.
* @param inputBytes input content, as a Uint8Array or Buffer.
* @param filename file name.
*/
sourceFromBytes(inputBytes: Uint8Array, filename: string): BytesInput {
return new BytesInput({
inputBytes: inputBytes,
filename: filename,
});
}

/**
* Load an input source from a Buffer.
* @param buffer input content, as a buffer.
* @param filename file name.
*/
sourceFromBuffer(buffer: Buffer, filename: string): BufferInput {
return new BufferInput({
buffer: buffer,
filename: filename,
});
}

/**
* Load an input source from a URL.
* @param url input url. Must be HTTPS.
*/
sourceFromUrl(url: string): UrlInput {
return new UrlInput({
url: url,
});
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export {
Document,
Page,
} from "./parsing/common";
export { InputSource, PageOptionsOperation, LocalResponse } from "./input";
export { InputSource, PageOptions, PageOptionsOperation, LocalResponse } from "./input";
export * as internal from "./internal";
export * as imageOperations from "./imageOperations";
2 changes: 1 addition & 1 deletion tests/inputs/pageOperations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("High level multi-page operations", () => {
inputPath: path.join(__dirname, "../data/file_types/pdf/multipage.pdf"),
});
await input.init();
await input.cutPdf({
await input.applyPageOptions({
operation: PageOptionsOperation.KeepOnly,
pageIndexes: [0, -2, -1],
onMinPages: 5,
Expand Down
Loading
Loading