@nocobase/plugin-flow-engine 2.2.0-beta.2 → 2.2.0-beta.3

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 (45) hide show
  1. package/dist/externalVersion.js +9 -9
  2. package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
  3. package/dist/node_modules/acorn/package.json +1 -1
  4. package/dist/node_modules/acorn-jsx/package.json +1 -1
  5. package/dist/node_modules/acorn-walk/package.json +1 -1
  6. package/dist/node_modules/ses/package.json +1 -1
  7. package/dist/node_modules/zod/package.json +1 -1
  8. package/dist/server/flow-surfaces/approval/authoring-validation.d.ts +9 -0
  9. package/dist/server/flow-surfaces/approval/authoring-validation.js +1151 -0
  10. package/dist/server/flow-surfaces/approval/blueprint-service.js +2 -0
  11. package/dist/server/flow-surfaces/authoring-validation.js +372 -32
  12. package/dist/server/flow-surfaces/blueprint/export-document.d.ts +50 -0
  13. package/dist/server/flow-surfaces/blueprint/export-document.js +2503 -0
  14. package/dist/server/flow-surfaces/constants.d.ts +9 -2
  15. package/dist/server/flow-surfaces/constants.js +1 -0
  16. package/dist/server/flow-surfaces/default-action-popup.d.ts +2 -0
  17. package/dist/server/flow-surfaces/default-action-popup.js +27 -13
  18. package/dist/server/flow-surfaces/filter-group.d.ts +19 -2
  19. package/dist/server/flow-surfaces/filter-group.js +232 -3
  20. package/dist/server/flow-surfaces/planning/compiler.d.ts +1 -0
  21. package/dist/server/flow-surfaces/planning/compiler.js +205 -82
  22. package/dist/server/flow-surfaces/planning/runtime.js +1 -0
  23. package/dist/server/flow-surfaces/planning/step-link.d.ts +1 -1
  24. package/dist/server/flow-surfaces/planning/step-link.js +22 -3
  25. package/dist/server/flow-surfaces/public-data-surface-default-filter.js +0 -9
  26. package/dist/server/flow-surfaces/reaction/field-value.d.ts +9 -0
  27. package/dist/server/flow-surfaces/reaction/field-value.js +51 -2
  28. package/dist/server/flow-surfaces/reaction/linkage.d.ts +6 -1
  29. package/dist/server/flow-surfaces/reaction/linkage.js +18 -3
  30. package/dist/server/flow-surfaces/reaction/meta.js +19 -1
  31. package/dist/server/flow-surfaces/reaction/types.d.ts +19 -0
  32. package/dist/server/flow-surfaces/relation-backing-foreign-key.d.ts +10 -0
  33. package/dist/server/flow-surfaces/relation-backing-foreign-key.js +79 -0
  34. package/dist/server/flow-surfaces/runjs-authoring/ast/source.d.ts +1 -0
  35. package/dist/server/flow-surfaces/runjs-authoring/ast/source.js +20 -0
  36. package/dist/server/flow-surfaces/runjs-authoring/scan/filter.js +12 -2
  37. package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +9 -1
  38. package/dist/server/flow-surfaces/service.d.ts +19 -0
  39. package/dist/server/flow-surfaces/service.js +189 -20
  40. package/dist/swagger/flow-surfaces.d.ts +180 -0
  41. package/dist/swagger/flow-surfaces.examples.d.ts +8 -0
  42. package/dist/swagger/flow-surfaces.examples.js +8 -0
  43. package/dist/swagger/flow-surfaces.js +160 -4
  44. package/dist/swagger/index.d.ts +180 -0
  45. package/package.json +2 -2
@@ -45,6 +45,13 @@ export declare const FLOW_SURFACE_ACTION_DEFINITIONS: {
45
45
  readonly mutate: false;
46
46
  readonly valueSource: "default";
47
47
  };
48
+ readonly exportBlueprint: {
49
+ readonly method: "post";
50
+ readonly read: true;
51
+ readonly transaction: false;
52
+ readonly mutate: false;
53
+ readonly valueSource: "default";
54
+ };
48
55
  readonly getReactionMeta: {
49
56
  readonly method: "post";
50
57
  readonly read: true;
@@ -373,7 +380,7 @@ type SelectFlowSurfaceActionNames<TFlag extends keyof FlowSurfaceActionDefinitio
373
380
  [K in FlowSurfacesActionName]: (typeof FLOW_SURFACE_ACTION_DEFINITIONS)[K][TFlag] extends true ? K : never;
374
381
  }[FlowSurfacesActionName];
375
382
  type FlowSurfaceMutateActionName = SelectFlowSurfaceActionNames<'mutate'>;
376
- export declare const FLOW_SURFACES_ACTION_NAMES: ("setFieldValueRules" | "setBlockLinkageRules" | "setFieldLinkageRules" | "setActionLinkageRules" | "context" | "get" | "configure" | "createPage" | "addTab" | "addPopupTab" | "addBlock" | "addField" | "addAction" | "addRecordAction" | "compose" | "createMenu" | "catalog" | "describeSurface" | "getReactionMeta" | "applyBlueprint" | "applyApprovalBlueprint" | "listTemplates" | "getTemplate" | "saveTemplate" | "updateTemplate" | "destroyTemplate" | "convertTemplateToCopy" | "updateMenu" | "destroyPage" | "updateTab" | "moveTab" | "removeTab" | "updatePopupTab" | "movePopupTab" | "removePopupTab" | "addBlocks" | "addFields" | "addActions" | "addRecordActions" | "updateSettings" | "getEventFlowMeta" | "addEventFlow" | "setEventFlow" | "removeEventFlow" | "setEventFlows" | "setLayout" | "moveNode" | "removeNode" | "mutate" | "apply")[];
383
+ export declare const FLOW_SURFACES_ACTION_NAMES: ("setFieldValueRules" | "setBlockLinkageRules" | "setFieldLinkageRules" | "setActionLinkageRules" | "context" | "get" | "configure" | "createPage" | "addTab" | "addPopupTab" | "addBlock" | "addField" | "addAction" | "addRecordAction" | "compose" | "createMenu" | "catalog" | "describeSurface" | "exportBlueprint" | "getReactionMeta" | "applyBlueprint" | "applyApprovalBlueprint" | "listTemplates" | "getTemplate" | "saveTemplate" | "updateTemplate" | "destroyTemplate" | "convertTemplateToCopy" | "updateMenu" | "destroyPage" | "updateTab" | "moveTab" | "removeTab" | "updatePopupTab" | "movePopupTab" | "removePopupTab" | "addBlocks" | "addFields" | "addActions" | "addRecordActions" | "updateSettings" | "getEventFlowMeta" | "addEventFlow" | "setEventFlow" | "removeEventFlow" | "setEventFlows" | "setLayout" | "moveNode" | "removeNode" | "mutate" | "apply")[];
377
384
  export declare const FLOW_SURFACES_READ_ACTION_NAMES: SelectFlowSurfaceActionNames<"read">[];
378
385
  export declare const FLOW_SURFACE_MUTATE_OP_TYPES: FlowSurfaceMutateActionName[];
379
- export declare const FLOW_SURFACES_ACTION_METHODS: Record<"setFieldValueRules" | "setBlockLinkageRules" | "setFieldLinkageRules" | "setActionLinkageRules" | "context" | "get" | "configure" | "createPage" | "addTab" | "addPopupTab" | "addBlock" | "addField" | "addAction" | "addRecordAction" | "compose" | "createMenu" | "catalog" | "describeSurface" | "getReactionMeta" | "applyBlueprint" | "applyApprovalBlueprint" | "listTemplates" | "getTemplate" | "saveTemplate" | "updateTemplate" | "destroyTemplate" | "convertTemplateToCopy" | "updateMenu" | "destroyPage" | "updateTab" | "moveTab" | "removeTab" | "updatePopupTab" | "movePopupTab" | "removePopupTab" | "addBlocks" | "addFields" | "addActions" | "addRecordActions" | "updateSettings" | "getEventFlowMeta" | "addEventFlow" | "setEventFlow" | "removeEventFlow" | "setEventFlows" | "setLayout" | "moveNode" | "removeNode" | "mutate" | "apply", FlowSurfaceActionMethod>;
386
+ export declare const FLOW_SURFACES_ACTION_METHODS: Record<"setFieldValueRules" | "setBlockLinkageRules" | "setFieldLinkageRules" | "setActionLinkageRules" | "context" | "get" | "configure" | "createPage" | "addTab" | "addPopupTab" | "addBlock" | "addField" | "addAction" | "addRecordAction" | "compose" | "createMenu" | "catalog" | "describeSurface" | "exportBlueprint" | "getReactionMeta" | "applyBlueprint" | "applyApprovalBlueprint" | "listTemplates" | "getTemplate" | "saveTemplate" | "updateTemplate" | "destroyTemplate" | "convertTemplateToCopy" | "updateMenu" | "destroyPage" | "updateTab" | "moveTab" | "removeTab" | "updatePopupTab" | "movePopupTab" | "removePopupTab" | "addBlocks" | "addFields" | "addActions" | "addRecordActions" | "updateSettings" | "getEventFlowMeta" | "addEventFlow" | "setEventFlow" | "removeEventFlow" | "setEventFlows" | "setLayout" | "moveNode" | "removeNode" | "mutate" | "apply", FlowSurfaceActionMethod>;
@@ -40,6 +40,7 @@ const FLOW_SURFACE_ACTION_DEFINITIONS = {
40
40
  context: { method: "post", read: true, transaction: false, mutate: false, valueSource: "default" },
41
41
  get: { method: "get", read: true, transaction: false, mutate: false, valueSource: "read" },
42
42
  describeSurface: { method: "post", read: true, transaction: false, mutate: false, valueSource: "default" },
43
+ exportBlueprint: { method: "post", read: true, transaction: false, mutate: false, valueSource: "default" },
43
44
  getReactionMeta: { method: "post", read: true, transaction: false, mutate: false, valueSource: "default" },
44
45
  setFieldValueRules: { method: "post", read: false, transaction: true, mutate: false, valueSource: "default" },
45
46
  setBlockLinkageRules: { method: "post", read: false, transaction: true, mutate: false, valueSource: "default" },
@@ -47,6 +47,7 @@ export type FlowSurfaceDefaultActionPopupFieldGroupCandidate = {
47
47
  type FlowSurfaceDefaultActionPopupFieldFilterOptions = {
48
48
  excludeAuditTimestampFields?: boolean;
49
49
  excludeAssociationFields?: boolean;
50
+ excludeRelationBackingForeignKeyFields?: boolean;
50
51
  };
51
52
  type FlowSurfaceDefaultActionPopupFieldsInput = any[] | {
52
53
  fieldPaths?: any[];
@@ -60,6 +61,7 @@ export declare function getFlowSurfaceDefaultActionPopupConfigByUse(use?: string
60
61
  export declare function resolveFlowSurfaceDefaultActionPopupTabTitle(use?: string, currentTitle?: string | null): string;
61
62
  export declare function isFlowSurfaceDefaultActionPopupBusinessField(field: any): boolean;
62
63
  export declare function pickFlowSurfaceDefaultActionPopupFieldPaths(candidates: FlowSurfaceDefaultActionPopupFieldCandidate[], options?: FlowSurfaceDefaultActionPopupFieldFilterOptions): string[];
64
+ export declare function collectFlowSurfaceDefaultActionPopupFieldGroupFieldPaths(fieldGroups: FlowSurfaceDefaultActionPopupFieldGroupCandidate[] | undefined): Set<string>;
63
65
  export declare function pickFlowSurfaceDefaultActionPopupFieldGroups(candidates: FlowSurfaceDefaultActionPopupFieldCandidate[], fieldGroups: FlowSurfaceDefaultActionPopupFieldGroupCandidate[] | undefined, options?: FlowSurfaceDefaultActionPopupFieldFilterOptions): FlowSurfaceDefaultActionPopupFieldGroupCandidate[];
64
66
  export declare function buildFlowSurfaceDefaultActionPopupBlocks(use: string | undefined, fieldsInput: FlowSurfaceDefaultActionPopupFieldsInput): _.Dictionary<string | any[] | Record<string, any> | FlowSurfaceDefaultActionPopupFieldGroupCandidate[] | FlowSurfaceDefaultActionPopupSubmitAction[] | {
65
67
  binding: "currentCollection" | "currentRecord";
@@ -39,6 +39,7 @@ __export(default_action_popup_exports, {
39
39
  FLOW_SURFACE_DEFAULT_ACTION_POPUP_TYPES: () => FLOW_SURFACE_DEFAULT_ACTION_POPUP_TYPES,
40
40
  FLOW_SURFACE_DEFAULT_ACTION_POPUP_USES: () => FLOW_SURFACE_DEFAULT_ACTION_POPUP_USES,
41
41
  buildFlowSurfaceDefaultActionPopupBlocks: () => buildFlowSurfaceDefaultActionPopupBlocks,
42
+ collectFlowSurfaceDefaultActionPopupFieldGroupFieldPaths: () => collectFlowSurfaceDefaultActionPopupFieldGroupFieldPaths,
42
43
  getFlowSurfaceDefaultActionPopupConfigByUse: () => getFlowSurfaceDefaultActionPopupConfigByUse,
43
44
  hasFlowSurfaceInlinePopupBlocks: () => hasFlowSurfaceInlinePopupBlocks,
44
45
  hasFlowSurfaceInlinePopupTemplate: () => hasFlowSurfaceInlinePopupTemplate,
@@ -52,6 +53,7 @@ __export(default_action_popup_exports, {
52
53
  module.exports = __toCommonJS(default_action_popup_exports);
53
54
  var import_lodash = __toESM(require("lodash"));
54
55
  var import_association_interfaces = require("./association-interfaces");
56
+ var import_relation_backing_foreign_key = require("./relation-backing-foreign-key");
55
57
  var import_service_helpers = require("./service-helpers");
56
58
  const DEFAULT_ACTION_POPUP_SYSTEM_FIELD_NAMES = /* @__PURE__ */ new Set(["id", "createdBy", "createdById", "updatedBy", "updatedById"]);
57
59
  const DEFAULT_ACTION_POPUP_SYSTEM_FIELD_INTERFACES = /* @__PURE__ */ new Set([
@@ -214,13 +216,10 @@ function isFlowSurfaceDefaultActionPopupAssociationField(field) {
214
216
  const fieldType = String((0, import_service_helpers.getFieldType)(field) || "").trim();
215
217
  return fieldType === "belongsTo" || fieldType === "hasOne" || fieldType === "hasMany" || fieldType === "belongsToMany";
216
218
  }
217
- function collectFlowSurfaceDefaultActionPopupAssociationForeignKeys(candidates) {
218
- return new Set(
219
- candidates.map((candidate) => candidate == null ? void 0 : candidate.field).filter((field) => (0, import_service_helpers.getFieldType)(field) === "belongsTo").map((field) => {
220
- var _a;
221
- return String((field == null ? void 0 : field.foreignKey) || ((_a = field == null ? void 0 : field.options) == null ? void 0 : _a.foreignKey) || "").trim();
222
- }).filter(Boolean)
223
- );
219
+ function collectFlowSurfaceDefaultActionPopupRelationBackingForeignKeys(candidates) {
220
+ return (0, import_relation_backing_foreign_key.collectRelationBackingForeignKeyNames)({
221
+ getFields: () => candidates.map((candidate) => candidate == null ? void 0 : candidate.field).filter(Boolean)
222
+ });
224
223
  }
225
224
  function isFlowSurfaceDefaultActionPopupAssociationForeignKeyField(field, associationForeignKeys) {
226
225
  const fieldName = String((0, import_service_helpers.getFieldName)(field) || "").trim();
@@ -229,13 +228,26 @@ function isFlowSurfaceDefaultActionPopupAssociationForeignKeyField(field, associ
229
228
  function pickFlowSurfaceDefaultActionPopupFieldPaths(candidates, options = {}) {
230
229
  return filterFlowSurfaceDefaultActionPopupFieldCandidates(candidates, options).map((candidate) => String((candidate == null ? void 0 : candidate.fieldPath) || "").trim()).filter(Boolean);
231
230
  }
231
+ function collectFlowSurfaceDefaultActionPopupFieldGroupFieldPaths(fieldGroups) {
232
+ const fieldPaths = /* @__PURE__ */ new Set();
233
+ import_lodash.default.castArray(fieldGroups || []).forEach((group) => {
234
+ import_lodash.default.castArray((group == null ? void 0 : group.fields) || []).forEach((field) => {
235
+ const fieldPath = getFlowSurfaceDefaultActionPopupFieldGroupFieldPath(field);
236
+ if (fieldPath) {
237
+ fieldPaths.add(fieldPath);
238
+ }
239
+ });
240
+ });
241
+ return fieldPaths;
242
+ }
232
243
  function filterFlowSurfaceDefaultActionPopupFieldCandidates(candidates, options = {}) {
233
- const associationForeignKeys = collectFlowSurfaceDefaultActionPopupAssociationForeignKeys(candidates);
244
+ const associationForeignKeys = collectFlowSurfaceDefaultActionPopupRelationBackingForeignKeys(candidates);
245
+ const excludeRelationBackingForeignKeyFields = options.excludeRelationBackingForeignKeyFields !== false;
234
246
  const preferredCandidates = candidates.filter(
235
- (candidate) => !isFlowSurfaceDefaultActionPopupSystemField(candidate.field) && (!options.excludeAuditTimestampFields || !isFlowSurfaceDefaultActionPopupAuditTimestampField(candidate.field)) && (!options.excludeAssociationFields || !isFlowSurfaceDefaultActionPopupAssociationField(candidate.field)) && !isFlowSurfaceDefaultActionPopupMultiValueAssociationField(candidate.field) && !isFlowSurfaceDefaultActionPopupAssociationForeignKeyField(candidate.field, associationForeignKeys)
247
+ (candidate) => !isFlowSurfaceDefaultActionPopupSystemField(candidate.field) && (!options.excludeAuditTimestampFields || !isFlowSurfaceDefaultActionPopupAuditTimestampField(candidate.field)) && (!options.excludeAssociationFields || !isFlowSurfaceDefaultActionPopupAssociationField(candidate.field)) && !isFlowSurfaceDefaultActionPopupMultiValueAssociationField(candidate.field) && (!excludeRelationBackingForeignKeyFields || !isFlowSurfaceDefaultActionPopupAssociationForeignKeyField(candidate.field, associationForeignKeys))
236
248
  );
237
249
  const fallbackCandidates = candidates.filter(
238
- (candidate) => !isFlowSurfaceDefaultActionPopupTechnicalIdField(candidate.field) && (!options.excludeAuditTimestampFields || !isFlowSurfaceDefaultActionPopupAuditTimestampField(candidate.field)) && (!options.excludeAssociationFields || !isFlowSurfaceDefaultActionPopupAssociationField(candidate.field)) && !isFlowSurfaceDefaultActionPopupMultiValueAssociationField(candidate.field) && !isFlowSurfaceDefaultActionPopupAssociationForeignKeyField(candidate.field, associationForeignKeys)
250
+ (candidate) => !isFlowSurfaceDefaultActionPopupTechnicalIdField(candidate.field) && (!options.excludeAuditTimestampFields || !isFlowSurfaceDefaultActionPopupAuditTimestampField(candidate.field)) && (!options.excludeAssociationFields || !isFlowSurfaceDefaultActionPopupAssociationField(candidate.field)) && !isFlowSurfaceDefaultActionPopupMultiValueAssociationField(candidate.field) && (!excludeRelationBackingForeignKeyFields || !isFlowSurfaceDefaultActionPopupAssociationForeignKeyField(candidate.field, associationForeignKeys))
239
251
  );
240
252
  const baseCandidates = preferredCandidates.length ? preferredCandidates : fallbackCandidates;
241
253
  return baseCandidates.filter((candidate) => String((candidate == null ? void 0 : candidate.fieldPath) || "").trim());
@@ -266,9 +278,10 @@ function normalizeFlowSurfaceDefaultActionPopupFieldGroupField(field, fieldPath)
266
278
  }
267
279
  function pickFlowSurfaceDefaultActionPopupFieldGroups(candidates, fieldGroups, options = {}) {
268
280
  const allowedFieldPaths = new Set(
269
- filterFlowSurfaceDefaultActionPopupFieldCandidates(candidates, options).map(
270
- (candidate) => String((candidate == null ? void 0 : candidate.fieldPath) || "").trim()
271
- )
281
+ filterFlowSurfaceDefaultActionPopupFieldCandidates(candidates, {
282
+ ...options,
283
+ excludeRelationBackingForeignKeyFields: false
284
+ }).map((candidate) => String((candidate == null ? void 0 : candidate.fieldPath) || "").trim())
272
285
  );
273
286
  const usedFieldPaths = /* @__PURE__ */ new Set();
274
287
  return import_lodash.default.castArray(fieldGroups || []).flatMap((group) => {
@@ -351,6 +364,7 @@ function hasFlowSurfaceInlinePopupBlocks(popup) {
351
364
  FLOW_SURFACE_DEFAULT_ACTION_POPUP_TYPES,
352
365
  FLOW_SURFACE_DEFAULT_ACTION_POPUP_USES,
353
366
  buildFlowSurfaceDefaultActionPopupBlocks,
367
+ collectFlowSurfaceDefaultActionPopupFieldGroupFieldPaths,
354
368
  getFlowSurfaceDefaultActionPopupConfigByUse,
355
369
  hasFlowSurfaceInlinePopupBlocks,
356
370
  hasFlowSurfaceInlinePopupTemplate,
@@ -11,13 +11,30 @@ export declare const FLOW_SURFACE_EMPTY_FILTER_GROUP: {
11
11
  items: any[];
12
12
  };
13
13
  export declare const FLOW_SURFACE_FILTER_GROUP_EXAMPLE: string;
14
+ export declare const FLOW_SURFACE_DATE_FILTER_OPERATORS: Set<string>;
14
15
  export declare function assertFlowSurfaceFilterOperator(operator: unknown, path: string): void;
15
- export declare function normalizeFlowSurfaceFilterDateValue(operator: unknown, value: unknown, path: string): unknown;
16
- export declare function normalizeFlowSurfaceStrictFilterDateValue(operator: unknown, value: unknown, path: string): unknown;
16
+ export declare function normalizeFlowSurfaceFilterDateValue(operator: unknown, value: unknown, path: string, options?: {
17
+ allowContextPathValue?: boolean;
18
+ }): unknown;
19
+ export declare function normalizeFlowSurfaceStrictFilterDateValue(operator: unknown, value: unknown, path: string, options?: {
20
+ allowContextPathValue?: boolean;
21
+ }): unknown;
22
+ export declare function isFlowSurfaceDateLikeFieldMeta(value: {
23
+ type?: unknown;
24
+ interface?: unknown;
25
+ } | undefined | null): boolean;
26
+ export declare function normalizeFlowSurfaceDateConditionValue(operator: unknown, value: unknown, path: string, options?: {
27
+ fieldPath?: string;
28
+ fieldType?: unknown;
29
+ fieldInterface?: unknown;
30
+ allowContextPathValue?: boolean;
31
+ }): unknown;
17
32
  export declare function normalizeFlowSurfaceFilterGroupValue(value: any, errorPrefix: string, options?: {
18
33
  strictDateValues?: boolean;
34
+ allowContextPathValue?: boolean;
19
35
  }): any;
20
36
  export declare function normalizeFlowSurfaceCompatibleFilterGroupValue(value: unknown, errorPrefix: string, options?: {
21
37
  strictDateValues?: boolean;
38
+ allowContextPathValue?: boolean;
22
39
  }): any;
23
40
  export declare function assertFlowSurfaceFilterGroupShape(filter: any): void;
@@ -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;