mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-23 07:55:07 +00:00
Merge pull request #586 from sbplat/version-2-contained-operators-test
fix(shared-operations): resolve typescript compile errors
This commit is contained in:
commit
a0cf84d16c
@ -2,6 +2,7 @@
|
|||||||
import { PdfFile, RepresentationType } from "../wrappers/PdfFile";
|
import { PdfFile, RepresentationType } from "../wrappers/PdfFile";
|
||||||
import { Operator, Progress, oneToOne } from ".";
|
import { Operator, Progress, oneToOne } from ".";
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
import * as pdfcpuWrapper from "#pdfcpu"; // This is updated by tsconfig.json/paths for the context (browser, node, etc.) this module is used in.
|
import * as pdfcpuWrapper from "#pdfcpu"; // This is updated by tsconfig.json/paths for the context (browser, node, etc.) this module is used in.
|
||||||
|
|
||||||
import Joi from "joi";
|
import Joi from "joi";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Operator } from "functions";
|
import { Operator } from "../functions";
|
||||||
import { Action } from "../../declarations/Action";
|
import { Action } from "../../declarations/Action";
|
||||||
import { getOperatorByName } from "./getOperatorByName";
|
import { getOperatorByName } from "./getOperatorByName";
|
||||||
|
|
||||||
@ -34,8 +34,11 @@ export function validateOperations(actions: Action[]): { valid: boolean, reason?
|
|||||||
return { valid: false, reason: "There is a wait action that does not have an associated done action." };
|
return { valid: false, reason: "There is a wait action that does not have an associated done action." };
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const afterDoneChild of done[childAction.values.id].actions) {
|
for (const afterDoneChild of done[childAction.values.id]?.actions || []) {
|
||||||
if(!ioCompatible(operator, getOperatorByName(afterDoneChild.type))) {
|
const receivingOperator = getOperatorByName(afterDoneChild.type);
|
||||||
|
if (!receivingOperator) {
|
||||||
|
return { valid: false, reason: `The receiving operator ${afterDoneChild.type} does not exist.` };
|
||||||
|
} else if (!ioCompatible(operator, receivingOperator)) {
|
||||||
return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${afterDoneChild.type}` };
|
return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${afterDoneChild.type}` };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +47,10 @@ export function validateOperations(actions: Action[]): { valid: boolean, reason?
|
|||||||
return { valid: false, reason: `There shouldn't be a done action here.` };
|
return { valid: false, reason: `There shouldn't be a done action here.` };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(!ioCompatible(operator, getOperatorByName(childAction.type))) {
|
const receivingOperator = getOperatorByName(childAction.type);
|
||||||
|
if (!receivingOperator) {
|
||||||
|
return { valid: false, reason: `The receiving operator ${childAction.type} does not exist.` };
|
||||||
|
} else if (!ioCompatible(operator, receivingOperator)) {
|
||||||
return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${childAction.type}` };
|
return { valid: false, reason: `Ouput of action ${action.type} is not compatible with input of action ${childAction.type}` };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,8 +66,8 @@ export function validateOperations(actions: Action[]): { valid: boolean, reason?
|
|||||||
return { valid: true };
|
return { valid: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
function ioCompatible(outputingOperator: typeof Operator, recievingOperator: typeof Operator): boolean {
|
function ioCompatible(outputingOperator: typeof Operator, receivingOperator: typeof Operator): boolean {
|
||||||
const outputType = outputingOperator.schema.describe().keys.output.label;
|
const outputType = outputingOperator.schema.describe().keys.output.label;
|
||||||
const inputType = recievingOperator.schema.describe().keys.input.label;
|
const inputType = receivingOperator.schema.describe().keys.input.label;
|
||||||
return outputType == inputType;
|
return outputType == inputType;
|
||||||
}
|
}
|
@ -23,5 +23,5 @@ export const JoiPDFFileSchema = Joi.custom((value: Express.Multer.File | Express
|
|||||||
}, "pdffile validation");
|
}, "pdffile validation");
|
||||||
|
|
||||||
function isPdfFileArray(value: any): value is PdfFile[] {
|
function isPdfFileArray(value: any): value is PdfFile[] {
|
||||||
return value.every((e) => e instanceof PdfFile)
|
return value.every((e: PdfFile) => e instanceof PdfFile)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user