@nocobase/plugin-workflow 1.0.0-alpha.3 → 1.0.0-alpha.4

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.
@@ -11,23 +11,23 @@ module.exports = {
11
11
  "react": "18.2.0",
12
12
  "antd": "5.12.8",
13
13
  "@ant-design/icons": "5.2.6",
14
- "@nocobase/client": "1.0.0-alpha.3",
14
+ "@nocobase/client": "1.0.0-alpha.4",
15
15
  "react-router-dom": "6.21.0",
16
- "@nocobase/utils": "1.0.0-alpha.3",
16
+ "@nocobase/utils": "1.0.0-alpha.4",
17
17
  "react-i18next": "11.18.6",
18
18
  "@formily/core": "2.3.0",
19
19
  "@formily/react": "2.3.0",
20
- "@nocobase/database": "1.0.0-alpha.3",
21
- "@nocobase/server": "1.0.0-alpha.3",
22
- "@nocobase/logger": "1.0.0-alpha.3",
23
- "@nocobase/evaluators": "1.0.0-alpha.3",
20
+ "@nocobase/database": "1.0.0-alpha.4",
21
+ "@nocobase/server": "1.0.0-alpha.4",
22
+ "@nocobase/logger": "1.0.0-alpha.4",
23
+ "@nocobase/evaluators": "1.0.0-alpha.4",
24
24
  "@formily/shared": "2.3.0",
25
25
  "lodash": "4.17.21",
26
26
  "@formily/antd-v5": "1.1.9",
27
- "@nocobase/actions": "1.0.0-alpha.3",
28
- "@nocobase/data-source-manager": "1.0.0-alpha.3",
27
+ "@nocobase/actions": "1.0.0-alpha.4",
28
+ "@nocobase/data-source-manager": "1.0.0-alpha.4",
29
29
  "sequelize": "6.35.2",
30
- "@nocobase/plugin-workflow-test": "1.0.0-alpha.3",
31
- "@nocobase/test": "1.0.0-alpha.3",
30
+ "@nocobase/plugin-workflow-test": "1.0.0-alpha.4",
31
+ "@nocobase/test": "1.0.0-alpha.4",
32
32
  "dayjs": "1.11.10"
33
33
  };
@@ -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":"2024-04-30T08:30:18.759Z"}
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":"2024-05-02T02:58:11.510Z"}
@@ -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":"2024-04-30T08:30:18.423Z"}
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":"2024-05-02T02:58:11.181Z"}
@@ -16,6 +16,11 @@ import Trigger from './triggers';
16
16
  import { InstructionInterface } from './instructions';
17
17
  import type { ExecutionModel, WorkflowModel } from './types';
18
18
  type ID = number | string;
19
+ type EventOptions = {
20
+ eventKey?: string;
21
+ context?: any;
22
+ [key: string]: any;
23
+ } & Transactionable;
19
24
  export default class PluginWorkflowServer extends Plugin {
20
25
  instructions: Registry<InstructionInterface>;
21
26
  triggers: Registry<Trigger>;
@@ -53,9 +58,7 @@ export default class PluginWorkflowServer extends Plugin {
53
58
  */
54
59
  load(): Promise<void>;
55
60
  private toggle;
56
- trigger(workflow: WorkflowModel, context: object, options?: {
57
- [key: string]: any;
58
- } & Transactionable): void | Promise<Processor | null>;
61
+ trigger(workflow: WorkflowModel, context: object, options?: EventOptions): void | Promise<Processor | null>;
59
62
  private triggerSync;
60
63
  resume(job: any): Promise<void>;
61
64
  createProcessor(execution: ExecutionModel, options?: {}): Processor;
@@ -40,6 +40,7 @@ __export(Plugin_exports, {
40
40
  });
41
41
  module.exports = __toCommonJS(Plugin_exports);
42
42
  var import_path = __toESM(require("path"));
43
+ var import_crypto = require("crypto");
43
44
  var import_lru_cache = __toESM(require("lru-cache"));
44
45
  var import_database = require("@nocobase/database");
45
46
  var import_server = require("@nocobase/server");
@@ -343,14 +344,23 @@ class PluginWorkflowServer extends import_server.Plugin {
343
344
  }
344
345
  return null;
345
346
  }
346
- const execution = await workflow.createExecution(
347
- {
348
- context,
349
- key: workflow.key,
350
- status: import_constants.EXECUTION_STATUS.QUEUEING
351
- },
352
- { transaction }
353
- );
347
+ let execution;
348
+ try {
349
+ execution = await workflow.createExecution(
350
+ {
351
+ context,
352
+ key: workflow.key,
353
+ eventKey: options.eventKey ?? (0, import_crypto.randomUUID)(),
354
+ status: import_constants.EXECUTION_STATUS.QUEUEING
355
+ },
356
+ { transaction }
357
+ );
358
+ } catch (err) {
359
+ if (!options.transaction) {
360
+ await transaction.rollback();
361
+ }
362
+ throw err;
363
+ }
354
364
  this.getLogger(workflow.id).info(`execution of workflow ${workflow.id} created as ${execution.id}`);
355
365
  await workflow.increment(["executed", "allExecuted"], { transaction });
356
366
  if (this.db.options.dialect !== "postgres") {
@@ -44,6 +44,11 @@ var executions_default = {
44
44
  type: "string",
45
45
  name: "key"
46
46
  },
47
+ {
48
+ type: "string",
49
+ name: "eventKey",
50
+ unique: true
51
+ },
47
52
  {
48
53
  type: "hasMany",
49
54
  name: "jobs",
@@ -298,12 +298,18 @@ class ScheduleTrigger {
298
298
  appends: workflow.config.appends,
299
299
  transaction
300
300
  });
301
- const key = `${workflow.id}:${recordPk}@${nextTime}`;
302
- this.cache.delete(key);
303
- this.workflow.trigger(workflow, {
304
- data: data.toJSON(),
305
- date: new Date(nextTime)
306
- });
301
+ const eventKey = `${workflow.id}:${recordPk}@${nextTime}`;
302
+ this.cache.delete(eventKey);
303
+ this.workflow.trigger(
304
+ workflow,
305
+ {
306
+ data: data.toJSON(),
307
+ date: new Date(nextTime)
308
+ },
309
+ {
310
+ eventKey
311
+ }
312
+ );
307
313
  if (!workflow.config.repeat || workflow.config.limit && workflow.allExecuted >= workflow.config.limit - 1) {
308
314
  return;
309
315
  }
@@ -7,17 +7,15 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import type Plugin from '../../Plugin';
10
+ import { WorkflowModel } from '../../types';
10
11
  export default class StaticScheduleTrigger {
11
12
  workflow: Plugin;
12
13
  private timers;
13
14
  constructor(workflow: Plugin);
14
- inspect(workflows: any): void;
15
- getNextTime({ config, allExecuted }: {
16
- config: any;
17
- allExecuted: any;
18
- }, currentDate: any, nextSecond?: boolean): any;
19
- schedule(workflow: any, nextTime: any, toggle?: boolean): void;
20
- trigger(workflow: any, time: any): Promise<void>;
15
+ inspect(workflows: WorkflowModel[]): void;
16
+ getNextTime({ config, allExecuted }: WorkflowModel, currentDate: Date, nextSecond?: boolean): number;
17
+ schedule(workflow: WorkflowModel, nextTime: number, toggle?: boolean): void;
18
+ trigger(workflow: WorkflowModel, time: number): Promise<void>;
21
19
  on(workflow: any): void;
22
20
  off(workflow: any): void;
23
21
  }
@@ -133,8 +133,9 @@ class StaticScheduleTrigger {
133
133
  }
134
134
  }
135
135
  async trigger(workflow, time) {
136
- this.timers.delete(`${workflow.id}@${time}`);
137
- this.workflow.trigger(workflow, { date: new Date(time) });
136
+ const eventKey = `${workflow.id}@${time}`;
137
+ this.timers.delete(eventKey);
138
+ this.workflow.trigger(workflow, { date: new Date(time) }, { eventKey });
138
139
  if (!workflow.config.repeat || workflow.config.limit && workflow.allExecuted >= workflow.config.limit - 1) {
139
140
  return;
140
141
  }
@@ -6,10 +6,8 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import { Transactionable } from 'sequelize';
10
9
  import Trigger from '..';
11
10
  import type Plugin from '../../Plugin';
12
- import { WorkflowModel } from '../../types';
13
11
  export default class ScheduleTrigger extends Trigger {
14
12
  sync: boolean;
15
13
  private modes;
@@ -17,5 +15,4 @@ export default class ScheduleTrigger extends Trigger {
17
15
  private getTrigger;
18
16
  on(workflow: any): void;
19
17
  off(workflow: any): void;
20
- validateEvent(workflow: WorkflowModel, context: any, options: Transactionable): Promise<boolean>;
21
18
  }
@@ -68,16 +68,17 @@ class ScheduleTrigger extends import__.default {
68
68
  trigger.off(workflow);
69
69
  }
70
70
  }
71
- async validateEvent(workflow, context, options) {
72
- if (!context.date) {
73
- return false;
74
- }
75
- const existed = await workflow.countExecutions({
76
- where: {
77
- "context.date": context.date instanceof Date ? context.date.toISOString() : context.date
78
- },
79
- transaction: options.transaction
80
- });
81
- return !existed;
82
- }
71
+ // async validateEvent(workflow: WorkflowModel, context: any, options: Transactionable): Promise<boolean> {
72
+ // if (!context.date) {
73
+ // return false;
74
+ // }
75
+ // const existed = await workflow.getExecutions({
76
+ // attributes: ['id'],
77
+ // where: {
78
+ // 'context.date': context.date instanceof Date ? context.date.toISOString() : context.date,
79
+ // },
80
+ // transaction: options.transaction,
81
+ // });
82
+ // return !existed.length;
83
+ // }
83
84
  }
package/package.json CHANGED
@@ -4,13 +4,13 @@
4
4
  "displayName.zh-CN": "工作流",
5
5
  "description": "A powerful BPM tool that provides foundational support for business automation, with the capability to extend unlimited triggers and nodes.",
6
6
  "description.zh-CN": "一个强大的 BPM 工具,为业务自动化提供基础支持,并且可任意扩展更多的触发器和节点。",
7
- "version": "1.0.0-alpha.3",
7
+ "version": "1.0.0-alpha.4",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/workflow",
11
11
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow",
12
12
  "dependencies": {
13
- "@nocobase/plugin-workflow-test": "1.0.0-alpha.3"
13
+ "@nocobase/plugin-workflow-test": "1.0.0-alpha.4"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@ant-design/icons": "5.x",
@@ -44,7 +44,7 @@
44
44
  "@nocobase/test": "1.x",
45
45
  "@nocobase/utils": "1.x"
46
46
  },
47
- "gitHead": "7ccb137c7616cba5d238f87368239640e1d9ace1",
47
+ "gitHead": "7a7005ce3bddf33498580a6486c45b5d9ea64ffb",
48
48
  "keywords": [
49
49
  "Workflow"
50
50
  ]