@nocobase/plugin-workflow-cc 2.1.0-alpha.1 → 2.1.0-alpha.10

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.
@@ -24,5 +24,8 @@ export declare const ccTodo: {
24
24
  Actions: typeof TodoExtraActions;
25
25
  Item: typeof TaskItem;
26
26
  Detail: typeof Drawer;
27
+ getPopupRecord: (apiClient: any, { params }: {
28
+ params: any;
29
+ }) => any;
27
30
  };
28
31
  export {};
@@ -8,6 +8,7 @@
8
8
  */
9
9
  declare const _default: {
10
10
  name: string;
11
+ filterTargetKey: string;
11
12
  dumpRules: {
12
13
  group: string;
13
14
  };
@@ -69,11 +70,17 @@ declare const _default: {
69
70
  type: string;
70
71
  name: string;
71
72
  target: string;
73
+ uiSchema: {
74
+ type: string;
75
+ title: string;
76
+ 'x-component'?: undefined;
77
+ 'x-component-props'?: undefined;
78
+ enum?: undefined;
79
+ };
72
80
  primaryKey?: undefined;
73
81
  allowNull?: undefined;
74
82
  foreignKey?: undefined;
75
83
  interface?: undefined;
76
- uiSchema?: undefined;
77
84
  onDelete?: undefined;
78
85
  defaultValue?: undefined;
79
86
  } | {
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(workflowCcTasks_exports);
32
32
  var import_constants = require("../constants");
33
33
  var workflowCcTasks_default = {
34
34
  name: "workflowCcTasks",
35
+ filterTargetKey: "id",
35
36
  dumpRules: {
36
37
  group: "log"
37
38
  },
@@ -78,7 +79,11 @@ var workflowCcTasks_default = {
78
79
  {
79
80
  type: "belongsTo",
80
81
  name: "node",
81
- target: "flow_nodes"
82
+ target: "flow_nodes",
83
+ uiSchema: {
84
+ type: "object",
85
+ title: `{{t("CC node", { ns: "${import_constants.NAMESPACE}" })}}`
86
+ }
82
87
  },
83
88
  {
84
89
  type: "belongsTo",
@@ -141,7 +146,7 @@ var workflowCcTasks_default = {
141
146
  interface: "createdAt",
142
147
  uiSchema: {
143
148
  type: "datetime",
144
- title: '{{t("Created at")}}',
149
+ title: `{{t("Created at", { ns: "${import_constants.NAMESPACE}" })}}`,
145
150
  "x-component": "DatePicker",
146
151
  "x-component-props": {
147
152
  showTime: true
@@ -154,7 +159,7 @@ var workflowCcTasks_default = {
154
159
  interface: "updatedAt",
155
160
  uiSchema: {
156
161
  type: "datetime",
157
- title: '{{t("Updated at")}}',
162
+ title: `{{t("Updated at", { ns: "${import_constants.NAMESPACE}" })}}`,
158
163
  "x-component": "DatePicker",
159
164
  "x-component-props": {
160
165
  showTime: true
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export declare const TEMP_ASSOCIATION_PREFIX = "ccTempAssoc_";
10
+ export declare const buildTempAssociationFieldName: (nodeType: string, nodeKey: string | number) => string;
@@ -0,0 +1,40 @@
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 tempAssociation_exports = {};
28
+ __export(tempAssociation_exports, {
29
+ TEMP_ASSOCIATION_PREFIX: () => TEMP_ASSOCIATION_PREFIX,
30
+ buildTempAssociationFieldName: () => buildTempAssociationFieldName
31
+ });
32
+ module.exports = __toCommonJS(tempAssociation_exports);
33
+ const TEMP_ASSOCIATION_PREFIX = "ccTempAssoc_";
34
+ const sanitizeFieldKey = (value) => String(value ?? "").replace(/[^a-zA-Z0-9_]/g, "_");
35
+ const buildTempAssociationFieldName = (nodeType, nodeKey) => `${TEMP_ASSOCIATION_PREFIX}${nodeType}_${sanitizeFieldKey(nodeKey)}`;
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ TEMP_ASSOCIATION_PREFIX,
39
+ buildTempAssociationFieldName
40
+ });
@@ -9,20 +9,22 @@
9
9
 
10
10
  module.exports = {
11
11
  "react": "18.2.0",
12
- "@nocobase/client": "2.1.0-alpha.1",
13
- "@nocobase/plugin-workflow": "2.1.0-alpha.1",
12
+ "@nocobase/client": "2.1.0-alpha.10",
13
+ "@nocobase/plugin-workflow": "2.1.0-alpha.10",
14
14
  "react-i18next": "11.18.6",
15
15
  "antd-style": "3.7.1",
16
16
  "antd": "5.24.2",
17
17
  "react-router-dom": "6.30.1",
18
18
  "lodash": "4.17.21",
19
- "@nocobase/utils": "2.1.0-alpha.1",
20
- "@nocobase/plugin-ui-schema-storage": "2.1.0-alpha.1",
21
- "@nocobase/actions": "2.1.0-alpha.1",
22
- "@nocobase/server": "2.1.0-alpha.1",
23
- "@nocobase/database": "2.1.0-alpha.1",
19
+ "@nocobase/utils": "2.1.0-alpha.10",
20
+ "@nocobase/plugin-ui-schema-storage": "2.1.0-alpha.10",
21
+ "@nocobase/actions": "2.1.0-alpha.10",
22
+ "@nocobase/server": "2.1.0-alpha.10",
23
+ "@nocobase/database": "2.1.0-alpha.10",
24
+ "@nocobase/data-source-manager": "2.1.0-alpha.10",
25
+ "@nocobase/flow-engine": "2.1.0-alpha.10",
24
26
  "@formily/shared": "2.3.7",
25
27
  "@formily/react": "2.3.7",
26
- "@formily/antd-v5": "1.2.3",
27
- "@ant-design/icons": "5.6.1"
28
+ "@ant-design/icons": "5.6.1",
29
+ "@formily/antd-v5": "1.2.3"
28
30
  };
@@ -1,15 +1,30 @@
1
1
  {
2
2
  "CC": "CC",
3
3
  "CC to me": "CC to me",
4
+ "CC information": "CC information",
4
5
  "Configure user interface": "Configure user interface",
6
+ "Configure v2 UI": "Configure v2 UI",
7
+ "Before using the v2 UI, you must delete the existing v1 UI. Are you sure you want to delete the v1 UI?": "Before using the v2 UI, you must delete the existing v1 UI. Are you sure you want to delete the v1 UI?",
8
+ "Delete v1 configuration": "Delete v1 configuration",
9
+ "Deleted successfully": "Deleted successfully",
10
+ "Go to configure": "Go to configure",
5
11
  "Mark all as read": "Mark all as read",
6
12
  "Mark as read": "Mark as read",
7
13
  "Mark as unread": "Mark as unread",
14
+ "Refresh": "Refresh",
15
+ "Filter": "Filter",
8
16
  "Provide a CC (carbon copy) feature in workflows to send approvals, or any other type of information to specified users.": "Provide a CC (carbon copy) feature in workflows to send approvals, or any other type of information to specified users.",
9
17
  "Read": "Read",
10
18
  "Recipients": "Recipients",
19
+ "Task card": "Task card",
20
+ "Task title": "Task title",
11
21
  "Title of each CC item in tasks center. Could use variables in string template. Default to node title.": "Title of each CC item in tasks center. Could use variables in string template. Default to node title.",
22
+ "Read at": "Read at",
23
+ "Created at": "Created at",
24
+ "Updated at": "Updated at",
12
25
  "Unread": "Unread",
13
26
  "User interface": "User interface",
14
- "View user interface": "View user interface"
15
- }
27
+ "View user interface": "View user interface",
28
+ "v1 (Legacy)": "v1 (Legacy)",
29
+ "v2": "v2"
30
+ }
@@ -1,15 +1,33 @@
1
1
  {
2
2
  "CC": "抄送",
3
3
  "CC to me": "抄送我的",
4
+ "CC information": "抄送信息",
5
+ "CC node": "抄送节点",
6
+ "Other information": "其他信息",
4
7
  "Configure user interface": "配置用户界面",
8
+ "Configure v2 UI": "配置 v2 界面",
9
+ "Before using the v2 UI, you must delete the existing v1 UI. Are you sure you want to delete the v1 UI?": "使用 v2 界面前,必须删除现有的 v1 界面。确定要删除 v1 界面吗?",
10
+ "Delete v1 configuration": "删除 v1 配置",
11
+ "Deleted successfully": "删除成功",
12
+ "Go to configure": "前往配置",
5
13
  "Mark all as read": "全部标为已读",
6
14
  "Mark as read": "标为已读",
7
15
  "Mark as unread": "标为未读",
16
+ "Refresh": "刷新",
17
+ "Filter": "筛选",
8
18
  "Provide a CC (carbon copy) feature in workflows to send approvals, or any other type of information to specified users.": "在工作流中提供抄送功能,将审批或其他任意信息抄送给特定的用户。",
9
19
  "Read": "已读",
10
20
  "Recipients": "接收人",
21
+ "Task card": "任务卡片",
22
+ "Task title": "任务标题",
23
+ "Status": "状态",
24
+ "Read at": "阅读时间",
25
+ "Created at": "创建时间",
26
+ "Updated at": "更新时间",
11
27
  "Title of each CC item in tasks center. Could use variables in string template. Default to node title.": "待办中心每个抄送项的标题。可以在字符串模板中使用变量。默认为节点标题。",
12
28
  "Unread": "未读",
13
29
  "User interface": "用户界面",
14
- "View user interface": "查看用户界面"
15
- }
30
+ "View user interface": "查看用户界面",
31
+ "v1 (Legacy)": "v1(旧版)",
32
+ "v2": "v2"
33
+ }
@@ -82,15 +82,30 @@ class CCInstruction extends import_plugin_workflow.Instruction {
82
82
  }
83
83
  async duplicateConfig(node, { transaction }) {
84
84
  const uiSchemaRepo = this.workflow.app.db.getRepository("uiSchemas");
85
- if (!node.config.ccDetail) {
86
- return node.config;
85
+ const flowModelRepo = this.workflow.app.db.getRepository("flowModels");
86
+ const nextConfig = { ...node.config };
87
+ if (node.config.ccDetail) {
88
+ const result = await uiSchemaRepo.duplicate(node.config.ccDetail, {
89
+ transaction
90
+ });
91
+ nextConfig.ccDetail = (result == null ? void 0 : result["x-uid"]) ?? (0, import_utils.uid)();
87
92
  }
88
- const result = await uiSchemaRepo.duplicate(node.config.ccDetail, {
89
- transaction
90
- });
91
- return {
92
- ...node.config,
93
- ccDetail: (result == null ? void 0 : result["x-uid"]) ?? (0, import_utils.uid)()
93
+ const duplicateFlowModelUid = async (modelUid) => {
94
+ var _a, _b, _c, _d;
95
+ if (!modelUid) return void 0;
96
+ try {
97
+ const duplicated = await ((_a = flowModelRepo == null ? void 0 : flowModelRepo.duplicate) == null ? void 0 : _a.call(flowModelRepo, modelUid, { transaction }));
98
+ return (duplicated == null ? void 0 : duplicated.uid) || ((_b = duplicated == null ? void 0 : duplicated.data) == null ? void 0 : _b.uid) || ((_d = (_c = duplicated == null ? void 0 : duplicated.data) == null ? void 0 : _c.data) == null ? void 0 : _d.uid) || (0, import_utils.uid)();
99
+ } catch (error) {
100
+ return modelUid;
101
+ }
94
102
  };
103
+ if (node.config.ccUid) {
104
+ nextConfig.ccUid = await duplicateFlowModelUid(node.config.ccUid);
105
+ }
106
+ if (node.config.taskCardUid) {
107
+ nextConfig.taskCardUid = await duplicateFlowModelUid(node.config.taskCardUid);
108
+ }
109
+ return nextConfig;
95
110
  }
96
111
  }
@@ -40,6 +40,12 @@ __export(actions_exports, {
40
40
  });
41
41
  module.exports = __toCommonJS(actions_exports);
42
42
  var import_actions = __toESM(require("@nocobase/actions"));
43
+ var import_tempAssociationFields = require("./tempAssociationFields");
44
+ const mergeAppends = (appends, required) => {
45
+ const result = /* @__PURE__ */ new Set([...appends || []]);
46
+ required.forEach((item) => result.add(item));
47
+ return Array.from(result);
48
+ };
43
49
  const workflowCcTasks = {
44
50
  async get(context, next) {
45
51
  context.action.mergeParams({
@@ -50,12 +56,15 @@ const workflowCcTasks = {
50
56
  return import_actions.default.get(context, next);
51
57
  },
52
58
  async listMine(context, next) {
59
+ var _a;
53
60
  context.action.mergeParams({
54
61
  filter: {
55
62
  userId: context.state.currentUser.id
56
- }
63
+ },
64
+ appends: mergeAppends((_a = context.action.params) == null ? void 0 : _a.appends, ["node", "workflow", "workflow.nodes"])
57
65
  });
58
- return import_actions.default.list(context, next);
66
+ await import_actions.default.list(context, next);
67
+ await (0, import_tempAssociationFields.appendTempAssociationFields)(context);
59
68
  },
60
69
  async read(context, next) {
61
70
  const { filterByTk } = context.action.params;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Context } from '@nocobase/actions';
10
+ export declare function appendTempAssociationFields(context: Context): Promise<void>;
@@ -0,0 +1,304 @@
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 tempAssociationFields_exports = {};
28
+ __export(tempAssociationFields_exports, {
29
+ appendTempAssociationFields: () => appendTempAssociationFields
30
+ });
31
+ module.exports = __toCommonJS(tempAssociationFields_exports);
32
+ var import_data_source_manager = require("@nocobase/data-source-manager");
33
+ var import_tempAssociation = require("../common/tempAssociation");
34
+ const TEMP_ASSOCIATION_FIELDS_LIMIT = 50;
35
+ const toPlainObject = (record) => {
36
+ if (!record || typeof record !== "object") return record;
37
+ if (typeof record.get === "function") return record.get();
38
+ if (typeof record.toJSON === "function") return record.toJSON();
39
+ return record;
40
+ };
41
+ const normalizeTempAssociationConfigs = (configs) => {
42
+ if (!Array.isArray(configs)) return [];
43
+ return configs.filter((config) => !!config && typeof config === "object").map((config) => ({
44
+ nodeId: config.nodeId,
45
+ nodeKey: config.nodeKey,
46
+ nodeType: config.nodeType
47
+ })).filter(
48
+ (config) => config.nodeId !== void 0 && typeof config.nodeKey === "string" && config.nodeKey.length > 0 && (config.nodeType === "workflow" || config.nodeType === "node")
49
+ ).slice(0, TEMP_ASSOCIATION_FIELDS_LIMIT);
50
+ };
51
+ const pickRecordData = (value) => {
52
+ if (!value) return null;
53
+ if (Array.isArray(value)) return value[0] ?? null;
54
+ if ((value == null ? void 0 : value.data) && typeof value.data === "object" && !Array.isArray(value.data)) return value.data;
55
+ return value;
56
+ };
57
+ const getRecordKey = (record, primaryKey) => {
58
+ if (!record || typeof record !== "object") return void 0;
59
+ if (primaryKey && record[primaryKey] != null) return record[primaryKey];
60
+ if (record.id != null) return record.id;
61
+ return void 0;
62
+ };
63
+ const setTaskFieldValue = (task, fieldName, value) => {
64
+ if (task && typeof task.setDataValue === "function") {
65
+ task.setDataValue(fieldName, value);
66
+ return;
67
+ }
68
+ task[fieldName] = value;
69
+ };
70
+ const normalizeNodeConfig = (config) => {
71
+ if (!config) return void 0;
72
+ if (typeof config === "string") {
73
+ try {
74
+ return JSON.parse(config);
75
+ } catch (error) {
76
+ return void 0;
77
+ }
78
+ }
79
+ return config;
80
+ };
81
+ const normalizeAppends = (appends) => {
82
+ if (!Array.isArray(appends)) return [];
83
+ const set = /* @__PURE__ */ new Set();
84
+ appends.forEach((field) => {
85
+ if (typeof field !== "string" || !field) return;
86
+ set.add(field.split(".")[0]);
87
+ set.add(field);
88
+ });
89
+ return Array.from(set);
90
+ };
91
+ const getConfigAppends = (config) => {
92
+ var _a;
93
+ return normalizeAppends(((_a = config == null ? void 0 : config.params) == null ? void 0 : _a.appends) ?? (config == null ? void 0 : config.appends));
94
+ };
95
+ async function appendTempAssociationFields(context) {
96
+ var _a, _b;
97
+ const body = context.body;
98
+ const bodyData = Array.isArray(body) ? body : body == null ? void 0 : body.rows;
99
+ if (!Array.isArray(bodyData) || bodyData.length === 0) {
100
+ return;
101
+ }
102
+ const tasksWithConfig = /* @__PURE__ */ new Map();
103
+ const executionIds = /* @__PURE__ */ new Set();
104
+ const tasksByNodeId = /* @__PURE__ */ new Map();
105
+ const ccNodeConfigMap = /* @__PURE__ */ new Map();
106
+ const ccNodeIdsToFetch = /* @__PURE__ */ new Set();
107
+ const workflowIds = /* @__PURE__ */ new Set();
108
+ bodyData.forEach((task) => {
109
+ var _a2, _b2, _c;
110
+ const nodeId = ((_a2 = task == null ? void 0 : task.node) == null ? void 0 : _a2.id) ?? (task == null ? void 0 : task.nodeId);
111
+ if (nodeId == null) return;
112
+ const tasks = tasksByNodeId.get(nodeId) || [];
113
+ tasks.push(task);
114
+ tasksByNodeId.set(nodeId, tasks);
115
+ if ((_b2 = task == null ? void 0 : task.node) == null ? void 0 : _b2.config) {
116
+ ccNodeConfigMap.set(nodeId, normalizeNodeConfig(task.node.config));
117
+ } else {
118
+ ccNodeIdsToFetch.add(nodeId);
119
+ }
120
+ if (task.executionId) {
121
+ executionIds.add(task.executionId);
122
+ }
123
+ const workflowId = task.workflowId ?? ((_c = task.workflow) == null ? void 0 : _c.id);
124
+ if (workflowId) {
125
+ workflowIds.add(workflowId);
126
+ }
127
+ });
128
+ if (ccNodeIdsToFetch.size) {
129
+ const nodeRepo = context.app.db.getRepository("flow_nodes");
130
+ const nodes = await nodeRepo.find({
131
+ filter: { id: Array.from(ccNodeIdsToFetch) }
132
+ });
133
+ nodes.forEach((node) => {
134
+ ccNodeConfigMap.set(node.id, normalizeNodeConfig(node.config) || {});
135
+ });
136
+ }
137
+ const referencedNodeIds = /* @__PURE__ */ new Set();
138
+ tasksByNodeId.forEach((tasks, nodeId) => {
139
+ const config = normalizeNodeConfig(ccNodeConfigMap.get(nodeId));
140
+ const configs = normalizeTempAssociationConfigs(config == null ? void 0 : config.tempAssociationFields);
141
+ if (!configs.length) return;
142
+ configs.forEach((item) => {
143
+ if (item.nodeType === "node") {
144
+ referencedNodeIds.add(item.nodeId);
145
+ }
146
+ });
147
+ tasks.forEach((task) => {
148
+ tasksWithConfig.set(task, configs);
149
+ });
150
+ });
151
+ if (!tasksWithConfig.size) return;
152
+ const workflowIdsNeedingConfig = /* @__PURE__ */ new Set();
153
+ for (const [task, configs] of tasksWithConfig.entries()) {
154
+ if (!configs.some((config) => config.nodeType === "workflow")) continue;
155
+ const workflow = task.workflow;
156
+ if ((_a = workflow == null ? void 0 : workflow.config) == null ? void 0 : _a.collection) continue;
157
+ const workflowId = task.workflowId ?? (workflow == null ? void 0 : workflow.id);
158
+ if (workflowId) {
159
+ workflowIdsNeedingConfig.add(workflowId);
160
+ }
161
+ }
162
+ if (workflowIdsNeedingConfig.size) {
163
+ const workflowRepo = context.app.db.getRepository("workflows");
164
+ const workflows = await workflowRepo.find({
165
+ filter: { id: Array.from(workflowIdsNeedingConfig) }
166
+ });
167
+ const workflowMap = new Map(workflows.map((workflow) => [workflow.id, workflow]));
168
+ for (const task of tasksWithConfig.keys()) {
169
+ const workflowId = task.workflowId ?? ((_b = task.workflow) == null ? void 0 : _b.id);
170
+ if (!workflowId) continue;
171
+ const stored = workflowMap.get(workflowId);
172
+ if (!stored) continue;
173
+ if (!task.workflow) {
174
+ task.workflow = toPlainObject(stored);
175
+ continue;
176
+ }
177
+ task.workflow.config = stored.config;
178
+ }
179
+ }
180
+ const executionRepo = context.app.db.getRepository("executions");
181
+ const executions = executionIds.size ? await executionRepo.find({
182
+ filter: { id: Array.from(executionIds) },
183
+ appends: ["jobs"]
184
+ }) : [];
185
+ const executionMap = new Map(executions.map((execution) => [execution.id, execution]));
186
+ const workflowNodeMap = /* @__PURE__ */ new Map();
187
+ const collectionCache = /* @__PURE__ */ new Map();
188
+ const pendingGroups = /* @__PURE__ */ new Map();
189
+ if (referencedNodeIds.size) {
190
+ const nodeRepo = context.app.db.getRepository("flow_nodes");
191
+ const nodes = await nodeRepo.find({
192
+ filter: { id: Array.from(referencedNodeIds) }
193
+ });
194
+ nodes.forEach((node) => {
195
+ workflowNodeMap.set(String(node.id), {
196
+ ...node,
197
+ config: normalizeNodeConfig(node.config)
198
+ });
199
+ });
200
+ }
201
+ const getRepository = (dataSourceName, collectionName) => {
202
+ var _a2;
203
+ const cacheKey = `${dataSourceName}:${collectionName}`;
204
+ if (collectionCache.has(cacheKey)) return collectionCache.get(cacheKey);
205
+ const dataSource = context.app.dataSourceManager.dataSources.get(dataSourceName);
206
+ if (!dataSource) return null;
207
+ const collection = dataSource.collectionManager.getCollection(collectionName);
208
+ if (!collection) return null;
209
+ const entry = {
210
+ repository: collection.repository,
211
+ collection,
212
+ filterTargetKey: collection.filterTargetKey || ((_a2 = collection.model) == null ? void 0 : _a2.primaryKeyAttribute)
213
+ };
214
+ collectionCache.set(cacheKey, entry);
215
+ return entry;
216
+ };
217
+ for (const [task, configs] of tasksWithConfig.entries()) {
218
+ const execution = executionMap.get(task.executionId);
219
+ const workflow = task.workflow;
220
+ configs.forEach((config) => {
221
+ var _a2, _b2, _c, _d, _e, _f;
222
+ const fieldName = (0, import_tempAssociation.buildTempAssociationFieldName)(config.nodeType, config.nodeKey);
223
+ let collectionConfig;
224
+ let recordData;
225
+ let appends = [];
226
+ if (config.nodeType === "workflow") {
227
+ collectionConfig = (_a2 = workflow == null ? void 0 : workflow.config) == null ? void 0 : _a2.collection;
228
+ recordData = pickRecordData((_b2 = execution == null ? void 0 : execution.context) == null ? void 0 : _b2.data);
229
+ appends = getConfigAppends(workflow == null ? void 0 : workflow.config);
230
+ } else {
231
+ const node = workflowNodeMap.get(String(config.nodeId));
232
+ collectionConfig = (_c = node == null ? void 0 : node.config) == null ? void 0 : _c.collection;
233
+ const job = (_d = execution == null ? void 0 : execution.jobs) == null ? void 0 : _d.find((item) => String(item.nodeId) === String(config.nodeId));
234
+ recordData = pickRecordData(job == null ? void 0 : job.result);
235
+ appends = getConfigAppends(node == null ? void 0 : node.config);
236
+ }
237
+ if (!collectionConfig) {
238
+ setTaskFieldValue(task, fieldName, null);
239
+ return;
240
+ }
241
+ const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collectionConfig);
242
+ if (!dataSourceName || !collectionName) {
243
+ setTaskFieldValue(task, fieldName, null);
244
+ return;
245
+ }
246
+ const repoEntry = getRepository(dataSourceName, collectionName);
247
+ if (!repoEntry) {
248
+ setTaskFieldValue(task, fieldName, null);
249
+ return;
250
+ }
251
+ const recordKey = getRecordKey(recordData, (_f = (_e = repoEntry.collection) == null ? void 0 : _e.model) == null ? void 0 : _f.primaryKeyAttribute);
252
+ if (recordKey == null) {
253
+ setTaskFieldValue(task, fieldName, recordData ? toPlainObject(recordData) : null);
254
+ return;
255
+ }
256
+ if (Array.isArray(repoEntry.filterTargetKey)) {
257
+ setTaskFieldValue(task, fieldName, recordData ? toPlainObject(recordData) : null);
258
+ return;
259
+ }
260
+ const groupKey = `${dataSourceName}:${collectionName}`;
261
+ const group = pendingGroups.get(groupKey) || {
262
+ dataSourceName,
263
+ collectionName,
264
+ recordKeys: /* @__PURE__ */ new Set(),
265
+ appends: /* @__PURE__ */ new Set(),
266
+ references: []
267
+ };
268
+ group.recordKeys.add(recordKey);
269
+ appends.forEach((append) => group.appends.add(append));
270
+ group.references.push({ task, fieldName, recordKey });
271
+ pendingGroups.set(groupKey, group);
272
+ });
273
+ }
274
+ for (const group of pendingGroups.values()) {
275
+ const repoEntry = getRepository(group.dataSourceName, group.collectionName);
276
+ if (!repoEntry) {
277
+ group.references.forEach(({ task, fieldName }) => {
278
+ setTaskFieldValue(task, fieldName, null);
279
+ });
280
+ continue;
281
+ }
282
+ const filterTargetKey = repoEntry.filterTargetKey;
283
+ if (!filterTargetKey) {
284
+ group.references.forEach(({ task, fieldName }) => {
285
+ setTaskFieldValue(task, fieldName, null);
286
+ });
287
+ continue;
288
+ }
289
+ const records = await repoEntry.repository.find({
290
+ filter: {
291
+ [filterTargetKey]: Array.from(group.recordKeys)
292
+ },
293
+ appends: group.appends.size ? Array.from(group.appends) : void 0
294
+ });
295
+ const recordMap = new Map(records.map((record) => [toPlainObject(record)[filterTargetKey], toPlainObject(record)]));
296
+ group.references.forEach(({ task, fieldName, recordKey }) => {
297
+ setTaskFieldValue(task, fieldName, recordMap.get(recordKey) ?? null);
298
+ });
299
+ }
300
+ }
301
+ // Annotate the CommonJS export names for ESM import in node:
302
+ 0 && (module.exports = {
303
+ appendTempAssociationFields
304
+ });
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  "homepage": "https://docs.nocobase.com/handbook/workflow-cc",
10
10
  "homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/workflow-cc",
11
11
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow-cc",
12
- "license": "AGPL-3.0",
13
- "version": "2.1.0-alpha.1",
12
+ "license": "Apache-2.0",
13
+ "version": "2.1.0-alpha.10",
14
14
  "main": "dist/server/index.js",
15
15
  "peerDependencies": {
16
16
  "@nocobase/actions": "2.x",
@@ -25,5 +25,5 @@
25
25
  "keywords": [
26
26
  "Workflow"
27
27
  ],
28
- "gitHead": "d27baf21569643d6fa83f882233f4e90eb5b89f1"
28
+ "gitHead": "ce790d46c0a5768ca9618c7d0d77ab8300de75c8"
29
29
  }