@nocobase/plugin-workflow 2.1.0-alpha.4 → 2.1.0-alpha.45

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 (185) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/dist/client/214.7e602cfe7a8251b8.js +10 -0
  4. package/dist/client/618.19af7f84261c815d.js +10 -0
  5. package/dist/client/67.452743ce8ec30617.js +10 -0
  6. package/dist/client/964.ffbf5b47ed12bbdc.js +10 -0
  7. package/dist/client/Branch.d.ts +7 -3
  8. package/dist/client/BranchContext.d.ts +18 -0
  9. package/dist/client/components/TimeoutInput.d.ts +11 -0
  10. package/dist/client/constants.d.ts +13 -0
  11. package/dist/client/flows/triggerWorkflows.d.ts +14 -1
  12. package/dist/client/hooks/{useWorkflowFilterActionProps.d.ts → useResourceFilterActionProps.d.ts} +1 -1
  13. package/dist/client/index.js +1 -1
  14. package/dist/client/nodes/create.d.ts +10 -0
  15. package/dist/client/nodes/destroy.d.ts +10 -0
  16. package/dist/client/nodes/index.d.ts +5 -0
  17. package/dist/client/nodes/query.d.ts +18 -2
  18. package/dist/client/nodes/update.d.ts +10 -0
  19. package/dist/client/schemas/collection.d.ts +8 -2
  20. package/dist/client/schemas/executions.d.ts +62 -2
  21. package/dist/client/triggers/collection.d.ts +14 -1
  22. package/dist/client/triggers/index.d.ts +4 -0
  23. package/dist/client/triggers/schedule/constants.d.ts +4 -0
  24. package/dist/client/triggers/schedule/index.d.ts +15 -0
  25. package/dist/client/utils.d.ts +17 -0
  26. package/dist/common/collections/executions.d.ts +43 -1
  27. package/dist/common/collections/executions.js +62 -1
  28. package/dist/common/collections/jobs.js +7 -0
  29. package/dist/common/collections/workflows.d.ts +65 -11
  30. package/dist/common/collections/workflows.js +34 -2
  31. package/dist/common/constants.d.ts +5 -0
  32. package/dist/common/constants.js +7 -0
  33. package/dist/externalVersion.js +15 -13
  34. package/dist/locale/de-DE.json +4 -0
  35. package/dist/locale/en-US.json +7 -0
  36. package/dist/locale/es-ES.json +4 -0
  37. package/dist/locale/fr-FR.json +4 -0
  38. package/dist/locale/hu-HU.json +7 -3
  39. package/dist/locale/id-ID.json +4 -0
  40. package/dist/locale/it-IT.json +4 -0
  41. package/dist/locale/ja-JP.json +5 -1
  42. package/dist/locale/ko-KR.json +4 -0
  43. package/dist/locale/nl-NL.json +7 -3
  44. package/dist/locale/pt-BR.json +4 -0
  45. package/dist/locale/ru-RU.json +4 -0
  46. package/dist/locale/tr-TR.json +4 -0
  47. package/dist/locale/uk-UA.json +7 -3
  48. package/dist/locale/vi-VN.json +7 -3
  49. package/dist/locale/zh-CN.json +12 -1
  50. package/dist/locale/zh-TW.json +7 -3
  51. package/dist/node_modules/cron-parser/lib/parser.js +1 -1
  52. package/dist/node_modules/cron-parser/package.json +1 -1
  53. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  54. package/dist/node_modules/joi/lib/annotate.js +175 -0
  55. package/dist/node_modules/joi/lib/base.js +1069 -0
  56. package/dist/node_modules/joi/lib/cache.js +143 -0
  57. package/dist/node_modules/joi/lib/common.js +216 -0
  58. package/dist/node_modules/joi/lib/compile.js +283 -0
  59. package/dist/node_modules/joi/lib/errors.js +271 -0
  60. package/dist/node_modules/joi/lib/extend.js +312 -0
  61. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  62. package/dist/node_modules/joi/lib/index.js +1 -0
  63. package/dist/node_modules/joi/lib/manifest.js +476 -0
  64. package/dist/node_modules/joi/lib/messages.js +178 -0
  65. package/dist/node_modules/joi/lib/modify.js +267 -0
  66. package/dist/node_modules/joi/lib/ref.js +414 -0
  67. package/dist/node_modules/joi/lib/schemas.js +302 -0
  68. package/dist/node_modules/joi/lib/state.js +166 -0
  69. package/dist/node_modules/joi/lib/template.js +463 -0
  70. package/dist/node_modules/joi/lib/trace.js +346 -0
  71. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  72. package/dist/node_modules/joi/lib/types/any.js +174 -0
  73. package/dist/node_modules/joi/lib/types/array.js +809 -0
  74. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  75. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  76. package/dist/node_modules/joi/lib/types/date.js +233 -0
  77. package/dist/node_modules/joi/lib/types/function.js +93 -0
  78. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  79. package/dist/node_modules/joi/lib/types/link.js +168 -0
  80. package/dist/node_modules/joi/lib/types/number.js +363 -0
  81. package/dist/node_modules/joi/lib/types/object.js +22 -0
  82. package/dist/node_modules/joi/lib/types/string.js +850 -0
  83. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  84. package/dist/node_modules/joi/lib/validator.js +750 -0
  85. package/dist/node_modules/joi/lib/values.js +263 -0
  86. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  87. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  88. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  89. package/dist/node_modules/joi/package.json +1 -0
  90. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts +5 -0
  91. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +10 -0
  92. package/dist/node_modules/lru-cache/dist/commonjs/index.d.ts +1381 -0
  93. package/dist/node_modules/lru-cache/dist/commonjs/index.js +1692 -0
  94. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -0
  95. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.d.ts +5 -0
  96. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  97. package/dist/node_modules/lru-cache/dist/esm/browser/index.d.ts +1381 -0
  98. package/dist/node_modules/lru-cache/dist/{mjs → esm/browser}/index.js +537 -179
  99. package/dist/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  100. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.d.ts +5 -0
  101. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  102. package/dist/node_modules/lru-cache/dist/esm/index.d.ts +1381 -0
  103. package/dist/node_modules/lru-cache/dist/{cjs → esm}/index.js +538 -184
  104. package/dist/node_modules/lru-cache/dist/esm/index.min.js +2 -0
  105. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.d.ts +5 -0
  106. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +7 -0
  107. package/dist/node_modules/lru-cache/dist/esm/node/index.d.ts +1381 -0
  108. package/dist/node_modules/lru-cache/dist/esm/node/index.js +1688 -0
  109. package/dist/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  110. package/dist/node_modules/lru-cache/package.json +1 -1
  111. package/dist/node_modules/nodejs-snowflake/nodejs_snowflake.js +1 -1
  112. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  113. package/dist/server/Dispatcher.d.ts +9 -6
  114. package/dist/server/Dispatcher.js +241 -160
  115. package/dist/server/ExecutionTimeoutManager.d.ts +45 -0
  116. package/dist/server/ExecutionTimeoutManager.js +312 -0
  117. package/dist/server/Plugin.d.ts +13 -0
  118. package/dist/server/Plugin.js +49 -4
  119. package/dist/server/Processor.d.ts +65 -9
  120. package/dist/server/Processor.js +285 -33
  121. package/dist/server/RunningExecutionRegistry.d.ts +18 -0
  122. package/dist/server/RunningExecutionRegistry.js +48 -0
  123. package/dist/server/actions/executions.d.ts +4 -3
  124. package/dist/server/actions/executions.js +42 -21
  125. package/dist/server/actions/jobs.d.ts +2 -1
  126. package/dist/server/actions/jobs.js +28 -1
  127. package/dist/server/actions/nodes.d.ts +5 -0
  128. package/dist/server/actions/nodes.js +38 -5
  129. package/dist/server/actions/workflows.d.ts +6 -0
  130. package/dist/server/actions/workflows.js +38 -0
  131. package/dist/server/constants.d.ts +2 -0
  132. package/dist/server/constants.js +3 -0
  133. package/dist/server/index.d.ts +2 -0
  134. package/dist/server/index.js +2 -0
  135. package/dist/server/instructions/ConditionInstruction.d.ts +2 -0
  136. package/dist/server/instructions/ConditionInstruction.js +17 -0
  137. package/dist/server/instructions/CreateInstruction.d.ts +3 -0
  138. package/dist/server/instructions/CreateInstruction.js +25 -0
  139. package/dist/server/instructions/DestroyInstruction.d.ts +3 -0
  140. package/dist/server/instructions/DestroyInstruction.js +25 -0
  141. package/dist/server/instructions/EndInstruction.d.ts +2 -0
  142. package/dist/server/instructions/EndInstruction.js +4 -0
  143. package/dist/server/instructions/MultiConditionsInstruction.d.ts +2 -0
  144. package/dist/server/instructions/MultiConditionsInstruction.js +23 -0
  145. package/dist/server/instructions/OutputInstruction.d.ts +2 -0
  146. package/dist/server/instructions/OutputInstruction.js +14 -0
  147. package/dist/server/instructions/QueryInstruction.d.ts +3 -0
  148. package/dist/server/instructions/QueryInstruction.js +32 -7
  149. package/dist/server/instructions/UpdateInstruction.d.ts +3 -0
  150. package/dist/server/instructions/UpdateInstruction.js +27 -0
  151. package/dist/server/instructions/index.d.ts +24 -4
  152. package/dist/server/instructions/index.js +18 -0
  153. package/dist/server/migrations/20260423225800-fill-workflow-created-updated-by.d.ts +13 -0
  154. package/dist/server/migrations/20260423225800-fill-workflow-created-updated-by.js +57 -0
  155. package/dist/server/migrations/20260501120000-workflow-timeout.d.ts +13 -0
  156. package/dist/server/migrations/20260501120000-workflow-timeout.js +63 -0
  157. package/dist/server/timeout-errors.d.ts +13 -0
  158. package/dist/server/timeout-errors.js +47 -0
  159. package/dist/server/triggers/CollectionTrigger.d.ts +3 -0
  160. package/dist/server/triggers/CollectionTrigger.js +28 -0
  161. package/dist/server/triggers/ScheduleTrigger/index.d.ts +3 -0
  162. package/dist/server/triggers/ScheduleTrigger/index.js +18 -3
  163. package/dist/server/triggers/index.d.ts +3 -0
  164. package/dist/server/triggers/index.js +18 -0
  165. package/dist/server/types/Execution.d.ts +6 -0
  166. package/dist/server/types/Job.d.ts +3 -3
  167. package/dist/server/types/Workflow.d.ts +6 -1
  168. package/dist/server/utils.d.ts +27 -0
  169. package/dist/server/utils.js +138 -2
  170. package/dist/swagger/index.d.ts +849 -106
  171. package/dist/swagger/index.js +969 -208
  172. package/package.json +6 -5
  173. package/dist/client/27bd65abee87cafa.js +0 -10
  174. package/dist/client/478692c1637f2742.js +0 -10
  175. package/dist/client/c1347b9d21f864d9.js +0 -10
  176. package/dist/client/f39e94207f92e352.js +0 -10
  177. package/dist/node_modules/lru-cache/LICENSE +0 -15
  178. package/dist/node_modules/lru-cache/dist/cjs/index-cjs.d.ts +0 -7
  179. package/dist/node_modules/lru-cache/dist/cjs/index-cjs.js +0 -1
  180. package/dist/node_modules/lru-cache/dist/cjs/index.d.ts +0 -807
  181. package/dist/node_modules/lru-cache/dist/cjs/index.min.js +0 -2
  182. package/dist/node_modules/lru-cache/dist/mjs/index.d.ts +0 -807
  183. package/dist/node_modules/lru-cache/dist/mjs/index.min.js +0 -2
  184. /package/dist/node_modules/lru-cache/dist/{cjs → commonjs}/package.json +0 -0
  185. /package/dist/node_modules/lru-cache/dist/{mjs → esm}/package.json +0 -0
@@ -7,9 +7,11 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
+ var __create = Object.create;
10
11
  var __defProp = Object.defineProperty;
11
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
13
15
  var __hasOwnProp = Object.prototype.hasOwnProperty;
14
16
  var __export = (target, all) => {
15
17
  for (var name in all)
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
23
25
  }
24
26
  return to;
25
27
  };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
26
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
37
  var QueryInstruction_exports = {};
28
38
  __export(QueryInstruction_exports, {
@@ -30,22 +40,37 @@ __export(QueryInstruction_exports, {
30
40
  default: () => QueryInstruction_default
31
41
  });
32
42
  module.exports = __toCommonJS(QueryInstruction_exports);
43
+ var import_joi = __toESM(require("joi"));
33
44
  var import_actions = require("@nocobase/actions");
34
45
  var import_data_source_manager = require("@nocobase/data-source-manager");
35
46
  var import_constants = require("../constants");
36
47
  var import_utils = require("../utils");
37
48
  var import__ = require(".");
38
49
  class QueryInstruction extends import__.Instruction {
50
+ configSchema = import_joi.default.object({
51
+ collection: import_joi.default.string().required().messages({ "any.required": "Collection is not configured" }),
52
+ multiple: import_joi.default.boolean(),
53
+ params: import_joi.default.object({
54
+ filter: import_joi.default.object(),
55
+ appends: import_joi.default.array().items(import_joi.default.string()),
56
+ page: import_joi.default.alternatives(import_joi.default.number(), import_joi.default.string()),
57
+ pageSize: import_joi.default.alternatives(import_joi.default.number(), import_joi.default.string()),
58
+ sort: import_joi.default.array().items(import_joi.default.object({ field: import_joi.default.string(), direction: import_joi.default.string().allow("asc", "desc") }))
59
+ }),
60
+ failOnEmpty: import_joi.default.boolean()
61
+ });
62
+ validateConfig(config) {
63
+ const errors = super.validateConfig(config);
64
+ if (errors) {
65
+ return errors;
66
+ }
67
+ return (0, import_utils.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
68
+ }
39
69
  async run(node, input, processor) {
40
70
  const { collection, multiple, params = {}, failOnEmpty = false } = node.config;
41
71
  const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
42
72
  const { repository } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
43
- const {
44
- page = import_actions.DEFAULT_PAGE,
45
- pageSize = import_actions.DEFAULT_PER_PAGE,
46
- sort = [],
47
- ...options
48
- } = processor.getParsedValue(params, node.id);
73
+ const { page, pageSize, sort = [], ...options } = processor.getParsedValue(params, node.id);
49
74
  const appends = options.appends ? Array.from(
50
75
  options.appends.reduce((set, field) => {
51
76
  set.add(field.split(".")[0]);
@@ -55,7 +80,7 @@ class QueryInstruction extends import__.Instruction {
55
80
  ) : options.appends;
56
81
  const result = await (multiple ? repository.find : repository.findOne).call(repository, {
57
82
  ...options,
58
- ...import_actions.utils.pageArgsToLimitArgs(page, pageSize),
83
+ ...import_actions.utils.pageArgsToLimitArgs(page ?? import_actions.DEFAULT_PAGE, pageSize ?? import_actions.DEFAULT_PER_PAGE),
59
84
  sort: sort.filter((item) => item.field).map((item) => {
60
85
  var _a;
61
86
  return `${((_a = item.direction) == null ? void 0 : _a.toLowerCase()) === "desc" ? "-" : ""}${item.field}`;
@@ -6,10 +6,13 @@
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 Joi from 'joi';
9
10
  import type Processor from '../Processor';
10
11
  import type { FlowNodeModel } from '../types';
11
12
  import { Instruction } from '.';
12
13
  export declare class UpdateInstruction extends Instruction {
14
+ configSchema: Joi.ObjectSchema<any>;
15
+ validateConfig(config: Record<string, any>): Record<string, string>;
13
16
  run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
14
17
  result: any;
15
18
  status: 1;
@@ -7,9 +7,11 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
+ var __create = Object.create;
10
11
  var __defProp = Object.defineProperty;
11
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
13
15
  var __hasOwnProp = Object.prototype.hasOwnProperty;
14
16
  var __export = (target, all) => {
15
17
  for (var name in all)
@@ -23,6 +25,14 @@ var __copyProps = (to, from, except, desc) => {
23
25
  }
24
26
  return to;
25
27
  };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
26
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
37
  var UpdateInstruction_exports = {};
28
38
  __export(UpdateInstruction_exports, {
@@ -30,10 +40,27 @@ __export(UpdateInstruction_exports, {
30
40
  default: () => UpdateInstruction_default
31
41
  });
32
42
  module.exports = __toCommonJS(UpdateInstruction_exports);
43
+ var import_joi = __toESM(require("joi"));
33
44
  var import_data_source_manager = require("@nocobase/data-source-manager");
34
45
  var import_constants = require("../constants");
46
+ var import_utils = require("../utils");
35
47
  var import__ = require(".");
36
48
  class UpdateInstruction extends import__.Instruction {
49
+ configSchema = import_joi.default.object({
50
+ collection: import_joi.default.string().required().messages({ "any.required": "Collection is not configured" }),
51
+ params: import_joi.default.object({
52
+ individualHooks: import_joi.default.boolean(),
53
+ filter: import_joi.default.object(),
54
+ values: import_joi.default.object()
55
+ })
56
+ });
57
+ validateConfig(config) {
58
+ const errors = super.validateConfig(config);
59
+ if (errors) {
60
+ return errors;
61
+ }
62
+ return (0, import_utils.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
63
+ }
37
64
  async run(node, input, processor) {
38
65
  const { collection, params = {} } = node.config;
39
66
  const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
@@ -6,17 +6,30 @@
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 Joi from 'joi';
9
10
  import { Transactionable } from '@nocobase/database';
10
11
  import type Plugin from '../Plugin';
11
12
  import type Processor from '../Processor';
12
- import type { FlowNodeModel } from '../types';
13
+ import type { FlowNodeModel, WorkflowModel } from '../types';
13
14
  export interface IJob {
14
15
  status: number;
15
16
  result?: unknown;
17
+ log?: string;
16
18
  [key: string]: unknown;
17
19
  }
18
- export type InstructionResult = IJob | Promise<IJob> | Promise<void> | null | void;
19
- export type Runner = (node: FlowNodeModel, input: any, processor: Processor) => InstructionResult;
20
+ /**
21
+ * The result of an instruction execution.
22
+ *
23
+ * Different type of result will cause according behavior in the workflow engine:
24
+ * 1. IJob | Promise<IJob>: processor will continue default processing by checking the status.
25
+ * 2. `null` | Promise<null>: processor will do exit process.
26
+ * 3. `void` | Promise<void>: processor will do nothing, and terminate the current execution without any action.
27
+ */
28
+ export type InstructionResult = IJob | null | void;
29
+ export type Runner = (node: FlowNodeModel, input: any, processor: Processor, options?: {
30
+ rerun?: true;
31
+ signal?: AbortSignal;
32
+ }) => InstructionResult | Promise<InstructionResult>;
20
33
  export type InstructionInterface = {
21
34
  run: Runner;
22
35
  resume?: Runner;
@@ -24,11 +37,18 @@ export type InstructionInterface = {
24
37
  duplicateConfig?: (node: FlowNodeModel, options: Transactionable & {
25
38
  origin?: FlowNodeModel;
26
39
  }) => object | Promise<object>;
40
+ validateConfig?: (config: Record<string, any>) => Record<string, string> | null;
41
+ isAvailable?: (workflow: WorkflowModel, node: FlowNodeModel) => boolean;
27
42
  test?: (config: Record<string, any>) => IJob | Promise<IJob>;
28
43
  };
29
44
  export declare abstract class Instruction implements InstructionInterface {
30
45
  workflow: Plugin;
46
+ configSchema?: Joi.ObjectSchema;
31
47
  constructor(workflow: Plugin);
32
- abstract run(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
48
+ validateConfig(config: Record<string, any>): Record<string, string> | null;
49
+ abstract run(node: FlowNodeModel, input: any, processor: Processor, options?: {
50
+ rerun?: true;
51
+ signal?: AbortSignal;
52
+ }): InstructionResult | Promise<InstructionResult>;
33
53
  }
34
54
  export default Instruction;
@@ -34,6 +34,24 @@ class Instruction {
34
34
  constructor(workflow) {
35
35
  this.workflow = workflow;
36
36
  }
37
+ configSchema;
38
+ validateConfig(config) {
39
+ if (!this.configSchema) {
40
+ return null;
41
+ }
42
+ const { error } = this.configSchema.validate(config, { abortEarly: false, allowUnknown: true });
43
+ if (!error) {
44
+ return null;
45
+ }
46
+ const errors = {};
47
+ for (const detail of error.details) {
48
+ const key = detail.path.join(".");
49
+ if (!errors[key]) {
50
+ errors[key] = detail.message;
51
+ }
52
+ }
53
+ return errors;
54
+ }
37
55
  }
38
56
  var instructions_default = Instruction;
39
57
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,13 @@
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 { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ appVersion: string;
12
+ up(): Promise<void>;
13
+ }
@@ -0,0 +1,57 @@
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
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var fill_workflow_created_updated_by_exports = {};
28
+ __export(fill_workflow_created_updated_by_exports, {
29
+ default: () => fill_workflow_created_updated_by_default
30
+ });
31
+ module.exports = __toCommonJS(fill_workflow_created_updated_by_exports);
32
+ var import_sequelize = require("sequelize");
33
+ var import_server = require("@nocobase/server");
34
+ class fill_workflow_created_updated_by_default extends import_server.Migration {
35
+ appVersion = "<2.1.0-beta.23";
36
+ async up() {
37
+ const { db } = this.context;
38
+ const WorkflowModel = db.getModel("workflows");
39
+ await db.sequelize.transaction(async (transaction) => {
40
+ await WorkflowModel.update(
41
+ {
42
+ createdById: 1,
43
+ updatedById: 1
44
+ },
45
+ {
46
+ where: {
47
+ createdById: {
48
+ [import_sequelize.Op.is]: null
49
+ }
50
+ },
51
+ silent: true,
52
+ transaction
53
+ }
54
+ );
55
+ });
56
+ }
57
+ }
@@ -0,0 +1,13 @@
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 { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ appVersion: string;
12
+ up(): Promise<void>;
13
+ }
@@ -0,0 +1,63 @@
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
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var workflow_timeout_exports = {};
28
+ __export(workflow_timeout_exports, {
29
+ default: () => workflow_timeout_default
30
+ });
31
+ module.exports = __toCommonJS(workflow_timeout_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class workflow_timeout_default extends import_server.Migration {
34
+ appVersion = "<2.1.0-beta.26";
35
+ async up() {
36
+ const { db } = this.context;
37
+ const executionCollection = db.getCollection("executions");
38
+ const tableInfo = executionCollection.getTableNameWithSchema();
39
+ const statusColumn = executionCollection.getField("status").columnName();
40
+ const expiresAtColumn = executionCollection.getField("expiresAt").columnName();
41
+ const parentExecutionIdColumn = executionCollection.getField("parentExecutionId").columnName();
42
+ await db.sequelize.transaction(async (transaction) => {
43
+ const tableExists = await this.queryInterface.tableExists(tableInfo, { transaction });
44
+ if (!tableExists) {
45
+ return;
46
+ }
47
+ const indexes = await this.queryInterface.showIndex(tableInfo, { transaction });
48
+ const indexNames = new Set(indexes.map((index) => index.name));
49
+ if (!indexNames.has("executions_status_expires_at")) {
50
+ await this.queryInterface.addIndex(tableInfo, [statusColumn, expiresAtColumn], {
51
+ name: "executions_status_expires_at",
52
+ transaction
53
+ });
54
+ }
55
+ if (!indexNames.has("executions_parent_execution_status")) {
56
+ await this.queryInterface.addIndex(tableInfo, [parentExecutionIdColumn, statusColumn], {
57
+ name: "executions_parent_execution_status",
58
+ transaction
59
+ });
60
+ }
61
+ });
62
+ }
63
+ }
@@ -0,0 +1,13 @@
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 class WorkflowTimeoutError extends Error {
10
+ code: string;
11
+ constructor(message?: string);
12
+ }
13
+ export declare function isWorkflowTimeoutError(error: any): boolean;
@@ -0,0 +1,47 @@
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
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var timeout_errors_exports = {};
28
+ __export(timeout_errors_exports, {
29
+ WorkflowTimeoutError: () => WorkflowTimeoutError,
30
+ isWorkflowTimeoutError: () => isWorkflowTimeoutError
31
+ });
32
+ module.exports = __toCommonJS(timeout_errors_exports);
33
+ class WorkflowTimeoutError extends Error {
34
+ code = "WORKFLOW_TIMEOUT";
35
+ constructor(message = "Workflow execution timed out") {
36
+ super(message);
37
+ this.name = "WorkflowTimeoutError";
38
+ }
39
+ }
40
+ function isWorkflowTimeoutError(error) {
41
+ return error instanceof WorkflowTimeoutError || (error == null ? void 0 : error.name) === "WorkflowTimeoutError" || (error == null ? void 0 : error.code) === "WORKFLOW_TIMEOUT";
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ WorkflowTimeoutError,
46
+ isWorkflowTimeoutError
47
+ });
@@ -6,6 +6,7 @@
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 Joi from 'joi';
9
10
  import { Model } from '@nocobase/database';
10
11
  import Trigger from '.';
11
12
  import type { WorkflowModel } from '../types';
@@ -18,6 +19,8 @@ export interface CollectionChangeTriggerConfig {
18
19
  }
19
20
  export default class CollectionTrigger extends Trigger {
20
21
  readonly workflow: PluginWorkflowServer;
22
+ configSchema: Joi.ObjectSchema<any>;
23
+ validateConfig(config: Record<string, any>): Record<string, string>;
21
24
  events: Map<any, any>;
22
25
  constructor(workflow: PluginWorkflowServer);
23
26
  private static handler;
@@ -39,6 +39,7 @@ __export(CollectionTrigger_exports, {
39
39
  default: () => CollectionTrigger
40
40
  });
41
41
  module.exports = __toCommonJS(CollectionTrigger_exports);
42
+ var import_joi = __toESM(require("joi"));
42
43
  var import_lodash = require("lodash");
43
44
  var import_utils = require("@nocobase/utils");
44
45
  var import_database = require("@nocobase/database");
@@ -81,6 +82,33 @@ class CollectionTrigger extends import__.default {
81
82
  }
82
83
  });
83
84
  }
85
+ configSchema = import_joi.default.object({
86
+ collection: import_joi.default.string().required(),
87
+ mode: import_joi.default.number().valid(
88
+ MODE_BITMAP.CREATE,
89
+ MODE_BITMAP.UPDATE,
90
+ MODE_BITMAP.DESTROY,
91
+ MODE_BITMAP.CREATE | MODE_BITMAP.UPDATE
92
+ ),
93
+ changed: import_joi.default.when("mode", {
94
+ is: (mode) => (mode & MODE_BITMAP.UPDATE) === MODE_BITMAP.UPDATE,
95
+ then: import_joi.default.array().items(import_joi.default.string()).optional(),
96
+ otherwise: import_joi.default.forbidden()
97
+ }),
98
+ condition: import_joi.default.object(),
99
+ appends: import_joi.default.when("mode", {
100
+ is: (mode) => mode !== MODE_BITMAP.DESTROY,
101
+ then: import_joi.default.array().items(import_joi.default.string()).optional(),
102
+ otherwise: import_joi.default.forbidden()
103
+ })
104
+ });
105
+ validateConfig(config) {
106
+ const errors = super.validateConfig(config);
107
+ if (errors) {
108
+ return errors;
109
+ }
110
+ return (0, import_utils2.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
111
+ }
84
112
  events = /* @__PURE__ */ new Map();
85
113
  // async function, should return promise
86
114
  static async handler(workflowId, eventType, data, options) {
@@ -6,10 +6,13 @@
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 Joi from 'joi';
9
10
  import Trigger from '..';
10
11
  import type Plugin from '../../Plugin';
11
12
  import { WorkflowModel } from '../../types';
12
13
  export default class ScheduleTrigger extends Trigger {
14
+ configSchema: Joi.ObjectSchema<any>;
15
+ validateConfig(config: Record<string, any>): Record<string, string>;
13
16
  sync: boolean;
14
17
  private modes;
15
18
  constructor(workflow: Plugin);
@@ -39,17 +39,32 @@ __export(ScheduleTrigger_exports, {
39
39
  default: () => ScheduleTrigger
40
40
  });
41
41
  module.exports = __toCommonJS(ScheduleTrigger_exports);
42
+ var import_joi = __toESM(require("joi"));
42
43
  var import__ = __toESM(require(".."));
44
+ var import_utils = require("../../utils");
43
45
  var import_DateFieldScheduleTrigger = __toESM(require("./DateFieldScheduleTrigger"));
44
46
  var import_StaticScheduleTrigger = __toESM(require("./StaticScheduleTrigger"));
45
- var import_utils = require("./utils");
47
+ var import_utils2 = require("./utils");
46
48
  class ScheduleTrigger extends import__.default {
49
+ configSchema = import_joi.default.object({
50
+ mode: import_joi.default.number().valid(import_utils2.SCHEDULE_MODE.STATIC, import_utils2.SCHEDULE_MODE.DATE_FIELD)
51
+ });
52
+ validateConfig(config) {
53
+ const errors = super.validateConfig(config);
54
+ if (errors) {
55
+ return errors;
56
+ }
57
+ if (config.mode === import_utils2.SCHEDULE_MODE.DATE_FIELD && config.collection) {
58
+ return (0, import_utils.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
59
+ }
60
+ return null;
61
+ }
47
62
  sync = false;
48
63
  modes = /* @__PURE__ */ new Map();
49
64
  constructor(workflow) {
50
65
  super(workflow);
51
- this.modes.set(import_utils.SCHEDULE_MODE.STATIC, new import_StaticScheduleTrigger.default(workflow));
52
- this.modes.set(import_utils.SCHEDULE_MODE.DATE_FIELD, new import_DateFieldScheduleTrigger.default(workflow));
66
+ this.modes.set(import_utils2.SCHEDULE_MODE.STATIC, new import_StaticScheduleTrigger.default(workflow));
67
+ this.modes.set(import_utils2.SCHEDULE_MODE.DATE_FIELD, new import_DateFieldScheduleTrigger.default(workflow));
53
68
  }
54
69
  getTrigger(mode) {
55
70
  return this.modes.get(mode);
@@ -6,12 +6,14 @@
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 Joi from 'joi';
9
10
  import { Transactionable } from '@nocobase/database';
10
11
  import type Plugin from '../Plugin';
11
12
  import type { WorkflowModel } from '../types';
12
13
  import Processor from '../Processor';
13
14
  export declare abstract class Trigger {
14
15
  readonly workflow: Plugin;
16
+ configSchema?: Joi.ObjectSchema;
15
17
  constructor(workflow: Plugin);
16
18
  on(workflow: WorkflowModel): void;
17
19
  off(workflow: WorkflowModel): void;
@@ -19,6 +21,7 @@ export declare abstract class Trigger {
19
21
  duplicateConfig?(workflow: WorkflowModel, options: Transactionable & {
20
22
  origin?: WorkflowModel;
21
23
  }): object | Promise<object>;
24
+ validateConfig(config: Record<string, any>): Record<string, string> | null;
22
25
  validateContext?(values: any, workflow: WorkflowModel): null | void | {
23
26
  [key: string]: string;
24
27
  };
@@ -34,6 +34,7 @@ class Trigger {
34
34
  constructor(workflow) {
35
35
  this.workflow = workflow;
36
36
  }
37
+ configSchema;
37
38
  on(workflow) {
38
39
  }
39
40
  off(workflow) {
@@ -41,6 +42,23 @@ class Trigger {
41
42
  validateEvent(workflow, context, options) {
42
43
  return true;
43
44
  }
45
+ validateConfig(config) {
46
+ if (!this.configSchema) {
47
+ return null;
48
+ }
49
+ const { error } = this.configSchema.validate(config, { abortEarly: false, allowUnknown: true });
50
+ if (!error) {
51
+ return null;
52
+ }
53
+ const errors = {};
54
+ for (const detail of error.details) {
55
+ const key = detail.path.join(".");
56
+ if (!errors[key]) {
57
+ errors[key] = detail.message;
58
+ }
59
+ }
60
+ return errors;
61
+ }
44
62
  sync;
45
63
  }
46
64
  var triggers_default = Trigger;
@@ -15,7 +15,13 @@ export default class ExecutionModel extends Model {
15
15
  title: string;
16
16
  context: any;
17
17
  status: number;
18
+ reason?: string | null;
18
19
  dispatched: boolean;
20
+ parentExecutionId?: number | null;
21
+ stack?: Array<number | string>;
22
+ startedAt?: Date | null;
23
+ expiresAt?: Date | null;
24
+ output?: any;
19
25
  createdAt: Date;
20
26
  updatedAt: Date;
21
27
  key: string;
@@ -11,12 +11,12 @@ import FlowNodeModel from './FlowNode';
11
11
  export default class JobModel extends Model {
12
12
  id: number;
13
13
  status: number;
14
- result: any;
15
- meta: any;
14
+ result?: any;
15
+ meta?: any;
16
16
  createdAt: Date;
17
17
  updatedAt: Date;
18
18
  upstreamId: number;
19
- upstream: JobModel;
19
+ upstream?: JobModel;
20
20
  nodeId: number;
21
21
  node?: FlowNodeModel;
22
22
  getNode: BelongsToGetAssociationMixin<FlowNodeModel>;
@@ -19,7 +19,12 @@ export default class WorkflowModel extends Model {
19
19
  description?: string;
20
20
  type: string;
21
21
  config: any;
22
- options: any;
22
+ options: {
23
+ timeout?: number;
24
+ stackLimit?: number;
25
+ deleteExecutionOnStatus?: number[];
26
+ [key: string]: any;
27
+ };
23
28
  sync: boolean;
24
29
  createdAt: Date;
25
30
  updatedAt: Date;