@nocobase/plugin-workflow 0.9.0-alpha.2 → 0.9.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/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/lib/client/AddButton.d.ts +1 -1
- package/lib/client/AddButton.js +7 -2
- package/lib/client/Branch.d.ts +1 -1
- package/lib/client/ExecutionCanvas.js +5 -10
- package/lib/client/WorkflowCanvas.js +11 -40
- package/lib/client/WorkflowProvider.js +10 -1
- package/lib/client/components/CollectionBlockInitializer.d.ts +7 -0
- package/lib/client/components/CollectionBlockInitializer.js +81 -0
- package/lib/client/components/CollectionFieldInitializers.d.ts +2 -0
- package/lib/client/components/CollectionFieldInitializers.js +89 -0
- package/lib/client/components/CollectionFieldset.js +21 -25
- package/lib/client/components/FilterDynamicComponent.d.ts +6 -0
- package/lib/client/components/FilterDynamicComponent.js +43 -0
- package/lib/client/components/NullRender.d.ts +1 -0
- package/lib/client/components/NullRender.js +10 -0
- package/lib/client/components/RadioWithTooltip.d.ts +7 -0
- package/lib/client/components/RadioWithTooltip.js +94 -0
- package/lib/client/constants.d.ts +10 -8
- package/lib/client/constants.js +52 -14
- package/lib/client/index.d.ts +0 -1
- package/lib/client/index.js +1 -10
- package/lib/client/locale/en-US.d.ts +18 -18
- package/lib/client/locale/en-US.js +19 -19
- package/lib/client/locale/zh-CN.d.ts +47 -20
- package/lib/client/locale/zh-CN.js +48 -21
- package/lib/client/nodes/calculation.d.ts +40 -6
- package/lib/client/nodes/calculation.js +171 -19
- package/lib/client/nodes/condition.d.ts +67 -0
- package/lib/client/nodes/condition.js +287 -27
- package/lib/client/nodes/create.d.ts +8 -6
- package/lib/client/nodes/create.js +27 -33
- package/lib/client/nodes/delay.d.ts +2 -0
- package/lib/client/nodes/delay.js +8 -4
- package/lib/client/nodes/destroy.d.ts +2 -2
- package/lib/client/nodes/destroy.js +2 -2
- package/lib/client/nodes/index.d.ts +10 -2
- package/lib/client/nodes/index.js +73 -27
- package/lib/client/nodes/manual/AssigneesSelect.d.ts +6 -0
- package/lib/client/nodes/manual/AssigneesSelect.js +64 -0
- package/lib/client/nodes/manual/ModeConfig.d.ts +5 -0
- package/lib/client/nodes/manual/ModeConfig.js +160 -0
- package/lib/client/nodes/manual/SchemaConfig.d.ts +6 -0
- package/lib/client/nodes/manual/SchemaConfig.js +715 -0
- package/lib/client/nodes/manual/WorkflowTodo.d.ts +8 -0
- package/lib/client/nodes/manual/WorkflowTodo.js +691 -0
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +5 -0
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +75 -0
- package/lib/client/nodes/manual/index.d.ts +64 -0
- package/lib/client/nodes/manual/index.js +146 -0
- package/lib/client/nodes/parallel.d.ts +11 -5
- package/lib/client/nodes/parallel.js +22 -34
- package/lib/client/nodes/query.d.ts +9 -14
- package/lib/client/nodes/query.js +38 -44
- package/lib/client/nodes/request.d.ts +75 -33
- package/lib/client/nodes/request.js +124 -63
- package/lib/client/nodes/update.d.ts +2 -2
- package/lib/client/nodes/update.js +2 -2
- package/lib/client/schemas/collection.js +1 -1
- package/lib/client/schemas/executions.js +1 -1
- package/lib/client/schemas/workflows.js +1 -1
- package/lib/client/style.js +0 -4
- package/lib/client/triggers/collection.d.ts +7 -3
- package/lib/client/triggers/collection.js +39 -48
- package/lib/client/triggers/index.d.ts +5 -2
- package/lib/client/triggers/index.js +34 -12
- package/lib/client/triggers/schedule/index.d.ts +7 -5
- package/lib/client/triggers/schedule/index.js +38 -79
- package/lib/client/utils.d.ts +1 -0
- package/lib/client/utils.js +38 -0
- package/lib/client/variable.d.ts +21 -0
- package/lib/client/variable.js +147 -0
- package/lib/server/Plugin.d.ts +3 -3
- package/lib/server/Plugin.js +12 -21
- package/lib/server/Processor.d.ts +9 -2
- package/lib/server/Processor.js +33 -33
- package/lib/server/actions/index.js +2 -4
- package/lib/server/actions/workflows.d.ts +1 -0
- package/lib/server/actions/workflows.js +80 -23
- package/lib/server/collections/executions.js +5 -7
- package/lib/server/collections/flow_nodes.js +6 -18
- package/lib/server/collections/jobs.js +3 -1
- package/lib/server/collections/workflows.js +8 -4
- package/lib/server/constants.d.ts +9 -3
- package/lib/server/constants.js +11 -5
- package/lib/server/functions/index.d.ts +4 -0
- package/lib/server/functions/index.js +38 -0
- package/lib/server/index.d.ts +0 -1
- package/lib/server/index.js +0 -14
- package/lib/server/instructions/calculation.d.ts +2 -7
- package/lib/server/instructions/calculation.js +32 -37
- package/lib/server/instructions/condition.d.ts +4 -4
- package/lib/server/instructions/condition.js +126 -54
- package/lib/server/instructions/index.js +1 -1
- package/lib/server/instructions/manual/actions.js +101 -0
- package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts +2 -0
- package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.js +2 -1
- package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js +10 -10
- package/lib/server/instructions/manual/index.d.ts +25 -0
- package/lib/server/instructions/manual/index.js +200 -0
- package/lib/server/instructions/parallel.js +11 -7
- package/lib/server/instructions/request.d.ts +5 -4
- package/lib/server/instructions/request.js +60 -79
- package/lib/server/migrations/20230221032941-change-request-body-type.d.ts +5 -0
- package/lib/server/migrations/20230221032941-change-request-body-type.js +113 -0
- package/lib/server/migrations/20230221071831-calculation-expression.d.ts +4 -0
- package/lib/server/migrations/20230221071831-calculation-expression.js +143 -0
- package/lib/server/migrations/20230221121203-condition-calculation.d.ts +4 -0
- package/lib/server/migrations/20230221121203-condition-calculation.js +126 -0
- package/lib/server/migrations/20230221162902-jsonb-to-json.d.ts +4 -0
- package/lib/server/migrations/20230221162902-jsonb-to-json.js +81 -0
- package/lib/server/triggers/schedule.js +11 -3
- package/package.json +10 -10
- package/lib/client/calculators.d.ts +0 -89
- package/lib/client/calculators.js +0 -668
- package/lib/client/components/CollectionFieldSelect.d.ts +0 -2
- package/lib/client/components/CollectionFieldSelect.js +0 -106
- package/lib/client/components/EjsTextArea.d.ts +0 -2
- package/lib/client/components/EjsTextArea.js +0 -232
- package/lib/server/actions/jobs.d.ts +0 -2
- package/lib/server/actions/jobs.js +0 -39
- package/lib/server/calculators/index.d.ts +0 -40
- package/lib/server/calculators/index.js +0 -187
- package/lib/server/extensions/assignees/actions.js +0 -75
- package/lib/server/extensions/assignees/index.d.ts +0 -2
- package/lib/server/extensions/assignees/index.js +0 -273
- package/lib/server/extensions/index.d.ts +0 -3
- package/lib/server/extensions/index.js +0 -13
- package/lib/server/instructions/prompt.d.ts +0 -19
- package/lib/server/instructions/prompt.js +0 -131
- /package/lib/server/{extensions/assignees → instructions/manual}/actions.d.ts +0 -0
- /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.d.ts +0 -0
- /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.js +0 -0
- /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.d.ts +0 -0
|
@@ -5,54 +5,49 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
function _evaluators() {
|
|
9
|
+
const data = _interopRequireDefault(require("@nocobase/evaluators"));
|
|
10
|
+
|
|
11
|
+
_evaluators = function _evaluators() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
8
18
|
var _constants = require("../constants");
|
|
9
19
|
|
|
10
|
-
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
21
|
|
|
12
22
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
13
23
|
|
|
14
24
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
15
25
|
|
|
16
|
-
// @calculation: {
|
|
17
|
-
// calculator: 'concat',
|
|
18
|
-
// operands: [
|
|
19
|
-
// {
|
|
20
|
-
// type: 'calculation',
|
|
21
|
-
// options: {
|
|
22
|
-
// calculator: 'add',
|
|
23
|
-
// operands: [{ value: 1 }, { value: 2 }]
|
|
24
|
-
// }
|
|
25
|
-
// },
|
|
26
|
-
// {
|
|
27
|
-
// type: 'constant',
|
|
28
|
-
// value: '{{$context.data.title}}'
|
|
29
|
-
// },
|
|
30
|
-
// {
|
|
31
|
-
// type: 'context',
|
|
32
|
-
// options: {
|
|
33
|
-
// path: 'data.title'
|
|
34
|
-
// }
|
|
35
|
-
// },
|
|
36
|
-
// {
|
|
37
|
-
// type: 'constant',
|
|
38
|
-
// value: 1
|
|
39
|
-
// }
|
|
40
|
-
// ]
|
|
41
|
-
// }
|
|
42
26
|
var _default = {
|
|
43
27
|
run(node, prevJob, processor) {
|
|
44
28
|
return _asyncToGenerator(function* () {
|
|
45
29
|
const _ref = node.config || {},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
_ref$engine = _ref.engine,
|
|
31
|
+
engine = _ref$engine === void 0 ? 'math.js' : _ref$engine,
|
|
32
|
+
_ref$expression = _ref.expression,
|
|
33
|
+
expression = _ref$expression === void 0 ? '' : _ref$expression;
|
|
34
|
+
|
|
35
|
+
const evaluator = _evaluators().default.get(engine);
|
|
36
|
+
|
|
37
|
+
const scope = processor.getScope();
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const result = evaluator && expression ? evaluator(expression, scope) : null;
|
|
41
|
+
return {
|
|
42
|
+
result,
|
|
43
|
+
status: _constants.JOB_STATUS.RESOLVED
|
|
44
|
+
};
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return {
|
|
47
|
+
result: e.toString(),
|
|
48
|
+
status: _constants.JOB_STATUS.ERROR
|
|
49
|
+
};
|
|
50
|
+
}
|
|
56
51
|
})();
|
|
57
52
|
}
|
|
58
53
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Registry } from "@nocobase/utils";
|
|
2
|
+
import { Instruction } from ".";
|
|
3
|
+
export declare const calculators: Registry<Function>;
|
|
4
|
+
declare const _default: Instruction;
|
|
5
5
|
export default _default;
|
|
@@ -3,88 +3,160 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.calculators = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
function _utils() {
|
|
9
|
+
const data = require("@nocobase/utils");
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
_utils = function _utils() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _evaluators() {
|
|
19
|
+
const data = _interopRequireDefault(require("@nocobase/evaluators"));
|
|
11
20
|
|
|
12
|
-
|
|
21
|
+
_evaluators = function _evaluators() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
13
24
|
|
|
14
|
-
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _constants = require("../constants");
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
31
|
|
|
16
32
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
17
33
|
|
|
18
34
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
19
35
|
|
|
20
|
-
//
|
|
21
|
-
// not: false,
|
|
22
|
-
// group: {
|
|
23
|
-
// type: 'and',
|
|
24
|
-
// calculations: [
|
|
25
|
-
// {
|
|
26
|
-
// calculator: 'time.equal',
|
|
27
|
-
// operands: [{ value: '{{$context.time}}' }, { value: '{{$fn.now}}' }]
|
|
28
|
-
// },
|
|
29
|
-
// {
|
|
30
|
-
// calculator: 'value.equal',
|
|
31
|
-
// operands: [{ value: '{{$jobsMapByNodeId.213}}' }, { value: 1 }]
|
|
32
|
-
// },
|
|
33
|
-
// {
|
|
34
|
-
// group: {
|
|
35
|
-
// type: 'or',
|
|
36
|
-
// calculations: [
|
|
37
|
-
// {
|
|
38
|
-
// calculator: 'value.equal',
|
|
39
|
-
// operands: [{ value: '{{$jobsMapByNodeId.213}}' }, { value: 1 }]
|
|
40
|
-
// }
|
|
41
|
-
// ]
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
// ]
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
function logicCalculate(calculation, input, processor) {
|
|
48
|
-
if (!calculation) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
36
|
+
const calculators = new (_utils().Registry)(); // built-in functions
|
|
51
37
|
|
|
52
|
-
|
|
53
|
-
group = calculation.group;
|
|
54
|
-
let result;
|
|
38
|
+
exports.calculators = calculators;
|
|
55
39
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} else {
|
|
60
|
-
const args = calculation.operands.map(operand => (0, _calculators.calculate)(operand, input, processor));
|
|
40
|
+
function equal(a, b) {
|
|
41
|
+
return a === b;
|
|
42
|
+
}
|
|
61
43
|
|
|
62
|
-
|
|
44
|
+
function notEqual(a, b) {
|
|
45
|
+
return a !== b;
|
|
46
|
+
}
|
|
63
47
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
function gt(a, b) {
|
|
49
|
+
return a > b;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function gte(a, b) {
|
|
53
|
+
return a >= b;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function lt(a, b) {
|
|
57
|
+
return a < b;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function lte(a, b) {
|
|
61
|
+
return a <= b;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
calculators.register('equal', equal);
|
|
65
|
+
calculators.register('notEqual', notEqual);
|
|
66
|
+
calculators.register('gt', gt);
|
|
67
|
+
calculators.register('gte', gte);
|
|
68
|
+
calculators.register('lt', lt);
|
|
69
|
+
calculators.register('lte', lte);
|
|
70
|
+
calculators.register('===', equal);
|
|
71
|
+
calculators.register('!==', notEqual);
|
|
72
|
+
calculators.register('>', gt);
|
|
73
|
+
calculators.register('>=', gte);
|
|
74
|
+
calculators.register('<', lt);
|
|
75
|
+
calculators.register('<=', lte);
|
|
76
|
+
|
|
77
|
+
function includes(a, b) {
|
|
78
|
+
return a.includes(b);
|
|
79
|
+
}
|
|
67
80
|
|
|
68
|
-
|
|
81
|
+
function notIncludes(a, b) {
|
|
82
|
+
return !a.includes(b);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function startsWith(a, b) {
|
|
86
|
+
return a.startsWith(b);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function notStartsWith(a, b) {
|
|
90
|
+
return !a.startsWith(b);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function endsWith(a, b) {
|
|
94
|
+
return a.endsWith(b);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function notEndsWith(a, b) {
|
|
98
|
+
return !a.endsWith(b);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
calculators.register('includes', includes);
|
|
102
|
+
calculators.register('notIncludes', notIncludes);
|
|
103
|
+
calculators.register('startsWith', startsWith);
|
|
104
|
+
calculators.register('notStartsWith', notStartsWith);
|
|
105
|
+
calculators.register('endsWith', endsWith);
|
|
106
|
+
calculators.register('notEndsWith', notEndsWith);
|
|
107
|
+
|
|
108
|
+
function calculate(calculation = {}) {
|
|
109
|
+
var _calculation$operands;
|
|
110
|
+
|
|
111
|
+
let fn;
|
|
112
|
+
|
|
113
|
+
if (!(calculation.calculator && (fn = calculators.get(calculation.calculator)))) {
|
|
114
|
+
throw new Error(`no calculator function registered for "${calculation.calculator}"`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return Boolean(fn(...((_calculation$operands = calculation.operands) !== null && _calculation$operands !== void 0 ? _calculation$operands : [])));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function logicCalculate(calculation) {
|
|
121
|
+
if (!calculation) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (typeof calculation['group'] === 'object') {
|
|
126
|
+
var _calculation$group$ca;
|
|
127
|
+
|
|
128
|
+
const method = calculation['group'].type === 'and' ? 'every' : 'some';
|
|
129
|
+
return ((_calculation$group$ca = calculation['group'].calculations) !== null && _calculation$group$ca !== void 0 ? _calculation$group$ca : [])[method](item => logicCalculate(item));
|
|
69
130
|
}
|
|
70
131
|
|
|
71
|
-
return
|
|
132
|
+
return calculate(calculation);
|
|
72
133
|
}
|
|
73
134
|
|
|
74
135
|
var _default = {
|
|
75
136
|
run(node, prevJob, processor) {
|
|
76
137
|
return _asyncToGenerator(function* () {
|
|
77
|
-
// TODO(optimize): loading of jobs could be reduced and turned into incrementally in processor
|
|
78
|
-
// const jobs = await processor.getJobs();
|
|
79
138
|
const _ref = node.config || {},
|
|
139
|
+
engine = _ref.engine,
|
|
80
140
|
calculation = _ref.calculation,
|
|
141
|
+
expression = _ref.expression,
|
|
81
142
|
rejectOnFalse = _ref.rejectOnFalse;
|
|
82
143
|
|
|
83
|
-
const
|
|
144
|
+
const evaluator = _evaluators().default.get(engine);
|
|
145
|
+
|
|
146
|
+
let result = true;
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
result = evaluator ? evaluator(expression, processor.getScope()) : logicCalculate(processor.getParsedValue(calculation));
|
|
150
|
+
} catch (e) {
|
|
151
|
+
return {
|
|
152
|
+
result: e.toString(),
|
|
153
|
+
status: _constants.JOB_STATUS.ERROR
|
|
154
|
+
};
|
|
155
|
+
}
|
|
84
156
|
|
|
85
157
|
if (!result && rejectOnFalse) {
|
|
86
158
|
return {
|
|
87
|
-
status: _constants.JOB_STATUS.
|
|
159
|
+
status: _constants.JOB_STATUS.FAILED,
|
|
88
160
|
result
|
|
89
161
|
};
|
|
90
162
|
}
|
|
@@ -47,7 +47,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
47
47
|
|
|
48
48
|
function _default(plugin, more = {}) {
|
|
49
49
|
const instructions = plugin.instructions;
|
|
50
|
-
const natives = ['calculation', 'condition', 'parallel', 'delay', '
|
|
50
|
+
const natives = ['calculation', 'condition', 'parallel', 'delay', 'manual', 'query', 'create', 'update', 'destroy', 'request'].reduce((result, key) => Object.assign(result, {
|
|
51
51
|
[key]: (0, _utils().requireModule)(_path().default.isAbsolute(key) ? key : _path().default.join(__dirname, key))
|
|
52
52
|
}), {});
|
|
53
53
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.submit = submit;
|
|
7
|
+
|
|
8
|
+
function _actions() {
|
|
9
|
+
const data = require("@nocobase/actions");
|
|
10
|
+
|
|
11
|
+
_actions = function _actions() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var _constants = require("../../constants");
|
|
19
|
+
|
|
20
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
21
|
+
|
|
22
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
23
|
+
|
|
24
|
+
function submit(_x, _x2) {
|
|
25
|
+
return _submit.apply(this, arguments);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _submit() {
|
|
29
|
+
_submit = _asyncToGenerator(function* (context, next) {
|
|
30
|
+
const repository = _actions().utils.getRepositoryFromParams(context);
|
|
31
|
+
|
|
32
|
+
const _context$action$param = context.action.params,
|
|
33
|
+
filterByTk = _context$action$param.filterByTk,
|
|
34
|
+
values = _context$action$param.values;
|
|
35
|
+
const currentUser = context.state.currentUser;
|
|
36
|
+
|
|
37
|
+
if (!currentUser) {
|
|
38
|
+
return context.throw(401);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const plugin = context.app.pm.get('workflow');
|
|
42
|
+
const userJob = yield context.db.sequelize.transaction( /*#__PURE__*/function () {
|
|
43
|
+
var _ref = _asyncToGenerator(function* (transaction) {
|
|
44
|
+
var _instance$node$config2;
|
|
45
|
+
|
|
46
|
+
const instance = yield repository.findOne({
|
|
47
|
+
filterByTk,
|
|
48
|
+
// filter: {
|
|
49
|
+
// userId: currentUser?.id
|
|
50
|
+
// },
|
|
51
|
+
appends: ['job', 'node', 'execution', 'workflow'],
|
|
52
|
+
context,
|
|
53
|
+
transaction
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (!instance) {
|
|
57
|
+
return context.throw(404);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const _instance$node$config = instance.node.config.actions,
|
|
61
|
+
actions = _instance$node$config === void 0 ? [] : _instance$node$config; // NOTE: validate status
|
|
62
|
+
|
|
63
|
+
if (instance.status !== _constants.JOB_STATUS.PENDING || instance.job.status !== _constants.JOB_STATUS.PENDING || instance.execution.status !== _constants.EXECUTION_STATUS.STARTED || !instance.workflow.enabled || !actions.includes(values.status)) {
|
|
64
|
+
return context.throw(400);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
instance.execution.workflow = instance.workflow;
|
|
68
|
+
const processor = plugin.createProcessor(instance.execution, {
|
|
69
|
+
transaction
|
|
70
|
+
});
|
|
71
|
+
yield processor.prepare();
|
|
72
|
+
const assignees = processor.getParsedValue((_instance$node$config2 = instance.node.config.assignees) !== null && _instance$node$config2 !== void 0 ? _instance$node$config2 : []);
|
|
73
|
+
|
|
74
|
+
if (!assignees.includes(currentUser.id) || instance.userId !== currentUser.id) {
|
|
75
|
+
return context.throw(403);
|
|
76
|
+
} // NOTE: validate assignee
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
yield instance.update({
|
|
80
|
+
status: values.status,
|
|
81
|
+
result: values.result
|
|
82
|
+
}, {
|
|
83
|
+
transaction
|
|
84
|
+
});
|
|
85
|
+
return instance;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return function (_x3) {
|
|
89
|
+
return _ref.apply(this, arguments);
|
|
90
|
+
};
|
|
91
|
+
}()); // await transaction.commit();
|
|
92
|
+
|
|
93
|
+
context.body = userJob;
|
|
94
|
+
context.status = 202;
|
|
95
|
+
yield next();
|
|
96
|
+
userJob.job.latestUserJob = userJob; // NOTE: resume the process and no `await` for quick returning
|
|
97
|
+
|
|
98
|
+
plugin.resume(userJob.job);
|
|
99
|
+
});
|
|
100
|
+
return _submit.apply(this, arguments);
|
|
101
|
+
}
|
package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts
RENAMED
|
@@ -6,11 +6,13 @@ declare const _default: {
|
|
|
6
6
|
through: string;
|
|
7
7
|
target?: undefined;
|
|
8
8
|
foreignKey?: undefined;
|
|
9
|
+
onDelete?: undefined;
|
|
9
10
|
} | {
|
|
10
11
|
type: string;
|
|
11
12
|
name: string;
|
|
12
13
|
target: string;
|
|
13
14
|
foreignKey: string;
|
|
15
|
+
onDelete: string;
|
|
14
16
|
through?: undefined;
|
|
15
17
|
})[];
|
|
16
18
|
};
|
package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js
RENAMED
|
@@ -5,26 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _default = {
|
|
8
|
+
namespace: 'workflow',
|
|
8
9
|
name: 'users_jobs',
|
|
10
|
+
duplicator: 'optional',
|
|
9
11
|
fields: [{
|
|
10
12
|
type: 'bigInt',
|
|
11
13
|
name: 'id',
|
|
12
14
|
primaryKey: true,
|
|
13
15
|
autoIncrement: true
|
|
14
|
-
}, {
|
|
15
|
-
type: 'bigInt',
|
|
16
|
-
name: 'userId',
|
|
17
|
-
primaryKey: false
|
|
18
|
-
}, {
|
|
19
|
-
type: 'bigInt',
|
|
20
|
-
name: 'jobId',
|
|
21
|
-
primaryKey: false
|
|
22
16
|
}, {
|
|
23
17
|
type: 'belongsTo',
|
|
24
|
-
name: 'job'
|
|
18
|
+
name: 'job',
|
|
19
|
+
target: 'jobs',
|
|
20
|
+
foreignKey: 'jobId',
|
|
21
|
+
primaryKey: false
|
|
25
22
|
}, {
|
|
26
23
|
type: 'belongsTo',
|
|
27
|
-
name: 'user'
|
|
24
|
+
name: 'user',
|
|
25
|
+
target: 'users',
|
|
26
|
+
foreignKey: 'userId',
|
|
27
|
+
primaryKey: false
|
|
28
28
|
}, {
|
|
29
29
|
type: 'belongsTo',
|
|
30
30
|
name: 'execution'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Plugin from '../..';
|
|
2
|
+
import { Instruction } from '..';
|
|
3
|
+
export interface ManualConfig {
|
|
4
|
+
schema: {
|
|
5
|
+
collection: {
|
|
6
|
+
name: string;
|
|
7
|
+
fields: any[];
|
|
8
|
+
};
|
|
9
|
+
blocks: {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
};
|
|
12
|
+
actions: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
actions: number[];
|
|
17
|
+
assignees?: number[];
|
|
18
|
+
mode?: number;
|
|
19
|
+
}
|
|
20
|
+
export default class implements Instruction {
|
|
21
|
+
protected plugin: Plugin;
|
|
22
|
+
constructor(plugin: Plugin);
|
|
23
|
+
run(node: any, prevJob: any, processor: any): Promise<any>;
|
|
24
|
+
resume(node: any, job: any, processor: any): Promise<any>;
|
|
25
|
+
}
|