@nocobase/plugin-flow-engine 2.2.0-beta.1 → 2.2.0-beta.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.
Files changed (70) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/externalVersion.js +9 -9
  3. package/dist/locale/en-US.json +1 -0
  4. package/dist/locale/index.d.ts +2 -0
  5. package/dist/locale/zh-CN.json +1 -0
  6. package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
  7. package/dist/node_modules/acorn/package.json +1 -1
  8. package/dist/node_modules/acorn-jsx/package.json +1 -1
  9. package/dist/node_modules/acorn-walk/package.json +1 -1
  10. package/dist/node_modules/ses/package.json +1 -1
  11. package/dist/node_modules/zod/package.json +1 -1
  12. package/dist/server/flow-surfaces/{runjs-authoring/blocked-global-stop/index.d.ts → approval/authoring-validation.d.ts} +1 -2
  13. package/dist/server/flow-surfaces/approval/authoring-validation.js +1151 -0
  14. package/dist/server/flow-surfaces/approval/blueprint-service.js +2 -0
  15. package/dist/server/flow-surfaces/authoring-validation.d.ts +2 -1
  16. package/dist/server/flow-surfaces/authoring-validation.js +495 -57
  17. package/dist/server/flow-surfaces/blueprint/compile-plan.js +19 -15
  18. package/dist/server/flow-surfaces/blueprint/export-document.d.ts +50 -0
  19. package/dist/server/flow-surfaces/blueprint/export-document.js +2510 -0
  20. package/dist/server/flow-surfaces/blueprint/normalize-document.js +2 -1
  21. package/dist/server/flow-surfaces/blueprint/public-types.d.ts +1 -0
  22. package/dist/server/flow-surfaces/builder.js +40 -5
  23. package/dist/server/flow-surfaces/catalog.js +13 -2
  24. package/dist/server/flow-surfaces/configure-options.js +5 -3
  25. package/dist/server/flow-surfaces/constants.d.ts +9 -2
  26. package/dist/server/flow-surfaces/constants.js +1 -0
  27. package/dist/server/flow-surfaces/contract-guard.js +24 -2
  28. package/dist/server/flow-surfaces/default-action-popup.d.ts +2 -0
  29. package/dist/server/flow-surfaces/default-action-popup.js +27 -13
  30. package/dist/server/flow-surfaces/filter-group.d.ts +19 -2
  31. package/dist/server/flow-surfaces/filter-group.js +232 -3
  32. package/dist/server/flow-surfaces/planning/compiler.d.ts +1 -0
  33. package/dist/server/flow-surfaces/planning/compiler.js +205 -82
  34. package/dist/server/flow-surfaces/planning/key-registry.d.ts +1 -1
  35. package/dist/server/flow-surfaces/planning/runtime.js +1 -0
  36. package/dist/server/flow-surfaces/planning/step-link.d.ts +1 -1
  37. package/dist/server/flow-surfaces/planning/step-link.js +22 -3
  38. package/dist/server/flow-surfaces/public-data-surface-default-filter.js +0 -9
  39. package/dist/server/flow-surfaces/reaction/field-value.d.ts +9 -0
  40. package/dist/server/flow-surfaces/reaction/field-value.js +51 -2
  41. package/dist/server/flow-surfaces/reaction/linkage.d.ts +6 -1
  42. package/dist/server/flow-surfaces/reaction/linkage.js +18 -3
  43. package/dist/server/flow-surfaces/reaction/meta.js +19 -1
  44. package/dist/server/flow-surfaces/reaction/types.d.ts +19 -0
  45. package/dist/server/flow-surfaces/relation-backing-foreign-key.d.ts +10 -0
  46. package/dist/server/flow-surfaces/relation-backing-foreign-key.js +79 -0
  47. package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +1 -0
  48. package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +20 -0
  49. package/dist/server/flow-surfaces/runjs-authoring/rules.js +0 -2
  50. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +0 -1
  51. package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +11 -19
  52. package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +0 -12
  53. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +12 -2
  54. package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +0 -14
  55. package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +10 -8
  56. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +0 -14
  57. package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +18 -73
  58. package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
  59. package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +9 -53
  60. package/dist/server/flow-surfaces/service.d.ts +53 -0
  61. package/dist/server/flow-surfaces/service.js +990 -122
  62. package/dist/server/flow-surfaces/types.d.ts +2 -1
  63. package/dist/server/variables/registry.js +3 -0
  64. package/dist/swagger/flow-surfaces.d.ts +193 -0
  65. package/dist/swagger/flow-surfaces.examples.d.ts +11 -0
  66. package/dist/swagger/flow-surfaces.examples.js +11 -0
  67. package/dist/swagger/flow-surfaces.js +179 -10
  68. package/dist/swagger/index.d.ts +193 -0
  69. package/package.json +2 -2
  70. package/dist/server/flow-surfaces/runjs-authoring/blocked-global-stop/index.js +0 -40
@@ -36,11 +36,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
36
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
37
  var filter_group_exports = {};
38
38
  __export(filter_group_exports, {
39
+ FLOW_SURFACE_DATE_FILTER_OPERATORS: () => FLOW_SURFACE_DATE_FILTER_OPERATORS,
39
40
  FLOW_SURFACE_EMPTY_FILTER_GROUP: () => FLOW_SURFACE_EMPTY_FILTER_GROUP,
40
41
  FLOW_SURFACE_FILTER_GROUP_EXAMPLE: () => FLOW_SURFACE_FILTER_GROUP_EXAMPLE,
41
42
  assertFlowSurfaceFilterGroupShape: () => assertFlowSurfaceFilterGroupShape,
42
43
  assertFlowSurfaceFilterOperator: () => assertFlowSurfaceFilterOperator,
44
+ isFlowSurfaceDateLikeFieldMeta: () => isFlowSurfaceDateLikeFieldMeta,
43
45
  normalizeFlowSurfaceCompatibleFilterGroupValue: () => normalizeFlowSurfaceCompatibleFilterGroupValue,
46
+ normalizeFlowSurfaceDateConditionValue: () => normalizeFlowSurfaceDateConditionValue,
44
47
  normalizeFlowSurfaceFilterDateValue: () => normalizeFlowSurfaceFilterDateValue,
45
48
  normalizeFlowSurfaceFilterGroupValue: () => normalizeFlowSurfaceFilterGroupValue,
46
49
  normalizeFlowSurfaceStrictFilterDateValue: () => normalizeFlowSurfaceStrictFilterDateValue
@@ -76,6 +79,17 @@ const FLOW_SURFACE_DATE_FILTER_OPERATORS = /* @__PURE__ */ new Set([
76
79
  "$dateNotAfter",
77
80
  "$dateBetween"
78
81
  ]);
82
+ const FLOW_SURFACE_DATE_COMPARISON_OPERATORS = /* @__PURE__ */ new Set(["$eq", "$ne", "$lt", "$lte", "$gt", "$gte", "$in", "$notIn"]);
83
+ const FLOW_SURFACE_EMPTY_FILTER_OPERATORS = /* @__PURE__ */ new Set(["$empty", "$notEmpty", "$exists", "$notExists"]);
84
+ const FLOW_SURFACE_DATE_LIKE_TYPES = /* @__PURE__ */ new Set([
85
+ "date",
86
+ "datetime",
87
+ "dateonly",
88
+ "datetimenotz",
89
+ "unixtimestamp",
90
+ "createdat",
91
+ "updatedat"
92
+ ]);
79
93
  const FLOW_SURFACE_DATE_RANGE_TYPES = /* @__PURE__ */ new Set([
80
94
  "today",
81
95
  "yesterday",
@@ -109,6 +123,18 @@ const FLOW_SURFACE_DATE_VALUE_REPAIR_EXAMPLE = {
109
123
  }
110
124
  ]
111
125
  };
126
+ const FLOW_SURFACE_DATE_CONDITION_REPAIR_HINT = "Date/DateTime condition values must be valid UI date values or safe context-path templates. Do not use template arithmetic such as {{$now - 14 * 24 * 60 * 60 * 1000}}; use date operators such as $dateBefore with a relative descriptor instead.";
127
+ const FLOW_SURFACE_DATE_CONDITION_REPAIR_EXAMPLE = {
128
+ logic: "$and",
129
+ items: [
130
+ {
131
+ path: "lastFollowUpAt",
132
+ operator: "$dateBefore",
133
+ value: { type: "past", number: 14, unit: "day" }
134
+ }
135
+ ]
136
+ };
137
+ const FLOW_SURFACE_ISO_DATE_VALUE_RE = /^\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,6})?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
112
138
  const FLOW_SURFACE_KNOWN_FILTER_OPERATORS = buildFlowSurfaceKnownFilterOperators();
113
139
  function buildFlowSurfaceKnownFilterOperators() {
114
140
  const operators = new Set(Object.keys(import_database.operators));
@@ -156,13 +182,16 @@ function assertFlowSurfaceFilterOperator(operator, path) {
156
182
  );
157
183
  }
158
184
  }
159
- function normalizeFlowSurfaceFilterDateValue(operator, value, path) {
185
+ function normalizeFlowSurfaceFilterDateValue(operator, value, path, options = {}) {
160
186
  if (typeof operator !== "string" || !FLOW_SURFACE_DATE_FILTER_OPERATORS.has(operator)) {
161
187
  return value;
162
188
  }
189
+ if (options.allowContextPathValue && isFlowSurfaceContextPathValueObject(value)) {
190
+ return value;
191
+ }
163
192
  return normalizeFlowSurfaceDateValue(value, path);
164
193
  }
165
- function normalizeFlowSurfaceStrictFilterDateValue(operator, value, path) {
194
+ function normalizeFlowSurfaceStrictFilterDateValue(operator, value, path, options = {}) {
166
195
  if (typeof operator !== "string" || !FLOW_SURFACE_DATE_FILTER_OPERATORS.has(operator)) {
167
196
  return value;
168
197
  }
@@ -171,8 +200,33 @@ function normalizeFlowSurfaceStrictFilterDateValue(operator, value, path) {
171
200
  invalidReason: "date filter value is required"
172
201
  });
173
202
  }
203
+ if (options.allowContextPathValue && isFlowSurfaceContextPathValueObject(value)) {
204
+ return value;
205
+ }
174
206
  return normalizeFlowSurfaceDateValue(value, path);
175
207
  }
208
+ function isFlowSurfaceDateLikeFieldMeta(value) {
209
+ const fieldType = String((value == null ? void 0 : value.type) || "").trim().toLowerCase();
210
+ const fieldInterface = String((value == null ? void 0 : value.interface) || "").trim().toLowerCase();
211
+ return FLOW_SURFACE_DATE_LIKE_TYPES.has(fieldType) || FLOW_SURFACE_DATE_LIKE_TYPES.has(fieldInterface);
212
+ }
213
+ function normalizeFlowSurfaceDateConditionValue(operator, value, path, options = {}) {
214
+ const normalizedOperator = typeof operator === "string" ? operator.trim() : "";
215
+ if (!normalizedOperator || FLOW_SURFACE_EMPTY_FILTER_OPERATORS.has(normalizedOperator)) {
216
+ return value;
217
+ }
218
+ if (options.allowContextPathValue && isFlowSurfaceContextPathValueObject(value)) {
219
+ return value;
220
+ }
221
+ if (FLOW_SURFACE_DATE_FILTER_OPERATORS.has(normalizedOperator)) {
222
+ assertNoUnsafeFlowSurfaceDateTemplateValues(value, path, options);
223
+ return normalizeFlowSurfaceStrictFilterDateValue(normalizedOperator, value, path);
224
+ }
225
+ if (!FLOW_SURFACE_DATE_COMPARISON_OPERATORS.has(normalizedOperator)) {
226
+ return value;
227
+ }
228
+ return normalizeFlowSurfaceDateComparisonValue(normalizedOperator, value, path, options);
229
+ }
176
230
  function normalizeFlowSurfaceFilterGroupValue(value, errorPrefix, options = {}) {
177
231
  const normalized = value === null || import_lodash.default.isPlainObject(value) && !Object.keys(value).length ? import_lodash.default.cloneDeep(FLOW_SURFACE_EMPTY_FILTER_GROUP) : import_lodash.default.cloneDeep(value);
178
232
  try {
@@ -332,7 +386,11 @@ function normalizeFlowSurfaceFilterGroupDateValues(filter, errorPrefix, options)
332
386
  normalizeFlowSurfaceFilterGroupDateValues(item, itemPath, options);
333
387
  return;
334
388
  }
335
- item.value = options.strictDateValues ? normalizeFlowSurfaceStrictFilterDateValue(item.operator, item.value, `${itemPath}.value`) : normalizeFlowSurfaceFilterDateValue(item.operator, item.value, `${itemPath}.value`);
389
+ item.value = options.strictDateValues ? normalizeFlowSurfaceStrictFilterDateValue(item.operator, item.value, `${itemPath}.value`, {
390
+ allowContextPathValue: options.allowContextPathValue
391
+ }) : normalizeFlowSurfaceFilterDateValue(item.operator, item.value, `${itemPath}.value`, {
392
+ allowContextPathValue: options.allowContextPathValue
393
+ });
336
394
  });
337
395
  }
338
396
  function normalizeFlowSurfaceDateValue(value, path) {
@@ -344,6 +402,82 @@ function normalizeFlowSurfaceDateValue(value, path) {
344
402
  }
345
403
  return normalizeFlowSurfaceDateValuePart(value, path);
346
404
  }
405
+ function normalizeFlowSurfaceDateComparisonValue(operator, value, path, options) {
406
+ if (operator === "$in" || operator === "$notIn") {
407
+ if (!Array.isArray(value)) {
408
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
409
+ ...options,
410
+ operator,
411
+ invalidReason: "date comparison array operators require an array value"
412
+ });
413
+ }
414
+ return value.map(
415
+ (item, index) => normalizeFlowSurfaceDateComparisonValuePart(item, `${path}[${index}]`, {
416
+ ...options,
417
+ operator
418
+ })
419
+ );
420
+ }
421
+ return normalizeFlowSurfaceDateComparisonValuePart(value, path, {
422
+ ...options,
423
+ operator
424
+ });
425
+ }
426
+ function normalizeFlowSurfaceDateComparisonValuePart(value, path, options) {
427
+ if (import_lodash.default.isNil(value) || value === "") {
428
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
429
+ ...options,
430
+ invalidReason: "date comparison value is required; use $empty or $notEmpty for empty checks"
431
+ });
432
+ }
433
+ if (options.allowContextPathValue && isFlowSurfaceContextPathValueObject(value)) {
434
+ return value;
435
+ }
436
+ if (isTemplateDateString(value)) {
437
+ if (isUnsafeFlowSurfaceDateTemplateString(value)) {
438
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
439
+ ...options,
440
+ invalidReason: "date condition template strings must be simple context-path references; template arithmetic, $now, Date/dayjs/moment calls, and Invalid date are not supported"
441
+ });
442
+ }
443
+ return value;
444
+ }
445
+ if (import_lodash.default.isDate(value)) {
446
+ if (!Number.isNaN(value.getTime())) {
447
+ return value;
448
+ }
449
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
450
+ ...options,
451
+ invalidReason: "date condition value must be a valid Date"
452
+ });
453
+ }
454
+ if (typeof value === "string") {
455
+ const normalized = value.trim();
456
+ if (/invalid\s+date/i.test(normalized)) {
457
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
458
+ ...options,
459
+ invalidReason: "date condition value cannot be Invalid date"
460
+ });
461
+ }
462
+ if (isFlowSurfaceIsoLikeDateValue(normalized)) {
463
+ return normalized;
464
+ }
465
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
466
+ ...options,
467
+ invalidReason: "date comparison strings must use concrete YYYY-MM-DD or ISO-like date/datetime strings"
468
+ });
469
+ }
470
+ if (import_lodash.default.isPlainObject(value)) {
471
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
472
+ ...options,
473
+ invalidReason: "relative date descriptors require date operators such as $dateBefore or $dateBetween instead of comparison operators"
474
+ });
475
+ }
476
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
477
+ ...options,
478
+ invalidReason: "date condition value must be an exact date string, ISO datetime string, or safe context path template"
479
+ });
480
+ }
347
481
  function normalizeFlowSurfaceDateArrayValue(value, path) {
348
482
  if (value.length !== 2) {
349
483
  throwInvalidFlowSurfaceDateValue(path, value, {
@@ -386,6 +520,25 @@ function isFlowSurfaceExactDateValue(value) {
386
520
  return parsed.isValid() && parsed.format(format) === value;
387
521
  });
388
522
  }
523
+ function isFlowSurfaceIsoLikeDateValue(value) {
524
+ const match = FLOW_SURFACE_ISO_DATE_VALUE_RE.exec(value);
525
+ if (!match) {
526
+ return false;
527
+ }
528
+ const [year, month, day] = value.slice(0, 10).split("-").map((item) => Number(item));
529
+ const date = new Date(Date.UTC(year, month - 1, day));
530
+ if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) {
531
+ return false;
532
+ }
533
+ const timeMatch = /[T\s](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,6}))?)?/.exec(value);
534
+ if (!timeMatch) {
535
+ return true;
536
+ }
537
+ const hour = Number(timeMatch[1]);
538
+ const minute = Number(timeMatch[2]);
539
+ const second = Number(timeMatch[3] || 0);
540
+ return hour <= 23 && minute <= 59 && second <= 59 && (0, import_utils.dayjs)(value).isValid();
541
+ }
389
542
  function normalizeRelativeDateDescriptor(value, path) {
390
543
  const invalidKeys = Object.keys(value).filter((key) => !FLOW_SURFACE_RELATIVE_DATE_DESCRIPTOR_KEYS.has(key));
391
544
  if (invalidKeys.length) {
@@ -456,6 +609,67 @@ function normalizeRelativeDateDescriptor(value, path) {
456
609
  function isTemplateDateString(value) {
457
610
  return typeof value === "string" && /^\s*\{\{[\s\S]*\}\}\s*$/.test(value);
458
611
  }
612
+ function isFlowSurfaceContextPathValueObject(value) {
613
+ if (!import_lodash.default.isPlainObject(value) || value.source !== "path") {
614
+ return false;
615
+ }
616
+ const path = value.path;
617
+ if (typeof path !== "string") {
618
+ return false;
619
+ }
620
+ const normalizedPath = path.trim();
621
+ if (isTemplateDateString(normalizedPath)) {
622
+ return !isUnsafeFlowSurfaceDateTemplateString(normalizedPath);
623
+ }
624
+ return isSimpleFlowSurfaceTemplateReference(normalizedPath);
625
+ }
626
+ function extractTemplateDateExpression(value) {
627
+ return value.replace(/^\s*\{\{\s*/, "").replace(/\s*\}\}\s*$/, "").trim();
628
+ }
629
+ function isSimpleFlowSurfaceTemplateReference(expression) {
630
+ const identifier = "[A-Za-z_$][A-Za-z0-9_$-]*";
631
+ const segment = `(?:\\.${identifier}|\\[(?:\\d+|"[^"\\]]+"|'[^'\\]]+')\\])`;
632
+ return new RegExp(`^${identifier}(?:${segment})*$`).test(expression.replace(/\s+/g, ""));
633
+ }
634
+ function isUnsafeFlowSurfaceDateTemplateString(value) {
635
+ const expression = extractTemplateDateExpression(value);
636
+ if (!expression) {
637
+ return true;
638
+ }
639
+ if (/\$now\b/i.test(expression)) {
640
+ return true;
641
+ }
642
+ if (/invalid\s+date/i.test(expression)) {
643
+ return true;
644
+ }
645
+ if (/\bnew\s+Date\b|\bDate\s*\(|\bdayjs\s*\(|\bmoment\s*\(/.test(expression)) {
646
+ return true;
647
+ }
648
+ if (isSimpleFlowSurfaceTemplateReference(expression)) {
649
+ return false;
650
+ }
651
+ return /[+\-*/%()]|=>/.test(expression);
652
+ }
653
+ function assertNoUnsafeFlowSurfaceDateTemplateValues(value, path, options = {}) {
654
+ if (isTemplateDateString(value)) {
655
+ if (isUnsafeFlowSurfaceDateTemplateString(value)) {
656
+ throwInvalidFlowSurfaceDateConditionValue(path, value, {
657
+ ...options,
658
+ invalidReason: "date filter template strings must be simple context-path references; template arithmetic, $now, Date/dayjs/moment calls, and Invalid date are not supported"
659
+ });
660
+ }
661
+ return;
662
+ }
663
+ if (Array.isArray(value)) {
664
+ value.forEach((item, index) => assertNoUnsafeFlowSurfaceDateTemplateValues(item, `${path}[${index}]`, options));
665
+ return;
666
+ }
667
+ if (import_lodash.default.isPlainObject(value)) {
668
+ Object.entries(value).forEach(
669
+ ([key, item]) => assertNoUnsafeFlowSurfaceDateTemplateValues(item, `${path}.${key}`, options)
670
+ );
671
+ }
672
+ }
459
673
  function hasTemplateDateValue(value) {
460
674
  if (isTemplateDateString(value)) {
461
675
  return true;
@@ -468,6 +682,18 @@ function hasTemplateDateValue(value) {
468
682
  }
469
683
  return false;
470
684
  }
685
+ function throwInvalidFlowSurfaceDateConditionValue(path, value, details = {}) {
686
+ (0, import_errors.throwBadRequest)(`${path} must be a valid Date/DateTime condition value`, {
687
+ path,
688
+ ruleId: "date-condition-value-invalid",
689
+ details: {
690
+ invalidValue: value,
691
+ ...details,
692
+ repairHint: FLOW_SURFACE_DATE_CONDITION_REPAIR_HINT,
693
+ repairExample: FLOW_SURFACE_DATE_CONDITION_REPAIR_EXAMPLE
694
+ }
695
+ });
696
+ }
471
697
  function throwInvalidFlowSurfaceDateValue(path, value, details = {}) {
472
698
  (0, import_errors.throwBadRequest)(`${path} must be a valid date filter value`, {
473
699
  path,
@@ -482,11 +708,14 @@ function throwInvalidFlowSurfaceDateValue(path, value, details = {}) {
482
708
  }
483
709
  // Annotate the CommonJS export names for ESM import in node:
484
710
  0 && (module.exports = {
711
+ FLOW_SURFACE_DATE_FILTER_OPERATORS,
485
712
  FLOW_SURFACE_EMPTY_FILTER_GROUP,
486
713
  FLOW_SURFACE_FILTER_GROUP_EXAMPLE,
487
714
  assertFlowSurfaceFilterGroupShape,
488
715
  assertFlowSurfaceFilterOperator,
716
+ isFlowSurfaceDateLikeFieldMeta,
489
717
  normalizeFlowSurfaceCompatibleFilterGroupValue,
718
+ normalizeFlowSurfaceDateConditionValue,
490
719
  normalizeFlowSurfaceFilterDateValue,
491
720
  normalizeFlowSurfaceFilterGroupValue,
492
721
  normalizeFlowSurfaceStrictFilterDateValue
@@ -22,6 +22,7 @@ type CompilePlanStepDeps = NormalizePlanSelectorDeps & {
22
22
  resolveLocator: (target: FlowSurfaceReadLocator, options?: {
23
23
  transaction?: any;
24
24
  }) => Promise<FlowSurfaceResolvedTarget>;
25
+ loadResolvedSurfaceTree?: (resolved: FlowSurfaceResolvedTarget, transaction?: any) => Promise<any>;
25
26
  buildPlanKeyKind: (node: any, resolvedKind?: string) => string;
26
27
  };
27
28
  export declare function normalizePlanSelector(actionName: string, selector: any, deps: NormalizePlanSelectorDeps, fieldName?: string, options?: NormalizePlanSelectorOptions): FlowSurfacePlanSelector;
@@ -180,6 +180,8 @@ async function resolvePlanSelectorInContext(actionName, selector, context, deps,
180
180
  uid: resolved.uid,
181
181
  source: "system",
182
182
  kind: deps.buildPlanKeyKind(node, resolved.kind),
183
+ node: node || resolved.node,
184
+ resolved,
183
185
  locator: (0, import_service_utils.buildDefinedPayload)({
184
186
  uid: normalizedSelector.locator.uid,
185
187
  pageSchemaUid: normalizedSelector.locator.pageSchemaUid,
@@ -217,51 +219,146 @@ function buildSelectorRuntimeValue(selector) {
217
219
  }
218
220
  return selector.uid;
219
221
  }
222
+ function getResolvedSelectorUid(selector) {
223
+ if (!selector || "summary" in selector) {
224
+ return void 0;
225
+ }
226
+ return selector.uid;
227
+ }
228
+ function isReplaceComposeStep(step) {
229
+ var _a;
230
+ return step.action === "compose" && String(((_a = step.values) == null ? void 0 : _a.mode) || "").trim() === "replace";
231
+ }
232
+ function assertReplaceComposeTargetSupportsScopeResolution(actionName, index, step, target) {
233
+ if (!isReplaceComposeStep(step) || !target || !("summary" in target) || target.summary.source !== "step") {
234
+ return;
235
+ }
236
+ (0, import_errors.throwBadRequest)(
237
+ `flowSurfaces ${actionName} plan.steps[${index}] compose replace does not support selectors.target.step; use a concrete locator or key for the existing replace target`
238
+ );
239
+ }
240
+ function collectDescendantUids(node, carry = /* @__PURE__ */ new Set()) {
241
+ if (!node || typeof node !== "object") {
242
+ return carry;
243
+ }
244
+ for (const value of Object.values(node.subModels || {})) {
245
+ for (const child of import_lodash.default.castArray(value)) {
246
+ if (child == null ? void 0 : child.uid) {
247
+ carry.add(child.uid);
248
+ }
249
+ collectDescendantUids(child, carry);
250
+ }
251
+ }
252
+ return carry;
253
+ }
254
+ function collectNodeAndDescendantUids(node, carry = /* @__PURE__ */ new Set()) {
255
+ if (!node || typeof node !== "object") {
256
+ return carry;
257
+ }
258
+ if (node.uid) {
259
+ carry.add(node.uid);
260
+ }
261
+ return collectDescendantUids(node, carry);
262
+ }
263
+ function findNodeInTreeByUid(node, uid) {
264
+ if (!node || typeof node !== "object" || !uid) {
265
+ return void 0;
266
+ }
267
+ if (node.uid === uid) {
268
+ return node;
269
+ }
270
+ for (const value of Object.values(node.subModels || {})) {
271
+ for (const child of import_lodash.default.castArray(value)) {
272
+ const matched = findNodeInTreeByUid(child, uid);
273
+ if (matched) {
274
+ return matched;
275
+ }
276
+ }
277
+ }
278
+ return void 0;
279
+ }
280
+ function getContextNodeByUid(context, uid) {
281
+ if (!uid) {
282
+ return void 0;
283
+ }
284
+ return findNodeInTreeByUid(context.publicTree, uid) || findNodeInTreeByUid(context.rawTree, uid);
285
+ }
286
+ function getSingleSubModel(node, key) {
287
+ var _a;
288
+ const value = (_a = node == null ? void 0 : node.subModels) == null ? void 0 : _a[key];
289
+ return Array.isArray(value) ? value[0] : value;
290
+ }
291
+ function getSubModelList(node, key) {
292
+ var _a;
293
+ return import_lodash.default.castArray(((_a = node == null ? void 0 : node.subModels) == null ? void 0 : _a[key]) || []).filter((item) => item && typeof item === "object");
294
+ }
295
+ function isGridNode(node) {
296
+ return typeof (node == null ? void 0 : node.use) === "string" && node.use.endsWith("GridModel");
297
+ }
298
+ function resolveReplaceComposeGridNode(targetNode) {
299
+ if (!targetNode || typeof targetNode !== "object") {
300
+ return void 0;
301
+ }
302
+ if (isGridNode(targetNode)) {
303
+ return targetNode;
304
+ }
305
+ const directGrid = getSingleSubModel(targetNode, "grid");
306
+ if (directGrid) {
307
+ return directGrid;
308
+ }
309
+ const firstTab = getSubModelList(targetNode, "tabs")[0];
310
+ const firstTabGrid = getSingleSubModel(firstTab, "grid");
311
+ if (firstTabGrid) {
312
+ return firstTabGrid;
313
+ }
314
+ const popupPage = getSingleSubModel(targetNode, "page");
315
+ const firstPopupTab = getSubModelList(popupPage, "tabs")[0];
316
+ return getSingleSubModel(firstPopupTab, "grid");
317
+ }
318
+ async function collectReplaceScopeExistingKeys(step, context, target, deps, options = {}) {
319
+ if (!isReplaceComposeStep(step)) {
320
+ return /* @__PURE__ */ new Set();
321
+ }
322
+ let targetNode = getContextNodeByUid(context, getResolvedSelectorUid(target)) || (!target || "summary" in target ? void 0 : target.node);
323
+ if (!targetNode && target && !("summary" in target) && target.resolved && deps.loadResolvedSurfaceTree) {
324
+ targetNode = await deps.loadResolvedSurfaceTree(target.resolved, options.transaction);
325
+ }
326
+ if (!targetNode) {
327
+ return /* @__PURE__ */ new Set();
328
+ }
329
+ const gridNode = resolveReplaceComposeGridNode(targetNode);
330
+ if (!gridNode) {
331
+ return /* @__PURE__ */ new Set();
332
+ }
333
+ const replacedUids = /* @__PURE__ */ new Set();
334
+ for (const item of getSubModelList(gridNode, "items")) {
335
+ collectNodeAndDescendantUids(item, replacedUids);
336
+ }
337
+ const keys = /* @__PURE__ */ new Set();
338
+ context.keyMap.forEach((info, key) => {
339
+ if (replacedUids.has(info.uid)) {
340
+ keys.add(key);
341
+ }
342
+ });
343
+ return keys;
344
+ }
345
+ function buildExistingKeysForConflict(context, priorCreatedKeys, allowedExistingKeys) {
346
+ const existing = /* @__PURE__ */ new Set();
347
+ context.keyMap.forEach((_info, key) => {
348
+ if (!allowedExistingKeys.has(key)) {
349
+ existing.add(key);
350
+ }
351
+ });
352
+ priorCreatedKeys.forEach((key) => existing.add(key));
353
+ return existing;
354
+ }
220
355
  async function compilePlanStep(actionName, step, index, context, deps, priorStepIds, priorCreatedKeys, options = {}) {
221
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
356
+ var _a, _b, _c, _d, _e, _f, _g;
222
357
  const runtimeValues = step.action === "compose" ? (0, import_created_keys.normalizeComposeInlineKeysForPlan)(step.values || {}, `plan.steps[${index}].values`) : import_lodash.default.cloneDeep(step.values || {});
223
- const payload = (0, import_step_link.replaceFlowSurfacePlanStepLinks)(
224
- actionName,
225
- runtimeValues,
226
- `plan.steps[${index}].values`,
227
- priorStepIds,
228
- /* @__PURE__ */ new Set([...context.keyMap.keys(), ...priorCreatedKeys])
229
- );
230
358
  const targetSelectorKey = (0, import_created_keys.isFlowSurfacePureKeyObject)((_a = step.selectors) == null ? void 0 : _a.target) ? String(step.selectors.target.key || "").trim() : void 0;
231
359
  const createdKeys = (0, import_created_keys.collectFlowSurfaceCreatedKeys)(step.action, step.values || {}, {
232
360
  targetSelectorKey
233
361
  });
234
- (0, import_created_keys.assertNoDuplicateFlowSurfaceCreatedKeys)(createdKeys, `flowSurfaces ${actionName} plan.steps[${index}]`, {
235
- existingKeys: [...context.keyMap.keys(), ...priorCreatedKeys],
236
- reservedNames: [...priorStepIds, ...step.id ? [step.id] : []]
237
- });
238
- const compiled = {
239
- index,
240
- ...step.id ? { id: step.id } : {},
241
- action: step.action,
242
- payload,
243
- resolvedSelectors: {},
244
- usedKeys: [],
245
- usedStepLinks: [],
246
- createdKeys
247
- };
248
- const addUsedKey = (selector) => {
249
- if ("summary" in selector) {
250
- if (isFlowSurfaceResolvedStepLink(selector)) {
251
- compiled.usedStepLinks.push(selector);
252
- }
253
- return selector.summary;
254
- }
255
- if (selector.source === "request" || selector.source === "declared") {
256
- compiled.usedKeys.push(selector);
257
- }
258
- return {
259
- uid: selector.uid,
260
- kind: selector.kind,
261
- ...selector.key ? { key: selector.key } : {},
262
- source: selector.source
263
- };
264
- };
265
362
  const spec = (0, import_action_specs.getFlowSurfacePlanActionSpec)(step.action);
266
363
  if (!spec) {
267
364
  (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} plan.steps[${index}].action '${step.action}' is not supported`);
@@ -283,14 +380,14 @@ async function compilePlanStep(actionName, step, index, context, deps, priorStep
283
380
  `flowSurfaces ${actionName} plan.steps[${index}] action '${step.action}' does not support selectors.source`
284
381
  );
285
382
  }
286
- if (spec.selectorMode === "none") {
287
- compiled.payload = payload;
288
- } else if (spec.selectorMode === "target") {
383
+ let resolvedTarget;
384
+ let resolvedSource;
385
+ if (selectorRequirements.requiresTarget) {
289
386
  const targetSelector = (_f = step.selectors) == null ? void 0 : _f.target;
290
387
  if (!targetSelector) {
291
388
  (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} plan.steps[${index}] requires selectors.target`);
292
389
  }
293
- const target = await resolvePlanSelectorInContext(
390
+ resolvedTarget = await resolvePlanSelectorInContext(
294
391
  actionName,
295
392
  targetSelector,
296
393
  context,
@@ -300,59 +397,85 @@ async function compilePlanStep(actionName, step, index, context, deps, priorStep
300
397
  priorCreatedKeys,
301
398
  options
302
399
  );
303
- compiled.payload = {
304
- ...payload,
305
- target: {
306
- uid: buildSelectorRuntimeValue(target)
307
- }
308
- };
309
- compiled.resolvedSelectors.target = addUsedKey(target);
310
- } else if (spec.selectorMode === "rootUidTarget") {
311
- const targetSelector = (_g = step.selectors) == null ? void 0 : _g.target;
312
- if (!targetSelector) {
313
- (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} plan.steps[${index}] requires selectors.target`);
400
+ }
401
+ if (selectorRequirements.requiresSource) {
402
+ const sourceSelector = (_g = step.selectors) == null ? void 0 : _g.source;
403
+ if (!sourceSelector) {
404
+ (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} plan.steps[${index}] requires selectors.source`);
314
405
  }
315
- const target = await resolvePlanSelectorInContext(
406
+ resolvedSource = await resolvePlanSelectorInContext(
316
407
  actionName,
317
- targetSelector,
408
+ sourceSelector,
318
409
  context,
319
410
  deps,
320
- `plan.steps[${index}].selectors.target`,
411
+ `plan.steps[${index}].selectors.source`,
321
412
  priorStepIds,
322
413
  priorCreatedKeys,
323
414
  options
324
415
  );
416
+ }
417
+ assertReplaceComposeTargetSupportsScopeResolution(actionName, index, step, resolvedTarget);
418
+ const allowedExistingKeys = await collectReplaceScopeExistingKeys(step, context, resolvedTarget, deps, options);
419
+ (0, import_created_keys.assertNoDuplicateFlowSurfaceCreatedKeys)(createdKeys, `flowSurfaces ${actionName} plan.steps[${index}]`, {
420
+ existingKeys: buildExistingKeysForConflict(context, priorCreatedKeys, allowedExistingKeys),
421
+ reservedNames: [...priorStepIds, ...step.id ? [step.id] : []]
422
+ });
423
+ const payload = (0, import_step_link.replaceFlowSurfacePlanStepLinks)(
424
+ actionName,
425
+ runtimeValues,
426
+ `plan.steps[${index}].values`,
427
+ priorStepIds,
428
+ /* @__PURE__ */ new Set([...context.keyMap.keys(), ...priorCreatedKeys]),
429
+ allowedExistingKeys
430
+ );
431
+ const compiled = {
432
+ index,
433
+ ...step.id ? { id: step.id } : {},
434
+ action: step.action,
435
+ payload,
436
+ resolvedSelectors: {},
437
+ usedKeys: [],
438
+ usedStepLinks: [],
439
+ createdKeys
440
+ };
441
+ const addUsedKey = (selector) => {
442
+ if ("summary" in selector) {
443
+ if (isFlowSurfaceResolvedStepLink(selector)) {
444
+ compiled.usedStepLinks.push(selector);
445
+ }
446
+ return selector.summary;
447
+ }
448
+ if (selector.source === "request" || selector.source === "declared") {
449
+ compiled.usedKeys.push(selector);
450
+ }
451
+ return {
452
+ uid: selector.uid,
453
+ kind: selector.kind,
454
+ ...selector.key ? { key: selector.key } : {},
455
+ source: selector.source
456
+ };
457
+ };
458
+ if (spec.selectorMode === "none") {
459
+ compiled.payload = payload;
460
+ } else if (spec.selectorMode === "target") {
461
+ const target = resolvedTarget;
462
+ compiled.payload = {
463
+ ...payload,
464
+ target: {
465
+ uid: buildSelectorRuntimeValue(target)
466
+ }
467
+ };
468
+ compiled.resolvedSelectors.target = addUsedKey(target);
469
+ } else if (spec.selectorMode === "rootUidTarget") {
470
+ const target = resolvedTarget;
325
471
  compiled.payload = {
326
472
  ...payload,
327
473
  uid: buildSelectorRuntimeValue(target)
328
474
  };
329
475
  compiled.resolvedSelectors.target = addUsedKey(target);
330
476
  } else if (spec.selectorMode === "sourceTarget") {
331
- const sourceSelector = (_h = step.selectors) == null ? void 0 : _h.source;
332
- const targetSelector = (_i = step.selectors) == null ? void 0 : _i.target;
333
- if (!sourceSelector || !targetSelector) {
334
- (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} plan.steps[${index}] requires selectors.source and selectors.target`);
335
- }
336
- const source = await resolvePlanSelectorInContext(
337
- actionName,
338
- sourceSelector,
339
- context,
340
- deps,
341
- `plan.steps[${index}].selectors.source`,
342
- priorStepIds,
343
- priorCreatedKeys,
344
- options
345
- );
346
- const target = await resolvePlanSelectorInContext(
347
- actionName,
348
- targetSelector,
349
- context,
350
- deps,
351
- `plan.steps[${index}].selectors.target`,
352
- priorStepIds,
353
- priorCreatedKeys,
354
- options
355
- );
477
+ const source = resolvedSource;
478
+ const target = resolvedTarget;
356
479
  compiled.payload = {
357
480
  ...payload,
358
481
  sourceUid: buildSelectorRuntimeValue(source),
@@ -26,7 +26,7 @@ export declare function buildSurfaceKeysObject(keyMap: Map<string, FlowSurfaceRe
26
26
  [k: string]: {
27
27
  uid: string;
28
28
  kind: string;
29
- source: "declared" | "request" | "system";
29
+ source: "system" | "declared" | "request";
30
30
  locator: FlowSurfaceReadLocator;
31
31
  };
32
32
  };
@@ -152,6 +152,7 @@ async function compilePlanStep(actionName, step, index, context, deps, priorStep
152
152
  {
153
153
  normalizeGetTarget: deps.normalizeGetTarget,
154
154
  resolveLocator: deps.resolveLocator,
155
+ loadResolvedSurfaceTree: deps.loadResolvedSurfaceTree,
155
156
  buildPlanKeyKind: import_key_kind.buildPlanKeyKind
156
157
  },
157
158
  priorStepIds,