Skip to content
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
2 changes: 1 addition & 1 deletion src/v2/product/classification/classification.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ClassificationResponse } from "./classificationResponse.js";
import { ClassificationParameters } from "./classificationParameters.js";
import { ClassificationParameters } from "./params/index.js";
import { BaseProduct } from "@/v2/product/baseProduct.js";

export class Classification extends BaseProduct {
Expand Down
2 changes: 1 addition & 1 deletion src/v2/product/classification/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Classification } from "./classification.js";
export { ClassificationParameters } from "./classificationParameters.js";
export { ClassificationParameters } from "./params/index.js";
export { ClassificationResponse } from "./classificationResponse.js";
export { ClassificationInference } from "./classificationInference.js";
export { ClassificationResult } from "./classificationResult.js";
Expand Down
1 change: 1 addition & 0 deletions src/v2/product/classification/params/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ClassificationParameters } from "./classificationParameters.js";
2 changes: 1 addition & 1 deletion src/v2/product/crop/crop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CropResponse } from "./cropResponse.js";
import { CropParameters } from "./cropParameters.js";
import { CropParameters } from "./params/index.js";
import { BaseProduct } from "@/v2/product/baseProduct.js";

export class Crop extends BaseProduct {
Expand Down
2 changes: 1 addition & 1 deletion src/v2/product/crop/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Crop } from "./crop.js";
export { CropParameters } from "./cropParameters.js";
export { CropParameters } from "./params/index.js";
export { CropInference } from "./cropInference.js";
export { CropItem } from "./cropItem.js";
export { CropResponse } from "./cropResponse.js";
Expand Down
1 change: 1 addition & 0 deletions src/v2/product/crop/params/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CropParameters } from "./cropParameters.js";
2 changes: 1 addition & 1 deletion src/v2/product/extraction/extraction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExtractionResponse } from "./extractionResponse.js";
import { ExtractionParameters } from "./extractionParameters.js";
import { ExtractionParameters } from "./params/index.js";
import { BaseProduct } from "@/v2/product/baseProduct.js";

export class Extraction extends BaseProduct {
Expand Down
4 changes: 2 additions & 2 deletions src/v2/product/extraction/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { Extraction } from "./extraction.js";
export { ExtractionParameters } from "./extractionParameters.js";
export { DataSchema } from "./dataSchema.js";
export { ExtractionParameters } from "./params/index.js";
export * as params from "./params/index.js";
export { ExtractionInference } from "./extractionInference.js";
export { ExtractionActiveOptions } from "./extractionActiveOptions.js";
export { ExtractionResponse } from "./extractionResponse.js";
Expand Down
29 changes: 29 additions & 0 deletions src/v2/product/extraction/params/dataSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { StringDict } from "@/parsing/stringDict.js";
import { DataSchemaReplace } from "./dataSchemaReplace.js";

/**
* Modify the Data Schema.
*/
export class DataSchema {
/**
* If set, completely replaces the data schema of the model.
*/
replace?: DataSchemaReplace;

constructor(dataSchema: StringDict | string) {
if (typeof dataSchema === "string") {
this.replace = new DataSchemaReplace(JSON.parse(dataSchema)["replace"]);
} else if (dataSchema instanceof DataSchema) {
this.replace = dataSchema.replace;
} else {
this.replace = new DataSchemaReplace(dataSchema["replace"] as StringDict);
}
}

toJSON() {
return { replace: this.replace?.toJSON() };
}
toString() {
return JSON.stringify(this.toJSON());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { StringDict } from "@/parsing/stringDict.js";
import { MindeeError } from "@/errors/index.js";
import { StringDict } from "@/parsing/index.js";

export class DataSchemaField {
/**
Expand Down Expand Up @@ -77,58 +76,3 @@ export class DataSchemaField {
return JSON.stringify(this.toJSON());
}
}

/**
* The structure to completely replace the data schema of the model.
*/
export class DataSchemaReplace {
/**
* List of fields in the Data Schema.
*/
fields: Array<DataSchemaField>;

constructor(dataSchemaReplace: StringDict) {
if (!dataSchemaReplace || !dataSchemaReplace.fields ) {
throw new MindeeError("Invalid Data Schema provided.");
}
if (dataSchemaReplace["fields"].length === 0) {
throw new TypeError("Data Schema replacement fields cannot be empty.");
}
this.fields = dataSchemaReplace["fields"].map((field: StringDict) => (new DataSchemaField(field)));
}

toJSON() {
return { fields: this.fields.map(e => e.toJSON()) };
}

toString() {
return JSON.stringify(this.toJSON());
}
}

/**
* Modify the Data Schema.
*/
export class DataSchema {
/**
* If set, completely replaces the data schema of the model.
*/
replace?: DataSchemaReplace;

constructor(dataSchema: StringDict | string) {
if (typeof dataSchema === "string") {
this.replace = new DataSchemaReplace(JSON.parse(dataSchema)["replace"]);
} else if (dataSchema instanceof DataSchema) {
this.replace = dataSchema.replace;
} else {
this.replace = new DataSchemaReplace(dataSchema["replace"] as StringDict);
}
}

toJSON() {
return { replace: this.replace?.toJSON() };
}
toString() {
return JSON.stringify(this.toJSON());
}
}
31 changes: 31 additions & 0 deletions src/v2/product/extraction/params/dataSchemaReplace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { StringDict } from "@/parsing/index.js";
import { DataSchemaField } from "./dataSchemaField.js";
import { MindeeError } from "@/errors/index.js";

/**
* The structure to completely replace the data schema of the model.
*/
export class DataSchemaReplace {
/**
* List of fields in the Data Schema.
*/
fields: Array<DataSchemaField>;

constructor(dataSchemaReplace: StringDict) {
if (!dataSchemaReplace || !dataSchemaReplace.fields ) {
throw new MindeeError("Invalid Data Schema provided.");
}
if (dataSchemaReplace["fields"].length === 0) {
throw new TypeError("Data Schema replacement fields cannot be empty.");
}
this.fields = dataSchemaReplace["fields"].map((field: StringDict) => (new DataSchemaField(field)));
}

toJSON() {
return { fields: this.fields.map(e => e.toJSON()) };
}

toString() {
return JSON.stringify(this.toJSON());
}
}
4 changes: 4 additions & 0 deletions src/v2/product/extraction/params/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { ExtractionParameters } from "./extractionParameters.js";
export { DataSchema } from "./dataSchema.js";
export { DataSchemaReplace } from "./dataSchemaReplace.js";
export { DataSchemaField } from "./dataSchemaField.js";
2 changes: 1 addition & 1 deletion src/v2/product/ocr/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Ocr } from "./ocr.js";
export { OcrParameters } from "./ocrParameters.js";
export { OcrParameters } from "./params/index.js";
export { OcrResponse } from "./ocrResponse.js";
export { OcrInference } from "./ocrInference.js";
export { OcrResult } from "./ocrResult.js";
Expand Down
2 changes: 1 addition & 1 deletion src/v2/product/ocr/ocr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OcrResponse } from "./ocrResponse.js";
import { OcrParameters } from "./ocrParameters.js";
import { OcrParameters } from "./params/index.js";
import { BaseProduct } from "@/v2/product/baseProduct.js";

export class Ocr extends BaseProduct {
Expand Down
1 change: 1 addition & 0 deletions src/v2/product/ocr/params/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { OcrParameters } from "./ocrParameters.js";
2 changes: 1 addition & 1 deletion src/v2/product/split/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Split } from "./split.js";
export { SplitParameters } from "./splitParameters.js";
export { SplitParameters } from "./params/index.js";
export { SplitResponse } from "./splitResponse.js";
export { SplitInference } from "./splitInference.js";
export { SplitRange } from "./splitRange.js";
Expand Down
1 change: 1 addition & 0 deletions src/v2/product/split/params/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SplitParameters } from "./splitParameters.js";
2 changes: 1 addition & 1 deletion src/v2/product/split/split.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SplitResponse } from "./splitResponse.js";
import { SplitParameters } from "./splitParameters.js";
import { SplitParameters } from "./params/index.js";
import { BaseProduct } from "@/v2/product/baseProduct.js";

export class Split extends BaseProduct {
Expand Down
4 changes: 2 additions & 2 deletions tests/v2/product/extractionParameter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { extraction } from "@/v2/product/index.js";

let expectedDataSchemaDict: StringDict;
let expectedDataSchemaString: string;
let expectedDataSchemaObject: extraction.DataSchema;
let expectedDataSchemaObject: extraction.params.DataSchema;

describe("MindeeV2 - Extraction Parameter", () => {
const modelIdValue = "test-model-id";
Expand All @@ -34,7 +34,7 @@ describe("MindeeV2 - Extraction Parameter", () => {
);
expectedDataSchemaDict = JSON.parse(fileContents.toString());
expectedDataSchemaString = JSON.stringify(expectedDataSchemaDict);
expectedDataSchemaObject = new extraction.DataSchema(expectedDataSchemaDict);
expectedDataSchemaObject = new extraction.params.DataSchema(expectedDataSchemaDict);
});

it("shouldn't replace when unset", () => {
Expand Down
Loading