@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
@@ -6,4 +6,31 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
+ import { Transactionable } from '@nocobase/database';
10
+ import type { DataSourceManager } from '@nocobase/data-source-manager';
11
+ import type PluginWorkflowServer from './Plugin';
12
+ import { EXECUTION_REASON } from './constants';
13
+ import type { ExecutionModel, WorkflowModel } from './types';
14
+ import Processor from './Processor';
15
+ type AbortOptions = Transactionable & {
16
+ reason?: (typeof EXECUTION_REASON)[keyof typeof EXECUTION_REASON];
17
+ };
18
+ export declare function getExecutionLockKey(executionId: number | string): string;
19
+ export declare function isLockAcquireError(error: unknown): boolean;
20
+ export declare function validateCollectionField(collection: string, dataSourceManager: DataSourceManager): Record<string, string> | null;
21
+ export declare function getExecutionStatusName(status: number | null | undefined): string;
22
+ export declare function getWorkflowExecutionLogMeta(workflow: WorkflowModel, processor?: Processor): {
23
+ workflowId: number;
24
+ workflowKey: string;
25
+ workflowTitle: string;
26
+ executionId: number;
27
+ executionStatus: number;
28
+ executionStatusName: string;
29
+ lastNodeId: number;
30
+ lastNodeType: string;
31
+ lastJobId: number;
32
+ lastJobStatus: number;
33
+ };
34
+ export declare function abortExecution(plugin: PluginWorkflowServer, execution: ExecutionModel, options?: AbortOptions): Promise<boolean>;
9
35
  export declare function toJSON(data: any): any;
36
+ export {};
@@ -26,10 +26,140 @@ 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
+ abortExecution: () => abortExecution,
30
+ getExecutionLockKey: () => getExecutionLockKey,
31
+ getExecutionStatusName: () => getExecutionStatusName,
32
+ getWorkflowExecutionLogMeta: () => getWorkflowExecutionLogMeta,
33
+ isLockAcquireError: () => isLockAcquireError,
34
+ toJSON: () => toJSON,
35
+ validateCollectionField: () => validateCollectionField
30
36
  });
31
37
  module.exports = __toCommonJS(utils_exports);
32
38
  var import_database = require("@nocobase/database");
39
+ var import_data_source_manager = require("@nocobase/data-source-manager");
40
+ var import_constants = require("./constants");
41
+ function getExecutionLockKey(executionId) {
42
+ return `workflow:execution:${executionId}`;
43
+ }
44
+ function isLockAcquireError(error) {
45
+ return error instanceof Error && error.constructor.name === "LockAcquireError";
46
+ }
47
+ function afterTransactionCommit(transaction, callback) {
48
+ if (typeof transaction.afterCommit === "function") {
49
+ transaction.afterCommit(callback);
50
+ return;
51
+ }
52
+ callback();
53
+ }
54
+ function validateCollectionField(collection, dataSourceManager) {
55
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
56
+ if (!dataSourceName || !collectionName) {
57
+ return { collection: `"collection" must be in the format "dataSourceName:collectionName"` };
58
+ }
59
+ const dataSource = dataSourceManager.dataSources.get(dataSourceName);
60
+ if (!dataSource) {
61
+ return { collection: `Data source "${dataSourceName}" does not exist` };
62
+ }
63
+ if (!dataSource.collectionManager.getCollection(collectionName)) {
64
+ return { collection: `Collection "${collectionName}" does not exist in data source "${dataSourceName}"` };
65
+ }
66
+ return null;
67
+ }
68
+ const EXECUTION_STATUS_NAMES = new Map(Object.entries(import_constants.EXECUTION_STATUS).map(([name, value]) => [value, name]));
69
+ function getExecutionStatusName(status) {
70
+ if (typeof status === "undefined") {
71
+ return "UNKNOWN";
72
+ }
73
+ return EXECUTION_STATUS_NAMES.get(status) ?? `${status}`;
74
+ }
75
+ function getWorkflowExecutionLogMeta(workflow, processor) {
76
+ var _a, _b, _c, _d;
77
+ const lastSavedJob = processor == null ? void 0 : processor.lastSavedJob;
78
+ const lastNode = (_a = processor == null ? void 0 : processor.nodesMap) == null ? void 0 : _a.get(lastSavedJob == null ? void 0 : lastSavedJob.nodeId);
79
+ return {
80
+ workflowId: workflow.id,
81
+ workflowKey: workflow.key,
82
+ workflowTitle: workflow.title,
83
+ executionId: ((_b = processor == null ? void 0 : processor.execution) == null ? void 0 : _b.id) ?? null,
84
+ executionStatus: ((_c = processor == null ? void 0 : processor.execution) == null ? void 0 : _c.status) ?? null,
85
+ executionStatusName: getExecutionStatusName((_d = processor == null ? void 0 : processor.execution) == null ? void 0 : _d.status),
86
+ lastNodeId: (lastNode == null ? void 0 : lastNode.id) ?? (lastSavedJob == null ? void 0 : lastSavedJob.nodeId) ?? null,
87
+ lastNodeType: (lastNode == null ? void 0 : lastNode.type) ?? null,
88
+ lastJobId: (lastSavedJob == null ? void 0 : lastSavedJob.id) ?? null,
89
+ lastJobStatus: (lastSavedJob == null ? void 0 : lastSavedJob.status) ?? null
90
+ };
91
+ }
92
+ async function abortExecution(plugin, execution, options = {}) {
93
+ const logger = plugin.getLogger(execution.workflowId);
94
+ const ownTransaction = !options.transaction;
95
+ const transaction = options.transaction ?? await plugin.useDataSourceTransaction("main", null, true);
96
+ const ExecutionRepo = plugin.db.getRepository("executions");
97
+ const JobRepo = plugin.db.getRepository("jobs");
98
+ try {
99
+ const lockedExecution = await ExecutionRepo.findOne({
100
+ filterByTk: execution.id,
101
+ transaction,
102
+ lock: transaction.LOCK.UPDATE
103
+ });
104
+ if (!lockedExecution || lockedExecution.status !== import_constants.EXECUTION_STATUS.STARTED) {
105
+ if (ownTransaction) {
106
+ await transaction.commit();
107
+ }
108
+ return false;
109
+ }
110
+ await lockedExecution.update(
111
+ {
112
+ status: import_constants.EXECUTION_STATUS.ABORTED,
113
+ ...options.reason ? {
114
+ reason: options.reason
115
+ } : {}
116
+ },
117
+ {
118
+ transaction
119
+ }
120
+ );
121
+ const updated = await JobRepo.update({
122
+ values: {
123
+ status: import_constants.JOB_STATUS.ABORTED
124
+ },
125
+ filter: {
126
+ executionId: execution.id,
127
+ status: import_constants.JOB_STATUS.PENDING
128
+ },
129
+ individualHooks: false,
130
+ transaction
131
+ });
132
+ const childExecutions = await plugin.db.getRepository("executions").find({
133
+ filter: {
134
+ parentExecutionId: execution.id,
135
+ status: import_constants.EXECUTION_STATUS.STARTED
136
+ },
137
+ transaction
138
+ });
139
+ for (const child of childExecutions) {
140
+ await abortExecution(plugin, child, { transaction, reason: import_constants.EXECUTION_REASON.PARENT_ABORTED });
141
+ }
142
+ afterTransactionCommit(transaction, () => {
143
+ execution.set("status", import_constants.EXECUTION_STATUS.ABORTED);
144
+ execution.set("reason", options.reason ?? null);
145
+ plugin.timeoutManager.clear(execution.id);
146
+ plugin.abortRunningExecution(execution.id, options.reason);
147
+ });
148
+ logger.info(`execution (${execution.id}) aborted`, {
149
+ workflowId: execution.workflowId,
150
+ pendingJobs: Array.isArray(updated) ? updated.length : updated
151
+ });
152
+ if (ownTransaction) {
153
+ await transaction.commit();
154
+ }
155
+ return true;
156
+ } catch (error) {
157
+ if (ownTransaction && !transaction.finished) {
158
+ await transaction.rollback();
159
+ }
160
+ throw error;
161
+ }
162
+ }
33
163
  function toJSON(data) {
34
164
  if (Array.isArray(data)) {
35
165
  return data.map(toJSON);
@@ -47,5 +177,11 @@ function toJSON(data) {
47
177
  }
48
178
  // Annotate the CommonJS export names for ESM import in node:
49
179
  0 && (module.exports = {
50
- toJSON
180
+ abortExecution,
181
+ getExecutionLockKey,
182
+ getExecutionStatusName,
183
+ getWorkflowExecutionLogMeta,
184
+ isLockAcquireError,
185
+ toJSON,
186
+ validateCollectionField
51
187
  });