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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -10
  3. package/dist/client/93d3f3f8ced1c194.js +10 -0
  4. package/dist/client/AddNodeContext.d.ts +1 -0
  5. package/dist/client/NodeClipboardContext.d.ts +11 -0
  6. package/dist/client/NodeDragContext.d.ts +11 -0
  7. package/dist/client/c46a9a8d11a5be44.js +10 -0
  8. package/dist/client/cd221313681d6736.js +10 -0
  9. package/dist/client/e9463c8cd2a45481.js +10 -0
  10. package/dist/client/hooks/{useWorkflowFilterActionProps.d.ts → useResourceFilterActionProps.d.ts} +1 -1
  11. package/dist/client/index.d.ts +3 -0
  12. package/dist/client/index.js +1 -1
  13. package/dist/client/models/NodeDetailsGridModel.d.ts +13 -0
  14. package/dist/client/models/NodeDetailsModel.d.ts +34 -0
  15. package/dist/client/models/NodeValueModel.d.ts +15 -0
  16. package/dist/client/models/TaskCardCommonItemModel.d.ts +14 -0
  17. package/dist/client/models/index.d.ts +11 -0
  18. package/dist/client/nodeVariableUtils.d.ts +14 -0
  19. package/dist/client/nodes/calculation.d.ts +7 -0
  20. package/dist/client/nodes/create.d.ts +23 -0
  21. package/dist/client/nodes/destroy.d.ts +10 -0
  22. package/dist/client/nodes/index.d.ts +24 -0
  23. package/dist/client/nodes/output.d.ts +53 -0
  24. package/dist/client/nodes/query.d.ts +23 -0
  25. package/dist/client/nodes/update.d.ts +11 -0
  26. package/dist/client/schemas/executions.d.ts +41 -22
  27. package/dist/client/style.d.ts +4 -0
  28. package/dist/client/triggers/collection.d.ts +27 -1
  29. package/dist/client/triggers/index.d.ts +14 -0
  30. package/dist/client/triggers/schedule/constants.d.ts +4 -0
  31. package/dist/client/triggers/schedule/index.d.ts +28 -0
  32. package/dist/common/collections/executions.d.ts +22 -22
  33. package/dist/common/collections/executions.js +12 -0
  34. package/dist/common/collections/jobs.js +4 -0
  35. package/dist/common/collections/workflows.d.ts +22 -9
  36. package/dist/common/collections/workflows.js +9 -1
  37. package/dist/externalVersion.js +12 -12
  38. package/dist/locale/de-DE.json +10 -3
  39. package/dist/locale/en-US.json +22 -3
  40. package/dist/locale/es-ES.json +10 -3
  41. package/dist/locale/fr-FR.json +10 -3
  42. package/dist/locale/hu-HU.json +10 -2
  43. package/dist/locale/id-ID.json +10 -2
  44. package/dist/locale/it-IT.json +10 -3
  45. package/dist/locale/ja-JP.json +10 -5
  46. package/dist/locale/ko-KR.json +10 -3
  47. package/dist/locale/nl-NL.json +10 -3
  48. package/dist/locale/pt-BR.json +10 -3
  49. package/dist/locale/ru-RU.json +10 -3
  50. package/dist/locale/tr-TR.json +10 -3
  51. package/dist/locale/uk-UA.json +10 -3
  52. package/dist/locale/vi-VN.json +10 -2
  53. package/dist/locale/zh-CN.json +28 -5
  54. package/dist/locale/zh-TW.json +10 -3
  55. package/dist/node_modules/cron-parser/package.json +1 -1
  56. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  57. package/dist/node_modules/joi/lib/annotate.js +175 -0
  58. package/dist/node_modules/joi/lib/base.js +1069 -0
  59. package/dist/node_modules/joi/lib/cache.js +143 -0
  60. package/dist/node_modules/joi/lib/common.js +216 -0
  61. package/dist/node_modules/joi/lib/compile.js +283 -0
  62. package/dist/node_modules/joi/lib/errors.js +271 -0
  63. package/dist/node_modules/joi/lib/extend.js +312 -0
  64. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  65. package/dist/node_modules/joi/lib/index.js +1 -0
  66. package/dist/node_modules/joi/lib/manifest.js +476 -0
  67. package/dist/node_modules/joi/lib/messages.js +178 -0
  68. package/dist/node_modules/joi/lib/modify.js +267 -0
  69. package/dist/node_modules/joi/lib/ref.js +414 -0
  70. package/dist/node_modules/joi/lib/schemas.js +302 -0
  71. package/dist/node_modules/joi/lib/state.js +166 -0
  72. package/dist/node_modules/joi/lib/template.js +463 -0
  73. package/dist/node_modules/joi/lib/trace.js +346 -0
  74. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  75. package/dist/node_modules/joi/lib/types/any.js +174 -0
  76. package/dist/node_modules/joi/lib/types/array.js +809 -0
  77. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  78. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  79. package/dist/node_modules/joi/lib/types/date.js +233 -0
  80. package/dist/node_modules/joi/lib/types/function.js +93 -0
  81. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  82. package/dist/node_modules/joi/lib/types/link.js +168 -0
  83. package/dist/node_modules/joi/lib/types/number.js +363 -0
  84. package/dist/node_modules/joi/lib/types/object.js +22 -0
  85. package/dist/node_modules/joi/lib/types/string.js +850 -0
  86. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  87. package/dist/node_modules/joi/lib/validator.js +750 -0
  88. package/dist/node_modules/joi/lib/values.js +263 -0
  89. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  90. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  91. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  92. package/dist/node_modules/joi/package.json +1 -0
  93. package/dist/node_modules/lru-cache/package.json +1 -1
  94. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  95. package/dist/server/Dispatcher.d.ts +3 -2
  96. package/dist/server/Dispatcher.js +76 -62
  97. package/dist/server/Plugin.d.ts +1 -0
  98. package/dist/server/Plugin.js +32 -1
  99. package/dist/server/Processor.d.ts +9 -0
  100. package/dist/server/Processor.js +6 -1
  101. package/dist/server/actions/index.js +2 -0
  102. package/dist/server/actions/nodes.d.ts +7 -0
  103. package/dist/server/actions/nodes.js +315 -4
  104. package/dist/server/actions/workflows.d.ts +6 -0
  105. package/dist/server/actions/workflows.js +38 -0
  106. package/dist/server/instructions/ConditionInstruction.js +4 -1
  107. package/dist/server/instructions/CreateInstruction.d.ts +3 -0
  108. package/dist/server/instructions/CreateInstruction.js +21 -0
  109. package/dist/server/instructions/DestroyInstruction.d.ts +3 -0
  110. package/dist/server/instructions/DestroyInstruction.js +22 -0
  111. package/dist/server/instructions/EndInstruction.d.ts +2 -0
  112. package/dist/server/instructions/EndInstruction.js +4 -0
  113. package/dist/server/instructions/OutputInstruction.d.ts +21 -0
  114. package/dist/server/instructions/OutputInstruction.js +54 -0
  115. package/dist/server/instructions/QueryInstruction.d.ts +3 -0
  116. package/dist/server/instructions/QueryInstruction.js +21 -0
  117. package/dist/server/instructions/UpdateInstruction.d.ts +3 -0
  118. package/dist/server/instructions/UpdateInstruction.js +22 -0
  119. package/dist/server/instructions/index.d.ts +4 -0
  120. package/dist/server/instructions/index.js +18 -0
  121. package/dist/server/repositories/WorkflowRepository.js +2 -1
  122. package/dist/server/triggers/CollectionTrigger.d.ts +3 -0
  123. package/dist/server/triggers/CollectionTrigger.js +23 -0
  124. package/dist/server/triggers/ScheduleTrigger/index.d.ts +3 -0
  125. package/dist/server/triggers/ScheduleTrigger/index.js +18 -3
  126. package/dist/server/triggers/index.d.ts +3 -0
  127. package/dist/server/triggers/index.js +18 -0
  128. package/dist/server/utils.d.ts +2 -0
  129. package/dist/server/utils.js +22 -2
  130. package/dist/swagger/index.d.ts +814 -62
  131. package/dist/swagger/index.js +975 -205
  132. package/package.json +4 -3
  133. package/dist/client/27bd65abee87cafa.js +0 -10
  134. package/dist/client/80d4cd8911e03c27.js +0 -10
  135. package/dist/client/bfc2a351589613e1.js +0 -10
  136. package/dist/client/e078314a62391f36.js +0 -10
@@ -0,0 +1,54 @@
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 OutputInstruction_exports = {};
28
+ __export(OutputInstruction_exports, {
29
+ default: () => ExecutionResultInstruction
30
+ });
31
+ module.exports = __toCommonJS(OutputInstruction_exports);
32
+ var import__ = require(".");
33
+ var import_constants = require("../constants");
34
+ class ExecutionResultInstruction extends import__.Instruction {
35
+ async run(node, prevJob, processor) {
36
+ const { value } = node.config;
37
+ const output = processor.getParsedValue(value, node.id);
38
+ try {
39
+ await processor.execution.update({ output }, { hooks: false, transaction: processor.mainTransaction });
40
+ } catch (e) {
41
+ return {
42
+ result: e.message,
43
+ status: import_constants.JOB_STATUS.FAILED
44
+ };
45
+ }
46
+ return {
47
+ result: output,
48
+ status: import_constants.JOB_STATUS.RESOLVED
49
+ };
50
+ }
51
+ async resume(node, job, processor) {
52
+ return job;
53
+ }
54
+ }
@@ -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,23 @@ __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
+ });
53
+ validateConfig(config) {
54
+ const errors = super.validateConfig(config);
55
+ if (errors) {
56
+ return errors;
57
+ }
58
+ return (0, import_utils.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
59
+ }
39
60
  async run(node, input, processor) {
40
61
  const { collection, multiple, params = {}, failOnEmpty = false } = node.config;
41
62
  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,22 @@ __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
+ });
52
+ validateConfig(config) {
53
+ const errors = super.validateConfig(config);
54
+ if (errors) {
55
+ return errors;
56
+ }
57
+ return (0, import_utils.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
58
+ }
37
59
  async run(node, input, processor) {
38
60
  const { collection, params = {} } = node.config;
39
61
  const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
@@ -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 { Transactionable } from '@nocobase/database';
10
11
  import type Plugin from '../Plugin';
11
12
  import type Processor from '../Processor';
@@ -24,11 +25,14 @@ export type InstructionInterface = {
24
25
  duplicateConfig?: (node: FlowNodeModel, options: Transactionable & {
25
26
  origin?: FlowNodeModel;
26
27
  }) => object | Promise<object>;
28
+ validateConfig?: (config: Record<string, any>) => Record<string, string> | null;
27
29
  test?: (config: Record<string, any>) => IJob | Promise<IJob>;
28
30
  };
29
31
  export declare abstract class Instruction implements InstructionInterface {
30
32
  workflow: Plugin;
33
+ configSchema?: Joi.ObjectSchema;
31
34
  constructor(workflow: Plugin);
35
+ validateConfig(config: Record<string, any>): Record<string, string> | null;
32
36
  abstract run(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
33
37
  }
34
38
  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:
@@ -97,7 +97,8 @@ class WorkflowRepository extends import_database.Repository {
97
97
  { transaction }
98
98
  );
99
99
  if (typeof instruction.duplicateConfig === "function") {
100
- await instruction.duplicateConfig(newNode, { origin: node, transaction });
100
+ const newConfig = await instruction.duplicateConfig(newNode, { origin: node, transaction });
101
+ await newNode.update({ config: newConfig }, { transaction });
101
102
  }
102
103
  oldToNew.set(node.id, newNode);
103
104
  newToOld.set(newNode.id, 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,28 @@ 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(...Object.values(MODE_BITMAP)),
88
+ changed: import_joi.default.when("mode", {
89
+ is: (mode) => (mode & MODE_BITMAP.UPDATE) === MODE_BITMAP.UPDATE,
90
+ then: import_joi.default.array().items(import_joi.default.string()).optional(),
91
+ otherwise: import_joi.default.forbidden()
92
+ }),
93
+ condition: import_joi.default.object(),
94
+ appends: import_joi.default.when("mode", {
95
+ is: (mode) => mode !== MODE_BITMAP.DESTROY,
96
+ then: import_joi.default.array().items(import_joi.default.string()).optional(),
97
+ otherwise: import_joi.default.forbidden()
98
+ })
99
+ });
100
+ validateConfig(config) {
101
+ const errors = super.validateConfig(config);
102
+ if (errors) {
103
+ return errors;
104
+ }
105
+ return (0, import_utils2.validateCollectionField)(config.collection, this.workflow.app.dataSourceManager);
106
+ }
84
107
  events = /* @__PURE__ */ new Map();
85
108
  // async function, should return promise
86
109
  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,4 +6,6 @@
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';
10
+ export declare function validateCollectionField(collection: string, dataSourceManager: DataSourceManager): Record<string, string> | null;
9
11
  export declare function toJSON(data: any): any;
@@ -26,10 +26,29 @@ var __copyProps = (to, from, except, desc) => {
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
27
  var utils_exports = {};
28
28
  __export(utils_exports, {
29
- toJSON: () => toJSON
29
+ toJSON: () => toJSON,
30
+ validateCollectionField: () => validateCollectionField
30
31
  });
31
32
  module.exports = __toCommonJS(utils_exports);
32
33
  var import_database = require("@nocobase/database");
34
+ var import_data_source_manager = require("@nocobase/data-source-manager");
35
+ function validateCollectionField(collection, dataSourceManager) {
36
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
37
+ if (collection.includes(":")) {
38
+ const parts = collection.split(":");
39
+ if (parts.length !== 2 || !parts[0] || !parts[1]) {
40
+ return { collection: `"collection" must be in the format "dataSourceName:collectionName"` };
41
+ }
42
+ }
43
+ const dataSource = dataSourceManager.dataSources.get(dataSourceName);
44
+ if (!dataSource) {
45
+ return { collection: `Data source "${dataSourceName}" does not exist` };
46
+ }
47
+ if (!dataSource.collectionManager.getCollection(collectionName)) {
48
+ return { collection: `Collection "${collectionName}" does not exist in data source "${dataSourceName}"` };
49
+ }
50
+ return null;
51
+ }
33
52
  function toJSON(data) {
34
53
  if (Array.isArray(data)) {
35
54
  return data.map(toJSON);
@@ -47,5 +66,6 @@ function toJSON(data) {
47
66
  }
48
67
  // Annotate the CommonJS export names for ESM import in node:
49
68
  0 && (module.exports = {
50
- toJSON
69
+ toJSON,
70
+ validateCollectionField
51
71
  });