@nocobase/plugin-workflow 2.1.0-beta.14 → 2.1.0-beta.16

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 (126) hide show
  1. package/dist/client/214.7e602cfe7a8251b8.js +10 -0
  2. package/dist/client/261.7722d7400942730e.js +10 -0
  3. package/dist/client/67.f904ef4520868b8a.js +10 -0
  4. package/dist/client/964.6251d37b35710747.js +10 -0
  5. package/dist/client/index.js +1 -1
  6. package/dist/client/nodes/create.d.ts +10 -0
  7. package/dist/client/nodes/destroy.d.ts +10 -0
  8. package/dist/client/nodes/index.d.ts +3 -0
  9. package/dist/client/nodes/query.d.ts +10 -0
  10. package/dist/client/nodes/update.d.ts +10 -0
  11. package/dist/client/schemas/executions.d.ts +0 -1
  12. package/dist/client/triggers/collection.d.ts +14 -1
  13. package/dist/client/triggers/index.d.ts +4 -0
  14. package/dist/client/triggers/schedule/constants.d.ts +4 -0
  15. package/dist/client/triggers/schedule/index.d.ts +15 -0
  16. package/dist/common/collections/jobs.js +7 -0
  17. package/dist/externalVersion.js +12 -12
  18. package/dist/locale/zh-CN.json +1 -0
  19. package/dist/node_modules/cron-parser/lib/parser.js +1 -1
  20. package/dist/node_modules/cron-parser/package.json +1 -1
  21. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  22. package/dist/node_modules/joi/lib/annotate.js +175 -0
  23. package/dist/node_modules/joi/lib/base.js +1069 -0
  24. package/dist/node_modules/joi/lib/cache.js +143 -0
  25. package/dist/node_modules/joi/lib/common.js +216 -0
  26. package/dist/node_modules/joi/lib/compile.js +283 -0
  27. package/dist/node_modules/joi/lib/errors.js +271 -0
  28. package/dist/node_modules/joi/lib/extend.js +312 -0
  29. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  30. package/dist/node_modules/joi/lib/index.js +1 -0
  31. package/dist/node_modules/joi/lib/manifest.js +476 -0
  32. package/dist/node_modules/joi/lib/messages.js +178 -0
  33. package/dist/node_modules/joi/lib/modify.js +267 -0
  34. package/dist/node_modules/joi/lib/ref.js +414 -0
  35. package/dist/node_modules/joi/lib/schemas.js +302 -0
  36. package/dist/node_modules/joi/lib/state.js +166 -0
  37. package/dist/node_modules/joi/lib/template.js +463 -0
  38. package/dist/node_modules/joi/lib/trace.js +346 -0
  39. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  40. package/dist/node_modules/joi/lib/types/any.js +174 -0
  41. package/dist/node_modules/joi/lib/types/array.js +809 -0
  42. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  43. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  44. package/dist/node_modules/joi/lib/types/date.js +233 -0
  45. package/dist/node_modules/joi/lib/types/function.js +93 -0
  46. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  47. package/dist/node_modules/joi/lib/types/link.js +168 -0
  48. package/dist/node_modules/joi/lib/types/number.js +363 -0
  49. package/dist/node_modules/joi/lib/types/object.js +22 -0
  50. package/dist/node_modules/joi/lib/types/string.js +850 -0
  51. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  52. package/dist/node_modules/joi/lib/validator.js +750 -0
  53. package/dist/node_modules/joi/lib/values.js +263 -0
  54. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  55. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  56. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  57. package/dist/node_modules/joi/package.json +1 -0
  58. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts +5 -0
  59. package/dist/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +10 -0
  60. package/dist/node_modules/lru-cache/dist/commonjs/index.d.ts +1381 -0
  61. package/dist/node_modules/lru-cache/dist/commonjs/index.js +1692 -0
  62. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -0
  63. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.d.ts +5 -0
  64. package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  65. package/dist/node_modules/lru-cache/dist/esm/browser/index.d.ts +1381 -0
  66. package/dist/node_modules/lru-cache/dist/{mjs → esm/browser}/index.js +537 -179
  67. package/dist/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  68. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.d.ts +5 -0
  69. package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  70. package/dist/node_modules/lru-cache/dist/esm/index.d.ts +1381 -0
  71. package/dist/node_modules/lru-cache/dist/{cjs → esm}/index.js +538 -184
  72. package/dist/node_modules/lru-cache/dist/esm/index.min.js +2 -0
  73. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.d.ts +5 -0
  74. package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +7 -0
  75. package/dist/node_modules/lru-cache/dist/esm/node/index.d.ts +1381 -0
  76. package/dist/node_modules/lru-cache/dist/esm/node/index.js +1688 -0
  77. package/dist/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  78. package/dist/node_modules/lru-cache/package.json +1 -1
  79. package/dist/node_modules/nodejs-snowflake/nodejs_snowflake.js +1 -1
  80. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  81. package/dist/server/Plugin.d.ts +1 -0
  82. package/dist/server/Plugin.js +28 -3
  83. package/dist/server/actions/nodes.d.ts +5 -0
  84. package/dist/server/actions/nodes.js +38 -5
  85. package/dist/server/actions/workflows.d.ts +6 -0
  86. package/dist/server/actions/workflows.js +38 -0
  87. package/dist/server/instructions/ConditionInstruction.d.ts +2 -0
  88. package/dist/server/instructions/ConditionInstruction.js +17 -0
  89. package/dist/server/instructions/CreateInstruction.d.ts +3 -0
  90. package/dist/server/instructions/CreateInstruction.js +25 -0
  91. package/dist/server/instructions/DestroyInstruction.d.ts +3 -0
  92. package/dist/server/instructions/DestroyInstruction.js +25 -0
  93. package/dist/server/instructions/EndInstruction.d.ts +2 -0
  94. package/dist/server/instructions/EndInstruction.js +4 -0
  95. package/dist/server/instructions/MultiConditionsInstruction.d.ts +2 -0
  96. package/dist/server/instructions/MultiConditionsInstruction.js +23 -0
  97. package/dist/server/instructions/OutputInstruction.d.ts +2 -0
  98. package/dist/server/instructions/OutputInstruction.js +14 -0
  99. package/dist/server/instructions/QueryInstruction.d.ts +3 -0
  100. package/dist/server/instructions/QueryInstruction.js +30 -0
  101. package/dist/server/instructions/UpdateInstruction.d.ts +3 -0
  102. package/dist/server/instructions/UpdateInstruction.js +27 -0
  103. package/dist/server/instructions/index.d.ts +15 -2
  104. package/dist/server/instructions/index.js +18 -0
  105. package/dist/server/triggers/CollectionTrigger.d.ts +3 -0
  106. package/dist/server/triggers/CollectionTrigger.js +28 -0
  107. package/dist/server/triggers/ScheduleTrigger/index.d.ts +3 -0
  108. package/dist/server/triggers/ScheduleTrigger/index.js +18 -3
  109. package/dist/server/triggers/index.d.ts +3 -0
  110. package/dist/server/triggers/index.js +18 -0
  111. package/dist/server/utils.d.ts +2 -0
  112. package/dist/server/utils.js +22 -2
  113. package/package.json +4 -3
  114. package/dist/client/10.dc2f9b83209e12b9.js +0 -10
  115. package/dist/client/626.7d24ff2a47742f1b.js +0 -10
  116. package/dist/client/771.5e7be8b4d4ac579f.js +0 -10
  117. package/dist/client/781.d9277df85d1beaba.js +0 -10
  118. package/dist/node_modules/lru-cache/LICENSE +0 -15
  119. package/dist/node_modules/lru-cache/dist/cjs/index-cjs.d.ts +0 -7
  120. package/dist/node_modules/lru-cache/dist/cjs/index-cjs.js +0 -1
  121. package/dist/node_modules/lru-cache/dist/cjs/index.d.ts +0 -807
  122. package/dist/node_modules/lru-cache/dist/cjs/index.min.js +0 -2
  123. package/dist/node_modules/lru-cache/dist/mjs/index.d.ts +0 -807
  124. package/dist/node_modules/lru-cache/dist/mjs/index.min.js +0 -2
  125. /package/dist/node_modules/lru-cache/dist/{cjs → commonjs}/package.json +0 -0
  126. /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 MultiConditionsInstruction_exports = {};
28
38
  __export(MultiConditionsInstruction_exports, {
@@ -30,11 +40,24 @@ __export(MultiConditionsInstruction_exports, {
30
40
  default: () => MultiConditionsInstruction_default
31
41
  });
32
42
  module.exports = __toCommonJS(MultiConditionsInstruction_exports);
43
+ var import_joi = __toESM(require("joi"));
33
44
  var import_evaluators = require("@nocobase/evaluators");
34
45
  var import__ = require(".");
35
46
  var import_constants = require("../constants");
36
47
  var import_logicCalculate = require("../logicCalculate");
37
48
  class MultiConditionsInstruction extends import__.Instruction {
49
+ configSchema = import_joi.default.object({
50
+ conditions: import_joi.default.array().items(
51
+ import_joi.default.object({
52
+ uid: import_joi.default.string(),
53
+ title: import_joi.default.string(),
54
+ engine: import_joi.default.string(),
55
+ calculation: import_joi.default.any(),
56
+ expression: import_joi.default.string()
57
+ })
58
+ ),
59
+ continueOnNoMatch: import_joi.default.boolean()
60
+ });
38
61
  async run(node, prevJob, processor) {
39
62
  const { conditions = [], continueOnNoMatch = false } = node.config || {};
40
63
  const meta = { conditions: [] };
@@ -6,10 +6,12 @@
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 { Instruction } from '.';
10
11
  import Processor from '../Processor';
11
12
  import { FlowNodeModel } from '../types';
12
13
  export default class ExecutionResultInstruction extends Instruction {
14
+ configSchema: Joi.ObjectSchema<any>;
13
15
  run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<{
14
16
  result: any;
15
17
  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,15 +25,27 @@ 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 OutputInstruction_exports = {};
28
38
  __export(OutputInstruction_exports, {
29
39
  default: () => ExecutionResultInstruction
30
40
  });
31
41
  module.exports = __toCommonJS(OutputInstruction_exports);
42
+ var import_joi = __toESM(require("joi"));
32
43
  var import__ = require(".");
33
44
  var import_constants = require("../constants");
34
45
  class ExecutionResultInstruction extends import__.Instruction {
46
+ configSchema = import_joi.default.object({
47
+ value: import_joi.default.any()
48
+ });
35
49
  async run(node, prevJob, processor) {
36
50
  const { value } = node.config;
37
51
  const output = processor.getParsedValue(value, node.id);
@@ -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 QueryInstruction 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 QueryInstruction_exports = {};
28
38
  __export(QueryInstruction_exports, {
@@ -30,12 +40,32 @@ __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);
@@ -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,16 +6,25 @@
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;
16
17
  [key: string]: unknown;
17
18
  }
18
- export type InstructionResult = IJob | Promise<IJob> | Promise<void> | null | void;
19
+ /**
20
+ * The result of an instruction execution.
21
+ *
22
+ * Different type of result will cause according behavior in the workflow engine:
23
+ * 1. IJob | Promise<IJob>: processor will continue default processing by checking the status.
24
+ * 2. `null` | Promise<null>: processor will do exit process.
25
+ * 3. `void` | Promise<void>: processor will do nothing, and terminate the current execution without any action.
26
+ */
27
+ export type InstructionResult = IJob | Promise<IJob> | Promise<void> | Promise<null> | null | void;
19
28
  export type Runner = (node: FlowNodeModel, input: any, processor: Processor) => InstructionResult;
20
29
  export type InstructionInterface = {
21
30
  run: Runner;
@@ -24,11 +33,15 @@ export type InstructionInterface = {
24
33
  duplicateConfig?: (node: FlowNodeModel, options: Transactionable & {
25
34
  origin?: FlowNodeModel;
26
35
  }) => object | Promise<object>;
36
+ validateConfig?: (config: Record<string, any>) => Record<string, string> | null;
37
+ isAvailable?: (workflow: WorkflowModel, node: FlowNodeModel) => boolean;
27
38
  test?: (config: Record<string, any>) => IJob | Promise<IJob>;
28
39
  };
29
40
  export declare abstract class Instruction implements InstructionInterface {
30
41
  workflow: Plugin;
42
+ configSchema?: Joi.ObjectSchema;
31
43
  constructor(workflow: Plugin);
44
+ validateConfig(config: Record<string, any>): Record<string, string> | null;
32
45
  abstract run(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
33
46
  }
34
47
  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:
@@ -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;
@@ -6,8 +6,10 @@
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 type { DataSourceManager } from '@nocobase/data-source-manager';
9
10
  import type { WorkflowModel } from './types';
10
11
  import Processor from './Processor';
12
+ export declare function validateCollectionField(collection: string, dataSourceManager: DataSourceManager): Record<string, string> | null;
11
13
  export declare function getExecutionStatusName(status: number | null | undefined): string;
12
14
  export declare function getWorkflowExecutionLogMeta(workflow: WorkflowModel, processor?: Processor): {
13
15
  workflowId: number;
@@ -28,11 +28,30 @@ var utils_exports = {};
28
28
  __export(utils_exports, {
29
29
  getExecutionStatusName: () => getExecutionStatusName,
30
30
  getWorkflowExecutionLogMeta: () => getWorkflowExecutionLogMeta,
31
- toJSON: () => toJSON
31
+ toJSON: () => toJSON,
32
+ validateCollectionField: () => validateCollectionField
32
33
  });
33
34
  module.exports = __toCommonJS(utils_exports);
34
35
  var import_database = require("@nocobase/database");
36
+ var import_data_source_manager = require("@nocobase/data-source-manager");
35
37
  var import_constants = require("./constants");
38
+ function validateCollectionField(collection, dataSourceManager) {
39
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
40
+ if (collection.includes(":")) {
41
+ const parts = collection.split(":");
42
+ if (parts.length !== 2 || !parts[0] || !parts[1]) {
43
+ return { collection: `"collection" must be in the format "dataSourceName:collectionName"` };
44
+ }
45
+ }
46
+ const dataSource = dataSourceManager.dataSources.get(dataSourceName);
47
+ if (!dataSource) {
48
+ return { collection: `Data source "${dataSourceName}" does not exist` };
49
+ }
50
+ if (!dataSource.collectionManager.getCollection(collectionName)) {
51
+ return { collection: `Collection "${collectionName}" does not exist in data source "${dataSourceName}"` };
52
+ }
53
+ return null;
54
+ }
36
55
  const EXECUTION_STATUS_NAMES = new Map(Object.entries(import_constants.EXECUTION_STATUS).map(([name, value]) => [value, name]));
37
56
  function getExecutionStatusName(status) {
38
57
  if (typeof status === "undefined") {
@@ -76,5 +95,6 @@ function toJSON(data) {
76
95
  0 && (module.exports = {
77
96
  getExecutionStatusName,
78
97
  getWorkflowExecutionLogMeta,
79
- toJSON
98
+ toJSON,
99
+ validateCollectionField
80
100
  });
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "A powerful BPM tool that provides foundational support for business automation, with the capability to extend unlimited triggers and nodes.",
7
7
  "description.zh-CN": "一个强大的 BPM 工具,为业务自动化提供基础支持,并且可任意扩展更多的触发器和节点。",
8
8
  "description.ru-RU": "Мощный инструмент BPM, обеспечивающий базовую поддержку автоматизации бизнес-процессов с возможностью неограниченного расширения триггеров и узлов.",
9
- "version": "2.1.0-beta.14",
9
+ "version": "2.1.0-beta.16",
10
10
  "license": "Apache-2.0",
11
11
  "main": "./dist/server/index.js",
12
12
  "homepage": "https://docs.nocobase.com/handbook/workflow",
@@ -22,8 +22,9 @@
22
22
  "classnames": "^2.3.1",
23
23
  "cron-parser": "4.4.0",
24
24
  "dayjs": "^1.11.8",
25
+ "joi": "^17.13.3",
25
26
  "lodash": "4.x",
26
- "lru-cache": "8.0.5",
27
+ "lru-cache": "^11.3.5",
27
28
  "nodejs-snowflake": "2.0.1",
28
29
  "react": "18.x",
29
30
  "react-i18next": "^11.15.1",
@@ -48,7 +49,7 @@
48
49
  "@nocobase/test": "2.x",
49
50
  "@nocobase/utils": "2.x"
50
51
  },
51
- "gitHead": "cd55c9a14596d834c30c83a82c38f1f719f7aac4",
52
+ "gitHead": "b9a191705a440a336c85d82fd877fdf152bec70f",
52
53
  "keywords": [
53
54
  "Workflow"
54
55
  ]