@nocobase/plugin-workflow 0.7.0-alpha.9 → 0.7.1-alpha.6
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/lib/Plugin.d.ts +18 -0
- package/lib/Plugin.js +285 -0
- package/lib/Processor.d.ts +40 -0
- package/lib/Processor.js +440 -0
- package/lib/actions/index.d.ts +3 -1
- package/lib/actions/index.js +33 -26
- package/{esm/actions/flow_nodes.d.ts → lib/actions/nodes.d.ts} +1 -0
- package/lib/actions/nodes.js +321 -0
- package/lib/actions/workflows.d.ts +2 -0
- package/lib/actions/workflows.js +197 -0
- package/lib/calculators/index.d.ts +2 -2
- package/lib/calculators/index.js +144 -92
- package/lib/collections/executions.js +32 -38
- package/lib/collections/flow_nodes.js +60 -72
- package/lib/collections/jobs.js +26 -47
- package/lib/collections/workflows.d.ts +1 -2
- package/lib/collections/workflows.js +70 -63
- package/lib/constants.js +22 -17
- package/lib/index.d.ts +4 -3
- package/lib/index.js +85 -22
- package/lib/instructions/calculation.d.ts +1 -1
- package/lib/instructions/calculation.js +32 -29
- package/lib/instructions/condition.d.ts +2 -2
- package/lib/instructions/condition.js +91 -88
- package/lib/instructions/create.d.ts +2 -2
- package/lib/instructions/create.js +39 -25
- package/lib/instructions/delay.d.ts +14 -0
- package/lib/instructions/delay.js +138 -0
- package/lib/instructions/destroy.d.ts +1 -1
- package/lib/instructions/destroy.js +38 -25
- package/lib/instructions/index.d.ts +11 -8
- package/lib/instructions/index.js +76 -25
- package/lib/instructions/parallel.d.ts +3 -3
- package/lib/instructions/parallel.js +95 -84
- package/lib/instructions/prompt.d.ts +2 -2
- package/lib/instructions/prompt.js +21 -13
- package/lib/instructions/query.d.ts +2 -1
- package/lib/instructions/query.js +42 -25
- package/lib/instructions/update.d.ts +2 -1
- package/lib/instructions/update.js +40 -25
- package/lib/models/Execution.d.ts +3 -33
- package/lib/models/Execution.js +18 -254
- package/lib/models/FlowNode.js +18 -5
- package/lib/models/Job.js +18 -5
- package/lib/models/Workflow.d.ts +5 -6
- package/lib/models/Workflow.js +18 -76
- package/lib/triggers/collection.d.ts +12 -0
- package/lib/triggers/collection.js +184 -0
- package/lib/triggers/index.d.ts +11 -7
- package/lib/triggers/index.js +64 -11
- package/lib/triggers/schedule.d.ts +38 -0
- package/lib/triggers/schedule.js +672 -0
- package/package.json +8 -12
- package/esm/actions/flow_nodes.js +0 -139
- package/esm/actions/flow_nodes.js.map +0 -1
- package/esm/actions/index.d.ts +0 -1
- package/esm/actions/index.js +0 -8
- package/esm/actions/index.js.map +0 -1
- package/esm/calculators/index.d.ts +0 -38
- package/esm/calculators/index.js +0 -128
- package/esm/calculators/index.js.map +0 -1
- package/esm/collections/executions.d.ts +0 -3
- package/esm/collections/executions.js +0 -38
- package/esm/collections/executions.js.map +0 -1
- package/esm/collections/flow_nodes.d.ts +0 -3
- package/esm/collections/flow_nodes.js +0 -72
- package/esm/collections/flow_nodes.js.map +0 -1
- package/esm/collections/jobs.d.ts +0 -3
- package/esm/collections/jobs.js +0 -47
- package/esm/collections/jobs.js.map +0 -1
- package/esm/collections/workflows.d.ts +0 -3
- package/esm/collections/workflows.js +0 -63
- package/esm/collections/workflows.js.map +0 -1
- package/esm/constants.d.ts +0 -17
- package/esm/constants.js +0 -18
- package/esm/constants.js.map +0 -1
- package/esm/index.d.ts +0 -5
- package/esm/index.js +0 -6
- package/esm/index.js.map +0 -1
- package/esm/instructions/calculation.d.ts +0 -8
- package/esm/instructions/calculation.js +0 -55
- package/esm/instructions/calculation.js.map +0 -1
- package/esm/instructions/condition.d.ts +0 -5
- package/esm/instructions/condition.js +0 -99
- package/esm/instructions/condition.js.map +0 -1
- package/esm/instructions/create.d.ts +0 -8
- package/esm/instructions/create.js +0 -25
- package/esm/instructions/create.js.map +0 -1
- package/esm/instructions/destroy.d.ts +0 -8
- package/esm/instructions/destroy.js +0 -25
- package/esm/instructions/destroy.js.map +0 -1
- package/esm/instructions/index.d.ts +0 -15
- package/esm/instructions/index.js +0 -20
- package/esm/instructions/index.js.map +0 -1
- package/esm/instructions/parallel.d.ts +0 -13
- package/esm/instructions/parallel.js +0 -88
- package/esm/instructions/parallel.js.map +0 -1
- package/esm/instructions/prompt.d.ts +0 -7
- package/esm/instructions/prompt.js +0 -13
- package/esm/instructions/prompt.js.map +0 -1
- package/esm/instructions/query.d.ts +0 -8
- package/esm/instructions/query.js +0 -25
- package/esm/instructions/query.js.map +0 -1
- package/esm/instructions/update.d.ts +0 -8
- package/esm/instructions/update.js +0 -25
- package/esm/instructions/update.js.map +0 -1
- package/esm/models/Execution.d.ts +0 -50
- package/esm/models/Execution.js +0 -250
- package/esm/models/Execution.js.map +0 -1
- package/esm/models/FlowNode.d.ts +0 -17
- package/esm/models/FlowNode.js +0 -4
- package/esm/models/FlowNode.js.map +0 -1
- package/esm/models/Job.d.ts +0 -15
- package/esm/models/Job.js +0 -4
- package/esm/models/Job.js.map +0 -1
- package/esm/models/Workflow.d.ts +0 -27
- package/esm/models/Workflow.js +0 -72
- package/esm/models/Workflow.js.map +0 -1
- package/esm/server.d.ts +0 -5
- package/esm/server.js +0 -62
- package/esm/server.js.map +0 -1
- package/esm/triggers/index.d.ts +0 -9
- package/esm/triggers/index.js +0 -6
- package/esm/triggers/index.js.map +0 -1
- package/esm/triggers/model.d.ts +0 -12
- package/esm/triggers/model.js +0 -47
- package/esm/triggers/model.js.map +0 -1
- package/lib/actions/flow_nodes.d.ts +0 -3
- package/lib/actions/flow_nodes.js +0 -163
- package/lib/actions/flow_nodes.js.map +0 -1
- package/lib/actions/index.js.map +0 -1
- package/lib/calculators/index.js.map +0 -1
- package/lib/collections/executions.js.map +0 -1
- package/lib/collections/flow_nodes.js.map +0 -1
- package/lib/collections/jobs.js.map +0 -1
- package/lib/collections/workflows.js.map +0 -1
- package/lib/constants.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/instructions/calculation.js.map +0 -1
- package/lib/instructions/condition.js.map +0 -1
- package/lib/instructions/create.js.map +0 -1
- package/lib/instructions/destroy.js.map +0 -1
- package/lib/instructions/index.js.map +0 -1
- package/lib/instructions/parallel.js.map +0 -1
- package/lib/instructions/prompt.js.map +0 -1
- package/lib/instructions/query.js.map +0 -1
- package/lib/instructions/update.js.map +0 -1
- package/lib/models/Execution.js.map +0 -1
- package/lib/models/FlowNode.js.map +0 -1
- package/lib/models/Job.js.map +0 -1
- package/lib/models/Workflow.js.map +0 -1
- package/lib/server.d.ts +0 -5
- package/lib/server.js +0 -68
- package/lib/server.js.map +0 -1
- package/lib/triggers/index.js.map +0 -1
- package/lib/triggers/model.d.ts +0 -12
- package/lib/triggers/model.js +0 -49
- package/lib/triggers/model.js.map +0 -1
- package/tsconfig.build.json +0 -9
package/lib/Processor.js
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _jsonTemplates() {
|
|
9
|
+
const data = _interopRequireDefault(require("json-templates"));
|
|
10
|
+
|
|
11
|
+
_jsonTemplates = function _jsonTemplates() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _database() {
|
|
19
|
+
const data = require("@nocobase/database");
|
|
20
|
+
|
|
21
|
+
_database = function _database() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _calculators = _interopRequireDefault(require("./calculators"));
|
|
29
|
+
|
|
30
|
+
var _constants = require("./constants");
|
|
31
|
+
|
|
32
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
|
+
|
|
34
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
35
|
+
|
|
36
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
37
|
+
|
|
38
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
39
|
+
|
|
40
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
41
|
+
|
|
42
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
43
|
+
|
|
44
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
45
|
+
|
|
46
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
47
|
+
|
|
48
|
+
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; }
|
|
49
|
+
|
|
50
|
+
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; }
|
|
51
|
+
|
|
52
|
+
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; }
|
|
53
|
+
|
|
54
|
+
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); } }
|
|
55
|
+
|
|
56
|
+
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); }); }; }
|
|
57
|
+
|
|
58
|
+
class Processor {
|
|
59
|
+
constructor(execution, options) {
|
|
60
|
+
this.execution = void 0;
|
|
61
|
+
this.options = void 0;
|
|
62
|
+
this.transaction = void 0;
|
|
63
|
+
this.nodes = [];
|
|
64
|
+
this.nodesMap = new Map();
|
|
65
|
+
this.jobsMap = new Map();
|
|
66
|
+
this.jobsMapByNodeId = {};
|
|
67
|
+
this.execution = execution;
|
|
68
|
+
this.options = options;
|
|
69
|
+
} // make dual linked nodes list then cache
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
makeNodes(nodes = []) {
|
|
73
|
+
this.nodes = nodes;
|
|
74
|
+
nodes.forEach(node => {
|
|
75
|
+
this.nodesMap.set(node.id, node);
|
|
76
|
+
});
|
|
77
|
+
nodes.forEach(node => {
|
|
78
|
+
if (node.upstreamId) {
|
|
79
|
+
node.upstream = this.nodesMap.get(node.upstreamId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (node.downstreamId) {
|
|
83
|
+
node.downstream = this.nodesMap.get(node.downstreamId);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
makeJobs(jobs) {
|
|
89
|
+
jobs.forEach(job => {
|
|
90
|
+
this.jobsMap.set(job.id, job); // TODO: should consider cycle, and from previous job
|
|
91
|
+
|
|
92
|
+
this.jobsMapByNodeId[job.nodeId] = job.result;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getTransaction() {
|
|
97
|
+
var _this = this;
|
|
98
|
+
|
|
99
|
+
return _asyncToGenerator(function* () {
|
|
100
|
+
if (!_this.execution.useTransaction) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const options = _this.options;
|
|
105
|
+
const sequelize = _this.execution.constructor.database.sequelize; // @ts-ignore
|
|
106
|
+
|
|
107
|
+
const transaction = options.transaction && !options.transaction.finished ? options.transaction : yield sequelize.transaction(); // @ts-ignore
|
|
108
|
+
|
|
109
|
+
if (_this.execution.transaction !== transaction.id) {
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
yield _this.execution.update({
|
|
112
|
+
transaction: transaction.id
|
|
113
|
+
}, {
|
|
114
|
+
transaction
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return transaction;
|
|
119
|
+
})();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
prepare(commit) {
|
|
123
|
+
var _this2 = this;
|
|
124
|
+
|
|
125
|
+
return _asyncToGenerator(function* () {
|
|
126
|
+
const transaction = yield _this2.getTransaction();
|
|
127
|
+
_this2.transaction = transaction;
|
|
128
|
+
const execution = _this2.execution;
|
|
129
|
+
|
|
130
|
+
if (!execution.workflow) {
|
|
131
|
+
execution.workflow = yield execution.getWorkflow({
|
|
132
|
+
transaction
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const nodes = yield execution.workflow.getNodes({
|
|
137
|
+
transaction
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
_this2.makeNodes(nodes);
|
|
141
|
+
|
|
142
|
+
const jobs = yield execution.getJobs({
|
|
143
|
+
order: [['id', 'ASC']],
|
|
144
|
+
transaction
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
_this2.makeJobs(jobs);
|
|
148
|
+
|
|
149
|
+
if (commit) {
|
|
150
|
+
yield _this2.commit();
|
|
151
|
+
}
|
|
152
|
+
})();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
start() {
|
|
156
|
+
var _this3 = this;
|
|
157
|
+
|
|
158
|
+
return _asyncToGenerator(function* () {
|
|
159
|
+
const execution = _this3.execution;
|
|
160
|
+
|
|
161
|
+
if (execution.status !== _constants.EXECUTION_STATUS.STARTED) {
|
|
162
|
+
throw new Error(`execution was ended with status ${execution.status}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
yield _this3.prepare();
|
|
166
|
+
|
|
167
|
+
if (_this3.nodes.length) {
|
|
168
|
+
const head = _this3.nodes.find(item => !item.upstream);
|
|
169
|
+
|
|
170
|
+
yield _this3.run(head, {
|
|
171
|
+
result: execution.context
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
yield _this3.exit(null);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
yield _this3.commit();
|
|
178
|
+
})();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
resume(job) {
|
|
182
|
+
var _this4 = this;
|
|
183
|
+
|
|
184
|
+
return _asyncToGenerator(function* () {
|
|
185
|
+
const execution = _this4.execution;
|
|
186
|
+
|
|
187
|
+
if (execution.status !== _constants.EXECUTION_STATUS.STARTED) {
|
|
188
|
+
throw new Error(`execution was ended with status ${execution.status}`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
yield _this4.prepare();
|
|
192
|
+
|
|
193
|
+
const node = _this4.nodesMap.get(job.nodeId);
|
|
194
|
+
|
|
195
|
+
yield _this4.recall(node, job);
|
|
196
|
+
yield _this4.commit();
|
|
197
|
+
})();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
commit() {
|
|
201
|
+
var _this5 = this;
|
|
202
|
+
|
|
203
|
+
return _asyncToGenerator(function* () {
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
if (_this5.transaction && (!_this5.options.transaction || _this5.options.transaction.finished)) {
|
|
206
|
+
yield _this5.transaction.commit();
|
|
207
|
+
}
|
|
208
|
+
})();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
exec(instruction, node, prevJob) {
|
|
212
|
+
var _this6 = this;
|
|
213
|
+
|
|
214
|
+
return _asyncToGenerator(function* () {
|
|
215
|
+
let job;
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
// call instruction to get result and status
|
|
219
|
+
job = yield instruction(node, prevJob, _this6);
|
|
220
|
+
|
|
221
|
+
if (!job) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
} catch (err) {
|
|
225
|
+
// for uncaught error, set to rejected
|
|
226
|
+
job = {
|
|
227
|
+
result: err instanceof Error ? {
|
|
228
|
+
message: err.message,
|
|
229
|
+
stack: process.env.NODE_ENV === 'production' ? [] : err.stack
|
|
230
|
+
} : err,
|
|
231
|
+
status: _constants.JOB_STATUS.REJECTED
|
|
232
|
+
}; // if previous job is from resuming
|
|
233
|
+
|
|
234
|
+
if (prevJob && prevJob.nodeId === node.id) {
|
|
235
|
+
prevJob.set(job);
|
|
236
|
+
job = prevJob;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let savedJob; // TODO(optimize): many checking of resuming or new could be improved
|
|
241
|
+
// could be implemented separately in exec() / resume()
|
|
242
|
+
|
|
243
|
+
if (job instanceof _database().Model) {
|
|
244
|
+
savedJob = yield job.save({
|
|
245
|
+
transaction: _this6.transaction
|
|
246
|
+
});
|
|
247
|
+
} else {
|
|
248
|
+
const upstreamId = prevJob instanceof _database().Model ? prevJob.get('id') : null;
|
|
249
|
+
savedJob = yield _this6.saveJob(_objectSpread({
|
|
250
|
+
nodeId: node.id,
|
|
251
|
+
upstreamId
|
|
252
|
+
}, job));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (savedJob.status === _constants.JOB_STATUS.RESOLVED && node.downstream) {
|
|
256
|
+
// run next node
|
|
257
|
+
return _this6.run(node.downstream, savedJob);
|
|
258
|
+
} // all nodes in scope have been executed
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
return _this6.end(node, savedJob);
|
|
262
|
+
})();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
run(node, input) {
|
|
266
|
+
var _this7 = this;
|
|
267
|
+
|
|
268
|
+
return _asyncToGenerator(function* () {
|
|
269
|
+
const instructions = _this7.options.plugin.instructions;
|
|
270
|
+
|
|
271
|
+
const _instructions$get = instructions.get(node.type),
|
|
272
|
+
run = _instructions$get.run;
|
|
273
|
+
|
|
274
|
+
if (typeof run !== 'function') {
|
|
275
|
+
return Promise.reject(new Error('`run` should be implemented for customized execution of the node'));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return _this7.exec(run, node, input);
|
|
279
|
+
})();
|
|
280
|
+
} // parent node should take over the control
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
end(node, job) {
|
|
284
|
+
const parentNode = this.findBranchParentNode(node); // no parent, means on main flow
|
|
285
|
+
|
|
286
|
+
if (parentNode) {
|
|
287
|
+
return this.recall(parentNode, job);
|
|
288
|
+
} // really done for all nodes
|
|
289
|
+
// * should mark execution as done with last job status
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
return this.exit(job);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
recall(node, job) {
|
|
296
|
+
var _this8 = this;
|
|
297
|
+
|
|
298
|
+
return _asyncToGenerator(function* () {
|
|
299
|
+
const instructions = _this8.options.plugin.instructions;
|
|
300
|
+
|
|
301
|
+
const _instructions$get2 = instructions.get(node.type),
|
|
302
|
+
resume = _instructions$get2.resume;
|
|
303
|
+
|
|
304
|
+
if (typeof resume !== 'function') {
|
|
305
|
+
return Promise.reject(new Error('`resume` should be implemented'));
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return _this8.exec(resume, node, job);
|
|
309
|
+
})();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
exit(job) {
|
|
313
|
+
var _this9 = this;
|
|
314
|
+
|
|
315
|
+
return _asyncToGenerator(function* () {
|
|
316
|
+
const status = job ? _this9.constructor.StatusMap[job.status] : _constants.EXECUTION_STATUS.RESOLVED;
|
|
317
|
+
yield _this9.execution.update({
|
|
318
|
+
status
|
|
319
|
+
}, {
|
|
320
|
+
transaction: _this9.transaction
|
|
321
|
+
});
|
|
322
|
+
return null;
|
|
323
|
+
})();
|
|
324
|
+
} // TODO(optimize)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
saveJob(payload) {
|
|
328
|
+
var _this10 = this;
|
|
329
|
+
|
|
330
|
+
return _asyncToGenerator(function* () {
|
|
331
|
+
const database = _this10.execution.constructor.database;
|
|
332
|
+
|
|
333
|
+
const _database$getCollecti = database.getCollection('jobs'),
|
|
334
|
+
model = _database$getCollecti.model;
|
|
335
|
+
|
|
336
|
+
let job;
|
|
337
|
+
|
|
338
|
+
if (payload instanceof model) {
|
|
339
|
+
job = yield payload.save({
|
|
340
|
+
transaction: _this10.transaction
|
|
341
|
+
});
|
|
342
|
+
} else if (payload.id) {
|
|
343
|
+
var _yield$model$update = yield model.update(payload, {
|
|
344
|
+
where: {
|
|
345
|
+
id: payload.id
|
|
346
|
+
},
|
|
347
|
+
returning: true,
|
|
348
|
+
transaction: _this10.transaction
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
var _yield$model$update2 = _slicedToArray(_yield$model$update, 1);
|
|
352
|
+
|
|
353
|
+
job = _yield$model$update2[0];
|
|
354
|
+
} else {
|
|
355
|
+
job = yield model.create(_objectSpread(_objectSpread({}, payload), {}, {
|
|
356
|
+
executionId: _this10.execution.id
|
|
357
|
+
}), {
|
|
358
|
+
transaction: _this10.transaction
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
_this10.jobsMap.set(job.id, job);
|
|
363
|
+
|
|
364
|
+
_this10.jobsMapByNodeId[job.nodeId] = job.result;
|
|
365
|
+
return job;
|
|
366
|
+
})();
|
|
367
|
+
} // find the first node in current branch
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
findBranchStartNode(node) {
|
|
371
|
+
for (let n = node; n; n = n.upstream) {
|
|
372
|
+
if (n.branchIndex !== null) {
|
|
373
|
+
return n;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return null;
|
|
378
|
+
} // find the node start current branch
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
findBranchParentNode(node) {
|
|
382
|
+
for (let n = node; n; n = n.upstream) {
|
|
383
|
+
if (n.branchIndex !== null) {
|
|
384
|
+
return n.upstream;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
findBranchParentJob(job, node) {
|
|
392
|
+
for (let j = job; j; j = this.jobsMap.get(j.upstreamId)) {
|
|
393
|
+
if (j.nodeId === node.id) {
|
|
394
|
+
return j;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
getParsedValue(value, node) {
|
|
402
|
+
const injectedFns = {};
|
|
403
|
+
const scope = {
|
|
404
|
+
execution: this.execution,
|
|
405
|
+
node
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
var _iterator = _createForOfIteratorHelper(_calculators.default.getEntities()),
|
|
409
|
+
_step;
|
|
410
|
+
|
|
411
|
+
try {
|
|
412
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
413
|
+
let _step$value = _slicedToArray(_step.value, 2),
|
|
414
|
+
name = _step$value[0],
|
|
415
|
+
fn = _step$value[1];
|
|
416
|
+
|
|
417
|
+
injectedFns[name] = fn.bind(scope);
|
|
418
|
+
}
|
|
419
|
+
} catch (err) {
|
|
420
|
+
_iterator.e(err);
|
|
421
|
+
} finally {
|
|
422
|
+
_iterator.f();
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return (0, _jsonTemplates().default)(value)({
|
|
426
|
+
$context: this.execution.context,
|
|
427
|
+
$jobsMapByNodeId: this.jobsMapByNodeId,
|
|
428
|
+
$fn: injectedFns
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
exports.default = Processor;
|
|
435
|
+
Processor.StatusMap = {
|
|
436
|
+
[_constants.JOB_STATUS.PENDING]: _constants.EXECUTION_STATUS.STARTED,
|
|
437
|
+
[_constants.JOB_STATUS.RESOLVED]: _constants.EXECUTION_STATUS.RESOLVED,
|
|
438
|
+
[_constants.JOB_STATUS.REJECTED]: _constants.EXECUTION_STATUS.REJECTED,
|
|
439
|
+
[_constants.JOB_STATUS.CANCELLED]: _constants.EXECUTION_STATUS.CANCELLED
|
|
440
|
+
};
|
package/lib/actions/index.d.ts
CHANGED
package/lib/actions/index.js
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
13
5
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
|
|
8
|
+
var workflows = _interopRequireWildcard(require("./workflows"));
|
|
9
|
+
|
|
10
|
+
var nodes = _interopRequireWildcard(require("./nodes"));
|
|
11
|
+
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
23
22
|
function make(name, mod) {
|
|
24
|
-
|
|
23
|
+
return Object.keys(mod).reduce((result, key) => _objectSpread(_objectSpread({}, result), {}, {
|
|
24
|
+
[`${name}:${key}`]: mod[key]
|
|
25
|
+
}), {});
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
|
|
28
|
+
function _default({
|
|
29
|
+
app
|
|
30
|
+
}) {
|
|
31
|
+
app.actions(_objectSpread(_objectSpread(_objectSpread({}, make('workflows', workflows)), make('workflows.nodes', {
|
|
32
|
+
create: nodes.create,
|
|
33
|
+
destroy: nodes.destroy
|
|
34
|
+
})), make('flow_nodes', {
|
|
35
|
+
update: nodes.update
|
|
36
|
+
})));
|
|
37
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Context } from '@nocobase/actions';
|
|
2
2
|
export declare function create(context: Context, next: any): Promise<void>;
|
|
3
3
|
export declare function destroy(context: Context, next: any): Promise<void>;
|
|
4
|
+
export declare function update(context: Context, next: any): Promise<void>;
|