@nocobase/plugin-workflow 2.1.0-beta.1 → 2.1.0-beta.11

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.
@@ -46,6 +46,28 @@ export declare const executionSchema: {
46
46
  unique?: undefined;
47
47
  onDelete?: undefined;
48
48
  defaultValue?: undefined;
49
+ } | {
50
+ type: string;
51
+ name: string;
52
+ interface: string;
53
+ uiSchema: {
54
+ type: string;
55
+ title: string;
56
+ 'x-component': string;
57
+ 'x-component-props': {
58
+ fieldNames?: undefined;
59
+ };
60
+ 'x-read-pretty': boolean;
61
+ 'x-decorator'?: undefined;
62
+ enum?: undefined;
63
+ };
64
+ primaryKey?: undefined;
65
+ allowNull?: undefined;
66
+ target?: undefined;
67
+ foreignKey?: undefined;
68
+ unique?: undefined;
69
+ onDelete?: undefined;
70
+ defaultValue?: undefined;
49
71
  } | {
50
72
  type: string;
51
73
  name: string;
@@ -139,28 +161,6 @@ export declare const executionSchema: {
139
161
  foreignKey?: undefined;
140
162
  unique?: undefined;
141
163
  onDelete?: undefined;
142
- } | {
143
- type: string;
144
- name: string;
145
- interface: string;
146
- uiSchema: {
147
- type: string;
148
- title: string;
149
- 'x-component': string;
150
- 'x-component-props': {
151
- fieldNames?: undefined;
152
- };
153
- 'x-read-pretty': boolean;
154
- 'x-decorator'?: undefined;
155
- enum?: undefined;
156
- };
157
- primaryKey?: undefined;
158
- allowNull?: undefined;
159
- target?: undefined;
160
- foreignKey?: undefined;
161
- unique?: undefined;
162
- onDelete?: undefined;
163
- defaultValue?: undefined;
164
164
  })[];
165
165
  indexes: {
166
166
  fields: string[];
@@ -189,6 +189,25 @@ export declare const executionSchema: {
189
189
  };
190
190
  };
191
191
  properties: {
192
+ filter: {
193
+ type: string;
194
+ title: string;
195
+ 'x-action': string;
196
+ 'x-component': string;
197
+ 'x-use-component-props': string;
198
+ 'x-component-props': {
199
+ icon: string;
200
+ nonfilterable: string[];
201
+ };
202
+ 'x-align': string;
203
+ default: {
204
+ $and: {
205
+ status: {
206
+ $eq: any;
207
+ };
208
+ }[];
209
+ };
210
+ };
192
211
  refresher: {
193
212
  type: string;
194
213
  title: string;
@@ -35,6 +35,28 @@ declare const _default: {
35
35
  unique?: undefined;
36
36
  onDelete?: undefined;
37
37
  defaultValue?: undefined;
38
+ } | {
39
+ type: string;
40
+ name: string;
41
+ interface: string;
42
+ uiSchema: {
43
+ type: string;
44
+ title: string;
45
+ 'x-component': string;
46
+ 'x-component-props': {
47
+ fieldNames?: undefined;
48
+ };
49
+ 'x-read-pretty': boolean;
50
+ 'x-decorator'?: undefined;
51
+ enum?: undefined;
52
+ };
53
+ primaryKey?: undefined;
54
+ allowNull?: undefined;
55
+ target?: undefined;
56
+ foreignKey?: undefined;
57
+ unique?: undefined;
58
+ onDelete?: undefined;
59
+ defaultValue?: undefined;
38
60
  } | {
39
61
  type: string;
40
62
  name: string;
@@ -128,28 +150,6 @@ declare const _default: {
128
150
  foreignKey?: undefined;
129
151
  unique?: undefined;
130
152
  onDelete?: undefined;
131
- } | {
132
- type: string;
133
- name: string;
134
- interface: string;
135
- uiSchema: {
136
- type: string;
137
- title: string;
138
- 'x-component': string;
139
- 'x-component-props': {
140
- fieldNames?: undefined;
141
- };
142
- 'x-read-pretty': boolean;
143
- 'x-decorator'?: undefined;
144
- enum?: undefined;
145
- };
146
- primaryKey?: undefined;
147
- allowNull?: undefined;
148
- target?: undefined;
149
- foreignKey?: undefined;
150
- unique?: undefined;
151
- onDelete?: undefined;
152
- defaultValue?: undefined;
153
153
  })[];
154
154
  indexes: {
155
155
  fields: string[];
@@ -52,6 +52,18 @@ var executions_default = {
52
52
  primaryKey: true,
53
53
  allowNull: false
54
54
  },
55
+ {
56
+ type: "bigInt",
57
+ name: "workflowId",
58
+ interface: "id",
59
+ uiSchema: {
60
+ type: "number",
61
+ title: `{{t("Version ID", { ns: "${import_constants.NAMESPACE}" })}}`,
62
+ "x-component": "InputNumber",
63
+ "x-component-props": {},
64
+ "x-read-pretty": true
65
+ }
66
+ },
55
67
  {
56
68
  type: "belongsTo",
57
69
  name: "workflow",
@@ -17,8 +17,21 @@ declare const _default: {
17
17
  type: string;
18
18
  primaryKey: boolean;
19
19
  allowNull: boolean;
20
- interface?: undefined;
21
- uiSchema?: undefined;
20
+ interface: string;
21
+ uiSchema: {
22
+ type: string;
23
+ title: string;
24
+ 'x-component': string;
25
+ 'x-component-props': {
26
+ multiple?: undefined;
27
+ fieldNames?: undefined;
28
+ mode?: undefined;
29
+ };
30
+ 'x-read-pretty': boolean;
31
+ required?: undefined;
32
+ enum?: undefined;
33
+ default?: undefined;
34
+ };
22
35
  defaultValue?: undefined;
23
36
  required?: undefined;
24
37
  target?: undefined;
@@ -53,10 +66,10 @@ declare const _default: {
53
66
  type: string;
54
67
  'x-component': string;
55
68
  required: boolean;
56
- enum?: undefined;
57
- default?: undefined;
58
69
  'x-component-props'?: undefined;
59
70
  'x-read-pretty'?: undefined;
71
+ enum?: undefined;
72
+ default?: undefined;
60
73
  };
61
74
  primaryKey?: undefined;
62
75
  allowNull?: undefined;
@@ -88,9 +101,9 @@ declare const _default: {
88
101
  })[];
89
102
  'x-component': string;
90
103
  default: boolean;
91
- required?: undefined;
92
104
  'x-component-props'?: undefined;
93
105
  'x-read-pretty'?: undefined;
106
+ required?: undefined;
94
107
  };
95
108
  primaryKey?: undefined;
96
109
  allowNull?: undefined;
@@ -110,11 +123,11 @@ declare const _default: {
110
123
  title: string;
111
124
  type: string;
112
125
  'x-component': string;
126
+ 'x-component-props'?: undefined;
127
+ 'x-read-pretty'?: undefined;
113
128
  required?: undefined;
114
129
  enum?: undefined;
115
130
  default?: undefined;
116
- 'x-component-props'?: undefined;
117
- 'x-read-pretty'?: undefined;
118
131
  };
119
132
  primaryKey?: undefined;
120
133
  allowNull?: undefined;
@@ -138,9 +151,9 @@ declare const _default: {
138
151
  'x-component': string;
139
152
  enum: string;
140
153
  required: boolean;
141
- default?: undefined;
142
154
  'x-component-props'?: undefined;
143
155
  'x-read-pretty'?: undefined;
156
+ default?: undefined;
144
157
  };
145
158
  primaryKey?: undefined;
146
159
  allowNull?: undefined;
@@ -215,9 +228,9 @@ declare const _default: {
215
228
  color: string;
216
229
  }[];
217
230
  required: boolean;
218
- default?: undefined;
219
231
  'x-component-props'?: undefined;
220
232
  'x-read-pretty'?: undefined;
233
+ default?: undefined;
221
234
  };
222
235
  primaryKey?: undefined;
223
236
  allowNull?: undefined;
@@ -41,7 +41,15 @@ var workflows_default = {
41
41
  name: "id",
42
42
  type: "snowflakeId",
43
43
  primaryKey: true,
44
- allowNull: false
44
+ allowNull: false,
45
+ interface: "id",
46
+ uiSchema: {
47
+ type: "number",
48
+ title: '{{t("ID")}}',
49
+ "x-component": "InputNumber",
50
+ "x-component-props": {},
51
+ "x-read-pretty": true
52
+ }
45
53
  },
46
54
  {
47
55
  name: "key",
@@ -11,8 +11,8 @@ module.exports = {
11
11
  "react": "18.2.0",
12
12
  "@formily/core": "2.3.7",
13
13
  "@formily/react": "2.3.7",
14
- "@nocobase/client": "2.1.0-beta.1",
15
- "@nocobase/utils": "2.1.0-beta.1",
14
+ "@nocobase/client": "2.1.0-beta.11",
15
+ "@nocobase/utils": "2.1.0-beta.11",
16
16
  "antd": "5.24.2",
17
17
  "@ant-design/icons": "5.6.1",
18
18
  "react-router-dom": "6.30.1",
@@ -20,18 +20,18 @@ module.exports = {
20
20
  "lodash": "4.17.21",
21
21
  "@dnd-kit/core": "6.1.0",
22
22
  "@formily/shared": "2.3.7",
23
- "@nocobase/flow-engine": "2.1.0-beta.1",
24
- "@nocobase/plugin-mobile": "2.1.0-beta.1",
23
+ "@nocobase/flow-engine": "2.1.0-beta.11",
24
+ "@nocobase/plugin-mobile": "2.1.0-beta.11",
25
25
  "sequelize": "6.35.2",
26
- "@nocobase/server": "2.1.0-beta.1",
27
- "@nocobase/database": "2.1.0-beta.1",
28
- "@nocobase/data-source-manager": "2.1.0-beta.1",
29
- "@nocobase/logger": "2.1.0-beta.1",
30
- "@nocobase/evaluators": "2.1.0-beta.1",
26
+ "@nocobase/server": "2.1.0-beta.11",
27
+ "@nocobase/database": "2.1.0-beta.11",
28
+ "@nocobase/data-source-manager": "2.1.0-beta.11",
29
+ "@nocobase/logger": "2.1.0-beta.11",
30
+ "@nocobase/evaluators": "2.1.0-beta.11",
31
31
  "@formily/antd-v5": "1.2.3",
32
32
  "@formily/reactive": "2.3.7",
33
- "@nocobase/actions": "2.1.0-beta.1",
33
+ "@nocobase/actions": "2.1.0-beta.11",
34
34
  "dayjs": "1.11.13",
35
- "@nocobase/plugin-workflow-test": "2.1.0-beta.1",
36
- "@nocobase/test": "2.1.0-beta.1"
35
+ "@nocobase/plugin-workflow-test": "2.1.0-beta.11",
36
+ "@nocobase/test": "2.1.0-beta.11"
37
37
  };
@@ -223,12 +223,13 @@
223
223
  "The workflow tasks page has already been created.": "工作流待办页面已创建。",
224
224
  "This is a main version, delete it will cause the whole workflow to be deleted (including all other revisions).": "当前是主版本,删除将导致整个流程被删除(包括所有其他版本)。",
225
225
  "This node contains branches, deleting will also be preformed to them, are you sure?": "节点包含分支,将同时删除其所有分支下的子节点,确定继续?",
226
+ "This type of node can not be used in current type of workflow or execute mode.": "该类型的节点在当前类型的工作流或执行模式中不可用。",
226
227
  "This type of trigger has not been supported to be executed manually.": "该类型的触发器暂未支持手动执行。",
227
228
  "This will perform all the actions configured in the workflow. Are you sure you want to continue?": "将按照工作流中配置的所有操作执行,确定继续吗?",
228
229
  "Trigger": "触发器",
229
230
  "Trigger data": "触发数据",
230
231
  "Trigger data context": "触发数据上下文",
231
- "Trigger in executed workflow cannot be modified": "Trigger in executed workflow cannot be modified",
232
+ "Trigger in executed workflow cannot be modified": "已执行的工作流中的触发器无法修改",
232
233
  "Trigger mode": "触发模式",
233
234
  "Trigger on": "触发时机",
234
235
  "Trigger time": "触发时间",
@@ -1 +1 @@
1
- {"name":"cron-parser","version":"4.4.0","description":"Node.js library for parsing crontab instructions","main":"lib/parser.js","types":"index.d.ts","typesVersions":{"<4.1":{"*":["types/ts3/*"]}},"directories":{"test":"test"},"scripts":{"test:tsd":"tsd","test:unit":"TZ=UTC tap ./test/*.js","test:cover":"TZ=UTC tap --coverage-report=html ./test/*.js","lint":"eslint .","lint:fix":"eslint --fix .","test":"npm run lint && npm run test:unit && npm run test:tsd"},"repository":{"type":"git","url":"https://github.com/harrisiirak/cron-parser.git"},"keywords":["cron","crontab","parser"],"author":"Harri Siirak","contributors":["Nicholas Clawson","Daniel Prentis <daniel@salsitasoft.com>","Renault John Lecoultre","Richard Astbury <richard.astbury@gmail.com>","Meaglin Wasabi <Meaglin.wasabi@gmail.com>","Mike Kusold <hello@mikekusold.com>","Alex Kit <alex.kit@atmajs.com>","Santiago Gimeno <santiago.gimeno@gmail.com>","Daniel <darc.tec@gmail.com>","Christian Steininger <christian.steininger.cs@gmail.com>","Mykola Piskovyi <m.piskovyi@gmail.com>","Brian Vaughn <brian.david.vaughn@gmail.com>","Nicholas Clawson <nickclaw@gmail.com>","Yasuhiroki <yasuhiroki.duck@gmail.com>","Nicholas Clawson <nickclaw@gmail.com>","Brendan Warkentin <faazshift@gmail.com>","Charlie Fish <fishcharlie.code@gmail.com>","Ian Graves <ian+diskimage@iangrav.es>","Andy Thompson <me@andytson.com>","Regev Brody <regevbr@gmail.com>"],"license":"MIT","dependencies":{"luxon":"^1.28.0"},"devDependencies":{"eslint":"^8.2.0","sinon":"^10.0.0","tap":"^16.0.1","tsd":"^0.19.0"},"engines":{"node":">=0.8"},"browser":{"fs":false},"tap":{"check-coverage":false},"tsd":{"directory":"test","compilerOptions":{"lib":["es2017","dom"]}},"_lastModified":"2026-02-14T14:45:27.092Z"}
1
+ {"name":"cron-parser","version":"4.4.0","description":"Node.js library for parsing crontab instructions","main":"lib/parser.js","types":"index.d.ts","typesVersions":{"<4.1":{"*":["types/ts3/*"]}},"directories":{"test":"test"},"scripts":{"test:tsd":"tsd","test:unit":"TZ=UTC tap ./test/*.js","test:cover":"TZ=UTC tap --coverage-report=html ./test/*.js","lint":"eslint .","lint:fix":"eslint --fix .","test":"npm run lint && npm run test:unit && npm run test:tsd"},"repository":{"type":"git","url":"https://github.com/harrisiirak/cron-parser.git"},"keywords":["cron","crontab","parser"],"author":"Harri Siirak","contributors":["Nicholas Clawson","Daniel Prentis <daniel@salsitasoft.com>","Renault John Lecoultre","Richard Astbury <richard.astbury@gmail.com>","Meaglin Wasabi <Meaglin.wasabi@gmail.com>","Mike Kusold <hello@mikekusold.com>","Alex Kit <alex.kit@atmajs.com>","Santiago Gimeno <santiago.gimeno@gmail.com>","Daniel <darc.tec@gmail.com>","Christian Steininger <christian.steininger.cs@gmail.com>","Mykola Piskovyi <m.piskovyi@gmail.com>","Brian Vaughn <brian.david.vaughn@gmail.com>","Nicholas Clawson <nickclaw@gmail.com>","Yasuhiroki <yasuhiroki.duck@gmail.com>","Nicholas Clawson <nickclaw@gmail.com>","Brendan Warkentin <faazshift@gmail.com>","Charlie Fish <fishcharlie.code@gmail.com>","Ian Graves <ian+diskimage@iangrav.es>","Andy Thompson <me@andytson.com>","Regev Brody <regevbr@gmail.com>"],"license":"MIT","dependencies":{"luxon":"^1.28.0"},"devDependencies":{"eslint":"^8.2.0","sinon":"^10.0.0","tap":"^16.0.1","tsd":"^0.19.0"},"engines":{"node":">=0.8"},"browser":{"fs":false},"tap":{"check-coverage":false},"tsd":{"directory":"test","compilerOptions":{"lib":["es2017","dom"]}},"_lastModified":"2026-03-20T08:10:07.910Z"}
@@ -1 +1 @@
1
- {"name":"lru-cache","description":"A cache object that deletes the least-recently-used items.","version":"8.0.5","author":"Isaac Z. Schlueter <i@izs.me>","keywords":["mru","lru","cache"],"sideEffects":false,"scripts":{"build":"npm run prepare","preprepare":"rm -rf dist","prepare":"tsc -p tsconfig.json && tsc -p tsconfig-esm.json","postprepare":"bash fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 tap","preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","format":"prettier --write .","typedoc":"typedoc --tsconfig tsconfig-esm.json ./src/*.ts","benchmark-results-typedoc":"bash scripts/benchmark-results-typedoc.sh","prebenchmark":"npm run prepare","benchmark":"make -C benchmark","preprofile":"npm run prepare","profile":"make -C benchmark profile"},"main":"./dist/cjs/index-cjs.js","module":"./dist/mjs/index.js","types":"./dist/mjs/index.d.ts","exports":{"./min":{"import":{"types":"./dist/mjs/index.d.ts","default":"./dist/mjs/index.min.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.min.js"}},".":{"import":{"types":"./dist/mjs/index.d.ts","default":"./dist/mjs/index.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index-cjs.js"}}},"repository":"git://github.com/isaacs/node-lru-cache.git","devDependencies":{"@size-limit/preset-small-lib":"^7.0.8","@types/node":"^17.0.31","@types/tap":"^15.0.6","benchmark":"^2.1.4","c8":"^7.11.2","clock-mock":"^1.0.6","esbuild":"^0.17.11","eslint-config-prettier":"^8.5.0","marked":"^4.2.12","mkdirp":"^2.1.5","prettier":"^2.6.2","size-limit":"^7.0.8","tap":"^16.3.4","ts-node":"^10.7.0","tslib":"^2.4.0","typedoc":"^0.23.24","typescript":"^4.6.4"},"license":"ISC","files":["dist"],"engines":{"node":">=16.14"},"prettier":{"semi":false,"printWidth":70,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"tap":{"coverage":false,"node-arg":["--expose-gc","--no-warnings","--loader","ts-node/esm"],"ts":false},"size-limit":[{"path":"./dist/mjs/index.js"}],"_lastModified":"2026-02-14T14:45:26.722Z"}
1
+ {"name":"lru-cache","description":"A cache object that deletes the least-recently-used items.","version":"8.0.5","author":"Isaac Z. Schlueter <i@izs.me>","keywords":["mru","lru","cache"],"sideEffects":false,"scripts":{"build":"npm run prepare","preprepare":"rm -rf dist","prepare":"tsc -p tsconfig.json && tsc -p tsconfig-esm.json","postprepare":"bash fixup.sh","pretest":"npm run prepare","presnap":"npm run prepare","test":"c8 tap","snap":"c8 tap","preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","format":"prettier --write .","typedoc":"typedoc --tsconfig tsconfig-esm.json ./src/*.ts","benchmark-results-typedoc":"bash scripts/benchmark-results-typedoc.sh","prebenchmark":"npm run prepare","benchmark":"make -C benchmark","preprofile":"npm run prepare","profile":"make -C benchmark profile"},"main":"./dist/cjs/index-cjs.js","module":"./dist/mjs/index.js","types":"./dist/mjs/index.d.ts","exports":{"./min":{"import":{"types":"./dist/mjs/index.d.ts","default":"./dist/mjs/index.min.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index.min.js"}},".":{"import":{"types":"./dist/mjs/index.d.ts","default":"./dist/mjs/index.js"},"require":{"types":"./dist/cjs/index.d.ts","default":"./dist/cjs/index-cjs.js"}}},"repository":"git://github.com/isaacs/node-lru-cache.git","devDependencies":{"@size-limit/preset-small-lib":"^7.0.8","@types/node":"^17.0.31","@types/tap":"^15.0.6","benchmark":"^2.1.4","c8":"^7.11.2","clock-mock":"^1.0.6","esbuild":"^0.17.11","eslint-config-prettier":"^8.5.0","marked":"^4.2.12","mkdirp":"^2.1.5","prettier":"^2.6.2","size-limit":"^7.0.8","tap":"^16.3.4","ts-node":"^10.7.0","tslib":"^2.4.0","typedoc":"^0.23.24","typescript":"^4.6.4"},"license":"ISC","files":["dist"],"engines":{"node":">=16.14"},"prettier":{"semi":false,"printWidth":70,"tabWidth":2,"useTabs":false,"singleQuote":true,"jsxSingleQuote":false,"bracketSameLine":true,"arrowParens":"avoid","endOfLine":"lf"},"tap":{"coverage":false,"node-arg":["--expose-gc","--no-warnings","--loader","ts-node/esm"],"ts":false},"size-limit":[{"path":"./dist/mjs/index.js"}],"_lastModified":"2026-03-20T08:10:07.592Z"}
@@ -1 +1 @@
1
- {"name":"nodejs-snowflake","collaborators":["Utkarsh Srivastava <utkarsh@sagacious.dev>"],"description":"Generate time sortable 64 bits unique ids for distributed systems (inspired from twitter snowflake)","version":"2.0.1","license":"Apache 2.0","repository":{"type":"git","url":"https://github.com/utkarsh-pro/nodejs-snowflake.git"},"files":["nodejs_snowflake_bg.wasm","nodejs_snowflake.js","nodejs_snowflake.d.ts"],"main":"nodejs_snowflake.js","types":"nodejs_snowflake.d.ts","_lastModified":"2026-02-14T14:45:26.515Z"}
1
+ {"name":"nodejs-snowflake","collaborators":["Utkarsh Srivastava <utkarsh@sagacious.dev>"],"description":"Generate time sortable 64 bits unique ids for distributed systems (inspired from twitter snowflake)","version":"2.0.1","license":"Apache 2.0","repository":{"type":"git","url":"https://github.com/utkarsh-pro/nodejs-snowflake.git"},"files":["nodejs_snowflake_bg.wasm","nodejs_snowflake.js","nodejs_snowflake.d.ts"],"main":"nodejs_snowflake.js","types":"nodejs_snowflake.d.ts","_lastModified":"2026-03-20T08:10:07.400Z"}
@@ -30,6 +30,7 @@ export default class Dispatcher {
30
30
  private readonly plugin;
31
31
  private ready;
32
32
  private executing;
33
+ private preparing;
33
34
  private pending;
34
35
  private events;
35
36
  private eventsCount;
@@ -39,15 +40,15 @@ export default class Dispatcher {
39
40
  setReady(ready: boolean): void;
40
41
  getEventsCount(): number;
41
42
  trigger(workflow: WorkflowModel, context: object, options?: EventOptions): void | Promise<Processor | null>;
43
+ private prepare;
42
44
  resume(job: any): Promise<void>;
43
45
  start(execution: ExecutionModel): Promise<void>;
44
46
  beforeStop(): Promise<void>;
45
- dispatch(): Promise<void>;
47
+ dispatch(): void;
46
48
  run(pending: Pending): Promise<void>;
47
49
  private triggerSync;
48
50
  private validateEvent;
49
51
  private createExecution;
50
- private prepare;
51
52
  private acquirePendingExecution;
52
53
  private acquireQueueingExecution;
53
54
  private process;
@@ -29,22 +29,22 @@ __export(Dispatcher_exports, {
29
29
  default: () => Dispatcher
30
30
  });
31
31
  module.exports = __toCommonJS(Dispatcher_exports);
32
- var import_crypto = require("crypto");
32
+ var import_node_crypto = require("node:crypto");
33
33
  var import_sequelize = require("sequelize");
34
34
  var import_constants = require("./constants");
35
35
  var import_Plugin = require("./Plugin");
36
36
  class Dispatcher {
37
37
  constructor(plugin) {
38
38
  this.plugin = plugin;
39
- this.prepare = this.prepare.bind(this);
40
39
  }
41
40
  ready = false;
42
41
  executing = null;
42
+ preparing = null;
43
43
  pending = [];
44
44
  events = [];
45
45
  eventsCount = 0;
46
46
  get idle() {
47
- return this.ready && !this.executing && !this.pending.length && !this.events.length;
47
+ return this.ready && !this.executing && !this.preparing && !this.pending.length && !this.events.length;
48
48
  }
49
49
  onQueueExecution = async (event) => {
50
50
  const ExecutionRepo = this.plugin.db.getRepository("executions");
@@ -96,11 +96,55 @@ class Dispatcher {
96
96
  this.eventsCount = this.events.length;
97
97
  logger.info(`new event triggered, now events: ${this.events.length}`);
98
98
  logger.debug(`event data:`, { context });
99
- if (this.events.length > 1) {
100
- logger.info(`new event is pending to be prepared after previous preparation is finished`);
99
+ this.prepare();
100
+ }
101
+ prepare() {
102
+ if (this.preparing) {
101
103
  return;
102
104
  }
103
- setImmediate(this.prepare);
105
+ this.preparing = (async () => {
106
+ try {
107
+ while (this.events.length) {
108
+ if (this.executing && this.plugin.db.options.dialect === "sqlite") {
109
+ await this.executing;
110
+ }
111
+ const event = this.events.shift();
112
+ this.eventsCount = this.events.length;
113
+ if (!event) continue;
114
+ const logger = this.plugin.getLogger(event[0].id);
115
+ logger.info(`preparing execution for event`);
116
+ try {
117
+ const execution = await this.createExecution(...event);
118
+ if (!(execution == null ? void 0 : execution.dispatched)) {
119
+ if (this.plugin.serving() && !this.executing && !this.pending.length) {
120
+ logger.info(`local pending list is empty, adding execution (${execution.id}) to pending list`);
121
+ this.pending.push({ execution });
122
+ } else {
123
+ logger.info(
124
+ `instance is not serving as worker or local pending list is not empty, sending execution (${execution.id}) to queue`
125
+ );
126
+ try {
127
+ await this.plugin.app.eventQueue.publish(this.plugin.channelPendingExecution, {
128
+ executionId: execution.id
129
+ });
130
+ } catch (qErr) {
131
+ logger.error(`publishing execution (${execution.id}) to queue failed:`, { error: qErr });
132
+ }
133
+ }
134
+ }
135
+ } catch (error) {
136
+ logger.error(`failed to create execution:`, { error });
137
+ }
138
+ }
139
+ } finally {
140
+ this.preparing = null;
141
+ if (this.events.length) {
142
+ this.prepare();
143
+ } else {
144
+ this.dispatch();
145
+ }
146
+ }
147
+ })();
104
148
  }
105
149
  async resume(job) {
106
150
  let { execution } = job;
@@ -119,16 +163,26 @@ class Dispatcher {
119
163
  }
120
164
  async beforeStop() {
121
165
  this.ready = false;
122
- if (this.events.length) {
123
- await this.prepare();
124
- }
125
- if (this.executing) {
126
- await this.executing;
166
+ this.plugin.getLogger("dispatcher").info("app is stopping, draining local queues...");
167
+ while (this.preparing || this.executing || this.events.length || this.pending.length) {
168
+ if (this.preparing) {
169
+ await this.preparing;
170
+ }
171
+ if (this.executing) {
172
+ await this.executing;
173
+ }
174
+ if (this.events.length && !this.preparing) {
175
+ this.prepare();
176
+ }
177
+ if (this.pending.length && !this.executing) {
178
+ this.dispatch();
179
+ }
180
+ await new Promise((resolve) => setImmediate(resolve));
127
181
  }
182
+ this.plugin.getLogger("dispatcher").info("local queues drained");
128
183
  }
129
184
  dispatch() {
130
- if (!this.ready) {
131
- this.plugin.getLogger("dispatcher").warn(`app is not ready, new dispatching will be ignored`);
185
+ if (!this.ready && !this.pending.length && !this.events.length) {
132
186
  return;
133
187
  }
134
188
  if (this.executing) {
@@ -136,7 +190,8 @@ class Dispatcher {
136
190
  return;
137
191
  }
138
192
  if (this.events.length) {
139
- return this.prepare();
193
+ this.prepare();
194
+ return;
140
195
  }
141
196
  this.executing = (async () => {
142
197
  let next = null;
@@ -149,13 +204,15 @@ class Dispatcher {
149
204
  this.plugin.getLogger(next[0].workflowId).info(`pending execution (${next[0].id}) ready to process`);
150
205
  }
151
206
  } else {
152
- if (this.plugin.serving()) {
207
+ if (this.ready && this.plugin.serving()) {
153
208
  execution = await this.acquireQueueingExecution();
154
209
  if (execution) {
155
210
  next = [execution];
156
211
  }
157
212
  } else {
158
- this.plugin.getLogger("dispatcher").warn(`${import_Plugin.WORKER_JOB_WORKFLOW_PROCESS} is not serving on this instance, new dispatching will be ignored`);
213
+ this.plugin.getLogger("dispatcher").warn(
214
+ `${import_Plugin.WORKER_JOB_WORKFLOW_PROCESS} is not serving on this instance or app not ready, new dispatching will be ignored`
215
+ );
159
216
  }
160
217
  }
161
218
  if (next) {
@@ -233,7 +290,7 @@ class Dispatcher {
233
290
  {
234
291
  context,
235
292
  key: workflow.key,
236
- eventKey: options.eventKey ?? (0, import_crypto.randomUUID)(),
293
+ eventKey: options.eventKey ?? (0, import_node_crypto.randomUUID)(),
237
294
  stack: options.stack,
238
295
  dispatched: deferred ?? false,
239
296
  status: deferred ? import_constants.EXECUTION_STATUS.STARTED : import_constants.EXECUTION_STATUS.QUEUEING,
@@ -268,50 +325,6 @@ class Dispatcher {
268
325
  execution.workflow = workflow;
269
326
  return execution;
270
327
  }
271
- prepare = async () => {
272
- if (this.executing && this.plugin.db.options.dialect === "sqlite") {
273
- await this.executing;
274
- }
275
- const event = this.events.shift();
276
- this.eventsCount = this.events.length;
277
- if (!event) {
278
- this.plugin.getLogger("dispatcher").info(`events queue is empty, no need to prepare`);
279
- return;
280
- }
281
- const logger = this.plugin.getLogger(event[0].id);
282
- logger.info(`preparing execution for event`);
283
- try {
284
- const execution = await this.createExecution(...event);
285
- if (!(execution == null ? void 0 : execution.dispatched)) {
286
- if (this.plugin.serving() && !this.executing && !this.pending.length) {
287
- logger.info(`local pending list is empty, adding execution (${execution.id}) to pending list`);
288
- this.pending.push({ execution });
289
- } else {
290
- logger.info(
291
- `instance is not serving as worker or local pending list is not empty, sending execution (${execution.id}) to queue`
292
- );
293
- try {
294
- await this.plugin.app.eventQueue.publish(this.plugin.channelPendingExecution, {
295
- executionId: execution.id
296
- });
297
- } catch (qErr) {
298
- logger.error(`publishing execution (${execution.id}) to queue failed:`, { error: qErr });
299
- }
300
- }
301
- }
302
- } catch (error) {
303
- logger.error(`failed to create execution:`, { error });
304
- }
305
- if (this.events.length) {
306
- await this.prepare();
307
- } else {
308
- this.plugin.getLogger("dispatcher").info("no more events need to be prepared, dispatching...");
309
- if (this.executing) {
310
- await this.executing;
311
- }
312
- this.dispatch();
313
- }
314
- };
315
328
  async acquirePendingExecution(execution) {
316
329
  const logger = this.plugin.getLogger(execution.workflowId);
317
330
  const isolationLevel = this.plugin.db.options.dialect === "sqlite" ? [][0] : import_sequelize.Transaction.ISOLATION_LEVELS.REPEATABLE_READ;