@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.
Files changed (159) 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/index.d.ts +3 -1
  6. package/lib/actions/index.js +33 -26
  7. package/{esm/actions/flow_nodes.d.ts → lib/actions/nodes.d.ts} +1 -0
  8. package/lib/actions/nodes.js +321 -0
  9. package/lib/actions/workflows.d.ts +2 -0
  10. package/lib/actions/workflows.js +197 -0
  11. package/lib/calculators/index.d.ts +2 -2
  12. package/lib/calculators/index.js +144 -92
  13. package/lib/collections/executions.js +32 -38
  14. package/lib/collections/flow_nodes.js +60 -72
  15. package/lib/collections/jobs.js +26 -47
  16. package/lib/collections/workflows.d.ts +1 -2
  17. package/lib/collections/workflows.js +70 -63
  18. package/lib/constants.js +22 -17
  19. package/lib/index.d.ts +4 -3
  20. package/lib/index.js +85 -22
  21. package/lib/instructions/calculation.d.ts +1 -1
  22. package/lib/instructions/calculation.js +32 -29
  23. package/lib/instructions/condition.d.ts +2 -2
  24. package/lib/instructions/condition.js +91 -88
  25. package/lib/instructions/create.d.ts +2 -2
  26. package/lib/instructions/create.js +39 -25
  27. package/lib/instructions/delay.d.ts +14 -0
  28. package/lib/instructions/delay.js +138 -0
  29. package/lib/instructions/destroy.d.ts +1 -1
  30. package/lib/instructions/destroy.js +38 -25
  31. package/lib/instructions/index.d.ts +11 -8
  32. package/lib/instructions/index.js +76 -25
  33. package/lib/instructions/parallel.d.ts +3 -3
  34. package/lib/instructions/parallel.js +95 -84
  35. package/lib/instructions/prompt.d.ts +2 -2
  36. package/lib/instructions/prompt.js +21 -13
  37. package/lib/instructions/query.d.ts +2 -1
  38. package/lib/instructions/query.js +42 -25
  39. package/lib/instructions/update.d.ts +2 -1
  40. package/lib/instructions/update.js +40 -25
  41. package/lib/models/Execution.d.ts +3 -33
  42. package/lib/models/Execution.js +18 -254
  43. package/lib/models/FlowNode.js +18 -5
  44. package/lib/models/Job.js +18 -5
  45. package/lib/models/Workflow.d.ts +5 -6
  46. package/lib/models/Workflow.js +18 -76
  47. package/lib/triggers/collection.d.ts +12 -0
  48. package/lib/triggers/collection.js +184 -0
  49. package/lib/triggers/index.d.ts +11 -7
  50. package/lib/triggers/index.js +64 -11
  51. package/lib/triggers/schedule.d.ts +38 -0
  52. package/lib/triggers/schedule.js +672 -0
  53. package/package.json +8 -12
  54. package/esm/actions/flow_nodes.js +0 -139
  55. package/esm/actions/flow_nodes.js.map +0 -1
  56. package/esm/actions/index.d.ts +0 -1
  57. package/esm/actions/index.js +0 -8
  58. package/esm/actions/index.js.map +0 -1
  59. package/esm/calculators/index.d.ts +0 -38
  60. package/esm/calculators/index.js +0 -128
  61. package/esm/calculators/index.js.map +0 -1
  62. package/esm/collections/executions.d.ts +0 -3
  63. package/esm/collections/executions.js +0 -38
  64. package/esm/collections/executions.js.map +0 -1
  65. package/esm/collections/flow_nodes.d.ts +0 -3
  66. package/esm/collections/flow_nodes.js +0 -72
  67. package/esm/collections/flow_nodes.js.map +0 -1
  68. package/esm/collections/jobs.d.ts +0 -3
  69. package/esm/collections/jobs.js +0 -47
  70. package/esm/collections/jobs.js.map +0 -1
  71. package/esm/collections/workflows.d.ts +0 -3
  72. package/esm/collections/workflows.js +0 -63
  73. package/esm/collections/workflows.js.map +0 -1
  74. package/esm/constants.d.ts +0 -17
  75. package/esm/constants.js +0 -18
  76. package/esm/constants.js.map +0 -1
  77. package/esm/index.d.ts +0 -5
  78. package/esm/index.js +0 -6
  79. package/esm/index.js.map +0 -1
  80. package/esm/instructions/calculation.d.ts +0 -8
  81. package/esm/instructions/calculation.js +0 -55
  82. package/esm/instructions/calculation.js.map +0 -1
  83. package/esm/instructions/condition.d.ts +0 -5
  84. package/esm/instructions/condition.js +0 -99
  85. package/esm/instructions/condition.js.map +0 -1
  86. package/esm/instructions/create.d.ts +0 -8
  87. package/esm/instructions/create.js +0 -25
  88. package/esm/instructions/create.js.map +0 -1
  89. package/esm/instructions/destroy.d.ts +0 -8
  90. package/esm/instructions/destroy.js +0 -25
  91. package/esm/instructions/destroy.js.map +0 -1
  92. package/esm/instructions/index.d.ts +0 -15
  93. package/esm/instructions/index.js +0 -20
  94. package/esm/instructions/index.js.map +0 -1
  95. package/esm/instructions/parallel.d.ts +0 -13
  96. package/esm/instructions/parallel.js +0 -88
  97. package/esm/instructions/parallel.js.map +0 -1
  98. package/esm/instructions/prompt.d.ts +0 -7
  99. package/esm/instructions/prompt.js +0 -13
  100. package/esm/instructions/prompt.js.map +0 -1
  101. package/esm/instructions/query.d.ts +0 -8
  102. package/esm/instructions/query.js +0 -25
  103. package/esm/instructions/query.js.map +0 -1
  104. package/esm/instructions/update.d.ts +0 -8
  105. package/esm/instructions/update.js +0 -25
  106. package/esm/instructions/update.js.map +0 -1
  107. package/esm/models/Execution.d.ts +0 -50
  108. package/esm/models/Execution.js +0 -250
  109. package/esm/models/Execution.js.map +0 -1
  110. package/esm/models/FlowNode.d.ts +0 -17
  111. package/esm/models/FlowNode.js +0 -4
  112. package/esm/models/FlowNode.js.map +0 -1
  113. package/esm/models/Job.d.ts +0 -15
  114. package/esm/models/Job.js +0 -4
  115. package/esm/models/Job.js.map +0 -1
  116. package/esm/models/Workflow.d.ts +0 -27
  117. package/esm/models/Workflow.js +0 -72
  118. package/esm/models/Workflow.js.map +0 -1
  119. package/esm/server.d.ts +0 -5
  120. package/esm/server.js +0 -62
  121. package/esm/server.js.map +0 -1
  122. package/esm/triggers/index.d.ts +0 -9
  123. package/esm/triggers/index.js +0 -6
  124. package/esm/triggers/index.js.map +0 -1
  125. package/esm/triggers/model.d.ts +0 -12
  126. package/esm/triggers/model.js +0 -47
  127. package/esm/triggers/model.js.map +0 -1
  128. package/lib/actions/flow_nodes.d.ts +0 -3
  129. package/lib/actions/flow_nodes.js +0 -163
  130. package/lib/actions/flow_nodes.js.map +0 -1
  131. package/lib/actions/index.js.map +0 -1
  132. package/lib/calculators/index.js.map +0 -1
  133. package/lib/collections/executions.js.map +0 -1
  134. package/lib/collections/flow_nodes.js.map +0 -1
  135. package/lib/collections/jobs.js.map +0 -1
  136. package/lib/collections/workflows.js.map +0 -1
  137. package/lib/constants.js.map +0 -1
  138. package/lib/index.js.map +0 -1
  139. package/lib/instructions/calculation.js.map +0 -1
  140. package/lib/instructions/condition.js.map +0 -1
  141. package/lib/instructions/create.js.map +0 -1
  142. package/lib/instructions/destroy.js.map +0 -1
  143. package/lib/instructions/index.js.map +0 -1
  144. package/lib/instructions/parallel.js.map +0 -1
  145. package/lib/instructions/prompt.js.map +0 -1
  146. package/lib/instructions/query.js.map +0 -1
  147. package/lib/instructions/update.js.map +0 -1
  148. package/lib/models/Execution.js.map +0 -1
  149. package/lib/models/FlowNode.js.map +0 -1
  150. package/lib/models/Job.js.map +0 -1
  151. package/lib/models/Workflow.js.map +0 -1
  152. package/lib/server.d.ts +0 -5
  153. package/lib/server.js +0 -68
  154. package/lib/server.js.map +0 -1
  155. package/lib/triggers/index.js.map +0 -1
  156. package/lib/triggers/model.d.ts +0 -12
  157. package/lib/triggers/model.js +0 -49
  158. package/lib/triggers/model.js.map +0 -1
  159. package/tsconfig.build.json +0 -9
@@ -1,78 +1,20 @@
1
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 database_1 = require("@nocobase/database");
16
- const triggers_1 = __importDefault(require("../triggers"));
17
- const constants_1 = require("../constants");
18
- class WorkflowModel extends database_1.Model {
19
- static mount() {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const collection = this.database.getCollection('workflows');
22
- const workflows = yield collection.repository.find({
23
- filter: { enabled: true },
24
- });
25
- workflows.forEach((workflow) => {
26
- workflow.toggle();
27
- });
28
- this.addHook('afterCreate', (model) => model.toggle());
29
- this.addHook('afterUpdate', (model) => model.toggle());
30
- this.addHook('afterDestroy', (model) => model.toggle(false));
31
- });
32
- }
33
- getHookId() {
34
- return `workflow-${this.get('id')}`;
35
- }
36
- getTransaction(options) {
37
- if (!this.useTransaction) {
38
- return undefined;
39
- }
40
- return options.transaction && !options.transaction.finished
41
- ? options.transaction
42
- : this.constructor.database.sequelize.transaction();
43
- }
44
- toggle(enable) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const type = this.get('type');
47
- const { on, off } = triggers_1.default.get(type);
48
- if (typeof enable !== 'undefined' ? enable : this.get('enabled')) {
49
- on.call(this, this.trigger.bind(this));
50
- }
51
- else {
52
- off.call(this);
53
- }
54
- });
55
- }
56
- trigger(context, options) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- // `null` means not to trigger
59
- if (context === null) {
60
- return;
61
- }
62
- const transaction = yield this.getTransaction(options);
63
- const execution = yield this.createExecution({
64
- context,
65
- status: constants_1.EXECUTION_STATUS.STARTED,
66
- useTransaction: this.useTransaction
67
- }, { transaction });
68
- execution.workflow = this;
69
- yield execution.start({ transaction });
70
- if (transaction && (!options.transaction || options.transaction.finished)) {
71
- yield transaction.commit();
72
- }
73
- return execution;
74
- });
75
- }
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _database() {
9
+ const data = require("@nocobase/database");
10
+
11
+ _database = function _database() {
12
+ return data;
13
+ };
14
+
15
+ return data;
76
16
  }
77
- exports.default = WorkflowModel;
78
- //# sourceMappingURL=Workflow.js.map
17
+
18
+ class WorkflowModel extends _database().Model {}
19
+
20
+ exports.default = WorkflowModel;
@@ -0,0 +1,12 @@
1
+ import { Trigger } from "..";
2
+ import WorkflowModel from "../models/Workflow";
3
+ export interface CollectionChangeTriggerConfig {
4
+ collection: string;
5
+ mode: number;
6
+ condition: any;
7
+ }
8
+ export default class CollectionTrigger extends Trigger {
9
+ events: Map<any, any>;
10
+ on(workflow: WorkflowModel): void;
11
+ off(workflow: WorkflowModel): void;
12
+ }
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _ = require("..");
9
+
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+
12
+ 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."); }
13
+
14
+ 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; }
15
+
16
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
+
18
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
19
+
20
+ 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); }
21
+
22
+ 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; }
23
+
24
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
25
+
26
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
27
+
28
+ const MODE_BITMAP = {
29
+ CREATE: 1,
30
+ UPDATE: 2,
31
+ DESTROY: 4
32
+ };
33
+ const MODE_BITMAP_EVENTS = new Map();
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');
37
+
38
+ function getHookId(workflow, type) {
39
+ return `${type}#${workflow.id}`;
40
+ } // async function, should return promise
41
+
42
+
43
+ function handler(_x, _x2, _x3) {
44
+ return _handler.apply(this, arguments);
45
+ }
46
+
47
+ function _handler() {
48
+ _handler = _asyncToGenerator(function* (workflow, data, options) {
49
+ var _condition$$and;
50
+
51
+ const _workflow$config3 = workflow.config,
52
+ collection = _workflow$config3.collection,
53
+ condition = _workflow$config3.condition,
54
+ changed = _workflow$config3.changed; // NOTE: if no configured fields changed, do not trigger
55
+
56
+ if (changed && changed.length && changed.every(name => !data.changed(name))) {// TODO: temp comment out
57
+ // return;
58
+ } // NOTE: if no configured condition match, do not trigger
59
+
60
+
61
+ if (condition && ((_condition$$and = condition.$and) === null || _condition$$and === void 0 ? void 0 : _condition$$and.length)) {
62
+ // TODO: change to map filter format to calculation format
63
+ // const calculation = toCalculation(condition);
64
+ const _data$constructor$dat = data.constructor.database.getCollection(collection),
65
+ repository = _data$constructor$dat.repository,
66
+ model = _data$constructor$dat.model;
67
+
68
+ const transaction = options.transaction;
69
+ const count = yield repository.count({
70
+ filter: {
71
+ $and: [condition, {
72
+ [model.primaryKeyAttribute]: data[model.primaryKeyAttribute]
73
+ }]
74
+ },
75
+ transaction
76
+ });
77
+
78
+ if (!count) {
79
+ return;
80
+ }
81
+ }
82
+
83
+ return this.plugin.trigger(workflow, {
84
+ data: data.get()
85
+ }, {
86
+ transaction: options.transaction
87
+ });
88
+ });
89
+ return _handler.apply(this, arguments);
90
+ }
91
+
92
+ class CollectionTrigger extends _.Trigger {
93
+ constructor(...args) {
94
+ super(...args);
95
+ this.events = new Map();
96
+ }
97
+
98
+ on(workflow) {
99
+ const db = this.plugin.app.db;
100
+ const _workflow$config = workflow.config,
101
+ collection = _workflow$config.collection,
102
+ mode = _workflow$config.mode;
103
+ const Collection = db.getCollection(collection);
104
+
105
+ if (!Collection) {
106
+ return;
107
+ }
108
+
109
+ var _iterator = _createForOfIteratorHelper(MODE_BITMAP_EVENTS.entries()),
110
+ _step;
111
+
112
+ try {
113
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
114
+ let _step$value = _slicedToArray(_step.value, 2),
115
+ key = _step$value[0],
116
+ type = _step$value[1];
117
+
118
+ const event = `${collection}.${type}`;
119
+ const name = getHookId(workflow, event);
120
+
121
+ if (mode & key) {
122
+ if (!this.events.has(name)) {
123
+ const listener = handler.bind(this, workflow);
124
+ this.events.set(name, listener);
125
+ db.on(event, listener);
126
+ }
127
+ } else {
128
+ const listener = this.events.get(name);
129
+
130
+ if (listener) {
131
+ db.off(event, listener);
132
+ this.events.delete(name);
133
+ }
134
+ }
135
+ }
136
+ } catch (err) {
137
+ _iterator.e(err);
138
+ } finally {
139
+ _iterator.f();
140
+ }
141
+ }
142
+
143
+ off(workflow) {
144
+ const db = this.plugin.app.db;
145
+ const _workflow$config2 = workflow.config,
146
+ collection = _workflow$config2.collection,
147
+ mode = _workflow$config2.mode;
148
+ const Collection = db.getCollection(collection);
149
+
150
+ if (!Collection) {
151
+ return;
152
+ }
153
+
154
+ var _iterator2 = _createForOfIteratorHelper(MODE_BITMAP_EVENTS.entries()),
155
+ _step2;
156
+
157
+ try {
158
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
159
+ let _step2$value = _slicedToArray(_step2.value, 2),
160
+ key = _step2$value[0],
161
+ type = _step2$value[1];
162
+
163
+ const event = `${collection}.${type}`;
164
+ const name = getHookId(workflow, event);
165
+
166
+ if (mode & key) {
167
+ const listener = this.events.get(name);
168
+
169
+ if (listener) {
170
+ db.off(event, listener);
171
+ this.events.delete(name);
172
+ }
173
+ }
174
+ }
175
+ } catch (err) {
176
+ _iterator2.e(err);
177
+ } finally {
178
+ _iterator2.f();
179
+ }
180
+ }
181
+
182
+ }
183
+
184
+ exports.default = CollectionTrigger;
@@ -1,9 +1,13 @@
1
- import { Registry } from '@nocobase/utils';
1
+ import Plugin from '..';
2
2
  import WorkflowModel from '../models/Workflow';
3
- export interface Trigger {
4
- name: string;
5
- on(this: WorkflowModel, callback: Function): void;
6
- off(this: WorkflowModel): void;
3
+ export declare abstract class Trigger {
4
+ readonly plugin: Plugin;
5
+ constructor(plugin: Plugin);
6
+ abstract on(workflow: WorkflowModel): void;
7
+ abstract off(workflow: WorkflowModel): void;
7
8
  }
8
- export declare const triggers: Registry<Trigger>;
9
- export default triggers;
9
+ export default function <T extends Trigger>(plugin: any, more?: {
10
+ [key: string]: {
11
+ new (p: Plugin): T;
12
+ };
13
+ }): void;
@@ -1,12 +1,65 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.triggers = void 0;
7
- const utils_1 = require("@nocobase/utils");
8
- const model_1 = __importDefault(require("./model"));
9
- exports.triggers = new utils_1.Registry();
10
- exports.default = exports.triggers;
11
- exports.triggers.register(model_1.default.name, model_1.default);
12
- //# sourceMappingURL=index.js.map
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Trigger = void 0;
7
+ exports.default = _default;
8
+
9
+ function _path() {
10
+ const data = _interopRequireDefault(require("path"));
11
+
12
+ _path = function _path() {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
19
+ function _utils() {
20
+ const data = require("@nocobase/utils");
21
+
22
+ _utils = function _utils() {
23
+ return data;
24
+ };
25
+
26
+ return data;
27
+ }
28
+
29
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
+
31
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
32
+
33
+ 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."); }
34
+
35
+ 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); }
36
+
37
+ 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; }
38
+
39
+ 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; }
40
+
41
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
42
+
43
+ class Trigger {
44
+ constructor(plugin) {
45
+ this.plugin = void 0;
46
+ this.plugin = plugin;
47
+ }
48
+
49
+ }
50
+
51
+ exports.Trigger = Trigger;
52
+
53
+ function _default(plugin, more = {}) {
54
+ const triggers = plugin.triggers;
55
+ triggers.register('collection', new ((0, _utils().requireModule)(_path().default.join(__dirname, 'collection')))(plugin));
56
+ triggers.register('schedule', new ((0, _utils().requireModule)(_path().default.join(__dirname, 'schedule')))(plugin));
57
+
58
+ for (var _i = 0, _Object$entries = Object.entries(more); _i < _Object$entries.length; _i++) {
59
+ const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
60
+ name = _Object$entries$_i[0],
61
+ TClass = _Object$entries$_i[1];
62
+
63
+ triggers.register(name, new TClass(plugin));
64
+ }
65
+ }
@@ -0,0 +1,38 @@
1
+ import Plugin, { Trigger } from '..';
2
+ export declare type ScheduleOnField = string | {
3
+ field: string;
4
+ offset?: number;
5
+ unit?: 1000 | 60000 | 3600000 | 86400000;
6
+ };
7
+ export interface ScheduleTriggerConfig {
8
+ mode: number;
9
+ repeat?: string | number | null;
10
+ limit?: number;
11
+ startsOn?: ScheduleOnField;
12
+ endsOn?: ScheduleOnField;
13
+ }
14
+ export declare const SCHEDULE_MODE: {
15
+ readonly CONSTANT: 0;
16
+ readonly COLLECTION_FIELD: 1;
17
+ };
18
+ export default class ScheduleTrigger extends Trigger {
19
+ static CacheRules: ((workflow: any, now: any) => any)[];
20
+ static TriggerRules: ((workflow: any, now: any) => boolean)[];
21
+ events: Map<any, any>;
22
+ private timer;
23
+ private cache;
24
+ interval: number;
25
+ cacheCycle: number;
26
+ constructor(plugin: Plugin);
27
+ init(): void;
28
+ run: () => void;
29
+ onTick(now: any): Promise<any>;
30
+ reload(): Promise<void>;
31
+ inspect(workflows: any): void;
32
+ setCache(workflow: any, out?: boolean): void;
33
+ shouldCache(workflow: any, now: any): Promise<boolean>;
34
+ shouldTrigger(workflow: any, now: any): boolean;
35
+ trigger(workflow: any, date: Date): Promise<any>;
36
+ on(workflow: any): void;
37
+ off(workflow: any): void;
38
+ }