@nocobase/plugin-workflow 0.7.0-alpha.56 → 0.7.0-alpha.59

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.
@@ -1 +1,3 @@
1
- export default function (app: any): void;
1
+ export default function ({ app }: {
2
+ app: any;
3
+ }): void;
@@ -25,7 +25,9 @@ function make(name, mod) {
25
25
  }), {});
26
26
  }
27
27
 
28
- function _default(app) {
28
+ function _default({
29
+ app
30
+ }) {
29
31
  app.actions(_objectSpread(_objectSpread(_objectSpread({}, make('workflows', workflows)), make('workflows.nodes', {
30
32
  create: nodes.create,
31
33
  destroy: nodes.destroy
@@ -12,57 +12,49 @@ var _default = {
12
12
  name: 'key',
13
13
  type: 'uid'
14
14
  }, {
15
- interface: 'string',
16
15
  type: 'string',
17
16
  name: 'title',
18
17
  title: '工作流名称',
19
18
  required: true
20
19
  }, {
21
- interface: 'boolean',
22
20
  type: 'boolean',
23
21
  name: 'enabled',
24
22
  title: '启用',
25
23
  defaultValue: false
26
24
  }, {
27
- interface: 'textarea',
28
25
  type: 'text',
29
26
  name: 'description',
30
27
  title: '描述'
31
28
  }, {
32
- interface: 'select',
33
29
  type: 'string',
34
30
  title: '触发方式',
35
31
  name: 'type',
36
32
  required: true
37
33
  }, {
38
- interface: 'json',
39
34
  type: 'jsonb',
40
35
  title: '触发配置',
41
36
  name: 'config',
42
37
  required: true,
43
38
  defaultValue: {}
44
39
  }, {
45
- interface: 'boolean',
46
40
  type: 'boolean',
47
41
  title: '使用事务',
48
42
  name: 'useTransaction',
49
43
  defaultValue: true
50
44
  }, {
51
- interface: 'linkTo',
52
45
  type: 'hasMany',
53
46
  name: 'nodes',
54
47
  target: 'flow_nodes',
55
48
  title: '流程节点'
56
49
  }, {
57
- interface: 'linkTo',
58
50
  type: 'hasMany',
59
51
  name: 'executions',
60
52
  target: 'executions',
61
53
  title: '触发执行'
62
54
  }, {
63
- type: 'boolean',
55
+ type: 'integer',
64
56
  name: 'executed',
65
- defaultValue: false
57
+ defaultValue: 0
66
58
  }, {
67
59
  type: 'boolean',
68
60
  name: 'current',
@@ -32,14 +32,13 @@ var _default = {
32
32
 
33
33
  const options = execution.getParsedValue(params);
34
34
  const result = yield (multiple ? repo.find : repo.findOne).call(repo, _objectSpread(_objectSpread({}, options), {}, {
35
- // NOTE: `raw` to avoid getting undefined value from Proxied model instance (#380)
36
- // e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
37
- // so the properties can not be get by json-templates(object-path)
38
- raw: true,
39
35
  transaction: execution.tx
40
- }));
36
+ })); // NOTE: `toJSON()` to avoid getting undefined value from Proxied model instance (#380)
37
+ // e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
38
+ // so the properties can not be get by json-templates(object-path)
39
+
41
40
  return {
42
- result,
41
+ result: multiple ? result.map(item => item.toJSON()) : result === null || result === void 0 ? void 0 : result.toJSON(),
43
42
  status: _constants.JOB_STATUS.RESOLVED
44
43
  };
45
44
  })();
@@ -11,7 +11,7 @@ export default class WorkflowModel extends Model {
11
11
  type: string;
12
12
  config: any;
13
13
  useTransaction: boolean;
14
- executed: boolean;
14
+ executed: number;
15
15
  createdAt: Date;
16
16
  updatedAt: Date;
17
17
  nodes: FlowNodeModel[];
@@ -21,9 +21,6 @@ export default class WorkflowModel extends Model {
21
21
  countExecutions: HasManyCountAssociationsMixin;
22
22
  getExecutions: HasManyGetAssociationsMixin<ExecutionModel>;
23
23
  createExecution: HasManyCreateAssociationMixin<ExecutionModel>;
24
- static mount(): Promise<void>;
25
- getHookId(): string;
26
24
  getTransaction(options: any): any;
27
- toggle(enable?: boolean): Promise<void>;
28
- trigger(context: Object, options: any): Promise<ExecutionModel>;
25
+ trigger: (context: Object, options?: {}) => Promise<ExecutionModel>;
29
26
  }
@@ -15,122 +15,84 @@ function _database() {
15
15
  return data;
16
16
  }
17
17
 
18
- var _triggers = _interopRequireDefault(require("../triggers"));
19
-
20
18
  var _constants = require("../constants");
21
19
 
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
20
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
25
21
 
26
22
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
27
23
 
28
24
  class WorkflowModel extends _database().Model {
29
- static mount() {
30
- var _this = this;
25
+ constructor(...args) {
26
+ var _this;
31
27
 
32
- return _asyncToGenerator(function* () {
33
- const collection = _this.database.getCollection('workflows');
28
+ super(...args);
29
+ _this = this;
34
30
 
35
- const workflows = yield collection.repository.find({
36
- filter: {
37
- enabled: true
31
+ this.trigger = /*#__PURE__*/function () {
32
+ var _ref = _asyncToGenerator(function* (context, options = {}) {
33
+ // `null` means not to trigger
34
+ if (context === null) {
35
+ return;
38
36
  }
39
- });
40
- workflows.forEach(workflow => {
41
- workflow.toggle();
42
- });
43
-
44
- _this.addHook('afterCreate', model => model.toggle());
45
37
 
46
- _this.addHook('afterUpdate', model => model.toggle());
38
+ const transaction = yield _this.getTransaction(options);
47
39
 
48
- _this.addHook('afterDestroy', model => model.toggle(false));
49
- })();
50
- }
51
-
52
- getHookId() {
53
- return `workflow-${this.get('id')}`;
54
- }
55
-
56
- getTransaction(options) {
57
- if (!this.useTransaction) {
58
- return undefined;
59
- }
60
-
61
- return options.transaction && !options.transaction.finished ? options.transaction : this.constructor.database.sequelize.transaction();
62
- }
63
-
64
- toggle(enable) {
65
- var _this2 = this;
66
-
67
- return _asyncToGenerator(function* () {
68
- const type = _this2.get('type');
69
-
70
- const _triggers$get = _triggers.default.get(type),
71
- on = _triggers$get.on,
72
- off = _triggers$get.off;
73
-
74
- if (typeof enable !== 'undefined' ? enable : _this2.get('enabled')) {
75
- on.call(_this2, _this2.trigger.bind(_this2));
76
- } else {
77
- off.call(_this2);
78
- }
79
- })();
80
- }
40
+ if (_this.useTransaction) {
41
+ const existed = yield _this.countExecutions({
42
+ where: {
43
+ transaction: transaction.id
44
+ },
45
+ transaction
46
+ });
81
47
 
82
- trigger(context, options) {
83
- var _this3 = this;
84
-
85
- return _asyncToGenerator(function* () {
86
- // `null` means not to trigger
87
- if (context === null) {
88
- return;
89
- }
90
-
91
- const transaction = yield _this3.getTransaction(options);
48
+ if (existed) {
49
+ console.warn(`workflow ${_this.id} has already been triggered in same execution (${transaction.id}), and newly triggering will be skipped.`);
50
+ return;
51
+ }
52
+ }
92
53
 
93
- if (_this3.useTransaction) {
94
- const existed = yield _this3.countExecutions({
95
- where: {
96
- transaction: transaction.id
97
- },
54
+ const execution = yield _this.createExecution({
55
+ context,
56
+ status: _constants.EXECUTION_STATUS.STARTED,
57
+ useTransaction: _this.useTransaction,
58
+ transaction: transaction.id
59
+ }, {
60
+ transaction
61
+ });
62
+ const executed = yield _this.countExecutions({
98
63
  transaction
64
+ }); // NOTE: not to trigger afterUpdate hook here
65
+
66
+ yield _this.update({
67
+ executed
68
+ }, {
69
+ transaction,
70
+ hooks: false
99
71
  });
72
+ execution.workflow = _this;
73
+ yield execution.start({
74
+ transaction
75
+ }); // @ts-ignore
100
76
 
101
- if (existed) {
102
- console.warn(`workflow ${_this3.id} has already been triggered in same execution (${transaction.id}), and newly triggering will be skipped.`);
103
- return;
77
+ if (transaction && (!options.transaction || options.transaction.finished)) {
78
+ yield transaction.commit();
104
79
  }
105
- }
106
-
107
- const execution = yield _this3.createExecution({
108
- context,
109
- status: _constants.EXECUTION_STATUS.STARTED,
110
- useTransaction: _this3.useTransaction,
111
- transaction: transaction.id
112
- }, {
113
- transaction
114
- });
115
- execution.workflow = _this3;
116
- yield execution.start({
117
- transaction
80
+
81
+ return execution;
118
82
  });
119
83
 
120
- if (!_this3.executed) {
121
- yield _this3.update({
122
- executed: true
123
- }, {
124
- transaction
125
- });
126
- }
84
+ return function (_x) {
85
+ return _ref.apply(this, arguments);
86
+ };
87
+ }();
88
+ }
127
89
 
128
- if (transaction && (!options.transaction || options.transaction.finished)) {
129
- yield transaction.commit();
130
- }
90
+ getTransaction(options) {
91
+ if (!this.useTransaction) {
92
+ return null;
93
+ }
131
94
 
132
- return execution;
133
- })();
95
+ return options.transaction && !options.transaction.finished ? options.transaction : this.constructor.database.sequelize.transaction();
134
96
  }
135
97
 
136
98
  }
package/lib/server.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { Plugin } from '@nocobase/server';
2
- export default class WorkflowPlugin extends Plugin {
3
- load(options?: {}): Promise<void>;
2
+ import WorkflowModel from './models/Workflow';
3
+ import { Trigger } from './triggers';
4
+ import { Registry } from '@nocobase/utils';
5
+ export default class extends Plugin {
6
+ triggers: Registry<Trigger>;
4
7
  getName(): string;
8
+ load(options?: {}): Promise<void>;
9
+ toggle(workflow: WorkflowModel, enable?: boolean): Promise<void>;
5
10
  }
package/lib/server.js CHANGED
@@ -31,13 +31,34 @@ var _Execution = _interopRequireDefault(require("./models/Execution"));
31
31
 
32
32
  var _actions = _interopRequireDefault(require("./actions"));
33
33
 
34
+ var _triggers = _interopRequireDefault(require("./triggers"));
35
+
36
+ function _utils() {
37
+ const data = require("@nocobase/utils");
38
+
39
+ _utils = function _utils() {
40
+ return data;
41
+ };
42
+
43
+ return data;
44
+ }
45
+
34
46
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
47
 
36
48
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
37
49
 
38
50
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
39
51
 
40
- class WorkflowPlugin extends _server().Plugin {
52
+ class _default extends _server().Plugin {
53
+ constructor(...args) {
54
+ super(...args);
55
+ this.triggers = new (_utils().Registry)();
56
+ }
57
+
58
+ getName() {
59
+ return this.getPackageName(__dirname);
60
+ }
61
+
41
62
  load(options = {}) {
42
63
  var _this = this;
43
64
 
@@ -50,46 +71,47 @@ class WorkflowPlugin extends _server().Plugin {
50
71
  yield db.import({
51
72
  directory: _path().default.resolve(__dirname, 'collections')
52
73
  });
53
- (0, _actions.default)(_this.app); // [Life Cycle]:
74
+ (0, _actions.default)(_this);
75
+ (0, _triggers.default)(_this); // [Life Cycle]:
54
76
  // * load all workflows in db
55
77
  // * add all hooks for enabled workflows
56
78
  // * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
57
79
 
58
80
  _this.app.on('beforeStart', /*#__PURE__*/_asyncToGenerator(function* () {
59
- const _db$getCollection = db.getCollection('workflows'),
60
- model = _db$getCollection.model;
61
-
62
- yield model.mount();
81
+ const collection = db.getCollection('workflows');
82
+ const workflows = yield collection.repository.find({
83
+ filter: {
84
+ enabled: true
85
+ }
86
+ });
87
+ workflows.forEach(workflow => {
88
+ _this.toggle(workflow);
89
+ });
90
+ db.on('workflows.afterCreate', model => _this.toggle(model));
91
+ db.on('workflows.afterUpdate', model => _this.toggle(model));
92
+ db.on('workflows.afterDestroy', model => _this.toggle(model, false));
63
93
  })); // [Life Cycle]: initialize all necessary seed data
64
-
65
-
66
- _this.app.on('db.init', /*#__PURE__*/_asyncToGenerator(function* () {})); // const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);
67
- // Automation.addHook('afterCreate', async (model: AutomationModel) => {
68
- // model.get('enabled') && await model.loadJobs();
69
- // });
70
- // Automation.addHook('afterUpdate', async (model: AutomationModel) => {
71
- // if (!model.changed('enabled' as any)) {
72
- // return;
73
- // }
74
- // model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();
75
- // });
76
- // Automation.addHook('beforeDestroy', async (model: AutomationModel) => {
77
- // await model.cancelJobs();
78
- // });
79
- // AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {
80
- // await model.bootstrap();
81
- // });
82
- // AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {
83
- // await model.cancel();
84
- // });
94
+ // this.app.on('db.init', async () => {});
85
95
 
86
96
  })();
87
97
  }
88
98
 
89
- getName() {
90
- return this.getPackageName(__dirname);
99
+ toggle(workflow, enable) {
100
+ var _this2 = this;
101
+
102
+ return _asyncToGenerator(function* () {
103
+ const type = workflow.get('type');
104
+
105
+ const trigger = _this2.triggers.get(type);
106
+
107
+ if (typeof enable !== 'undefined' ? enable : workflow.get('enabled')) {
108
+ yield trigger.on(workflow);
109
+ } else {
110
+ yield trigger.off(workflow);
111
+ }
112
+ })();
91
113
  }
92
114
 
93
115
  }
94
116
 
95
- exports.default = WorkflowPlugin;
117
+ exports.default = _default;
@@ -1,12 +1,16 @@
1
+ import { Trigger } from ".";
1
2
  import WorkflowModel from "../models/Workflow";
2
- export interface ModelChangeTriggerConfig {
3
+ export interface CollectionChangeTriggerConfig {
3
4
  collection: string;
4
5
  mode: number;
5
6
  condition: any;
6
7
  }
7
- declare const _default: {
8
- name: string;
9
- on(this: WorkflowModel, callback: Function): void;
10
- off(this: WorkflowModel): void;
11
- };
12
- export default _default;
8
+ export default class CollectionTrigger implements Trigger {
9
+ db: any;
10
+ events: Map<any, any>;
11
+ constructor({ app }: {
12
+ app: any;
13
+ });
14
+ on(workflow: WorkflowModel): void;
15
+ off(workflow: WorkflowModel): void;
16
+ }
@@ -19,46 +19,67 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
19
19
 
20
20
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
21
 
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
+
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
+
26
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
+
22
28
  const MODE_BITMAP = {
23
29
  CREATE: 1,
24
30
  UPDATE: 2,
25
31
  DESTROY: 4
26
32
  };
27
33
  const MODE_BITMAP_EVENTS = new Map();
28
- MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');
29
- MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');
30
- MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy'); // async function, should return promise
34
+ MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreateWithAssociations');
35
+ MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdateWithAssociations');
36
+ MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');
31
37
 
32
- function bindHandler(callback) {
38
+ function getHookId(workflow, type) {
39
+ return `${type}#${workflow.id}`;
40
+ } // async function, should return promise
41
+
42
+
43
+ function handler(data, options) {
33
44
  const _this$config = this.config,
34
45
  condition = _this$config.condition,
35
- changed = _this$config.changed;
36
- return (data, options) => {
37
- // NOTE: if no configured fields changed, do not trigger
38
- if (changed && changed.length && changed.every(name => !data.changed(name))) {
39
- return;
40
- } // NOTE: if no configured condition match, do not trigger
46
+ changed = _this$config.changed; // NOTE: if no configured fields changed, do not trigger
41
47
 
48
+ if (changed && changed.length && changed.every(name => !data.changed(name))) {
49
+ return;
50
+ } // NOTE: if no configured condition match, do not trigger
42
51
 
43
- if (condition && condition.$and.length) {// TODO: check all conditions in condition against data
44
- // const calculation = toCalculation(condition);
45
- }
46
52
 
47
- return callback({
48
- data: data.get()
49
- }, options);
50
- };
53
+ if (condition && condition.$and.length) {// TODO: check all conditions in condition against data
54
+ // const calculation = toCalculation(condition);
55
+ }
56
+
57
+ return this.trigger({
58
+ data: data.get()
59
+ }, options);
51
60
  }
52
61
 
53
- var _default = {
54
- name: 'collection',
62
+ class CollectionTrigger {
63
+ constructor({
64
+ app
65
+ }) {
66
+ this.db = void 0;
67
+ this.events = new Map();
68
+ this.db = app.db;
69
+ }
70
+
71
+ on(workflow) {
72
+ // NOTE: remove previous listener if config updated
73
+ const prev = workflow.previous();
74
+
75
+ if (prev.config) {
76
+ this.off(_objectSpread(_objectSpread({}, workflow.get()), prev));
77
+ }
55
78
 
56
- on(callback) {
57
- const database = this.constructor.database;
58
- const _this$config2 = this.config,
59
- collection = _this$config2.collection,
60
- mode = _this$config2.mode;
61
- const Collection = database.getCollection(collection);
79
+ const _workflow$config = workflow.config,
80
+ collection = _workflow$config.collection,
81
+ mode = _workflow$config.mode;
82
+ const Collection = this.db.getCollection(collection);
62
83
 
63
84
  if (!Collection) {
64
85
  return;
@@ -71,16 +92,24 @@ var _default = {
71
92
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
72
93
  let _step$value = _slicedToArray(_step.value, 2),
73
94
  key = _step$value[0],
74
- event = _step$value[1];
95
+ type = _step$value[1];
75
96
 
76
- if (mode & key) {
77
- var _Collection$model$opt;
97
+ const event = `${collection}.${type}`;
98
+ const name = getHookId(workflow, event);
78
99
 
79
- if (!((_Collection$model$opt = Collection.model.options.hooks[event]) === null || _Collection$model$opt === void 0 ? void 0 : _Collection$model$opt.find(item => item.name && item.name === this.getHookId()))) {
80
- Collection.model.addHook(event, this.getHookId(), bindHandler.call(this, callback));
100
+ if (mode & key) {
101
+ if (!this.events.has(name)) {
102
+ const listener = handler.bind(workflow);
103
+ this.events.set(name, listener);
104
+ this.db.on(event, listener);
81
105
  }
82
106
  } else {
83
- Collection.model.removeHook(event, this.getHookId());
107
+ const listener = this.events.get(name);
108
+
109
+ if (listener) {
110
+ this.db.off(event, listener);
111
+ this.events.delete(name);
112
+ }
84
113
  }
85
114
  }
86
115
  } catch (err) {
@@ -88,14 +117,13 @@ var _default = {
88
117
  } finally {
89
118
  _iterator.f();
90
119
  }
91
- },
120
+ }
92
121
 
93
- off() {
94
- const database = this.constructor.database;
95
- const _this$config3 = this.config,
96
- collection = _this$config3.collection,
97
- mode = _this$config3.mode;
98
- const Collection = database.getCollection(collection);
122
+ off(workflow) {
123
+ const _workflow$config2 = workflow.config,
124
+ collection = _workflow$config2.collection,
125
+ mode = _workflow$config2.mode;
126
+ const Collection = this.db.getCollection(collection);
99
127
 
100
128
  if (!Collection) {
101
129
  return;
@@ -108,10 +136,18 @@ var _default = {
108
136
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
109
137
  let _step2$value = _slicedToArray(_step2.value, 2),
110
138
  key = _step2$value[0],
111
- event = _step2$value[1];
139
+ type = _step2$value[1];
140
+
141
+ const event = `${collection}.${type}`;
142
+ const name = getHookId(workflow, event);
112
143
 
113
144
  if (mode & key) {
114
- Collection.model.removeHook(event, this.getHookId());
145
+ const listener = this.events.get(name);
146
+
147
+ if (listener) {
148
+ this.db.off(event, listener);
149
+ this.events.delete(name);
150
+ }
115
151
  }
116
152
  }
117
153
  } catch (err) {
@@ -121,5 +157,6 @@ var _default = {
121
157
  }
122
158
  }
123
159
 
124
- };
125
- exports.default = _default;
160
+ }
161
+
162
+ exports.default = CollectionTrigger;
@@ -1,9 +1,6 @@
1
- import { Registry } from '@nocobase/utils';
2
1
  import WorkflowModel from '../models/Workflow';
3
2
  export interface Trigger {
4
- name: string;
5
- on(this: WorkflowModel, callback: Function): void;
6
- off(this: WorkflowModel): void;
3
+ on(workflow: WorkflowModel): void;
4
+ off(workflow: WorkflowModel): void;
7
5
  }
8
- export declare const triggers: Registry<Trigger>;
9
- export default triggers;
6
+ export default function (plugin: any): void;
@@ -3,24 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.triggers = exports.default = void 0;
7
-
8
- function _utils() {
9
- const data = require("@nocobase/utils");
10
-
11
- _utils = function _utils() {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
6
+ exports.default = _default;
17
7
 
18
8
  var _collection = _interopRequireDefault(require("./collection"));
19
9
 
20
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
11
 
22
- const triggers = new (_utils().Registry)();
23
- exports.triggers = triggers;
24
- var _default = triggers;
25
- exports.default = _default;
26
- triggers.register(_collection.default.name, _collection.default);
12
+ function _default(plugin) {
13
+ const triggers = plugin.triggers;
14
+ triggers.register('collection', new _collection.default(plugin)); // triggers.register('schedule', new Schedule(plugin));
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-workflow",
3
- "version": "0.7.0-alpha.56",
3
+ "version": "0.7.0-alpha.59",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -10,14 +10,14 @@
10
10
  }
11
11
  ],
12
12
  "dependencies": {
13
- "@nocobase/actions": "0.7.0-alpha.56",
14
- "@nocobase/database": "0.7.0-alpha.56",
15
- "@nocobase/server": "0.7.0-alpha.56",
16
- "@nocobase/utils": "0.7.0-alpha.56",
13
+ "@nocobase/actions": "0.7.0-alpha.59",
14
+ "@nocobase/database": "0.7.0-alpha.59",
15
+ "@nocobase/server": "0.7.0-alpha.59",
16
+ "@nocobase/utils": "0.7.0-alpha.59",
17
17
  "json-templates": "^4.2.0"
18
18
  },
19
19
  "devDependencies": {
20
- "@nocobase/test": "0.7.0-alpha.56"
20
+ "@nocobase/test": "0.7.0-alpha.59"
21
21
  },
22
- "gitHead": "9a8c05e8fb26029f1d1ba68408a8bddac0e67a76"
22
+ "gitHead": "c90e5aee4c8257a3ab7ff492e69cb568cccff8b5"
23
23
  }