@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
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _actions() {
|
|
9
|
+
const data = _interopRequireDefault(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
|
+
var _jobs = _interopRequireDefault(require("./collecions/jobs"));
|
|
21
|
+
|
|
22
|
+
var _users = _interopRequireDefault(require("./collecions/users"));
|
|
23
|
+
|
|
24
|
+
var _users_jobs = _interopRequireDefault(require("./collecions/users_jobs"));
|
|
25
|
+
|
|
26
|
+
var _actions2 = require("./actions");
|
|
27
|
+
|
|
28
|
+
const _excluded = ["mode"];
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
+
|
|
32
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
33
|
+
|
|
34
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
35
|
+
|
|
36
|
+
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); } }
|
|
37
|
+
|
|
38
|
+
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); }); }; }
|
|
39
|
+
|
|
40
|
+
const MULTIPLE_ASSIGNED_MODE = {
|
|
41
|
+
SINGLE: Symbol('single'),
|
|
42
|
+
ALL: Symbol('all'),
|
|
43
|
+
ANY: Symbol('any'),
|
|
44
|
+
ALL_PERCENTAGE: Symbol('all percentage'),
|
|
45
|
+
ANY_PERCENTAGE: Symbol('any percentage')
|
|
46
|
+
};
|
|
47
|
+
const Modes = {
|
|
48
|
+
[MULTIPLE_ASSIGNED_MODE.SINGLE]: {
|
|
49
|
+
getStatus(distribution, assignees) {
|
|
50
|
+
const done = distribution.find(item => item.status !== _constants.JOB_STATUS.PENDING && item.count > 0);
|
|
51
|
+
return done ? done.status : null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
},
|
|
55
|
+
[MULTIPLE_ASSIGNED_MODE.ALL]: {
|
|
56
|
+
getStatus(distribution, assignees) {
|
|
57
|
+
const resolved = distribution.find(item => item.status === _constants.JOB_STATUS.RESOLVED);
|
|
58
|
+
|
|
59
|
+
if (resolved && resolved.count === assignees.length) {
|
|
60
|
+
return _constants.JOB_STATUS.RESOLVED;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const rejected = distribution.find(item => item.status < _constants.JOB_STATUS.PENDING);
|
|
64
|
+
|
|
65
|
+
if (rejected && rejected.count) {
|
|
66
|
+
return rejected.status;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
},
|
|
73
|
+
[MULTIPLE_ASSIGNED_MODE.ANY]: {
|
|
74
|
+
getStatus(distribution, assignees) {
|
|
75
|
+
const resolved = distribution.find(item => item.status === _constants.JOB_STATUS.RESOLVED);
|
|
76
|
+
|
|
77
|
+
if (resolved && resolved.count) {
|
|
78
|
+
return _constants.JOB_STATUS.RESOLVED;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const rejectedCount = distribution.reduce((count, item) => item.status < _constants.JOB_STATUS.PENDING ? count + item.count : count, 0); // NOTE: all failures are considered as rejected for now
|
|
82
|
+
|
|
83
|
+
if (rejectedCount === assignees.length) {
|
|
84
|
+
return _constants.JOB_STATUS.REJECTED;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
function getMode(mode) {
|
|
94
|
+
switch (true) {
|
|
95
|
+
case mode === 1:
|
|
96
|
+
return Modes[MULTIPLE_ASSIGNED_MODE.ALL];
|
|
97
|
+
|
|
98
|
+
case mode === -1:
|
|
99
|
+
return Modes[MULTIPLE_ASSIGNED_MODE.ANY];
|
|
100
|
+
|
|
101
|
+
case mode > 0:
|
|
102
|
+
return Modes[MULTIPLE_ASSIGNED_MODE.ALL_PERCENTAGE];
|
|
103
|
+
|
|
104
|
+
case mode < 0:
|
|
105
|
+
return Modes[MULTIPLE_ASSIGNED_MODE.ANY_PERCENTAGE];
|
|
106
|
+
|
|
107
|
+
default:
|
|
108
|
+
return Modes[MULTIPLE_ASSIGNED_MODE.SINGLE];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class _default {
|
|
113
|
+
constructor(plugin) {
|
|
114
|
+
this.plugin = void 0;
|
|
115
|
+
this.plugin = plugin;
|
|
116
|
+
plugin.db.collection(_users_jobs.default);
|
|
117
|
+
plugin.db.extendCollection(_users.default);
|
|
118
|
+
plugin.db.extendCollection(_jobs.default);
|
|
119
|
+
plugin.app.resource({
|
|
120
|
+
name: 'users_jobs',
|
|
121
|
+
actions: {
|
|
122
|
+
list: {
|
|
123
|
+
filter: {
|
|
124
|
+
$or: [{
|
|
125
|
+
'workflow.enabled': true
|
|
126
|
+
}, {
|
|
127
|
+
'workflow.enabled': false,
|
|
128
|
+
status: {
|
|
129
|
+
$ne: _constants.JOB_STATUS.PENDING
|
|
130
|
+
}
|
|
131
|
+
}]
|
|
132
|
+
},
|
|
133
|
+
handler: _actions().default.list
|
|
134
|
+
},
|
|
135
|
+
submit: _actions2.submit
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
run(node, prevJob, processor) {
|
|
141
|
+
return _asyncToGenerator(function* () {
|
|
142
|
+
var _prevJob$id;
|
|
143
|
+
|
|
144
|
+
const _node$config = node.config,
|
|
145
|
+
mode = _node$config.mode,
|
|
146
|
+
config = _objectWithoutProperties(_node$config, _excluded);
|
|
147
|
+
|
|
148
|
+
const assignees = [...new Set(processor.getParsedValue(config.assignees) || [])];
|
|
149
|
+
const job = yield processor.saveJob({
|
|
150
|
+
status: _constants.JOB_STATUS.PENDING,
|
|
151
|
+
result: mode ? [] : null,
|
|
152
|
+
nodeId: node.id,
|
|
153
|
+
upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
|
|
154
|
+
}); // NOTE: batch create users jobs
|
|
155
|
+
|
|
156
|
+
const UserJobModel = processor.options.plugin.db.getModel('users_jobs');
|
|
157
|
+
yield UserJobModel.bulkCreate(assignees.map(userId => ({
|
|
158
|
+
userId,
|
|
159
|
+
jobId: job.id,
|
|
160
|
+
nodeId: node.id,
|
|
161
|
+
executionId: job.executionId,
|
|
162
|
+
workflowId: node.workflowId,
|
|
163
|
+
status: _constants.JOB_STATUS.PENDING
|
|
164
|
+
})), {
|
|
165
|
+
transaction: processor.transaction
|
|
166
|
+
});
|
|
167
|
+
return job;
|
|
168
|
+
})();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
resume(node, job, processor) {
|
|
172
|
+
return _asyncToGenerator(function* () {
|
|
173
|
+
var _job$latestUserJob$re, _job$latestUserJob, _getMode$getStatus;
|
|
174
|
+
|
|
175
|
+
// NOTE: check all users jobs related if all done then continue as parallel
|
|
176
|
+
const _node$config2 = node.config,
|
|
177
|
+
_node$config2$assigne = _node$config2.assignees,
|
|
178
|
+
assignees = _node$config2$assigne === void 0 ? [] : _node$config2$assigne,
|
|
179
|
+
mode = _node$config2.mode;
|
|
180
|
+
const UserJobModel = processor.options.plugin.db.getModel('users_jobs');
|
|
181
|
+
const distribution = yield UserJobModel.count({
|
|
182
|
+
where: {
|
|
183
|
+
jobId: job.id
|
|
184
|
+
},
|
|
185
|
+
group: ['status']
|
|
186
|
+
});
|
|
187
|
+
const submitted = distribution.reduce((count, item) => item.status !== _constants.JOB_STATUS.PENDING ? count + item.count : count, 0);
|
|
188
|
+
const result = mode ? (submitted || 0) / assignees.length : (_job$latestUserJob$re = (_job$latestUserJob = job.latestUserJob) === null || _job$latestUserJob === void 0 ? void 0 : _job$latestUserJob.result) !== null && _job$latestUserJob$re !== void 0 ? _job$latestUserJob$re : job.result;
|
|
189
|
+
job.set({
|
|
190
|
+
status: job.status || ((_getMode$getStatus = getMode(mode).getStatus(distribution, assignees)) !== null && _getMode$getStatus !== void 0 ? _getMode$getStatus : _constants.JOB_STATUS.PENDING),
|
|
191
|
+
result
|
|
192
|
+
});
|
|
193
|
+
return job;
|
|
194
|
+
})();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
exports.default = _default;
|
|
200
|
+
;
|
|
@@ -20,12 +20,14 @@ exports.PARALLEL_MODE = PARALLEL_MODE;
|
|
|
20
20
|
const Modes = {
|
|
21
21
|
[PARALLEL_MODE.ALL]: {
|
|
22
22
|
next(previous) {
|
|
23
|
-
return previous.status
|
|
23
|
+
return previous.status >= _constants.JOB_STATUS.PENDING;
|
|
24
24
|
},
|
|
25
25
|
|
|
26
26
|
getStatus(result) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const failedStatus = result.find(status => status != null && status < _constants.JOB_STATUS.PENDING);
|
|
28
|
+
|
|
29
|
+
if (typeof failedStatus !== 'undefined') {
|
|
30
|
+
return failedStatus;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
if (result.every(status => status != null && status === _constants.JOB_STATUS.RESOLVED)) {
|
|
@@ -38,7 +40,7 @@ const Modes = {
|
|
|
38
40
|
},
|
|
39
41
|
[PARALLEL_MODE.ANY]: {
|
|
40
42
|
next(previous) {
|
|
41
|
-
return previous.status
|
|
43
|
+
return previous.status <= _constants.JOB_STATUS.PENDING;
|
|
42
44
|
},
|
|
43
45
|
|
|
44
46
|
getStatus(result) {
|
|
@@ -50,7 +52,7 @@ const Modes = {
|
|
|
50
52
|
return _constants.JOB_STATUS.PENDING;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
return _constants.JOB_STATUS.
|
|
55
|
+
return _constants.JOB_STATUS.FAILED;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
},
|
|
@@ -64,8 +66,10 @@ const Modes = {
|
|
|
64
66
|
return _constants.JOB_STATUS.RESOLVED;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
const failedStatus = result.find(status => status != null && status < _constants.JOB_STATUS.PENDING);
|
|
70
|
+
|
|
71
|
+
if (typeof failedStatus !== 'undefined') {
|
|
72
|
+
return failedStatus;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
return _constants.JOB_STATUS.PENDING;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { Instruction } from './index';
|
|
3
|
+
import Processor from '../Processor';
|
|
4
|
+
import FlowNodeModel from '../models/FlowNode';
|
|
3
5
|
export interface Header {
|
|
4
6
|
name: string;
|
|
5
7
|
value: string;
|
|
6
8
|
}
|
|
7
|
-
export declare type RequestConfig = Pick<AxiosRequestConfig, 'url' | 'method' | 'data' | 'timeout'> & {
|
|
9
|
+
export declare type RequestConfig = Pick<AxiosRequestConfig, 'url' | 'method' | 'params' | 'data' | 'timeout'> & {
|
|
8
10
|
headers: Array<Header>;
|
|
9
11
|
ignoreFail: boolean;
|
|
10
12
|
};
|
|
11
13
|
export default class implements Instruction {
|
|
12
14
|
plugin: any;
|
|
13
15
|
constructor(plugin: any);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
resume(node: any, job: any, processor: any): Promise<any>;
|
|
16
|
+
run(node: FlowNodeModel, input: any, processor: Processor): Promise<any>;
|
|
17
|
+
resume(node: FlowNodeModel, job: any, processor: Processor): Promise<any>;
|
|
17
18
|
}
|
|
@@ -5,16 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
function _ejs() {
|
|
9
|
-
const data = require("ejs");
|
|
10
|
-
|
|
11
|
-
_ejs = function _ejs() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
8
|
function _axios() {
|
|
19
9
|
const data = _interopRequireDefault(require("axios"));
|
|
20
10
|
|
|
@@ -33,91 +23,82 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
33
23
|
|
|
34
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); }); }; }
|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
function request(_x) {
|
|
27
|
+
return _request.apply(this, arguments);
|
|
28
|
+
}
|
|
39
29
|
|
|
40
|
-
|
|
30
|
+
function _request() {
|
|
31
|
+
_request = _asyncToGenerator(function* (config) {
|
|
32
|
+
var _config$headers, _config$params;
|
|
33
|
+
|
|
34
|
+
// default headers
|
|
35
|
+
const url = config.url,
|
|
36
|
+
_config$method = config.method,
|
|
37
|
+
method = _config$method === void 0 ? 'POST' : _config$method,
|
|
38
|
+
data = config.data,
|
|
39
|
+
_config$timeout = config.timeout,
|
|
40
|
+
timeout = _config$timeout === void 0 ? 5000 : _config$timeout;
|
|
41
|
+
const headers = ((_config$headers = config.headers) !== null && _config$headers !== void 0 ? _config$headers : []).reduce((result, header) => {
|
|
42
|
+
if (header.name.toLowerCase() === 'content-type') {
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const templateVars = {
|
|
45
|
-
node: processor.jobsMapByNodeId,
|
|
46
|
-
ctx: processor.execution.context,
|
|
47
|
-
$jobsMapByNodeId: processor.jobsMapByNodeId,
|
|
48
|
-
$context: processor.execution.context
|
|
49
|
-
};
|
|
50
|
-
const requestConfig = node.config; // default headers
|
|
51
|
-
|
|
52
|
-
const headers = {
|
|
53
|
-
'Content-Type': 'application/json'
|
|
54
|
-
};
|
|
55
|
-
const _requestConfig$header = requestConfig.headers,
|
|
56
|
-
headerArr = _requestConfig$header === void 0 ? [] : _requestConfig$header,
|
|
57
|
-
_requestConfig$method = requestConfig.method,
|
|
58
|
-
method = _requestConfig$method === void 0 ? 'POST' : _requestConfig$method,
|
|
59
|
-
_requestConfig$timeou = requestConfig.timeout,
|
|
60
|
-
timeout = _requestConfig$timeou === void 0 ? 5000 : _requestConfig$timeou;
|
|
61
|
-
headerArr.forEach(header => headers[header.name] = header.value);
|
|
62
|
-
let url, data;
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
url = yield (0, _ejs().render)(requestConfig.url.trim(), templateVars, {
|
|
66
|
-
async: true
|
|
67
|
-
});
|
|
68
|
-
data = requestConfig.data ? yield (0, _ejs().render)(requestConfig.data.trim(), templateVars, {
|
|
69
|
-
async: true
|
|
70
|
-
}) : undefined;
|
|
71
|
-
} catch (error2) {
|
|
72
|
-
// console.error(error2);
|
|
73
|
-
job.set({
|
|
74
|
-
status: _constants.JOB_STATUS.REJECTED,
|
|
75
|
-
result: error2.message
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const response = yield _axios().default.request({
|
|
81
|
-
url,
|
|
82
|
-
method,
|
|
83
|
-
headers,
|
|
84
|
-
data,
|
|
85
|
-
timeout
|
|
86
|
-
});
|
|
87
|
-
job.set({
|
|
88
|
-
status: _constants.JOB_STATUS.RESOLVED,
|
|
89
|
-
result: response.data
|
|
90
|
-
});
|
|
91
|
-
} catch (error1) {
|
|
92
|
-
// console.error('axios error?', error1);
|
|
93
|
-
job.set({
|
|
94
|
-
status: _constants.JOB_STATUS.REJECTED,
|
|
95
|
-
result: error1.isAxiosError ? error1.toJSON() : error1.message
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return _this.plugin.resume(job);
|
|
46
|
+
return Object.assign(result, {
|
|
47
|
+
[header.name]: header.value
|
|
100
48
|
});
|
|
49
|
+
}, {});
|
|
50
|
+
const params = ((_config$params = config.params) !== null && _config$params !== void 0 ? _config$params : []).reduce((result, param) => Object.assign(result, {
|
|
51
|
+
[param.name]: param.value
|
|
52
|
+
}), {}); // TODO(feat): only support JSON type for now, should support others in future
|
|
53
|
+
|
|
54
|
+
headers['Content-Type'] = 'application/json';
|
|
55
|
+
return _axios().default.request({
|
|
56
|
+
url,
|
|
57
|
+
method,
|
|
58
|
+
headers,
|
|
59
|
+
params,
|
|
60
|
+
data,
|
|
61
|
+
timeout
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
return _request.apply(this, arguments);
|
|
65
|
+
}
|
|
101
66
|
|
|
102
|
-
|
|
103
|
-
return _ref.apply(this, arguments);
|
|
104
|
-
};
|
|
105
|
-
}();
|
|
67
|
+
;
|
|
106
68
|
|
|
69
|
+
class _default {
|
|
70
|
+
constructor(plugin) {
|
|
71
|
+
this.plugin = void 0;
|
|
107
72
|
this.plugin = plugin;
|
|
108
73
|
}
|
|
109
74
|
|
|
110
75
|
run(node, input, processor) {
|
|
111
|
-
var
|
|
76
|
+
var _this = this;
|
|
112
77
|
|
|
113
78
|
return _asyncToGenerator(function* () {
|
|
114
79
|
const job = yield processor.saveJob({
|
|
115
80
|
status: _constants.JOB_STATUS.PENDING,
|
|
116
81
|
nodeId: node.id
|
|
117
82
|
});
|
|
118
|
-
|
|
119
|
-
|
|
83
|
+
const config = processor.getParsedValue(node.config);
|
|
84
|
+
request(config).then(response => {
|
|
85
|
+
job.set({
|
|
86
|
+
status: _constants.JOB_STATUS.RESOLVED,
|
|
87
|
+
result: response.data
|
|
88
|
+
});
|
|
89
|
+
}).catch(error => {
|
|
90
|
+
job.set({
|
|
91
|
+
status: _constants.JOB_STATUS.FAILED,
|
|
92
|
+
result: error.isAxiosError ? error.toJSON() : error.message
|
|
93
|
+
});
|
|
94
|
+
}).finally(() => {
|
|
95
|
+
_this.plugin.app.logger.info(`[Workflow] request (#${node.id}) response received, status: ${job.get('status')}`);
|
|
96
|
+
|
|
97
|
+
_this.plugin.resume(job);
|
|
120
98
|
});
|
|
99
|
+
|
|
100
|
+
_this.plugin.app.logger.info(`[Workflow] request (#${node.id}) sent to "${config.url}", waiting for response...`);
|
|
101
|
+
|
|
121
102
|
return job;
|
|
122
103
|
})();
|
|
123
104
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _server() {
|
|
9
|
+
const data = require("@nocobase/server");
|
|
10
|
+
|
|
11
|
+
_server = function _server() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
|
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
+
|
|
24
|
+
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); } }
|
|
25
|
+
|
|
26
|
+
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); }); }; }
|
|
27
|
+
|
|
28
|
+
const EJS_RE = /"?<%=\s*(ctx|node)([\w\.\[\]-]+)\s*.*%>"?/;
|
|
29
|
+
|
|
30
|
+
function migrateData(input) {
|
|
31
|
+
if (typeof input !== 'string') {
|
|
32
|
+
return input;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!input) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const typeMap = {
|
|
40
|
+
ctx: '$context',
|
|
41
|
+
node: '$jobsMapByNodeId'
|
|
42
|
+
};
|
|
43
|
+
return input.replace(EJS_RE, (_, type, path) => {
|
|
44
|
+
if (type === 'ctx') {
|
|
45
|
+
return `"{{$context${path}}}"`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (type === 'node') {
|
|
49
|
+
return `"{{$jobsMapByNodeId${path.replace('[', '.').replace(']', '.').replace(/\.$/, '')}}}"`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return _;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class _default extends _server().Migration {
|
|
57
|
+
up() {
|
|
58
|
+
var _this = this;
|
|
59
|
+
|
|
60
|
+
return _asyncToGenerator(function* () {
|
|
61
|
+
const match = yield _this.app.version.satisfies('<0.9.0-alpha.3');
|
|
62
|
+
|
|
63
|
+
if (!match) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const NodeRepo = _this.context.db.getRepository('flow_nodes');
|
|
68
|
+
|
|
69
|
+
yield _this.context.db.sequelize.transaction( /*#__PURE__*/function () {
|
|
70
|
+
var _ref = _asyncToGenerator(function* (transaction) {
|
|
71
|
+
const nodes = yield NodeRepo.find({
|
|
72
|
+
filter: {
|
|
73
|
+
type: 'request'
|
|
74
|
+
},
|
|
75
|
+
transaction
|
|
76
|
+
});
|
|
77
|
+
console.log('%d nodes need to be migrated.', nodes.length);
|
|
78
|
+
yield nodes.reduce((promise, node) => promise.then( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
79
|
+
if (typeof node.config.data !== 'string') {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let data = migrateData(node.config.data);
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
data = JSON.parse(node.config.data);
|
|
87
|
+
return node.update({
|
|
88
|
+
config: _objectSpread(_objectSpread({}, node.config), {}, {
|
|
89
|
+
data
|
|
90
|
+
})
|
|
91
|
+
}, {
|
|
92
|
+
transaction
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error(`flow_node #${node.id} config migrating failed! you should migrate its format from ejs to json-templates manually in your db.`);
|
|
96
|
+
}
|
|
97
|
+
})), Promise.resolve());
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return function (_x) {
|
|
101
|
+
return _ref.apply(this, arguments);
|
|
102
|
+
};
|
|
103
|
+
}());
|
|
104
|
+
})();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
down() {
|
|
108
|
+
return _asyncToGenerator(function* () {})();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
exports.default = _default;
|