@nocobase/plugin-workflow 1.5.0-alpha.5 → 1.6.0-alpha.1

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 (35) hide show
  1. package/dist/client/383.index.js +10 -0
  2. package/dist/client/923.index.js +10 -0
  3. package/dist/client/929.index.js +10 -0
  4. package/dist/client/999.index.js +10 -0
  5. package/dist/client/components/TriggerCollectionRecordSelect.d.ts +10 -0
  6. package/dist/client/components/index.d.ts +1 -0
  7. package/dist/client/constants.d.ts +1 -0
  8. package/dist/client/index.js +1 -1
  9. package/dist/client/triggers/collection.d.ts +14 -0
  10. package/dist/client/triggers/index.d.ts +3 -3
  11. package/dist/client/triggers/schedule/ScheduleModes.d.ts +167 -0
  12. package/dist/client/triggers/schedule/TriggerScheduleConfig.d.ts +10 -0
  13. package/dist/client/triggers/schedule/index.d.ts +11 -0
  14. package/dist/externalVersion.js +10 -10
  15. package/dist/locale/zh-CN.json +14 -0
  16. package/dist/node_modules/cron-parser/package.json +1 -1
  17. package/dist/node_modules/lru-cache/package.json +1 -1
  18. package/dist/server/Plugin.d.ts +5 -1
  19. package/dist/server/Plugin.js +31 -23
  20. package/dist/server/actions/workflows.d.ts +5 -0
  21. package/dist/server/actions/workflows.js +56 -61
  22. package/dist/server/collections/workflows.js +2 -2
  23. package/dist/server/index.d.ts +1 -1
  24. package/dist/server/index.js +2 -0
  25. package/dist/server/repositories/WorkflowRepository.d.ts +12 -0
  26. package/dist/server/repositories/WorkflowRepository.js +112 -0
  27. package/dist/server/triggers/CollectionTrigger.d.ts +9 -1
  28. package/dist/server/triggers/CollectionTrigger.js +76 -57
  29. package/dist/server/triggers/ScheduleTrigger/DateFieldScheduleTrigger.d.ts +1 -1
  30. package/dist/server/triggers/ScheduleTrigger/DateFieldScheduleTrigger.js +7 -4
  31. package/dist/server/triggers/ScheduleTrigger/index.d.ts +2 -0
  32. package/dist/server/triggers/ScheduleTrigger/index.js +4 -0
  33. package/dist/server/triggers/index.d.ts +4 -2
  34. package/dist/server/triggers/index.js +4 -0
  35. package/package.json +3 -3
@@ -10,6 +10,7 @@
10
10
  import { SchemaInitializerItemType, useCollectionDataSource } from '@nocobase/client';
11
11
  import { useWorkflowAnyExecuted } from '../hooks';
12
12
  import { Trigger } from '.';
13
+ import { TriggerCollectionRecordSelect } from '../components/TriggerCollectionRecordSelect';
13
14
  declare function useVariables(config: any, options: any): import("../variable").VariableOption[];
14
15
  export default class extends Trigger {
15
16
  title: string;
@@ -117,7 +118,20 @@ export default class extends Trigger {
117
118
  };
118
119
  components: {
119
120
  FieldsSelect: import("react").MemoExoticComponent<import("@formily/reactive-react").ReactFC<Omit<any, "ref">>>;
121
+ TriggerCollectionRecordSelect: typeof TriggerCollectionRecordSelect;
120
122
  };
123
+ triggerFieldset: {
124
+ data: {
125
+ type: string;
126
+ title: string;
127
+ description: string;
128
+ 'x-decorator': string;
129
+ 'x-component': string;
130
+ default: any;
131
+ required: boolean;
132
+ };
133
+ };
134
+ validate(values: any): any;
121
135
  useVariables: typeof useVariables;
122
136
  useInitializers(config: any): SchemaInitializerItemType | null;
123
137
  }
@@ -15,9 +15,9 @@ export declare abstract class Trigger {
15
15
  title: string;
16
16
  description?: string;
17
17
  useVariables?(config: Record<string, any>, options?: UseVariableOptions): VariableOption[];
18
- fieldset: {
19
- [key: string]: ISchema;
20
- };
18
+ fieldset: Record<string, ISchema>;
19
+ triggerFieldset?: Record<string, ISchema>;
20
+ validate(config: Record<string, any>): boolean;
21
21
  view?: ISchema;
22
22
  scope?: {
23
23
  [key: string]: any;
@@ -0,0 +1,167 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export declare const ScheduleModes: {
10
+ [x: number]: {
11
+ fieldset: {
12
+ startsOn: {
13
+ type: string;
14
+ title: string;
15
+ 'x-decorator': string;
16
+ 'x-component': string;
17
+ 'x-component-props': {
18
+ showTime: boolean;
19
+ };
20
+ required: boolean;
21
+ 'x-reactions'?: undefined;
22
+ };
23
+ repeat: {
24
+ type: string;
25
+ title: string;
26
+ 'x-decorator': string;
27
+ 'x-component': string;
28
+ 'x-reactions': {
29
+ target: string;
30
+ fulfill: {
31
+ state: {
32
+ visible: string;
33
+ };
34
+ };
35
+ }[];
36
+ };
37
+ endsOn: {
38
+ type: string;
39
+ title: string;
40
+ 'x-decorator': string;
41
+ 'x-component': string;
42
+ 'x-component-props': {
43
+ showTime: boolean;
44
+ };
45
+ };
46
+ limit: {
47
+ type: string;
48
+ title: string;
49
+ 'x-decorator': string;
50
+ 'x-component': string;
51
+ 'x-component-props': {
52
+ placeholder: string;
53
+ min: number;
54
+ };
55
+ };
56
+ collection?: undefined;
57
+ appends?: undefined;
58
+ };
59
+ triggerFieldset: {
60
+ date: {
61
+ type: string;
62
+ title: string;
63
+ 'x-decorator': string;
64
+ 'x-component': string;
65
+ 'x-component-props': {
66
+ showTime: boolean;
67
+ placeholder: string;
68
+ };
69
+ };
70
+ data?: undefined;
71
+ };
72
+ } | {
73
+ fieldset: {
74
+ collection: {
75
+ 'x-component-props': {
76
+ dataSourceFilter(item: any): any;
77
+ };
78
+ 'x-reactions': any[];
79
+ type: string;
80
+ title: string;
81
+ required: boolean;
82
+ 'x-decorator': string;
83
+ 'x-component': string;
84
+ };
85
+ startsOn: {
86
+ type: string;
87
+ title: string;
88
+ 'x-decorator': string;
89
+ 'x-component': string;
90
+ 'x-reactions': {
91
+ target: string;
92
+ fulfill: {
93
+ state: {
94
+ visible: string;
95
+ };
96
+ };
97
+ }[];
98
+ required: boolean;
99
+ 'x-component-props'?: undefined;
100
+ };
101
+ repeat: {
102
+ type: string;
103
+ title: string;
104
+ 'x-decorator': string;
105
+ 'x-component': string;
106
+ 'x-reactions': {
107
+ target: string;
108
+ fulfill: {
109
+ state: {
110
+ visible: string;
111
+ };
112
+ };
113
+ }[];
114
+ };
115
+ endsOn: {
116
+ type: string;
117
+ title: string;
118
+ 'x-decorator': string;
119
+ 'x-component': string;
120
+ 'x-component-props'?: undefined;
121
+ };
122
+ limit: {
123
+ type: string;
124
+ title: string;
125
+ 'x-decorator': string;
126
+ 'x-component': string;
127
+ 'x-component-props': {
128
+ placeholder: string;
129
+ min: number;
130
+ };
131
+ };
132
+ appends: {
133
+ 'x-reactions': {
134
+ dependencies: string[];
135
+ fulfill: {
136
+ state: {
137
+ visible: string;
138
+ };
139
+ };
140
+ }[];
141
+ type: string;
142
+ title: string;
143
+ description: string;
144
+ 'x-decorator': string;
145
+ 'x-component': string;
146
+ 'x-component-props': {
147
+ title: string;
148
+ multiple: boolean;
149
+ useCollection(): any;
150
+ };
151
+ };
152
+ };
153
+ triggerFieldset: {
154
+ data: {
155
+ type: string;
156
+ title: string;
157
+ description: string;
158
+ 'x-decorator': string;
159
+ 'x-component': string;
160
+ default: any;
161
+ required: boolean;
162
+ };
163
+ date?: undefined;
164
+ };
165
+ validate(config: any): any;
166
+ };
167
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import React from 'react';
10
+ export declare function TriggerScheduleConfig(): React.JSX.Element;
@@ -9,6 +9,8 @@
9
9
  /// <reference types="react" />
10
10
  import { SchemaInitializerItemType, useCollectionDataSource } from '@nocobase/client';
11
11
  import { Trigger } from '..';
12
+ import { TriggerScheduleConfig } from './TriggerScheduleConfig';
13
+ import { TriggerCollectionRecordSelect } from '../../components/TriggerCollectionRecordSelect';
12
14
  declare function useVariables(config: any, opts: any): any[];
13
15
  export default class extends Trigger {
14
16
  sync: boolean;
@@ -21,11 +23,20 @@ export default class extends Trigger {
21
23
  'x-component-props': {};
22
24
  };
23
25
  };
26
+ triggerFieldset: {
27
+ proxy: {
28
+ type: string;
29
+ 'x-component': string;
30
+ };
31
+ };
32
+ validate(config: any): any;
24
33
  scope: {
25
34
  useCollectionDataSource: typeof useCollectionDataSource;
26
35
  };
27
36
  components: {
28
37
  ScheduleConfig: () => import("react").JSX.Element;
38
+ TriggerScheduleConfig: typeof TriggerScheduleConfig;
39
+ TriggerCollectionRecordSelect: typeof TriggerCollectionRecordSelect;
29
40
  };
30
41
  useVariables: typeof useVariables;
31
42
  useInitializers(config: any): SchemaInitializerItemType | null;
@@ -11,24 +11,24 @@ module.exports = {
11
11
  "react": "18.2.0",
12
12
  "@formily/core": "2.3.0",
13
13
  "@formily/react": "2.3.0",
14
- "@nocobase/client": "1.5.0-alpha.5",
15
- "@nocobase/utils": "1.5.0-alpha.5",
14
+ "@nocobase/client": "1.6.0-alpha.1",
15
+ "@nocobase/utils": "1.6.0-alpha.1",
16
16
  "antd": "5.12.8",
17
17
  "@ant-design/icons": "5.2.6",
18
18
  "react-router-dom": "6.21.0",
19
19
  "react-i18next": "11.18.6",
20
20
  "@formily/shared": "2.3.2",
21
21
  "lodash": "4.17.21",
22
- "@nocobase/database": "1.5.0-alpha.5",
23
- "@nocobase/server": "1.5.0-alpha.5",
24
- "@nocobase/logger": "1.5.0-alpha.5",
25
- "@nocobase/evaluators": "1.5.0-alpha.5",
22
+ "@nocobase/database": "1.6.0-alpha.1",
23
+ "@nocobase/server": "1.6.0-alpha.1",
24
+ "@nocobase/logger": "1.6.0-alpha.1",
25
+ "@nocobase/actions": "1.6.0-alpha.1",
26
+ "@nocobase/data-source-manager": "1.6.0-alpha.1",
27
+ "@nocobase/evaluators": "1.6.0-alpha.1",
26
28
  "@formily/antd-v5": "1.1.9",
27
29
  "@formily/reactive": "2.3.0",
28
- "@nocobase/actions": "1.5.0-alpha.5",
29
30
  "dayjs": "1.11.10",
30
- "@nocobase/data-source-manager": "1.5.0-alpha.5",
31
31
  "sequelize": "6.35.2",
32
- "@nocobase/plugin-workflow-test": "1.5.0-alpha.5",
33
- "@nocobase/test": "1.5.0-alpha.5"
32
+ "@nocobase/plugin-workflow-test": "1.6.0-alpha.1",
33
+ "@nocobase/test": "1.6.0-alpha.1"
34
34
  };
@@ -16,6 +16,15 @@
16
16
  "Duplicate": "复制",
17
17
  "Duplicate to new workflow": "复制为新工作流",
18
18
  "Delete a main version will cause all other revisions to be deleted too.": "删除主版本将导致其他版本一并被删除。",
19
+ "Execute manually": "手动执行",
20
+ "The trigger is not configured correctly, please check the trigger configuration.": "触发器配置不正确,请检查触发器配置。",
21
+ "This type of trigger has not been supported to be executed manually.": "该类型的触发器暂未支持手动执行。",
22
+ "Trigger variables need to be filled for executing.": "执行需要填写触发器变量。",
23
+ "A new version will be created automatically after execution if current version is not executed.": "如果当前版本还未执行过,将在执行后自动创建一个新版本。",
24
+ "This will perform all the actions configured in the workflow. Are you sure you want to continue?": "将按照工作流中配置的所有操作执行,确定继续吗?",
25
+ "Automatically create a new version after execution": "执行后自动创建新版本",
26
+ "Workflow executed, the result status is <1>{{statusText}}</1><2>View the execution</2>": "工作流已执行,结果状态为 <1>{{statusText}}</1><2>查看执行详情</2>",
27
+
19
28
  "Loading": "加载中",
20
29
  "Load failed": "加载失败",
21
30
  "Use transaction": "启用事务",
@@ -64,6 +73,8 @@
64
73
  "Preload associations": "预加载关联数据",
65
74
  "Please select the associated fields that need to be accessed in subsequent nodes. With more than two levels of to-many associations may cause performance issue, please use with caution.":
66
75
  "请选中需要在后续节点中被访问的关系字段。超过两层的对多关联可能会导致性能问题,请谨慎使用。",
76
+ "Choose a record of the collection to trigger.": "选择数据表中的一行记录来触发。",
77
+
67
78
  "Schedule event": "定时任务",
68
79
  "Triggered according to preset time conditions. Suitable for one-time or periodic tasks, such as sending notifications and cleaning data on a schedule.": "按预设的时间条件定时触发。适用于一次性或周期性的任务,如定时发送通知、清理数据等。",
69
80
  "Trigger mode": "触发模式",
@@ -92,6 +103,9 @@
92
103
  "By field": "数据表字段",
93
104
  "By custom date": "自定义时间",
94
105
  "Advanced": "高级模式",
106
+ "Execute on": "执行时间",
107
+ "Current time": "当前时间",
108
+
95
109
  "End": "结束",
96
110
  "Node result": "节点数据",
97
111
  "Variable key of node": "节点变量标识",
@@ -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-11-23T15:57:17.219Z"}
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-12-03T15:36:12.566Z"}
@@ -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-11-23T15:57:16.824Z"}
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-12-03T15:36:12.178Z"}
@@ -15,11 +15,13 @@ import { CustomFunction } from './functions';
15
15
  import Trigger from './triggers';
16
16
  import { InstructionInterface } from './instructions';
17
17
  import type { ExecutionModel, WorkflowModel } from './types';
18
+ import { Context } from '@nocobase/actions';
18
19
  type ID = number | string;
19
- type EventOptions = {
20
+ export type EventOptions = {
20
21
  eventKey?: string;
21
22
  context?: any;
22
23
  deferred?: boolean;
24
+ manually?: boolean;
23
25
  [key: string]: any;
24
26
  } & Transactionable;
25
27
  export default class PluginWorkflowServer extends Plugin {
@@ -55,6 +57,7 @@ export default class PluginWorkflowServer extends Plugin {
55
57
  }): void;
56
58
  private initTriggers;
57
59
  private initInstructions;
60
+ beforeLoad(): Promise<void>;
58
61
  /**
59
62
  * @internal
60
63
  */
@@ -73,6 +76,7 @@ export default class PluginWorkflowServer extends Plugin {
73
76
  private prepare;
74
77
  private dispatch;
75
78
  private process;
79
+ execute(workflow: WorkflowModel, context: Context, options?: EventOptions): Promise<void | Processor>;
76
80
  /**
77
81
  * @experimental
78
82
  * @param {string} dataSourceName
@@ -58,6 +58,7 @@ var import_CreateInstruction = __toESM(require("./instructions/CreateInstruction
58
58
  var import_DestroyInstruction = __toESM(require("./instructions/DestroyInstruction"));
59
59
  var import_QueryInstruction = __toESM(require("./instructions/QueryInstruction"));
60
60
  var import_UpdateInstruction = __toESM(require("./instructions/UpdateInstruction"));
61
+ var import_WorkflowRepository = __toESM(require("./repositories/WorkflowRepository"));
61
62
  class PluginWorkflowServer extends import_server.Plugin {
62
63
  instructions = new import_utils.Registry();
63
64
  triggers = new import_utils.Registry();
@@ -75,19 +76,6 @@ class PluginWorkflowServer extends import_server.Plugin {
75
76
  const Model = instance.constructor;
76
77
  if (instance.enabled) {
77
78
  instance.set("current", true);
78
- } else if (!instance.current) {
79
- const count = await Model.count({
80
- where: {
81
- key: instance.key
82
- },
83
- transaction
84
- });
85
- if (!count) {
86
- instance.set("current", true);
87
- }
88
- }
89
- if (!instance.changed("enabled") || !instance.enabled) {
90
- return;
91
79
  }
92
80
  const previous = await Model.findOne({
93
81
  where: {
@@ -99,7 +87,10 @@ class PluginWorkflowServer extends import_server.Plugin {
99
87
  },
100
88
  transaction
101
89
  });
102
- if (previous) {
90
+ if (!previous) {
91
+ instance.set("current", true);
92
+ }
93
+ if (instance.current && previous) {
103
94
  await previous.update(
104
95
  { enabled: false, current: null },
105
96
  {
@@ -198,6 +189,11 @@ class PluginWorkflowServer extends import_server.Plugin {
198
189
  this.registerInstruction(name, instruction);
199
190
  }
200
191
  }
192
+ async beforeLoad() {
193
+ this.db.registerRepositories({
194
+ WorkflowRepository: import_WorkflowRepository.default
195
+ });
196
+ }
201
197
  /**
202
198
  * @internal
203
199
  */
@@ -322,20 +318,20 @@ class PluginWorkflowServer extends import_server.Plugin {
322
318
  }
323
319
  trigger(workflow, context, options = {}) {
324
320
  const logger = this.getLogger(workflow.id);
325
- if (!workflow.enabled) {
326
- logger.warn(`workflow ${workflow.id} is not enabled, event will be ignored`);
327
- return;
328
- }
329
321
  if (!this.ready) {
330
322
  logger.warn(`app is not ready, event of workflow ${workflow.id} will be ignored`);
331
323
  logger.debug(`ignored event data:`, context);
332
324
  return;
333
325
  }
326
+ if (!options.manually && !workflow.enabled) {
327
+ logger.warn(`workflow ${workflow.id} is not enabled, event will be ignored`);
328
+ return;
329
+ }
334
330
  if (context == null) {
335
331
  logger.warn(`workflow ${workflow.id} event data context is null, event will be ignored`);
336
332
  return;
337
333
  }
338
- if (this.isWorkflowSync(workflow)) {
334
+ if (options.manually || this.isWorkflowSync(workflow)) {
339
335
  return this.triggerSync(workflow, context, options);
340
336
  }
341
337
  const { transaction, ...rest } = options;
@@ -388,11 +384,13 @@ class PluginWorkflowServer extends import_server.Plugin {
388
384
  return new import_Processor.default(execution, { ...options, plugin: this });
389
385
  }
390
386
  async createExecution(workflow, context, options) {
391
- const { transaction = await this.db.sequelize.transaction(), deferred } = options;
387
+ const { deferred } = options;
388
+ const transaction = await this.useDataSourceTransaction("main", options.transaction, true);
389
+ const sameTransaction = options.transaction === transaction;
392
390
  const trigger = this.triggers.get(workflow.type);
393
391
  const valid = await trigger.validateEvent(workflow, context, { ...options, transaction });
394
392
  if (!valid) {
395
- if (!options.transaction) {
393
+ if (!sameTransaction) {
396
394
  await transaction.commit();
397
395
  }
398
396
  return null;
@@ -409,7 +407,7 @@ class PluginWorkflowServer extends import_server.Plugin {
409
407
  { transaction }
410
408
  );
411
409
  } catch (err) {
412
- if (!options.transaction) {
410
+ if (!sameTransaction) {
413
411
  await transaction.rollback();
414
412
  }
415
413
  throw err;
@@ -430,7 +428,7 @@ class PluginWorkflowServer extends import_server.Plugin {
430
428
  transaction
431
429
  }
432
430
  );
433
- if (!options.transaction) {
431
+ if (!sameTransaction) {
434
432
  await transaction.commit();
435
433
  }
436
434
  execution.workflow = workflow;
@@ -527,6 +525,16 @@ class PluginWorkflowServer extends import_server.Plugin {
527
525
  }
528
526
  return processor;
529
527
  }
528
+ async execute(workflow, context, options = {}) {
529
+ const trigger = this.triggers.get(workflow.type);
530
+ if (!trigger) {
531
+ throw new Error(`trigger type "${workflow.type}" of workflow ${workflow.id} is not registered`);
532
+ }
533
+ if (!trigger.execute) {
534
+ throw new Error(`"execute" method of trigger ${workflow.type} is not implemented`);
535
+ }
536
+ return trigger.execute(workflow, context, options);
537
+ }
530
538
  /**
531
539
  * @experimental
532
540
  * @param {string} dataSourceName
@@ -11,4 +11,9 @@ export declare function update(context: Context, next: any): Promise<void>;
11
11
  export declare function destroy(context: Context, next: any): Promise<void>;
12
12
  export declare function revision(context: Context, next: any): Promise<void>;
13
13
  export declare function sync(context: Context, next: any): Promise<void>;
14
+ /**
15
+ * @deprecated
16
+ * Keep for action trigger compatibility
17
+ */
14
18
  export declare function trigger(context: Context, next: any): Promise<any>;
19
+ export declare function execute(context: Context, next: any): Promise<any>;
@@ -37,6 +37,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
37
37
  var workflows_exports = {};
38
38
  __export(workflows_exports, {
39
39
  destroy: () => destroy,
40
+ execute: () => execute,
40
41
  revision: () => revision,
41
42
  sync: () => sync,
42
43
  trigger: () => trigger,
@@ -90,69 +91,13 @@ async function destroy(context, next) {
90
91
  next();
91
92
  }
92
93
  async function revision(context, next) {
93
- const plugin = context.app.getPlugin(import_Plugin.default);
94
94
  const repository = import_actions.utils.getRepositoryFromParams(context);
95
95
  const { filterByTk, filter = {}, values = {} } = context.action.params;
96
- context.body = await context.db.sequelize.transaction(async (transaction) => {
97
- const origin = await repository.findOne({
98
- filterByTk,
99
- filter,
100
- appends: ["nodes"],
101
- context,
102
- transaction
103
- });
104
- const trigger2 = plugin.triggers.get(origin.type);
105
- const revisionData = filter.key ? {
106
- key: filter.key,
107
- title: origin.title,
108
- triggerTitle: origin.triggerTitle,
109
- allExecuted: origin.allExecuted
110
- } : values;
111
- const instance = await repository.create({
112
- values: {
113
- title: `${origin.title} copy`,
114
- description: origin.description,
115
- ...revisionData,
116
- sync: origin.sync,
117
- type: origin.type,
118
- config: typeof trigger2.duplicateConfig === "function" ? await trigger2.duplicateConfig(origin, { transaction }) : origin.config
119
- },
120
- transaction
121
- });
122
- const originalNodesMap = /* @__PURE__ */ new Map();
123
- origin.nodes.forEach((node) => {
124
- originalNodesMap.set(node.id, node);
125
- });
126
- const oldToNew = /* @__PURE__ */ new Map();
127
- const newToOld = /* @__PURE__ */ new Map();
128
- for await (const node of origin.nodes) {
129
- const instruction = plugin.instructions.get(node.type);
130
- const newNode = await instance.createNode(
131
- {
132
- type: node.type,
133
- key: node.key,
134
- config: typeof instruction.duplicateConfig === "function" ? await instruction.duplicateConfig(node, { transaction }) : node.config,
135
- title: node.title,
136
- branchIndex: node.branchIndex
137
- },
138
- { transaction }
139
- );
140
- oldToNew.set(node.id, newNode);
141
- newToOld.set(newNode.id, node);
142
- }
143
- for await (const [oldId, newNode] of oldToNew.entries()) {
144
- const oldNode = originalNodesMap.get(oldId);
145
- const newUpstream = oldNode.upstreamId ? oldToNew.get(oldNode.upstreamId) : null;
146
- const newDownstream = oldNode.downstreamId ? oldToNew.get(oldNode.downstreamId) : null;
147
- await newNode.update(
148
- {
149
- upstreamId: (newUpstream == null ? void 0 : newUpstream.id) ?? null,
150
- downstreamId: (newDownstream == null ? void 0 : newDownstream.id) ?? null
151
- },
152
- { transaction }
153
- );
154
- }
155
- return instance;
96
+ context.body = await repository.revision({
97
+ filterByTk,
98
+ filter,
99
+ values,
100
+ context
156
101
  });
157
102
  await next();
158
103
  }
@@ -174,9 +119,59 @@ async function sync(context, next) {
174
119
  async function trigger(context, next) {
175
120
  return next();
176
121
  }
122
+ async function execute(context, next) {
123
+ const plugin = context.app.pm.get(import_Plugin.default);
124
+ const { filterByTk, autoRevision } = context.action.params;
125
+ if (!filterByTk) {
126
+ return context.throw(400, "filterByTk is required");
127
+ }
128
+ const id = Number.parseInt(filterByTk, 10);
129
+ if (Number.isNaN(id)) {
130
+ return context.throw(400, "filterByTk is invalid");
131
+ }
132
+ const repository = import_actions.utils.getRepositoryFromParams(context);
133
+ const workflow = plugin.enabledCache.get(id) || await repository.findOne({ filterByTk });
134
+ if (!workflow) {
135
+ return context.throw(404, "workflow not found");
136
+ }
137
+ const { executed } = workflow;
138
+ let processor;
139
+ try {
140
+ processor = await plugin.execute(workflow, context, { manually: true });
141
+ if (!processor) {
142
+ return context.throw(400, "workflow not triggered");
143
+ }
144
+ } catch (ex) {
145
+ return context.throw(400, ex.message);
146
+ }
147
+ context.action.mergeParams({
148
+ filter: { key: workflow.key }
149
+ });
150
+ let newVersion;
151
+ if (!executed && autoRevision) {
152
+ newVersion = await repository.revision({
153
+ filterByTk: workflow.id,
154
+ filter: { key: workflow.key },
155
+ values: {
156
+ current: workflow.current,
157
+ enabled: workflow.enabled
158
+ },
159
+ context
160
+ });
161
+ }
162
+ context.body = {
163
+ execution: {
164
+ id: processor.execution.id,
165
+ status: processor.execution.status
166
+ },
167
+ newVersionId: newVersion == null ? void 0 : newVersion.id
168
+ };
169
+ return next();
170
+ }
177
171
  // Annotate the CommonJS export names for ESM import in node:
178
172
  0 && (module.exports = {
179
173
  destroy,
174
+ execute,
180
175
  revision,
181
176
  sync,
182
177
  trigger,