@nocobase/plugin-workflow 0.7.0-alpha.83 → 0.7.1-alpha.5

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.
Files changed (47) hide show
  1. package/lib/Plugin.d.ts +18 -0
  2. package/lib/Plugin.js +285 -0
  3. package/lib/Processor.d.ts +40 -0
  4. package/lib/Processor.js +440 -0
  5. package/lib/actions/workflows.d.ts +1 -2
  6. package/lib/actions/workflows.js +13 -87
  7. package/lib/calculators/index.d.ts +2 -2
  8. package/lib/calculators/index.js +4 -4
  9. package/lib/collections/executions.js +7 -15
  10. package/lib/collections/jobs.js +7 -26
  11. package/lib/collections/workflows.d.ts +1 -2
  12. package/lib/collections/workflows.js +67 -67
  13. package/lib/index.d.ts +4 -3
  14. package/lib/index.js +24 -10
  15. package/lib/instructions/calculation.d.ts +1 -1
  16. package/lib/instructions/calculation.js +4 -6
  17. package/lib/instructions/condition.d.ts +2 -2
  18. package/lib/instructions/condition.js +15 -19
  19. package/lib/instructions/create.d.ts +1 -1
  20. package/lib/instructions/create.js +8 -12
  21. package/lib/instructions/delay.d.ts +14 -0
  22. package/lib/instructions/delay.js +138 -0
  23. package/lib/instructions/destroy.d.ts +1 -1
  24. package/lib/instructions/destroy.js +8 -12
  25. package/lib/instructions/index.d.ts +11 -8
  26. package/lib/instructions/index.js +43 -13
  27. package/lib/instructions/parallel.d.ts +3 -3
  28. package/lib/instructions/parallel.js +15 -19
  29. package/lib/instructions/prompt.d.ts +2 -2
  30. package/lib/instructions/prompt.js +2 -2
  31. package/lib/instructions/query.d.ts +2 -1
  32. package/lib/instructions/query.js +9 -13
  33. package/lib/instructions/update.d.ts +2 -2
  34. package/lib/instructions/update.js +10 -14
  35. package/lib/models/Execution.d.ts +2 -33
  36. package/lib/models/Execution.js +2 -397
  37. package/lib/models/Workflow.d.ts +2 -2
  38. package/lib/models/Workflow.js +1 -81
  39. package/lib/triggers/collection.d.ts +2 -6
  40. package/lib/triggers/collection.js +62 -27
  41. package/lib/triggers/index.d.ts +11 -4
  42. package/lib/triggers/index.js +52 -5
  43. package/lib/triggers/schedule.d.ts +4 -7
  44. package/lib/triggers/schedule.js +205 -135
  45. package/package.json +8 -9
  46. package/lib/server.d.ts +0 -10
  47. package/lib/server.js +0 -124
@@ -3,7 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.instructions = exports.default = void 0;
6
+ exports.default = _default;
7
+
8
+ function _path() {
9
+ const data = _interopRequireDefault(require("path"));
10
+
11
+ _path = function _path() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
7
17
 
8
18
  function _utils() {
9
19
  const data = require("@nocobase/utils");
@@ -33,15 +43,35 @@ var _destroy = _interopRequireDefault(require("./destroy"));
33
43
 
34
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
45
 
36
- const instructions = new (_utils().Registry)();
37
- exports.instructions = instructions;
38
- instructions.register('prompt', _prompt.default);
39
- instructions.register('calculation', _calculation.default);
40
- instructions.register('condition', _condition.default);
41
- instructions.register('parallel', _parallel.default);
42
- instructions.register('query', _query.default);
43
- instructions.register('create', _create.default);
44
- instructions.register('update', _update.default);
45
- instructions.register('destroy', _destroy.default);
46
- var _default = instructions;
47
- exports.default = _default;
46
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
47
+
48
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
49
+
50
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
51
+
52
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
53
+
54
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
55
+
56
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
57
+
58
+ function _default(plugin, more = {}) {
59
+ const instructions = plugin.instructions;
60
+ instructions.register('prompt', _prompt.default);
61
+ instructions.register('calculation', _calculation.default);
62
+ instructions.register('condition', _condition.default);
63
+ instructions.register('parallel', _parallel.default);
64
+ instructions.register('query', _query.default);
65
+ instructions.register('create', _create.default);
66
+ instructions.register('update', _update.default);
67
+ instructions.register('destroy', _destroy.default);
68
+ instructions.register('delay', new ((0, _utils().requireModule)(_path().default.join(__dirname, 'delay')))(plugin));
69
+
70
+ for (var _i = 0, _Object$entries = Object.entries(more); _i < _Object$entries.length; _i++) {
71
+ const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
72
+ name = _Object$entries$_i[0],
73
+ instruction = _Object$entries$_i[1];
74
+
75
+ instructions.register(name, typeof instruction === 'function' ? new instruction(plugin) : instruction);
76
+ }
77
+ }
@@ -1,13 +1,13 @@
1
- import ExecutionModel from "../models/Execution";
2
1
  import FlowNodeModel from "../models/FlowNode";
3
2
  import JobModel from "../models/Job";
3
+ import Processor from "../Processor";
4
4
  export declare const PARALLEL_MODE: {
5
5
  readonly ALL: "all";
6
6
  readonly ANY: "any";
7
7
  readonly RACE: "race";
8
8
  };
9
9
  declare const _default: {
10
- run(this: FlowNodeModel, prevJob: JobModel, execution: ExecutionModel): Promise<any>;
11
- resume(this: any, branchJob: any, execution: ExecutionModel): Promise<any>;
10
+ run(node: FlowNodeModel, prevJob: JobModel, processor: Processor): Promise<any>;
11
+ resume(node: FlowNodeModel, branchJob: any, processor: Processor): Promise<any>;
12
12
  };
13
13
  export default _default;
@@ -40,34 +40,30 @@ const StatusGetters = {
40
40
 
41
41
  };
42
42
  var _default = {
43
- run(prevJob, execution) {
44
- var _this = this;
45
-
43
+ run(node, prevJob, processor) {
46
44
  return _asyncToGenerator(function* () {
47
45
  var _prevJob$id;
48
46
 
49
- const branches = execution.nodes.filter(item => item.upstream === _this && item.branchIndex !== null).sort((a, b) => a.branchIndex - b.branchIndex);
50
- const job = yield execution.saveJob({
47
+ const branches = processor.nodes.filter(item => item.upstream === node && item.branchIndex !== null).sort((a, b) => a.branchIndex - b.branchIndex);
48
+ const job = yield processor.saveJob({
51
49
  status: _constants.JOB_STATUS.PENDING,
52
50
  result: Array(branches.length).fill(null),
53
- nodeId: _this.id,
51
+ nodeId: node.id,
54
52
  upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
55
53
  }); // NOTE:
56
54
  // use `reduce` but not `Promise.all` here to avoid racing manupulating db.
57
55
  // for users, this is almost equivalent to `Promise.all`,
58
56
  // because of the delay is not significant sensible.
59
- // another better aspect of this is, it could handle sequenced branches in future.
57
+ // another benifit of this is, it could handle sequenced branches in future.
60
58
 
61
- yield branches.reduce((promise, branch) => promise.then(() => execution.run(branch, job)), Promise.resolve());
62
- return execution.end(_this, job);
59
+ yield branches.reduce((promise, branch) => promise.then(() => processor.run(branch, job)), Promise.resolve());
60
+ return processor.end(node, job);
63
61
  })();
64
62
  },
65
63
 
66
- resume(branchJob, execution) {
67
- var _this2 = this;
68
-
64
+ resume(node, branchJob, processor) {
69
65
  return _asyncToGenerator(function* () {
70
- const job = execution.findBranchParentJob(branchJob, _this2);
66
+ const job = processor.findBranchParentJob(branchJob, node);
71
67
  const result = job.result,
72
68
  status = job.status; // if parallel has been done (resolved / rejected), do not care newly executed branch jobs.
73
69
 
@@ -76,12 +72,12 @@ var _default = {
76
72
  } // find the index of the node which start the branch
77
73
 
78
74
 
79
- const jobNode = execution.nodesMap.get(branchJob.nodeId);
75
+ const jobNode = processor.nodesMap.get(branchJob.nodeId);
80
76
 
81
- const _execution$findBranch = execution.findBranchStartNode(jobNode),
82
- branchIndex = _execution$findBranch.branchIndex;
77
+ const _processor$findBranch = processor.findBranchStartNode(jobNode),
78
+ branchIndex = _processor$findBranch.branchIndex;
83
79
 
84
- const _ref = _this2.config || {},
80
+ const _ref = node.config || {},
85
81
  _ref$mode = _ref.mode,
86
82
  mode = _ref$mode === void 0 ? PARALLEL_MODE.ALL : _ref$mode;
87
83
 
@@ -93,9 +89,9 @@ var _default = {
93
89
 
94
90
  if (job.status === _constants.JOB_STATUS.PENDING) {
95
91
  yield job.save({
96
- transaction: execution.tx
92
+ transaction: processor.transaction
97
93
  });
98
- return execution.end(_this2, job);
94
+ return processor.end(node, job);
99
95
  }
100
96
 
101
97
  return job;
@@ -1,7 +1,7 @@
1
1
  declare const _default: {
2
- run(this: any, input: any, execution: any): {
2
+ run(node: any, input: any, processor: any): {
3
3
  status: number;
4
4
  };
5
- resume(this: any, job: any, execution: any): any;
5
+ resume(node: any, job: any, processor: any): any;
6
6
  };
7
7
  export default _default;
@@ -8,13 +8,13 @@ exports.default = void 0;
8
8
  var _constants = require("../constants");
9
9
 
10
10
  var _default = {
11
- run(input, execution) {
11
+ run(node, input, processor) {
12
12
  return {
13
13
  status: _constants.JOB_STATUS.PENDING
14
14
  };
15
15
  },
16
16
 
17
- resume(job, execution) {
17
+ resume(node, job, processor) {
18
18
  job.set('status', _constants.JOB_STATUS.RESOLVED);
19
19
  return job;
20
20
  }
@@ -1,6 +1,7 @@
1
1
  import FlowNodeModel from "../models/FlowNode";
2
+ import Processor from "../Processor";
2
3
  declare const _default: {
3
- run(this: FlowNodeModel, input: any, execution: any): Promise<{
4
+ run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
4
5
  result: any;
5
6
  status: number;
6
7
  }>;
@@ -18,21 +18,17 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
18
18
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
19
19
 
20
20
  var _default = {
21
- run(input, execution) {
22
- var _this = this;
23
-
21
+ run(node, input, processor) {
24
22
  return _asyncToGenerator(function* () {
25
- const _this$config = _this.config,
26
- collection = _this$config.collection,
27
- multiple = _this$config.multiple,
28
- _this$config$params = _this$config.params,
29
- params = _this$config$params === void 0 ? {} : _this$config$params;
30
-
31
- const repo = _this.constructor.database.getRepository(collection);
32
-
33
- const options = execution.getParsedValue(params);
23
+ const _node$config = node.config,
24
+ collection = _node$config.collection,
25
+ multiple = _node$config.multiple,
26
+ _node$config$params = _node$config.params,
27
+ params = _node$config$params === void 0 ? {} : _node$config$params;
28
+ const repo = node.constructor.database.getRepository(collection);
29
+ const options = processor.getParsedValue(params);
34
30
  const result = yield (multiple ? repo.find : repo.findOne).call(repo, _objectSpread(_objectSpread({}, options), {}, {
35
- transaction: execution.tx
31
+ transaction: processor.transaction
36
32
  })); // NOTE: `toJSON()` to avoid getting undefined value from Proxied model instance (#380)
37
33
  // e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
38
34
  // so the properties can not be get by json-templates(object-path)
@@ -1,7 +1,7 @@
1
- import ExecutionModel from "../models/Execution";
2
1
  import FlowNodeModel from "../models/FlowNode";
2
+ import Processor from "../Processor";
3
3
  declare const _default: {
4
- run(this: FlowNodeModel, input: any, execution: ExecutionModel): Promise<{
4
+ run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
5
5
  result: import("@nocobase/database").Model<any, any> | import("@nocobase/database").Model<any, any>[];
6
6
  status: number;
7
7
  }>;
@@ -18,22 +18,18 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
18
18
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
19
19
 
20
20
  var _default = {
21
- run(input, execution) {
22
- var _this = this;
23
-
21
+ run(node, input, processor) {
24
22
  return _asyncToGenerator(function* () {
25
- const _this$config = _this.config,
26
- collection = _this$config.collection,
27
- _this$config$multiple = _this$config.multiple,
28
- multiple = _this$config$multiple === void 0 ? false : _this$config$multiple,
29
- _this$config$params = _this$config.params,
30
- params = _this$config$params === void 0 ? {} : _this$config$params;
31
-
32
- const repo = _this.constructor.database.getRepository(collection);
33
-
34
- const options = execution.getParsedValue(params);
23
+ const _node$config = node.config,
24
+ collection = _node$config.collection,
25
+ _node$config$multiple = _node$config.multiple,
26
+ multiple = _node$config$multiple === void 0 ? false : _node$config$multiple,
27
+ _node$config$params = _node$config.params,
28
+ params = _node$config$params === void 0 ? {} : _node$config$params;
29
+ const repo = node.constructor.database.getRepository(collection);
30
+ const options = processor.getParsedValue(params);
35
31
  const result = yield repo.update(_objectSpread(_objectSpread({}, options), {}, {
36
- transaction: execution.tx
32
+ transaction: processor.transaction
37
33
  }));
38
34
  return {
39
35
  result: multiple ? result : result[0] || null,
@@ -1,11 +1,7 @@
1
1
  import { Database, Model } from '@nocobase/database';
2
- import { BelongsToGetAssociationMixin, HasManyGetAssociationsMixin, Transaction } from 'sequelize';
2
+ import { BelongsToGetAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';
3
3
  import WorkflowModel from './Workflow';
4
- import FlowNodeModel from './FlowNode';
5
4
  import JobModel from './Job';
6
- export interface ExecutionOptions {
7
- transaction?: Transaction;
8
- }
9
5
  export default class ExecutionModel extends Model {
10
6
  static readonly database: Database;
11
7
  id: number;
@@ -16,36 +12,9 @@ export default class ExecutionModel extends Model {
16
12
  transaction: string;
17
13
  createdAt: Date;
18
14
  updatedAt: Date;
15
+ key: string;
19
16
  workflow?: WorkflowModel;
20
17
  getWorkflow: BelongsToGetAssociationMixin<WorkflowModel>;
21
18
  jobs?: JobModel[];
22
19
  getJobs: HasManyGetAssociationsMixin<JobModel>;
23
- options: ExecutionOptions;
24
- tx: Transaction;
25
- nodes: Array<FlowNodeModel>;
26
- nodesMap: Map<number, FlowNodeModel>;
27
- jobsMap: Map<number, JobModel>;
28
- jobsMapByNodeId: {
29
- [key: number]: any;
30
- };
31
- static StatusMap: {
32
- [x: number]: number;
33
- };
34
- makeNodes(nodes?: any[]): void;
35
- makeJobs(jobs: Array<JobModel>): void;
36
- getTransaction(): Promise<Transaction>;
37
- prepare(options: any, commit?: boolean): Promise<void>;
38
- start(options: ExecutionOptions): Promise<void>;
39
- resume(job: JobModel, options: ExecutionOptions): Promise<void>;
40
- private commit;
41
- private exec;
42
- run(node: any, input?: any): any;
43
- end(node: any, job: any): any;
44
- recall(node: any, job: any): any;
45
- exit(job: JobModel | null): Promise<any>;
46
- saveJob(payload: any): Promise<JobModel>;
47
- findBranchStartNode(node: FlowNodeModel): FlowNodeModel | null;
48
- findBranchParentNode(node: FlowNodeModel): FlowNodeModel | null;
49
- findBranchParentJob(job: JobModel, node: FlowNodeModel): JobModel | null;
50
- getParsedValue(value: any, node?: any): any;
51
20
  }