@flowgram.ai/runtime-js 0.2.23 → 0.2.25
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/esm/index.js +342 -66
- package/dist/esm/index.js.map +1 -1
- package/dist/{index.d.mts → index.d.cts} +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +350 -73
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
|
@@ -4,7 +4,7 @@ declare enum FlowGramAPIName {
|
|
|
4
4
|
TaskReport = "TaskReport",
|
|
5
5
|
TaskResult = "TaskResult",
|
|
6
6
|
TaskCancel = "TaskCancel",
|
|
7
|
-
|
|
7
|
+
TaskValidate = "TaskValidate"
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -14,6 +14,16 @@ declare enum FlowGramAPIName {
|
|
|
14
14
|
type WorkflowInputs = Record<string, any>;
|
|
15
15
|
type WorkflowOutputs = Record<string, any>;
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
19
|
+
* SPDX-License-Identifier: MIT
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface ValidationResult {
|
|
23
|
+
valid: boolean;
|
|
24
|
+
errors?: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
/**
|
|
18
28
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
19
29
|
* SPDX-License-Identifier: MIT
|
|
@@ -115,6 +125,18 @@ interface TaskReportInput {
|
|
|
115
125
|
}
|
|
116
126
|
type TaskReportOutput = IReport | undefined;
|
|
117
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
130
|
+
* SPDX-License-Identifier: MIT
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
interface TaskValidateInput {
|
|
134
|
+
inputs: WorkflowInputs;
|
|
135
|
+
schema: string;
|
|
136
|
+
}
|
|
137
|
+
interface TaskValidateOutput extends ValidationResult {
|
|
138
|
+
}
|
|
139
|
+
|
|
118
140
|
/**
|
|
119
141
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
120
142
|
* SPDX-License-Identifier: MIT
|
|
@@ -137,6 +159,13 @@ type TaskCancelOutput = {
|
|
|
137
159
|
success: boolean;
|
|
138
160
|
};
|
|
139
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
164
|
+
* SPDX-License-Identifier: MIT
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
declare const TaskValidateAPI: (input: TaskValidateInput) => Promise<TaskValidateOutput>;
|
|
168
|
+
|
|
140
169
|
/**
|
|
141
170
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
142
171
|
* SPDX-License-Identifier: MIT
|
|
@@ -172,4 +201,4 @@ declare const TaskCancelAPI: (input: TaskCancelInput) => Promise<TaskCancelOutpu
|
|
|
172
201
|
|
|
173
202
|
declare const WorkflowRuntimeAPIs: Record<FlowGramAPIName, (i: any) => any>;
|
|
174
203
|
|
|
175
|
-
export { TaskCancelAPI, TaskReportAPI, TaskResultAPI, TaskRunAPI, WorkflowRuntimeAPIs };
|
|
204
|
+
export { TaskCancelAPI, TaskReportAPI, TaskResultAPI, TaskRunAPI, TaskValidateAPI, WorkflowRuntimeAPIs };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare enum FlowGramAPIName {
|
|
|
4
4
|
TaskReport = "TaskReport",
|
|
5
5
|
TaskResult = "TaskResult",
|
|
6
6
|
TaskCancel = "TaskCancel",
|
|
7
|
-
|
|
7
|
+
TaskValidate = "TaskValidate"
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -14,6 +14,16 @@ declare enum FlowGramAPIName {
|
|
|
14
14
|
type WorkflowInputs = Record<string, any>;
|
|
15
15
|
type WorkflowOutputs = Record<string, any>;
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
19
|
+
* SPDX-License-Identifier: MIT
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface ValidationResult {
|
|
23
|
+
valid: boolean;
|
|
24
|
+
errors?: string[];
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
/**
|
|
18
28
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
19
29
|
* SPDX-License-Identifier: MIT
|
|
@@ -115,6 +125,18 @@ interface TaskReportInput {
|
|
|
115
125
|
}
|
|
116
126
|
type TaskReportOutput = IReport | undefined;
|
|
117
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
130
|
+
* SPDX-License-Identifier: MIT
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
interface TaskValidateInput {
|
|
134
|
+
inputs: WorkflowInputs;
|
|
135
|
+
schema: string;
|
|
136
|
+
}
|
|
137
|
+
interface TaskValidateOutput extends ValidationResult {
|
|
138
|
+
}
|
|
139
|
+
|
|
118
140
|
/**
|
|
119
141
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
120
142
|
* SPDX-License-Identifier: MIT
|
|
@@ -137,6 +159,13 @@ type TaskCancelOutput = {
|
|
|
137
159
|
success: boolean;
|
|
138
160
|
};
|
|
139
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
164
|
+
* SPDX-License-Identifier: MIT
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
declare const TaskValidateAPI: (input: TaskValidateInput) => Promise<TaskValidateOutput>;
|
|
168
|
+
|
|
140
169
|
/**
|
|
141
170
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
142
171
|
* SPDX-License-Identifier: MIT
|
|
@@ -172,4 +201,4 @@ declare const TaskCancelAPI: (input: TaskCancelInput) => Promise<TaskCancelOutpu
|
|
|
172
201
|
|
|
173
202
|
declare const WorkflowRuntimeAPIs: Record<FlowGramAPIName, (i: any) => any>;
|
|
174
203
|
|
|
175
|
-
export { TaskCancelAPI, TaskReportAPI, TaskResultAPI, TaskRunAPI, WorkflowRuntimeAPIs };
|
|
204
|
+
export { TaskCancelAPI, TaskReportAPI, TaskResultAPI, TaskRunAPI, TaskValidateAPI, WorkflowRuntimeAPIs };
|
package/dist/index.js
CHANGED
|
@@ -34,98 +34,98 @@ __export(src_exports, {
|
|
|
34
34
|
TaskReportAPI: () => TaskReportAPI,
|
|
35
35
|
TaskResultAPI: () => TaskResultAPI,
|
|
36
36
|
TaskRunAPI: () => TaskRunAPI,
|
|
37
|
+
TaskValidateAPI: () => TaskValidateAPI,
|
|
37
38
|
WorkflowRuntimeAPIs: () => WorkflowRuntimeAPIs
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(src_exports);
|
|
40
41
|
|
|
41
42
|
// ../interface/dist/esm/index.js
|
|
42
|
-
var import_zod = __toESM(require("zod"));
|
|
43
|
-
var import_zod2 = __toESM(require("zod"));
|
|
44
|
-
var import_zod3 = __toESM(require("zod"));
|
|
45
|
-
var import_zod4 = __toESM(require("zod"));
|
|
46
|
-
var import_zod5 = __toESM(require("zod"));
|
|
47
|
-
var import_zod6 = __toESM(require("zod"));
|
|
48
|
-
var import_zod7 = __toESM(require("zod"));
|
|
43
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
44
|
+
var import_zod2 = __toESM(require("zod"), 1);
|
|
45
|
+
var import_zod3 = __toESM(require("zod"), 1);
|
|
46
|
+
var import_zod4 = __toESM(require("zod"), 1);
|
|
47
|
+
var import_zod5 = __toESM(require("zod"), 1);
|
|
48
|
+
var import_zod6 = __toESM(require("zod"), 1);
|
|
49
|
+
var import_zod7 = __toESM(require("zod"), 1);
|
|
50
|
+
var WorkflowIOZodSchema = import_zod2.default.record(import_zod2.default.string(), import_zod2.default.any());
|
|
51
|
+
var WorkflowSnapshotZodSchema = import_zod2.default.object({
|
|
52
|
+
id: import_zod2.default.string(),
|
|
53
|
+
nodeID: import_zod2.default.string(),
|
|
54
|
+
inputs: WorkflowIOZodSchema,
|
|
55
|
+
outputs: WorkflowIOZodSchema.optional(),
|
|
56
|
+
data: WorkflowIOZodSchema,
|
|
57
|
+
branch: import_zod2.default.string().optional()
|
|
58
|
+
});
|
|
59
|
+
var WorkflowStatusZodShape = {
|
|
60
|
+
status: import_zod2.default.string(),
|
|
61
|
+
terminated: import_zod2.default.boolean(),
|
|
62
|
+
startTime: import_zod2.default.number(),
|
|
63
|
+
endTime: import_zod2.default.number().optional(),
|
|
64
|
+
timeCost: import_zod2.default.number()
|
|
65
|
+
};
|
|
66
|
+
var WorkflowStatusZodSchema = import_zod2.default.object(WorkflowStatusZodShape);
|
|
67
|
+
var WorkflowNodeReportZodSchema = import_zod2.default.object({
|
|
68
|
+
id: import_zod2.default.string(),
|
|
69
|
+
...WorkflowStatusZodShape,
|
|
70
|
+
snapshots: import_zod2.default.array(WorkflowSnapshotZodSchema)
|
|
71
|
+
});
|
|
72
|
+
var WorkflowReportsZodSchema = import_zod2.default.record(import_zod2.default.string(), WorkflowNodeReportZodSchema);
|
|
73
|
+
var WorkflowMessageZodSchema = import_zod2.default.object({
|
|
74
|
+
id: import_zod2.default.string(),
|
|
75
|
+
type: import_zod2.default.enum(["log", "info", "debug", "error", "warning"]),
|
|
76
|
+
message: import_zod2.default.string(),
|
|
77
|
+
nodeID: import_zod2.default.string().optional(),
|
|
78
|
+
timestamp: import_zod2.default.number()
|
|
79
|
+
});
|
|
80
|
+
var WorkflowMessagesZodSchema = import_zod2.default.record(
|
|
81
|
+
import_zod2.default.enum(["log", "info", "debug", "error", "warning"]),
|
|
82
|
+
import_zod2.default.array(WorkflowMessageZodSchema)
|
|
83
|
+
);
|
|
84
|
+
var WorkflowZodSchema = {
|
|
85
|
+
Inputs: WorkflowIOZodSchema,
|
|
86
|
+
Outputs: WorkflowIOZodSchema,
|
|
87
|
+
Status: WorkflowStatusZodSchema,
|
|
88
|
+
Snapshot: WorkflowSnapshotZodSchema,
|
|
89
|
+
Reports: WorkflowReportsZodSchema,
|
|
90
|
+
Messages: WorkflowMessagesZodSchema
|
|
91
|
+
};
|
|
49
92
|
var FlowGramAPIName = /* @__PURE__ */ ((FlowGramAPIName2) => {
|
|
50
93
|
FlowGramAPIName2["ServerInfo"] = "ServerInfo";
|
|
51
94
|
FlowGramAPIName2["TaskRun"] = "TaskRun";
|
|
52
95
|
FlowGramAPIName2["TaskReport"] = "TaskReport";
|
|
53
96
|
FlowGramAPIName2["TaskResult"] = "TaskResult";
|
|
54
97
|
FlowGramAPIName2["TaskCancel"] = "TaskCancel";
|
|
55
|
-
FlowGramAPIName2["
|
|
98
|
+
FlowGramAPIName2["TaskValidate"] = "TaskValidate";
|
|
56
99
|
return FlowGramAPIName2;
|
|
57
100
|
})(FlowGramAPIName || {});
|
|
58
|
-
var
|
|
59
|
-
name: "
|
|
101
|
+
var TaskValidateDefine = {
|
|
102
|
+
name: "TaskValidate",
|
|
60
103
|
method: "POST",
|
|
61
|
-
path: "/
|
|
62
|
-
module: "
|
|
104
|
+
path: "/task/validate",
|
|
105
|
+
module: "Task",
|
|
63
106
|
schema: {
|
|
64
107
|
input: import_zod.default.object({
|
|
65
|
-
schema: import_zod.default.string()
|
|
108
|
+
schema: import_zod.default.string(),
|
|
109
|
+
inputs: WorkflowZodSchema.Inputs
|
|
66
110
|
}),
|
|
67
111
|
output: import_zod.default.object({
|
|
68
112
|
valid: import_zod.default.boolean(),
|
|
69
|
-
|
|
70
|
-
import_zod.default.object({
|
|
71
|
-
message: import_zod.default.string(),
|
|
72
|
-
nodeID: import_zod.default.string()
|
|
73
|
-
})
|
|
74
|
-
),
|
|
75
|
-
edgeErrors: import_zod.default.array(
|
|
76
|
-
import_zod.default.object({
|
|
77
|
-
message: import_zod.default.string(),
|
|
78
|
-
edge: import_zod.default.object({
|
|
79
|
-
sourceNodeID: import_zod.default.string(),
|
|
80
|
-
targetNodeID: import_zod.default.string(),
|
|
81
|
-
sourcePortID: import_zod.default.string().optional(),
|
|
82
|
-
targetPortID: import_zod.default.string().optional()
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
)
|
|
113
|
+
errors: import_zod.default.array(import_zod.default.string()).optional()
|
|
86
114
|
})
|
|
87
115
|
}
|
|
88
116
|
};
|
|
89
|
-
var WorkflowIOZodSchema = import_zod3.default.record(import_zod3.default.string(), import_zod3.default.any());
|
|
90
|
-
var WorkflowSnapshotZodSchema = import_zod3.default.object({
|
|
91
|
-
id: import_zod3.default.string(),
|
|
92
|
-
nodeID: import_zod3.default.string(),
|
|
93
|
-
inputs: WorkflowIOZodSchema,
|
|
94
|
-
outputs: WorkflowIOZodSchema.optional(),
|
|
95
|
-
data: WorkflowIOZodSchema,
|
|
96
|
-
branch: import_zod3.default.string().optional()
|
|
97
|
-
});
|
|
98
|
-
var WorkflowStatusZodShape = {
|
|
99
|
-
status: import_zod3.default.string(),
|
|
100
|
-
terminated: import_zod3.default.boolean(),
|
|
101
|
-
startTime: import_zod3.default.number(),
|
|
102
|
-
endTime: import_zod3.default.number().optional(),
|
|
103
|
-
timeCost: import_zod3.default.number()
|
|
104
|
-
};
|
|
105
|
-
var WorkflowStatusZodSchema = import_zod3.default.object(WorkflowStatusZodShape);
|
|
106
|
-
var WorkflowZodSchema = {
|
|
107
|
-
Inputs: WorkflowIOZodSchema,
|
|
108
|
-
Outputs: WorkflowIOZodSchema,
|
|
109
|
-
Status: WorkflowStatusZodSchema,
|
|
110
|
-
Snapshot: WorkflowSnapshotZodSchema,
|
|
111
|
-
NodeReport: import_zod3.default.object({
|
|
112
|
-
id: import_zod3.default.string(),
|
|
113
|
-
...WorkflowStatusZodShape,
|
|
114
|
-
snapshots: import_zod3.default.array(WorkflowSnapshotZodSchema)
|
|
115
|
-
})
|
|
116
|
-
};
|
|
117
117
|
var TaskRunDefine = {
|
|
118
118
|
name: "TaskRun",
|
|
119
119
|
method: "POST",
|
|
120
120
|
path: "/task/run",
|
|
121
121
|
module: "Task",
|
|
122
122
|
schema: {
|
|
123
|
-
input:
|
|
124
|
-
schema:
|
|
123
|
+
input: import_zod3.default.object({
|
|
124
|
+
schema: import_zod3.default.string(),
|
|
125
125
|
inputs: WorkflowZodSchema.Inputs
|
|
126
126
|
}),
|
|
127
|
-
output:
|
|
128
|
-
taskID:
|
|
127
|
+
output: import_zod3.default.object({
|
|
128
|
+
taskID: import_zod3.default.string()
|
|
129
129
|
})
|
|
130
130
|
}
|
|
131
131
|
};
|
|
@@ -155,7 +155,8 @@ var TaskReportDefine = {
|
|
|
155
155
|
inputs: WorkflowZodSchema.Inputs,
|
|
156
156
|
outputs: WorkflowZodSchema.Outputs,
|
|
157
157
|
workflowStatus: WorkflowZodSchema.Status,
|
|
158
|
-
reports:
|
|
158
|
+
reports: WorkflowZodSchema.Reports,
|
|
159
|
+
messages: WorkflowZodSchema.Messages
|
|
159
160
|
})
|
|
160
161
|
}
|
|
161
162
|
};
|
|
@@ -210,9 +211,9 @@ var FlowGramAPIs = {
|
|
|
210
211
|
/* TaskCancel */
|
|
211
212
|
]: TaskCancelDefine,
|
|
212
213
|
[
|
|
213
|
-
"
|
|
214
|
-
/*
|
|
215
|
-
]:
|
|
214
|
+
"TaskValidate"
|
|
215
|
+
/* TaskValidate */
|
|
216
|
+
]: TaskValidateDefine
|
|
216
217
|
};
|
|
217
218
|
var FlowGramAPINames = Object.keys(FlowGramAPIs);
|
|
218
219
|
var WorkflowPortType = /* @__PURE__ */ ((WorkflowPortType2) => {
|
|
@@ -402,6 +403,205 @@ function compareNodeGroups(groupA, groupB) {
|
|
|
402
403
|
};
|
|
403
404
|
}
|
|
404
405
|
|
|
406
|
+
// src/infrastructure/utils/json-schema-validator.ts
|
|
407
|
+
var ROOT_PATH = "root";
|
|
408
|
+
var isRootPath = (path) => path === ROOT_PATH;
|
|
409
|
+
var validateValue = (value, schema, path) => {
|
|
410
|
+
if (schema.$ref) {
|
|
411
|
+
return { result: true };
|
|
412
|
+
}
|
|
413
|
+
if (schema.enum && schema.enum.length > 0) {
|
|
414
|
+
if (!schema.enum.includes(value)) {
|
|
415
|
+
return {
|
|
416
|
+
result: false,
|
|
417
|
+
errorMessage: `Value at ${path} must be one of: ${schema.enum.join(
|
|
418
|
+
", "
|
|
419
|
+
)}, but got: ${JSON.stringify(value)}`
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
switch (schema.type) {
|
|
424
|
+
case "boolean":
|
|
425
|
+
return validateBoolean(value, path);
|
|
426
|
+
case "string":
|
|
427
|
+
return validateString(value, path);
|
|
428
|
+
case "integer":
|
|
429
|
+
return validateInteger(value, path);
|
|
430
|
+
case "number":
|
|
431
|
+
return validateNumber(value, path);
|
|
432
|
+
case "object":
|
|
433
|
+
return validateObject(value, schema, path);
|
|
434
|
+
case "array":
|
|
435
|
+
return validateArray(value, schema, path);
|
|
436
|
+
case "map":
|
|
437
|
+
return validateMap(value, schema, path);
|
|
438
|
+
default:
|
|
439
|
+
return {
|
|
440
|
+
result: false,
|
|
441
|
+
errorMessage: `Unknown type "${schema.type}" at ${path}`
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
var validateBoolean = (value, path) => {
|
|
446
|
+
if (typeof value !== "boolean") {
|
|
447
|
+
return {
|
|
448
|
+
result: false,
|
|
449
|
+
errorMessage: `Expected boolean at ${path}, but got: ${typeof value}`
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
return { result: true };
|
|
453
|
+
};
|
|
454
|
+
var validateString = (value, path) => {
|
|
455
|
+
if (typeof value !== "string") {
|
|
456
|
+
return {
|
|
457
|
+
result: false,
|
|
458
|
+
errorMessage: `Expected string at ${path}, but got: ${typeof value}`
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
return { result: true };
|
|
462
|
+
};
|
|
463
|
+
var validateInteger = (value, path) => {
|
|
464
|
+
if (!Number.isInteger(value)) {
|
|
465
|
+
return {
|
|
466
|
+
result: false,
|
|
467
|
+
errorMessage: `Expected integer at ${path}, but got: ${JSON.stringify(value)}`
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
return { result: true };
|
|
471
|
+
};
|
|
472
|
+
var validateNumber = (value, path) => {
|
|
473
|
+
if (typeof value !== "number" || isNaN(value)) {
|
|
474
|
+
return {
|
|
475
|
+
result: false,
|
|
476
|
+
errorMessage: `Expected number at ${path}, but got: ${JSON.stringify(value)}`
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
return { result: true };
|
|
480
|
+
};
|
|
481
|
+
var validateObject = (value, schema, path) => {
|
|
482
|
+
if (value === null || value === void 0) {
|
|
483
|
+
return {
|
|
484
|
+
result: false,
|
|
485
|
+
errorMessage: `Expected object at ${path}, but got: ${value}`
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
489
|
+
return {
|
|
490
|
+
result: false,
|
|
491
|
+
errorMessage: `Expected object at ${path}, but got: ${Array.isArray(value) ? "array" : typeof value}`
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
const objectValue = value;
|
|
495
|
+
if (schema.required && schema.required.length > 0) {
|
|
496
|
+
for (const requiredProperty of schema.required) {
|
|
497
|
+
if (!(requiredProperty in objectValue)) {
|
|
498
|
+
return {
|
|
499
|
+
result: false,
|
|
500
|
+
errorMessage: `Missing required property "${requiredProperty}" at ${path}`
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (schema.properties) {
|
|
506
|
+
for (const [propertyName, propertySchema] of Object.entries(schema.properties)) {
|
|
507
|
+
const isRequired = propertySchema.isPropertyRequired === true;
|
|
508
|
+
if (isRequired && !(propertyName in objectValue)) {
|
|
509
|
+
return {
|
|
510
|
+
result: false,
|
|
511
|
+
errorMessage: `Missing required property "${propertyName}" at ${path}`
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (schema.properties) {
|
|
517
|
+
for (const [propertyName, propertySchema] of Object.entries(schema.properties)) {
|
|
518
|
+
if (propertyName in objectValue) {
|
|
519
|
+
const propertyPath = isRootPath(path) ? propertyName : `${path}.${propertyName}`;
|
|
520
|
+
const propertyResult = validateValue(
|
|
521
|
+
objectValue[propertyName],
|
|
522
|
+
propertySchema,
|
|
523
|
+
propertyPath
|
|
524
|
+
);
|
|
525
|
+
if (!propertyResult.result) {
|
|
526
|
+
return propertyResult;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (schema.additionalProperties) {
|
|
532
|
+
const definedProperties = new Set(Object.keys(schema.properties || {}));
|
|
533
|
+
for (const [propertyName, propertyValue] of Object.entries(objectValue)) {
|
|
534
|
+
if (!definedProperties.has(propertyName)) {
|
|
535
|
+
const propertyPath = isRootPath(path) ? propertyName : `${path}.${propertyName}`;
|
|
536
|
+
const propertyResult = validateValue(
|
|
537
|
+
propertyValue,
|
|
538
|
+
schema.additionalProperties,
|
|
539
|
+
propertyPath
|
|
540
|
+
);
|
|
541
|
+
if (!propertyResult.result) {
|
|
542
|
+
return propertyResult;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return { result: true };
|
|
548
|
+
};
|
|
549
|
+
var validateArray = (value, schema, path) => {
|
|
550
|
+
if (!Array.isArray(value)) {
|
|
551
|
+
return {
|
|
552
|
+
result: false,
|
|
553
|
+
errorMessage: `Expected array at ${path}, but got: ${typeof value}`
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
if (schema.items) {
|
|
557
|
+
for (const [index, item] of value.entries()) {
|
|
558
|
+
const itemPath = `${path}[${index}]`;
|
|
559
|
+
const itemResult = validateValue(item, schema.items, itemPath);
|
|
560
|
+
if (!itemResult.result) {
|
|
561
|
+
return itemResult;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return { result: true };
|
|
566
|
+
};
|
|
567
|
+
var validateMap = (value, schema, path) => {
|
|
568
|
+
if (value === null || value === void 0) {
|
|
569
|
+
return {
|
|
570
|
+
result: false,
|
|
571
|
+
errorMessage: `Expected map at ${path}, but got: ${value}`
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
575
|
+
return {
|
|
576
|
+
result: false,
|
|
577
|
+
errorMessage: `Expected map at ${path}, but got: ${Array.isArray(value) ? "array" : typeof value}`
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
const mapValue = value;
|
|
581
|
+
if (schema.additionalProperties) {
|
|
582
|
+
for (const [key, mapItemValue] of Object.entries(mapValue)) {
|
|
583
|
+
const keyPath = isRootPath(path) ? key : `${path}.${key}`;
|
|
584
|
+
const keyResult = validateValue(mapItemValue, schema.additionalProperties, keyPath);
|
|
585
|
+
if (!keyResult.result) {
|
|
586
|
+
return keyResult;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return { result: true };
|
|
591
|
+
};
|
|
592
|
+
var JSONSchemaValidator = (params) => {
|
|
593
|
+
const { schema, value } = params;
|
|
594
|
+
try {
|
|
595
|
+
const validationResult = validateValue(value, schema, ROOT_PATH);
|
|
596
|
+
return validationResult;
|
|
597
|
+
} catch (error) {
|
|
598
|
+
return {
|
|
599
|
+
result: false,
|
|
600
|
+
errorMessage: `Validation error: ${error instanceof Error ? error.message : String(error)}`
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
|
|
405
605
|
// src/nodes/loop/index.ts
|
|
406
606
|
var LoopExecutor = class {
|
|
407
607
|
constructor() {
|
|
@@ -920,11 +1120,48 @@ var WorkflowRuntimeNodeExecutors = [
|
|
|
920
1120
|
|
|
921
1121
|
// src/domain/validation/index.ts
|
|
922
1122
|
var WorkflowRuntimeValidation = class {
|
|
923
|
-
|
|
1123
|
+
invoke(params) {
|
|
1124
|
+
const { schema, inputs } = params;
|
|
1125
|
+
const schemaValidationResult = this.schema(schema);
|
|
1126
|
+
if (!schemaValidationResult.valid) {
|
|
1127
|
+
return schemaValidationResult;
|
|
1128
|
+
}
|
|
1129
|
+
const inputsValidationResult = this.inputs(this.getWorkflowInputsDeclare(schema), inputs);
|
|
1130
|
+
if (!inputsValidationResult.valid) {
|
|
1131
|
+
return inputsValidationResult;
|
|
1132
|
+
}
|
|
924
1133
|
return {
|
|
925
1134
|
valid: true
|
|
926
1135
|
};
|
|
927
1136
|
}
|
|
1137
|
+
schema(schema) {
|
|
1138
|
+
return {
|
|
1139
|
+
valid: true
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
inputs(inputsSchema, inputs) {
|
|
1143
|
+
const { result, errorMessage } = JSONSchemaValidator({
|
|
1144
|
+
schema: inputsSchema,
|
|
1145
|
+
value: inputs
|
|
1146
|
+
});
|
|
1147
|
+
if (!result) {
|
|
1148
|
+
const error = `JSON Schema validation failed: ${errorMessage}`;
|
|
1149
|
+
return {
|
|
1150
|
+
valid: false,
|
|
1151
|
+
errors: [error]
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
return {
|
|
1155
|
+
valid: true
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
getWorkflowInputsDeclare(schema) {
|
|
1159
|
+
const startNode = schema.nodes.find((node) => node.type === FlowGramNode.Start);
|
|
1160
|
+
if (!startNode) {
|
|
1161
|
+
throw new Error("Workflow schema must have a start node");
|
|
1162
|
+
}
|
|
1163
|
+
return startNode.data.outputs;
|
|
1164
|
+
}
|
|
928
1165
|
};
|
|
929
1166
|
|
|
930
1167
|
// src/domain/executor/index.ts
|
|
@@ -1932,11 +2169,19 @@ var WorkflowRuntimeContext = class _WorkflowRuntimeContext {
|
|
|
1932
2169
|
// src/domain/engine/index.ts
|
|
1933
2170
|
var WorkflowRuntimeEngine = class {
|
|
1934
2171
|
constructor(service) {
|
|
2172
|
+
this.validation = service.Validation;
|
|
1935
2173
|
this.executor = service.Executor;
|
|
1936
2174
|
}
|
|
1937
2175
|
invoke(params) {
|
|
1938
2176
|
const context = WorkflowRuntimeContext.create();
|
|
1939
2177
|
context.init(params);
|
|
2178
|
+
const valid = this.validate(params, context);
|
|
2179
|
+
if (!valid) {
|
|
2180
|
+
return WorkflowRuntimeTask.create({
|
|
2181
|
+
processing: Promise.resolve({}),
|
|
2182
|
+
context
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
1940
2185
|
const processing = this.process(context);
|
|
1941
2186
|
processing.then(() => {
|
|
1942
2187
|
context.dispose();
|
|
@@ -2003,6 +2248,19 @@ var WorkflowRuntimeEngine = class {
|
|
|
2003
2248
|
return {};
|
|
2004
2249
|
}
|
|
2005
2250
|
}
|
|
2251
|
+
validate(params, context) {
|
|
2252
|
+
const { valid, errors } = this.validation.invoke(params);
|
|
2253
|
+
if (valid) {
|
|
2254
|
+
return true;
|
|
2255
|
+
}
|
|
2256
|
+
errors?.forEach((message) => {
|
|
2257
|
+
context.messageCenter.error({
|
|
2258
|
+
message
|
|
2259
|
+
});
|
|
2260
|
+
});
|
|
2261
|
+
context.statusCenter.workflow.fail();
|
|
2262
|
+
return false;
|
|
2263
|
+
}
|
|
2006
2264
|
canExecuteNode(params) {
|
|
2007
2265
|
const { node, context } = params;
|
|
2008
2266
|
const prevNodes = node.prev;
|
|
@@ -2071,6 +2329,7 @@ var WorkflowRuntimeContainer = class _WorkflowRuntimeContainer {
|
|
|
2071
2329
|
const Validation = new WorkflowRuntimeValidation();
|
|
2072
2330
|
const Executor = new WorkflowRuntimeExecutor(WorkflowRuntimeNodeExecutors);
|
|
2073
2331
|
const Engine = new WorkflowRuntimeEngine({
|
|
2332
|
+
Validation,
|
|
2074
2333
|
Executor
|
|
2075
2334
|
});
|
|
2076
2335
|
return {
|
|
@@ -2127,6 +2386,12 @@ var WorkflowApplication = class _WorkflowApplication {
|
|
|
2127
2386
|
}
|
|
2128
2387
|
return task.context.ioCenter.outputs;
|
|
2129
2388
|
}
|
|
2389
|
+
validate(params) {
|
|
2390
|
+
const validation = this.container.get(IValidation);
|
|
2391
|
+
const result = validation.invoke(params);
|
|
2392
|
+
console.log("> POST TaskValidate - valid: ", result.valid);
|
|
2393
|
+
return result;
|
|
2394
|
+
}
|
|
2130
2395
|
static get instance() {
|
|
2131
2396
|
if (this._instance) {
|
|
2132
2397
|
return this._instance;
|
|
@@ -2136,6 +2401,19 @@ var WorkflowApplication = class _WorkflowApplication {
|
|
|
2136
2401
|
}
|
|
2137
2402
|
};
|
|
2138
2403
|
|
|
2404
|
+
// src/api/task-validate.ts
|
|
2405
|
+
var TaskValidateAPI = async (input) => {
|
|
2406
|
+
const app = WorkflowApplication.instance;
|
|
2407
|
+
const { schema: stringSchema, inputs } = input;
|
|
2408
|
+
const schema = JSON.parse(stringSchema);
|
|
2409
|
+
const result = app.validate({
|
|
2410
|
+
schema,
|
|
2411
|
+
inputs
|
|
2412
|
+
});
|
|
2413
|
+
const output = result;
|
|
2414
|
+
return output;
|
|
2415
|
+
};
|
|
2416
|
+
|
|
2139
2417
|
// src/api/task-run.ts
|
|
2140
2418
|
var TaskRunAPI = async (input) => {
|
|
2141
2419
|
const app = WorkflowApplication.instance;
|
|
@@ -2186,16 +2464,14 @@ var TaskCancelAPI = async (input) => {
|
|
|
2186
2464
|
|
|
2187
2465
|
// src/api/index.ts
|
|
2188
2466
|
var WorkflowRuntimeAPIs = {
|
|
2467
|
+
[FlowGramAPIName.ServerInfo]: () => {
|
|
2468
|
+
},
|
|
2469
|
+
// TODO
|
|
2189
2470
|
[FlowGramAPIName.TaskRun]: TaskRunAPI,
|
|
2190
2471
|
[FlowGramAPIName.TaskReport]: TaskReportAPI,
|
|
2191
2472
|
[FlowGramAPIName.TaskResult]: TaskResultAPI,
|
|
2192
2473
|
[FlowGramAPIName.TaskCancel]: TaskCancelAPI,
|
|
2193
|
-
[FlowGramAPIName.
|
|
2194
|
-
},
|
|
2195
|
-
// TODO
|
|
2196
|
-
[FlowGramAPIName.Validation]: () => {
|
|
2197
|
-
}
|
|
2198
|
-
// TODO
|
|
2474
|
+
[FlowGramAPIName.TaskValidate]: TaskValidateAPI
|
|
2199
2475
|
};
|
|
2200
2476
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2201
2477
|
0 && (module.exports = {
|
|
@@ -2203,6 +2479,7 @@ var WorkflowRuntimeAPIs = {
|
|
|
2203
2479
|
TaskReportAPI,
|
|
2204
2480
|
TaskResultAPI,
|
|
2205
2481
|
TaskRunAPI,
|
|
2482
|
+
TaskValidateAPI,
|
|
2206
2483
|
WorkflowRuntimeAPIs
|
|
2207
2484
|
});
|
|
2208
2485
|
//# sourceMappingURL=index.js.map
|