@nocobase/plugin-flow-engine 2.1.0-alpha.15 → 2.1.0-alpha.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 (116) hide show
  1. package/dist/externalVersion.js +10 -10
  2. package/dist/node_modules/ses/package.json +1 -1
  3. package/dist/node_modules/zod/package.json +1 -1
  4. package/dist/server/flow-surfaces/{compiler.d.ts → apply/compiler.d.ts} +1 -10
  5. package/dist/server/flow-surfaces/{compiler.js → apply/compiler.js} +41 -280
  6. package/dist/server/flow-surfaces/apply/layout.d.ts +34 -0
  7. package/dist/server/flow-surfaces/apply/layout.js +175 -0
  8. package/dist/server/flow-surfaces/apply/matching.d.ts +16 -0
  9. package/dist/server/flow-surfaces/apply/matching.js +181 -0
  10. package/dist/server/flow-surfaces/association-title-field.d.ts +20 -0
  11. package/dist/server/flow-surfaces/association-title-field.js +158 -0
  12. package/dist/server/flow-surfaces/blueprint/compile-blocks.d.ts +14 -0
  13. package/dist/server/flow-surfaces/blueprint/compile-blocks.js +706 -0
  14. package/dist/server/flow-surfaces/blueprint/compile-plan.d.ts +13 -0
  15. package/dist/server/flow-surfaces/blueprint/compile-plan.js +308 -0
  16. package/dist/server/flow-surfaces/blueprint/compile-reaction.d.ts +11 -0
  17. package/dist/server/flow-surfaces/blueprint/compile-reaction.js +72 -0
  18. package/dist/server/flow-surfaces/blueprint/index.d.ts +12 -0
  19. package/dist/server/flow-surfaces/blueprint/index.js +44 -0
  20. package/dist/server/flow-surfaces/blueprint/normalize-document.d.ts +10 -0
  21. package/dist/server/flow-surfaces/blueprint/normalize-document.js +296 -0
  22. package/dist/server/flow-surfaces/blueprint/private-utils.d.ts +26 -0
  23. package/dist/server/flow-surfaces/blueprint/private-utils.js +182 -0
  24. package/dist/server/flow-surfaces/blueprint/public-types.d.ts +153 -0
  25. package/dist/server/flow-surfaces/blueprint/public-types.js +24 -0
  26. package/dist/server/flow-surfaces/catalog-smart.d.ts +18 -0
  27. package/dist/server/flow-surfaces/catalog-smart.js +239 -0
  28. package/dist/server/flow-surfaces/catalog-smart.projector.d.ts +15 -0
  29. package/dist/server/flow-surfaces/catalog-smart.projector.js +157 -0
  30. package/dist/server/flow-surfaces/catalog-smart.types.d.ts +99 -0
  31. package/dist/server/flow-surfaces/catalog-smart.types.js +24 -0
  32. package/dist/server/flow-surfaces/catalog.d.ts +3 -0
  33. package/dist/server/flow-surfaces/catalog.js +163 -34
  34. package/dist/server/flow-surfaces/compose-compiler.d.ts +104 -0
  35. package/dist/server/flow-surfaces/compose-compiler.js +162 -0
  36. package/dist/server/flow-surfaces/compose-runtime.d.ts +89 -0
  37. package/dist/server/flow-surfaces/compose-runtime.js +338 -0
  38. package/dist/server/flow-surfaces/configure-options.js +12 -3
  39. package/dist/server/flow-surfaces/constants.d.ts +3 -2
  40. package/dist/server/flow-surfaces/constants.js +36 -3
  41. package/dist/server/flow-surfaces/default-action-popup.d.ts +52 -0
  42. package/dist/server/flow-surfaces/default-action-popup.js +258 -0
  43. package/dist/server/flow-surfaces/executor.d.ts +10 -0
  44. package/dist/server/flow-surfaces/executor.js +59 -24
  45. package/dist/server/flow-surfaces/field-binding-registry.d.ts +23 -0
  46. package/dist/server/flow-surfaces/field-binding-registry.js +391 -0
  47. package/dist/server/flow-surfaces/field-semantics.d.ts +1 -1
  48. package/dist/server/flow-surfaces/index.js +75 -0
  49. package/dist/server/flow-surfaces/node-use-sets.d.ts +15 -0
  50. package/dist/server/flow-surfaces/node-use-sets.js +114 -0
  51. package/dist/server/flow-surfaces/payload-shape.d.ts +9 -0
  52. package/dist/server/flow-surfaces/payload-shape.js +64 -0
  53. package/dist/server/flow-surfaces/placement.js +2 -6
  54. package/dist/server/flow-surfaces/planning/action-specs.d.ts +179 -0
  55. package/dist/server/flow-surfaces/planning/action-specs.js +190 -0
  56. package/dist/server/flow-surfaces/planning/compiler.d.ts +37 -0
  57. package/dist/server/flow-surfaces/planning/compiler.js +376 -0
  58. package/dist/server/flow-surfaces/planning/context.d.ts +30 -0
  59. package/dist/server/flow-surfaces/planning/context.js +139 -0
  60. package/dist/server/flow-surfaces/planning/created-keys.d.ts +34 -0
  61. package/dist/server/flow-surfaces/planning/created-keys.js +375 -0
  62. package/dist/server/flow-surfaces/planning/key-kind.d.ts +11 -0
  63. package/dist/server/flow-surfaces/planning/key-kind.js +86 -0
  64. package/dist/server/flow-surfaces/planning/key-persistence.d.ts +34 -0
  65. package/dist/server/flow-surfaces/planning/key-persistence.js +148 -0
  66. package/dist/server/flow-surfaces/planning/key-registry.d.ts +40 -0
  67. package/dist/server/flow-surfaces/planning/key-registry.js +206 -0
  68. package/dist/server/flow-surfaces/planning/runtime.d.ts +37 -0
  69. package/dist/server/flow-surfaces/planning/runtime.js +259 -0
  70. package/dist/server/flow-surfaces/planning/step-link.d.ts +14 -0
  71. package/dist/server/flow-surfaces/planning/step-link.js +104 -0
  72. package/dist/server/flow-surfaces/planning/types.d.ts +55 -0
  73. package/dist/server/flow-surfaces/planning/types.js +24 -0
  74. package/dist/server/flow-surfaces/reaction/errors.d.ts +20 -0
  75. package/dist/server/flow-surfaces/reaction/errors.js +69 -0
  76. package/dist/server/flow-surfaces/reaction/field-value.d.ts +34 -0
  77. package/dist/server/flow-surfaces/reaction/field-value.js +181 -0
  78. package/dist/server/flow-surfaces/reaction/fingerprint.d.ts +16 -0
  79. package/dist/server/flow-surfaces/reaction/fingerprint.js +71 -0
  80. package/dist/server/flow-surfaces/reaction/linkage.d.ts +136 -0
  81. package/dist/server/flow-surfaces/reaction/linkage.js +882 -0
  82. package/dist/server/flow-surfaces/reaction/meta.d.ts +11 -0
  83. package/dist/server/flow-surfaces/reaction/meta.js +451 -0
  84. package/dist/server/flow-surfaces/reaction/registry.d.ts +136 -0
  85. package/dist/server/flow-surfaces/reaction/registry.js +186 -0
  86. package/dist/server/flow-surfaces/reaction/resolver.d.ts +22 -0
  87. package/dist/server/flow-surfaces/reaction/resolver.js +202 -0
  88. package/dist/server/flow-surfaces/reaction/types.d.ts +241 -0
  89. package/dist/server/flow-surfaces/reaction/types.js +24 -0
  90. package/dist/server/flow-surfaces/reaction/utils.d.ts +17 -0
  91. package/dist/server/flow-surfaces/reaction/utils.js +67 -0
  92. package/dist/server/flow-surfaces/reaction/value-expr.d.ts +15 -0
  93. package/dist/server/flow-surfaces/reaction/value-expr.js +209 -0
  94. package/dist/server/flow-surfaces/reference-guards.d.ts +19 -0
  95. package/dist/server/flow-surfaces/reference-guards.js +103 -0
  96. package/dist/server/flow-surfaces/service-helpers.d.ts +42 -0
  97. package/dist/server/flow-surfaces/service-helpers.js +377 -0
  98. package/dist/server/flow-surfaces/service-utils.d.ts +105 -0
  99. package/dist/server/flow-surfaces/service-utils.js +760 -0
  100. package/dist/server/flow-surfaces/service.d.ts +189 -103
  101. package/dist/server/flow-surfaces/service.js +3975 -1770
  102. package/dist/server/flow-surfaces/template-compatibility.d.ts +42 -0
  103. package/dist/server/flow-surfaces/template-compatibility.js +189 -0
  104. package/dist/server/flow-surfaces/template-service-utils.d.ts +62 -0
  105. package/dist/server/flow-surfaces/template-service-utils.js +281 -0
  106. package/dist/server/flow-surfaces/types.d.ts +129 -37
  107. package/dist/swagger/flow-surfaces.d.ts +3773 -1581
  108. package/dist/swagger/flow-surfaces.examples.d.ts +1215 -0
  109. package/dist/swagger/flow-surfaces.examples.js +1363 -0
  110. package/dist/swagger/flow-surfaces.js +2209 -1684
  111. package/dist/swagger/flow-surfaces.template-action-docs.d.ts +62 -0
  112. package/dist/swagger/flow-surfaces.template-action-docs.js +121 -0
  113. package/dist/swagger/flow-surfaces.template-schemas.d.ts +239 -0
  114. package/dist/swagger/flow-surfaces.template-schemas.js +255 -0
  115. package/dist/swagger/index.d.ts +3773 -1581
  116. package/package.json +2 -2
@@ -0,0 +1,42 @@
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 type FlowSurfaceTemplateCompatibilityRow = {
10
+ uid?: string;
11
+ useModel?: string;
12
+ dataSourceKey?: string;
13
+ collectionName?: string;
14
+ associationName?: string;
15
+ };
16
+ export type FlowSurfaceTemplateResourceInfo = {
17
+ dataSourceKey?: string;
18
+ collectionName?: string;
19
+ associationName?: string;
20
+ };
21
+ export type FlowSurfaceTemplateAssociationMatchMode = 'none' | 'exactIfTemplateHasAssociationName' | 'associationResourceOnly';
22
+ export declare function getFlowTemplateRootUseFamily(use: any): string;
23
+ export declare function areFlowTemplateRootUsesCompatible(hostUse: any, templateUse: any): boolean;
24
+ export declare function buildTemplateMissingResourceReason(): string;
25
+ export declare function buildTemplateDataSourceMismatchReason(expectedDataSourceKey: string, actualDataSourceKey: string): string;
26
+ export declare function buildTemplateCollectionMismatchReason(expectedCollectionName: string, actualCollectionName: string): string;
27
+ export declare function buildTemplateAssociationMismatchReason(expectedAssociationName?: string, actualAssociationName?: string): string;
28
+ export declare function buildTemplateMissingContextReason(param: string): string;
29
+ export declare function resolveAssociationTargetResourceInfo(input: FlowSurfaceTemplateResourceInfo, options: {
30
+ getCollection: (dataSourceKey: string, collectionName: string) => any;
31
+ }): FlowSurfaceTemplateResourceInfo;
32
+ export declare function resolveTemplateResourceInfo(input: FlowSurfaceTemplateResourceInfo, options: {
33
+ getCollection: (dataSourceKey: string, collectionName: string) => any;
34
+ }): FlowSurfaceTemplateResourceInfo;
35
+ export declare function resolveBlockTemplateExpectedResourceInfo(node: any, options: {
36
+ resolveTemplateResourceInfo: (input: FlowSurfaceTemplateResourceInfo) => FlowSurfaceTemplateResourceInfo;
37
+ }): FlowSurfaceTemplateResourceInfo;
38
+ export declare function getTemplateResourceCompatibilityDisabledReason(template: FlowSurfaceTemplateCompatibilityRow, expected: FlowSurfaceTemplateResourceInfo, options: {
39
+ associationMatch?: FlowSurfaceTemplateAssociationMatchMode;
40
+ checkResource?: boolean;
41
+ resolveTemplateResourceInfo: (input: FlowSurfaceTemplateResourceInfo) => FlowSurfaceTemplateResourceInfo;
42
+ }): string;
@@ -0,0 +1,189 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
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
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var template_compatibility_exports = {};
38
+ __export(template_compatibility_exports, {
39
+ areFlowTemplateRootUsesCompatible: () => areFlowTemplateRootUsesCompatible,
40
+ buildTemplateAssociationMismatchReason: () => buildTemplateAssociationMismatchReason,
41
+ buildTemplateCollectionMismatchReason: () => buildTemplateCollectionMismatchReason,
42
+ buildTemplateDataSourceMismatchReason: () => buildTemplateDataSourceMismatchReason,
43
+ buildTemplateMissingContextReason: () => buildTemplateMissingContextReason,
44
+ buildTemplateMissingResourceReason: () => buildTemplateMissingResourceReason,
45
+ getFlowTemplateRootUseFamily: () => getFlowTemplateRootUseFamily,
46
+ getTemplateResourceCompatibilityDisabledReason: () => getTemplateResourceCompatibilityDisabledReason,
47
+ resolveAssociationTargetResourceInfo: () => resolveAssociationTargetResourceInfo,
48
+ resolveBlockTemplateExpectedResourceInfo: () => resolveBlockTemplateExpectedResourceInfo,
49
+ resolveTemplateResourceInfo: () => resolveTemplateResourceInfo
50
+ });
51
+ module.exports = __toCommonJS(template_compatibility_exports);
52
+ var import_lodash = __toESM(require("lodash"));
53
+ var import_service_helpers = require("./service-helpers");
54
+ const FLOW_TEMPLATE_ROOT_USE_FAMILIES = {
55
+ CreateFormModel: "crudForm",
56
+ EditFormModel: "crudForm",
57
+ ApplyFormModel: "approvalForm",
58
+ ProcessFormModel: "approvalForm"
59
+ };
60
+ function getFlowTemplateRootUseFamily(use) {
61
+ const normalizedUse = String(use || "").trim();
62
+ return FLOW_TEMPLATE_ROOT_USE_FAMILIES[normalizedUse] || normalizedUse;
63
+ }
64
+ function areFlowTemplateRootUsesCompatible(hostUse, templateUse) {
65
+ const normalizedHostUse = String(hostUse || "").trim();
66
+ const normalizedTemplateUse = String(templateUse || "").trim();
67
+ if (!normalizedHostUse || !normalizedTemplateUse) {
68
+ return true;
69
+ }
70
+ return getFlowTemplateRootUseFamily(normalizedHostUse) === getFlowTemplateRootUseFamily(normalizedTemplateUse);
71
+ }
72
+ function buildTemplateMissingResourceReason() {
73
+ return "missing data source or collection information";
74
+ }
75
+ function buildTemplateDataSourceMismatchReason(expectedDataSourceKey, actualDataSourceKey) {
76
+ return `data source mismatch: expected '${expectedDataSourceKey}', got '${actualDataSourceKey}'`;
77
+ }
78
+ function buildTemplateCollectionMismatchReason(expectedCollectionName, actualCollectionName) {
79
+ return `collection mismatch: expected '${expectedCollectionName}', got '${actualCollectionName}'`;
80
+ }
81
+ function buildTemplateAssociationMismatchReason(expectedAssociationName, actualAssociationName) {
82
+ return `association mismatch: expected '${expectedAssociationName || "(none)"}', got '${actualAssociationName || "(none)"}'`;
83
+ }
84
+ function buildTemplateMissingContextReason(param) {
85
+ return `cannot resolve template parameter '${param}'`;
86
+ }
87
+ function resolveAssociationTargetResourceInfo(input, options) {
88
+ var _a;
89
+ const dataSourceKey = String((input == null ? void 0 : input.dataSourceKey) || "").trim() || void 0;
90
+ const collectionName = String((input == null ? void 0 : input.collectionName) || "").trim() || void 0;
91
+ const associationName = String((input == null ? void 0 : input.associationName) || "").trim() || void 0;
92
+ if (!associationName) {
93
+ return {
94
+ dataSourceKey,
95
+ collectionName
96
+ };
97
+ }
98
+ const parts = associationName.split(".").filter(Boolean);
99
+ const baseCollectionName = (parts.length > 1 ? parts[0] : collectionName) || void 0;
100
+ const fieldPath = (parts.length > 1 ? parts.slice(1).join(".") : associationName) || void 0;
101
+ if (!dataSourceKey || !baseCollectionName || !fieldPath) {
102
+ return {
103
+ dataSourceKey,
104
+ collectionName,
105
+ associationName
106
+ };
107
+ }
108
+ const baseCollection = options.getCollection(dataSourceKey, baseCollectionName);
109
+ const associationField = (0, import_service_helpers.resolveFieldFromCollection)(baseCollection, fieldPath);
110
+ const targetCollection = (0, import_service_helpers.resolveFieldTargetCollection)(
111
+ associationField,
112
+ dataSourceKey,
113
+ (resolvedDsKey, targetCollectionName) => options.getCollection(resolvedDsKey, targetCollectionName)
114
+ );
115
+ return {
116
+ dataSourceKey: (targetCollection == null ? void 0 : targetCollection.dataSourceKey) || ((_a = targetCollection == null ? void 0 : targetCollection.options) == null ? void 0 : _a.dataSourceKey) || dataSourceKey,
117
+ collectionName: (0, import_service_helpers.getCollectionName)(targetCollection) || (0, import_service_helpers.getFieldTarget)(associationField) || collectionName || baseCollectionName,
118
+ associationName
119
+ };
120
+ }
121
+ function resolveTemplateResourceInfo(input, options) {
122
+ return resolveAssociationTargetResourceInfo(input, options);
123
+ }
124
+ function resolveBlockTemplateExpectedResourceInfo(node, options) {
125
+ const init = import_lodash.default.get(node, ["stepParams", "resourceSettings", "init"]) || {};
126
+ return options.resolveTemplateResourceInfo({
127
+ dataSourceKey: String(init.dataSourceKey || "").trim() || void 0,
128
+ collectionName: String(init.collectionName || "").trim() || void 0,
129
+ associationName: String(init.associationName || "").trim() || void 0
130
+ });
131
+ }
132
+ function getTemplateResourceCompatibilityDisabledReason(template, expected, options) {
133
+ const associationMatch = options.associationMatch || "none";
134
+ const checkResource = options.checkResource !== false;
135
+ const templateAssociationName = String((template == null ? void 0 : template.associationName) || "").trim() || void 0;
136
+ const expectedAssociationName = String((expected == null ? void 0 : expected.associationName) || "").trim() || void 0;
137
+ const getAssociationMismatchReason = () => {
138
+ if (associationMatch === "none") {
139
+ return void 0;
140
+ }
141
+ if (associationMatch === "exactIfTemplateHasAssociationName") {
142
+ if (!templateAssociationName || templateAssociationName === expectedAssociationName) {
143
+ return void 0;
144
+ }
145
+ return buildTemplateAssociationMismatchReason(expectedAssociationName, templateAssociationName);
146
+ }
147
+ const toAssociationResource = (value) => value && value.includes(".") ? value : void 0;
148
+ const templateAssociationResource = toAssociationResource(templateAssociationName);
149
+ if (!templateAssociationResource) {
150
+ return void 0;
151
+ }
152
+ const expectedAssociationResource = toAssociationResource(expectedAssociationName);
153
+ if (templateAssociationResource === expectedAssociationResource) {
154
+ return void 0;
155
+ }
156
+ return buildTemplateAssociationMismatchReason(expectedAssociationResource, templateAssociationResource);
157
+ };
158
+ if (!checkResource) {
159
+ return getAssociationMismatchReason();
160
+ }
161
+ const templateResource = options.resolveTemplateResourceInfo(template || {});
162
+ const expectedResource = options.resolveTemplateResourceInfo(expected || {});
163
+ if (expectedResource.dataSourceKey && expectedResource.collectionName) {
164
+ if (!templateResource.dataSourceKey || !templateResource.collectionName) {
165
+ return buildTemplateMissingResourceReason();
166
+ }
167
+ if (templateResource.dataSourceKey !== expectedResource.dataSourceKey) {
168
+ return buildTemplateDataSourceMismatchReason(expectedResource.dataSourceKey, templateResource.dataSourceKey);
169
+ }
170
+ if (templateResource.collectionName !== expectedResource.collectionName) {
171
+ return buildTemplateCollectionMismatchReason(expectedResource.collectionName, templateResource.collectionName);
172
+ }
173
+ }
174
+ return getAssociationMismatchReason();
175
+ }
176
+ // Annotate the CommonJS export names for ESM import in node:
177
+ 0 && (module.exports = {
178
+ areFlowTemplateRootUsesCompatible,
179
+ buildTemplateAssociationMismatchReason,
180
+ buildTemplateCollectionMismatchReason,
181
+ buildTemplateDataSourceMismatchReason,
182
+ buildTemplateMissingContextReason,
183
+ buildTemplateMissingResourceReason,
184
+ getFlowTemplateRootUseFamily,
185
+ getTemplateResourceCompatibilityDisabledReason,
186
+ resolveAssociationTargetResourceInfo,
187
+ resolveBlockTemplateExpectedResourceInfo,
188
+ resolveTemplateResourceInfo
189
+ });
@@ -0,0 +1,62 @@
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 _ from 'lodash';
10
+ import type { FlowSurfaceWriteTarget } from './types';
11
+ export type FlowSurfaceTemplateRow = {
12
+ uid: string;
13
+ name?: string;
14
+ description?: string;
15
+ targetUid?: string;
16
+ useModel?: string;
17
+ type?: string;
18
+ dataSourceKey?: string;
19
+ collectionName?: string;
20
+ associationName?: string;
21
+ filterByTk?: string;
22
+ sourceId?: string;
23
+ usageCount?: number;
24
+ available?: boolean;
25
+ disabledReason?: string;
26
+ };
27
+ export type FlowSurfaceTemplateListValues = {
28
+ search?: string;
29
+ filter?: Record<string, any>;
30
+ sort?: string | string[];
31
+ page?: number;
32
+ pageSize?: number;
33
+ target?: FlowSurfaceWriteTarget;
34
+ type?: 'block' | 'popup';
35
+ usage?: 'block' | 'fields';
36
+ actionType?: string;
37
+ actionScope?: 'block' | 'record';
38
+ };
39
+ export type FlowSurfaceTemplateListPopupActionContext = {
40
+ hasCurrentRecord?: boolean;
41
+ };
42
+ export declare const FLOW_TEMPLATE_SUPPORTED_TYPES: Set<string>;
43
+ export declare const FLOW_TEMPLATE_SUPPORTED_MODES: Set<string>;
44
+ export declare const FLOW_TEMPLATE_BLOCK_USAGES: Set<string>;
45
+ export declare const FLOW_TEMPLATE_UNSUPPORTED_BLOCK_TEMPLATE_SOURCE_USES: Set<string>;
46
+ export declare const POPUP_HOST_STEP_PARAM_PATHS: readonly [readonly ["popupSettings", "openView"], readonly ["selectExitRecordSettings", "openView"], readonly ["openSelectRecordView", "openView"], readonly ["openAddRecordView", "openView"]];
47
+ export declare function normalizeTemplateUidValue(actionName: string, values: Record<string, any>): string;
48
+ export declare function normalizeRequiredTemplateString(actionName: string, value: any, field: string): string;
49
+ export declare function normalizeTemplateSaveMode(actionName: string, value: any): "duplicate" | "convert";
50
+ export declare function buildTemplateListFilter(existingFilter: any, search: any, requestedType?: 'block' | 'popup'): any;
51
+ export declare function findFlowTemplateOpenViewStep(node: any): {
52
+ flowKey: "popupSettings" | "selectExitRecordSettings" | "openSelectRecordView" | "openAddRecordView";
53
+ stepKey: "openView";
54
+ openView: any;
55
+ };
56
+ export declare function buildFlowTemplateReferenceBlockStepParams(template: FlowSurfaceTemplateRow, templateTargetUid: string, resourceInit?: Record<string, any>): _.Dictionary<any>;
57
+ export declare function collectFlowTemplateUsageMapFromModelOptions(modelUid: string, options: any, carry?: Map<string, Set<string>>): Map<string, Set<string>>;
58
+ export declare function collectFlowTemplateModelUids(node: any, carry?: Set<string>): Set<string>;
59
+ export declare function replaceFlowModelTreeUids(node: any, uidMap: Record<string, string>): any;
60
+ export declare function stripTemplateInternalOpenViewFields(openView: any): any;
61
+ export declare function stripTemplateInternalReferenceSettings(node: any): void;
62
+ export declare function findFieldsTemplateReferenceGrid(node: any): import("./types").FlowSurfaceNodeSpec;
@@ -0,0 +1,281 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
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
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var template_service_utils_exports = {};
38
+ __export(template_service_utils_exports, {
39
+ FLOW_TEMPLATE_BLOCK_USAGES: () => FLOW_TEMPLATE_BLOCK_USAGES,
40
+ FLOW_TEMPLATE_SUPPORTED_MODES: () => FLOW_TEMPLATE_SUPPORTED_MODES,
41
+ FLOW_TEMPLATE_SUPPORTED_TYPES: () => FLOW_TEMPLATE_SUPPORTED_TYPES,
42
+ FLOW_TEMPLATE_UNSUPPORTED_BLOCK_TEMPLATE_SOURCE_USES: () => FLOW_TEMPLATE_UNSUPPORTED_BLOCK_TEMPLATE_SOURCE_USES,
43
+ POPUP_HOST_STEP_PARAM_PATHS: () => POPUP_HOST_STEP_PARAM_PATHS,
44
+ buildFlowTemplateReferenceBlockStepParams: () => buildFlowTemplateReferenceBlockStepParams,
45
+ buildTemplateListFilter: () => buildTemplateListFilter,
46
+ collectFlowTemplateModelUids: () => collectFlowTemplateModelUids,
47
+ collectFlowTemplateUsageMapFromModelOptions: () => collectFlowTemplateUsageMapFromModelOptions,
48
+ findFieldsTemplateReferenceGrid: () => findFieldsTemplateReferenceGrid,
49
+ findFlowTemplateOpenViewStep: () => findFlowTemplateOpenViewStep,
50
+ normalizeRequiredTemplateString: () => normalizeRequiredTemplateString,
51
+ normalizeTemplateSaveMode: () => normalizeTemplateSaveMode,
52
+ normalizeTemplateUidValue: () => normalizeTemplateUidValue,
53
+ replaceFlowModelTreeUids: () => replaceFlowModelTreeUids,
54
+ stripTemplateInternalOpenViewFields: () => stripTemplateInternalOpenViewFields,
55
+ stripTemplateInternalReferenceSettings: () => stripTemplateInternalReferenceSettings
56
+ });
57
+ module.exports = __toCommonJS(template_service_utils_exports);
58
+ var import_lodash = __toESM(require("lodash"));
59
+ var import_service_helpers = require("./service-helpers");
60
+ var import_service_utils = require("./service-utils");
61
+ var import_errors = require("./errors");
62
+ const FLOW_TEMPLATE_SUPPORTED_TYPES = /* @__PURE__ */ new Set(["block", "popup"]);
63
+ const FLOW_TEMPLATE_SUPPORTED_MODES = /* @__PURE__ */ new Set(["reference", "copy"]);
64
+ const FLOW_TEMPLATE_BLOCK_USAGES = /* @__PURE__ */ new Set(["block", "fields"]);
65
+ const FLOW_TEMPLATE_UNSUPPORTED_BLOCK_TEMPLATE_SOURCE_USES = /* @__PURE__ */ new Set([
66
+ "ApplyTaskCardDetailsModel",
67
+ "ApprovalTaskCardDetailsModel"
68
+ ]);
69
+ const POPUP_HOST_STEP_PARAM_PATHS = [
70
+ ["popupSettings", "openView"],
71
+ ["selectExitRecordSettings", "openView"],
72
+ ["openSelectRecordView", "openView"],
73
+ ["openAddRecordView", "openView"]
74
+ ];
75
+ function normalizeTemplateUidValue(actionName, values) {
76
+ const templateUid = String((values == null ? void 0 : values.filterByTk) || (values == null ? void 0 : values.uid) || "").trim();
77
+ if (!templateUid) {
78
+ (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} template uid is required`, "FLOW_SURFACE_TEMPLATE_UID_REQUIRED");
79
+ }
80
+ return templateUid;
81
+ }
82
+ function normalizeRequiredTemplateString(actionName, value, field) {
83
+ const normalized = String(value || "").trim();
84
+ if (!normalized) {
85
+ (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} ${field} is required`, "FLOW_SURFACE_TEMPLATE_REQUIRED_FIELD");
86
+ }
87
+ return normalized;
88
+ }
89
+ function normalizeTemplateSaveMode(actionName, value) {
90
+ const normalized = String(value || "duplicate").trim() || "duplicate";
91
+ if (normalized !== "duplicate" && normalized !== "convert") {
92
+ (0, import_errors.throwBadRequest)(
93
+ `flowSurfaces ${actionName} saveMode only supports 'duplicate' or 'convert'`,
94
+ "FLOW_SURFACE_TEMPLATE_SAVE_MODE_UNSUPPORTED"
95
+ );
96
+ }
97
+ return normalized;
98
+ }
99
+ function buildTemplateListFilter(existingFilter, search, requestedType) {
100
+ const typeFilter = requestedType ? { type: requestedType } : void 0;
101
+ return (0, import_service_helpers.buildFlowTemplateSearchFilter)(
102
+ existingFilter && typeFilter ? { $and: [existingFilter, typeFilter] } : existingFilter || typeFilter,
103
+ search
104
+ );
105
+ }
106
+ function findFlowTemplateOpenViewStep(node) {
107
+ for (const [flowKey, stepKey] of POPUP_HOST_STEP_PARAM_PATHS) {
108
+ const openView = import_lodash.default.get(node, ["stepParams", flowKey, stepKey]);
109
+ if (import_lodash.default.isPlainObject(openView)) {
110
+ return {
111
+ flowKey,
112
+ stepKey,
113
+ openView
114
+ };
115
+ }
116
+ }
117
+ return null;
118
+ }
119
+ function buildFlowTemplateReferenceBlockStepParams(template, templateTargetUid, resourceInit) {
120
+ const normalizedResourceInit = (0, import_service_utils.buildDefinedPayload)(resourceInit || {});
121
+ return (0, import_service_utils.buildDefinedPayload)({
122
+ referenceSettings: {
123
+ target: {
124
+ targetUid: templateTargetUid,
125
+ mode: "reference"
126
+ },
127
+ useTemplate: {
128
+ templateUid: template.uid,
129
+ templateName: template.name,
130
+ templateDescription: template.description,
131
+ targetUid: templateTargetUid,
132
+ mode: "reference"
133
+ }
134
+ },
135
+ ...Object.keys(normalizedResourceInit).length ? {
136
+ resourceSettings: {
137
+ init: normalizedResourceInit
138
+ }
139
+ } : {}
140
+ });
141
+ }
142
+ function collectFlowTemplateUsageMapFromModelOptions(modelUid, options, carry = /* @__PURE__ */ new Map()) {
143
+ const normalizedModelUid = String(modelUid || "").trim();
144
+ if (!normalizedModelUid) {
145
+ return carry;
146
+ }
147
+ const addUsage = (templateUid) => {
148
+ var _a;
149
+ const normalizedTemplateUid = String(templateUid || "").trim();
150
+ if (!normalizedTemplateUid) {
151
+ return;
152
+ }
153
+ if (!carry.has(normalizedModelUid)) {
154
+ carry.set(normalizedModelUid, /* @__PURE__ */ new Set());
155
+ }
156
+ (_a = carry.get(normalizedModelUid)) == null ? void 0 : _a.add(normalizedTemplateUid);
157
+ };
158
+ const normalizedOptions = import_lodash.default.isPlainObject(options) || Array.isArray(options) ? options : typeof options === "string" ? JSON.parse(options) : {};
159
+ const useTemplate = import_lodash.default.get(normalizedOptions, ["stepParams", "referenceSettings", "useTemplate"]);
160
+ const useTemplateUid = String((useTemplate == null ? void 0 : useTemplate.templateUid) || "").trim();
161
+ const useTemplateMode = String((useTemplate == null ? void 0 : useTemplate.mode) || "reference").trim() || "reference";
162
+ if (useTemplateUid && useTemplateMode !== "copy") {
163
+ addUsage(useTemplateUid);
164
+ }
165
+ const popupGroups = [
166
+ import_lodash.default.get(normalizedOptions, ["stepParams", "popupSettings"]),
167
+ import_lodash.default.get(normalizedOptions, ["stepParams", "selectExitRecordSettings"])
168
+ ];
169
+ for (const group of popupGroups) {
170
+ if (!group || typeof group !== "object") {
171
+ continue;
172
+ }
173
+ for (const value of Object.values(group)) {
174
+ const popupTemplateUid = String((value == null ? void 0 : value.popupTemplateUid) || "").trim();
175
+ const popupTemplateMode = String((value == null ? void 0 : value.popupTemplateMode) || "reference").trim() || "reference";
176
+ if (popupTemplateUid && popupTemplateMode !== "copy") {
177
+ addUsage(popupTemplateUid);
178
+ }
179
+ }
180
+ }
181
+ return carry;
182
+ }
183
+ function collectFlowTemplateModelUids(node, carry = /* @__PURE__ */ new Set()) {
184
+ if (!(node == null ? void 0 : node.uid)) {
185
+ return carry;
186
+ }
187
+ carry.add(String(node.uid));
188
+ for (const child of Object.values(node.subModels || {})) {
189
+ for (const item of import_lodash.default.castArray(child)) {
190
+ collectFlowTemplateModelUids(item, carry);
191
+ }
192
+ }
193
+ return carry;
194
+ }
195
+ function replaceFlowModelTreeUids(node, uidMap) {
196
+ const replaceInPlace = (value) => {
197
+ if (Array.isArray(value)) {
198
+ for (let i = 0; i < value.length; i += 1) {
199
+ value[i] = replaceInPlace(value[i]);
200
+ }
201
+ return value;
202
+ }
203
+ if (value && typeof value === "object") {
204
+ for (const key of Object.keys(value)) {
205
+ value[key] = replaceInPlace(value[key]);
206
+ }
207
+ return value;
208
+ }
209
+ return typeof value === "string" && uidMap[value] ? uidMap[value] : value;
210
+ };
211
+ const walk = (current) => {
212
+ if (!current || typeof current !== "object") {
213
+ return current;
214
+ }
215
+ if (typeof current.uid === "string" && uidMap[current.uid]) {
216
+ current.uid = uidMap[current.uid];
217
+ }
218
+ if (typeof current.parent === "string" && uidMap[current.parent]) {
219
+ current.parent = uidMap[current.parent];
220
+ }
221
+ if (typeof current.parentId === "string" && uidMap[current.parentId]) {
222
+ current.parentId = uidMap[current.parentId];
223
+ }
224
+ if (current.stepParams) {
225
+ current.stepParams = replaceInPlace(current.stepParams);
226
+ }
227
+ Object.values(current.subModels || {}).forEach((child) => {
228
+ import_lodash.default.castArray(child).forEach((item) => walk(item));
229
+ });
230
+ return current;
231
+ };
232
+ return walk(import_lodash.default.cloneDeep(node));
233
+ }
234
+ function stripTemplateInternalOpenViewFields(openView) {
235
+ if (!import_lodash.default.isPlainObject(openView)) {
236
+ return openView;
237
+ }
238
+ const hasTemplateState = !!String(openView.popupTemplateUid || "").trim() || !!openView.popupTemplateContext || !!String(openView.popupTemplateMode || "").trim();
239
+ return import_lodash.default.omit(openView, [
240
+ "popupTemplateUid",
241
+ "popupTemplateMode",
242
+ "popupTemplateContext",
243
+ "popupTemplateHasFilterByTk",
244
+ "popupTemplateHasSourceId",
245
+ ...hasTemplateState ? ["uid"] : []
246
+ ]);
247
+ }
248
+ function stripTemplateInternalReferenceSettings(node) {
249
+ var _a;
250
+ if (!import_lodash.default.isPlainObject((_a = node == null ? void 0 : node.stepParams) == null ? void 0 : _a.referenceSettings)) {
251
+ return;
252
+ }
253
+ delete node.stepParams.referenceSettings;
254
+ if (import_lodash.default.isPlainObject(node.stepParams) && !Object.keys(node.stepParams).length) {
255
+ delete node.stepParams;
256
+ }
257
+ }
258
+ function findFieldsTemplateReferenceGrid(node) {
259
+ var _a;
260
+ return (0, import_service_utils.getSingleNodeSubModel)((_a = node == null ? void 0 : node.subModels) == null ? void 0 : _a.grid);
261
+ }
262
+ // Annotate the CommonJS export names for ESM import in node:
263
+ 0 && (module.exports = {
264
+ FLOW_TEMPLATE_BLOCK_USAGES,
265
+ FLOW_TEMPLATE_SUPPORTED_MODES,
266
+ FLOW_TEMPLATE_SUPPORTED_TYPES,
267
+ FLOW_TEMPLATE_UNSUPPORTED_BLOCK_TEMPLATE_SOURCE_USES,
268
+ POPUP_HOST_STEP_PARAM_PATHS,
269
+ buildFlowTemplateReferenceBlockStepParams,
270
+ buildTemplateListFilter,
271
+ collectFlowTemplateModelUids,
272
+ collectFlowTemplateUsageMapFromModelOptions,
273
+ findFieldsTemplateReferenceGrid,
274
+ findFlowTemplateOpenViewStep,
275
+ normalizeRequiredTemplateString,
276
+ normalizeTemplateSaveMode,
277
+ normalizeTemplateUidValue,
278
+ replaceFlowModelTreeUids,
279
+ stripTemplateInternalOpenViewFields,
280
+ stripTemplateInternalReferenceSettings
281
+ });