@mat3ra/wode 2026.5.29-0 → 2026.6.16-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/Subworkflow.d.ts +46 -9
- package/dist/js/Subworkflow.js +5 -2
- package/dist/js/Workflow.d.ts +2 -1
- package/dist/js/context/mixins/MaterialContextMixin.d.ts +1 -1
- package/dist/js/enums.d.ts +3 -1
- package/dist/js/enums.js +2 -0
- package/dist/js/generated/ErrorUnitSchemaMixin.d.ts +5 -0
- package/dist/js/generated/ErrorUnitSchemaMixin.js +21 -0
- package/dist/js/index.d.ts +3 -2
- package/dist/js/index.js +4 -1
- package/dist/js/repair/createErrorUnitData.d.ts +3 -0
- package/dist/js/repair/createErrorUnitData.js +25 -0
- package/dist/js/repair/formatRepairReason.d.ts +1 -0
- package/dist/js/repair/formatRepairReason.js +22 -0
- package/dist/js/repair/types.d.ts +16 -0
- package/dist/js/repair/types.js +2 -0
- package/dist/js/units/ErrorUnit.d.ts +16 -0
- package/dist/js/units/ErrorUnit.js +31 -0
- package/dist/js/units/factory.d.ts +13 -8
- package/dist/js/units/factory.js +5 -0
- package/dist/js/units/index.d.ts +2 -1
- package/dist/js/units/index.js +3 -1
- package/dist/js/utils/index.d.ts +1 -0
- package/dist/js/utils/index.js +2 -1
- package/dist/js/utils/repair.d.ts +2 -0
- package/dist/js/utils/repair.js +140 -0
- package/dist/js/workflows/default.d.ts +1 -1
- package/dist/js/workflows/types.d.ts +4 -0
- package/dist/js/workflows/types.js +2 -0
- package/package.json +5 -3
- package/src/js/Subworkflow.ts +8 -3
- package/src/js/Workflow.ts +2 -5
- package/src/js/context/mixins/MaterialContextMixin.ts +1 -1
- package/src/js/enums.ts +2 -0
- package/src/js/generated/ErrorUnitSchemaMixin.ts +28 -0
- package/src/js/index.ts +3 -0
- package/src/js/units/ErrorUnit.ts +42 -0
- package/src/js/units/factory.ts +35 -11
- package/src/js/units/index.ts +2 -0
- package/src/js/utils/index.ts +1 -0
- package/src/js/utils/repair.ts +171 -0
- package/src/js/workflows/default.ts +1 -1
- package/src/js/workflows/types.ts +5 -0
package/dist/js/Subworkflow.d.ts
CHANGED
|
@@ -44,9 +44,9 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
44
44
|
static get defaultConfig(): {
|
|
45
45
|
_id: any;
|
|
46
46
|
name: string;
|
|
47
|
-
application: import("@mat3ra/esse/dist/js/types").ApplicationSchema
|
|
47
|
+
application: import("@mat3ra/esse/dist/js/types").ApplicationSchema;
|
|
48
48
|
model: {
|
|
49
|
-
functional:
|
|
49
|
+
functional: "pbe";
|
|
50
50
|
method: {
|
|
51
51
|
readonly type: "pseudopotential";
|
|
52
52
|
readonly subtype: "us";
|
|
@@ -461,7 +461,7 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
461
461
|
contextProviderName: "vasp-neb";
|
|
462
462
|
};
|
|
463
463
|
extraData: {
|
|
464
|
-
materialHash
|
|
464
|
+
materialHash?: string;
|
|
465
465
|
};
|
|
466
466
|
isEdited: boolean;
|
|
467
467
|
} | {
|
|
@@ -483,7 +483,7 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
483
483
|
preferGridMetric?: boolean;
|
|
484
484
|
};
|
|
485
485
|
extraData: {
|
|
486
|
-
materialHash
|
|
486
|
+
materialHash?: string;
|
|
487
487
|
};
|
|
488
488
|
isEdited: boolean;
|
|
489
489
|
} | {
|
|
@@ -496,7 +496,7 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
496
496
|
steps: number;
|
|
497
497
|
}[]];
|
|
498
498
|
extraData: {
|
|
499
|
-
materialHash
|
|
499
|
+
materialHash?: string;
|
|
500
500
|
};
|
|
501
501
|
isEdited: boolean;
|
|
502
502
|
} | {
|
|
@@ -522,7 +522,7 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
522
522
|
hubbardUValue?: number;
|
|
523
523
|
}[];
|
|
524
524
|
extraData: {
|
|
525
|
-
materialHash
|
|
525
|
+
materialHash?: string;
|
|
526
526
|
};
|
|
527
527
|
isEdited: boolean;
|
|
528
528
|
} | {
|
|
@@ -575,7 +575,7 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
575
575
|
targetFermiEnergy?: number;
|
|
576
576
|
};
|
|
577
577
|
extraData: {
|
|
578
|
-
materialHash
|
|
578
|
+
materialHash?: string;
|
|
579
579
|
};
|
|
580
580
|
isEdited: boolean;
|
|
581
581
|
} | {
|
|
@@ -615,7 +615,7 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
615
615
|
totalMagnetization: number;
|
|
616
616
|
};
|
|
617
617
|
extraData: {
|
|
618
|
-
materialHash
|
|
618
|
+
materialHash?: string;
|
|
619
619
|
};
|
|
620
620
|
isEdited: boolean;
|
|
621
621
|
} | {
|
|
@@ -650,7 +650,7 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
650
650
|
};
|
|
651
651
|
};
|
|
652
652
|
extraData: {
|
|
653
|
-
materialHash
|
|
653
|
+
materialHash?: string;
|
|
654
654
|
};
|
|
655
655
|
isEdited: boolean;
|
|
656
656
|
})[];
|
|
@@ -697,6 +697,43 @@ declare class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
697
697
|
}[];
|
|
698
698
|
operand: string;
|
|
699
699
|
value: string | boolean | number;
|
|
700
|
+
} | {
|
|
701
|
+
_id?: string;
|
|
702
|
+
slug?: string;
|
|
703
|
+
systemName?: string;
|
|
704
|
+
schemaVersion?: string;
|
|
705
|
+
name: string;
|
|
706
|
+
isDefault?: boolean;
|
|
707
|
+
preProcessors: {
|
|
708
|
+
name: string;
|
|
709
|
+
[k: string]: unknown;
|
|
710
|
+
}[];
|
|
711
|
+
postProcessors: {
|
|
712
|
+
name: string;
|
|
713
|
+
[k: string]: unknown;
|
|
714
|
+
}[];
|
|
715
|
+
monitors: {
|
|
716
|
+
name: string;
|
|
717
|
+
[k: string]: unknown;
|
|
718
|
+
}[];
|
|
719
|
+
results: {
|
|
720
|
+
name: string;
|
|
721
|
+
[k: string]: unknown;
|
|
722
|
+
}[];
|
|
723
|
+
tags?: string[];
|
|
724
|
+
status?: "idle" | "active" | "warning" | "error" | "finished";
|
|
725
|
+
statusTrack?: {
|
|
726
|
+
trackedAt: number;
|
|
727
|
+
status: string;
|
|
728
|
+
repetition?: number;
|
|
729
|
+
}[];
|
|
730
|
+
isDraft?: boolean;
|
|
731
|
+
type: "error";
|
|
732
|
+
head?: boolean;
|
|
733
|
+
flowchartId: string;
|
|
734
|
+
next?: string;
|
|
735
|
+
enableRender?: boolean;
|
|
736
|
+
reason: string;
|
|
700
737
|
} | undefined;
|
|
701
738
|
findUnitKeyById(id: string): string;
|
|
702
739
|
private findUnitWithTag;
|
package/dist/js/Subworkflow.js
CHANGED
|
@@ -35,11 +35,14 @@ class Subworkflow extends entity_1.InMemoryEntity {
|
|
|
35
35
|
}
|
|
36
36
|
static get defaultConfig() {
|
|
37
37
|
const defaultName = "New Subworkflow";
|
|
38
|
+
const application = new standata_1.ApplicationRegistry().getDefaultApplication();
|
|
39
|
+
if (!application) {
|
|
40
|
+
throw new Error("No default application found");
|
|
41
|
+
}
|
|
38
42
|
return {
|
|
39
43
|
_id: utils_1.Utils.uuid.getUUID(),
|
|
40
44
|
name: defaultName,
|
|
41
|
-
application
|
|
42
|
-
// TODO: confirm if `functional` is required field. If not, update ESSE schema
|
|
45
|
+
application,
|
|
43
46
|
// `Model.defaultConfig` from @mat3ra/mode may omit `functional`; ESSE subworkflow schema requires it once schemas are registered.
|
|
44
47
|
model: { ...mode_1.Model.defaultConfig, functional: "pbe" },
|
|
45
48
|
properties: [],
|
package/dist/js/Workflow.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type HasDescription } from "@mat3ra/code/dist/js/entity/mixins/HasDescr
|
|
|
4
4
|
import { type HashedEntity } from "@mat3ra/code/dist/js/entity/mixins/HashedEntityMixin";
|
|
5
5
|
import { Taggable } from "@mat3ra/code/dist/js/entity/mixins/TaggableMixin";
|
|
6
6
|
import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
|
|
7
|
-
import type { ApplicationSchema
|
|
7
|
+
import type { ApplicationSchema } from "@mat3ra/esse/dist/js/types";
|
|
8
8
|
import { ComputedEntityMixin } from "@mat3ra/ide/dist/js/compute";
|
|
9
9
|
import type { Material } from "@mat3ra/made";
|
|
10
10
|
import type { MetaPropertyHolder } from "@mat3ra/prode";
|
|
@@ -17,6 +17,7 @@ import { type WorkflowSchemaMixin } from "./generated/WorkflowSchemaMixin";
|
|
|
17
17
|
import Subworkflow from "./Subworkflow";
|
|
18
18
|
import { MapUnit } from "./units";
|
|
19
19
|
import { type AnyWorkflowUnit } from "./units/factory";
|
|
20
|
+
import type { WorkflowSchema } from "./workflows/types";
|
|
20
21
|
interface Workflow extends Defaultable, NamedInMemoryEntity, WorkflowSchemaMixin, Taggable, HashedEntity, ComputedEntityMixin, HasDescription {
|
|
21
22
|
compute: WorkflowSchema["compute"];
|
|
22
23
|
}
|
|
@@ -7,7 +7,7 @@ export type MaterialContextMixin = {
|
|
|
7
7
|
readonly isMaterialUpdated: boolean;
|
|
8
8
|
material: OrderedMaterial;
|
|
9
9
|
extraData?: {
|
|
10
|
-
materialHash
|
|
10
|
+
materialHash?: string;
|
|
11
11
|
};
|
|
12
12
|
initMaterialContextMixin(externalContext: MaterialExternalContext): void;
|
|
13
13
|
updateMaterialHash(): void;
|
package/dist/js/enums.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare const UNIT_TYPES: {
|
|
|
9
9
|
readonly subworkflow: "subworkflow";
|
|
10
10
|
readonly io: "io";
|
|
11
11
|
readonly assertion: "assertion";
|
|
12
|
+
readonly error: "error";
|
|
12
13
|
};
|
|
13
14
|
export declare enum UnitType {
|
|
14
15
|
convergence = "convergence",
|
|
@@ -20,7 +21,8 @@ export declare enum UnitType {
|
|
|
20
21
|
condition = "condition",
|
|
21
22
|
subworkflow = "subworkflow",
|
|
22
23
|
io = "io",
|
|
23
|
-
assertion = "assertion"
|
|
24
|
+
assertion = "assertion",
|
|
25
|
+
error = "error"
|
|
24
26
|
}
|
|
25
27
|
export declare enum UnitTag {
|
|
26
28
|
hasConvergenceParam = "hasConvergenceParam",
|
package/dist/js/enums.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.UNIT_TYPES = {
|
|
|
14
14
|
subworkflow: "subworkflow",
|
|
15
15
|
io: "io",
|
|
16
16
|
assertion: "assertion",
|
|
17
|
+
error: "error",
|
|
17
18
|
};
|
|
18
19
|
var UnitType;
|
|
19
20
|
(function (UnitType) {
|
|
@@ -27,6 +28,7 @@ var UnitType;
|
|
|
27
28
|
UnitType["subworkflow"] = "subworkflow";
|
|
28
29
|
UnitType["io"] = "io";
|
|
29
30
|
UnitType["assertion"] = "assertion";
|
|
31
|
+
UnitType["error"] = "error";
|
|
30
32
|
})(UnitType || (exports.UnitType = UnitType = {}));
|
|
31
33
|
var UnitTag;
|
|
32
34
|
(function (UnitTag) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
2
|
+
import type { ErrorUnitMixinSchema } from "@mat3ra/esse/dist/js/types";
|
|
3
|
+
export type ErrorUnitSchemaMixin = ErrorUnitMixinSchema;
|
|
4
|
+
export type ErrorUnitInMemoryEntity = InMemoryEntity & ErrorUnitSchemaMixin;
|
|
5
|
+
export declare function errorUnitSchemaMixin<T extends InMemoryEntity>(item: InMemoryEntity): asserts item is T & ErrorUnitSchemaMixin;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorUnitSchemaMixin = errorUnitSchemaMixin;
|
|
4
|
+
function errorUnitSchemaMixin(item) {
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
const properties = {
|
|
7
|
+
get type() {
|
|
8
|
+
return this.prop("type");
|
|
9
|
+
},
|
|
10
|
+
set type(value) {
|
|
11
|
+
this.setProp("type", value);
|
|
12
|
+
},
|
|
13
|
+
get reason() {
|
|
14
|
+
return this.requiredProp("reason");
|
|
15
|
+
},
|
|
16
|
+
set reason(value) {
|
|
17
|
+
this.setProp("reason", value);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
|
|
21
|
+
}
|
package/dist/js/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import PointsPathFormDataProvider from "./context/providers/PointsPath/PointsPat
|
|
|
2
2
|
import { globalSettings } from "./context/providers/settings";
|
|
3
3
|
import { TAB_NAVIGATION_CONFIG, UNIT_NAME_INVALID_CHARS, WORKFLOW_STATUSES } from "./enums";
|
|
4
4
|
import Subworkflow from "./Subworkflow";
|
|
5
|
-
import { AssertionUnit, AssignmentUnit, BaseUnit, ConditionUnit, ExecutionUnit, IOUnit, MapUnit, ReduceUnit, SubworkflowUnit } from "./units";
|
|
5
|
+
import { AssertionUnit, AssignmentUnit, BaseUnit, ConditionUnit, ErrorUnit, ExecutionUnit, IOUnit, MapUnit, ReduceUnit, SubworkflowUnit } from "./units";
|
|
6
6
|
import { UnitFactory } from "./units/factory";
|
|
7
7
|
import { defaultMapConfig } from "./units/MapUnit";
|
|
8
8
|
import * as utils from "./utils";
|
|
@@ -10,4 +10,5 @@ import Workflow from "./Workflow";
|
|
|
10
10
|
export type { OrderedMaterial } from "./context/mixins/MaterialContextMixin";
|
|
11
11
|
export type { MaterialsSet } from "./context/mixins/MaterialsSetContextMixin";
|
|
12
12
|
export type { AnySubworkflowUnit, DefaultSubworkflowUnitType } from "./units/factory";
|
|
13
|
-
export {
|
|
13
|
+
export { repairWorkflow } from "./utils/repair";
|
|
14
|
+
export { Subworkflow, Workflow, UnitFactory, TAB_NAVIGATION_CONFIG, UNIT_NAME_INVALID_CHARS, WORKFLOW_STATUSES, BaseUnit, ExecutionUnit, AssertionUnit, AssignmentUnit, ConditionUnit, ErrorUnit, IOUnit, MapUnit, ReduceUnit, SubworkflowUnit, defaultMapConfig, PointsPathFormDataProvider, globalSettings, utils, };
|
package/dist/js/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.utils = exports.globalSettings = exports.PointsPathFormDataProvider = exports.defaultMapConfig = exports.SubworkflowUnit = exports.ReduceUnit = exports.MapUnit = exports.IOUnit = exports.ConditionUnit = exports.AssignmentUnit = exports.AssertionUnit = exports.ExecutionUnit = exports.BaseUnit = exports.WORKFLOW_STATUSES = exports.UNIT_NAME_INVALID_CHARS = exports.TAB_NAVIGATION_CONFIG = exports.UnitFactory = exports.Workflow = exports.Subworkflow = void 0;
|
|
39
|
+
exports.utils = exports.globalSettings = exports.PointsPathFormDataProvider = exports.defaultMapConfig = exports.SubworkflowUnit = exports.ReduceUnit = exports.MapUnit = exports.IOUnit = exports.ErrorUnit = exports.ConditionUnit = exports.AssignmentUnit = exports.AssertionUnit = exports.ExecutionUnit = exports.BaseUnit = exports.WORKFLOW_STATUSES = exports.UNIT_NAME_INVALID_CHARS = exports.TAB_NAVIGATION_CONFIG = exports.UnitFactory = exports.Workflow = exports.Subworkflow = exports.repairWorkflow = void 0;
|
|
40
40
|
const PointsPathFormDataProvider_1 = __importDefault(require("./context/providers/PointsPath/PointsPathFormDataProvider"));
|
|
41
41
|
exports.PointsPathFormDataProvider = PointsPathFormDataProvider_1.default;
|
|
42
42
|
const settings_1 = require("./context/providers/settings");
|
|
@@ -52,6 +52,7 @@ Object.defineProperty(exports, "AssertionUnit", { enumerable: true, get: functio
|
|
|
52
52
|
Object.defineProperty(exports, "AssignmentUnit", { enumerable: true, get: function () { return units_1.AssignmentUnit; } });
|
|
53
53
|
Object.defineProperty(exports, "BaseUnit", { enumerable: true, get: function () { return units_1.BaseUnit; } });
|
|
54
54
|
Object.defineProperty(exports, "ConditionUnit", { enumerable: true, get: function () { return units_1.ConditionUnit; } });
|
|
55
|
+
Object.defineProperty(exports, "ErrorUnit", { enumerable: true, get: function () { return units_1.ErrorUnit; } });
|
|
55
56
|
Object.defineProperty(exports, "ExecutionUnit", { enumerable: true, get: function () { return units_1.ExecutionUnit; } });
|
|
56
57
|
Object.defineProperty(exports, "IOUnit", { enumerable: true, get: function () { return units_1.IOUnit; } });
|
|
57
58
|
Object.defineProperty(exports, "MapUnit", { enumerable: true, get: function () { return units_1.MapUnit; } });
|
|
@@ -65,3 +66,5 @@ const utils = __importStar(require("./utils"));
|
|
|
65
66
|
exports.utils = utils;
|
|
66
67
|
const Workflow_1 = __importDefault(require("./Workflow"));
|
|
67
68
|
exports.Workflow = Workflow_1.default;
|
|
69
|
+
var repair_1 = require("./utils/repair");
|
|
70
|
+
Object.defineProperty(exports, "repairWorkflow", { enumerable: true, get: function () { return repair_1.repairWorkflow; } });
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ErrorUnitSchema } from "@mat3ra/esse/dist/js/types";
|
|
2
|
+
import type { AnySubworkflowUnitSchema } from "../units/factory";
|
|
3
|
+
export declare function createErrorUnitData(unitData: AnySubworkflowUnitSchema | Record<string, unknown>, reason: string): ErrorUnitSchema;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createErrorUnitData = createErrorUnitData;
|
|
4
|
+
const utils_1 = require("@mat3ra/utils");
|
|
5
|
+
const enums_1 = require("../enums");
|
|
6
|
+
function createErrorUnitData(unitData, reason) {
|
|
7
|
+
const original = structuredClone(unitData);
|
|
8
|
+
return {
|
|
9
|
+
results: [],
|
|
10
|
+
preProcessors: [],
|
|
11
|
+
postProcessors: [],
|
|
12
|
+
monitors: [],
|
|
13
|
+
name: typeof original.name === "string" ? original.name : enums_1.UnitType.error,
|
|
14
|
+
type: enums_1.UnitType.error,
|
|
15
|
+
status: enums_1.UnitStatus.error,
|
|
16
|
+
flowchartId: typeof original.flowchartId === "string" ? original.flowchartId : utils_1.Utils.uuid.getUUID(),
|
|
17
|
+
originalUnit: original,
|
|
18
|
+
reason,
|
|
19
|
+
...(typeof original._id === "string" ? { _id: original._id } : {}),
|
|
20
|
+
...(typeof original.next === "string" ? { next: original.next } : {}),
|
|
21
|
+
...(original.head === true ? { head: true } : {}),
|
|
22
|
+
...(Array.isArray(original.statusTrack) ? { statusTrack: original.statusTrack } : {}),
|
|
23
|
+
...(Array.isArray(original.tags) ? { tags: original.tags } : {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatRepairReason(error: unknown): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatRepairReason = formatRepairReason;
|
|
4
|
+
function formatRepairReason(error) {
|
|
5
|
+
var _a;
|
|
6
|
+
if (error && typeof error === "object") {
|
|
7
|
+
const entityError = error;
|
|
8
|
+
if (((_a = entityError.details) === null || _a === void 0 ? void 0 : _a.error) !== undefined) {
|
|
9
|
+
return JSON.stringify(entityError.details.error);
|
|
10
|
+
}
|
|
11
|
+
if (typeof entityError.message === "string" && entityError.message.length > 0) {
|
|
12
|
+
return entityError.message;
|
|
13
|
+
}
|
|
14
|
+
if (typeof entityError.code === "string" && entityError.code.length > 0) {
|
|
15
|
+
return entityError.code;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
return error.message;
|
|
20
|
+
}
|
|
21
|
+
return String(error);
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SubworkflowSchema, WorkflowSchema } from "@mat3ra/esse/dist/js/types";
|
|
2
|
+
export type SubworkflowUnitRepairRecord = {
|
|
3
|
+
subworkflowId: string;
|
|
4
|
+
flowchartId: string;
|
|
5
|
+
reason: string;
|
|
6
|
+
};
|
|
7
|
+
export type SubworkflowRepairResult = {
|
|
8
|
+
document: SubworkflowSchema;
|
|
9
|
+
changed: boolean;
|
|
10
|
+
repairs: SubworkflowUnitRepairRecord[];
|
|
11
|
+
};
|
|
12
|
+
export type WorkflowRepairResult = {
|
|
13
|
+
document: WorkflowSchema;
|
|
14
|
+
changed: boolean;
|
|
15
|
+
repairs: SubworkflowUnitRepairRecord[];
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
|
|
2
|
+
import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
|
|
3
|
+
import type { ErrorUnitSchema } from "@mat3ra/esse/dist/js/types";
|
|
4
|
+
import { type ErrorUnitSchemaMixin } from "../generated/ErrorUnitSchemaMixin";
|
|
5
|
+
import BaseUnit from "./BaseUnit";
|
|
6
|
+
type Schema = ErrorUnitSchema;
|
|
7
|
+
type Base = typeof BaseUnit<Schema> & Constructor<ErrorUnitSchemaMixin>;
|
|
8
|
+
export type ErrorUnitConfig = Partial<Schema>;
|
|
9
|
+
declare const ErrorUnit_base: Base;
|
|
10
|
+
declare class ErrorUnit extends ErrorUnit_base implements Schema {
|
|
11
|
+
toJSON: () => Schema & AnyObject;
|
|
12
|
+
_json: Schema & AnyObject;
|
|
13
|
+
static get jsonSchema(): import("json-schema").JSONSchema7 | undefined;
|
|
14
|
+
constructor(config: ErrorUnitConfig);
|
|
15
|
+
}
|
|
16
|
+
export default ErrorUnit;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const JSONSchemasInterface_1 = __importDefault(require("@mat3ra/esse/dist/js/esse/JSONSchemasInterface"));
|
|
7
|
+
const enums_1 = require("../enums");
|
|
8
|
+
const ErrorUnitSchemaMixin_1 = require("../generated/ErrorUnitSchemaMixin");
|
|
9
|
+
const BaseUnit_1 = __importDefault(require("./BaseUnit"));
|
|
10
|
+
class ErrorUnit extends BaseUnit_1.default {
|
|
11
|
+
static get jsonSchema() {
|
|
12
|
+
return JSONSchemasInterface_1.default.getSchemaById("workflow/unit/error");
|
|
13
|
+
}
|
|
14
|
+
constructor(config) {
|
|
15
|
+
var _a;
|
|
16
|
+
const schema = {
|
|
17
|
+
name: enums_1.UnitType.error,
|
|
18
|
+
results: [],
|
|
19
|
+
preProcessors: [],
|
|
20
|
+
postProcessors: [],
|
|
21
|
+
monitors: [],
|
|
22
|
+
reason: "",
|
|
23
|
+
...config,
|
|
24
|
+
type: enums_1.UnitType.error,
|
|
25
|
+
status: (_a = config.status) !== null && _a !== void 0 ? _a : enums_1.UnitStatus.error,
|
|
26
|
+
};
|
|
27
|
+
super(schema);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
(0, ErrorUnitSchemaMixin_1.errorUnitSchemaMixin)(ErrorUnit.prototype);
|
|
31
|
+
exports.default = ErrorUnit;
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import type { AssertionUnitSchema, AssignmentUnitSchema, ConditionUnitSchema, DataIOUnitSchema, ExecutionUnitSchema, MapUnitSchema, ReduceUnitSchema, SubworkflowUnitSchema, WorkflowUnitSchema } from "@mat3ra/esse/dist/js/types";
|
|
1
|
+
import type { ApplicationSchema, AssertionUnitSchema, AssignmentUnitSchema, ConditionUnitSchema, DataIOUnitSchema, ErrorUnitSchema, ExecutionUnitSchema, MapUnitSchema, ReduceUnitSchema, SubworkflowUnitSchema, WorkflowUnitSchema } from "@mat3ra/esse/dist/js/types";
|
|
2
2
|
import AssertionUnit, { type AssertionUnitConfig } from "./AssertionUnit";
|
|
3
3
|
import AssignmentUnit, { type AssignmentUnitConfig } from "./AssignmentUnit";
|
|
4
4
|
import ConditionUnit, { type ConditionUnitConfig } from "./ConditionUnit";
|
|
5
|
+
import ErrorUnit, { type ErrorUnitConfig } from "./ErrorUnit";
|
|
5
6
|
import ExecutionUnit, { type ExecutionUnitConfig } from "./ExecutionUnit";
|
|
6
7
|
import IOUnit, { type IOUnitConfig } from "./IOUnit";
|
|
7
8
|
import MapUnit from "./MapUnit";
|
|
8
9
|
import ReduceUnit from "./ReduceUnit";
|
|
9
10
|
import SubworkflowUnit from "./SubworkflowUnit";
|
|
10
|
-
export type AnyWorkflowUnit = MapUnit | SubworkflowUnit | ReduceUnit;
|
|
11
|
-
export type AnyWorkflowUnitSchema = MapUnitSchema | SubworkflowUnitSchema | ReduceUnitSchema;
|
|
12
|
-
export type AnySubworkflowUnit = ExecutionUnit | AssignmentUnit | ConditionUnit | IOUnit | AssertionUnit;
|
|
13
|
-
export type AnySubworkflowUnitSchema = ExecutionUnitSchema | AssertionUnitSchema | AssignmentUnitSchema | ConditionUnitSchema | DataIOUnitSchema;
|
|
11
|
+
export type AnyWorkflowUnit = MapUnit | SubworkflowUnit | ReduceUnit | ErrorUnit;
|
|
12
|
+
export type AnyWorkflowUnitSchema = MapUnitSchema | SubworkflowUnitSchema | ReduceUnitSchema | ErrorUnitSchema;
|
|
13
|
+
export type AnySubworkflowUnit = ExecutionUnit | AssignmentUnit | ConditionUnit | IOUnit | AssertionUnit | ErrorUnit;
|
|
14
|
+
export type AnySubworkflowUnitSchema = ExecutionUnitSchema | AssertionUnitSchema | AssignmentUnitSchema | ConditionUnitSchema | DataIOUnitSchema | ErrorUnitSchema;
|
|
14
15
|
type ExcutionConfig = ExecutionUnitConfig & Pick<ExecutionUnitSchema, "type">;
|
|
15
16
|
type AssignmentConfig = AssignmentUnitConfig & Pick<AssignmentUnitSchema, "type">;
|
|
16
17
|
type ConditionConfig = ConditionUnitConfig & Pick<ConditionUnitSchema, "type">;
|
|
17
18
|
type IOConfig = IOUnitConfig & Pick<DataIOUnitSchema, "type">;
|
|
18
19
|
type AssertionConfig = AssertionUnitConfig & Pick<AssertionUnitSchema, "type">;
|
|
20
|
+
type ErrorConfig = ErrorUnitConfig & Pick<ErrorUnitSchema, "type">;
|
|
19
21
|
/** Subworkflow unit kinds supported by {@link UnitFactory.createDefaultSubworkflowUnit}. */
|
|
20
22
|
export type DefaultSubworkflowUnitType = "execution" | "assignment" | "condition" | "io" | "assertion";
|
|
21
23
|
export declare class UnitFactory {
|
|
@@ -23,9 +25,12 @@ export declare class UnitFactory {
|
|
|
23
25
|
* Create a new subworkflow unit with fresh `flowchartId` and constructor defaults.
|
|
24
26
|
* For execution units, pass the subworkflow (or parent) `application` JSON.
|
|
25
27
|
*/
|
|
26
|
-
static createDefaultSubworkflowUnit(type: "execution", application:
|
|
27
|
-
static createDefaultSubworkflowUnit(type: "assignment"
|
|
28
|
+
static createDefaultSubworkflowUnit(type: "execution", application: ApplicationSchema): ExecutionUnit;
|
|
29
|
+
static createDefaultSubworkflowUnit(type: "assignment"): AssignmentUnit;
|
|
30
|
+
static createDefaultSubworkflowUnit(type: "condition"): ConditionUnit;
|
|
31
|
+
static createDefaultSubworkflowUnit(type: "io"): IOUnit;
|
|
32
|
+
static createDefaultSubworkflowUnit(type: "assertion"): AssertionUnit;
|
|
28
33
|
static createInWorkflow(config: WorkflowUnitSchema): AnyWorkflowUnit;
|
|
29
|
-
static createInSubworkflow(config: ExcutionConfig | AssignmentConfig | ConditionConfig | IOConfig | AssertionConfig): AnySubworkflowUnit;
|
|
34
|
+
static createInSubworkflow(config: ExcutionConfig | AssignmentConfig | ConditionConfig | IOConfig | AssertionConfig | ErrorConfig): AnySubworkflowUnit;
|
|
30
35
|
}
|
|
31
36
|
export {};
|
package/dist/js/units/factory.js
CHANGED
|
@@ -8,6 +8,7 @@ const enums_1 = require("../enums");
|
|
|
8
8
|
const AssertionUnit_1 = __importDefault(require("./AssertionUnit"));
|
|
9
9
|
const AssignmentUnit_1 = __importDefault(require("./AssignmentUnit"));
|
|
10
10
|
const ConditionUnit_1 = __importDefault(require("./ConditionUnit"));
|
|
11
|
+
const ErrorUnit_1 = __importDefault(require("./ErrorUnit"));
|
|
11
12
|
const ExecutionUnit_1 = __importDefault(require("./ExecutionUnit"));
|
|
12
13
|
const IOUnit_1 = __importDefault(require("./IOUnit"));
|
|
13
14
|
const MapUnit_1 = __importDefault(require("./MapUnit"));
|
|
@@ -47,6 +48,8 @@ class UnitFactory {
|
|
|
47
48
|
return new SubworkflowUnit_1.default(config);
|
|
48
49
|
case enums_1.UnitType.reduce:
|
|
49
50
|
return new ReduceUnit_1.default(config);
|
|
51
|
+
case enums_1.UnitType.error:
|
|
52
|
+
return new ErrorUnit_1.default(config);
|
|
50
53
|
default:
|
|
51
54
|
throw new Error(`Unknown unit type: ${config.type}`);
|
|
52
55
|
}
|
|
@@ -63,6 +66,8 @@ class UnitFactory {
|
|
|
63
66
|
return new IOUnit_1.default(config);
|
|
64
67
|
case enums_1.UnitType.assertion:
|
|
65
68
|
return new AssertionUnit_1.default(config);
|
|
69
|
+
case enums_1.UnitType.error:
|
|
70
|
+
return new ErrorUnit_1.default(config);
|
|
66
71
|
default:
|
|
67
72
|
throw new Error(`Unknown unit type: ${config.type}`);
|
|
68
73
|
}
|
package/dist/js/units/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import AssertionUnit from "./AssertionUnit";
|
|
|
2
2
|
import AssignmentUnit from "./AssignmentUnit";
|
|
3
3
|
import BaseUnit from "./BaseUnit";
|
|
4
4
|
import ConditionUnit from "./ConditionUnit";
|
|
5
|
+
import ErrorUnit from "./ErrorUnit";
|
|
5
6
|
import ExecutionUnit from "./ExecutionUnit";
|
|
6
7
|
import { UnitFactory } from "./factory";
|
|
7
8
|
import IOUnit from "./IOUnit";
|
|
@@ -10,5 +11,5 @@ import ReduceUnit from "./ReduceUnit";
|
|
|
10
11
|
import SubworkflowUnit from "./SubworkflowUnit";
|
|
11
12
|
export type { ReduceUnitConfig } from "./ReduceUnit";
|
|
12
13
|
export type { SubworkflowUnitConfig } from "./SubworkflowUnit";
|
|
13
|
-
export { BaseUnit, AssertionUnit, AssignmentUnit, ConditionUnit, ExecutionUnit, IOUnit, MapUnit, ReduceUnit, SubworkflowUnit, UnitFactory, };
|
|
14
|
+
export { BaseUnit, AssertionUnit, AssignmentUnit, ConditionUnit, ErrorUnit, ExecutionUnit, IOUnit, MapUnit, ReduceUnit, SubworkflowUnit, UnitFactory, };
|
|
14
15
|
export type { DefaultSubworkflowUnitType } from "./factory";
|
package/dist/js/units/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.UnitFactory = exports.SubworkflowUnit = exports.ReduceUnit = exports.MapUnit = exports.IOUnit = exports.ExecutionUnit = exports.ConditionUnit = exports.AssignmentUnit = exports.AssertionUnit = exports.BaseUnit = void 0;
|
|
6
|
+
exports.UnitFactory = exports.SubworkflowUnit = exports.ReduceUnit = exports.MapUnit = exports.IOUnit = exports.ExecutionUnit = exports.ErrorUnit = exports.ConditionUnit = exports.AssignmentUnit = exports.AssertionUnit = exports.BaseUnit = void 0;
|
|
7
7
|
const AssertionUnit_1 = __importDefault(require("./AssertionUnit"));
|
|
8
8
|
exports.AssertionUnit = AssertionUnit_1.default;
|
|
9
9
|
const AssignmentUnit_1 = __importDefault(require("./AssignmentUnit"));
|
|
@@ -12,6 +12,8 @@ const BaseUnit_1 = __importDefault(require("./BaseUnit"));
|
|
|
12
12
|
exports.BaseUnit = BaseUnit_1.default;
|
|
13
13
|
const ConditionUnit_1 = __importDefault(require("./ConditionUnit"));
|
|
14
14
|
exports.ConditionUnit = ConditionUnit_1.default;
|
|
15
|
+
const ErrorUnit_1 = __importDefault(require("./ErrorUnit"));
|
|
16
|
+
exports.ErrorUnit = ErrorUnit_1.default;
|
|
15
17
|
const ExecutionUnit_1 = __importDefault(require("./ExecutionUnit"));
|
|
16
18
|
exports.ExecutionUnit = ExecutionUnit_1.default;
|
|
17
19
|
const factory_1 = require("./factory");
|
package/dist/js/utils/index.d.ts
CHANGED
package/dist/js/utils/index.js
CHANGED
|
@@ -33,7 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.baseUnits = exports.workflow = exports.units = void 0;
|
|
36
|
+
exports.repair = exports.baseUnits = exports.workflow = exports.units = void 0;
|
|
37
37
|
exports.units = __importStar(require("./units"));
|
|
38
38
|
exports.workflow = __importStar(require("./workflow"));
|
|
39
39
|
exports.baseUnits = __importStar(require("./baseUnits"));
|
|
40
|
+
exports.repair = __importStar(require("./repair"));
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.repairWorkflow = repairWorkflow;
|
|
7
|
+
const in_memory_1 = require("@mat3ra/code/dist/js/entity/in_memory");
|
|
8
|
+
const utils_1 = require("@mat3ra/utils");
|
|
9
|
+
const enums_1 = require("../enums");
|
|
10
|
+
const Subworkflow_1 = __importDefault(require("../Subworkflow"));
|
|
11
|
+
const ConditionUnit_1 = __importDefault(require("../units/ConditionUnit"));
|
|
12
|
+
const ExecutionUnit_1 = __importDefault(require("../units/ExecutionUnit"));
|
|
13
|
+
function toErrorUnitSchema(unitData, error) {
|
|
14
|
+
var _a, _b, _c, _d;
|
|
15
|
+
let reasonPayload;
|
|
16
|
+
if (error instanceof in_memory_1.EntityError && error.details) {
|
|
17
|
+
reasonPayload = {
|
|
18
|
+
error: error.details.error,
|
|
19
|
+
json: unitData,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
else if (error instanceof Error) {
|
|
23
|
+
reasonPayload = {
|
|
24
|
+
error: { message: error.message, name: error.name },
|
|
25
|
+
json: unitData,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
reasonPayload = {
|
|
30
|
+
error,
|
|
31
|
+
json: unitData,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
results: [],
|
|
36
|
+
preProcessors: [],
|
|
37
|
+
postProcessors: [],
|
|
38
|
+
monitors: [],
|
|
39
|
+
name: (_a = unitData.name) !== null && _a !== void 0 ? _a : enums_1.UnitType.error,
|
|
40
|
+
type: enums_1.UnitType.error,
|
|
41
|
+
status: enums_1.UnitStatus.error,
|
|
42
|
+
flowchartId: (_b = unitData.flowchartId) !== null && _b !== void 0 ? _b : utils_1.Utils.uuid.getUUID(),
|
|
43
|
+
reason: JSON.stringify(reasonPayload),
|
|
44
|
+
next: (_c = unitData.next) !== null && _c !== void 0 ? _c : "",
|
|
45
|
+
head: (_d = unitData.head) !== null && _d !== void 0 ? _d : false,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function repairExecutionUnit(unitData) {
|
|
49
|
+
try {
|
|
50
|
+
return new ExecutionUnit_1.default(unitData).toJSON();
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return toErrorUnitSchema(unitData, error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function repairConditionUnit(unitData) {
|
|
57
|
+
try {
|
|
58
|
+
return new ConditionUnit_1.default(unitData).toJSON();
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return toErrorUnitSchema(unitData, error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function getSubworkflowValidationError(subworkflow) {
|
|
65
|
+
// Two checks, same order as the old isValid() path (construct + validate), but split so we
|
|
66
|
+
// keep AJV errors when hydration would fail first:
|
|
67
|
+
// 1. validateData — JSON Schema on raw persisted subworkflow (no Application/ModelFactory/units).
|
|
68
|
+
// Surfaces structured AJV errors (e.g. missing model) before the constructor runs.
|
|
69
|
+
// 2. new Subworkflow().validate() — hydration (app, model, units) then schema on the instance.
|
|
70
|
+
// Catches schema-valid JSON that still cannot be built (unknown model, bad units, etc.).
|
|
71
|
+
try {
|
|
72
|
+
Subworkflow_1.default.validateData({ ...subworkflow });
|
|
73
|
+
new Subworkflow_1.default(subworkflow).validate();
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error instanceof in_memory_1.EntityError || error instanceof Error) {
|
|
78
|
+
return error;
|
|
79
|
+
}
|
|
80
|
+
return new Error(String(error));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function repairSubworkflow(subworkflowData) {
|
|
84
|
+
const units = subworkflowData.units.map((unit) => {
|
|
85
|
+
if (unit.type === enums_1.UnitType.execution) {
|
|
86
|
+
return repairExecutionUnit(unit);
|
|
87
|
+
}
|
|
88
|
+
if (unit.type === enums_1.UnitType.condition) {
|
|
89
|
+
return repairConditionUnit(unit);
|
|
90
|
+
}
|
|
91
|
+
return unit;
|
|
92
|
+
});
|
|
93
|
+
return { ...subworkflowData, units };
|
|
94
|
+
}
|
|
95
|
+
function repairWorkflow(workflowData) {
|
|
96
|
+
const subworkflows = workflowData.subworkflows.map((subworkflow) => {
|
|
97
|
+
return repairSubworkflow(subworkflow);
|
|
98
|
+
});
|
|
99
|
+
const invalidSubworkflows = subworkflows
|
|
100
|
+
.map((subworkflow) => {
|
|
101
|
+
const error = getSubworkflowValidationError(subworkflow);
|
|
102
|
+
return error ? { subworkflow, error } : null;
|
|
103
|
+
})
|
|
104
|
+
.filter((entry) => entry !== null);
|
|
105
|
+
const units = workflowData.units.map((unit) => {
|
|
106
|
+
const invalidEntry = invalidSubworkflows.find(({ subworkflow }) => subworkflow._id === unit._id);
|
|
107
|
+
if (invalidEntry) {
|
|
108
|
+
const { subworkflow, error } = invalidEntry;
|
|
109
|
+
const errorUnit = toErrorUnitSchema(unit, error);
|
|
110
|
+
const reasonPayload = {
|
|
111
|
+
...JSON.parse(errorUnit.reason),
|
|
112
|
+
json: { unit, subworkflow },
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
...errorUnit,
|
|
116
|
+
_id: unit._id,
|
|
117
|
+
name: unit.name || errorUnit.name,
|
|
118
|
+
flowchartId: unit.flowchartId,
|
|
119
|
+
reason: JSON.stringify(reasonPayload),
|
|
120
|
+
preProcessors: unit.preProcessors || [],
|
|
121
|
+
postProcessors: unit.postProcessors || [],
|
|
122
|
+
monitors: unit.monitors || [],
|
|
123
|
+
results: unit.results || [],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return unit;
|
|
127
|
+
});
|
|
128
|
+
const validSubworkflows = subworkflows.filter((subworkflow) => {
|
|
129
|
+
return !invalidSubworkflows.some(({ subworkflow: invalid }) => invalid._id === subworkflow._id);
|
|
130
|
+
});
|
|
131
|
+
const workflows = workflowData.workflows.map((nested) => {
|
|
132
|
+
return repairWorkflow(nested);
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
...workflowData,
|
|
136
|
+
subworkflows: validSubworkflows,
|
|
137
|
+
workflows,
|
|
138
|
+
units,
|
|
139
|
+
};
|
|
140
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mat3ra/wode",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.6.16-0",
|
|
4
4
|
"description": "WOrkflow DEfinitions",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "mocha --recursive --bail --require ts-node/register 'tests/js/**/*.ts'",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@exabyte-io/eslint-config": "2025.5.13-0",
|
|
43
43
|
"@mat3ra/ade": "2026.5.28-0",
|
|
44
44
|
"@mat3ra/code": "2026.5.27-0",
|
|
45
|
-
"@mat3ra/esse": "2026.
|
|
45
|
+
"@mat3ra/esse": "2026.6.16-0",
|
|
46
46
|
"@mat3ra/ide": "2026.5.28-0",
|
|
47
47
|
"@mat3ra/made": "2026.5.28-0",
|
|
48
48
|
"@mat3ra/mode": "2026.5.29-1",
|
|
@@ -50,6 +50,8 @@
|
|
|
50
50
|
"@mat3ra/standata": "2026.5.28-0",
|
|
51
51
|
"@mat3ra/tsconfig": "^2024.6.3-0",
|
|
52
52
|
"@mat3ra/utils": "2025.9.20-0",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
54
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
53
55
|
"@types/nunjucks": "^3.2.6",
|
|
54
56
|
"chai": "^4.3.4",
|
|
55
57
|
"eslint": "^7.32.0",
|
|
@@ -76,7 +78,7 @@
|
|
|
76
78
|
"peerDependencies": {
|
|
77
79
|
"@mat3ra/ade": "*",
|
|
78
80
|
"@mat3ra/code": "*",
|
|
79
|
-
"@mat3ra/esse": "
|
|
81
|
+
"@mat3ra/esse": "file:../esse/mat3ra-esse-0.0.0.tgz",
|
|
80
82
|
"@mat3ra/ide": "*",
|
|
81
83
|
"@mat3ra/made": "*",
|
|
82
84
|
"@mat3ra/mode": "*",
|
package/src/js/Subworkflow.ts
CHANGED
|
@@ -100,13 +100,18 @@ class Subworkflow extends InMemoryEntity implements SubworkflowSchema {
|
|
|
100
100
|
|
|
101
101
|
static get defaultConfig() {
|
|
102
102
|
const defaultName = "New Subworkflow";
|
|
103
|
+
const application = new ApplicationRegistry().getDefaultApplication();
|
|
104
|
+
|
|
105
|
+
if (!application) {
|
|
106
|
+
throw new Error("No default application found");
|
|
107
|
+
}
|
|
108
|
+
|
|
103
109
|
return {
|
|
104
110
|
_id: Utils.uuid.getUUID(),
|
|
105
111
|
name: defaultName,
|
|
106
|
-
application
|
|
107
|
-
// TODO: confirm if `functional` is required field. If not, update ESSE schema
|
|
112
|
+
application,
|
|
108
113
|
// `Model.defaultConfig` from @mat3ra/mode may omit `functional`; ESSE subworkflow schema requires it once schemas are registered.
|
|
109
|
-
model: { ...Model.defaultConfig, functional: "pbe" },
|
|
114
|
+
model: { ...Model.defaultConfig, functional: "pbe" as const },
|
|
110
115
|
properties: [],
|
|
111
116
|
units: [],
|
|
112
117
|
};
|
package/src/js/Workflow.ts
CHANGED
|
@@ -15,11 +15,7 @@ import { namedEntityMixin } from "@mat3ra/code/dist/js/entity/mixins/NamedEntity
|
|
|
15
15
|
import { Taggable, taggableMixin } from "@mat3ra/code/dist/js/entity/mixins/TaggableMixin";
|
|
16
16
|
import JSONSchemasInterface from "@mat3ra/esse/dist/js/esse/JSONSchemasInterface";
|
|
17
17
|
import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
|
|
18
|
-
import type {
|
|
19
|
-
ApplicationSchema,
|
|
20
|
-
SubworkflowSchema,
|
|
21
|
-
WorkflowSchema,
|
|
22
|
-
} from "@mat3ra/esse/dist/js/types";
|
|
18
|
+
import type { ApplicationSchema, SubworkflowSchema } from "@mat3ra/esse/dist/js/types";
|
|
23
19
|
import { ComputedEntityMixin, computedEntityMixin } from "@mat3ra/ide/dist/js/compute";
|
|
24
20
|
import type { Material } from "@mat3ra/made";
|
|
25
21
|
import type { MetaPropertyHolder } from "@mat3ra/prode";
|
|
@@ -45,6 +41,7 @@ import {
|
|
|
45
41
|
getUsedModels,
|
|
46
42
|
} from "./utils/workflow";
|
|
47
43
|
import defaultWorkflowConfig from "./workflows/default";
|
|
44
|
+
import type { WorkflowSchema } from "./workflows/types";
|
|
48
45
|
|
|
49
46
|
interface Workflow
|
|
50
47
|
extends Defaultable,
|
|
@@ -9,7 +9,7 @@ export type MaterialContextMixin = {
|
|
|
9
9
|
readonly isMaterialCreatedDefault: boolean;
|
|
10
10
|
readonly isMaterialUpdated: boolean;
|
|
11
11
|
material: OrderedMaterial;
|
|
12
|
-
extraData?: { materialHash
|
|
12
|
+
extraData?: { materialHash?: string };
|
|
13
13
|
initMaterialContextMixin(externalContext: MaterialExternalContext): void;
|
|
14
14
|
updateMaterialHash(): void;
|
|
15
15
|
};
|
package/src/js/enums.ts
CHANGED
|
@@ -11,6 +11,7 @@ export const UNIT_TYPES = {
|
|
|
11
11
|
subworkflow: "subworkflow",
|
|
12
12
|
io: "io",
|
|
13
13
|
assertion: "assertion",
|
|
14
|
+
error: "error",
|
|
14
15
|
} as const;
|
|
15
16
|
|
|
16
17
|
export enum UnitType {
|
|
@@ -24,6 +25,7 @@ export enum UnitType {
|
|
|
24
25
|
subworkflow = "subworkflow",
|
|
25
26
|
io = "io",
|
|
26
27
|
assertion = "assertion",
|
|
28
|
+
error = "error",
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export enum UnitTag {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
2
|
+
import type { ErrorUnitMixinSchema } from "@mat3ra/esse/dist/js/types";
|
|
3
|
+
|
|
4
|
+
export type ErrorUnitSchemaMixin = ErrorUnitMixinSchema;
|
|
5
|
+
|
|
6
|
+
export type ErrorUnitInMemoryEntity = InMemoryEntity & ErrorUnitSchemaMixin;
|
|
7
|
+
|
|
8
|
+
export function errorUnitSchemaMixin<T extends InMemoryEntity>(
|
|
9
|
+
item: InMemoryEntity,
|
|
10
|
+
): asserts item is T & ErrorUnitSchemaMixin {
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
const properties: InMemoryEntity & ErrorUnitSchemaMixin = {
|
|
13
|
+
get type() {
|
|
14
|
+
return this.prop<ErrorUnitMixinSchema["type"]>("type");
|
|
15
|
+
},
|
|
16
|
+
set type(value: ErrorUnitMixinSchema["type"]) {
|
|
17
|
+
this.setProp("type", value);
|
|
18
|
+
},
|
|
19
|
+
get reason() {
|
|
20
|
+
return this.requiredProp<ErrorUnitMixinSchema["reason"]>("reason");
|
|
21
|
+
},
|
|
22
|
+
set reason(value: ErrorUnitMixinSchema["reason"]) {
|
|
23
|
+
this.setProp("reason", value);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
|
|
28
|
+
}
|
package/src/js/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
AssignmentUnit,
|
|
8
8
|
BaseUnit,
|
|
9
9
|
ConditionUnit,
|
|
10
|
+
ErrorUnit,
|
|
10
11
|
ExecutionUnit,
|
|
11
12
|
IOUnit,
|
|
12
13
|
MapUnit,
|
|
@@ -21,6 +22,7 @@ import Workflow from "./Workflow";
|
|
|
21
22
|
export type { OrderedMaterial } from "./context/mixins/MaterialContextMixin";
|
|
22
23
|
export type { MaterialsSet } from "./context/mixins/MaterialsSetContextMixin";
|
|
23
24
|
export type { AnySubworkflowUnit, DefaultSubworkflowUnitType } from "./units/factory";
|
|
25
|
+
export { repairWorkflow } from "./utils/repair";
|
|
24
26
|
export {
|
|
25
27
|
Subworkflow,
|
|
26
28
|
Workflow,
|
|
@@ -33,6 +35,7 @@ export {
|
|
|
33
35
|
AssertionUnit,
|
|
34
36
|
AssignmentUnit,
|
|
35
37
|
ConditionUnit,
|
|
38
|
+
ErrorUnit,
|
|
36
39
|
IOUnit,
|
|
37
40
|
MapUnit,
|
|
38
41
|
ReduceUnit,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
|
|
2
|
+
import JSONSchemasInterface from "@mat3ra/esse/dist/js/esse/JSONSchemasInterface";
|
|
3
|
+
import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
|
|
4
|
+
import type { ErrorUnitSchema } from "@mat3ra/esse/dist/js/types";
|
|
5
|
+
|
|
6
|
+
import { UnitStatus, UnitType } from "../enums";
|
|
7
|
+
import { type ErrorUnitSchemaMixin, errorUnitSchemaMixin } from "../generated/ErrorUnitSchemaMixin";
|
|
8
|
+
import BaseUnit from "./BaseUnit";
|
|
9
|
+
|
|
10
|
+
type Schema = ErrorUnitSchema;
|
|
11
|
+
type Base = typeof BaseUnit<Schema> & Constructor<ErrorUnitSchemaMixin>;
|
|
12
|
+
|
|
13
|
+
export type ErrorUnitConfig = Partial<Schema>;
|
|
14
|
+
|
|
15
|
+
class ErrorUnit extends (BaseUnit as Base) implements Schema {
|
|
16
|
+
declare toJSON: () => Schema & AnyObject;
|
|
17
|
+
|
|
18
|
+
declare _json: Schema & AnyObject;
|
|
19
|
+
|
|
20
|
+
static get jsonSchema() {
|
|
21
|
+
return JSONSchemasInterface.getSchemaById("workflow/unit/error");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
constructor(config: ErrorUnitConfig) {
|
|
25
|
+
const schema = {
|
|
26
|
+
name: UnitType.error,
|
|
27
|
+
results: [],
|
|
28
|
+
preProcessors: [],
|
|
29
|
+
postProcessors: [],
|
|
30
|
+
monitors: [],
|
|
31
|
+
reason: "",
|
|
32
|
+
...config,
|
|
33
|
+
type: UnitType.error as Schema["type"],
|
|
34
|
+
status: config.status ?? UnitStatus.error,
|
|
35
|
+
};
|
|
36
|
+
super(schema);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
errorUnitSchemaMixin(ErrorUnit.prototype);
|
|
41
|
+
|
|
42
|
+
export default ErrorUnit;
|
package/src/js/units/factory.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ApplicationSchema,
|
|
2
3
|
AssertionUnitSchema,
|
|
3
4
|
AssignmentUnitSchema,
|
|
4
5
|
ConditionUnitSchema,
|
|
5
6
|
DataIOUnitSchema,
|
|
7
|
+
ErrorUnitSchema,
|
|
6
8
|
ExecutionUnitSchema,
|
|
7
9
|
MapUnitSchema,
|
|
8
10
|
ReduceUnitSchema,
|
|
@@ -14,35 +16,43 @@ import { UnitType } from "../enums";
|
|
|
14
16
|
import AssertionUnit, { type AssertionUnitConfig } from "./AssertionUnit";
|
|
15
17
|
import AssignmentUnit, { type AssignmentUnitConfig } from "./AssignmentUnit";
|
|
16
18
|
import ConditionUnit, { type ConditionUnitConfig } from "./ConditionUnit";
|
|
19
|
+
import ErrorUnit, { type ErrorUnitConfig } from "./ErrorUnit";
|
|
17
20
|
import ExecutionUnit, { type ExecutionUnitConfig } from "./ExecutionUnit";
|
|
18
21
|
import IOUnit, { type IOUnitConfig } from "./IOUnit";
|
|
19
22
|
import MapUnit from "./MapUnit";
|
|
20
23
|
import ReduceUnit from "./ReduceUnit";
|
|
21
24
|
import SubworkflowUnit from "./SubworkflowUnit";
|
|
22
25
|
|
|
23
|
-
export type AnyWorkflowUnit = MapUnit | SubworkflowUnit | ReduceUnit;
|
|
26
|
+
export type AnyWorkflowUnit = MapUnit | SubworkflowUnit | ReduceUnit | ErrorUnit;
|
|
24
27
|
|
|
25
|
-
export type AnyWorkflowUnitSchema =
|
|
28
|
+
export type AnyWorkflowUnitSchema =
|
|
29
|
+
| MapUnitSchema
|
|
30
|
+
| SubworkflowUnitSchema
|
|
31
|
+
| ReduceUnitSchema
|
|
32
|
+
| ErrorUnitSchema;
|
|
26
33
|
|
|
27
34
|
export type AnySubworkflowUnit =
|
|
28
35
|
| ExecutionUnit
|
|
29
36
|
| AssignmentUnit
|
|
30
37
|
| ConditionUnit
|
|
31
38
|
| IOUnit
|
|
32
|
-
| AssertionUnit
|
|
39
|
+
| AssertionUnit
|
|
40
|
+
| ErrorUnit;
|
|
33
41
|
|
|
34
42
|
export type AnySubworkflowUnitSchema =
|
|
35
43
|
| ExecutionUnitSchema
|
|
36
44
|
| AssertionUnitSchema
|
|
37
45
|
| AssignmentUnitSchema
|
|
38
46
|
| ConditionUnitSchema
|
|
39
|
-
| DataIOUnitSchema
|
|
47
|
+
| DataIOUnitSchema
|
|
48
|
+
| ErrorUnitSchema;
|
|
40
49
|
|
|
41
50
|
type ExcutionConfig = ExecutionUnitConfig & Pick<ExecutionUnitSchema, "type">;
|
|
42
51
|
type AssignmentConfig = AssignmentUnitConfig & Pick<AssignmentUnitSchema, "type">;
|
|
43
52
|
type ConditionConfig = ConditionUnitConfig & Pick<ConditionUnitSchema, "type">;
|
|
44
53
|
type IOConfig = IOUnitConfig & Pick<DataIOUnitSchema, "type">;
|
|
45
54
|
type AssertionConfig = AssertionUnitConfig & Pick<AssertionUnitSchema, "type">;
|
|
55
|
+
type ErrorConfig = ErrorUnitConfig & Pick<ErrorUnitSchema, "type">;
|
|
46
56
|
|
|
47
57
|
/** Subworkflow unit kinds supported by {@link UnitFactory.createDefaultSubworkflowUnit}. */
|
|
48
58
|
export type DefaultSubworkflowUnitType =
|
|
@@ -59,16 +69,20 @@ export class UnitFactory {
|
|
|
59
69
|
*/
|
|
60
70
|
static createDefaultSubworkflowUnit(
|
|
61
71
|
type: "execution",
|
|
62
|
-
application:
|
|
63
|
-
):
|
|
72
|
+
application: ApplicationSchema,
|
|
73
|
+
): ExecutionUnit;
|
|
64
74
|
|
|
65
|
-
static createDefaultSubworkflowUnit(
|
|
66
|
-
|
|
67
|
-
):
|
|
75
|
+
static createDefaultSubworkflowUnit(type: "assignment"): AssignmentUnit;
|
|
76
|
+
|
|
77
|
+
static createDefaultSubworkflowUnit(type: "condition"): ConditionUnit;
|
|
78
|
+
|
|
79
|
+
static createDefaultSubworkflowUnit(type: "io"): IOUnit;
|
|
80
|
+
|
|
81
|
+
static createDefaultSubworkflowUnit(type: "assertion"): AssertionUnit;
|
|
68
82
|
|
|
69
83
|
static createDefaultSubworkflowUnit(
|
|
70
84
|
type: DefaultSubworkflowUnitType,
|
|
71
|
-
application?:
|
|
85
|
+
application?: ApplicationSchema,
|
|
72
86
|
): AnySubworkflowUnit {
|
|
73
87
|
if (type === "execution") {
|
|
74
88
|
if (application === undefined) {
|
|
@@ -105,13 +119,21 @@ export class UnitFactory {
|
|
|
105
119
|
return new SubworkflowUnit(config);
|
|
106
120
|
case UnitType.reduce:
|
|
107
121
|
return new ReduceUnit(config);
|
|
122
|
+
case UnitType.error:
|
|
123
|
+
return new ErrorUnit(config);
|
|
108
124
|
default:
|
|
109
125
|
throw new Error(`Unknown unit type: ${config.type}`);
|
|
110
126
|
}
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
static createInSubworkflow(
|
|
114
|
-
config:
|
|
130
|
+
config:
|
|
131
|
+
| ExcutionConfig
|
|
132
|
+
| AssignmentConfig
|
|
133
|
+
| ConditionConfig
|
|
134
|
+
| IOConfig
|
|
135
|
+
| AssertionConfig
|
|
136
|
+
| ErrorConfig,
|
|
115
137
|
): AnySubworkflowUnit {
|
|
116
138
|
switch (config.type) {
|
|
117
139
|
case UnitType.execution:
|
|
@@ -124,6 +146,8 @@ export class UnitFactory {
|
|
|
124
146
|
return new IOUnit(config);
|
|
125
147
|
case UnitType.assertion:
|
|
126
148
|
return new AssertionUnit(config);
|
|
149
|
+
case UnitType.error:
|
|
150
|
+
return new ErrorUnit(config);
|
|
127
151
|
default:
|
|
128
152
|
throw new Error(`Unknown unit type: ${config.type}`);
|
|
129
153
|
}
|
package/src/js/units/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import AssertionUnit from "./AssertionUnit";
|
|
|
2
2
|
import AssignmentUnit from "./AssignmentUnit";
|
|
3
3
|
import BaseUnit from "./BaseUnit";
|
|
4
4
|
import ConditionUnit from "./ConditionUnit";
|
|
5
|
+
import ErrorUnit from "./ErrorUnit";
|
|
5
6
|
import ExecutionUnit from "./ExecutionUnit";
|
|
6
7
|
import { UnitFactory } from "./factory";
|
|
7
8
|
import IOUnit from "./IOUnit";
|
|
@@ -16,6 +17,7 @@ export {
|
|
|
16
17
|
AssertionUnit,
|
|
17
18
|
AssignmentUnit,
|
|
18
19
|
ConditionUnit,
|
|
20
|
+
ErrorUnit,
|
|
19
21
|
ExecutionUnit,
|
|
20
22
|
IOUnit,
|
|
21
23
|
MapUnit,
|
package/src/js/utils/index.ts
CHANGED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { EntityError } from "@mat3ra/code/dist/js/entity/in_memory";
|
|
2
|
+
import type {
|
|
3
|
+
ConditionUnitSchema,
|
|
4
|
+
ErrorUnitSchema,
|
|
5
|
+
ExecutionUnitSchema,
|
|
6
|
+
SubworkflowSchema,
|
|
7
|
+
WorkflowBaseUnitSchema,
|
|
8
|
+
} from "@mat3ra/esse/dist/js/types";
|
|
9
|
+
import { Utils } from "@mat3ra/utils";
|
|
10
|
+
|
|
11
|
+
import { UnitStatus, UnitType } from "../enums";
|
|
12
|
+
import Subworkflow from "../Subworkflow";
|
|
13
|
+
import ConditionUnit from "../units/ConditionUnit";
|
|
14
|
+
import ExecutionUnit from "../units/ExecutionUnit";
|
|
15
|
+
import type { AnyWorkflowUnitSchema } from "../units/factory";
|
|
16
|
+
import type { WorkflowSchema } from "../workflows/types";
|
|
17
|
+
|
|
18
|
+
function toErrorUnitSchema(
|
|
19
|
+
unitData: Partial<WorkflowBaseUnitSchema>,
|
|
20
|
+
error: unknown,
|
|
21
|
+
): ErrorUnitSchema {
|
|
22
|
+
let reasonPayload: { error: unknown; json: object };
|
|
23
|
+
|
|
24
|
+
if (error instanceof EntityError && error.details) {
|
|
25
|
+
reasonPayload = {
|
|
26
|
+
error: error.details.error,
|
|
27
|
+
json: unitData as object,
|
|
28
|
+
};
|
|
29
|
+
} else if (error instanceof Error) {
|
|
30
|
+
reasonPayload = {
|
|
31
|
+
error: { message: error.message, name: error.name },
|
|
32
|
+
json: unitData as object,
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
reasonPayload = {
|
|
36
|
+
error,
|
|
37
|
+
json: unitData as object,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
results: [],
|
|
43
|
+
preProcessors: [],
|
|
44
|
+
postProcessors: [],
|
|
45
|
+
monitors: [],
|
|
46
|
+
name: unitData.name ?? UnitType.error,
|
|
47
|
+
type: UnitType.error,
|
|
48
|
+
status: UnitStatus.error,
|
|
49
|
+
flowchartId: unitData.flowchartId ?? Utils.uuid.getUUID(),
|
|
50
|
+
reason: JSON.stringify(reasonPayload),
|
|
51
|
+
next: unitData.next ?? "",
|
|
52
|
+
head: unitData.head ?? false,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function repairExecutionUnit(
|
|
57
|
+
unitData: Partial<ExecutionUnitSchema>,
|
|
58
|
+
): ExecutionUnitSchema | ErrorUnitSchema {
|
|
59
|
+
try {
|
|
60
|
+
return new ExecutionUnit(unitData as ExecutionUnitSchema).toJSON();
|
|
61
|
+
} catch (error: unknown) {
|
|
62
|
+
return toErrorUnitSchema(unitData as Partial<WorkflowBaseUnitSchema>, error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function repairConditionUnit(
|
|
67
|
+
unitData: Partial<ConditionUnitSchema>,
|
|
68
|
+
): ConditionUnitSchema | ErrorUnitSchema {
|
|
69
|
+
try {
|
|
70
|
+
return new ConditionUnit(unitData as ConditionUnitSchema).toJSON();
|
|
71
|
+
} catch (error: unknown) {
|
|
72
|
+
return toErrorUnitSchema(unitData as Partial<WorkflowBaseUnitSchema>, error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getSubworkflowValidationError(subworkflow: SubworkflowSchema): EntityError | Error | null {
|
|
77
|
+
// Two checks, same order as the old isValid() path (construct + validate), but split so we
|
|
78
|
+
// keep AJV errors when hydration would fail first:
|
|
79
|
+
// 1. validateData — JSON Schema on raw persisted subworkflow (no Application/ModelFactory/units).
|
|
80
|
+
// Surfaces structured AJV errors (e.g. missing model) before the constructor runs.
|
|
81
|
+
// 2. new Subworkflow().validate() — hydration (app, model, units) then schema on the instance.
|
|
82
|
+
// Catches schema-valid JSON that still cannot be built (unknown model, bad units, etc.).
|
|
83
|
+
try {
|
|
84
|
+
Subworkflow.validateData({ ...subworkflow });
|
|
85
|
+
new Subworkflow(subworkflow).validate();
|
|
86
|
+
return null;
|
|
87
|
+
} catch (error: unknown) {
|
|
88
|
+
if (error instanceof EntityError || error instanceof Error) {
|
|
89
|
+
return error;
|
|
90
|
+
}
|
|
91
|
+
return new Error(String(error));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function repairSubworkflow(subworkflowData: SubworkflowSchema): SubworkflowSchema {
|
|
96
|
+
const units = subworkflowData.units.map((unit) => {
|
|
97
|
+
if (unit.type === UnitType.execution) {
|
|
98
|
+
return repairExecutionUnit(unit);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (unit.type === UnitType.condition) {
|
|
102
|
+
return repairConditionUnit(unit);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return unit;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return { ...subworkflowData, units };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function repairWorkflow<T extends WorkflowSchema>(workflowData: T): T {
|
|
112
|
+
const subworkflows = workflowData.subworkflows.map((subworkflow) => {
|
|
113
|
+
return repairSubworkflow(subworkflow);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const invalidSubworkflows = subworkflows
|
|
117
|
+
.map((subworkflow) => {
|
|
118
|
+
const error = getSubworkflowValidationError(subworkflow);
|
|
119
|
+
return error ? { subworkflow, error } : null;
|
|
120
|
+
})
|
|
121
|
+
.filter(
|
|
122
|
+
(entry): entry is { subworkflow: SubworkflowSchema; error: EntityError | Error } =>
|
|
123
|
+
entry !== null,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const units = workflowData.units.map((unit): AnyWorkflowUnitSchema => {
|
|
127
|
+
const invalidEntry = invalidSubworkflows.find(
|
|
128
|
+
({ subworkflow }) => subworkflow._id === unit._id,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
if (invalidEntry) {
|
|
132
|
+
const { subworkflow, error } = invalidEntry;
|
|
133
|
+
const errorUnit = toErrorUnitSchema(unit, error);
|
|
134
|
+
const reasonPayload = {
|
|
135
|
+
...JSON.parse(errorUnit.reason),
|
|
136
|
+
json: { unit, subworkflow },
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
...errorUnit,
|
|
141
|
+
_id: unit._id,
|
|
142
|
+
name: unit.name || errorUnit.name,
|
|
143
|
+
flowchartId: unit.flowchartId,
|
|
144
|
+
reason: JSON.stringify(reasonPayload),
|
|
145
|
+
preProcessors: unit.preProcessors || [],
|
|
146
|
+
postProcessors: unit.postProcessors || [],
|
|
147
|
+
monitors: unit.monitors || [],
|
|
148
|
+
results: unit.results || [],
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return unit;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const validSubworkflows = subworkflows.filter((subworkflow) => {
|
|
156
|
+
return !invalidSubworkflows.some(
|
|
157
|
+
({ subworkflow: invalid }) => invalid._id === subworkflow._id,
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const workflows = workflowData.workflows.map((nested) => {
|
|
162
|
+
return repairWorkflow(nested as WorkflowSchema);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
...workflowData,
|
|
167
|
+
subworkflows: validSubworkflows,
|
|
168
|
+
workflows,
|
|
169
|
+
units,
|
|
170
|
+
};
|
|
171
|
+
}
|