@nocobase/plugin-flow-engine 2.1.0-alpha.15 → 2.1.0-alpha.17

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 +717 -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 +61 -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 +199 -104
  101. package/dist/server/flow-surfaces/service.js +4158 -1890
  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 +3777 -1581
  108. package/dist/swagger/flow-surfaces.examples.d.ts +1246 -0
  109. package/dist/swagger/flow-surfaces.examples.js +1396 -0
  110. package/dist/swagger/flow-surfaces.js +2020 -1469
  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 +3777 -1581
  116. package/package.json +2 -2
@@ -0,0 +1,717 @@
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 compile_blocks_exports = {};
38
+ __export(compile_blocks_exports, {
39
+ collectReferencedBlockKeys: () => collectReferencedBlockKeys,
40
+ compileTabComposeValues: () => compileTabComposeValues
41
+ });
42
+ module.exports = __toCommonJS(compile_blocks_exports);
43
+ var import_lodash = __toESM(require("lodash"));
44
+ var import_errors = require("../errors");
45
+ var import_service_utils = require("../service-utils");
46
+ var import_private_utils = require("./private-utils");
47
+ const APPLY_BLUEPRINT_BLOCK_TYPE_ENUM = [
48
+ "table",
49
+ "createForm",
50
+ "editForm",
51
+ "details",
52
+ "filterForm",
53
+ "list",
54
+ "gridCard",
55
+ "markdown",
56
+ "iframe",
57
+ "chart",
58
+ "actionPanel",
59
+ "jsBlock"
60
+ ];
61
+ const APPLY_BLUEPRINT_BLOCK_ALLOWED_KEYS = [
62
+ "key",
63
+ "type",
64
+ "title",
65
+ "collection",
66
+ "dataSourceKey",
67
+ "associationPathName",
68
+ "binding",
69
+ "associationField",
70
+ "resource",
71
+ "template",
72
+ "settings",
73
+ "fields",
74
+ "actions",
75
+ "recordActions",
76
+ "script",
77
+ "chart"
78
+ ];
79
+ const APPLY_BLUEPRINT_FIELD_ALLOWED_KEYS = [
80
+ "key",
81
+ "field",
82
+ "associationPathName",
83
+ "renderer",
84
+ "type",
85
+ "label",
86
+ "target",
87
+ "settings",
88
+ "popup",
89
+ "script",
90
+ "chart"
91
+ ];
92
+ const APPLY_BLUEPRINT_ACTION_ALLOWED_KEYS = ["key", "type", "title", "settings", "popup", "script", "chart"];
93
+ const APPLY_BLUEPRINT_POPUP_ALLOWED_KEYS = ["title", "mode", "template", "blocks", "layout"];
94
+ const APPLY_BLUEPRINT_LAYOUT_ALLOWED_KEYS = ["rows"];
95
+ const APPLY_BLUEPRINT_LAYOUT_CELL_ALLOWED_KEYS = ["key", "span"];
96
+ const APPLY_BLUEPRINT_BLOCK_RESOURCE_ALLOWED_KEYS = [
97
+ "binding",
98
+ "dataSourceKey",
99
+ "collectionName",
100
+ "associationField",
101
+ "associationName",
102
+ "associationPathName",
103
+ "sourceId",
104
+ "filterByTk"
105
+ ];
106
+ const APPLY_BLUEPRINT_BLOCK_RESOURCE_RAW_ONLY_KEYS = [
107
+ "associationName",
108
+ "associationPathName",
109
+ "sourceId",
110
+ "filterByTk"
111
+ ];
112
+ const APPLY_BLUEPRINT_BLOCK_RESOURCE_SHORTHAND_KEYS = [
113
+ "collection",
114
+ "dataSourceKey",
115
+ "associationPathName",
116
+ "binding",
117
+ "associationField"
118
+ ];
119
+ const APPLY_BLUEPRINT_RECORD_CAPABLE_BLOCK_TYPES = /* @__PURE__ */ new Set(["table", "details", "list", "gridCard"]);
120
+ const APPLY_BLUEPRINT_AUTO_PROMOTED_RECORD_ACTION_TYPES = /* @__PURE__ */ new Set([
121
+ "view",
122
+ "edit",
123
+ "delete",
124
+ "updateRecord",
125
+ "duplicate"
126
+ ]);
127
+ const APPLY_BLUEPRINT_BLOCK_TYPES = new Set(APPLY_BLUEPRINT_BLOCK_TYPE_ENUM);
128
+ const APPLY_BLUEPRINT_ADD_CHILD_RECORD_ACTION_ERROR = "type 'addChild' must be authored under recordActions and is only valid when the live target catalog.recordActions exposes it for a tree collection table with treeTable enabled";
129
+ function assertNoBlockLevelLayout(input, context) {
130
+ if (Object.prototype.hasOwnProperty.call(input, "layout")) {
131
+ (0, import_errors.throwBadRequest)(`${context}.layout is not supported; layout is only allowed on tabs[] and popup`);
132
+ }
133
+ }
134
+ function assertApplyBlueprintBlockType(type, context) {
135
+ if (!type) {
136
+ return;
137
+ }
138
+ if (type === "form") {
139
+ (0, import_errors.throwBadRequest)(`${context}.type 'form' is unsupported in applyBlueprint; use 'editForm' or 'createForm'`);
140
+ }
141
+ if (!APPLY_BLUEPRINT_BLOCK_TYPES.has(type)) {
142
+ (0, import_errors.throwBadRequest)(
143
+ `${context}.type '${type}' is unsupported in applyBlueprint; supported types: ${APPLY_BLUEPRINT_BLOCK_TYPE_ENUM.join(
144
+ ", "
145
+ )}`
146
+ );
147
+ }
148
+ }
149
+ function normalizeEditPopupBlocks(input, context) {
150
+ input.forEach((block, index) => {
151
+ const blockType = (0, import_private_utils.readOptionalString)(block == null ? void 0 : block.type);
152
+ if (blockType === "form") {
153
+ (0, import_errors.throwBadRequest)(`${context}.blocks[${index}].type 'form' is unsupported in applyBlueprint; use 'editForm'`);
154
+ }
155
+ });
156
+ const editFormBlocks = input.filter((block) => (0, import_private_utils.readOptionalString)(block == null ? void 0 : block.type) === "editForm");
157
+ if (!editFormBlocks.length) {
158
+ (0, import_errors.throwBadRequest)(`${context} custom edit popup must contain exactly one editForm block`);
159
+ }
160
+ if (editFormBlocks.length > 1) {
161
+ (0, import_errors.throwBadRequest)(`${context} custom edit popup must contain exactly one editForm block`);
162
+ }
163
+ return input.map((block, index) => {
164
+ const blockType = (0, import_private_utils.readOptionalString)(block == null ? void 0 : block.type);
165
+ if (blockType !== "editForm") {
166
+ return block;
167
+ }
168
+ if (!import_lodash.default.isPlainObject(block)) {
169
+ return block;
170
+ }
171
+ if (!import_lodash.default.isUndefined(block.resource)) {
172
+ if (import_lodash.default.isPlainObject(block.resource)) {
173
+ const binding = "binding" in block.resource ? (0, import_private_utils.readOptionalString)(block.resource.binding) : void 0;
174
+ if (!binding) {
175
+ (0, import_errors.throwBadRequest)(
176
+ `${context}.blocks[${index}].resource must use binding='currentRecord' or be omitted in a custom edit popup`
177
+ );
178
+ }
179
+ if (binding !== "currentRecord") {
180
+ (0, import_errors.throwBadRequest)(
181
+ `${context}.blocks[${index}].resource.binding must be 'currentRecord' in a custom edit popup`
182
+ );
183
+ }
184
+ }
185
+ return block;
186
+ }
187
+ const shorthandBinding = (0, import_private_utils.readOptionalString)(block.binding);
188
+ if (!import_lodash.default.isUndefined(shorthandBinding)) {
189
+ if (shorthandBinding !== "currentRecord") {
190
+ (0, import_errors.throwBadRequest)(`${context}.blocks[${index}].binding must be 'currentRecord' in a custom edit popup`);
191
+ }
192
+ return block;
193
+ }
194
+ const hasRawShorthandResource = !import_lodash.default.isUndefined(block.collection) || !import_lodash.default.isUndefined(block.dataSourceKey) || !import_lodash.default.isUndefined(block.associationPathName) || !import_lodash.default.isUndefined(block.associationField);
195
+ if (hasRawShorthandResource) {
196
+ (0, import_errors.throwBadRequest)(
197
+ `${context}.blocks[${index}] must use binding='currentRecord' or omit resource entirely in a custom edit popup`
198
+ );
199
+ }
200
+ return {
201
+ ...block,
202
+ resource: {
203
+ binding: "currentRecord"
204
+ }
205
+ };
206
+ });
207
+ }
208
+ function readAssociationFieldFromSingleSegmentPath(value, context) {
209
+ const associationPathName = (0, import_private_utils.readOptionalString)(value);
210
+ if (!associationPathName) {
211
+ return void 0;
212
+ }
213
+ const segments = associationPathName.split(".").map((segment) => segment.trim()).filter(Boolean);
214
+ if (!segments.length) {
215
+ (0, import_errors.throwBadRequest)(`${context}.associationPathName must be a non-empty association field path`);
216
+ }
217
+ if (segments.length > 1) {
218
+ (0, import_errors.throwBadRequest)(
219
+ `${context}.associationPathName '${associationPathName}' must be a single association field name when used with ${context}.binding; prefer ${context}.associationField for popup relation tables`
220
+ );
221
+ }
222
+ return segments[0];
223
+ }
224
+ function normalizeAssociatedRecordsBindingFromAssociationPath(input, context) {
225
+ const binding = (0, import_private_utils.readOptionalString)(input.binding);
226
+ const associationLeaf = readAssociationFieldFromSingleSegmentPath(input.associationPathName, context);
227
+ if (!binding || !associationLeaf) {
228
+ return null;
229
+ }
230
+ if (binding !== "currentRecord" && binding !== "associatedRecords") {
231
+ (0, import_errors.throwBadRequest)(
232
+ `${context} cannot mix ${context}.binding='${binding}' with ${context}.associationPathName; use associatedRecords + associationField on popup collection blocks`
233
+ );
234
+ }
235
+ const associationField = (0, import_private_utils.readOptionalString)(input.associationField);
236
+ if (associationField && associationField !== associationLeaf) {
237
+ (0, import_errors.throwBadRequest)(
238
+ `${context}.associationField '${associationField}' conflicts with ${context}.associationPathName '${(0, import_private_utils.readOptionalString)(
239
+ input.associationPathName
240
+ )}'`
241
+ );
242
+ }
243
+ return {
244
+ binding: "associatedRecords",
245
+ associationField: associationField || associationLeaf
246
+ };
247
+ }
248
+ function readApplyBlueprintActionType(input) {
249
+ if (typeof input === "string") {
250
+ return (0, import_private_utils.readString)(input);
251
+ }
252
+ if (import_lodash.default.isPlainObject(input)) {
253
+ return (0, import_private_utils.readOptionalString)(input.type);
254
+ }
255
+ return void 0;
256
+ }
257
+ function splitApplyBlueprintBlockActionsByScope(block, context) {
258
+ const rawActions = readOptionalItems(block.actions, `${context}.actions`);
259
+ const rawRecordActions = readOptionalItems(block.recordActions, `${context}.recordActions`);
260
+ const blockType = (0, import_private_utils.readOptionalString)(block.type);
261
+ if (!blockType || !APPLY_BLUEPRINT_RECORD_CAPABLE_BLOCK_TYPES.has(blockType)) {
262
+ return {
263
+ actions: rawActions,
264
+ recordActions: rawRecordActions
265
+ };
266
+ }
267
+ const promotedRecordActions = [];
268
+ const remainingActions = [];
269
+ rawActions.forEach((action, index) => {
270
+ const actionType = readApplyBlueprintActionType(action);
271
+ if (actionType === "addChild") {
272
+ (0, import_errors.throwBadRequest)(`${context}.actions[${index}] ${APPLY_BLUEPRINT_ADD_CHILD_RECORD_ACTION_ERROR}`);
273
+ }
274
+ if (actionType && APPLY_BLUEPRINT_AUTO_PROMOTED_RECORD_ACTION_TYPES.has(actionType)) {
275
+ promotedRecordActions.push(action);
276
+ return;
277
+ }
278
+ remainingActions.push(action);
279
+ });
280
+ return {
281
+ actions: remainingActions,
282
+ recordActions: [...rawRecordActions, ...promotedRecordActions]
283
+ };
284
+ }
285
+ function resolveAssetSettings(settings, spec, assets, context) {
286
+ const nextSettings = (0, import_private_utils.cloneOptionalPlainObject)(settings, `${context}.settings`) || {};
287
+ const mergeAsset = (bucket, assetKey) => {
288
+ const normalizedKey = (0, import_private_utils.readOptionalString)(assetKey);
289
+ if (!normalizedKey) {
290
+ return;
291
+ }
292
+ const registry = assets[bucket] || {};
293
+ const asset = registry[normalizedKey];
294
+ if (!import_lodash.default.isPlainObject(asset)) {
295
+ (0, import_errors.throwBadRequest)(`${context} ${bucket.slice(0, -1)} asset '${normalizedKey}' is not defined in assets.${bucket}`);
296
+ }
297
+ import_lodash.default.merge(nextSettings, import_lodash.default.cloneDeep(asset));
298
+ };
299
+ mergeAsset("charts", spec.chart);
300
+ mergeAsset("scripts", spec.script);
301
+ return nextSettings;
302
+ }
303
+ function readOptionalItems(value, context) {
304
+ return (0, import_private_utils.readOptionalArray)(value, context) || [];
305
+ }
306
+ function ensureOptionalTemplate(value, context) {
307
+ return (0, import_private_utils.cloneOptionalPlainObject)(value, context);
308
+ }
309
+ function resolvePopupTitleSettings(settings, title) {
310
+ if (!title) {
311
+ return settings;
312
+ }
313
+ const nextSettings = import_lodash.default.cloneDeep(settings || {});
314
+ if (import_lodash.default.isUndefined(import_lodash.default.get(nextSettings, ["openView", "title"]))) {
315
+ import_lodash.default.set(nextSettings, ["openView", "title"], title);
316
+ }
317
+ return nextSettings;
318
+ }
319
+ function normalizeBlockResourceObject(input, context) {
320
+ (0, import_private_utils.assertOnlyAllowedKeys)(input, context, APPLY_BLUEPRINT_BLOCK_RESOURCE_ALLOWED_KEYS);
321
+ const hasBinding = Object.prototype.hasOwnProperty.call(input, "binding");
322
+ if (hasBinding) {
323
+ const normalizedAssociatedRecords = normalizeAssociatedRecordsBindingFromAssociationPath(input, context);
324
+ const mixedRawKeys = APPLY_BLUEPRINT_BLOCK_RESOURCE_RAW_ONLY_KEYS.filter(
325
+ (key) => Object.prototype.hasOwnProperty.call(input, key) && !(normalizedAssociatedRecords && key === "associationPathName")
326
+ );
327
+ if (mixedRawKeys.length) {
328
+ (0, import_errors.throwBadRequest)(
329
+ `${context} cannot mix binding with ${mixedRawKeys.map((key) => `${context}.${key}`).join(", ")}`
330
+ );
331
+ }
332
+ return (0, import_service_utils.buildDefinedPayload)({
333
+ binding: (normalizedAssociatedRecords == null ? void 0 : normalizedAssociatedRecords.binding) || (0, import_private_utils.assertNonEmptyString)(input.binding, `${context}.binding`),
334
+ dataSourceKey: (0, import_private_utils.readOptionalString)(input.dataSourceKey),
335
+ collectionName: (0, import_private_utils.readOptionalString)(input.collectionName),
336
+ associationField: (normalizedAssociatedRecords == null ? void 0 : normalizedAssociatedRecords.associationField) || (0, import_private_utils.readOptionalString)(input.associationField)
337
+ });
338
+ }
339
+ if (Object.prototype.hasOwnProperty.call(input, "associationField")) {
340
+ (0, import_errors.throwBadRequest)(`${context}.associationField only works when ${context}.binding is provided`);
341
+ }
342
+ const collectionName = (0, import_private_utils.readOptionalString)(input.collectionName);
343
+ const normalized = (0, import_service_utils.buildDefinedPayload)({
344
+ dataSourceKey: (0, import_private_utils.readOptionalString)(input.dataSourceKey) || (collectionName ? "main" : void 0),
345
+ collectionName,
346
+ associationName: (0, import_private_utils.readOptionalString)(input.associationName),
347
+ associationPathName: (0, import_private_utils.readOptionalString)(input.associationPathName),
348
+ sourceId: input.sourceId,
349
+ filterByTk: input.filterByTk
350
+ });
351
+ if (!Object.keys(normalized).length) {
352
+ (0, import_errors.throwBadRequest)(`${context} cannot be empty`);
353
+ }
354
+ return normalized;
355
+ }
356
+ function buildBlockResource(block, context) {
357
+ if (!import_lodash.default.isUndefined(block.resource)) {
358
+ if (!import_lodash.default.isPlainObject(block.resource)) {
359
+ (0, import_errors.throwBadRequest)(`${context}.resource must be an object`);
360
+ }
361
+ const mixedShorthandKeys = APPLY_BLUEPRINT_BLOCK_RESOURCE_SHORTHAND_KEYS.filter(
362
+ (key) => Object.prototype.hasOwnProperty.call(block, key)
363
+ );
364
+ if (mixedShorthandKeys.length) {
365
+ (0, import_errors.throwBadRequest)(
366
+ `${context} cannot mix resource with ${mixedShorthandKeys.map((key) => `${context}.${key}`).join(", ")}`
367
+ );
368
+ }
369
+ return normalizeBlockResourceObject(block.resource, `${context}.resource`);
370
+ }
371
+ const binding = (0, import_private_utils.readOptionalString)(block.binding);
372
+ if (binding) {
373
+ const normalizedAssociatedRecords = normalizeAssociatedRecordsBindingFromAssociationPath(
374
+ block,
375
+ context
376
+ );
377
+ if (Object.prototype.hasOwnProperty.call(block, "associationPathName") && !normalizedAssociatedRecords) {
378
+ (0, import_errors.throwBadRequest)(`${context} cannot mix ${context}.binding with ${context}.associationPathName`);
379
+ }
380
+ return (0, import_service_utils.buildDefinedPayload)({
381
+ binding: (normalizedAssociatedRecords == null ? void 0 : normalizedAssociatedRecords.binding) || binding,
382
+ dataSourceKey: (0, import_private_utils.readOptionalString)(block.dataSourceKey),
383
+ collectionName: (0, import_private_utils.readOptionalString)(block.collection),
384
+ associationField: (normalizedAssociatedRecords == null ? void 0 : normalizedAssociatedRecords.associationField) || (0, import_private_utils.readOptionalString)(block.associationField)
385
+ });
386
+ }
387
+ if (Object.prototype.hasOwnProperty.call(block, "associationField")) {
388
+ (0, import_errors.throwBadRequest)(`${context}.associationField only works when ${context}.binding is provided`);
389
+ }
390
+ const collectionName = (0, import_private_utils.readOptionalString)(block.collection);
391
+ if (!collectionName) {
392
+ return void 0;
393
+ }
394
+ return (0, import_service_utils.buildDefinedPayload)({
395
+ dataSourceKey: (0, import_private_utils.readOptionalString)(block.dataSourceKey) || "main",
396
+ collectionName,
397
+ associationPathName: (0, import_private_utils.readOptionalString)(block.associationPathName)
398
+ });
399
+ }
400
+ function ensureLayoutRows(layout, context) {
401
+ if (import_lodash.default.isUndefined(layout)) {
402
+ return void 0;
403
+ }
404
+ if (!import_lodash.default.isPlainObject(layout)) {
405
+ (0, import_errors.throwBadRequest)(`${context} must be an object`);
406
+ }
407
+ (0, import_private_utils.assertOnlyAllowedKeys)(layout, context, APPLY_BLUEPRINT_LAYOUT_ALLOWED_KEYS);
408
+ if (!Array.isArray(layout.rows) || !layout.rows.length) {
409
+ (0, import_errors.throwBadRequest)(`${context}.rows must be a non-empty array`);
410
+ }
411
+ return layout.rows.map((row, rowIndex) => {
412
+ if (!Array.isArray(row) || !row.length) {
413
+ (0, import_errors.throwBadRequest)(`${context}.rows[${rowIndex}] must be a non-empty array`);
414
+ }
415
+ row.forEach((item, itemIndex) => {
416
+ if (typeof item === "string") {
417
+ return;
418
+ }
419
+ if (!import_lodash.default.isPlainObject(item)) {
420
+ (0, import_errors.throwBadRequest)(`${context}.rows[${rowIndex}][${itemIndex}] must be a string or object`);
421
+ }
422
+ (0, import_private_utils.assertOnlyAllowedKeys)(
423
+ item,
424
+ `${context}.rows[${rowIndex}][${itemIndex}]`,
425
+ APPLY_BLUEPRINT_LAYOUT_CELL_ALLOWED_KEYS
426
+ );
427
+ });
428
+ return row;
429
+ });
430
+ }
431
+ function autoLayoutFromBlockKeys(blockKeys) {
432
+ return {
433
+ rows: blockKeys.map((key) => [key])
434
+ };
435
+ }
436
+ function collectReferencedBlockKeys(layout, context) {
437
+ const referenced = /* @__PURE__ */ new Set();
438
+ const rows = ensureLayoutRows(layout, context) || [];
439
+ rows.forEach((row, rowIndex) => {
440
+ row.forEach((cell, itemIndex) => {
441
+ if (typeof cell === "string") {
442
+ const key2 = (0, import_private_utils.readString)(cell);
443
+ if (key2) {
444
+ referenced.add(key2);
445
+ }
446
+ return;
447
+ }
448
+ const key = (0, import_private_utils.assertNonEmptyString)(cell.key, `${context}.rows[${rowIndex}][${itemIndex}].key`);
449
+ if (key) {
450
+ referenced.add(key);
451
+ }
452
+ });
453
+ });
454
+ return referenced;
455
+ }
456
+ function compileLayout(layout, blockKeysByLocalKey, context) {
457
+ const rows = ensureLayoutRows(layout, context);
458
+ if (!rows) {
459
+ return void 0;
460
+ }
461
+ return {
462
+ rows: rows.map((row, rowIndex) => {
463
+ return row.map((item, itemIndex) => {
464
+ if (typeof item === "string") {
465
+ const itemKey = (0, import_private_utils.readString)(item);
466
+ const resolved2 = blockKeysByLocalKey.get(itemKey) || [...blockKeysByLocalKey.values()].find((value) => value === itemKey);
467
+ if (!resolved2) {
468
+ (0, import_errors.throwBadRequest)(`${context}.rows[${rowIndex}][${itemIndex}] references unknown block '${item}'`);
469
+ }
470
+ return resolved2;
471
+ }
472
+ const rawKey = (0, import_private_utils.assertNonEmptyString)(item.key, `${context}.rows[${rowIndex}][${itemIndex}].key`);
473
+ const resolved = blockKeysByLocalKey.get(rawKey) || [...blockKeysByLocalKey.values()].find((value) => value === rawKey) || rawKey;
474
+ return (0, import_service_utils.buildDefinedPayload)({
475
+ key: resolved,
476
+ span: import_lodash.default.isUndefined(item.span) ? void 0 : import_lodash.default.isNumber(item.span) ? item.span : (0, import_errors.throwBadRequest)(`${context}.rows[${rowIndex}][${itemIndex}].span must be a number`)
477
+ });
478
+ });
479
+ })
480
+ };
481
+ }
482
+ function compilePopup(popup, scopePrefix, assets, context, options = {}) {
483
+ if (import_lodash.default.isUndefined(popup)) {
484
+ return {};
485
+ }
486
+ if (!import_lodash.default.isPlainObject(popup)) {
487
+ (0, import_errors.throwBadRequest)(`${context} must be an object`);
488
+ }
489
+ (0, import_private_utils.assertOnlyAllowedKeys)(popup, context, APPLY_BLUEPRINT_POPUP_ALLOWED_KEYS);
490
+ const popupTitle = (0, import_private_utils.readOptionalString)(popup.title);
491
+ const template = ensureOptionalTemplate(popup.template, `${context}.template`);
492
+ if (template) {
493
+ return {
494
+ popup: {
495
+ template
496
+ },
497
+ popupTitle
498
+ };
499
+ }
500
+ const rawPopupBlocks = readOptionalItems(popup.blocks, `${context}.blocks`);
501
+ const popupBlocks = options.ownerActionType === "edit" && rawPopupBlocks.length ? normalizeEditPopupBlocks(rawPopupBlocks, context) : rawPopupBlocks;
502
+ const compiledBlocks = popupBlocks.length ? compileBlocks(
503
+ popupBlocks,
504
+ scopePrefix,
505
+ assets,
506
+ `${context}.blocks`,
507
+ collectReferencedBlockKeys(popup.layout, `${context}.layout`)
508
+ ) : { blocks: [], blockKeysByLocalKey: /* @__PURE__ */ new Map() };
509
+ const layout = popupBlocks.length || popup.layout ? compileLayout(
510
+ popup.layout || autoLayoutFromBlockKeys(compiledBlocks.blocks.map((block) => block.key)),
511
+ compiledBlocks.blockKeysByLocalKey,
512
+ `${context}.layout`
513
+ ) : void 0;
514
+ const popupMode = (0, import_private_utils.readOptionalString)(popup.mode);
515
+ if (popupMode && popupMode !== "replace" && popupMode !== "append") {
516
+ (0, import_errors.throwBadRequest)(`${context}.mode must be 'replace' or 'append'`);
517
+ }
518
+ const compiledPopup = (0, import_service_utils.buildDefinedPayload)({
519
+ mode: popupMode || (popupBlocks.length || template || layout ? "replace" : void 0),
520
+ template,
521
+ blocks: compiledBlocks.blocks.length ? compiledBlocks.blocks : void 0,
522
+ layout
523
+ });
524
+ return {
525
+ popup: Object.keys(compiledPopup).length ? compiledPopup : {},
526
+ popupTitle
527
+ };
528
+ }
529
+ function resolveTargetBlockKey(value, localBlockKeys, context) {
530
+ if (import_lodash.default.isUndefined(value) || value === null || value === "") {
531
+ return void 0;
532
+ }
533
+ if (typeof value === "string") {
534
+ const normalized = (0, import_private_utils.readString)(value);
535
+ return localBlockKeys.get(normalized) || normalized;
536
+ }
537
+ (0, import_errors.throwBadRequest)(`${context} must be a string block key`);
538
+ }
539
+ function compileField(input, index, scopePrefix, assets, localBlockKeys, context) {
540
+ if (typeof input === "string") {
541
+ const fieldPath2 = (0, import_private_utils.assertNonEmptyString)(input, `${context}[${index}]`);
542
+ return {
543
+ key: (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, fieldPath2), `${context}[${index}]`),
544
+ fieldPath: fieldPath2
545
+ };
546
+ }
547
+ if (!import_lodash.default.isPlainObject(input)) {
548
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be a string or object`);
549
+ }
550
+ (0, import_private_utils.assertOnlyAllowedKeys)(input, `${context}[${index}]`, APPLY_BLUEPRINT_FIELD_ALLOWED_KEYS);
551
+ const fieldPath = (0, import_private_utils.readOptionalString)(input.field);
552
+ const syntheticType = (0, import_private_utils.readOptionalString)(input.type);
553
+ if (!fieldPath && !syntheticType) {
554
+ (0, import_errors.throwBadRequest)(`${context}[${index}] requires field or type`);
555
+ }
556
+ if (fieldPath && syntheticType) {
557
+ (0, import_errors.throwBadRequest)(`${context}[${index}] cannot mix field with synthetic type`);
558
+ }
559
+ const localKey = (0, import_private_utils.normalizeBlueprintLocalKey)(
560
+ input.key,
561
+ fieldPath || (syntheticType ? `${syntheticType}_${index + 1}` : `field_${index + 1}`),
562
+ `${context}[${index}].key`
563
+ );
564
+ const key = (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, localKey), `${context}[${index}]`);
565
+ let settings = resolveAssetSettings(input.settings, input, assets, `${context}[${index}]`);
566
+ if ((0, import_private_utils.readOptionalString)(input.label) && import_lodash.default.isUndefined(settings.label)) {
567
+ settings.label = (0, import_private_utils.readOptionalString)(input.label);
568
+ }
569
+ const popupResult = compilePopup(input.popup, `${key}.popup`, assets, `${context}[${index}].popup`);
570
+ settings = resolvePopupTitleSettings(settings, popupResult.popupTitle);
571
+ return (0, import_service_utils.buildDefinedPayload)({
572
+ key,
573
+ fieldPath,
574
+ associationPathName: (0, import_private_utils.readOptionalString)(input.associationPathName),
575
+ renderer: (0, import_private_utils.readOptionalString)(input.renderer),
576
+ type: syntheticType,
577
+ target: resolveTargetBlockKey(input.target, localBlockKeys, `${context}[${index}].target`),
578
+ settings: Object.keys(settings).length ? settings : void 0,
579
+ popup: popupResult.popup
580
+ });
581
+ }
582
+ function compileAction(input, index, scopePrefix, assets, context) {
583
+ if (typeof input === "string") {
584
+ const type2 = (0, import_private_utils.assertNonEmptyString)(input, `${context}[${index}]`);
585
+ return {
586
+ key: (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, `${type2}_${index + 1}`), `${context}[${index}]`),
587
+ type: type2
588
+ };
589
+ }
590
+ if (!import_lodash.default.isPlainObject(input)) {
591
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be a string or object`);
592
+ }
593
+ (0, import_private_utils.assertOnlyAllowedKeys)(input, `${context}[${index}]`, APPLY_BLUEPRINT_ACTION_ALLOWED_KEYS);
594
+ const type = (0, import_private_utils.assertNonEmptyString)(input.type, `${context}[${index}].type`);
595
+ const localKey = (0, import_private_utils.normalizeBlueprintLocalKey)(input.key, `${type}_${index + 1}`, `${context}[${index}].key`);
596
+ const key = (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, localKey), `${context}[${index}]`);
597
+ let settings = resolveAssetSettings(input.settings, input, assets, `${context}[${index}]`);
598
+ if ((0, import_private_utils.readOptionalString)(input.title) && import_lodash.default.isUndefined(settings.title)) {
599
+ settings.title = (0, import_private_utils.readOptionalString)(input.title);
600
+ }
601
+ const popupResult = compilePopup(input.popup, `${key}.popup`, assets, `${context}[${index}].popup`, {
602
+ ownerActionType: type
603
+ });
604
+ settings = resolvePopupTitleSettings(settings, popupResult.popupTitle);
605
+ return (0, import_service_utils.buildDefinedPayload)({
606
+ key,
607
+ type,
608
+ settings: Object.keys(settings).length ? settings : void 0,
609
+ popup: popupResult.popup
610
+ });
611
+ }
612
+ function compileBlocks(input, scopePrefix, assets, context, requiredExplicitBlockKeys = /* @__PURE__ */ new Set()) {
613
+ const blockKeysByLocalKey = /* @__PURE__ */ new Map();
614
+ const referencedBlockKeys = new Set(requiredExplicitBlockKeys);
615
+ const rawBlocks = import_lodash.default.castArray(input || []);
616
+ rawBlocks.forEach((block, index) => {
617
+ if (!import_lodash.default.isPlainObject(block)) {
618
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be an object`);
619
+ }
620
+ const fields = readOptionalItems(block == null ? void 0 : block.fields, `${context}[${index}].fields`);
621
+ fields.forEach((field, fieldIndex) => {
622
+ if (typeof (field == null ? void 0 : field.target) !== "string" || !field.target.trim()) {
623
+ return;
624
+ }
625
+ referencedBlockKeys.add(
626
+ (0, import_service_utils.normalizeFlowSurfaceComposeKey)(field.target, `${context}[${index}].fields[${fieldIndex}].target`)
627
+ );
628
+ });
629
+ });
630
+ rawBlocks.forEach((block, index) => {
631
+ if (!import_lodash.default.isPlainObject(block)) {
632
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be an object`);
633
+ }
634
+ assertNoBlockLevelLayout(block, `${context}[${index}]`);
635
+ (0, import_private_utils.assertOnlyAllowedKeys)(block, `${context}[${index}]`, APPLY_BLUEPRINT_BLOCK_ALLOWED_KEYS);
636
+ assertApplyBlueprintBlockType((0, import_private_utils.readOptionalString)(block.type), `${context}[${index}]`);
637
+ const explicitKey = (0, import_private_utils.readString)(block.key);
638
+ const fallback = block.type ? `${block.type}_${index + 1}` : `block_${index + 1}`;
639
+ const localKey = (0, import_private_utils.normalizeBlueprintLocalKey)(block.key, fallback, `${context}[${index}].key`);
640
+ if (!explicitKey && referencedBlockKeys.has(localKey)) {
641
+ (0, import_errors.throwBadRequest)(
642
+ `${context}[${index}] must provide key explicitly because it is referenced by layout or field.target`
643
+ );
644
+ }
645
+ if (blockKeysByLocalKey.has(localKey)) {
646
+ (0, import_errors.throwBadRequest)(`${context}[${index}] key '${localKey}' is duplicated`);
647
+ }
648
+ const key = (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, localKey), `${context}[${index}]`);
649
+ blockKeysByLocalKey.set(localKey, key);
650
+ });
651
+ const blocks = rawBlocks.map((block, index) => {
652
+ const blockContext = `${context}[${index}]`;
653
+ const localKey = (0, import_private_utils.normalizeBlueprintLocalKey)(
654
+ block.key,
655
+ block.type ? `${block.type}_${index + 1}` : `block_${index + 1}`,
656
+ `${blockContext}.key`
657
+ );
658
+ const key = blockKeysByLocalKey.get(localKey);
659
+ if (!key) {
660
+ (0, import_errors.throwBadRequest)(`${blockContext} key '${localKey}' is missing after block key compilation`);
661
+ }
662
+ const settings = resolveAssetSettings(block.settings, block, assets, blockContext);
663
+ if ((0, import_private_utils.readOptionalString)(block.title) && import_lodash.default.isUndefined(settings.title)) {
664
+ settings.title = (0, import_private_utils.readOptionalString)(block.title);
665
+ }
666
+ const template = ensureOptionalTemplate(block.template, `${blockContext}.template`);
667
+ const fields = readOptionalItems(block.fields, `${blockContext}.fields`);
668
+ const { actions, recordActions } = splitApplyBlueprintBlockActionsByScope(block, blockContext);
669
+ return (0, import_service_utils.buildDefinedPayload)({
670
+ key,
671
+ type: (0, import_private_utils.readOptionalString)(block.type),
672
+ resource: buildBlockResource(block, blockContext),
673
+ template,
674
+ settings: Object.keys(settings).length ? settings : void 0,
675
+ fields: fields.map(
676
+ (field, fieldIndex) => compileField(field, fieldIndex, key, assets, blockKeysByLocalKey, `${blockContext}.fields`)
677
+ ),
678
+ actions: actions.map(
679
+ (action, actionIndex) => compileAction(action, actionIndex, key, assets, `${blockContext}.actions`)
680
+ ),
681
+ recordActions: recordActions.map(
682
+ (action, actionIndex) => compileAction(action, actionIndex, key, assets, `${blockContext}.recordActions`)
683
+ )
684
+ });
685
+ });
686
+ return {
687
+ blocks,
688
+ blockKeysByLocalKey
689
+ };
690
+ }
691
+ function compileTabComposeValues(tab, document, tabIndex, options) {
692
+ const tabPublicPath = (0, import_private_utils.buildApplyBlueprintTabPublicPath)(tabIndex);
693
+ const blocksPath = `${tabPublicPath}.blocks`;
694
+ const layoutPath = `${tabPublicPath}.layout`;
695
+ const compiledBlocks = compileBlocks(
696
+ tab.blocks,
697
+ tab.key,
698
+ document.assets,
699
+ blocksPath,
700
+ collectReferencedBlockKeys(tab.layout, layoutPath)
701
+ );
702
+ const layout = compileLayout(
703
+ tab.layout || autoLayoutFromBlockKeys(compiledBlocks.blocks.map((block) => block.key)),
704
+ compiledBlocks.blockKeysByLocalKey,
705
+ layoutPath
706
+ );
707
+ return (0, import_service_utils.buildDefinedPayload)({
708
+ mode: options.mode,
709
+ blocks: compiledBlocks.blocks,
710
+ layout
711
+ });
712
+ }
713
+ // Annotate the CommonJS export names for ESM import in node:
714
+ 0 && (module.exports = {
715
+ collectReferencedBlockKeys,
716
+ compileTabComposeValues
717
+ });