@nocobase/plugin-workflow 0.7.0-alpha.34 → 0.7.0-alpha.57
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/actions/index.js +31 -32
- package/lib/actions/nodes.js +310 -182
- package/lib/actions/workflows.js +260 -157
- package/lib/calculators/index.js +142 -90
- package/lib/collections/executions.js +40 -43
- package/lib/collections/flow_nodes.js +60 -65
- package/lib/collections/jobs.js +45 -47
- package/lib/collections/workflows.js +78 -87
- package/lib/constants.js +22 -17
- package/lib/index.js +71 -22
- package/lib/instructions/calculation.js +34 -29
- package/lib/instructions/condition.js +94 -87
- package/lib/instructions/create.js +43 -26
- package/lib/instructions/destroy.js +42 -25
- package/lib/instructions/index.js +46 -25
- package/lib/instructions/parallel.js +99 -84
- package/lib/instructions/prompt.js +21 -13
- package/lib/instructions/query.js +47 -29
- package/lib/instructions/update.js +44 -25
- package/lib/models/Execution.js +401 -248
- package/lib/models/FlowNode.js +18 -5
- package/lib/models/Job.js +18 -5
- package/lib/models/Workflow.js +132 -88
- package/lib/server.js +93 -66
- package/lib/triggers/collection.js +113 -51
- package/lib/triggers/index.js +25 -11
- package/package.json +7 -12
- package/esm/actions/index.d.ts +0 -1
- package/esm/actions/index.js +0 -14
- package/esm/actions/index.js.map +0 -1
- package/esm/actions/nodes.d.ts +0 -4
- package/esm/actions/nodes.js +0 -187
- package/esm/actions/nodes.js.map +0 -1
- package/esm/actions/workflows.d.ts +0 -3
- package/esm/actions/workflows.js +0 -163
- package/esm/actions/workflows.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 -43
- package/esm/collections/executions.js.map +0 -1
- package/esm/collections/flow_nodes.d.ts +0 -3
- package/esm/collections/flow_nodes.js +0 -65
- 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 -87
- 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 -26
- 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 -29
- package/esm/instructions/query.js.map +0 -1
- package/esm/instructions/update.d.ts +0 -9
- package/esm/instructions/update.js +0 -25
- package/esm/instructions/update.js.map +0 -1
- package/esm/models/Execution.d.ts +0 -51
- package/esm/models/Execution.js +0 -256
- 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 -29
- package/esm/models/Workflow.js +0 -88
- 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/collection.d.ts +0 -12
- package/esm/triggers/collection.js +0 -61
- package/esm/triggers/collection.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/lib/actions/index.js.map +0 -1
- package/lib/actions/nodes.js.map +0 -1
- package/lib/actions/workflows.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.js.map +0 -1
- package/lib/triggers/collection.js.map +0 -1
- package/lib/triggers/index.js.map +0 -1
- package/tsconfig.build.json +0 -9
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.js
CHANGED
|
@@ -1,94 +1,138 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return undefined;
|
|
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;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var _triggers = _interopRequireDefault(require("../triggers"));
|
|
19
|
+
|
|
20
|
+
var _constants = require("../constants");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
25
|
+
|
|
26
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
27
|
+
|
|
28
|
+
class WorkflowModel extends _database().Model {
|
|
29
|
+
static mount() {
|
|
30
|
+
var _this = this;
|
|
31
|
+
|
|
32
|
+
return _asyncToGenerator(function* () {
|
|
33
|
+
const collection = _this.database.getCollection('workflows');
|
|
34
|
+
|
|
35
|
+
const workflows = yield collection.repository.find({
|
|
36
|
+
filter: {
|
|
37
|
+
enabled: true
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
});
|
|
40
|
+
workflows.forEach(workflow => {
|
|
41
|
+
workflow.toggle();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
_this.addHook('afterCreate', model => model.toggle());
|
|
45
|
+
|
|
46
|
+
_this.addHook('afterUpdate', model => model.toggle());
|
|
47
|
+
|
|
48
|
+
_this.addHook('afterDestroy', model => model.toggle(false));
|
|
49
|
+
})();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getHookId() {
|
|
53
|
+
return `workflow-${this.get('id')}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getTransaction(options) {
|
|
57
|
+
if (!this.useTransaction) {
|
|
58
|
+
return undefined;
|
|
43
59
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
|
|
61
|
+
return options.transaction && !options.transaction.finished ? options.transaction : this.constructor.database.sequelize.transaction();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
toggle(enable) {
|
|
65
|
+
var _this2 = this;
|
|
66
|
+
|
|
67
|
+
return _asyncToGenerator(function* () {
|
|
68
|
+
const type = _this2.get('type');
|
|
69
|
+
|
|
70
|
+
const _triggers$get = _triggers.default.get(type),
|
|
71
|
+
on = _triggers$get.on,
|
|
72
|
+
off = _triggers$get.off;
|
|
73
|
+
|
|
74
|
+
if (typeof enable !== 'undefined' ? enable : _this2.get('enabled')) {
|
|
75
|
+
on.call(_this2, _this2.trigger.bind(_this2));
|
|
76
|
+
} else {
|
|
77
|
+
off.call(_this2);
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
trigger(context, options) {
|
|
83
|
+
var _this3 = this;
|
|
84
|
+
|
|
85
|
+
return _asyncToGenerator(function* () {
|
|
86
|
+
// `null` means not to trigger
|
|
87
|
+
if (context === null) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const transaction = yield _this3.getTransaction(options);
|
|
92
|
+
|
|
93
|
+
if (_this3.useTransaction) {
|
|
94
|
+
const existed = yield _this3.countExecutions({
|
|
95
|
+
where: {
|
|
96
|
+
transaction: transaction.id
|
|
97
|
+
},
|
|
98
|
+
transaction
|
|
54
99
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}, { transaction });
|
|
81
|
-
execution.workflow = this;
|
|
82
|
-
yield execution.start({ transaction });
|
|
83
|
-
if (!this.executed) {
|
|
84
|
-
yield this.update({ executed: true }, { transaction });
|
|
85
|
-
}
|
|
86
|
-
if (transaction && (!options.transaction || options.transaction.finished)) {
|
|
87
|
-
yield transaction.commit();
|
|
88
|
-
}
|
|
89
|
-
return execution;
|
|
100
|
+
|
|
101
|
+
if (existed) {
|
|
102
|
+
console.warn(`workflow ${_this3.id} has already been triggered in same execution (${transaction.id}), and newly triggering will be skipped.`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const execution = yield _this3.createExecution({
|
|
108
|
+
context,
|
|
109
|
+
status: _constants.EXECUTION_STATUS.STARTED,
|
|
110
|
+
useTransaction: _this3.useTransaction,
|
|
111
|
+
transaction: transaction.id
|
|
112
|
+
}, {
|
|
113
|
+
transaction
|
|
114
|
+
});
|
|
115
|
+
execution.workflow = _this3;
|
|
116
|
+
yield execution.start({
|
|
117
|
+
transaction
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (!_this3.executed) {
|
|
121
|
+
yield _this3.update({
|
|
122
|
+
executed: true
|
|
123
|
+
}, {
|
|
124
|
+
transaction
|
|
90
125
|
});
|
|
91
|
-
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (transaction && (!options.transaction || options.transaction.finished)) {
|
|
129
|
+
yield transaction.commit();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return execution;
|
|
133
|
+
})();
|
|
134
|
+
}
|
|
135
|
+
|
|
92
136
|
}
|
|
93
|
-
|
|
94
|
-
|
|
137
|
+
|
|
138
|
+
exports.default = WorkflowModel;
|
package/lib/server.js
CHANGED
|
@@ -1,68 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const server_1 = require("@nocobase/server");
|
|
17
|
-
const Workflow_1 = __importDefault(require("./models/Workflow"));
|
|
18
|
-
const Execution_1 = __importDefault(require("./models/Execution"));
|
|
19
|
-
const actions_1 = __importDefault(require("./actions"));
|
|
20
|
-
class WorkflowPlugin extends server_1.Plugin {
|
|
21
|
-
load(options = {}) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const { db } = this.app;
|
|
24
|
-
db.registerModels({
|
|
25
|
-
WorkflowModel: Workflow_1.default,
|
|
26
|
-
ExecutionModel: Execution_1.default,
|
|
27
|
-
});
|
|
28
|
-
yield db.import({
|
|
29
|
-
directory: path_1.default.resolve(__dirname, 'collections'),
|
|
30
|
-
});
|
|
31
|
-
(0, actions_1.default)(this.app);
|
|
32
|
-
// [Life Cycle]:
|
|
33
|
-
// * load all workflows in db
|
|
34
|
-
// * add all hooks for enabled workflows
|
|
35
|
-
// * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
|
|
36
|
-
this.app.on('beforeStart', () => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const { model } = db.getCollection('workflows');
|
|
38
|
-
yield model.mount();
|
|
39
|
-
}));
|
|
40
|
-
// [Life Cycle]: initialize all necessary seed data
|
|
41
|
-
this.app.on('db.init', () => __awaiter(this, void 0, void 0, function* () { }));
|
|
42
|
-
// const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);
|
|
43
|
-
// Automation.addHook('afterCreate', async (model: AutomationModel) => {
|
|
44
|
-
// model.get('enabled') && await model.loadJobs();
|
|
45
|
-
// });
|
|
46
|
-
// Automation.addHook('afterUpdate', async (model: AutomationModel) => {
|
|
47
|
-
// if (!model.changed('enabled' as any)) {
|
|
48
|
-
// return;
|
|
49
|
-
// }
|
|
50
|
-
// model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();
|
|
51
|
-
// });
|
|
52
|
-
// Automation.addHook('beforeDestroy', async (model: AutomationModel) => {
|
|
53
|
-
// await model.cancelJobs();
|
|
54
|
-
// });
|
|
55
|
-
// AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {
|
|
56
|
-
// await model.bootstrap();
|
|
57
|
-
// });
|
|
58
|
-
// AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {
|
|
59
|
-
// await model.cancel();
|
|
60
|
-
// });
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
getName() {
|
|
64
|
-
return this.getPackageName(__dirname);
|
|
65
|
-
}
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _path() {
|
|
9
|
+
const data = _interopRequireDefault(require("path"));
|
|
10
|
+
|
|
11
|
+
_path = function _path() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
66
16
|
}
|
|
67
|
-
|
|
68
|
-
|
|
17
|
+
|
|
18
|
+
function _server() {
|
|
19
|
+
const data = require("@nocobase/server");
|
|
20
|
+
|
|
21
|
+
_server = function _server() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var _Workflow = _interopRequireDefault(require("./models/Workflow"));
|
|
29
|
+
|
|
30
|
+
var _Execution = _interopRequireDefault(require("./models/Execution"));
|
|
31
|
+
|
|
32
|
+
var _actions = _interopRequireDefault(require("./actions"));
|
|
33
|
+
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
|
+
|
|
36
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
37
|
+
|
|
38
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
39
|
+
|
|
40
|
+
class WorkflowPlugin extends _server().Plugin {
|
|
41
|
+
load(options = {}) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
|
|
44
|
+
return _asyncToGenerator(function* () {
|
|
45
|
+
const db = _this.app.db;
|
|
46
|
+
db.registerModels({
|
|
47
|
+
WorkflowModel: _Workflow.default,
|
|
48
|
+
ExecutionModel: _Execution.default
|
|
49
|
+
});
|
|
50
|
+
yield db.import({
|
|
51
|
+
directory: _path().default.resolve(__dirname, 'collections')
|
|
52
|
+
});
|
|
53
|
+
(0, _actions.default)(_this.app); // [Life Cycle]:
|
|
54
|
+
// * load all workflows in db
|
|
55
|
+
// * add all hooks for enabled workflows
|
|
56
|
+
// * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
|
|
57
|
+
|
|
58
|
+
_this.app.on('beforeStart', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
59
|
+
const _db$getCollection = db.getCollection('workflows'),
|
|
60
|
+
model = _db$getCollection.model;
|
|
61
|
+
|
|
62
|
+
yield model.mount();
|
|
63
|
+
})); // [Life Cycle]: initialize all necessary seed data
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
_this.app.on('db.init', /*#__PURE__*/_asyncToGenerator(function* () {})); // const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);
|
|
67
|
+
// Automation.addHook('afterCreate', async (model: AutomationModel) => {
|
|
68
|
+
// model.get('enabled') && await model.loadJobs();
|
|
69
|
+
// });
|
|
70
|
+
// Automation.addHook('afterUpdate', async (model: AutomationModel) => {
|
|
71
|
+
// if (!model.changed('enabled' as any)) {
|
|
72
|
+
// return;
|
|
73
|
+
// }
|
|
74
|
+
// model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();
|
|
75
|
+
// });
|
|
76
|
+
// Automation.addHook('beforeDestroy', async (model: AutomationModel) => {
|
|
77
|
+
// await model.cancelJobs();
|
|
78
|
+
// });
|
|
79
|
+
// AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {
|
|
80
|
+
// await model.bootstrap();
|
|
81
|
+
// });
|
|
82
|
+
// AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {
|
|
83
|
+
// await model.cancel();
|
|
84
|
+
// });
|
|
85
|
+
|
|
86
|
+
})();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getName() {
|
|
90
|
+
return this.getPackageName(__dirname);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
exports.default = WorkflowPlugin;
|
|
@@ -1,63 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
+
|
|
10
|
+
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."); }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
+
|
|
16
|
+
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; } } }; }
|
|
17
|
+
|
|
18
|
+
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); }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
3
22
|
const MODE_BITMAP = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
23
|
+
CREATE: 1,
|
|
24
|
+
UPDATE: 2,
|
|
25
|
+
DESTROY: 4
|
|
7
26
|
};
|
|
8
27
|
const MODE_BITMAP_EVENTS = new Map();
|
|
9
28
|
MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');
|
|
10
29
|
MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');
|
|
11
|
-
MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');
|
|
12
|
-
|
|
30
|
+
MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy'); // async function, should return promise
|
|
31
|
+
|
|
13
32
|
function bindHandler(callback) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
33
|
+
const _this$config = this.config,
|
|
34
|
+
condition = _this$config.condition,
|
|
35
|
+
changed = _this$config.changed;
|
|
36
|
+
return (data, options) => {
|
|
37
|
+
// NOTE: if no configured fields changed, do not trigger
|
|
38
|
+
if (changed && changed.length && changed.every(name => !data.changed(name))) {
|
|
39
|
+
return;
|
|
40
|
+
} // NOTE: if no configured condition match, do not trigger
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if (condition && condition.$and.length) {// TODO: check all conditions in condition against data
|
|
44
|
+
// const calculation = toCalculation(condition);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return callback({
|
|
48
|
+
data: data.get()
|
|
49
|
+
}, options);
|
|
50
|
+
};
|
|
27
51
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
|
|
53
|
+
var _default = {
|
|
54
|
+
name: 'collection',
|
|
55
|
+
|
|
56
|
+
on(callback) {
|
|
57
|
+
const database = this.constructor.database;
|
|
58
|
+
const _this$config2 = this.config,
|
|
59
|
+
collection = _this$config2.collection,
|
|
60
|
+
mode = _this$config2.mode;
|
|
61
|
+
const Collection = database.getCollection(collection);
|
|
62
|
+
|
|
63
|
+
if (!Collection) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var _iterator = _createForOfIteratorHelper(MODE_BITMAP_EVENTS.entries()),
|
|
68
|
+
_step;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
72
|
+
let _step$value = _slicedToArray(_step.value, 2),
|
|
73
|
+
key = _step$value[0],
|
|
74
|
+
event = _step$value[1];
|
|
75
|
+
|
|
76
|
+
if (mode & key) {
|
|
77
|
+
var _Collection$model$opt;
|
|
78
|
+
|
|
79
|
+
if (!((_Collection$model$opt = Collection.model.options.hooks[event]) === null || _Collection$model$opt === void 0 ? void 0 : _Collection$model$opt.find(item => item.name && item.name === this.getHookId()))) {
|
|
80
|
+
Collection.model.addHook(event, this.getHookId(), bindHandler.call(this, callback));
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
Collection.model.removeHook(event, this.getHookId());
|
|
55
84
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
85
|
+
}
|
|
86
|
+
} catch (err) {
|
|
87
|
+
_iterator.e(err);
|
|
88
|
+
} finally {
|
|
89
|
+
_iterator.f();
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
off() {
|
|
94
|
+
const database = this.constructor.database;
|
|
95
|
+
const _this$config3 = this.config,
|
|
96
|
+
collection = _this$config3.collection,
|
|
97
|
+
mode = _this$config3.mode;
|
|
98
|
+
const Collection = database.getCollection(collection);
|
|
99
|
+
|
|
100
|
+
if (!Collection) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var _iterator2 = _createForOfIteratorHelper(MODE_BITMAP_EVENTS.entries()),
|
|
105
|
+
_step2;
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
109
|
+
let _step2$value = _slicedToArray(_step2.value, 2),
|
|
110
|
+
key = _step2$value[0],
|
|
111
|
+
event = _step2$value[1];
|
|
112
|
+
|
|
113
|
+
if (mode & key) {
|
|
114
|
+
Collection.model.removeHook(event, this.getHookId());
|
|
60
115
|
}
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
_iterator2.e(err);
|
|
119
|
+
} finally {
|
|
120
|
+
_iterator2.f();
|
|
61
121
|
}
|
|
122
|
+
}
|
|
123
|
+
|
|
62
124
|
};
|
|
63
|
-
|
|
125
|
+
exports.default = _default;
|
package/lib/triggers/index.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.triggers = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.triggers = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _utils() {
|
|
9
|
+
const data = require("@nocobase/utils");
|
|
10
|
+
|
|
11
|
+
_utils = function _utils() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var _collection = _interopRequireDefault(require("./collection"));
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
const triggers = new (_utils().Registry)();
|
|
23
|
+
exports.triggers = triggers;
|
|
24
|
+
var _default = triggers;
|
|
25
|
+
exports.default = _default;
|
|
26
|
+
triggers.register(_collection.default.name, _collection.default);
|