@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,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
|
|
10
|
+
var _default = {
|
|
11
|
+
run(node, input, processor) {
|
|
12
|
+
return {
|
|
13
|
+
status: _constants.JOB_STATUS.PENDING
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
resume(node, job, processor) {
|
|
18
|
+
job.set('status', _constants.JOB_STATUS.RESOLVED);
|
|
19
|
+
return job;
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
};
|
|
15
|
-
|
|
23
|
+
exports.default = _default;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import FlowNodeModel from "../models/FlowNode";
|
|
2
|
+
import Processor from "../Processor";
|
|
2
3
|
declare const _default: {
|
|
3
|
-
run(
|
|
4
|
+
run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
|
|
4
5
|
result: any;
|
|
5
6
|
status: number;
|
|
6
7
|
}>;
|
|
@@ -1,27 +1,44 @@
|
|
|
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
|
+
multiple = _node$config.multiple,
|
|
26
|
+
_node$config$params = _node$config.params,
|
|
27
|
+
params = _node$config$params === void 0 ? {} : _node$config$params;
|
|
28
|
+
const repo = node.constructor.database.getRepository(collection);
|
|
29
|
+
const options = processor.getParsedValue(params);
|
|
30
|
+
const result = yield (multiple ? repo.find : repo.findOne).call(repo, _objectSpread(_objectSpread({}, options), {}, {
|
|
31
|
+
transaction: processor.transaction
|
|
32
|
+
})); // NOTE: `toJSON()` to avoid getting undefined value from Proxied model instance (#380)
|
|
33
|
+
// e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
|
|
34
|
+
// so the properties can not be get by json-templates(object-path)
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
result: multiple ? result.map(item => item.toJSON()) : result === null || result === void 0 ? void 0 : result.toJSON(),
|
|
38
|
+
status: _constants.JOB_STATUS.RESOLVED
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
}
|
|
42
|
+
|
|
10
43
|
};
|
|
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, multiple, params = {} } = this.config;
|
|
17
|
-
const repo = this.constructor.database.getRepository(collection);
|
|
18
|
-
const options = execution.getParsedValue(params);
|
|
19
|
-
const result = yield (multiple ? repo.find : repo.findOne).call(repo, 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=query.js.map
|
|
44
|
+
exports.default = _default;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import FlowNodeModel from "../models/FlowNode";
|
|
2
|
+
import Processor from "../Processor";
|
|
2
3
|
declare const _default: {
|
|
3
|
-
run(
|
|
4
|
+
run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
|
|
4
5
|
result: import("@nocobase/database").Model<any, any> | import("@nocobase/database").Model<any, any>[];
|
|
5
6
|
status: number;
|
|
6
7
|
}>;
|
|
@@ -1,27 +1,42 @@
|
|
|
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$multiple = _node$config.multiple,
|
|
26
|
+
multiple = _node$config$multiple === void 0 ? false : _node$config$multiple,
|
|
27
|
+
_node$config$params = _node$config.params,
|
|
28
|
+
params = _node$config$params === void 0 ? {} : _node$config$params;
|
|
29
|
+
const repo = node.constructor.database.getRepository(collection);
|
|
30
|
+
const options = processor.getParsedValue(params);
|
|
31
|
+
const result = yield repo.update(_objectSpread(_objectSpread({}, options), {}, {
|
|
32
|
+
transaction: processor.transaction
|
|
33
|
+
}));
|
|
34
|
+
return {
|
|
35
|
+
result: multiple ? result : result[0] || null,
|
|
36
|
+
status: _constants.JOB_STATUS.RESOLVED
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
}
|
|
40
|
+
|
|
10
41
|
};
|
|
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, multiple = false, params = {} } = this.config;
|
|
17
|
-
const repo = this.constructor.database.getRepository(collection);
|
|
18
|
-
const options = execution.getParsedValue(params);
|
|
19
|
-
const result = yield repo.update(Object.assign(Object.assign({}, options), { transaction: execution.transaction }));
|
|
20
|
-
return {
|
|
21
|
-
result: multiple ? result : (result[0] || null),
|
|
22
|
-
status: constants_1.JOB_STATUS.RESOLVED
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=update.js.map
|
|
42
|
+
exports.default = _default;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { Database, Model } from '@nocobase/database';
|
|
2
|
-
import { BelongsToGetAssociationMixin, HasManyGetAssociationsMixin
|
|
2
|
+
import { BelongsToGetAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';
|
|
3
3
|
import WorkflowModel from './Workflow';
|
|
4
|
-
import FlowNodeModel from './FlowNode';
|
|
5
4
|
import JobModel from './Job';
|
|
6
|
-
export interface ExecutionOptions {
|
|
7
|
-
transaction?: Transaction;
|
|
8
|
-
}
|
|
9
5
|
export default class ExecutionModel extends Model {
|
|
10
6
|
static readonly database: Database;
|
|
11
7
|
id: number;
|
|
@@ -13,38 +9,12 @@ export default class ExecutionModel extends Model {
|
|
|
13
9
|
context: any;
|
|
14
10
|
status: number;
|
|
15
11
|
useTransaction: boolean;
|
|
12
|
+
transaction: string;
|
|
16
13
|
createdAt: Date;
|
|
17
14
|
updatedAt: Date;
|
|
15
|
+
key: string;
|
|
18
16
|
workflow?: WorkflowModel;
|
|
19
17
|
getWorkflow: BelongsToGetAssociationMixin<WorkflowModel>;
|
|
20
18
|
jobs?: JobModel[];
|
|
21
19
|
getJobs: HasManyGetAssociationsMixin<JobModel>;
|
|
22
|
-
options: ExecutionOptions;
|
|
23
|
-
transaction: Transaction;
|
|
24
|
-
nodes: Array<FlowNodeModel>;
|
|
25
|
-
nodesMap: Map<number, FlowNodeModel>;
|
|
26
|
-
jobsMap: Map<number, JobModel>;
|
|
27
|
-
jobsMapByNodeId: {
|
|
28
|
-
[key: number]: any;
|
|
29
|
-
};
|
|
30
|
-
static StatusMap: {
|
|
31
|
-
[x: number]: number;
|
|
32
|
-
};
|
|
33
|
-
makeNodes(nodes?: any[]): void;
|
|
34
|
-
makeJobs(jobs: Array<JobModel>): void;
|
|
35
|
-
getTransaction(): Transaction | Promise<Transaction>;
|
|
36
|
-
prepare(options: any, commit?: boolean): Promise<void>;
|
|
37
|
-
start(options: ExecutionOptions): Promise<void>;
|
|
38
|
-
resume(job: JobModel, options: ExecutionOptions): Promise<void>;
|
|
39
|
-
private commit;
|
|
40
|
-
private exec;
|
|
41
|
-
run(node: any, input?: any): any;
|
|
42
|
-
end(node: any, job: any): any;
|
|
43
|
-
recall(node: any, job: any): any;
|
|
44
|
-
exit(job: JobModel | null): Promise<any>;
|
|
45
|
-
saveJob(payload: any): Promise<JobModel>;
|
|
46
|
-
findBranchStartNode(node: FlowNodeModel): FlowNodeModel | null;
|
|
47
|
-
findBranchParentNode(node: FlowNodeModel): FlowNodeModel | null;
|
|
48
|
-
findBranchParentJob(job: JobModel, node: FlowNodeModel): JobModel | null;
|
|
49
|
-
getParsedValue(value: any, node?: any): any;
|
|
50
20
|
}
|
package/lib/models/Execution.js
CHANGED
|
@@ -1,256 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const json_templates_1 = __importDefault(require("json-templates"));
|
|
17
|
-
const constants_1 = require("../constants");
|
|
18
|
-
const instructions_1 = __importDefault(require("../instructions"));
|
|
19
|
-
const calculators_1 = __importDefault(require("../calculators"));
|
|
20
|
-
class ExecutionModel extends database_1.Model {
|
|
21
|
-
constructor() {
|
|
22
|
-
super(...arguments);
|
|
23
|
-
this.nodes = [];
|
|
24
|
-
this.nodesMap = new Map();
|
|
25
|
-
this.jobsMap = new Map();
|
|
26
|
-
this.jobsMapByNodeId = {};
|
|
27
|
-
}
|
|
28
|
-
// make dual linked nodes list then cache
|
|
29
|
-
makeNodes(nodes = []) {
|
|
30
|
-
this.nodes = nodes;
|
|
31
|
-
nodes.forEach((node) => {
|
|
32
|
-
this.nodesMap.set(node.id, node);
|
|
33
|
-
});
|
|
34
|
-
nodes.forEach((node) => {
|
|
35
|
-
if (node.upstreamId) {
|
|
36
|
-
node.upstream = this.nodesMap.get(node.upstreamId);
|
|
37
|
-
}
|
|
38
|
-
if (node.downstreamId) {
|
|
39
|
-
node.downstream = this.nodesMap.get(node.downstreamId);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
makeJobs(jobs) {
|
|
44
|
-
jobs.forEach((job) => {
|
|
45
|
-
this.jobsMap.set(job.id, job);
|
|
46
|
-
// TODO: should consider cycle, and from previous job
|
|
47
|
-
this.jobsMapByNodeId[job.nodeId] = job.result;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
getTransaction() {
|
|
51
|
-
const { sequelize } = this.constructor.database;
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
if (!this.useTransaction) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
const { options } = this;
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
return options.transaction && !options.transaction.finished
|
|
59
|
-
? options.transaction
|
|
60
|
-
: sequelize.transaction();
|
|
61
|
-
}
|
|
62
|
-
prepare(options, commit = false) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
this.options = options || {};
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
const transaction = yield this.getTransaction();
|
|
67
|
-
this.transaction = transaction;
|
|
68
|
-
if (!this.workflow) {
|
|
69
|
-
this.workflow = yield this.getWorkflow({ transaction });
|
|
70
|
-
}
|
|
71
|
-
const nodes = yield this.workflow.getNodes({ transaction });
|
|
72
|
-
this.makeNodes(nodes);
|
|
73
|
-
const jobs = yield this.getJobs({
|
|
74
|
-
order: [['id', 'ASC']],
|
|
75
|
-
transaction,
|
|
76
|
-
});
|
|
77
|
-
this.makeJobs(jobs);
|
|
78
|
-
if (commit) {
|
|
79
|
-
yield this.commit();
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
start(options) {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
if (this.status !== constants_1.EXECUTION_STATUS.STARTED) {
|
|
86
|
-
throw new Error(`execution was ended with status ${this.status}`);
|
|
87
|
-
}
|
|
88
|
-
yield this.prepare(options);
|
|
89
|
-
if (this.nodes.length) {
|
|
90
|
-
const head = this.nodes.find(item => !item.upstream);
|
|
91
|
-
yield this.run(head, { result: this.context });
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
yield this.exit(null);
|
|
95
|
-
}
|
|
96
|
-
yield this.commit();
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
resume(job, options) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
if (this.status !== constants_1.EXECUTION_STATUS.STARTED) {
|
|
102
|
-
throw new Error(`execution was ended with status ${this.status}`);
|
|
103
|
-
}
|
|
104
|
-
yield this.prepare(options);
|
|
105
|
-
const node = this.nodesMap.get(job.nodeId);
|
|
106
|
-
yield this.recall(node, job);
|
|
107
|
-
yield this.commit();
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
commit() {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
if (this.transaction && (!this.options.transaction || this.options.transaction.finished)) {
|
|
114
|
-
yield this.transaction.commit();
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
exec(instruction, node, prevJob) {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
let job;
|
|
121
|
-
try {
|
|
122
|
-
// call instruction to get result and status
|
|
123
|
-
job = yield instruction.call(node, prevJob, this);
|
|
124
|
-
if (!job) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
// for uncaught error, set to rejected
|
|
130
|
-
job = {
|
|
131
|
-
result: err instanceof Error
|
|
132
|
-
? { message: err.message, stack: process.env.NODE_ENV === 'production' ? [] : err.stack }
|
|
133
|
-
: err,
|
|
134
|
-
status: constants_1.JOB_STATUS.REJECTED,
|
|
135
|
-
};
|
|
136
|
-
// if previous job is from resuming
|
|
137
|
-
if (prevJob && prevJob.nodeId === node.id) {
|
|
138
|
-
prevJob.set(job);
|
|
139
|
-
job = prevJob;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
let savedJob;
|
|
143
|
-
// TODO(optimize): many checking of resuming or new could be improved
|
|
144
|
-
// could be implemented separately in exec() / resume()
|
|
145
|
-
if (job instanceof database_1.Model) {
|
|
146
|
-
savedJob = (yield job.save({ transaction: this.transaction }));
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
const upstreamId = prevJob instanceof database_1.Model ? prevJob.get('id') : null;
|
|
150
|
-
savedJob = yield this.saveJob(Object.assign({ nodeId: node.id, upstreamId }, job));
|
|
151
|
-
}
|
|
152
|
-
if (savedJob.status === constants_1.JOB_STATUS.RESOLVED && node.downstream) {
|
|
153
|
-
// run next node
|
|
154
|
-
return this.run(node.downstream, savedJob);
|
|
155
|
-
}
|
|
156
|
-
// all nodes in scope have been executed
|
|
157
|
-
return this.end(node, savedJob);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
run(node, input) {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const { run } = instructions_1.default.get(node.type);
|
|
163
|
-
if (typeof run !== 'function') {
|
|
164
|
-
return Promise.reject(new Error('`run` should be implemented for customized execution of the node'));
|
|
165
|
-
}
|
|
166
|
-
return this.exec(run, node, input);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
// parent node should take over the control
|
|
170
|
-
end(node, job) {
|
|
171
|
-
const parentNode = this.findBranchParentNode(node);
|
|
172
|
-
// no parent, means on main flow
|
|
173
|
-
if (parentNode) {
|
|
174
|
-
return this.recall(parentNode, job);
|
|
175
|
-
}
|
|
176
|
-
// really done for all nodes
|
|
177
|
-
// * should mark execution as done with last job status
|
|
178
|
-
return this.exit(job);
|
|
179
|
-
}
|
|
180
|
-
recall(node, job) {
|
|
181
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
const { resume } = instructions_1.default.get(node.type);
|
|
183
|
-
if (typeof resume !== 'function') {
|
|
184
|
-
return Promise.reject(new Error('`resume` should be implemented because the node made branch'));
|
|
185
|
-
}
|
|
186
|
-
return this.exec(resume, node, job);
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
exit(job) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
const status = job ? ExecutionModel.StatusMap[job.status] : constants_1.EXECUTION_STATUS.RESOLVED;
|
|
192
|
-
yield this.update({ status }, { transaction: this.transaction });
|
|
193
|
-
return null;
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
// TODO(optimize)
|
|
197
|
-
saveJob(payload) {
|
|
198
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
const { database } = this.constructor;
|
|
200
|
-
const { model } = database.getCollection('jobs');
|
|
201
|
-
const [job] = (yield model.upsert(Object.assign(Object.assign({}, payload), { executionId: this.id }), { transaction: this.transaction }));
|
|
202
|
-
this.jobsMap.set(job.id, job);
|
|
203
|
-
this.jobsMapByNodeId[job.nodeId] = job.result;
|
|
204
|
-
return job;
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
// find the first node in current branch
|
|
208
|
-
findBranchStartNode(node) {
|
|
209
|
-
for (let n = node; n; n = n.upstream) {
|
|
210
|
-
if (n.branchIndex !== null) {
|
|
211
|
-
return n;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
// find the node start current branch
|
|
217
|
-
findBranchParentNode(node) {
|
|
218
|
-
for (let n = node; n; n = n.upstream) {
|
|
219
|
-
if (n.branchIndex !== null) {
|
|
220
|
-
return n.upstream;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
findBranchParentJob(job, node) {
|
|
226
|
-
for (let j = job; j; j = this.jobsMap.get(j.upstreamId)) {
|
|
227
|
-
if (j.nodeId === node.id) {
|
|
228
|
-
return j;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
getParsedValue(value, node) {
|
|
234
|
-
const injectedFns = {};
|
|
235
|
-
const scope = {
|
|
236
|
-
execution: this,
|
|
237
|
-
node
|
|
238
|
-
};
|
|
239
|
-
for (let [name, fn] of calculators_1.default.getEntities()) {
|
|
240
|
-
injectedFns[name] = fn.bind(scope);
|
|
241
|
-
}
|
|
242
|
-
return (0, json_templates_1.default)(value)({
|
|
243
|
-
$context: this.context,
|
|
244
|
-
$jobsMapByNodeId: this.jobsMapByNodeId,
|
|
245
|
-
$fn: injectedFns
|
|
246
|
-
});
|
|
247
|
-
}
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
248
16
|
}
|
|
249
|
-
|
|
250
|
-
ExecutionModel.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
[constants_1.JOB_STATUS.REJECTED]: constants_1.EXECUTION_STATUS.REJECTED,
|
|
254
|
-
[constants_1.JOB_STATUS.CANCELLED]: constants_1.EXECUTION_STATUS.CANCELLED,
|
|
255
|
-
};
|
|
256
|
-
//# sourceMappingURL=Execution.js.map
|
|
17
|
+
|
|
18
|
+
class ExecutionModel extends _database().Model {}
|
|
19
|
+
|
|
20
|
+
exports.default = ExecutionModel;
|
package/lib/models/FlowNode.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
5
16
|
}
|
|
6
|
-
|
|
7
|
-
|
|
17
|
+
|
|
18
|
+
class FlowNodeModel extends _database().Model {}
|
|
19
|
+
|
|
20
|
+
exports.default = FlowNodeModel;
|
package/lib/models/Job.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
5
16
|
}
|
|
6
|
-
|
|
7
|
-
|
|
17
|
+
|
|
18
|
+
class JobModel extends _database().Model {}
|
|
19
|
+
|
|
20
|
+
exports.default = JobModel;
|
package/lib/models/Workflow.d.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { Database, Model } from '@nocobase/database';
|
|
2
|
-
import { HasManyCreateAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';
|
|
2
|
+
import { HasManyCountAssociationsMixin, HasManyCreateAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';
|
|
3
3
|
import ExecutionModel from './Execution';
|
|
4
4
|
import FlowNodeModel from './FlowNode';
|
|
5
5
|
export default class WorkflowModel extends Model {
|
|
6
6
|
static database: Database;
|
|
7
7
|
id: number;
|
|
8
|
+
key: string;
|
|
8
9
|
title: string;
|
|
9
10
|
enabled: boolean;
|
|
11
|
+
current: boolean;
|
|
10
12
|
description?: string;
|
|
11
13
|
type: string;
|
|
12
14
|
config: any;
|
|
13
15
|
useTransaction: boolean;
|
|
16
|
+
executed: number;
|
|
14
17
|
createdAt: Date;
|
|
15
18
|
updatedAt: Date;
|
|
16
19
|
nodes: FlowNodeModel[];
|
|
17
20
|
getNodes: HasManyGetAssociationsMixin<FlowNodeModel>;
|
|
18
21
|
createNode: HasManyCreateAssociationMixin<FlowNodeModel>;
|
|
19
22
|
executions: ExecutionModel[];
|
|
23
|
+
countExecutions: HasManyCountAssociationsMixin;
|
|
20
24
|
getExecutions: HasManyGetAssociationsMixin<ExecutionModel>;
|
|
21
25
|
createExecution: HasManyCreateAssociationMixin<ExecutionModel>;
|
|
22
|
-
static mount(): Promise<void>;
|
|
23
|
-
getHookId(): string;
|
|
24
|
-
getTransaction(options: any): any;
|
|
25
|
-
toggle(enable?: boolean): Promise<void>;
|
|
26
|
-
trigger(context: Object, options: any): Promise<ExecutionModel>;
|
|
27
26
|
}
|