@nocobase/plugin-workflow 0.10.1-alpha.1 → 0.11.1-alpha.1
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/client.d.ts +2 -3
- package/client.js +1 -30
- package/lib/client/AddButton.js +13 -11
- package/lib/client/Branch.js +10 -8
- package/lib/client/CanvasContent.js +12 -10
- package/lib/client/ExecutionCanvas.js +37 -33
- package/lib/client/ExecutionPage.js +4 -9
- package/lib/client/WorkflowCanvas.js +18 -15
- package/lib/client/WorkflowPage.js +4 -9
- package/lib/client/WorkflowProvider.js +1 -40
- package/lib/client/components/CollectionBlockInitializer.js +3 -3
- package/lib/client/components/CollectionFieldset.d.ts +1 -1
- package/lib/client/components/CollectionFieldset.js +15 -16
- package/lib/client/components/Duration.js +5 -5
- package/lib/client/components/DynamicExpression.d.ts +3 -3
- package/lib/client/components/FieldsSelect.d.ts +1 -1
- package/lib/client/components/FieldsSelect.js +10 -7
- package/lib/client/components/NodeDescription.js +45 -31
- package/lib/client/components/RadioWithTooltip.js +13 -20
- package/lib/client/components/ValueBlock.js +14 -21
- package/lib/client/components/renderEngineReference.js +1 -8
- package/lib/client/index.d.ts +12 -4
- package/lib/client/index.js +78 -15
- package/lib/client/locale/zh-CN.d.ts +5 -1
- package/lib/client/locale/zh-CN.js +6 -2
- package/lib/client/nodes/aggregate.d.ts +8 -3
- package/lib/client/nodes/aggregate.js +5 -4
- package/lib/client/nodes/calculation.d.ts +6 -4
- package/lib/client/nodes/calculation.js +22 -28
- package/lib/client/nodes/condition.d.ts +2 -10
- package/lib/client/nodes/condition.js +19 -37
- package/lib/client/nodes/create.d.ts +5 -6
- package/lib/client/nodes/create.js +1 -3
- package/lib/client/nodes/destroy.d.ts +1 -1
- package/lib/client/nodes/index.d.ts +2 -3
- package/lib/client/nodes/index.js +95 -102
- package/lib/client/nodes/loop.d.ts +1 -1
- package/lib/client/nodes/loop.js +46 -54
- package/lib/client/nodes/manual/FormBlockInitializer.js +6 -5
- package/lib/client/nodes/manual/ModeConfig.js +23 -30
- package/lib/client/nodes/manual/SchemaConfig.d.ts +4 -5
- package/lib/client/nodes/manual/SchemaConfig.js +180 -25
- package/lib/client/nodes/manual/WorkflowTodo.js +95 -110
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +2 -5
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +6 -5
- package/lib/client/nodes/manual/forms/create.js +8 -1
- package/lib/client/nodes/manual/forms/custom.js +22 -22
- package/lib/client/nodes/manual/forms/update.js +8 -1
- package/lib/client/nodes/manual/index.d.ts +6 -1
- package/lib/client/nodes/manual/index.js +5 -4
- package/lib/client/nodes/parallel.js +23 -20
- package/lib/client/nodes/query.d.ts +3 -5
- package/lib/client/nodes/query.js +1 -3
- package/lib/client/nodes/request.d.ts +2 -2
- package/lib/client/nodes/request.js +7 -7
- package/lib/client/nodes/sql.d.ts +26 -0
- package/lib/client/{triggers/schedule/DateFieldsSelect.js → nodes/sql.js} +37 -46
- package/lib/client/nodes/update.d.ts +2 -2
- package/lib/client/nodes/update.js +1 -1
- package/lib/client/schemas/collection.d.ts +3 -4
- package/lib/client/schemas/collection.js +11 -17
- package/lib/client/style.d.ts +18 -13
- package/lib/client/style.js +315 -292
- package/lib/client/triggers/collection.d.ts +13 -13
- package/lib/client/triggers/collection.js +5 -1
- package/lib/client/triggers/index.d.ts +3 -4
- package/lib/client/triggers/index.js +51 -53
- package/lib/client/triggers/schedule/EndsByField.js +11 -11
- package/lib/client/triggers/schedule/OnField.js +45 -33
- package/lib/client/triggers/schedule/RepeatField.js +4 -4
- package/lib/client/triggers/schedule/ScheduleConfig.js +24 -31
- package/lib/client/triggers/schedule/index.d.ts +1 -1
- package/lib/client/triggers/schedule/index.js +32 -20
- package/lib/client/variable.d.ts +31 -13
- package/lib/client/variable.js +44 -29
- package/lib/server/Plugin.d.ts +3 -6
- package/lib/server/Plugin.js +15 -12
- package/lib/server/Processor.d.ts +3 -5
- package/lib/server/Processor.js +2 -2
- package/lib/server/actions/nodes.js +7 -7
- package/lib/server/fields/expression-field.d.ts +1 -2
- package/lib/server/fields/expression-field.js +1 -8
- package/lib/server/functions/index.d.ts +2 -3
- package/lib/server/index.d.ts +1 -0
- package/lib/server/index.js +12 -0
- package/lib/server/instructions/aggregate.d.ts +1 -1
- package/lib/server/instructions/aggregate.js +5 -5
- package/lib/server/instructions/condition.d.ts +2 -1
- package/lib/server/instructions/create.d.ts +2 -2
- package/lib/server/instructions/create.js +13 -13
- package/lib/server/instructions/delay.d.ts +3 -3
- package/lib/server/instructions/delay.js +66 -64
- package/lib/server/instructions/destroy.d.ts +1 -1
- package/lib/server/instructions/index.d.ts +5 -5
- package/lib/server/instructions/index.js +1 -1
- package/lib/server/instructions/loop.d.ts +1 -2
- package/lib/server/instructions/manual/actions.js +19 -7
- package/lib/server/instructions/manual/forms/create.js +7 -1
- package/lib/server/instructions/manual/forms/index.d.ts +1 -1
- package/lib/server/instructions/manual/forms/update.js +7 -1
- package/lib/server/instructions/manual/index.d.ts +1 -1
- package/lib/server/instructions/parallel.d.ts +1 -2
- package/lib/server/instructions/query.d.ts +1 -1
- package/lib/server/instructions/query.js +8 -1
- package/lib/server/instructions/request.d.ts +3 -3
- package/lib/server/instructions/request.js +5 -2
- package/lib/server/instructions/sql.d.ts +12 -0
- package/lib/server/instructions/sql.js +34 -0
- package/lib/server/instructions/update.d.ts +1 -1
- package/lib/server/migrations/20230221071831-calculation-expression.js +1 -1
- package/lib/server/migrations/20230221121203-condition-calculation.js +1 -1
- package/lib/server/migrations/20230221162902-jsonb-to-json.js +7 -7
- package/lib/server/migrations/20230411034722-manual-multi-form.js +1 -8
- package/lib/server/migrations/20230710115902-manual-action-values.d.ts +4 -0
- package/lib/server/migrations/20230710115902-manual-action-values.js +97 -0
- package/lib/server/triggers/collection.d.ts +1 -1
- package/lib/server/triggers/collection.js +15 -13
- package/lib/server/triggers/index.d.ts +1 -1
- package/lib/server/triggers/schedule.d.ts +1 -1
- package/lib/server/triggers/schedule.js +18 -18
- package/lib/server/{models → types}/Execution.d.ts +2 -3
- package/lib/server/{models → types}/FlowNode.d.ts +1 -2
- package/lib/server/{models → types}/Job.d.ts +1 -2
- package/lib/server/{models → types}/Workflow.d.ts +1 -2
- package/lib/server/types/index.d.ts +4 -0
- package/lib/server/types/index.js +5 -0
- package/lib/server/utils.d.ts +2 -0
- package/lib/server/utils.js +21 -0
- package/package.json +39 -18
- package/server.d.ts +2 -3
- package/server.js +1 -30
- package/src/client/AddButton.tsx +111 -0
- package/src/client/Branch.tsx +37 -0
- package/src/client/CanvasContent.tsx +25 -0
- package/src/client/ExecutionCanvas.tsx +166 -0
- package/src/client/ExecutionLink.tsx +16 -0
- package/src/client/ExecutionPage.tsx +45 -0
- package/src/client/ExecutionResourceProvider.tsx +21 -0
- package/src/client/FlowContext.ts +7 -0
- package/src/client/WorkflowCanvas.tsx +221 -0
- package/src/client/WorkflowLink.tsx +16 -0
- package/src/client/WorkflowPage.tsx +52 -0
- package/src/client/WorkflowProvider.tsx +84 -0
- package/src/client/components/CollectionBlockInitializer.tsx +71 -0
- package/src/client/components/CollectionFieldset.tsx +160 -0
- package/src/client/components/Duration.tsx +45 -0
- package/src/client/components/DynamicExpression.tsx +53 -0
- package/src/client/components/FieldsSelect.tsx +32 -0
- package/src/client/components/FilterDynamicComponent.tsx +15 -0
- package/src/client/components/NodeDescription.tsx +51 -0
- package/src/client/components/NullRender.tsx +3 -0
- package/src/client/components/OpenDrawer.tsx +24 -0
- package/src/client/components/RadioWithTooltip.tsx +38 -0
- package/src/client/components/ValueBlock.tsx +67 -0
- package/src/client/components/renderEngineReference.tsx +30 -0
- package/src/client/constants.tsx +91 -0
- package/src/client/index.tsx +51 -0
- package/src/client/interfaces/expression.tsx +25 -0
- package/src/client/locale/en-US.ts +136 -0
- package/src/client/locale/es-ES.ts +129 -0
- package/src/client/locale/index.ts +18 -0
- package/src/client/locale/ja-JP.ts +90 -0
- package/src/client/locale/pt-BR.ts +136 -0
- package/src/client/locale/ru-RU.ts +90 -0
- package/src/client/locale/tr-TR.ts +90 -0
- package/src/client/locale/zh-CN.ts +248 -0
- package/src/client/nodes/aggregate.tsx +327 -0
- package/src/client/nodes/calculation.tsx +216 -0
- package/src/client/nodes/condition.tsx +463 -0
- package/src/client/nodes/create.tsx +85 -0
- package/src/client/nodes/delay.tsx +37 -0
- package/src/client/nodes/destroy.tsx +34 -0
- package/src/client/nodes/index.tsx +485 -0
- package/src/client/nodes/loop.tsx +144 -0
- package/src/client/nodes/manual/AssigneesSelect.tsx +33 -0
- package/src/client/nodes/manual/DetailsBlockProvider.tsx +80 -0
- package/src/client/nodes/manual/FormBlockInitializer.tsx +69 -0
- package/src/client/nodes/manual/FormBlockProvider.tsx +75 -0
- package/src/client/nodes/manual/ModeConfig.tsx +84 -0
- package/src/client/nodes/manual/SchemaConfig.tsx +509 -0
- package/src/client/nodes/manual/WorkflowTodo.tsx +607 -0
- package/src/client/nodes/manual/WorkflowTodoBlockInitializer.tsx +28 -0
- package/src/client/nodes/manual/forms/create.tsx +92 -0
- package/src/client/nodes/manual/forms/custom.tsx +392 -0
- package/src/client/nodes/manual/forms/update.tsx +134 -0
- package/src/client/nodes/manual/index.tsx +162 -0
- package/src/client/nodes/manual/utils.ts +28 -0
- package/src/client/nodes/parallel.tsx +138 -0
- package/src/client/nodes/query.tsx +88 -0
- package/src/client/nodes/request.tsx +185 -0
- package/src/client/nodes/sql.tsx +37 -0
- package/src/client/nodes/update.tsx +99 -0
- package/src/client/schemas/collection.ts +75 -0
- package/src/client/schemas/executions.tsx +169 -0
- package/src/client/schemas/workflows.ts +364 -0
- package/src/client/style.tsx +347 -0
- package/src/client/triggers/collection.tsx +190 -0
- package/src/client/triggers/index.tsx +311 -0
- package/src/client/triggers/schedule/EndsByField.tsx +40 -0
- package/src/client/triggers/schedule/OnField.tsx +64 -0
- package/src/client/triggers/schedule/RepeatField.tsx +116 -0
- package/src/client/triggers/schedule/ScheduleConfig.tsx +227 -0
- package/src/client/triggers/schedule/constants.ts +4 -0
- package/src/client/triggers/schedule/index.tsx +78 -0
- package/src/client/triggers/schedule/locale/Cron.zh-CN.ts +79 -0
- package/src/client/utils.ts +36 -0
- package/src/client/variable.tsx +318 -0
- package/src/index.ts +1 -0
- package/src/server/Plugin.ts +355 -0
- package/src/server/Processor.ts +354 -0
- package/src/server/__tests__/Plugin.test.ts +398 -0
- package/src/server/__tests__/Processor.test.ts +474 -0
- package/src/server/__tests__/actions/workflows.test.ts +419 -0
- package/src/server/__tests__/collections/categories.ts +27 -0
- package/src/server/__tests__/collections/comments.ts +24 -0
- package/src/server/__tests__/collections/posts.ts +42 -0
- package/src/server/__tests__/collections/replies.ts +9 -0
- package/src/server/__tests__/collections/tags.ts +15 -0
- package/src/server/__tests__/index.ts +89 -0
- package/src/server/__tests__/instructions/aggregate.test.ts +294 -0
- package/src/server/__tests__/instructions/calculation.test.ts +265 -0
- package/src/server/__tests__/instructions/condition.test.ts +335 -0
- package/src/server/__tests__/instructions/create.test.ts +129 -0
- package/src/server/__tests__/instructions/delay.test.ts +182 -0
- package/src/server/__tests__/instructions/destroy.test.ts +58 -0
- package/src/server/__tests__/instructions/loop.test.ts +331 -0
- package/src/server/__tests__/instructions/manual.test.ts +1173 -0
- package/src/server/__tests__/instructions/parallel.test.ts +445 -0
- package/src/server/__tests__/instructions/query.test.ts +359 -0
- package/src/server/__tests__/instructions/request.test.ts +247 -0
- package/src/server/__tests__/instructions/sql.test.ts +162 -0
- package/src/server/__tests__/instructions/update.test.ts +189 -0
- package/src/server/__tests__/triggers/collection.test.ts +333 -0
- package/src/server/__tests__/triggers/schedule.test.ts +369 -0
- package/src/server/actions/index.ts +25 -0
- package/src/server/actions/nodes.ts +214 -0
- package/src/server/actions/workflows.ts +178 -0
- package/src/server/collections/executions.ts +35 -0
- package/src/server/collections/flow_nodes.ts +54 -0
- package/src/server/collections/jobs.ts +31 -0
- package/src/server/collections/workflows.ts +88 -0
- package/src/server/constants.ts +26 -0
- package/src/server/fields/expression-field.ts +11 -0
- package/src/server/fields/index.ts +7 -0
- package/src/server/functions/index.ts +16 -0
- package/src/server/index.ts +6 -0
- package/src/server/instructions/aggregate.ts +42 -0
- package/src/server/instructions/calculation.ts +41 -0
- package/src/server/instructions/condition.ts +172 -0
- package/src/server/instructions/create.ts +39 -0
- package/src/server/instructions/delay.ts +105 -0
- package/src/server/instructions/destroy.ts +23 -0
- package/src/server/instructions/index.ts +64 -0
- package/src/server/instructions/loop.ts +99 -0
- package/src/server/instructions/manual/actions.ts +91 -0
- package/src/server/instructions/manual/collecions/jobs.ts +17 -0
- package/src/server/instructions/manual/collecions/users.ts +15 -0
- package/src/server/instructions/manual/collecions/users_jobs.ts +50 -0
- package/src/server/instructions/manual/forms/create.ts +23 -0
- package/src/server/instructions/manual/forms/index.ts +12 -0
- package/src/server/instructions/manual/forms/update.ts +23 -0
- package/src/server/instructions/manual/index.ts +184 -0
- package/src/server/instructions/parallel.ts +121 -0
- package/src/server/instructions/query.ts +42 -0
- package/src/server/instructions/request.ts +88 -0
- package/src/server/instructions/sql.ts +25 -0
- package/src/server/instructions/update.ts +24 -0
- package/src/server/migrations/20221129153547-calculation-variables.ts +64 -0
- package/src/server/migrations/20230221032941-change-request-body-type.ts +76 -0
- package/src/server/migrations/20230221071831-calculation-expression.ts +102 -0
- package/src/server/migrations/20230221121203-condition-calculation.ts +82 -0
- package/src/server/migrations/20230221162902-jsonb-to-json.ts +51 -0
- package/src/server/migrations/20230411034722-manual-multi-form.ts +282 -0
- package/src/server/migrations/20230612021134-manual-collection-block.ts +138 -0
- package/src/server/migrations/20230710115902-manual-action-values.ts +78 -0
- package/src/server/triggers/collection.ts +146 -0
- package/src/server/triggers/index.ts +22 -0
- package/src/server/triggers/schedule.ts +567 -0
- package/src/server/types/Execution.ts +26 -0
- package/src/server/types/FlowNode.ts +21 -0
- package/src/server/types/Job.ts +18 -0
- package/src/server/types/Workflow.ts +36 -0
- package/src/server/types/index.ts +4 -0
- package/src/server/utils.ts +17 -0
- package/lib/client/triggers/schedule/DateFieldsSelect.d.ts +0 -2
- /package/lib/server/{models → types}/Execution.js +0 -0
- /package/lib/server/{models → types}/FlowNode.js +0 -0
- /package/lib/server/{models → types}/Job.js +0 -0
- /package/lib/server/{models → types}/Workflow.js +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Migration } from '@nocobase/server';
|
|
2
|
+
|
|
3
|
+
function addQuote(v) {
|
|
4
|
+
if (typeof v !== 'string') {
|
|
5
|
+
return v;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (v.match(/^{{\s*([^{}]+)\s*}}$/)) {
|
|
9
|
+
return v;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return `'${v}'`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const calculatorsMap = {
|
|
16
|
+
equal: '==',
|
|
17
|
+
'===': '==',
|
|
18
|
+
notEqual: '!=',
|
|
19
|
+
'!==': '!=',
|
|
20
|
+
gt: '>',
|
|
21
|
+
gte: '>=',
|
|
22
|
+
lt: '<',
|
|
23
|
+
lte: '<=',
|
|
24
|
+
add: '+',
|
|
25
|
+
minus: '-',
|
|
26
|
+
multiple: '*',
|
|
27
|
+
divide: '/',
|
|
28
|
+
mod: '%',
|
|
29
|
+
includes(a, b) {
|
|
30
|
+
return `SEARCH(${b}, ${a}) >= 0`;
|
|
31
|
+
},
|
|
32
|
+
notIncludes(a, b) {
|
|
33
|
+
return `SEARCH(${b}, ${a}) < 0`;
|
|
34
|
+
},
|
|
35
|
+
startsWith(a, b) {
|
|
36
|
+
return `SEARCH(${b}, ${a}) == 0`;
|
|
37
|
+
},
|
|
38
|
+
endsWith(a, b) {
|
|
39
|
+
return `RIGHT(${a}, LEN(${b})) == ${b}`;
|
|
40
|
+
},
|
|
41
|
+
notStartsWith(a, b) {
|
|
42
|
+
return `SEARCH(${b}, ${a}) != 0`;
|
|
43
|
+
},
|
|
44
|
+
notEndsWith(a, b) {
|
|
45
|
+
return `RIGHT(${a}, LEN(${b})) != ${b}`;
|
|
46
|
+
},
|
|
47
|
+
concat(a, b) {
|
|
48
|
+
return `CONCATENATE(${a}, ${b})`;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function migrateConfig({ calculation, ...config }: any = {}) {
|
|
53
|
+
if (!calculation?.calculator || !calculation?.operands?.length) {
|
|
54
|
+
return config;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const calculator = calculatorsMap[calculation.calculator];
|
|
58
|
+
const operands = (calculator.operands ?? []).map((operand) => addQuote(operand));
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
engine: 'formula.js',
|
|
62
|
+
expression:
|
|
63
|
+
typeof calculator === 'function'
|
|
64
|
+
? calculator(...operands)
|
|
65
|
+
: operands.join(` ${calculator ?? calculation.calculator} `),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default class extends Migration {
|
|
70
|
+
async up() {
|
|
71
|
+
const match = await this.app.version.satisfies('<0.9.0-alpha.3');
|
|
72
|
+
if (!match) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const NodeRepo = this.context.db.getRepository('flow_nodes');
|
|
77
|
+
await this.context.db.sequelize.transaction(async (transaction) => {
|
|
78
|
+
const nodes = await NodeRepo.find({
|
|
79
|
+
filter: {
|
|
80
|
+
type: 'calculation',
|
|
81
|
+
},
|
|
82
|
+
transaction,
|
|
83
|
+
});
|
|
84
|
+
console.log('%d nodes need to be migrated.', nodes.length);
|
|
85
|
+
|
|
86
|
+
await nodes.reduce(
|
|
87
|
+
(promise, node) =>
|
|
88
|
+
promise.then(() => {
|
|
89
|
+
return node.update(
|
|
90
|
+
{
|
|
91
|
+
config: migrateConfig(node.config),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
transaction,
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
}),
|
|
98
|
+
Promise.resolve(),
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Migration } from '@nocobase/server';
|
|
2
|
+
|
|
3
|
+
const calculatorsMap = {
|
|
4
|
+
equal: '==',
|
|
5
|
+
'===': '==',
|
|
6
|
+
notEqual: '!=',
|
|
7
|
+
'!==': '!=',
|
|
8
|
+
gt: '>',
|
|
9
|
+
gte: '>=',
|
|
10
|
+
lt: '<',
|
|
11
|
+
lte: '<=',
|
|
12
|
+
includes(a, b) {
|
|
13
|
+
return `SEARCH('${b}', '${a}') >= 0`;
|
|
14
|
+
},
|
|
15
|
+
notIncludes(a, b) {
|
|
16
|
+
return `SEARCH('${b}', '${a}') < 0`;
|
|
17
|
+
},
|
|
18
|
+
startsWith(a, b) {
|
|
19
|
+
return `SEARCH('${b}', '${a}') == 0`;
|
|
20
|
+
},
|
|
21
|
+
endsWith(a, b) {
|
|
22
|
+
return `RIGHT('${a}', LEN('${b}')) == '${b}'`;
|
|
23
|
+
},
|
|
24
|
+
notStartsWith(a, b) {
|
|
25
|
+
return `SEARCH('${b}', '${a}') != 0`;
|
|
26
|
+
},
|
|
27
|
+
notEndsWith(a, b) {
|
|
28
|
+
return `RIGHT('${a}', LEN('${b}')) != '${b}'`;
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function migrateConfig({ group: { type = 'and', calculations = [] } }) {
|
|
33
|
+
return {
|
|
34
|
+
group: {
|
|
35
|
+
type,
|
|
36
|
+
calculations: calculations.map(({ calculator = '===', operands = [] }: any) => {
|
|
37
|
+
return `(${operands
|
|
38
|
+
.map((operand) => (operand?.group ? migrateConfig(operand) : operand))
|
|
39
|
+
.join(` ${calculatorsMap[calculator]} `)})`;
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default class extends Migration {
|
|
46
|
+
async up() {
|
|
47
|
+
const match = await this.app.version.satisfies('<0.9.0-alpha.3');
|
|
48
|
+
if (!match) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const NodeRepo = this.context.db.getRepository('flow_nodes');
|
|
53
|
+
await this.context.db.sequelize.transaction(async (transaction) => {
|
|
54
|
+
const nodes = await NodeRepo.find({
|
|
55
|
+
filter: {
|
|
56
|
+
type: 'condition',
|
|
57
|
+
},
|
|
58
|
+
transaction,
|
|
59
|
+
});
|
|
60
|
+
console.log('%d nodes need to be migrated.', nodes.length);
|
|
61
|
+
|
|
62
|
+
await nodes.reduce(
|
|
63
|
+
(promise, node) =>
|
|
64
|
+
promise.then(() => {
|
|
65
|
+
return node.update(
|
|
66
|
+
{
|
|
67
|
+
config: {
|
|
68
|
+
...node.config,
|
|
69
|
+
engine: 'basic',
|
|
70
|
+
// calculation: migrateConfig(node.config.calculation)
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
transaction,
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
}),
|
|
78
|
+
Promise.resolve(),
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DataTypes } from '@nocobase/database';
|
|
2
|
+
|
|
3
|
+
import { Migration } from '@nocobase/server';
|
|
4
|
+
|
|
5
|
+
export default class extends Migration {
|
|
6
|
+
async up() {
|
|
7
|
+
const match = await this.app.version.satisfies('<0.9.0-alpha.3');
|
|
8
|
+
if (!match) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const sequelize = this.sequelize;
|
|
13
|
+
const queryInterface = this.queryInterface;
|
|
14
|
+
|
|
15
|
+
const { db } = this.app;
|
|
16
|
+
await sequelize.transaction(async (transaction) => {
|
|
17
|
+
await queryInterface.changeColumn(
|
|
18
|
+
db.getCollection('workflows').model.getTableName(),
|
|
19
|
+
'config',
|
|
20
|
+
{
|
|
21
|
+
type: DataTypes.JSON,
|
|
22
|
+
},
|
|
23
|
+
{ transaction },
|
|
24
|
+
);
|
|
25
|
+
await queryInterface.changeColumn(
|
|
26
|
+
db.getCollection('flow_nodes').model.getTableName(),
|
|
27
|
+
'config',
|
|
28
|
+
{
|
|
29
|
+
type: DataTypes.JSON,
|
|
30
|
+
},
|
|
31
|
+
{ transaction },
|
|
32
|
+
);
|
|
33
|
+
await queryInterface.changeColumn(
|
|
34
|
+
db.getCollection('executions').model.getTableName(),
|
|
35
|
+
'context',
|
|
36
|
+
{
|
|
37
|
+
type: DataTypes.JSON,
|
|
38
|
+
},
|
|
39
|
+
{ transaction },
|
|
40
|
+
);
|
|
41
|
+
await queryInterface.changeColumn(
|
|
42
|
+
db.getCollection('jobs').model.getTableName(),
|
|
43
|
+
'result',
|
|
44
|
+
{
|
|
45
|
+
type: DataTypes.JSON,
|
|
46
|
+
},
|
|
47
|
+
{ transaction },
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { Migration } from '@nocobase/server';
|
|
2
|
+
import { lodash, uid } from '@nocobase/utils';
|
|
3
|
+
|
|
4
|
+
function findSchema(root, filter, onlyLeaf = false) {
|
|
5
|
+
const result = [];
|
|
6
|
+
|
|
7
|
+
if (!root) {
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (filter(root) && (!onlyLeaf || !root.properties)) {
|
|
12
|
+
result.push(root);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (root.properties) {
|
|
17
|
+
Object.keys(root.properties).forEach((key) => {
|
|
18
|
+
result.push(...findSchema(root.properties[key], filter));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function findParent(root, node) {
|
|
25
|
+
return findSchema(root, (item) => item.properties && Object.values(item.properties).includes(node))[0];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 1. all form blocks combine into one, at first form block position
|
|
29
|
+
// 2. add fields move to the form
|
|
30
|
+
// 3. remove all other form blocks except first (should remove ancestors till grid)
|
|
31
|
+
// 4. add 'x-interface-options' property to all fields as collection field
|
|
32
|
+
// 5. make collection fields decorator as `FormCollectionProvider` for form block
|
|
33
|
+
// 6. add form component wrapper for form grid
|
|
34
|
+
// 7. move action footer to form block
|
|
35
|
+
function migrateConfig({ schema = {}, actions = [] }: { schema: any; actions: number[] }): object {
|
|
36
|
+
const { blocks, collection } = schema;
|
|
37
|
+
if (!blocks) {
|
|
38
|
+
return {
|
|
39
|
+
forms: {},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const root = { properties: blocks };
|
|
43
|
+
const formBlocks = findSchema(root, (item) => {
|
|
44
|
+
return (
|
|
45
|
+
item['x-component'] === 'CardItem' &&
|
|
46
|
+
item['x-designer'] === 'SimpleDesigner' &&
|
|
47
|
+
item.properties.grid['x-initializer'] === 'AddFormField'
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
if (!formBlocks.length) {
|
|
51
|
+
return {
|
|
52
|
+
schema: blocks,
|
|
53
|
+
forms: {},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 1.
|
|
58
|
+
formBlocks.forEach((formBlock, i) => {
|
|
59
|
+
const formItems = findSchema(
|
|
60
|
+
formBlock,
|
|
61
|
+
(item) => {
|
|
62
|
+
return item['x-component'] === 'CollectionField' && item['x-decorator'] === 'FormItem';
|
|
63
|
+
},
|
|
64
|
+
true,
|
|
65
|
+
);
|
|
66
|
+
// 4.
|
|
67
|
+
formItems.forEach((item) => {
|
|
68
|
+
Object.assign(item, {
|
|
69
|
+
'x-interface-options': collection.fields.find((field) => field.name === item.name),
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
// skip first form block
|
|
73
|
+
if (!i) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// 2.
|
|
77
|
+
Object.assign(formBlocks[0].properties.grid.properties, formBlock.properties.grid.properties);
|
|
78
|
+
|
|
79
|
+
// 3.
|
|
80
|
+
const col = findParent(root, formBlock);
|
|
81
|
+
const row = findParent(root, col);
|
|
82
|
+
delete row.properties[col.name];
|
|
83
|
+
if (!Object.keys(row.properties).length) {
|
|
84
|
+
const grid = findParent(root, row);
|
|
85
|
+
delete grid.properties[row.name];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// 5.
|
|
90
|
+
const [formBlock] = formBlocks;
|
|
91
|
+
Object.assign(formBlock, {
|
|
92
|
+
'x-decorator': 'FormCollectionProvider',
|
|
93
|
+
'x-decorator-props': {
|
|
94
|
+
collection,
|
|
95
|
+
},
|
|
96
|
+
'x-component-props': {
|
|
97
|
+
title: '{{t("Form")}}',
|
|
98
|
+
},
|
|
99
|
+
'x-designer-props': {
|
|
100
|
+
type: 'customForm',
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const formId = uid();
|
|
105
|
+
// 6.
|
|
106
|
+
const newFormBlock = {
|
|
107
|
+
[formId]: {
|
|
108
|
+
type: 'void',
|
|
109
|
+
'x-component': 'FormV2',
|
|
110
|
+
'x-component-props': {
|
|
111
|
+
useProps: '{{ useFormBlockProps }}',
|
|
112
|
+
},
|
|
113
|
+
properties: {
|
|
114
|
+
grid: Object.assign(formBlock.properties.grid, {
|
|
115
|
+
'x-initializer': 'AddCustomFormField',
|
|
116
|
+
}),
|
|
117
|
+
// 7.
|
|
118
|
+
actions: {
|
|
119
|
+
type: 'void',
|
|
120
|
+
'x-decorator': 'ActionBarProvider',
|
|
121
|
+
'x-component': 'ActionBar',
|
|
122
|
+
'x-component-props': {
|
|
123
|
+
layout: 'one-column',
|
|
124
|
+
style: {
|
|
125
|
+
marginTop: '1.5em',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
'x-initializer': 'AddActionButton',
|
|
129
|
+
properties: schema.actions,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
delete formBlock.properties.grid;
|
|
135
|
+
Object.assign(formBlock.properties, newFormBlock);
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
schema: blocks,
|
|
139
|
+
forms: {
|
|
140
|
+
[formId]: {
|
|
141
|
+
type: 'custom',
|
|
142
|
+
title: '{{t("Form")}}',
|
|
143
|
+
actions,
|
|
144
|
+
collection,
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function migrateUsedConfig(config, manualForms) {
|
|
151
|
+
Object.keys(config).forEach((key) => {
|
|
152
|
+
const valueType = typeof config[key];
|
|
153
|
+
if (valueType === 'string') {
|
|
154
|
+
config[key] = config[key].replace(/{{\s*\$jobsMapByNodeId\.(\d+)(\.[^}]+)?\s*}}/g, (matched, id, path) => {
|
|
155
|
+
if (!manualForms[id]) {
|
|
156
|
+
return matched;
|
|
157
|
+
}
|
|
158
|
+
return `{{$jobsMapByNodeId.${id}.${manualForms[id]}${path || ''}}}`;
|
|
159
|
+
});
|
|
160
|
+
} else if (valueType === 'object' && config[key]) {
|
|
161
|
+
migrateUsedConfig(config[key], manualForms);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return config;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export default class extends Migration {
|
|
168
|
+
async up() {
|
|
169
|
+
const match = await this.app.version.satisfies('<0.9.1-alpha.3');
|
|
170
|
+
if (!match) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const { db } = this.context;
|
|
174
|
+
const NodeRepo = db.getRepository('flow_nodes');
|
|
175
|
+
const UserJobRepo = db.getRepository('users_jobs');
|
|
176
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
177
|
+
const nodes = await NodeRepo.find({
|
|
178
|
+
filter: {
|
|
179
|
+
type: 'manual',
|
|
180
|
+
},
|
|
181
|
+
transaction,
|
|
182
|
+
});
|
|
183
|
+
console.log('%d nodes need to be migrated.', nodes.length);
|
|
184
|
+
|
|
185
|
+
await nodes.reduce(
|
|
186
|
+
(promise, node) =>
|
|
187
|
+
promise.then(() => {
|
|
188
|
+
const { forms, schema, actions, ...config } = node.config;
|
|
189
|
+
if (forms) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
return node.update(
|
|
193
|
+
{
|
|
194
|
+
config: {
|
|
195
|
+
...config,
|
|
196
|
+
...migrateConfig({ schema, actions }),
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
silent: true,
|
|
201
|
+
transaction,
|
|
202
|
+
},
|
|
203
|
+
);
|
|
204
|
+
}),
|
|
205
|
+
Promise.resolve(),
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const usersJobs = await UserJobRepo.find({
|
|
209
|
+
filter: {
|
|
210
|
+
nodeId: nodes.map((item) => item.id),
|
|
211
|
+
},
|
|
212
|
+
appends: ['job', 'node'],
|
|
213
|
+
transaction,
|
|
214
|
+
});
|
|
215
|
+
// update all results
|
|
216
|
+
await usersJobs.reduce(
|
|
217
|
+
(promise, userJob) =>
|
|
218
|
+
promise.then(async () => {
|
|
219
|
+
const { result, job, node } = userJob;
|
|
220
|
+
const { forms } = node.config;
|
|
221
|
+
const [formId] = Object.keys(forms);
|
|
222
|
+
if (result) {
|
|
223
|
+
await userJob.update(
|
|
224
|
+
{
|
|
225
|
+
result: { [formId]: result },
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
silent: true,
|
|
229
|
+
transaction,
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
if (job.result) {
|
|
234
|
+
await job.update(
|
|
235
|
+
{
|
|
236
|
+
result: { [formId]: result },
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
silent: true,
|
|
240
|
+
transaction,
|
|
241
|
+
},
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
}),
|
|
245
|
+
Promise.resolve(),
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const usedNodes = await NodeRepo.find({
|
|
249
|
+
filter: {
|
|
250
|
+
type: {
|
|
251
|
+
$notIn: ['delay', 'parallel'],
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
transaction,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const nodeForms = {};
|
|
258
|
+
nodes.forEach((node) => {
|
|
259
|
+
const [form] = Object.keys(node.config.forms);
|
|
260
|
+
if (form) {
|
|
261
|
+
nodeForms[node.id] = form;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
await usedNodes.reduce(
|
|
266
|
+
(promise, node) =>
|
|
267
|
+
promise.then(async () => {
|
|
268
|
+
await node.update(
|
|
269
|
+
{
|
|
270
|
+
config: migrateUsedConfig(lodash.cloneDeep(node.config ?? {}), nodeForms),
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
silent: true,
|
|
274
|
+
transaction,
|
|
275
|
+
},
|
|
276
|
+
);
|
|
277
|
+
}),
|
|
278
|
+
Promise.resolve(),
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Migration } from '@nocobase/server';
|
|
2
|
+
import { uid } from '@nocobase/utils';
|
|
3
|
+
|
|
4
|
+
function findSchema(root, filter, onlyLeaf = false) {
|
|
5
|
+
const result = [];
|
|
6
|
+
|
|
7
|
+
if (!root) {
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (filter(root) && (!onlyLeaf || !root.properties)) {
|
|
12
|
+
result.push(root);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (root.properties) {
|
|
17
|
+
Object.keys(root.properties).forEach((key) => {
|
|
18
|
+
result.push(...findSchema(root.properties[key], filter));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function migrateSchema(schema = {}): object {
|
|
25
|
+
const root = { properties: schema };
|
|
26
|
+
const collectionBlocks = findSchema(root, (item) => {
|
|
27
|
+
return (
|
|
28
|
+
item['x-component'] === 'CardItem' &&
|
|
29
|
+
item['x-designer'] === 'SimpleDesigner' &&
|
|
30
|
+
item['x-decorator'] === 'CollectionProvider'
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
collectionBlocks.forEach((block) => {
|
|
35
|
+
const id = uid();
|
|
36
|
+
const { grid } = block.properties;
|
|
37
|
+
delete block.properties.grid;
|
|
38
|
+
const fields = findSchema(grid, (item) => {
|
|
39
|
+
return item['x-decorator'] === 'FormItem';
|
|
40
|
+
});
|
|
41
|
+
fields.forEach((field) => {
|
|
42
|
+
Object.assign(field, {
|
|
43
|
+
'x-component': 'CollectionField',
|
|
44
|
+
'x-collection-field': `${block['x-decorator-props'].collection}.${field['x-collection-field']}`,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
Object.assign(block, {
|
|
49
|
+
'x-decorator': 'DetailsBlockProvider',
|
|
50
|
+
'x-decorator-props': {
|
|
51
|
+
...block['x-decorator-props'],
|
|
52
|
+
dataSource: grid['x-context-datasource'],
|
|
53
|
+
},
|
|
54
|
+
properties: {
|
|
55
|
+
[id]: {
|
|
56
|
+
type: 'void',
|
|
57
|
+
name: id,
|
|
58
|
+
'x-component': 'FormV2',
|
|
59
|
+
'x-component-props': {
|
|
60
|
+
useProps: '{{useDetailsBlockProps}}',
|
|
61
|
+
},
|
|
62
|
+
properties: {
|
|
63
|
+
grid: {
|
|
64
|
+
type: 'void',
|
|
65
|
+
name: 'grid',
|
|
66
|
+
'x-component': 'Grid',
|
|
67
|
+
'x-initializer': 'ReadPrettyFormItemInitializers',
|
|
68
|
+
properties: grid.properties,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const customForms = findSchema(root, (item) => {
|
|
77
|
+
return item['x-decorator'] === 'FormCollectionProvider';
|
|
78
|
+
});
|
|
79
|
+
customForms.forEach((item) => {
|
|
80
|
+
Object.assign(item, {
|
|
81
|
+
'x-decorator': 'CustomFormBlockProvider',
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const customFormFields = findSchema(root, (item) => {
|
|
86
|
+
return item['x-interface-options'];
|
|
87
|
+
});
|
|
88
|
+
customFormFields.forEach((field) => {
|
|
89
|
+
const options = field['x-interface-options'];
|
|
90
|
+
delete field['x-interface-options'];
|
|
91
|
+
Object.assign(field, {
|
|
92
|
+
'x-component-props': {
|
|
93
|
+
field: options,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return schema;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default class extends Migration {
|
|
102
|
+
async up() {
|
|
103
|
+
const match = await this.app.version.satisfies('<0.9.4-alpha.3');
|
|
104
|
+
if (!match) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const { db } = this.context;
|
|
108
|
+
const NodeRepo = db.getRepository('flow_nodes');
|
|
109
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
110
|
+
const nodes = await NodeRepo.find({
|
|
111
|
+
filter: {
|
|
112
|
+
type: 'manual',
|
|
113
|
+
},
|
|
114
|
+
transaction,
|
|
115
|
+
});
|
|
116
|
+
console.log('%d nodes need to be migrated.', nodes.length);
|
|
117
|
+
|
|
118
|
+
await nodes.reduce(
|
|
119
|
+
(promise, node) =>
|
|
120
|
+
promise.then(() => {
|
|
121
|
+
const { schema, ...config } = node.config;
|
|
122
|
+
node.set('config', {
|
|
123
|
+
...config,
|
|
124
|
+
schema: {
|
|
125
|
+
...migrateSchema(schema),
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
node.changed('config', true);
|
|
129
|
+
return node.save({
|
|
130
|
+
silent: true,
|
|
131
|
+
transaction,
|
|
132
|
+
});
|
|
133
|
+
}),
|
|
134
|
+
Promise.resolve(),
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|