@nocobase/plugin-workflow 0.7.0-alpha.9 → 0.7.1-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Plugin.d.ts +18 -0
- package/lib/Plugin.js +285 -0
- package/lib/Processor.d.ts +40 -0
- package/lib/Processor.js +440 -0
- package/lib/actions/index.d.ts +3 -1
- package/lib/actions/index.js +33 -26
- package/{esm/actions/flow_nodes.d.ts → lib/actions/nodes.d.ts} +1 -0
- package/lib/actions/nodes.js +321 -0
- package/lib/actions/workflows.d.ts +2 -0
- package/lib/actions/workflows.js +197 -0
- package/lib/calculators/index.d.ts +2 -2
- package/lib/calculators/index.js +144 -92
- package/lib/collections/executions.js +32 -38
- package/lib/collections/flow_nodes.js +60 -72
- package/lib/collections/jobs.js +26 -47
- package/lib/collections/workflows.d.ts +1 -2
- package/lib/collections/workflows.js +70 -63
- package/lib/constants.js +22 -17
- package/lib/index.d.ts +4 -3
- package/lib/index.js +85 -22
- package/lib/instructions/calculation.d.ts +1 -1
- package/lib/instructions/calculation.js +32 -29
- package/lib/instructions/condition.d.ts +2 -2
- package/lib/instructions/condition.js +91 -88
- package/lib/instructions/create.d.ts +2 -2
- package/lib/instructions/create.js +39 -25
- package/lib/instructions/delay.d.ts +14 -0
- package/lib/instructions/delay.js +138 -0
- package/lib/instructions/destroy.d.ts +1 -1
- package/lib/instructions/destroy.js +38 -25
- package/lib/instructions/index.d.ts +11 -8
- package/lib/instructions/index.js +76 -25
- package/lib/instructions/parallel.d.ts +3 -3
- package/lib/instructions/parallel.js +95 -84
- package/lib/instructions/prompt.d.ts +2 -2
- package/lib/instructions/prompt.js +21 -13
- package/lib/instructions/query.d.ts +2 -1
- package/lib/instructions/query.js +42 -25
- package/lib/instructions/update.d.ts +2 -1
- package/lib/instructions/update.js +40 -25
- package/lib/models/Execution.d.ts +3 -33
- package/lib/models/Execution.js +18 -254
- package/lib/models/FlowNode.js +18 -5
- package/lib/models/Job.js +18 -5
- package/lib/models/Workflow.d.ts +5 -6
- package/lib/models/Workflow.js +18 -76
- package/lib/triggers/collection.d.ts +12 -0
- package/lib/triggers/collection.js +184 -0
- package/lib/triggers/index.d.ts +11 -7
- package/lib/triggers/index.js +64 -11
- package/lib/triggers/schedule.d.ts +38 -0
- package/lib/triggers/schedule.js +672 -0
- package/package.json +8 -12
- package/esm/actions/flow_nodes.js +0 -139
- package/esm/actions/flow_nodes.js.map +0 -1
- package/esm/actions/index.d.ts +0 -1
- package/esm/actions/index.js +0 -8
- package/esm/actions/index.js.map +0 -1
- package/esm/calculators/index.d.ts +0 -38
- package/esm/calculators/index.js +0 -128
- package/esm/calculators/index.js.map +0 -1
- package/esm/collections/executions.d.ts +0 -3
- package/esm/collections/executions.js +0 -38
- package/esm/collections/executions.js.map +0 -1
- package/esm/collections/flow_nodes.d.ts +0 -3
- package/esm/collections/flow_nodes.js +0 -72
- package/esm/collections/flow_nodes.js.map +0 -1
- package/esm/collections/jobs.d.ts +0 -3
- package/esm/collections/jobs.js +0 -47
- package/esm/collections/jobs.js.map +0 -1
- package/esm/collections/workflows.d.ts +0 -3
- package/esm/collections/workflows.js +0 -63
- package/esm/collections/workflows.js.map +0 -1
- package/esm/constants.d.ts +0 -17
- package/esm/constants.js +0 -18
- package/esm/constants.js.map +0 -1
- package/esm/index.d.ts +0 -5
- package/esm/index.js +0 -6
- package/esm/index.js.map +0 -1
- package/esm/instructions/calculation.d.ts +0 -8
- package/esm/instructions/calculation.js +0 -55
- package/esm/instructions/calculation.js.map +0 -1
- package/esm/instructions/condition.d.ts +0 -5
- package/esm/instructions/condition.js +0 -99
- package/esm/instructions/condition.js.map +0 -1
- package/esm/instructions/create.d.ts +0 -8
- package/esm/instructions/create.js +0 -25
- package/esm/instructions/create.js.map +0 -1
- package/esm/instructions/destroy.d.ts +0 -8
- package/esm/instructions/destroy.js +0 -25
- package/esm/instructions/destroy.js.map +0 -1
- package/esm/instructions/index.d.ts +0 -15
- package/esm/instructions/index.js +0 -20
- package/esm/instructions/index.js.map +0 -1
- package/esm/instructions/parallel.d.ts +0 -13
- package/esm/instructions/parallel.js +0 -88
- package/esm/instructions/parallel.js.map +0 -1
- package/esm/instructions/prompt.d.ts +0 -7
- package/esm/instructions/prompt.js +0 -13
- package/esm/instructions/prompt.js.map +0 -1
- package/esm/instructions/query.d.ts +0 -8
- package/esm/instructions/query.js +0 -25
- package/esm/instructions/query.js.map +0 -1
- package/esm/instructions/update.d.ts +0 -8
- package/esm/instructions/update.js +0 -25
- package/esm/instructions/update.js.map +0 -1
- package/esm/models/Execution.d.ts +0 -50
- package/esm/models/Execution.js +0 -250
- package/esm/models/Execution.js.map +0 -1
- package/esm/models/FlowNode.d.ts +0 -17
- package/esm/models/FlowNode.js +0 -4
- package/esm/models/FlowNode.js.map +0 -1
- package/esm/models/Job.d.ts +0 -15
- package/esm/models/Job.js +0 -4
- package/esm/models/Job.js.map +0 -1
- package/esm/models/Workflow.d.ts +0 -27
- package/esm/models/Workflow.js +0 -72
- package/esm/models/Workflow.js.map +0 -1
- package/esm/server.d.ts +0 -5
- package/esm/server.js +0 -62
- package/esm/server.js.map +0 -1
- package/esm/triggers/index.d.ts +0 -9
- package/esm/triggers/index.js +0 -6
- package/esm/triggers/index.js.map +0 -1
- package/esm/triggers/model.d.ts +0 -12
- package/esm/triggers/model.js +0 -47
- package/esm/triggers/model.js.map +0 -1
- package/lib/actions/flow_nodes.d.ts +0 -3
- package/lib/actions/flow_nodes.js +0 -163
- package/lib/actions/flow_nodes.js.map +0 -1
- package/lib/actions/index.js.map +0 -1
- package/lib/calculators/index.js.map +0 -1
- package/lib/collections/executions.js.map +0 -1
- package/lib/collections/flow_nodes.js.map +0 -1
- package/lib/collections/jobs.js.map +0 -1
- package/lib/collections/workflows.js.map +0 -1
- package/lib/constants.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/instructions/calculation.js.map +0 -1
- package/lib/instructions/condition.js.map +0 -1
- package/lib/instructions/create.js.map +0 -1
- package/lib/instructions/destroy.js.map +0 -1
- package/lib/instructions/index.js.map +0 -1
- package/lib/instructions/parallel.js.map +0 -1
- package/lib/instructions/prompt.js.map +0 -1
- package/lib/instructions/query.js.map +0 -1
- package/lib/instructions/update.js.map +0 -1
- package/lib/models/Execution.js.map +0 -1
- package/lib/models/FlowNode.js.map +0 -1
- package/lib/models/Job.js.map +0 -1
- package/lib/models/Workflow.js.map +0 -1
- package/lib/server.d.ts +0 -5
- package/lib/server.js +0 -68
- package/lib/server.js.map +0 -1
- package/lib/triggers/index.js.map +0 -1
- package/lib/triggers/model.d.ts +0 -12
- package/lib/triggers/model.js +0 -49
- package/lib/triggers/model.js.map +0 -1
- package/tsconfig.build.json +0 -9
package/esm/triggers/model.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const MODE_BITMAP = {
|
|
2
|
-
CREATE: 1,
|
|
3
|
-
UPDATE: 2,
|
|
4
|
-
DESTROY: 4
|
|
5
|
-
};
|
|
6
|
-
const MODE_BITMAP_EVENTS = new Map();
|
|
7
|
-
MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');
|
|
8
|
-
MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');
|
|
9
|
-
MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');
|
|
10
|
-
export default {
|
|
11
|
-
name: 'model',
|
|
12
|
-
on(callback) {
|
|
13
|
-
const { database } = this.constructor;
|
|
14
|
-
const { collection, mode, filter } = this.config;
|
|
15
|
-
const Collection = database.getCollection(collection);
|
|
16
|
-
if (!Collection) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
// async function, should return promise
|
|
20
|
-
const handler = (data, options) => {
|
|
21
|
-
if (filter) {
|
|
22
|
-
// TODO: check all conditions in filter against data
|
|
23
|
-
}
|
|
24
|
-
return callback({ data: data.get() }, options);
|
|
25
|
-
};
|
|
26
|
-
// TODO: duplication when mode change should be considered
|
|
27
|
-
for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {
|
|
28
|
-
if (mode & key) {
|
|
29
|
-
Collection.model.addHook(event, this.getHookId(), handler);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
off() {
|
|
34
|
-
const { database } = this.constructor;
|
|
35
|
-
const { collection, mode } = this.config;
|
|
36
|
-
const Collection = database.getCollection(collection);
|
|
37
|
-
if (!Collection) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {
|
|
41
|
-
if (mode & key) {
|
|
42
|
-
Collection.model.removeHook(event, this.getHookId());
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=model.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/triggers/model.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;AACrC,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAE5D,eAAe;IACb,IAAI,EAAE,OAAO;IACb,EAAE,CAAsB,QAAkB;QACxC,MAAM,EAAE,QAAQ,EAAE,GAAyB,IAAI,CAAC,WAAW,CAAC;QAC5D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QACD,wCAAwC;QACxC,MAAM,OAAO,GAAG,CAAC,IAAS,EAAE,OAAO,EAAE,EAAE;YACrC,IAAI,MAAM,EAAE;gBACV,oDAAoD;aACrD;YACD,OAAO,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC,CAAC;QACF,0DAA0D;QAC1D,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,EAAE;gBACd,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,CAAC;aAC5D;SACF;IACH,CAAC;IACD,GAAG;QACD,MAAM,EAAE,QAAQ,EAAE,GAAyB,IAAI,CAAC,WAAW,CAAC;QAC5D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,EAAE;gBACd,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aACtD;SACF;IACH,CAAC;CACF,CAAA","sourcesContent":["import WorkflowModel from \"../models/Workflow\";\n\nexport interface ModelChangeTriggerConfig {\n collection: string;\n mode: number;\n // TODO: ICondition\n filter: any;\n}\n\nconst MODE_BITMAP = {\n CREATE: 1,\n UPDATE: 2,\n DESTROY: 4\n};\n\nconst MODE_BITMAP_EVENTS = new Map();\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');\n\nexport default {\n name: 'model',\n on(this: WorkflowModel, callback: Function) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode, filter } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n // async function, should return promise\n const handler = (data: any, options) => {\n if (filter) {\n // TODO: check all conditions in filter against data\n }\n return callback({ data: data.get() }, options);\n };\n // TODO: duplication when mode change should be considered\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.addHook(event, this.getHookId(), handler);\n }\n }\n },\n off(this: WorkflowModel) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.removeHook(event, this.getHookId());\n }\n }\n }\n}\n"]}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.destroy = exports.create = void 0;
|
|
32
|
-
const sequelize_1 = require("sequelize");
|
|
33
|
-
const actions_1 = __importStar(require("@nocobase/actions"));
|
|
34
|
-
function create(context, next) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
return actions_1.default.create(context, () => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const { body: instance, db } = context;
|
|
38
|
-
const repository = actions_1.utils.getRepositoryFromParams(context);
|
|
39
|
-
if (!instance.upstreamId) {
|
|
40
|
-
const previousHead = yield repository.findOne({
|
|
41
|
-
filter: {
|
|
42
|
-
id: {
|
|
43
|
-
$ne: instance.id
|
|
44
|
-
},
|
|
45
|
-
upstreamId: null
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
if (previousHead) {
|
|
49
|
-
yield previousHead.setUpstream(instance);
|
|
50
|
-
yield instance.setDownstream(previousHead);
|
|
51
|
-
instance.set('downstream', previousHead);
|
|
52
|
-
}
|
|
53
|
-
return next();
|
|
54
|
-
}
|
|
55
|
-
const upstream = yield instance.getUpstream();
|
|
56
|
-
if (instance.branchIndex == null) {
|
|
57
|
-
const downstream = yield upstream.getDownstream();
|
|
58
|
-
if (downstream) {
|
|
59
|
-
yield downstream.setUpstream(instance);
|
|
60
|
-
yield instance.setDownstream(downstream);
|
|
61
|
-
instance.set('downstream', downstream);
|
|
62
|
-
}
|
|
63
|
-
yield upstream.update({
|
|
64
|
-
downstreamId: instance.id
|
|
65
|
-
});
|
|
66
|
-
upstream.set('downstream', instance);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const [downstream] = yield upstream.getBranches({
|
|
70
|
-
where: {
|
|
71
|
-
id: {
|
|
72
|
-
[sequelize_1.Op.ne]: instance.id
|
|
73
|
-
},
|
|
74
|
-
branchIndex: instance.branchIndex
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
if (downstream) {
|
|
78
|
-
yield downstream.update({
|
|
79
|
-
upstreamId: instance.id,
|
|
80
|
-
branchIndex: null
|
|
81
|
-
});
|
|
82
|
-
yield instance.setDownstream(downstream);
|
|
83
|
-
instance.set('downstream', downstream);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
instance.set('upstream', upstream);
|
|
87
|
-
yield next();
|
|
88
|
-
}));
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
exports.create = create;
|
|
92
|
-
function searchBranchNodes(nodes, from) {
|
|
93
|
-
const branchHeads = nodes
|
|
94
|
-
.filter((item) => item.upstreamId === from.id && item.branchIndex != null);
|
|
95
|
-
return branchHeads.reduce((flatten, head) => flatten.concat(searchBranchDownstreams(nodes, head)), []);
|
|
96
|
-
}
|
|
97
|
-
function searchBranchDownstreams(nodes, from) {
|
|
98
|
-
let result = [];
|
|
99
|
-
for (let search = from; search; search = search.downstream) {
|
|
100
|
-
result = [...result, search, ...searchBranchNodes(nodes, search)];
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
function destroy(context, next) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const repository = actions_1.utils.getRepositoryFromParams(context);
|
|
107
|
-
const { db } = context;
|
|
108
|
-
const { filterByTk } = context.action.params;
|
|
109
|
-
context.body = yield db.sequelize.transaction((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
const fields = ['id', 'upstreamId', 'downstreamId', 'branchIndex'];
|
|
111
|
-
const instance = yield repository.findOne({
|
|
112
|
-
filterByTk,
|
|
113
|
-
fields: [...fields, 'workflowId'],
|
|
114
|
-
appends: ['upstream', 'downstream'],
|
|
115
|
-
transaction
|
|
116
|
-
});
|
|
117
|
-
const { upstream, downstream } = instance.get();
|
|
118
|
-
if (upstream && upstream.downstreamId === instance.id) {
|
|
119
|
-
yield upstream.update({
|
|
120
|
-
downstreamId: instance.downstreamId
|
|
121
|
-
}, { transaction });
|
|
122
|
-
}
|
|
123
|
-
if (downstream) {
|
|
124
|
-
yield downstream.update({
|
|
125
|
-
upstreamId: instance.upstreamId,
|
|
126
|
-
branchIndex: instance.branchIndex
|
|
127
|
-
}, { transaction });
|
|
128
|
-
}
|
|
129
|
-
const nodes = yield repository.find({
|
|
130
|
-
filter: {
|
|
131
|
-
workflowId: instance.workflowId
|
|
132
|
-
},
|
|
133
|
-
fields,
|
|
134
|
-
transaction
|
|
135
|
-
});
|
|
136
|
-
const nodesMap = new Map();
|
|
137
|
-
// make map
|
|
138
|
-
nodes.forEach(item => {
|
|
139
|
-
nodesMap.set(item.id, item);
|
|
140
|
-
});
|
|
141
|
-
// overwrite
|
|
142
|
-
nodesMap.set(instance.id, instance);
|
|
143
|
-
// make linked list
|
|
144
|
-
nodes.forEach(item => {
|
|
145
|
-
if (item.upstreamId) {
|
|
146
|
-
item.upstream = nodesMap.get(item.upstreamId);
|
|
147
|
-
}
|
|
148
|
-
if (item.downstreamId) {
|
|
149
|
-
item.downstream = nodesMap.get(item.downstreamId);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
const branchNodes = searchBranchNodes(nodes, instance);
|
|
153
|
-
yield repository.destroy({
|
|
154
|
-
filterByTk: [instance.id, ...branchNodes.map(item => item.id)],
|
|
155
|
-
transaction
|
|
156
|
-
});
|
|
157
|
-
return instance;
|
|
158
|
-
}));
|
|
159
|
-
yield next();
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
exports.destroy = destroy;
|
|
163
|
-
//# sourceMappingURL=flow_nodes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flow_nodes.js","sourceRoot":"","sources":["../../src/actions/flow_nodes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA+B;AAC/B,6DAA4D;AAE5D,SAAsB,MAAM,CAAC,OAAgB,EAAE,IAAI;;QACjD,OAAO,iBAAO,CAAC,MAAM,CAAC,OAAO,EAAE,GAAS,EAAE;YACxC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;YACvC,MAAM,UAAU,GAAG,eAAK,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;YAE1D,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;gBACxB,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;oBAC5C,MAAM,EAAE;wBACN,EAAE,EAAE;4BACF,GAAG,EAAE,QAAQ,CAAC,EAAE;yBACjB;wBACD,UAAU,EAAE,IAAI;qBACjB;iBACF,CAAC,CAAC;gBACH,IAAI,YAAY,EAAE;oBAChB,MAAM,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;oBACzC,MAAM,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;oBAC3C,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;iBAC1C;gBACD,OA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BAC/C;gBACD,IAAI,IAAI,CAAC,YAAY,EAAE;oBACrB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACnD;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,WAAW,GAAG,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAEvD,MAAM,UAAU,CAAC,OAAO,CAAC;gBACvB,UAAU,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC9D,WAAW;aACZ,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAA,CAAC,CAAC;QAEH,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA;AA/DD,0BA+DC","sourcesContent":["import { Op } from 'sequelize';\nimport actions, { Context, utils } from '@nocobase/actions';\n\nexport async function create(context: Context, next) {\n return actions.create(context, async () => {\n const { body: instance, db } = context;\n const repository = utils.getRepositoryFromParams(context);\n\n if (!instance.upstreamId) {\n const previousHead = await repository.findOne({\n filter: {\n id: {\n $ne: instance.id\n },\n upstreamId: null\n }\n });\n if (previousHead) {\n await previousHead.setUpstream(instance);\n await instance.setDownstream(previousHead);\n instance.set('downstream', previousHead);\n }\n return next();\n }\n\n const upstream = await instance.getUpstream();\n\n if (instance.branchIndex == null) {\n const downstream = await upstream.getDownstream();\n\n if (downstream) {\n await downstream.setUpstream(instance);\n await instance.setDownstream(downstream);\n instance.set('downstream', downstream);\n }\n\n await upstream.update({\n downstreamId: instance.id\n });\n\n upstream.set('downstream', instance);\n } else {\n const [downstream] = await upstream.getBranches({\n where: {\n id: {\n [Op.ne]: instance.id\n },\n branchIndex: instance.branchIndex\n }\n });\n\n if (downstream) {\n await downstream.update({\n upstreamId: instance.id,\n branchIndex: null\n });\n await instance.setDownstream(downstream);\n instance.set('downstream', downstream);\n }\n }\n\n instance.set('upstream', upstream);\n\n await next();\n });\n}\n\nfunction searchBranchNodes(nodes, from): any[] {\n const branchHeads = nodes\n .filter((item: any) => item.upstreamId === from.id && item.branchIndex != null);\n return branchHeads.reduce((flatten: any[], head) => flatten.concat(searchBranchDownstreams(nodes, head)), []) as any[];\n}\n\nfunction searchBranchDownstreams(nodes, from) {\n let result = [];\n for (let search = from; search; search = search.downstream) {\n result = [...result, search, ...searchBranchNodes(nodes, search)];\n }\n return result;\n}\n\nexport async function destroy(context: Context, next) {\n const repository = utils.getRepositoryFromParams(context);\n const { db } = context;\n const { filterByTk } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const fields = ['id', 'upstreamId', 'downstreamId', 'branchIndex'];\n const instance = await repository.findOne({\n filterByTk,\n fields: [...fields, 'workflowId'],\n appends: ['upstream', 'downstream'],\n transaction\n });\n const { upstream, downstream } = instance.get();\n\n if (upstream && upstream.downstreamId === instance.id) {\n await upstream.update({\n downstreamId: instance.downstreamId\n }, { transaction });\n }\n\n if (downstream) {\n await downstream.update({\n upstreamId: instance.upstreamId,\n branchIndex: instance.branchIndex\n }, { transaction });\n }\n\n const nodes = await repository.find({\n filter: {\n workflowId: instance.workflowId\n },\n fields,\n transaction\n });\n const nodesMap = new Map();\n // make map\n nodes.forEach(item => {\n nodesMap.set(item.id, item);\n });\n // overwrite\n nodesMap.set(instance.id, instance);\n // make linked list\n nodes.forEach(item => {\n if (item.upstreamId) {\n item.upstream = nodesMap.get(item.upstreamId);\n }\n if (item.downstreamId) {\n item.downstream = nodesMap.get(item.downstreamId);\n }\n });\n\n const branchNodes = searchBranchNodes(nodes, instance);\n\n await repository.destroy({\n filterByTk: [instance.id, ...branchNodes.map(item => item.id)],\n transaction\n });\n\n return instance;\n });\n\n await next();\n}\n"]}
|
package/lib/actions/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAE3C,SAAS,IAAI,CAAC,IAAI,EAAE,GAAG;IACrB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iCAC3C,MAAM,KACT,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IAC5B,EAAE,EAAE,CAAC,CAAA;AACT,CAAC;AAED,mBAAwB,GAAG;IACzB,GAAG,CAAC,OAAO,mBACN,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,EACjC,CAAC;AACL,CAAC;AAJD,4BAIC","sourcesContent":["import * as flow_nodes from './flow_nodes';\n\nfunction make(name, mod) {\n return Object.keys(mod).reduce((result, key) => ({\n ...result,\n [`${name}:${key}`]: mod[key]\n }), {})\n}\n\nexport default function(app) {\n app.actions({\n ...make('flow_nodes', flow_nodes)\n });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/calculators/index.ts"],"names":[],"mappings":";;;AAAA,mCAA4C;AAC5C,2CAA2C;AAK9B,QAAA,WAAW,GAAG,IAAI,gBAAQ,EAAY,CAAC;AAEpD,kBAAe,mBAAW,CAAC;AA8C3B,cAAc;AACd,yCAAyC;AACzC,kDAAkD;AAClD,sDAAsD;AACtD,SAAS,GAAG,CAAC,MAAM,EAAE,IAA6B;IAChD,OAAO,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAA,YAAW,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC3E,CAAC;AAED,QAAQ;AACR,sDAAsD;AACtD,gEAAgE;AAChE,8CAA8C;AAC9C,SAAgB,SAAS,CAAC,OAAgB,EAAE,OAAiB,EAAE,SAAyB;IACtF,QAAQ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,CAAC;AAED,SAAS,WAAW,CAAC,CAAC,EAAE,CAAC;IACvB,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,UAAU,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,aAAa,CAAC,CAAS,EAAE,CAAS;IACzC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IACpC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,CAAS,EAAE,CAAS;IACvC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,mBAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,mBAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AACjD,mBAAW,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC/C,mBAAW,CAAC,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AACrD,mBAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,mBAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAEjD,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,mBAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAE9C,oCAAoC","sourcesContent":["import { get as getWithPath } from 'lodash';\nimport { Registry } from \"@nocobase/utils\";\n\nimport ExecutionModel from '../models/Execution';\nimport JobModel from '../models/Job';\n\nexport const calculators = new Registry<Function>();\n\nexport default calculators;\n\n\nexport type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';\n\nexport type ObjectGetterOptions = {\n path?: string\n};\n\nexport type JobGetterOptions = ObjectGetterOptions & {\n nodeId: number\n};\n\nexport type CalculationOptions = {\n calculator: string,\n operands: Operand[]\n};\n\nexport type ConstantOperand = {\n type?: 'constant';\n value: any\n};\n\nexport type ContextOperand = {\n type: '$context';\n options: ObjectGetterOptions;\n};\n\nexport type InputOperand = {\n type: '$input';\n options: ObjectGetterOptions;\n};\n\nexport type JobOperand = {\n type: '$jobsMapByNodeId';\n options: JobGetterOptions;\n};\n\nexport type Calculation = {\n type: '$calculation';\n options: CalculationOptions\n};\n\n// TODO(type): union type here is wrong\nexport type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;\n\n// @deprecated\n// HACK: if no path provided, return self\n// @see https://github.com/lodash/lodash/pull/1270\n// TODO(question): should add default value as lodash?\nfunction get(object, path?: string | Array<string>) {\n return path == null || !path.length ? object : getWithPath(object, path);\n}\n\n// NOTE:\n// this method could only be used in executing nodes.\n// because type of 'job' need loaded jobs in runtime execution.\n// or the execution should be prepared first.\nexport function calculate(operand: Operand, lastJob: JobModel, execution: ExecutionModel) {\n switch (operand.type) {\n // @Deprecated\n // from execution context\n case '$context':\n return get(execution.context, operand.options.path);\n\n // @Deprecated\n // from last job (or input job)\n case '$input':\n return lastJob ?? get(lastJob.result, operand.options.path);\n\n // @Deprecated\n // from job in execution\n case '$jobsMapByNodeId':\n // assume jobs have been fetched from execution before\n const job = execution.jobsMapByNodeId[operand.options.nodeId];\n return job && get(job, operand.options.path);\n\n case '$calculation':\n const fn = calculators.get(operand.options.calculator);\n if (!fn) {\n throw new Error(`no calculator function registered for \"${operand.options.calculator}\"`);\n }\n return fn(...operand.options.operands.map(item => calculate(item, lastJob, execution)));\n\n // constant\n default:\n return operand.value;\n }\n}\n\n\n\n// built-in functions\n\nfunction equal(a, b) {\n return a === b;\n}\n\nfunction notEqual(a, b) {\n return a !== b;\n}\n\nfunction gt(a, b) {\n return a > b;\n}\n\nfunction gte(a, b) {\n return a >= b;\n}\n\nfunction lt(a, b) {\n return a < b;\n}\n\nfunction lte(a, b) {\n return a <= b;\n}\n\ncalculators.register('equal', equal);\ncalculators.register('notEqual', notEqual);\ncalculators.register('gt', gt);\ncalculators.register('gte', gte);\ncalculators.register('lt', lt);\ncalculators.register('lte', lte);\n\ncalculators.register('===', equal);\ncalculators.register('!==', notEqual);\ncalculators.register('>', gt);\ncalculators.register('>=', gte);\ncalculators.register('<', lt);\ncalculators.register('<=', lte);\n\n\n\nfunction add(...args) {\n return args.reduce((sum, a) => sum + a, 0);\n}\n\nfunction minus(a, b) {\n return a - b;\n}\n\nfunction multipe(...args) {\n return args.reduce((result, a) => result * a, 1);\n}\n\nfunction divide(a, b) {\n return a / b;\n}\n\nfunction mod(a, b) {\n return a % b;\n}\n\ncalculators.register('add', add);\ncalculators.register('minus', minus);\ncalculators.register('multipe', multipe);\ncalculators.register('divide', divide);\ncalculators.register('mod', mod);\n\ncalculators.register('+', add);\ncalculators.register('-', minus);\ncalculators.register('*', multipe);\ncalculators.register('/', divide);\ncalculators.register('%', mod);\n\nfunction includes(a, b) {\n return a.includes(b);\n}\n\nfunction notIncludes(a, b) {\n return !a.includes(b);\n}\n\nfunction startsWith(a: string, b: string) {\n return a.startsWith(b);\n}\n\nfunction notStartsWith(a: string, b: string) {\n return !a.startsWith(b);\n}\n\nfunction endsWith(a: string, b: string) {\n return a.endsWith(b);\n}\n\nfunction notEndsWith(a: string, b: string) {\n return !a.endsWith(b);\n}\n\ncalculators.register('includes', includes);\ncalculators.register('notIncludes', notIncludes);\ncalculators.register('startsWith', startsWith);\ncalculators.register('notStartsWith', notStartsWith);\ncalculators.register('endsWith', endsWith);\ncalculators.register('notEndsWith', notEndsWith);\n\nfunction before(a: string, b: string) {\n return a < b;\n}\n\ncalculators.register('now', () => new Date());\n\n// TODO: add more common calculators\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"executions.js","sourceRoot":"","sources":["../../src/collections/executions.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,gBAAgB;IACvB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,OAAO;SACf;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,gBAAgB;YACtB,KAAK,EAAE,MAAM;YACb,YAAY,EAAE,KAAK;SACpB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,OAAO;SACf;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,IAAI;SACZ;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'executions',\n model: 'ExecutionModel',\n title: '执行流程',\n fields: [\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'workflow',\n title: '所属工作流'\n },\n {\n type: 'boolean',\n name: 'useTransaction',\n title: '使用事务',\n defaultValue: false\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'jobs',\n title: '流程记录'\n },\n {\n interface: 'json',\n type: 'jsonb',\n name: 'context',\n title: '上下文数据'\n },\n {\n interface: 'select',\n type: 'integer',\n name: 'status',\n title: '状态'\n }\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flow_nodes.js","sourceRoot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AE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE;aACtC;SACF;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,EAAE;SACjB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'flow_nodes',\n // model: 'FlowNodeModel',\n title: 'Workflow Nodes',\n fields: [\n {\n interface: 'string',\n type: 'string',\n name: 'title',\n title: '名称'\n },\n // which workflow belongs to\n {\n interface: 'linkTo',\n name: 'workflow',\n type: 'belongsTo',\n },\n {\n interface: 'linkTo',\n name: 'upstream',\n type: 'belongsTo',\n target: 'flow_nodes'\n },\n {\n interface: 'linkTo',\n name: 'branches',\n type: 'hasMany',\n target: 'flow_nodes',\n sourceKey: 'id',\n foreignKey: 'upstreamId',\n },\n // only works when upstream node is branching type, such as condition and parallel.\n // put here because the design of flow-links model is not really necessary for now.\n // or it should be put into flow-links model.\n {\n interface: 'select',\n name: 'branchIndex',\n type: 'integer',\n title: 'branch index'\n },\n // for reasons:\n // 1. redirect type node to solve cycle flow.\n // 2. recognize as real next node after branches.\n {\n interface: 'linkTo',\n name: 'downstream',\n type: 'belongsTo',\n target: 'flow_nodes'\n },\n {\n interface: 'select',\n type: 'string',\n name: 'type',\n title: '类型',\n // TODO: data for test only now\n dataSource: [\n { label: '数据处理', value: 'data' },\n { label: '数据查询', value: 'query' },\n { label: '等待人工输入', value: 'prompt' },\n { label: '条件判断', value: 'condition' },\n ]\n },\n {\n interface: 'json',\n type: 'jsonb',\n name: 'config',\n title: '配置',\n defaultValue: {}\n }\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../src/collections/jobs.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,MAAM;SACd;QACD,gCAAgC;QAChC;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,MAAM;SACd;QACD,qEAAqE;QACrE,IAAI;QACJ,uBAAuB;QACvB,mBAAmB;QACnB,0BAA0B;QAC1B,2BAA2B;QAC3B,IAAI;KACL;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'jobs',\n title: '流程记录',\n fields: [\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'execution',\n title: '所属流程'\n },\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'node',\n target: 'flow_nodes',\n title: '所属节点'\n },\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'upstream',\n target: 'jobs',\n title: '上游记录'\n },\n // pending / resolved / rejected\n {\n interface: 'status',\n type: 'integer',\n name: 'status',\n title: '处理状态'\n },\n {\n interface: 'json',\n type: 'jsonb',\n name: 'result',\n title: '处理结果'\n },\n // TODO: possibly need node snapshot in case if node has been changed\n // {\n // interface: 'json',\n // type: 'jsonb',\n // name: 'nodeSnapshot',\n // title: 'node snapshot'\n // }\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/collections/workflows.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,eAAe;IACtB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,IAAI;SACf;QACD;YACE,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,IAAI;SACZ;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,IAAI;SACZ;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,IAAI;SACf;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,EAAE;SACjB;QACD;YACE,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,gBAAgB;YACtB,YAAY,EAAE,IAAI;SACnB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,MAAM;SACd;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'workflows',\n model: 'WorkflowModel',\n title: '自动化',\n fields: [\n {\n interface: 'string',\n type: 'string',\n name: 'title',\n title: '自动化名称',\n required: true\n },\n {\n interface: 'boolean',\n type: 'boolean',\n name: 'enabled',\n title: '启用'\n },\n {\n interface: 'textarea',\n type: 'text',\n name: 'description',\n title: '描述'\n },\n {\n interface: 'select',\n type: 'string',\n title: '触发方式',\n name: 'type',\n required: true\n },\n {\n interface: 'json',\n type: 'jsonb',\n title: '触发配置',\n name: 'config',\n required: true,\n defaultValue: {}\n },\n {\n interface: 'boolean',\n type: 'boolean',\n title: '使用事务',\n name: 'useTransaction',\n defaultValue: true\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'nodes',\n target: 'flow_nodes',\n title: '流程节点'\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'executions',\n target: 'executions',\n title: '触发执行'\n }\n ]\n} as CollectionOptions;\n"]}
|
package/lib/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG;IAC9B,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC,CAAC;IACZ,SAAS,EAAE,CAAC,CAAC;CACd,CAAC;AAEW,QAAA,UAAU,GAAG;IACxB,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC,CAAC;IACZ,SAAS,EAAE,CAAC,CAAC;CACd,CAAC;AAEW,QAAA,YAAY,GAAG;IAC1B,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;CACZ,CAAC","sourcesContent":["export const EXECUTION_STATUS = {\n STARTED: 0,\n RESOLVED: 1,\n REJECTED: -1,\n CANCELLED: -2\n};\n\nexport const JOB_STATUS = {\n PENDING: 0,\n RESOLVED: 1,\n REJECTED: -1,\n CANCELLED: -2\n};\n\nexport const BRANCH_INDEX = {\n DEFAULT: null,\n ON_TRUE: 1,\n ON_FALSE: 0\n};\n"]}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B;AAC9B,6CAA2B;AAC3B,iDAA+B;AAE/B,mCAAmC;AAA1B,kHAAA,OAAO,OAAA","sourcesContent":["export * from './constants';\nexport * from './calculators';\nexport * from './triggers';\nexport * from './instructions';\n\nexport { default } from './server';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculation.js","sourceRoot":"","sources":["../../src/instructions/calculation.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAE1C,gDAA2C;AAE3C,kBAAkB;AAClB,0BAA0B;AAC1B,gBAAgB;AAChB,QAAQ;AACR,6BAA6B;AAC7B,mBAAmB;AACnB,6BAA6B;AAC7B,iDAAiD;AACjD,UAAU;AACV,SAAS;AACT,QAAQ;AACR,0BAA0B;AAC1B,yCAAyC;AACzC,SAAS;AACT,QAAQ;AACR,yBAAyB;AACzB,mBAAmB;AACnB,6BAA6B;AAC7B,UAAU;AACV,SAAS;AACT,QAAQ;AACR,0BAA0B;AAC1B,iBAAiB;AACjB,QAAQ;AACR,MAAM;AACN,IAAI;AAEJ,kBAAe;IACP,GAAG,CAAsB,OAAO,EAAE,SAAS;;YAC/C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;YAE1C,MAAM,MAAM,GAAG,WAAW;gBACxB,CAAC,CAAC,IAAA,uBAAS,EAAC;oBACV,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC;iBAC/C,EAAE,OAAO,EAAE,SAAS,CAAC;gBACtB,CAAC,CAAC,IAAI,CAAC;YAET,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\nimport { calculate } from \"../calculators\";\n\n// @calculation: {\n// calculator: 'concat',\n// operands: [\n// {\n// type: 'calculation',\n// options: {\n// calculator: 'add',\n// operands: [{ value: 1 }, { value: 2 }]\n// }\n// },\n// {\n// type: 'constant',\n// value: '{{$context.data.title}}'\n// },\n// {\n// type: 'context',\n// options: {\n// path: 'data.title'\n// }\n// },\n// {\n// type: 'constant',\n// value: 1\n// }\n// ]\n// }\n\nexport default {\n async run(this: FlowNodeModel, prevJob, execution) {\n const { calculation } = this.config || {};\n\n const result = calculation\n ? calculate({\n type: '$calculation',\n options: execution.getParsedValue(calculation)\n }, prevJob, execution)\n : null;\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../src/instructions/condition.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAiE;AACjE,4CAA0C;AAuB1C,kBAAkB;AAClB,gBAAgB;AAChB,aAAa;AACb,mBAAmB;AACnB,sBAAsB;AACtB,UAAU;AACV,oCAAoC;AACpC,+EAA+E;AAC/E,WAAW;AACX,UAAU;AACV,qCAAqC;AACrC,0EAA0E;AAC1E,WAAW;AACX,UAAU;AACV,mBAAmB;AACnB,wBAAwB;AACxB,4BAA4B;AAC5B,gBAAgB;AAChB,2CAA2C;AAC3C,gFAAgF;AAChF,gBAAgB;AAChB,cAAc;AACd,YAAY;AACZ,UAAU;AACV,QAAQ;AACR,MAAM;AACN,IAAI;AACJ,SAAS,c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aAAa,EAAE;gBAC5B,OAAO;oBACL,MAAM,EAAE,sBAAU,CAAC,QAAQ;oBAC3B,MAAM;iBACP,CAAC;aACH;YAED,MAAM,GAAG,GAAG;gBACV,MAAM,EAAE,sBAAU,CAAC,QAAQ;gBAC3B,MAAM;gBACN,gDAAgD;gBAChD,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,UAAU,EAAE,OAAO,IAAI,OAAO,CAAC,EAAE,IAAI,IAAI;aAC1C,CAAC;YAEF,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK;iBAC/B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,MAAM,CAAC,CAAC;YAEhF,IAAI,CAAC,UAAU,EAAE;gBACf,OAAO,GAAG,CAAC;aACZ;YAED,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAE9C,OAAO,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;KAAA;IAEK,MAAM,CAAO,SAAS,EAAE,SAAS;;YACrC,IAAI,SAAS,CAAC,MAAM,KAAK,sBAAU,CAAC,QAAQ,EAAE;gBAC5C,qCAAqC;gBACrC,OAAO,SAAS,CAAC;aAClB;YAED,sDAAsD;YACtD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACxC,CAAC;KAAA;CACF,CAAC","sourcesContent":["import calculators, { calculate, Operand } from \"../calculators\";\nimport { JOB_STATUS } from \"../constants\";\n\ntype BaseCalculation = {\n not?: boolean;\n};\n\ntype SingleCalculation = BaseCalculation & {\n calculation: string;\n operands?: Operand[];\n};\n\ntype GroupCalculationOptions = {\n type: 'and' | 'or';\n calculations: Calculation[]\n};\n\ntype GroupCalculation = BaseCalculation & {\n group: GroupCalculationOptions\n};\n\n// TODO(type)\ntype Calculation = SingleCalculation | GroupCalculation;\n\n// @calculation: {\n// not: false,\n// group: {\n// type: 'and',\n// calculations: [\n// {\n// calculator: 'time.equal',\n// operands: [{ value: '{{$context.time}}' }, { value: '{{$fn.now}}' }]\n// },\n// {\n// calculator: 'value.equal',\n// operands: [{ value: '{{$jobsMapByNodeId.213}}' }, { value: 1 }]\n// },\n// {\n// group: {\n// type: 'or',\n// calculations: [\n// {\n// calculator: 'value.equal',\n// operands: [{ value: '{{$jobsMapByNodeId.213}}' }, { value: 1 }]\n// }\n// ]\n// }\n// }\n// ]\n// }\n// }\nfunction logicCalculate(calculation, input, execution) {\n if (!calculation) {\n return true;\n }\n\n const { not, group } = calculation;\n let result;\n if (group) {\n const method = group.type === 'and' ? 'every' : 'some';\n result = group.calculations[method](item => logicCalculate(item, input, execution));\n } else {\n const args = calculation.operands.map(operand => calculate(operand, input, execution));\n const fn = calculators.get(calculation.calculator);\n if (!fn) {\n throw new Error(`no calculator function registered for \"${calculation.calculator}\"`);\n }\n result = fn(...args);\n }\n\n return not ? !result : result;\n}\n\n\nexport default {\n async run(this, prevJob, execution) {\n // TODO(optimize): loading of jobs could be reduced and turned into incrementally in execution\n // const jobs = await execution.getJobs();\n const { calculation, rejectOnFalse } = this.config || {};\n const result = logicCalculate(calculation, prevJob, execution);\n\n if (!result && rejectOnFalse) {\n return {\n status: JOB_STATUS.REJECTED,\n result\n };\n }\n\n const job = {\n status: JOB_STATUS.RESOLVED,\n result,\n // TODO(optimize): try unify the building of job\n nodeId: this.id,\n upstreamId: prevJob && prevJob.id || null\n };\n\n const branchNode = execution.nodes\n .find(item => item.upstream === this && Boolean(item.branchIndex) === result);\n\n if (!branchNode) {\n return job;\n }\n\n const savedJob = await execution.saveJob(job);\n\n return execution.run(branchNode, savedJob);\n },\n\n async resume(this, branchJob, execution) {\n if (branchJob.status === JOB_STATUS.RESOLVED) {\n // return to continue this.downstream\n return branchJob;\n }\n\n // pass control to upper scope by ending current scope\n return execution.end(this, branchJob);\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/instructions/create.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAG1C,kBAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,iCAC3B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,WAAW,IAClC,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await repo.create({\n ...options,\n transaction: execution.transaction\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../src/instructions/destroy.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAG1C,kBAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,iCAC5B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,WAAW,IAClC,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await repo.destroy({\n ...options,\n transaction: execution.transaction\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instructions/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA2C;AAK3C,sDAA8B;AAC9B,gEAAwC;AACxC,4DAAoC;AACpC,0DAAkC;AAClC,oDAA4B;AAC5B,sDAA8B;AAC9B,sDAA8B;AAC9B,wDAAgC;AA+BnB,QAAA,YAAY,GAAG,IAAI,gBAAQ,EAAe,CAAC;AAExD,oBAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAM,CAAC,CAAC;AACxC,oBAAY,CAAC,QAAQ,CAAC,aAAa,EAAE,qBAAW,CAAC,CAAC;AAClD,oBAAY,CAAC,QAAQ,CAAC,WAAW,EAAE,mBAAS,CAAC,CAAC;AAC9C,oBAAY,CAAC,QAAQ,CAAC,UAAU,EAAE,kBAAQ,CAAC,CAAC;AAC5C,oBAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAK,CAAC,CAAC;AACtC,oBAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAM,CAAC,CAAC;AACxC,oBAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAM,CAAC,CAAC;AACxC,oBAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,iBAAO,CAAC,CAAC;AAE1C,kBAAe,oBAAY,CAAC","sourcesContent":["import { Registry } from '@nocobase/utils';\n\nimport ExecutionModel from '../models/Execution';\nimport FlowNodeModel from '../models/FlowNode';\n\nimport prompt from './prompt';\nimport calculation from './calculation';\nimport condition from './condition';\nimport parallel from './parallel';\nimport query from './query';\nimport create from './create';\nimport update from './update';\nimport destroy from './destroy';\n\nexport interface Job {\n status: number;\n result?: unknown;\n [key: string]: unknown;\n}\n\nexport type InstructionResult = Job | Promise<Job>;\n\n// what should a instruction do?\n// - base on input and context, do any calculations or system call (io), and produce a result or pending.\nexport interface Instruction {\n run(\n this: FlowNodeModel,\n // what should input to be?\n // - just use previously output result for convenience?\n input: any,\n // what should context to be?\n // - could be the workflow execution object (containing context data)\n execution: ExecutionModel\n ): InstructionResult;\n\n // for start node in main flow (or branch) to resume when manual sub branch triggered\n resume?(\n this: FlowNodeModel,\n input: any,\n execution: ExecutionModel\n ): InstructionResult\n}\n\nexport const instructions = new Registry<Instruction>();\n\ninstructions.register('prompt', prompt);\ninstructions.register('calculation', calculation);\ninstructions.register('condition', condition);\ninstructions.register('parallel', parallel);\ninstructions.register('query', query);\ninstructions.register('create', create);\ninstructions.register('update', update);\ninstructions.register('destroy', destroy);\n\nexport default instructions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.js","sourceRoot":"","sources":["../../src/instructions/parallel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0C;AAK7B,QAAA,aAAa,GAAG;IAC3B,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,MAAM,a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AS,EAAE,IAAI,CAAC,CAAC;YAE3D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;YAC/B,2FAA2F;YAC3F,IAAI,MAAM,KAAK,sBAAU,CAAC,OAAO,EAAE;gBACjC,OAAO,IAAI,CAAC;aACb;YAED,oDAAoD;YACpD,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACzD,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAC/D,MAAM,EAAE,IAAI,GAAG,qBAAa,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;YAEvD,MAAM,SAAS,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,SAAS,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC;YACvG,GAAG,CAAC,GAAG,CAAC;gBACN,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC;aACvC,CAAC,CAAC;YAEH,IAAI,GAAG,CAAC,MAAM,KAAK,sBAAU,CAAC,OAAO,EAAE;gBACrC,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;gBACvD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;aACjC;YAED,OAAO,GAAG,CAAC;QACb,CAAC;KAAA;CACF,CAAC","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport ExecutionModel from \"../models/Execution\";\nimport FlowNodeModel from \"../models/FlowNode\";\nimport JobModel from \"../models/Job\";\n\nexport const PARALLEL_MODE = {\n ALL: 'all',\n ANY: 'any',\n RACE: 'race'\n} as const;\n\nconst StatusGetters = {\n [PARALLEL_MODE.ALL](result) {\n if (result.some(j => j && j.status === JOB_STATUS.REJECTED)) {\n return JOB_STATUS.REJECTED;\n }\n if (result.every(j => j && j.status === JOB_STATUS.RESOLVED)) {\n return JOB_STATUS.RESOLVED;\n }\n return JOB_STATUS.PENDING;\n },\n [PARALLEL_MODE.ANY](result) {\n return result.some(j => j && j.status === JOB_STATUS.RESOLVED)\n ? JOB_STATUS.RESOLVED\n : (\n result.some(j => j && j.status === JOB_STATUS.PENDING)\n ? JOB_STATUS.PENDING\n : JOB_STATUS.REJECTED\n )\n },\n [PARALLEL_MODE.RACE](result) {\n return result.some(j => j && j.status === JOB_STATUS.RESOLVED)\n ? JOB_STATUS.RESOLVED\n : (\n result.some(j => j && j.status === JOB_STATUS.REJECTED)\n ? JOB_STATUS.REJECTED\n : JOB_STATUS.PENDING\n )\n }\n};\n\nexport default {\n async run(this: FlowNodeModel, prevJob: JobModel, execution: ExecutionModel) {\n const branches = execution.nodes\n .filter(item => item.upstream === this && item.branchIndex !== null)\n .sort((a, b) => a.branchIndex - b.branchIndex);\n\n const job = await execution.saveJob({\n status: JOB_STATUS.PENDING,\n result: Array(branches.length).fill(null),\n nodeId: this.id,\n upstreamId: prevJob?.id ?? null\n });\n\n // NOTE:\n // use `reduce` but not `Promise.all` here to avoid racing manupulating db.\n // for users, this is almost equivalent to `Promise.all`,\n // because of the delay is not significant sensible.\n // another better aspect of this is, it could handle sequenced branches in future.\n await branches.reduce((promise: Promise<any>, branch) => promise.then(() => execution.run(branch, job)), Promise.resolve());\n\n return execution.end(this, job);\n },\n\n async resume(this, branchJob, execution: ExecutionModel) {\n const job = execution.findBranchParentJob(branchJob, this);\n\n const { result, status } = job;\n // if parallel has been done (resolved / rejected), do not care newly executed branch jobs.\n if (status !== JOB_STATUS.PENDING) {\n return null;\n }\n\n // find the index of the node which start the branch\n const jobNode = execution.nodesMap.get(branchJob.nodeId);\n const { branchIndex } = execution.findBranchStartNode(jobNode);\n const { mode = PARALLEL_MODE.ALL } = this.config || {};\n\n const newResult = [...result.slice(0, branchIndex), branchJob.get(), ...result.slice(branchIndex + 1)];\n job.set({\n result: newResult,\n status: StatusGetters[mode](newResult)\n });\n\n if (job.status === JOB_STATUS.PENDING) {\n await job.save({ transaction: execution.transaction });\n return execution.end(this, job);\n }\n\n return job;\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/instructions/prompt.ts"],"names":[],"mappings":";;AAAA,4CAA0C;AAE1C,kBAAe;IACb,GAAG,CAAO,KAAK,EAAE,SAAS;QACxB,OAAO;YACL,MAAM,EAAE,sBAAU,CAAC,OAAO;SAC3B,CAAC;IACJ,CAAC;IAED,MAAM,CAAO,GAAG,EAAE,SAAS;QACzB,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,sBAAU,CAAC,QAAQ,CAAC,CAAC;QACvC,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC","sourcesContent":["import { JOB_STATUS } from \"../constants\";\n\nexport default {\n run(this, input, execution) {\n return {\n status: JOB_STATUS.PENDING\n };\n },\n\n resume(this, job, execution) {\n job.set('status', JOB_STATUS.RESOLVED);\n return job;\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/instructions/query.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAG1C,kBAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,QAAQ,EACR,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,kCAC/D,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,WAAW,IAClC,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAC","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n multiple,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await (multiple ? repo.find : repo.findOne).call(repo, {\n ...options,\n transaction: execution.transaction\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/instructions/update.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAG1C,kBAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,QAAQ,GAAG,KAAK,EAChB,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,iCAC3B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,WAAW,IAClC,CAAC;YAEH,OAAO;gBACL,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;gBAC/C,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n multiple = false,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await repo.update({\n ...options,\n transaction: execution.transaction\n });\n\n return {\n result: multiple ? result : (result[0] || null),\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Execution.js","sourceRoot":"","sources":["../../src/models/Execution.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAAqD;AACrD,oEAAmC;AAEnC,4CAA4D;AAC5D,mEAA2C;AAI3C,iEAAyC;AAMzC,MAAqB,cAAe,SAAQ,gBAAK;IAAjD;;QAsBE,UAAK,GAAyB,EAAE,CAAC;QACjC,aAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC5C,YAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;QACtC,oBAAe,GAA2B,EAAE,CAAC;IA6P/C,CAAC;IApPC,yCAAyC;IACzC,SAAS,CAAC,KAAK,GAAG,EAAE;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAI,IAAI,CAAC,UAAU,EAAE;gBACnB,IAAI,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C;IACd,CAAC;IAEM,cAAc,CAAC,KAAK,EAAE,IAAK;QAChC,MAAM,WAAW,GAAG,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG;YACZ,SAAS,EAAE,IAAI;YACf,IAAI;SACL,CAAC;QACF,KAAK,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,qBAAW,CAAC,WAAW,EAAE,EAAE;YAChD,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpC;QAED,OAAO,IAAA,wBAAK,EAAC,KAAK,CAAC,CAAC;YAClB,QAAQ,EAAE,IAAI,CAAC,OAAO;YACtB,gBAAgB,EAAE,IAAI,CAAC,eAAe;YACtC,GAAG,EAAE,WAAW;SACjB,CAAC,CAAC;IACL,CAAC;;AArRH,iCAsRC;AA3PQ,wBAAS,GAAG;IACjB,CAAC,sBAAU,CAAC,OAAO,CAAC,EAAE,4BAAgB,CAAC,OAAO;IAC9C,CAAC,sBAAU,CAAC,QAAQ,CAAC,EAAE,4BAAgB,CAAC,QAAQ;IAChD,CAAC,sBAAU,CAAC,QAAQ,CAAC,EAAE,4BAAgB,CAAC,QAAQ;IAChD,CAAC,sBAAU,CAAC,SAAS,CAAC,EAAE,4BAAgB,CAAC,SAAS;CACnD,CAAC","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport parse from 'json-templates';\nimport { BelongsToGetAssociationMixin, HasManyGetAssociationsMixin, Transaction } from 'sequelize';\nimport { EXECUTION_STATUS, JOB_STATUS } from '../constants';\nimport instructions from '../instructions';\nimport WorkflowModel from './Workflow';\nimport FlowNodeModel from './FlowNode';\nimport JobModel from './Job';\nimport calculators from '../calculators';\n\nexport interface ExecutionOptions {\n transaction?: Transaction;\n}\n\nexport default class ExecutionModel extends Model {\n declare static readonly database: Database;\n\n declare id: number;\n declare title: string;\n declare context: any;\n declare status: number;\n // NOTE: this duplicated column is for transaction in preparing cycle from workflow\n declare useTransaction: boolean;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare workflow?: WorkflowModel;\n declare getWorkflow: BelongsToGetAssociationMixin<WorkflowModel>;\n\n declare jobs?: JobModel[];\n declare getJobs: HasManyGetAssociationsMixin<JobModel>;\n\n options: ExecutionOptions;\n transaction: Transaction;\n\n nodes: Array<FlowNodeModel> = [];\n nodesMap = new Map<number, FlowNodeModel>();\n jobsMap = new Map<number, JobModel>();\n jobsMapByNodeId: { [key: number]: any } = {};\n\n static StatusMap = {\n [JOB_STATUS.PENDING]: EXECUTION_STATUS.STARTED,\n [JOB_STATUS.RESOLVED]: EXECUTION_STATUS.RESOLVED,\n [JOB_STATUS.REJECTED]: EXECUTION_STATUS.REJECTED,\n [JOB_STATUS.CANCELLED]: EXECUTION_STATUS.CANCELLED,\n };\n\n // make dual linked nodes list then cache\n makeNodes(nodes = []) {\n this.nodes = nodes;\n\n nodes.forEach((node) => {\n this.nodesMap.set(node.id, node);\n });\n\n nodes.forEach((node) => {\n if (node.upstreamId) {\n node.upstream = this.nodesMap.get(node.upstreamId);\n }\n\n if (node.downstreamId) {\n node.downstream = this.nodesMap.get(node.downstreamId);\n }\n });\n }\n\n makeJobs(jobs: Array<JobModel>) {\n jobs.forEach((job) => {\n this.jobsMap.set(job.id, job);\n // TODO: should consider cycle, and from previous job\n this.jobsMapByNodeId[job.nodeId] = job.result;\n });\n }\n\n getTransaction() {\n const { sequelize } = (<typeof WorkflowModel>this.constructor).database;\n // @ts-ignore\n if (!this.useTransaction) {\n return undefined;\n }\n\n const { options } = this;\n\n // @ts-ignore\n return options.transaction && !options.transaction.finished\n ? options.transaction\n : sequelize.transaction();\n }\n\n async prepare(options, commit = false) {\n this.options = options || {};\n // @ts-ignore\n const transaction = await this.getTransaction()\n this.transaction = transaction;\n\n if (!this.workflow) {\n this.workflow = await this.getWorkflow({ transaction });\n }\n\n const nodes = await this.workflow.getNodes({ transaction });\n\n this.makeNodes(nodes);\n\n const jobs = await this.getJobs({\n order: [['id', 'ASC']],\n transaction,\n });\n\n this.makeJobs(jobs);\n\n if (commit) {\n await this.commit();\n }\n }\n\n public async start(options: ExecutionOptions) {\n if (this.status !== EXECUTION_STATUS.STARTED) {\n throw new Error(`execution was ended with status ${this.status}`);\n }\n await this.prepare(options);\n if (this.nodes.length) {\n const head = this.nodes.find(item => !item.upstream);\n await this.run(head, { result: this.context });\n } else {\n await this.exit(null);\n }\n await this.commit();\n }\n\n public async resume(job: JobModel, options: ExecutionOptions) {\n if (this.status !== EXECUTION_STATUS.STARTED) {\n throw new Error(`execution was ended with status ${this.status}`);\n }\n await this.prepare(options);\n const node = this.nodesMap.get(job.nodeId);\n await this.recall(node, job);\n await this.commit();\n }\n\n private async commit() {\n // @ts-ignore\n if (this.transaction && (!this.options.transaction || this.options.transaction.finished)) {\n await this.transaction.commit();\n }\n }\n\n private async exec(instruction: Function, node: FlowNodeModel, prevJob) {\n let job;\n try {\n // call instruction to get result and status\n job = await instruction.call(node, prevJob, this);\n if (!job) {\n return null;\n }\n } catch (err) {\n // for uncaught error, set to rejected\n job = {\n result: err instanceof Error\n ? { message: err.message, stack: process.env.NODE_ENV === 'production' ? [] : err.stack }\n : err,\n status: JOB_STATUS.REJECTED,\n };\n // if previous job is from resuming\n if (prevJob && prevJob.nodeId === node.id) {\n prevJob.set(job);\n job = prevJob;\n }\n }\n\n let savedJob;\n // TODO(optimize): many checking of resuming or new could be improved\n // could be implemented separately in exec() / resume()\n if (job instanceof Model) {\n savedJob = (await job.save({ transaction: this.transaction })) as unknown as JobModel;\n } else {\n const upstreamId = prevJob instanceof Model ? prevJob.get('id') : null;\n savedJob = await this.saveJob({\n nodeId: node.id,\n upstreamId,\n ...job,\n });\n }\n\n if (savedJob.status === JOB_STATUS.RESOLVED && node.downstream) {\n // run next node\n return this.run(node.downstream, savedJob);\n }\n\n // all nodes in scope have been executed\n return this.end(node, savedJob);\n }\n\n public async run(node, input?) {\n const { run } = instructions.get(node.type);\n if (typeof run !== 'function') {\n return Promise.reject(new Error('`run` should be implemented for customized execution of the node'));\n }\n\n return this.exec(run, node, input);\n }\n\n // parent node should take over the control\n public end(node, job) {\n const parentNode = this.findBranchParentNode(node);\n // no parent, means on main flow\n if (parentNode) {\n return this.recall(parentNode, job);\n }\n\n // really done for all nodes\n // * should mark execution as done with last job status\n return this.exit(job);\n }\n\n async recall(node, job) {\n const { resume } = instructions.get(node.type);\n if (typeof resume !== 'function') {\n return Promise.reject(new Error('`resume` should be implemented because the node made branch'));\n }\n\n return this.exec(resume, node, job);\n }\n\n async exit(job: JobModel | null) {\n const status = job ? ExecutionModel.StatusMap[job.status] : EXECUTION_STATUS.RESOLVED;\n await this.update({ status }, { transaction: this.transaction });\n return null;\n }\n\n // TODO(optimize)\n async saveJob(payload) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { model } = database.getCollection('jobs');\n const [job] = (await model.upsert(\n {\n ...payload,\n executionId: this.id,\n },\n { transaction: this.transaction },\n )) as unknown as [JobModel, boolean | null];\n this.jobsMap.set(job.id, job);\n this.jobsMapByNodeId[job.nodeId] = job.result;\n\n return job;\n }\n\n // find the first node in current branch\n findBranchStartNode(node: FlowNodeModel): FlowNodeModel | null {\n for (let n = node; n; n = n.upstream) {\n if (n.branchIndex !== null) {\n return n;\n }\n }\n return null;\n }\n\n // find the node start current branch\n findBranchParentNode(node: FlowNodeModel): FlowNodeModel | null {\n for (let n = node; n; n = n.upstream) {\n if (n.branchIndex !== null) {\n return n.upstream;\n }\n }\n return null;\n }\n\n findBranchParentJob(job: JobModel, node: FlowNodeModel): JobModel | null {\n for (let j = job; j; j = this.jobsMap.get(j.upstreamId)) {\n if (j.nodeId === node.id) {\n return j;\n }\n }\n return null;\n }\n\n public getParsedValue(value, node?) {\n const injectedFns = {};\n const scope = {\n execution: this,\n node\n };\n for (let [name, fn] of calculators.getEntities()) {\n injectedFns[name] = fn.bind(scope);\n }\n\n return parse(value)({\n $context: this.context,\n $jobsMapByNodeId: this.jobsMapByNodeId,\n $fn: injectedFns\n });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FlowNode.js","sourceRoot":"","sources":["../../src/models/FlowNode.ts"],"names":[],"mappings":";;AAAA,iDAAqD;AAKrD,MAAqB,aAAc,SAAQ,gBAAK;CAiB/C;AAjBD,gCAiBC","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport { BelongsToGetAssociationMixin } from 'sequelize';\nimport WorkflowModel from './Workflow';\n\n\nexport default class FlowNodeModel extends Model {\n declare static readonly database: Database;\n\n declare id: number;\n declare title: string;\n declare branchIndex: null | number;\n declare type: string;\n declare config: any;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare upstream: FlowNodeModel;\n declare downstream: FlowNodeModel;\n\n declare workflow?: WorkflowModel;\n declare getWorkflow: BelongsToGetAssociationMixin<WorkflowModel>;\n}\n"]}
|
package/lib/models/Job.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../src/models/Job.ts"],"names":[],"mappings":";;AAAA,iDAA2C;AAI3C,MAAqB,QAAS,SAAQ,gBAAK;CAc1C;AAdD,2BAcC","sourcesContent":["import { Model } from '@nocobase/database';\nimport { BelongsToGetAssociationMixin } from 'sequelize';\nimport FlowNodeModel from './FlowNode';\n\nexport default class JobModel extends Model {\n declare id: number;\n declare status: number;\n declare result: any;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare upstreamId: number;\n declare upstream: JobModel;\n\n declare nodeId: number;\n declare node?: FlowNodeModel;\n declare getNode: BelongsToGetAssociationMixin<FlowNodeModel>;\n}"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Workflow.js","sourceRoot":"","sources":["../../src/models/Workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAAqD;AAGrD,2DAAmC;AACnC,4CAAgD;AAIhD,MAAqB,aAAc,SAAQ,gBAAK;IAsB9C,MAAM,CAAO,KAAK;;YAChB,M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C,GAAG,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;gBAChE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;aACxC;iBAAM;gBACL,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAChB;QACH,CAAC;KAAA;IAEK,OAAO,CAAC,OAAe,EAAE,OAAO;;YACpC,8BAA8B;YAC9B,IAAI,OAAO,KAAK,IAAI,EAAE;gBACpB,OAAO;aACR;YAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAEvD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC;gBAC3C,OAAO;gBACP,MAAM,EAAE,4BAAgB,CAAC,OAAO;gBAChC,cAAc,EAAE,IAAI,CAAC,cAAc;aACpC,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;YAEpB,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;YAE1B,MAAM,SAAS,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;YAEvC,IAAI,WAAW,IAAI,CAAC,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;gBACzE,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;aAC5B;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;CACF;AArFD,gCAqFC","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport { HasManyCreateAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';\n\nimport triggers from '../triggers';\nimport { EXECUTION_STATUS } from '../constants';\nimport ExecutionModel from './Execution';\nimport FlowNodeModel from './FlowNode';\n\nexport default class WorkflowModel extends Model {\n declare static database: Database;\n\n declare id: number;\n declare title: string;\n declare enabled: boolean;\n declare description?: string;\n declare type: string;\n declare config: any;\n declare useTransaction: boolean;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare nodes: FlowNodeModel[];\n declare getNodes: HasManyGetAssociationsMixin<FlowNodeModel>;\n declare createNode: HasManyCreateAssociationMixin<FlowNodeModel>;\n\n declare executions: ExecutionModel[];\n declare getExecutions: HasManyGetAssociationsMixin<ExecutionModel>;\n declare createExecution: HasManyCreateAssociationMixin<ExecutionModel>;\n\n static async mount() {\n const collection = this.database.getCollection('workflows');\n const workflows = await collection.repository.find({\n filter: { enabled: true },\n });\n\n workflows.forEach((workflow: WorkflowModel) => {\n workflow.toggle();\n });\n\n this.addHook('afterCreate', (model: WorkflowModel) => model.toggle());\n this.addHook('afterUpdate', (model: WorkflowModel) => model.toggle());\n this.addHook('afterDestroy', (model: WorkflowModel) => model.toggle(false));\n }\n\n getHookId() {\n return `workflow-${this.get('id')}`;\n }\n\n getTransaction(options) {\n if (!this.useTransaction) {\n return undefined;\n }\n\n return options.transaction && !options.transaction.finished\n ? options.transaction\n : (<typeof WorkflowModel>this.constructor).database.sequelize.transaction();\n }\n\n async toggle(enable?: boolean) {\n const type = this.get('type');\n const { on, off } = triggers.get(type);\n if (typeof enable !== 'undefined' ? enable : this.get('enabled')) {\n on.call(this, this.trigger.bind(this));\n } else {\n off.call(this);\n }\n }\n\n async trigger(context: Object, options) {\n // `null` means not to trigger\n if (context === null) {\n return;\n }\n\n const transaction = await this.getTransaction(options);\n\n const execution = await this.createExecution({\n context,\n status: EXECUTION_STATUS.STARTED,\n useTransaction: this.useTransaction\n }, { transaction });\n\n execution.workflow = this;\n\n await execution.start({ transaction });\n\n if (transaction && (!options.transaction || options.transaction.finished)) {\n await transaction.commit();\n }\n\n return execution;\n }\n}\n"]}
|
package/lib/server.d.ts
DELETED
package/lib/server.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const path_1 = __importDefault(require("path"));
|
|
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
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.default = WorkflowPlugin;
|
|
68
|
-
//# sourceMappingURL=server.js.map
|
package/lib/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAwB;AAExB,6CAA0C;AAE1C,iEAA8C;AAC9C,mEAAgD;AAChD,wDAAgC;AAEhC,MAAqB,cAAe,SAAQ,eAAM;IAC1C,IAAI,CAAC,OAAO,GAAG,EAAE;;YACrB,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;YAExB,EAAE,CAAC,cAAc,CAAC;gBAChB,aAAa,EAAb,kBAAa;gBACb,cAAc,EAAd,mBAAc;aACf,CAAC,CAAC;YAEH,MAAM,EAAE,CAAC,MAAM,CAAC;gBACd,SAAS,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC;aAClD,CAAC,CAAC;YAEH,IAAA,iBAAO,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAElB,gBAAgB;YAChB,+BAA+B;YAC/B,0CAA0C;YAC1C,wFAAwF;YACxF,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,EAAE,GAAS,EAAE;gBACpC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBAChD,MAAO,KAA8B,CAAC,KAAK,EAAE,CAAC;YAChD,CAAC,CAAA,CAAC,CAAC;YAEH,mDAAmD;YACnD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAS,EAAE,gDAAE,CAAC,CAAA,CAAC,CAAC;YAEvC,+FAA+F;YAE/F,wEAAwE;YACxE,oDAAoD;YACpD,MAAM;YAEN,wEAAwE;YACxE,4CAA4C;YAC5C,cAAc;YACd,MAAM;YACN,8EAA8E;YAC9E,MAAM;YAEN,0EAA0E;YAC1E,8BAA8B;YAC9B,MAAM;YAEN,8EAA8E;YAC9E,6BAA6B;YAC7B,MAAM;YAEN,gFAAgF;YAChF,0BAA0B;YAC1B,MAAM;QACR,CAAC;KAAA;IAED,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF;AAxDD,iCAwDC","sourcesContent":["import path from 'path';\n\nimport { Plugin } from '@nocobase/server';\n\nimport WorkflowModel from './models/Workflow';\nimport ExecutionModel from './models/Execution';\nimport actions from './actions';\n\nexport default class WorkflowPlugin extends Plugin {\n async load(options = {}) {\n const { db } = this.app;\n\n db.registerModels({\n WorkflowModel,\n ExecutionModel,\n });\n\n await db.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n\n actions(this.app);\n\n // [Life Cycle]:\n // * load all workflows in db\n // * add all hooks for enabled workflows\n // * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks\n this.app.on('beforeStart', async () => {\n const { model } = db.getCollection('workflows');\n await (model as typeof WorkflowModel).mount();\n });\n\n // [Life Cycle]: initialize all necessary seed data\n this.app.on('db.init', async () => {});\n\n // const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);\n\n // Automation.addHook('afterCreate', async (model: AutomationModel) => {\n // model.get('enabled') && await model.loadJobs();\n // });\n\n // Automation.addHook('afterUpdate', async (model: AutomationModel) => {\n // if (!model.changed('enabled' as any)) {\n // return;\n // }\n // model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();\n // });\n\n // Automation.addHook('beforeDestroy', async (model: AutomationModel) => {\n // await model.cancelJobs();\n // });\n\n // AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {\n // await model.bootstrap();\n // });\n\n // AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {\n // await model.cancel();\n // });\n }\n\n getName(): string {\n return this.getPackageName(__dirname);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/triggers/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA2C;AAE3C,oDAAmC;AAQtB,QAAA,QAAQ,GAAG,IAAI,gBAAQ,EAAW,CAAC;AAEhD,kBAAe,gBAAQ,CAAC;AAExB,gBAAQ,CAAC,QAAQ,CAAC,eAAY,CAAC,IAAI,EAAE,eAAY,CAAC,CAAC","sourcesContent":["import { Registry } from '@nocobase/utils';\nimport WorkflowModel from '../models/Workflow';\nimport modelTrigger from './model';\n\nexport interface Trigger {\n name: string;\n on(this: WorkflowModel, callback: Function): void;\n off(this: WorkflowModel): void;\n}\n\nexport const triggers = new Registry<Trigger>();\n\nexport default triggers;\n\ntriggers.register(modelTrigger.name, modelTrigger);\n"]}
|
package/lib/triggers/model.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import WorkflowModel from "../models/Workflow";
|
|
2
|
-
export interface ModelChangeTriggerConfig {
|
|
3
|
-
collection: string;
|
|
4
|
-
mode: number;
|
|
5
|
-
filter: any;
|
|
6
|
-
}
|
|
7
|
-
declare const _default: {
|
|
8
|
-
name: string;
|
|
9
|
-
on(this: WorkflowModel, callback: Function): void;
|
|
10
|
-
off(this: WorkflowModel): void;
|
|
11
|
-
};
|
|
12
|
-
export default _default;
|