@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,7 @@ var import_lodash = __toESM(require("lodash"));
45
45
  var import_service_utils = require("../service-utils");
46
46
  var import_errors = require("../errors");
47
47
  var import_blueprint = require("./blueprint");
48
+ var import_authoring_validation = require("./authoring-validation");
48
49
  var import_builder = require("./builder");
49
50
  class FlowSurfaceApprovalBlueprintService {
50
51
  constructor(deps) {
@@ -541,6 +542,7 @@ class FlowSurfaceApprovalBlueprintService {
541
542
  }
542
543
  }
543
544
  async applyApprovalBlueprint(values, options = {}) {
545
+ (0, import_authoring_validation.assertFlowSurfaceApprovalBlueprintAuthoringPayload)(values);
544
546
  const document = (0, import_blueprint.prepareFlowSurfaceApplyApprovalBlueprintDocument)(values);
545
547
  const bindingContext = await this.resolveApprovalBlueprintBindingContext(document, options.transaction);
546
548
  const surfaceRoot = await this.ensureApprovalBlueprintSurfaceRoot(bindingContext, options.transaction);
@@ -51,6 +51,7 @@ var import_association_title_field = require("./association-title-field");
51
51
  var import_chart_config = require("./chart-config");
52
52
  var import_public_data_surface_default_filter = require("./public-data-surface-default-filter");
53
53
  var import_default_action_popup = require("./default-action-popup");
54
+ var import_relation_backing_foreign_key = require("./relation-backing-foreign-key");
54
55
  var import_default_block_actions = require("./default-block-actions");
55
56
  var import_hidden_popup_contract = require("./hidden-popup-contract");
56
57
  var import_node_use_sets = require("./node-use-sets");
@@ -60,6 +61,7 @@ var import_association_interfaces = require("./association-interfaces");
60
61
  var import_defaults = require("./blueprint/defaults");
61
62
  var import_runjs_authoring = require("./runjs-authoring");
62
63
  var import_configure_options = require("./configure-options");
64
+ var import_context = require("./context");
63
65
  var import_filter_group = require("./filter-group");
64
66
  const MAIN_BLOCK_UNSUPPORTED_SECTIONS = {
65
67
  calendar: ["fields", "fieldGroups", "recordActions", "fieldsLayout"],
@@ -472,7 +474,10 @@ async function collectFlowSurfaceAuthoringErrors(actionName, values, context = {
472
474
  blocks.forEach(({ block }) => collectLocalKeys(block, localKeys));
473
475
  }
474
476
  blocks.forEach(({ block, path }) => collectBlockErrors(block, path, errors, localKeys, validationContext));
475
- collectReactionErrors(values == null ? void 0 : values.reaction, "$.reaction", localKeys, errors);
477
+ collectReactionErrors(values == null ? void 0 : values.reaction, "$.reaction", localKeys, errors, {
478
+ values,
479
+ context: validationContext
480
+ });
476
481
  if (!validationContext.skipGeneratedPopupDefaultFieldGroups) {
477
482
  collectGeneratedPopupDefaultFieldGroupErrors(actionName, values, validationContext, errors);
478
483
  }
@@ -1177,47 +1182,69 @@ function collectBuilderChartAssetQueryErrors(query, path, context, errors) {
1177
1182
  errors,
1178
1183
  withChartRepairHint()
1179
1184
  );
1180
- collectChartQueryFilterOperatorErrors(query, `${path}.query`, errors);
1185
+ collectChartQueryFilterOperatorErrors(query, `${path}.query`, errors, context);
1181
1186
  collectBuilderChartAssetFieldErrors(query, path, context, errors);
1182
1187
  }
1183
- function collectChartQueryFilterOperatorErrors(query, path, errors) {
1188
+ const AUTHORABLE_REACTION_SCALAR_CONTEXT_PATHS = /* @__PURE__ */ new Set(["role", "locale", "token", "deviceType"]);
1189
+ const AUTHORABLE_REACTION_CONTEXT_ROOTS = /* @__PURE__ */ new Set([
1190
+ "user",
1191
+ "collection",
1192
+ "formValues",
1193
+ "record",
1194
+ "item",
1195
+ "popup",
1196
+ "urlSearchParams"
1197
+ ]);
1198
+ function collectChartQueryFilterOperatorErrors(query, path, errors, context) {
1184
1199
  if (!_.isPlainObject(query) || !hasOwn(query, "filter")) {
1185
1200
  return;
1186
1201
  }
1187
- collectChartFilterOperatorErrors(query.filter, `${path}.filter`, errors);
1202
+ collectChartFilterOperatorErrors(
1203
+ query.filter,
1204
+ `${path}.filter`,
1205
+ errors,
1206
+ createChartQueryDateConditionFieldResolver(query, context)
1207
+ );
1188
1208
  }
1189
- function collectChartFilterOperatorErrors(filter, path, errors) {
1209
+ function collectChartFilterOperatorErrors(filter, path, errors, resolveField) {
1190
1210
  if (_.isUndefined(filter) || _.isNull(filter) || !_.isPlainObject(filter)) {
1191
1211
  return;
1192
1212
  }
1193
1213
  if (Array.isArray(filter.items)) {
1194
- collectChartFilterGroupOperatorErrors(filter.items, `${path}.items`, errors);
1214
+ collectChartFilterGroupOperatorErrors(filter.items, `${path}.items`, errors, resolveField);
1195
1215
  return;
1196
1216
  }
1197
- collectBackendQueryFilterOperatorErrors(filter, path, errors);
1217
+ collectBackendQueryFilterOperatorErrors(filter, path, errors, resolveField);
1198
1218
  }
1199
- function collectChartFilterGroupOperatorErrors(items, path, errors) {
1219
+ function collectChartFilterGroupOperatorErrors(items, path, errors, resolveField) {
1200
1220
  items.forEach((item, index) => {
1201
1221
  const itemPath = `${path}[${index}]`;
1202
1222
  if (!_.isPlainObject(item)) {
1203
1223
  return;
1204
1224
  }
1205
1225
  if (Array.isArray(item.items)) {
1206
- collectChartFilterGroupOperatorErrors(item.items, `${itemPath}.items`, errors);
1226
+ collectChartFilterGroupOperatorErrors(item.items, `${itemPath}.items`, errors, resolveField);
1207
1227
  return;
1208
1228
  }
1209
1229
  if (hasOwn(item, "operator")) {
1210
1230
  collectChartFilterOperatorError(item.operator, `${itemPath}.operator`, errors);
1211
- collectChartFilterDateValueError(item.operator, item.value, `${itemPath}.value`, errors);
1231
+ const fieldPath = String(item.path || item.field || "").trim();
1232
+ collectChartFilterDateValueError(
1233
+ item.operator,
1234
+ item.value,
1235
+ `${itemPath}.value`,
1236
+ errors,
1237
+ fieldPath ? (resolveField == null ? void 0 : resolveField(fieldPath)) || { fieldPath } : void 0
1238
+ );
1212
1239
  }
1213
1240
  });
1214
1241
  }
1215
- function collectBackendQueryFilterOperatorErrors(filter, path, errors) {
1242
+ function collectBackendQueryFilterOperatorErrors(filter, path, errors, resolveField) {
1216
1243
  Object.entries(filter).forEach(([field, condition]) => {
1217
1244
  const fieldPath = `${path}.${field}`;
1218
1245
  if ((field === "$and" || field === "$or") && Array.isArray(condition)) {
1219
1246
  condition.forEach(
1220
- (operand, index) => collectChartFilterOperatorErrors(operand, `${fieldPath}[${index}]`, errors)
1247
+ (operand, index) => collectChartFilterOperatorErrors(operand, `${fieldPath}[${index}]`, errors, resolveField)
1221
1248
  );
1222
1249
  return;
1223
1250
  }
@@ -1226,11 +1253,17 @@ function collectBackendQueryFilterOperatorErrors(filter, path, errors) {
1226
1253
  }
1227
1254
  Object.keys(condition).forEach((operator) => {
1228
1255
  if (operator === "$and" || operator === "$or") {
1229
- collectChartFilterOperatorErrors({ [operator]: condition[operator] }, fieldPath, errors);
1256
+ collectChartFilterOperatorErrors({ [operator]: condition[operator] }, fieldPath, errors, resolveField);
1230
1257
  return;
1231
1258
  }
1232
1259
  collectChartFilterOperatorError(operator, `${fieldPath}.${operator}`, errors);
1233
- collectChartFilterDateValueError(operator, condition[operator], `${fieldPath}.${operator}`, errors);
1260
+ collectChartFilterDateValueError(
1261
+ operator,
1262
+ condition[operator],
1263
+ `${fieldPath}.${operator}`,
1264
+ errors,
1265
+ (resolveField == null ? void 0 : resolveField(field)) || { fieldPath: field }
1266
+ );
1234
1267
  });
1235
1268
  });
1236
1269
  }
@@ -1245,9 +1278,18 @@ function collectChartFilterOperatorError(operator, path, errors) {
1245
1278
  throw error;
1246
1279
  }
1247
1280
  }
1248
- function collectChartFilterDateValueError(operator, value, path, errors) {
1281
+ function collectChartFilterDateValueError(operator, value, path, errors, fieldContext) {
1282
+ const fieldMeta = getDateConditionFieldContextMeta(fieldContext);
1283
+ const normalizedOperator = typeof operator === "string" ? operator.trim() : "";
1284
+ if (!import_filter_group.FLOW_SURFACE_DATE_FILTER_OPERATORS.has(normalizedOperator) && !(0, import_filter_group.isFlowSurfaceDateLikeFieldMeta)(fieldMeta)) {
1285
+ return;
1286
+ }
1249
1287
  try {
1250
- (0, import_filter_group.normalizeFlowSurfaceStrictFilterDateValue)(operator, value, path);
1288
+ (0, import_filter_group.normalizeFlowSurfaceDateConditionValue)(operator, value, path, {
1289
+ fieldPath: fieldContext == null ? void 0 : fieldContext.fieldPath,
1290
+ fieldType: fieldMeta.type,
1291
+ fieldInterface: fieldMeta.interface
1292
+ });
1251
1293
  } catch (error) {
1252
1294
  if (error instanceof import_errors.FlowSurfaceBadRequestError) {
1253
1295
  pushChartBadRequestAuthoringError(errors, error, path);
@@ -1256,6 +1298,38 @@ function collectChartFilterDateValueError(operator, value, path, errors) {
1256
1298
  throw error;
1257
1299
  }
1258
1300
  }
1301
+ function createChartQueryDateConditionFieldResolver(query, context) {
1302
+ const resource = _.isPlainObject(query == null ? void 0 : query.resource) ? query.resource : null;
1303
+ const collectionName = String((resource == null ? void 0 : resource.collectionName) || "").trim();
1304
+ if (!collectionName || typeof (context == null ? void 0 : context.getCollection) !== "function") {
1305
+ return null;
1306
+ }
1307
+ const dataSourceKey = String((resource == null ? void 0 : resource.dataSourceKey) || "main").trim() || "main";
1308
+ const collection = context.getCollection(dataSourceKey, collectionName);
1309
+ if (!collection) {
1310
+ return null;
1311
+ }
1312
+ return (fieldPath) => {
1313
+ const normalizedFieldPath = (0, import_service_helpers.normalizeFieldPath)(fieldPath);
1314
+ const resolved = resolveDefaultFilterFieldPath(collection, normalizedFieldPath, dataSourceKey, context);
1315
+ return {
1316
+ fieldPath,
1317
+ field: resolved.field
1318
+ };
1319
+ };
1320
+ }
1321
+ function getDateConditionFieldMeta(field) {
1322
+ return {
1323
+ type: (0, import_service_helpers.getFieldType)(field),
1324
+ interface: (0, import_service_helpers.getFieldInterface)(field)
1325
+ };
1326
+ }
1327
+ function getDateConditionFieldContextMeta(fieldContext) {
1328
+ return {
1329
+ ...getDateConditionFieldMeta(fieldContext == null ? void 0 : fieldContext.field),
1330
+ ...(fieldContext == null ? void 0 : fieldContext.fieldMeta) || {}
1331
+ };
1332
+ }
1259
1333
  function normalizeChartAssetFieldPath(input) {
1260
1334
  if (Array.isArray(input)) {
1261
1335
  return input.map((item) => String(item || "").trim()).filter(Boolean).join(".");
@@ -3616,6 +3690,9 @@ function getGeneratedPopupBusinessFieldCandidates(collection) {
3616
3690
  if (!fieldName || !(0, import_default_action_popup.isFlowSurfaceDefaultActionPopupBusinessField)(field)) {
3617
3691
  return [];
3618
3692
  }
3693
+ if ((0, import_relation_backing_foreign_key.isRelationBackingForeignKeyField)(collection, field)) {
3694
+ return [];
3695
+ }
3619
3696
  return [
3620
3697
  {
3621
3698
  field,
@@ -3730,11 +3807,15 @@ function getGeneratedPopupDefaultFormFieldPaths(candidates, fieldGroups) {
3730
3807
  }
3731
3808
  function getGeneratedPopupRuntimeFieldCandidates(input) {
3732
3809
  const candidateContext = DEFAULT_ACTION_POPUP_FIELD_CONTEXT_BY_TYPE[input.actionType];
3810
+ const explicitDefaultFieldPaths = (0, import_default_action_popup.collectFlowSurfaceDefaultActionPopupFieldGroupFieldPaths)(input.fieldGroups);
3733
3811
  return (0, import_service_helpers.getCollectionFields)(input.collection).flatMap((field) => {
3734
3812
  const fieldName = (0, import_service_helpers.getFieldName)(field);
3735
3813
  if (!fieldName || !(0, import_default_action_popup.isFlowSurfaceDefaultActionPopupBusinessField)(field)) {
3736
3814
  return [];
3737
3815
  }
3816
+ if ((0, import_relation_backing_foreign_key.isRelationBackingForeignKeyField)(input.collection, field) && !explicitDefaultFieldPaths.has(fieldName)) {
3817
+ return [];
3818
+ }
3738
3819
  const fieldInterface = (0, import_service_helpers.getFieldInterface)(field);
3739
3820
  const registeredBinding = (0, import_field_binding_registry.resolveRegisteredFieldBinding)({
3740
3821
  containerUse: candidateContext.ownerUse,
@@ -3958,9 +4039,16 @@ function collectBlockErrors(block, path, errors, localKeys, context) {
3958
4039
  collectChartDisplayTitleErrors(block, blockType, path, errors);
3959
4040
  collectTreeTableExplicitFieldsErrors(block, blockType, path, errors, context);
3960
4041
  collectTreeConnectFieldsErrors((_a = block.settings) == null ? void 0 : _a.connectFields, `${path}.settings.connectFields`, errors);
3961
- collectTableSettingsErrors(block, blockType, path, errors, {
3962
- deferPublicDataScopeErrors: context.authoringActionName === "addBlocks"
3963
- });
4042
+ collectTableSettingsErrors(
4043
+ block,
4044
+ blockType,
4045
+ path,
4046
+ errors,
4047
+ {
4048
+ deferPublicDataScopeErrors: context.authoringActionName === "addBlocks"
4049
+ },
4050
+ context
4051
+ );
3964
4052
  collectGridCardSettingsErrors(block, blockType, path, errors);
3965
4053
  const descendantContext = getBlockDescendantValidationContext(block, context);
3966
4054
  collectActionListErrors(block.actions, `${path}.actions`, errors, block, descendantContext, "actions");
@@ -4268,8 +4356,8 @@ async function collectConfigureErrors(values, errors, context) {
4268
4356
  collectCommentsBlockErrors(changesBlock, hostBlockType, "$.changes", errors, context);
4269
4357
  collectRecordHistoryBlockErrors(changesBlock, hostBlockType, "$.changes", errors, context);
4270
4358
  collectChartDisplayTitleErrors(changes, hostBlockType, "$.changes", errors);
4271
- collectChartConfigureFilterOperatorErrors(changes, hostBlockType, "$.changes", errors);
4272
- collectTableSettingsErrors(changes, hostBlockType, "$.changes", errors, { directSettings: true });
4359
+ collectChartConfigureFilterOperatorErrors(changes, hostBlockType, "$.changes", errors, context);
4360
+ collectTableSettingsErrors(changes, hostBlockType, "$.changes", errors, { directSettings: true }, context);
4273
4361
  collectGridCardSettingsErrors(changes, hostBlockType, "$.changes", errors, { directSettings: true });
4274
4362
  collectAssignValuesErrors(changes.assignValues, "$.changes.assignValues", errors, changesBlock, context);
4275
4363
  collectTriggerWorkflowsErrors(changes.triggerWorkflows, "$.changes.triggerWorkflows", errors);
@@ -4357,10 +4445,20 @@ function collectUnsupportedDefaultFilterOperatorError(operator, path, errors) {
4357
4445
  }
4358
4446
  });
4359
4447
  }
4360
- function collectDefaultFilterDateValueError(operator, value, path, errors) {
4448
+ function collectDefaultFilterDateValueError(operator, value, path, errors, fieldContext, options = {}) {
4361
4449
  var _a, _b, _c;
4450
+ const fieldMeta = getDateConditionFieldContextMeta(fieldContext);
4451
+ const normalizedOperator = typeof operator === "string" ? operator.trim() : "";
4452
+ if (!import_filter_group.FLOW_SURFACE_DATE_FILTER_OPERATORS.has(normalizedOperator) && !(0, import_filter_group.isFlowSurfaceDateLikeFieldMeta)(fieldMeta)) {
4453
+ return;
4454
+ }
4362
4455
  try {
4363
- (0, import_filter_group.normalizeFlowSurfaceStrictFilterDateValue)(operator, value, path);
4456
+ (0, import_filter_group.normalizeFlowSurfaceDateConditionValue)(operator, value, path, {
4457
+ fieldPath: fieldContext == null ? void 0 : fieldContext.fieldPath,
4458
+ fieldType: fieldMeta.type,
4459
+ fieldInterface: fieldMeta.interface,
4460
+ allowContextPathValue: options.allowContextPathValue
4461
+ });
4364
4462
  } catch (error) {
4365
4463
  if (!(error instanceof import_errors.FlowSurfaceBadRequestError)) {
4366
4464
  throw error;
@@ -5423,13 +5521,13 @@ function collectChartDisplayTitleErrors(block, blockType, blockPath, errors) {
5423
5521
  message: "Chart block settings do not support displayTitle in the current flowSurfaces runtime; keep settings.title and omit displayTitle."
5424
5522
  });
5425
5523
  }
5426
- function collectChartConfigureFilterOperatorErrors(changes, hostBlockType, path, errors) {
5524
+ function collectChartConfigureFilterOperatorErrors(changes, hostBlockType, path, errors, context) {
5427
5525
  if (hostBlockType !== "chart" || !_.isPlainObject(changes)) {
5428
5526
  return;
5429
5527
  }
5430
- collectChartQueryFilterOperatorErrors(changes.query, `${path}.query`, errors);
5528
+ collectChartQueryFilterOperatorErrors(changes.query, `${path}.query`, errors, context);
5431
5529
  if (_.isPlainObject(changes.configure)) {
5432
- collectChartQueryFilterOperatorErrors(changes.configure.query, `${path}.configure.query`, errors);
5530
+ collectChartQueryFilterOperatorErrors(changes.configure.query, `${path}.configure.query`, errors, context);
5433
5531
  }
5434
5532
  }
5435
5533
  function visitFilterItems(value, path, errors, block, context = {}) {
@@ -5446,7 +5544,13 @@ function visitFilterItems(value, path, errors, block, context = {}) {
5446
5544
  }
5447
5545
  if (typeof value.operator === "string") {
5448
5546
  collectUnsupportedDefaultFilterOperatorError(value.operator, `${path}.operator`, errors);
5449
- collectDefaultFilterDateValueError(value.operator, value.value, `${path}.value`, errors);
5547
+ collectDefaultFilterDateValueError(
5548
+ value.operator,
5549
+ value.value,
5550
+ `${path}.value`,
5551
+ errors,
5552
+ fieldRef ? resolveDefaultFilterDateConditionField(fieldRef.value, block, context) : void 0
5553
+ );
5450
5554
  }
5451
5555
  const filterItems = value.items;
5452
5556
  if (Array.isArray(filterItems)) {
@@ -5472,11 +5576,33 @@ function visitFilterItems(value, path, errors, block, context = {}) {
5472
5576
  if (_.isPlainObject(child)) {
5473
5577
  Object.entries(child).forEach(([operator, operatorValue]) => {
5474
5578
  collectUnsupportedDefaultFilterOperatorError(operator, `${path}.${key}.${operator}`, errors);
5475
- collectDefaultFilterDateValueError(operator, operatorValue, `${path}.${key}.${operator}`, errors);
5579
+ collectDefaultFilterDateValueError(
5580
+ operator,
5581
+ operatorValue,
5582
+ `${path}.${key}.${operator}`,
5583
+ errors,
5584
+ resolveDefaultFilterDateConditionField(key, block, context)
5585
+ );
5476
5586
  });
5477
5587
  }
5478
5588
  });
5479
5589
  }
5590
+ function resolveDefaultFilterDateConditionField(rawFieldPath, block, context) {
5591
+ const fieldPath = String(rawFieldPath || "").trim();
5592
+ if (!fieldPath || fieldPath.startsWith("$") || fieldPath.startsWith("{{")) {
5593
+ return null;
5594
+ }
5595
+ const collection = getBlockCollection(block, context);
5596
+ if (!collection) {
5597
+ return null;
5598
+ }
5599
+ const dataSourceKey = getBlockDataSourceKey(block, context);
5600
+ const resolved = resolveDefaultFilterFieldPath(collection, (0, import_service_helpers.normalizeFieldPath)(fieldPath), dataSourceKey, context);
5601
+ return {
5602
+ fieldPath,
5603
+ field: resolved.field
5604
+ };
5605
+ }
5480
5606
  function collectTreeConnectFieldsErrors(value, path, errors) {
5481
5607
  if (_.isUndefined(value)) {
5482
5608
  return [];
@@ -5825,7 +5951,7 @@ function getCollectionFilterTargetKey(collection) {
5825
5951
  function normalizeDataSourceKey(value) {
5826
5952
  return String(value || "main").trim() || "main";
5827
5953
  }
5828
- function collectTableSettingsErrors(block, blockType, blockPath, errors, options = {}) {
5954
+ function collectTableSettingsErrors(block, blockType, blockPath, errors, options = {}, context = {}) {
5829
5955
  if (blockType !== "table" || !_.isPlainObject(block)) {
5830
5956
  return;
5831
5957
  }
@@ -5850,7 +5976,7 @@ function collectTableSettingsErrors(block, blockType, blockPath, errors, options
5850
5976
  pushTableSettingsUnsupportedError(errors, `${settingsPath}.${key}`, key);
5851
5977
  });
5852
5978
  if (!shouldDeferPublicDataScopeErrorsToBatchItem(blockPath, errors, options)) {
5853
- collectPublicDataScopeErrors(settings.dataScope, `${settingsPath}.dataScope`, errors);
5979
+ collectPublicDataScopeErrors(settings.dataScope, `${settingsPath}.dataScope`, errors, block, context);
5854
5980
  }
5855
5981
  }
5856
5982
  function pushTableSettingsUnsupportedError(errors, path, key) {
@@ -5865,7 +5991,7 @@ function pushTableSettingsUnsupportedError(errors, path, key) {
5865
5991
  }
5866
5992
  });
5867
5993
  }
5868
- function collectPublicDataScopeErrors(value, path, errors) {
5994
+ function collectPublicDataScopeErrors(value, path, errors, block, context) {
5869
5995
  if (_.isUndefined(value)) {
5870
5996
  return;
5871
5997
  }
@@ -5885,7 +6011,9 @@ function collectPublicDataScopeErrors(value, path, errors) {
5885
6011
  repairHint: 'Use settings.dataScope with logic/items, for example {"logic":"$and","items":[{"path":"status","operator":"$eq","value":"Active"}]}; do not use a field-name map.'
5886
6012
  }
5887
6013
  });
6014
+ return;
5888
6015
  }
6016
+ collectFilterGroupDateConditionErrors(validationValue, path, errors, block, context);
5889
6017
  }
5890
6018
  function shouldDeferPublicDataScopeErrorsToBatchItem(blockPath, errors, options) {
5891
6019
  if (options.deferPublicDataScopeErrors !== true) {
@@ -5906,6 +6034,28 @@ function normalizePublicDataScopeValueForValidation(value) {
5906
6034
  }
5907
6035
  return value;
5908
6036
  }
6037
+ function collectFilterGroupDateConditionErrors(value, path, errors, block, context) {
6038
+ if (!_.isPlainObject(value)) {
6039
+ return;
6040
+ }
6041
+ if (Array.isArray(value.items)) {
6042
+ value.items.forEach(
6043
+ (item, index) => collectFilterGroupDateConditionErrors(item, `${path}.items[${index}]`, errors, block, context)
6044
+ );
6045
+ return;
6046
+ }
6047
+ if (!hasOwn(value, "operator")) {
6048
+ return;
6049
+ }
6050
+ const fieldPath = String(value.path || value.field || "").trim();
6051
+ collectDefaultFilterDateValueError(
6052
+ value.operator,
6053
+ value.value,
6054
+ `${path}.value`,
6055
+ errors,
6056
+ fieldPath ? resolveDefaultFilterDateConditionField(fieldPath, block, context) : void 0
6057
+ );
6058
+ }
5909
6059
  function collectGridCardSettingsErrors(block, blockType, blockPath, errors, options = {}) {
5910
6060
  const hasSettings = _.isPlainObject(block == null ? void 0 : block.settings);
5911
6061
  if (!hasSettings && options.directSettings !== true) {
@@ -6516,7 +6666,7 @@ function collectNestedBlockErrors(blocks, path, errors, localKeys, context) {
6516
6666
  }
6517
6667
  blocks.forEach((block, index) => collectBlockErrors(block, `${path}[${index}]`, errors, localKeys, context));
6518
6668
  }
6519
- function collectReactionErrors(reaction, path, localKeys, errors) {
6669
+ function collectReactionErrors(reaction, path, localKeys, errors, options = {}) {
6520
6670
  const items = Array.isArray(reaction == null ? void 0 : reaction.items) ? reaction.items : [];
6521
6671
  items.forEach((item, index) => {
6522
6672
  const rawTarget = (item == null ? void 0 : item.target) ?? (item == null ? void 0 : item.targetKey) ?? (item == null ? void 0 : item.targetBlock);
@@ -6534,8 +6684,198 @@ function collectReactionErrors(reaction, path, localKeys, errors) {
6534
6684
  message: `flowSurfaces authoring ${path}.items[${index}].target references unknown local target '${target}'`
6535
6685
  });
6536
6686
  }
6687
+ collectReactionItemDateConditionErrors(item, `${path}.items[${index}]`, target, errors, options);
6537
6688
  });
6538
6689
  }
6690
+ function collectReactionItemDateConditionErrors(item, path, target, errors, options) {
6691
+ if (!_.isPlainObject(item) || !_.isPlainObject(options.values) || !options.context) {
6692
+ return;
6693
+ }
6694
+ const targetMatch = findApplyBlueprintReactionTargetBlock(options.values, target, options.context);
6695
+ if (!targetMatch) {
6696
+ return;
6697
+ }
6698
+ const type = String(item.type || "").trim();
6699
+ const conditionFieldMetaByPath = buildApplyBlueprintReactionConditionFieldMetaByPath(
6700
+ targetMatch.block,
6701
+ targetMatch.context
6702
+ );
6703
+ _.castArray(item.rules || []).forEach((rule, ruleIndex) => {
6704
+ collectReactionFilterDateConditionErrors(
6705
+ (rule == null ? void 0 : rule.when) ?? (rule == null ? void 0 : rule.condition),
6706
+ `${path}.rules[${ruleIndex}].when`,
6707
+ errors,
6708
+ targetMatch.block,
6709
+ targetMatch.context,
6710
+ conditionFieldMetaByPath
6711
+ );
6712
+ if (type !== "setFieldLinkageRules") {
6713
+ return;
6714
+ }
6715
+ _.castArray((rule == null ? void 0 : rule.then) || (rule == null ? void 0 : rule.actions) || []).forEach((action, actionIndex) => {
6716
+ _.castArray((action == null ? void 0 : action.items) || []).forEach((assignItem, itemIndex) => {
6717
+ collectReactionFilterDateConditionErrors(
6718
+ (assignItem == null ? void 0 : assignItem.when) ?? (assignItem == null ? void 0 : assignItem.condition),
6719
+ `${path}.rules[${ruleIndex}].then[${actionIndex}].items[${itemIndex}].when`,
6720
+ errors,
6721
+ targetMatch.block,
6722
+ targetMatch.context,
6723
+ conditionFieldMetaByPath
6724
+ );
6725
+ });
6726
+ });
6727
+ });
6728
+ }
6729
+ function collectReactionFilterDateConditionErrors(filter, path, errors, block, context, fieldMetaByPath = {}) {
6730
+ if (!_.isPlainObject(filter)) {
6731
+ return;
6732
+ }
6733
+ if (Array.isArray(filter.items)) {
6734
+ filter.items.forEach(
6735
+ (item, index) => collectReactionFilterDateConditionErrors(
6736
+ item,
6737
+ `${path}.items[${index}]`,
6738
+ errors,
6739
+ block,
6740
+ context,
6741
+ fieldMetaByPath
6742
+ )
6743
+ );
6744
+ return;
6745
+ }
6746
+ if (!hasOwn(filter, "operator")) {
6747
+ return;
6748
+ }
6749
+ const conditionPath = normalizeReactionConditionPath(filter.path);
6750
+ const fieldContext = resolveReactionConditionFieldContext(conditionPath, block, context, fieldMetaByPath);
6751
+ collectDefaultFilterDateValueError(filter.operator, filter.value, `${path}.value`, errors, fieldContext, {
6752
+ allowContextPathValue: true
6753
+ });
6754
+ }
6755
+ function normalizeReactionConditionPath(rawPath) {
6756
+ const value = String(rawPath || "").trim();
6757
+ const templateMatch = /^\{\{\s*ctx(?:\.([^}]+?))?\s*\}\}$/.exec(value);
6758
+ const path = templateMatch ? String(templateMatch[1] || "").trim() : value.replace(/^ctx\./, "");
6759
+ return path.split(".").map((segment) => segment.trim()).filter(Boolean).join(".");
6760
+ }
6761
+ function buildApplyBlueprintReactionConditionFieldMetaByPath(block, context) {
6762
+ var _a, _b;
6763
+ const collection = getBlockCollection(block, context);
6764
+ const dataSourceKey = getBlockDataSourceKey(block, context);
6765
+ const userCollection = ((_a = context.getCollection) == null ? void 0 : _a.call(context, "main", "users")) || ((_b = context.getCollection) == null ? void 0 : _b.call(context, dataSourceKey, "users")) || null;
6766
+ const response = (0, import_context.buildFlowSurfaceContextResponse)({
6767
+ semantic: {
6768
+ collection,
6769
+ userCollection,
6770
+ recordCollection: collection,
6771
+ formValuesCollection: collection,
6772
+ itemCollections: collection ? [collection] : [],
6773
+ itemRootCollection: collection || void 0,
6774
+ popupLevels: context.isPopupSurface || context.popupHasCurrentRecord ? [
6775
+ {
6776
+ recordCollection: collection,
6777
+ sourceRecordCollection: collection
6778
+ }
6779
+ ] : []
6780
+ },
6781
+ maxDepth: 4
6782
+ });
6783
+ const fieldMetaByPath = collectAuthorableReactionContextFieldMetaByPath(response);
6784
+ addCollectionFieldMetaAliases(fieldMetaByPath, collection, ["collection", "record", "formValues"]);
6785
+ addCollectionFieldMetaAliases(fieldMetaByPath, collection, ["item"], {
6786
+ preserveExisting: true,
6787
+ reservedKeys: /* @__PURE__ */ new Set(["index", "length", "value", "parentItem"])
6788
+ });
6789
+ if (userCollection) {
6790
+ addCollectionFieldMetaAliases(fieldMetaByPath, userCollection, ["user"]);
6791
+ }
6792
+ return fieldMetaByPath;
6793
+ }
6794
+ function collectAuthorableReactionContextFieldMetaByPath(context) {
6795
+ const fieldMetaByPath = {};
6796
+ const visit = (prefix, info) => {
6797
+ if (!prefix || !info) {
6798
+ return;
6799
+ }
6800
+ if (isAuthorableReactionContextPath(prefix)) {
6801
+ fieldMetaByPath[prefix] = {
6802
+ ...info.type ? { type: info.type } : {},
6803
+ ...info.interface ? { interface: info.interface } : {}
6804
+ };
6805
+ }
6806
+ if (info.dynamicProperties) {
6807
+ visit(`${prefix}.*`, info.dynamicProperties);
6808
+ }
6809
+ Object.entries(info.properties || {}).forEach(([key, child]) => visit(`${prefix}.${key}`, child));
6810
+ };
6811
+ Object.entries((context == null ? void 0 : context.vars) || {}).forEach(([key, info]) => visit(key, info));
6812
+ return fieldMetaByPath;
6813
+ }
6814
+ function isAuthorableReactionContextPath(path) {
6815
+ const segments = String(path || "").split(".").filter(Boolean);
6816
+ const root = segments[0];
6817
+ if (!root) {
6818
+ return false;
6819
+ }
6820
+ if (AUTHORABLE_REACTION_SCALAR_CONTEXT_PATHS.has(root)) {
6821
+ return segments.length === 1;
6822
+ }
6823
+ return AUTHORABLE_REACTION_CONTEXT_ROOTS.has(root);
6824
+ }
6825
+ function addCollectionFieldMetaAliases(fieldMetaByPath, collection, roots, options = {}) {
6826
+ var _a;
6827
+ for (const field of (0, import_service_helpers.getCollectionFields)(collection)) {
6828
+ const fieldName = (0, import_service_helpers.getFieldName)(field);
6829
+ if (!fieldName) {
6830
+ continue;
6831
+ }
6832
+ const fieldMeta = {
6833
+ ...(0, import_service_helpers.getFieldType)(field) ? { type: (0, import_service_helpers.getFieldType)(field) } : {},
6834
+ ...(0, import_service_helpers.getFieldInterface)(field) ? { interface: (0, import_service_helpers.getFieldInterface)(field) } : {}
6835
+ };
6836
+ for (const root of roots) {
6837
+ if ((_a = options.reservedKeys) == null ? void 0 : _a.has(fieldName)) {
6838
+ continue;
6839
+ }
6840
+ const aliasPath = `${root}.${fieldName}`;
6841
+ if (options.preserveExisting && fieldMetaByPath[aliasPath]) {
6842
+ continue;
6843
+ }
6844
+ fieldMetaByPath[aliasPath] = {
6845
+ ...fieldMetaByPath[aliasPath],
6846
+ ...fieldMeta
6847
+ };
6848
+ }
6849
+ }
6850
+ }
6851
+ function resolveReactionConditionFieldContext(path, block, context, fieldMetaByPath) {
6852
+ const normalized = String(path || "").trim();
6853
+ const contextMeta = resolveReactionConditionFieldMeta(normalized, fieldMetaByPath);
6854
+ if (contextMeta) {
6855
+ return {
6856
+ fieldPath: normalized,
6857
+ fieldMeta: contextMeta
6858
+ };
6859
+ }
6860
+ const fieldPath = resolveReactionConditionFieldPath(normalized);
6861
+ return fieldPath ? resolveDefaultFilterDateConditionField(fieldPath, block, context) || void 0 : void 0;
6862
+ }
6863
+ function resolveReactionConditionFieldMeta(path, fieldMetaByPath) {
6864
+ if (fieldMetaByPath[path]) {
6865
+ return fieldMetaByPath[path];
6866
+ }
6867
+ const wildcardPath = Object.keys(fieldMetaByPath).filter((candidate) => candidate.endsWith(".*")).sort((a, b) => b.length - a.length).find((candidate) => {
6868
+ const prefix = candidate.slice(0, -2);
6869
+ return path.startsWith(`${prefix}.`) && path.length > prefix.length + 1;
6870
+ });
6871
+ return wildcardPath ? fieldMetaByPath[wildcardPath] : void 0;
6872
+ }
6873
+ function resolveReactionConditionFieldPath(path) {
6874
+ const normalized = String(path || "").trim();
6875
+ const prefixes = ["formValues.", "record.", "item.value.", "item.", "popup.record.", "collection.", "user."];
6876
+ const prefix = prefixes.find((candidate) => normalized.startsWith(candidate));
6877
+ return prefix ? normalized.slice(prefix.length) : "";
6878
+ }
6539
6879
  function collectFieldListErrors(fields, path, errors, localKeys, context, block) {
6540
6880
  if (!Array.isArray(fields)) {
6541
6881
  return;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import type { FlowSurfaceApplyBlueprintDocument } from './public-types';
10
+ export type FlowSurfaceExportBlueprintUnsupportedPolicy = 'error' | 'warn';
11
+ export type FlowSurfaceExportBlueprintUnsupportedItem = {
12
+ kind: 'page' | 'tab' | 'block' | 'field' | 'action' | 'recordAction' | 'reaction' | 'layout' | 'popup';
13
+ use?: string;
14
+ type?: string;
15
+ path: string;
16
+ reasonCode: string;
17
+ manualAction: string;
18
+ };
19
+ export type FlowSurfaceExportBlueprintResult = {
20
+ document: FlowSurfaceApplyBlueprintDocument;
21
+ source: {
22
+ target: {
23
+ pageSchemaUid: string;
24
+ };
25
+ pageTitle?: string;
26
+ };
27
+ warnings: string[];
28
+ unsupported: FlowSurfaceExportBlueprintUnsupportedItem[];
29
+ };
30
+ type FlowSurfaceExportNode = Record<string, unknown> & {
31
+ uid?: string;
32
+ use?: string;
33
+ props?: Record<string, unknown>;
34
+ decoratorProps?: Record<string, unknown>;
35
+ stepParams?: Record<string, unknown>;
36
+ flowRegistry?: Record<string, unknown>;
37
+ template?: Record<string, unknown>;
38
+ fieldsTemplate?: Record<string, unknown>;
39
+ popup?: Record<string, unknown>;
40
+ subModels?: Record<string, unknown>;
41
+ };
42
+ export declare function exportFlowSurfaceBlueprintDocument(input: {
43
+ page: FlowSurfaceExportNode;
44
+ pageRoute?: Record<string, unknown>;
45
+ target: {
46
+ pageSchemaUid: string;
47
+ };
48
+ unsupportedPolicy?: FlowSurfaceExportBlueprintUnsupportedPolicy;
49
+ }): FlowSurfaceExportBlueprintResult;
50
+ export {};