@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
|
@@ -1,27 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
|
|
10
|
+
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; }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
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
|
+
|
|
18
|
+
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
|
+
|
|
20
|
+
var _default = {
|
|
21
|
+
run(node, input, processor) {
|
|
22
|
+
return _asyncToGenerator(function* () {
|
|
23
|
+
const _node$config = node.config,
|
|
24
|
+
collection = _node$config.collection,
|
|
25
|
+
_node$config$params = _node$config.params,
|
|
26
|
+
params = _node$config$params === void 0 ? {} : _node$config$params;
|
|
27
|
+
const repo = node.constructor.database.getRepository(collection);
|
|
28
|
+
const options = processor.getParsedValue(params);
|
|
29
|
+
const result = yield repo.create(_objectSpread(_objectSpread({}, options), {}, {
|
|
30
|
+
transaction: processor.transaction
|
|
31
|
+
}));
|
|
32
|
+
return {
|
|
33
|
+
// NOTE: get() for non-proxied instance (#380)
|
|
34
|
+
result: result.get(),
|
|
35
|
+
status: _constants.JOB_STATUS.RESOLVED
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
}
|
|
39
|
+
|
|
10
40
|
};
|
|
11
|
-
|
|
12
|
-
const constants_1 = require("../constants");
|
|
13
|
-
exports.default = {
|
|
14
|
-
run(input, execution) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const { collection, params = {} } = this.config;
|
|
17
|
-
const repo = this.constructor.database.getRepository(collection);
|
|
18
|
-
const options = execution.getParsedValue(params);
|
|
19
|
-
const result = yield repo.create(Object.assign(Object.assign({}, options), { transaction: execution.transaction }));
|
|
20
|
-
return {
|
|
21
|
-
result,
|
|
22
|
-
status: constants_1.JOB_STATUS.RESOLVED
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=create.js.map
|
|
41
|
+
exports.default = _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Plugin from '..';
|
|
3
|
+
import Processor from '../Processor';
|
|
4
|
+
export default class {
|
|
5
|
+
protected plugin: Plugin;
|
|
6
|
+
timers: Map<number, NodeJS.Timeout>;
|
|
7
|
+
constructor(plugin: Plugin);
|
|
8
|
+
load(): Promise<void>;
|
|
9
|
+
unload(): void;
|
|
10
|
+
schedule(job: any, duration: number): void;
|
|
11
|
+
trigger(job: any): Promise<void>;
|
|
12
|
+
run: (node: any, prevJob: any, processor: Processor) => Promise<any>;
|
|
13
|
+
resume: (node: any, prevJob: any, processor: Processor) => Promise<any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
|
|
10
|
+
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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
11
|
+
|
|
12
|
+
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); }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
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
|
+
|
|
18
|
+
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
|
+
|
|
20
|
+
class _default {
|
|
21
|
+
constructor(plugin) {
|
|
22
|
+
var _this = this;
|
|
23
|
+
|
|
24
|
+
this.plugin = void 0;
|
|
25
|
+
this.timers = new Map();
|
|
26
|
+
|
|
27
|
+
this.run = /*#__PURE__*/function () {
|
|
28
|
+
var _ref = _asyncToGenerator(function* (node, prevJob, processor) {
|
|
29
|
+
var _prevJob$id;
|
|
30
|
+
|
|
31
|
+
const job = yield processor.saveJob({
|
|
32
|
+
status: _constants.JOB_STATUS.PENDING,
|
|
33
|
+
result: null,
|
|
34
|
+
nodeId: node.id,
|
|
35
|
+
upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
|
|
36
|
+
});
|
|
37
|
+
const duration = node.config.duration; // add to schedule
|
|
38
|
+
|
|
39
|
+
_this.schedule(job, duration);
|
|
40
|
+
|
|
41
|
+
return processor.end(node, job);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return function (_x, _x2, _x3) {
|
|
45
|
+
return _ref.apply(this, arguments);
|
|
46
|
+
};
|
|
47
|
+
}();
|
|
48
|
+
|
|
49
|
+
this.resume = /*#__PURE__*/function () {
|
|
50
|
+
var _ref2 = _asyncToGenerator(function* (node, prevJob, processor) {
|
|
51
|
+
const endStatus = node.config.endStatus;
|
|
52
|
+
prevJob.set('status', endStatus);
|
|
53
|
+
return prevJob;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return function (_x4, _x5, _x6) {
|
|
57
|
+
return _ref2.apply(this, arguments);
|
|
58
|
+
};
|
|
59
|
+
}();
|
|
60
|
+
|
|
61
|
+
this.plugin = plugin;
|
|
62
|
+
plugin.app.on('beforeStart', () => this.load());
|
|
63
|
+
plugin.app.on('beforeStop', () => this.unload());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
load() {
|
|
67
|
+
var _this2 = this;
|
|
68
|
+
|
|
69
|
+
return _asyncToGenerator(function* () {
|
|
70
|
+
const _this2$plugin$db$getC = _this2.plugin.db.getCollection('jobs'),
|
|
71
|
+
model = _this2$plugin$db$getC.model;
|
|
72
|
+
|
|
73
|
+
const jobs = yield model.findAll({
|
|
74
|
+
where: {
|
|
75
|
+
status: _constants.JOB_STATUS.PENDING
|
|
76
|
+
},
|
|
77
|
+
include: [{
|
|
78
|
+
association: 'execution'
|
|
79
|
+
}, {
|
|
80
|
+
association: 'node',
|
|
81
|
+
where: {
|
|
82
|
+
type: 'delay'
|
|
83
|
+
},
|
|
84
|
+
required: true
|
|
85
|
+
}]
|
|
86
|
+
});
|
|
87
|
+
jobs.forEach(job => {
|
|
88
|
+
_this2.schedule(job, job.node.config.duration);
|
|
89
|
+
});
|
|
90
|
+
})();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
unload() {
|
|
94
|
+
var _iterator = _createForOfIteratorHelper(this.timers.values()),
|
|
95
|
+
_step;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
99
|
+
const timer = _step.value;
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
}
|
|
102
|
+
} catch (err) {
|
|
103
|
+
_iterator.e(err);
|
|
104
|
+
} finally {
|
|
105
|
+
_iterator.f();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.timers = new Map();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
schedule(job, duration) {
|
|
112
|
+
const now = new Date();
|
|
113
|
+
const createdAt = Date.parse(job.createdAt);
|
|
114
|
+
const delay = createdAt + duration - now.getTime();
|
|
115
|
+
const trigger = this.trigger.bind(this, job);
|
|
116
|
+
this.timers.set(job.id, setTimeout(trigger, Math.max(0, delay)));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
trigger(job) {
|
|
120
|
+
var _this3 = this;
|
|
121
|
+
|
|
122
|
+
return _asyncToGenerator(function* () {
|
|
123
|
+
const _job$execution = job.execution,
|
|
124
|
+
execution = _job$execution === void 0 ? yield job.getExecution() : _job$execution;
|
|
125
|
+
|
|
126
|
+
const processor = _this3.plugin.createProcessor(execution);
|
|
127
|
+
|
|
128
|
+
yield processor.resume(job);
|
|
129
|
+
|
|
130
|
+
if (_this3.timers.get(job.id)) {
|
|
131
|
+
_this3.timers.delete(job.id);
|
|
132
|
+
}
|
|
133
|
+
})();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.default = _default;
|
|
@@ -1,27 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
|
|
10
|
+
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; }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
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
|
+
|
|
18
|
+
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
|
+
|
|
20
|
+
var _default = {
|
|
21
|
+
run(node, input, processor) {
|
|
22
|
+
return _asyncToGenerator(function* () {
|
|
23
|
+
const _node$config = node.config,
|
|
24
|
+
collection = _node$config.collection,
|
|
25
|
+
_node$config$params = _node$config.params,
|
|
26
|
+
params = _node$config$params === void 0 ? {} : _node$config$params;
|
|
27
|
+
const repo = node.constructor.database.getRepository(collection);
|
|
28
|
+
const options = processor.getParsedValue(params);
|
|
29
|
+
const result = yield repo.destroy(_objectSpread(_objectSpread({}, options), {}, {
|
|
30
|
+
transaction: processor.transaction
|
|
31
|
+
}));
|
|
32
|
+
return {
|
|
33
|
+
result,
|
|
34
|
+
status: _constants.JOB_STATUS.RESOLVED
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
}
|
|
38
|
+
|
|
10
39
|
};
|
|
11
|
-
|
|
12
|
-
const constants_1 = require("../constants");
|
|
13
|
-
exports.default = {
|
|
14
|
-
run(input, execution) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const { collection, params = {} } = this.config;
|
|
17
|
-
const repo = this.constructor.database.getRepository(collection);
|
|
18
|
-
const options = execution.getParsedValue(params);
|
|
19
|
-
const result = yield repo.destroy(Object.assign(Object.assign({}, options), { transaction: execution.transaction }));
|
|
20
|
-
return {
|
|
21
|
-
result,
|
|
22
|
-
status: constants_1.JOB_STATUS.RESOLVED
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=destroy.js.map
|
|
40
|
+
exports.default = _default;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { Registry } from '@nocobase/utils';
|
|
2
|
-
import ExecutionModel from '../models/Execution';
|
|
3
1
|
import FlowNodeModel from '../models/FlowNode';
|
|
4
|
-
|
|
2
|
+
import Plugin from '..';
|
|
3
|
+
import Processor from '../Processor';
|
|
4
|
+
export declare type Job = {
|
|
5
5
|
status: number;
|
|
6
6
|
result?: unknown;
|
|
7
7
|
[key: string]: unknown;
|
|
8
|
-
}
|
|
8
|
+
} | null;
|
|
9
9
|
export declare type InstructionResult = Job | Promise<Job>;
|
|
10
10
|
export interface Instruction {
|
|
11
|
-
run(
|
|
12
|
-
resume?(
|
|
11
|
+
run(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
|
|
12
|
+
resume?(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
|
|
13
13
|
}
|
|
14
|
-
export
|
|
15
|
-
|
|
14
|
+
export default function <T extends Instruction>(plugin: any, more?: {
|
|
15
|
+
[key: string]: T | {
|
|
16
|
+
new (p: Plugin): T;
|
|
17
|
+
};
|
|
18
|
+
}): void;
|
|
@@ -1,26 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
|
|
8
|
+
function _path() {
|
|
9
|
+
const data = _interopRequireDefault(require("path"));
|
|
10
|
+
|
|
11
|
+
_path = function _path() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _utils() {
|
|
19
|
+
const data = require("@nocobase/utils");
|
|
20
|
+
|
|
21
|
+
_utils = function _utils() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _prompt = _interopRequireDefault(require("./prompt"));
|
|
29
|
+
|
|
30
|
+
var _calculation = _interopRequireDefault(require("./calculation"));
|
|
31
|
+
|
|
32
|
+
var _condition = _interopRequireDefault(require("./condition"));
|
|
33
|
+
|
|
34
|
+
var _parallel = _interopRequireDefault(require("./parallel"));
|
|
35
|
+
|
|
36
|
+
var _query = _interopRequireDefault(require("./query"));
|
|
37
|
+
|
|
38
|
+
var _create = _interopRequireDefault(require("./create"));
|
|
39
|
+
|
|
40
|
+
var _update = _interopRequireDefault(require("./update"));
|
|
41
|
+
|
|
42
|
+
var _destroy = _interopRequireDefault(require("./destroy"));
|
|
43
|
+
|
|
44
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
45
|
+
|
|
46
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
47
|
+
|
|
48
|
+
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."); }
|
|
49
|
+
|
|
50
|
+
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); }
|
|
51
|
+
|
|
52
|
+
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; }
|
|
53
|
+
|
|
54
|
+
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; }
|
|
55
|
+
|
|
56
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
57
|
+
|
|
58
|
+
function _default(plugin, more = {}) {
|
|
59
|
+
const instructions = plugin.instructions;
|
|
60
|
+
instructions.register('prompt', _prompt.default);
|
|
61
|
+
instructions.register('calculation', _calculation.default);
|
|
62
|
+
instructions.register('condition', _condition.default);
|
|
63
|
+
instructions.register('parallel', _parallel.default);
|
|
64
|
+
instructions.register('query', _query.default);
|
|
65
|
+
instructions.register('create', _create.default);
|
|
66
|
+
instructions.register('update', _update.default);
|
|
67
|
+
instructions.register('destroy', _destroy.default);
|
|
68
|
+
instructions.register('delay', new ((0, _utils().requireModule)(_path().default.join(__dirname, 'delay')))(plugin));
|
|
69
|
+
|
|
70
|
+
for (var _i = 0, _Object$entries = Object.entries(more); _i < _Object$entries.length; _i++) {
|
|
71
|
+
const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
72
|
+
name = _Object$entries$_i[0],
|
|
73
|
+
instruction = _Object$entries$_i[1];
|
|
74
|
+
|
|
75
|
+
instructions.register(name, typeof instruction === 'function' ? new instruction(plugin) : instruction);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import ExecutionModel from "../models/Execution";
|
|
2
1
|
import FlowNodeModel from "../models/FlowNode";
|
|
3
2
|
import JobModel from "../models/Job";
|
|
3
|
+
import Processor from "../Processor";
|
|
4
4
|
export declare const PARALLEL_MODE: {
|
|
5
5
|
readonly ALL: "all";
|
|
6
6
|
readonly ANY: "any";
|
|
7
7
|
readonly RACE: "race";
|
|
8
8
|
};
|
|
9
9
|
declare const _default: {
|
|
10
|
-
run(
|
|
11
|
-
resume(
|
|
10
|
+
run(node: FlowNodeModel, prevJob: JobModel, processor: Processor): Promise<any>;
|
|
11
|
+
resume(node: FlowNodeModel, branchJob: any, processor: Processor): Promise<any>;
|
|
12
12
|
};
|
|
13
13
|
export default _default;
|
|
@@ -1,91 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.PARALLEL_MODE = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
|
|
10
|
+
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); } }
|
|
11
|
+
|
|
12
|
+
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); }); }; }
|
|
13
|
+
|
|
14
|
+
const PARALLEL_MODE = {
|
|
15
|
+
ALL: 'all',
|
|
16
|
+
ANY: 'any',
|
|
17
|
+
RACE: 'race'
|
|
18
18
|
};
|
|
19
|
+
exports.PARALLEL_MODE = PARALLEL_MODE;
|
|
19
20
|
const StatusGetters = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return constants_1.JOB_STATUS.PENDING;
|
|
28
|
-
},
|
|
29
|
-
[exports.PARALLEL_MODE.ANY](result) {
|
|
30
|
-
return result.some(j => j && j.status === constants_1.JOB_STATUS.RESOLVED)
|
|
31
|
-
? constants_1.JOB_STATUS.RESOLVED
|
|
32
|
-
: (result.some(j => j && j.status === constants_1.JOB_STATUS.PENDING)
|
|
33
|
-
? constants_1.JOB_STATUS.PENDING
|
|
34
|
-
: constants_1.JOB_STATUS.REJECTED);
|
|
35
|
-
},
|
|
36
|
-
[exports.PARALLEL_MODE.RACE](result) {
|
|
37
|
-
return result.some(j => j && j.status === constants_1.JOB_STATUS.RESOLVED)
|
|
38
|
-
? constants_1.JOB_STATUS.RESOLVED
|
|
39
|
-
: (result.some(j => j && j.status === constants_1.JOB_STATUS.REJECTED)
|
|
40
|
-
? constants_1.JOB_STATUS.REJECTED
|
|
41
|
-
: constants_1.JOB_STATUS.PENDING);
|
|
21
|
+
[PARALLEL_MODE.ALL](result) {
|
|
22
|
+
if (result.some(j => j && j.status === _constants.JOB_STATUS.REJECTED)) {
|
|
23
|
+
return _constants.JOB_STATUS.REJECTED;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (result.every(j => j && j.status === _constants.JOB_STATUS.RESOLVED)) {
|
|
27
|
+
return _constants.JOB_STATUS.RESOLVED;
|
|
42
28
|
}
|
|
29
|
+
|
|
30
|
+
return _constants.JOB_STATUS.PENDING;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
[PARALLEL_MODE.ANY](result) {
|
|
34
|
+
return result.some(j => j && j.status === _constants.JOB_STATUS.RESOLVED) ? _constants.JOB_STATUS.RESOLVED : result.some(j => j && j.status === _constants.JOB_STATUS.PENDING) ? _constants.JOB_STATUS.PENDING : _constants.JOB_STATUS.REJECTED;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
[PARALLEL_MODE.RACE](result) {
|
|
38
|
+
return result.some(j => j && j.status === _constants.JOB_STATUS.RESOLVED) ? _constants.JOB_STATUS.RESOLVED : result.some(j => j && j.status === _constants.JOB_STATUS.REJECTED) ? _constants.JOB_STATUS.REJECTED : _constants.JOB_STATUS.PENDING;
|
|
39
|
+
}
|
|
40
|
+
|
|
43
41
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
42
|
+
var _default = {
|
|
43
|
+
run(node, prevJob, processor) {
|
|
44
|
+
return _asyncToGenerator(function* () {
|
|
45
|
+
var _prevJob$id;
|
|
46
|
+
|
|
47
|
+
const branches = processor.nodes.filter(item => item.upstream === node && item.branchIndex !== null).sort((a, b) => a.branchIndex - b.branchIndex);
|
|
48
|
+
const job = yield processor.saveJob({
|
|
49
|
+
status: _constants.JOB_STATUS.PENDING,
|
|
50
|
+
result: Array(branches.length).fill(null),
|
|
51
|
+
nodeId: node.id,
|
|
52
|
+
upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
|
|
53
|
+
}); // NOTE:
|
|
54
|
+
// use `reduce` but not `Promise.all` here to avoid racing manupulating db.
|
|
55
|
+
// for users, this is almost equivalent to `Promise.all`,
|
|
56
|
+
// because of the delay is not significant sensible.
|
|
57
|
+
// another benifit of this is, it could handle sequenced branches in future.
|
|
58
|
+
|
|
59
|
+
yield branches.reduce((promise, branch) => promise.then(() => processor.run(branch, job)), Promise.resolve());
|
|
60
|
+
return processor.end(node, job);
|
|
61
|
+
})();
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
resume(node, branchJob, processor) {
|
|
65
|
+
return _asyncToGenerator(function* () {
|
|
66
|
+
const job = processor.findBranchParentJob(branchJob, node);
|
|
67
|
+
const result = job.result,
|
|
68
|
+
status = job.status; // if parallel has been done (resolved / rejected), do not care newly executed branch jobs.
|
|
69
|
+
|
|
70
|
+
if (status !== _constants.JOB_STATUS.PENDING) {
|
|
71
|
+
return null;
|
|
72
|
+
} // find the index of the node which start the branch
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const jobNode = processor.nodesMap.get(branchJob.nodeId);
|
|
76
|
+
|
|
77
|
+
const _processor$findBranch = processor.findBranchStartNode(jobNode),
|
|
78
|
+
branchIndex = _processor$findBranch.branchIndex;
|
|
79
|
+
|
|
80
|
+
const _ref = node.config || {},
|
|
81
|
+
_ref$mode = _ref.mode,
|
|
82
|
+
mode = _ref$mode === void 0 ? PARALLEL_MODE.ALL : _ref$mode;
|
|
83
|
+
|
|
84
|
+
const newResult = [...result.slice(0, branchIndex), branchJob.get(), ...result.slice(branchIndex + 1)];
|
|
85
|
+
job.set({
|
|
86
|
+
result: newResult,
|
|
87
|
+
status: StatusGetters[mode](newResult)
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (job.status === _constants.JOB_STATUS.PENDING) {
|
|
91
|
+
yield job.save({
|
|
92
|
+
transaction: processor.transaction
|
|
64
93
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
// find the index of the node which start the branch
|
|
75
|
-
const jobNode = execution.nodesMap.get(branchJob.nodeId);
|
|
76
|
-
const { branchIndex } = execution.findBranchStartNode(jobNode);
|
|
77
|
-
const { mode = exports.PARALLEL_MODE.ALL } = this.config || {};
|
|
78
|
-
const newResult = [...result.slice(0, branchIndex), branchJob.get(), ...result.slice(branchIndex + 1)];
|
|
79
|
-
job.set({
|
|
80
|
-
result: newResult,
|
|
81
|
-
status: StatusGetters[mode](newResult)
|
|
82
|
-
});
|
|
83
|
-
if (job.status === constants_1.JOB_STATUS.PENDING) {
|
|
84
|
-
yield job.save({ transaction: execution.transaction });
|
|
85
|
-
return execution.end(this, job);
|
|
86
|
-
}
|
|
87
|
-
return job;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
94
|
+
return processor.end(node, job);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return job;
|
|
98
|
+
})();
|
|
99
|
+
}
|
|
100
|
+
|
|
90
101
|
};
|
|
91
|
-
|
|
102
|
+
exports.default = _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
run(
|
|
2
|
+
run(node: any, input: any, processor: any): {
|
|
3
3
|
status: number;
|
|
4
4
|
};
|
|
5
|
-
resume(
|
|
5
|
+
resume(node: any, job: any, processor: any): any;
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|