@auto-mas/auto-mas-plugin-data-management 0.0.0-stage → 0.1.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/LICENSE +661 -0
- package/dist/index.js +1 -0
- package/dist/server/backup.js +68 -0
- package/dist/server/blockly-compiler.js +277 -0
- package/dist/server/blockly.js +157 -0
- package/dist/server/builtin-plugins/data-management.js +43 -0
- package/dist/server/features.js +31 -0
- package/dist/server/migration/history.js +161 -0
- package/dist/server/migration/index.js +260 -0
- package/dist/server/migration/source.js +79 -0
- package/dist/server/migration/targets.js +85 -0
- package/dist/server/storage.js +76 -0
- package/dist/server/workflow-model.js +155 -0
- package/package.json +31 -6
- package/README.md +0 -3
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
export const workflowCollections = ['workflows', 'workflow-runs'];
|
|
2
|
+
export function interruptWorkflowRun(run, error) {
|
|
3
|
+
return { ...run, status: 'interrupted', error, finished: new Date().toISOString(),
|
|
4
|
+
steps: run.steps.map(step => ({ ...step, status: step.status === 'running' ? 'interrupted' : step.status === 'pending' ? 'skipped' : step.status })) };
|
|
5
|
+
}
|
|
6
|
+
function record(value, label) {
|
|
7
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
8
|
+
throw new Error(`${label}格式无效`);
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function string(value, label) {
|
|
12
|
+
if (typeof value !== 'string' || !value.trim() || value.length > 180)
|
|
13
|
+
throw new Error(`请填写有效的${label}`);
|
|
14
|
+
return value.trim();
|
|
15
|
+
}
|
|
16
|
+
function id(value, label) {
|
|
17
|
+
const key = string(value, label);
|
|
18
|
+
if (!/^[\w-]+$/u.test(key))
|
|
19
|
+
throw new Error(`${label}标识无效`);
|
|
20
|
+
return key;
|
|
21
|
+
}
|
|
22
|
+
export function encodeWorkflowValue(value) {
|
|
23
|
+
const encoded = JSON.stringify(value);
|
|
24
|
+
if (encoded === undefined || Buffer.byteLength(encoded) > 64 * 1024)
|
|
25
|
+
throw new Error('节点输入必须是 64 KiB 以内的 JSON');
|
|
26
|
+
return encoded;
|
|
27
|
+
}
|
|
28
|
+
const validPointer = /^(?:\/(?:[^~/]|~[01])*)*$/u;
|
|
29
|
+
export function readWorkflowOutput(output, pointer) {
|
|
30
|
+
for (const part of pointer.split('/').slice(1)) {
|
|
31
|
+
const key = part.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
32
|
+
if (!output || typeof output !== 'object' || !Object.hasOwn(output, key) ||
|
|
33
|
+
(Array.isArray(output) && !/^(?:0|[1-9]\d*)$/u.test(key)))
|
|
34
|
+
throw new Error(`上游输出中找不到路径 ${pointer}`);
|
|
35
|
+
output = output[key];
|
|
36
|
+
}
|
|
37
|
+
if (output === undefined)
|
|
38
|
+
throw new Error('上游节点没有提供 JSON 输出');
|
|
39
|
+
return output;
|
|
40
|
+
}
|
|
41
|
+
function readInput(value) {
|
|
42
|
+
if (value === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
const input = record(value, '节点输入');
|
|
45
|
+
if (input.kind === 'literal')
|
|
46
|
+
return { kind: 'literal', value: JSON.parse(encodeWorkflowValue(input.value)) };
|
|
47
|
+
if (input.kind !== 'output' || typeof input.pointer !== 'string' || !validPointer.test(input.pointer)) {
|
|
48
|
+
throw new Error('请选择有效的输入来源和 JSON 路径');
|
|
49
|
+
}
|
|
50
|
+
return { kind: 'output', nodeId: id(input.nodeId, '上游节点'), pointer: input.pointer };
|
|
51
|
+
}
|
|
52
|
+
function readNode(value) {
|
|
53
|
+
const row = record(value, '流程节点');
|
|
54
|
+
const label = string(row.label, '节点名称');
|
|
55
|
+
try {
|
|
56
|
+
const position = record(row.position, '节点位置');
|
|
57
|
+
if (typeof position.x !== 'number' || typeof position.y !== 'number' || !Number.isFinite(position.x) || !Number.isFinite(position.y)) {
|
|
58
|
+
throw new Error('节点位置无效');
|
|
59
|
+
}
|
|
60
|
+
if (row.kind !== 'script' && row.kind !== 'published')
|
|
61
|
+
throw new Error('节点类型无效');
|
|
62
|
+
const node = { id: id(row.id, '节点'), label, position: { x: position.x, y: position.y }, kind: row.kind };
|
|
63
|
+
if (row.kind === 'script') {
|
|
64
|
+
node.scriptId = id(row.scriptId, '托管');
|
|
65
|
+
if (row.accountId)
|
|
66
|
+
node.accountId = id(row.accountId, '账号');
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
node.nodeId = id(row.nodeId, '已发布节点');
|
|
70
|
+
if (typeof row.version !== 'number' || !Number.isSafeInteger(row.version) || row.version < 1)
|
|
71
|
+
throw new Error('请选择已发布版本');
|
|
72
|
+
node.version = row.version;
|
|
73
|
+
}
|
|
74
|
+
if (row.success)
|
|
75
|
+
node.success = id(row.success, '成功出口');
|
|
76
|
+
if (row.failure)
|
|
77
|
+
node.failure = id(row.failure, '失败出口');
|
|
78
|
+
const input = readInput(row.input);
|
|
79
|
+
if (input)
|
|
80
|
+
node.input = input;
|
|
81
|
+
return node;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw new Error(`${label}:${error.message}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function readSchedule(value) {
|
|
88
|
+
if (value === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
const schedule = record(value, '定时规则');
|
|
91
|
+
if (!Array.isArray(schedule.times) || !schedule.times.length ||
|
|
92
|
+
schedule.times.some(time => typeof time !== 'string' || !/^(?:[01]\d|2[0-3]):[0-5]\d$/u.test(time))) {
|
|
93
|
+
throw new Error('请填写有效的定时时刻');
|
|
94
|
+
}
|
|
95
|
+
if (!Array.isArray(schedule.weekdays) || schedule.weekdays.some(day => !Number.isInteger(day) || day < 0 || day > 6)) {
|
|
96
|
+
throw new Error('请选择有效的星期');
|
|
97
|
+
}
|
|
98
|
+
if (schedule.enabled !== undefined && typeof schedule.enabled !== 'boolean')
|
|
99
|
+
throw new Error('定时规则的启用状态无效');
|
|
100
|
+
return { times: [...new Set(schedule.times)].sort(), weekdays: [...new Set(schedule.weekdays)].sort(),
|
|
101
|
+
...(schedule.enabled === undefined ? {} : { enabled: schedule.enabled }) };
|
|
102
|
+
}
|
|
103
|
+
export function readWorkflow(value) {
|
|
104
|
+
const row = record(value, '工作流');
|
|
105
|
+
const name = string(row.name, '工作流名称');
|
|
106
|
+
const workflowId = row.id ? id(row.id, '工作流') : '';
|
|
107
|
+
if (typeof row.revision !== 'number' || !Number.isSafeInteger(row.revision) || row.revision < 0)
|
|
108
|
+
throw new Error('工作流修订无效');
|
|
109
|
+
if (!Array.isArray(row.nodes) || !row.nodes.length || row.nodes.length > 100)
|
|
110
|
+
throw new Error('工作流须包含 1 到 100 个节点');
|
|
111
|
+
const entry = id(row.entry, '起点');
|
|
112
|
+
const nodes = row.nodes.map(readNode);
|
|
113
|
+
const byId = new Map(nodes.map(node => [node.id, node]));
|
|
114
|
+
if (byId.size !== nodes.length)
|
|
115
|
+
throw new Error('工作流包含重复的节点 ID');
|
|
116
|
+
if (!byId.has(entry))
|
|
117
|
+
throw new Error('请选择有效的起点');
|
|
118
|
+
const visiting = new Set();
|
|
119
|
+
const visited = new Set();
|
|
120
|
+
const visit = (node) => {
|
|
121
|
+
if (visiting.has(node.id))
|
|
122
|
+
throw new Error(`${node.label}:工作流存在环路`);
|
|
123
|
+
if (visited.has(node.id))
|
|
124
|
+
return;
|
|
125
|
+
visiting.add(node.id);
|
|
126
|
+
for (const edge of [node.success, node.failure]) {
|
|
127
|
+
if (!edge)
|
|
128
|
+
continue;
|
|
129
|
+
const next = byId.get(edge);
|
|
130
|
+
if (!next)
|
|
131
|
+
throw new Error(`${node.label}:出口指向不存在的节点`);
|
|
132
|
+
visit(next);
|
|
133
|
+
}
|
|
134
|
+
visiting.delete(node.id);
|
|
135
|
+
visited.add(node.id);
|
|
136
|
+
};
|
|
137
|
+
visit(byId.get(entry));
|
|
138
|
+
const unreachable = nodes.find(node => !visited.has(node.id));
|
|
139
|
+
if (unreachable)
|
|
140
|
+
throw new Error(`${unreachable.label}:从起点无法到达此节点`);
|
|
141
|
+
const predecessors = (from, target, seen) => {
|
|
142
|
+
if (seen.has(from.id))
|
|
143
|
+
return false;
|
|
144
|
+
seen.add(from.id);
|
|
145
|
+
return [from.success, from.failure].some(edge => edge && (edge === target || predecessors(byId.get(edge), target, seen)));
|
|
146
|
+
};
|
|
147
|
+
for (const node of nodes) {
|
|
148
|
+
if (node.input?.kind !== 'output')
|
|
149
|
+
continue;
|
|
150
|
+
const source = byId.get(node.input.nodeId);
|
|
151
|
+
if (!source || !predecessors(source, node.id, new Set()))
|
|
152
|
+
throw new Error(`${node.label}:输入须引用前序节点的输出`);
|
|
153
|
+
}
|
|
154
|
+
return { id: workflowId, name, revision: row.revision, entry, nodes, schedule: readSchedule(row.schedule) };
|
|
155
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@auto-mas/auto-mas-plugin-data-management",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@auto-mas/auto-mas-plugin-data-management",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"exports": "./dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"auto-mas-plugin"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"description": "AUTO-MAS data-management Cordis component",
|
|
21
|
+
"autoMas": {
|
|
22
|
+
"id": "data-management",
|
|
23
|
+
"abi": 1,
|
|
24
|
+
"hostDependencies": {
|
|
25
|
+
"cordis": "4.0.0-rc.13",
|
|
26
|
+
"jsonc-parser": "3.3.1",
|
|
27
|
+
"schemastery": "3.18.0",
|
|
28
|
+
"yaml": "2.8.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
package/README.md
DELETED