@aranzatech/diagrams-bpmn 0.2.15 → 0.3.1

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 (75) hide show
  1. package/README.md +34 -4
  2. package/dist/{catalog-xOMF2ifW.d.cts → catalog-DAGDhO-D.d.cts} +1 -1
  3. package/dist/{catalog-CK3_4cOb.d.ts → catalog-Q1QmKLDD.d.ts} +1 -1
  4. package/dist/{chunk-YUE5EM3W.js → chunk-334WN4JZ.js} +276 -107
  5. package/dist/chunk-334WN4JZ.js.map +1 -0
  6. package/dist/chunk-77L6O76M.js +3 -0
  7. package/dist/chunk-77L6O76M.js.map +1 -0
  8. package/dist/{chunk-QSMP34CT.js → chunk-CPFUQM6H.js} +80 -44
  9. package/dist/chunk-CPFUQM6H.js.map +1 -0
  10. package/dist/{chunk-XMVV7FRZ.js → chunk-FFWJA5BV.js} +3 -3
  11. package/dist/{chunk-XMVV7FRZ.js.map → chunk-FFWJA5BV.js.map} +1 -1
  12. package/dist/{chunk-FBTGIYZS.js → chunk-JEGYVEJO.js} +80 -3
  13. package/dist/{chunk-FBTGIYZS.js.map → chunk-JEGYVEJO.js.map} +1 -1
  14. package/dist/chunk-TB6V4S5N.js +104 -0
  15. package/dist/chunk-TB6V4S5N.js.map +1 -0
  16. package/dist/{chunk-HOWK3ZOO.js → chunk-YAYZW45I.js} +379 -16
  17. package/dist/chunk-YAYZW45I.js.map +1 -0
  18. package/dist/edges/index.cjs +78 -42
  19. package/dist/edges/index.cjs.map +1 -1
  20. package/dist/edges/index.js +1 -1
  21. package/dist/elements/index.cjs +78 -0
  22. package/dist/elements/index.cjs.map +1 -1
  23. package/dist/elements/index.d.cts +24 -5
  24. package/dist/elements/index.d.ts +24 -5
  25. package/dist/elements/index.js +1 -1
  26. package/dist/elk-QT7H4252.js +6 -0
  27. package/dist/elk-QT7H4252.js.map +1 -0
  28. package/dist/extensions/index.cjs +108 -0
  29. package/dist/extensions/index.cjs.map +1 -0
  30. package/dist/extensions/index.d.cts +145 -0
  31. package/dist/extensions/index.d.ts +145 -0
  32. package/dist/extensions/index.js +4 -0
  33. package/dist/extensions/index.js.map +1 -0
  34. package/dist/index.cjs +922 -160
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +7 -5
  37. package/dist/index.d.ts +7 -5
  38. package/dist/index.js +6 -4
  39. package/dist/index.js.map +1 -1
  40. package/dist/layout/index.cjs +366 -90
  41. package/dist/layout/index.cjs.map +1 -1
  42. package/dist/layout/index.d.cts +4 -3
  43. package/dist/layout/index.d.ts +4 -3
  44. package/dist/layout/index.js +358 -92
  45. package/dist/layout/index.js.map +1 -1
  46. package/dist/modeling/index.cjs +387 -13
  47. package/dist/modeling/index.cjs.map +1 -1
  48. package/dist/modeling/index.d.cts +62 -4
  49. package/dist/modeling/index.d.ts +62 -4
  50. package/dist/modeling/index.js +1 -1
  51. package/dist/types-BX_o95GC.d.cts +40 -0
  52. package/dist/{types-y-ZbX-ff.d.ts → types-BYN4Zuee.d.cts} +15 -1
  53. package/dist/{types-y-ZbX-ff.d.cts → types-BYN4Zuee.d.ts} +15 -1
  54. package/dist/{types-jIDz306Y.d.cts → types-CggktCqr.d.cts} +4 -1
  55. package/dist/types-D7zel9dq.d.ts +40 -0
  56. package/dist/{types-DG5yPKld.d.ts → types-DmDODKlh.d.ts} +4 -1
  57. package/dist/validation/index.cjs +81 -125
  58. package/dist/validation/index.cjs.map +1 -1
  59. package/dist/validation/index.d.cts +22 -5
  60. package/dist/validation/index.d.ts +22 -5
  61. package/dist/validation/index.js +82 -126
  62. package/dist/validation/index.js.map +1 -1
  63. package/dist/xml/index.cjs +319 -49
  64. package/dist/xml/index.cjs.map +1 -1
  65. package/dist/xml/index.d.cts +5 -3
  66. package/dist/xml/index.d.ts +5 -3
  67. package/dist/xml/index.js +2 -1
  68. package/package.json +6 -1
  69. package/dist/chunk-HOWK3ZOO.js.map +0 -1
  70. package/dist/chunk-QSMP34CT.js.map +0 -1
  71. package/dist/chunk-YUE5EM3W.js.map +0 -1
  72. package/dist/elk-FSFIEL6O.js +0 -6
  73. package/dist/elk-FSFIEL6O.js.map +0 -1
  74. package/dist/guards-C70uIY_O.d.cts +0 -16
  75. package/dist/guards-foB6XIfZ.d.ts +0 -16
@@ -15,6 +15,14 @@ var ARANZA_DESCRIPTOR = {
15
15
  { name: "owner", isAttr: true, type: "String" },
16
16
  { name: "sla", isAttr: true, type: "String" },
17
17
  // Aranza connector execution config (resolved at runtime by the Flowable delegate)
18
+ { name: "implementation", isAttr: true, type: "String" },
19
+ { name: "connectorInstanceId", isAttr: true, type: "String" },
20
+ { name: "connectorId", isAttr: true, type: "String" },
21
+ { name: "connectorAction", isAttr: true, type: "String" },
22
+ { name: "connectorParamsJson", isAttr: true, type: "String" },
23
+ { name: "httpMethod", isAttr: true, type: "String" },
24
+ { name: "endpoint", isAttr: true, type: "String" },
25
+ { name: "operationRef", isAttr: true, type: "String" },
18
26
  { name: "connector", isAttr: true, type: "String" },
19
27
  { name: "action", isAttr: true, type: "String" },
20
28
  // Flowable implementation hints stored for round-trip fidelity
@@ -774,6 +782,11 @@ function asElements(v) {
774
782
  function asString(v) {
775
783
  return typeof v === "string" && v.trim() ? v.trim() : void 0;
776
784
  }
785
+ function asStringRecord(value) {
786
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
787
+ const entries = Object.entries(value).filter((entry) => typeof entry[1] === "string");
788
+ return entries.length > 0 ? Object.fromEntries(entries) : void 0;
789
+ }
777
790
  function extractDocumentation(el) {
778
791
  const [doc] = asElements(el.documentation);
779
792
  return asString(doc?.text);
@@ -952,6 +965,35 @@ function extractAranzaExtensions(el) {
952
965
  if (owner) result.owner = owner;
953
966
  const sla = asString(taskConfig.sla);
954
967
  if (sla) result.sla = sla;
968
+ const serviceConfig = {};
969
+ const implementation = asString(taskConfig.implementation);
970
+ if (implementation === "none" || implementation === "connector" || implementation === "http" || implementation === "webService") {
971
+ serviceConfig.implementation = implementation;
972
+ }
973
+ const connectorInstanceId = asString(taskConfig.connectorInstanceId);
974
+ if (connectorInstanceId) serviceConfig.connectorInstanceId = connectorInstanceId;
975
+ const connectorId = asString(taskConfig.connectorId);
976
+ if (connectorId) serviceConfig.connectorId = connectorId;
977
+ const connectorAction = asString(taskConfig.connectorAction);
978
+ if (connectorAction) serviceConfig.connectorAction = connectorAction;
979
+ const connectorParamsJson = asString(taskConfig.connectorParamsJson);
980
+ if (connectorParamsJson) {
981
+ try {
982
+ const parsed = JSON.parse(connectorParamsJson);
983
+ const connectorParams = asStringRecord(parsed);
984
+ if (connectorParams) serviceConfig.connectorParams = connectorParams;
985
+ } catch {
986
+ }
987
+ }
988
+ const httpMethod = asString(taskConfig.httpMethod);
989
+ if (httpMethod === "GET" || httpMethod === "POST" || httpMethod === "PUT" || httpMethod === "DELETE" || httpMethod === "PATCH") {
990
+ serviceConfig.httpMethod = httpMethod;
991
+ }
992
+ const endpoint = asString(taskConfig.endpoint);
993
+ if (endpoint) serviceConfig.endpoint = endpoint;
994
+ const operationRef = asString(taskConfig.operationRef);
995
+ if (operationRef) serviceConfig.operationRef = operationRef;
996
+ if (Object.keys(serviceConfig).length > 0) result.serviceConfig = serviceConfig;
955
997
  const connector = asString(taskConfig.connector);
956
998
  if (connector) result.connector = connector;
957
999
  const action = asString(taskConfig.action);
@@ -1044,6 +1086,7 @@ function buildNode(el, elementType, parentId, ctx, nodes) {
1044
1086
  const completionCondition = elementType === "AdHocSubProcess" ? extractCompletionCondition(el) : void 0;
1045
1087
  const loopChars = extractLoopCharacteristics(el);
1046
1088
  const dataObjectRef = elementType === "DataObjectReference" ? asString(el.dataObjectRef?.id) : void 0;
1089
+ const dataStoreRef = elementType === "DataStoreReference" ? asString(el.dataStoreRef?.id) : void 0;
1047
1090
  const data = {
1048
1091
  elementType,
1049
1092
  ...label ? { label } : {},
@@ -1065,6 +1108,7 @@ function buildNode(el, elementType, parentId, ctx, nodes) {
1065
1108
  ...script ? { script } : {},
1066
1109
  ...completionCondition ? { completionCondition } : {},
1067
1110
  ...dataObjectRef ? { dataObjectRef } : {},
1111
+ ...dataStoreRef ? { dataStoreRef } : {},
1068
1112
  ...loopChars,
1069
1113
  ...aranzaExt
1070
1114
  };
@@ -1221,9 +1265,10 @@ async function parseBpmnXml(xml) {
1221
1265
  }
1222
1266
  }
1223
1267
  const defaultFlowById = /* @__PURE__ */ new Set();
1268
+ const defaultFlowBySourceId = /* @__PURE__ */ new Map();
1224
1269
  const nodeIds = new Set(nodes.map((node) => node.id));
1225
1270
  for (const rootEl of asElements(rootElement.rootElements)) {
1226
- collectDefaultFlows(rootEl, defaultFlowById);
1271
+ collectDefaultFlows(rootEl, defaultFlowById, defaultFlowBySourceId);
1227
1272
  }
1228
1273
  const normalizedEdges = edges.map((edge) => {
1229
1274
  if (!defaultFlowById.has(edge.id)) return edge;
@@ -1246,18 +1291,36 @@ async function parseBpmnXml(xml) {
1246
1291
  if (importedDefinitions) importedProcess.definitions = importedDefinitions;
1247
1292
  return importedProcess;
1248
1293
  })() : importedDefinitions ? { definitions: importedDefinitions } : void 0;
1294
+ const normalizedNodes = normalizeChildPositions(nodes, nodeIds).map((node) => {
1295
+ const defaultFlowId = defaultFlowBySourceId.get(node.id);
1296
+ if (!defaultFlowId) return node;
1297
+ return {
1298
+ ...node,
1299
+ data: {
1300
+ ...node.data,
1301
+ default: defaultFlowId
1302
+ }
1303
+ };
1304
+ });
1249
1305
  return {
1250
- nodes: normalizeChildPositions(nodes, nodeIds),
1306
+ nodes: normalizedNodes,
1251
1307
  edges: normalizedEdges,
1252
1308
  warnings,
1253
1309
  ...process ? { process } : {}
1254
1310
  };
1255
1311
  }
1256
- function collectDefaultFlows(el, defaultFlowById) {
1312
+ function collectDefaultFlows(el, defaultFlowById, defaultFlowBySourceId) {
1257
1313
  const defaultRef = el.default;
1258
- if (defaultRef?.id) defaultFlowById.add(defaultRef.id);
1259
- for (const child of asElements(el.rootElements)) collectDefaultFlows(child, defaultFlowById);
1260
- for (const child of asElements(el.flowElements)) collectDefaultFlows(child, defaultFlowById);
1314
+ if (defaultRef?.id) {
1315
+ defaultFlowById.add(defaultRef.id);
1316
+ if (el.id) defaultFlowBySourceId.set(el.id, defaultRef.id);
1317
+ }
1318
+ for (const child of asElements(el.rootElements)) {
1319
+ collectDefaultFlows(child, defaultFlowById, defaultFlowBySourceId);
1320
+ }
1321
+ for (const child of asElements(el.flowElements)) {
1322
+ collectDefaultFlows(child, defaultFlowById, defaultFlowBySourceId);
1323
+ }
1261
1324
  }
1262
1325
  function normalizeChildPositions(nodes, nodeIds) {
1263
1326
  const absoluteById = new Map(nodes.map((node) => [node.id, node.position]));
@@ -1275,6 +1338,43 @@ function normalizeChildPositions(nodes, nodeIds) {
1275
1338
  });
1276
1339
  }
1277
1340
 
1341
+ // src/extensions/types.ts
1342
+ function hasText(value) {
1343
+ return typeof value === "string" && value.trim().length > 0;
1344
+ }
1345
+ function getBpmnTaskExecutionExtensions(data) {
1346
+ const result = {};
1347
+ if (data.priority) result.priority = data.priority;
1348
+ if (hasText(data.owner)) result.owner = data.owner;
1349
+ if (hasText(data.sla)) result.sla = data.sla;
1350
+ if (hasText(data.connector)) result.connector = data.connector;
1351
+ if (hasText(data.action)) result.action = data.action;
1352
+ if (hasText(data.flowableType)) result.flowableType = data.flowableType;
1353
+ if (hasText(data.flowableDelegateExpression)) {
1354
+ result.flowableDelegateExpression = data.flowableDelegateExpression;
1355
+ }
1356
+ if (data.serviceConfig && Object.keys(data.serviceConfig).length > 0) {
1357
+ result.serviceConfig = data.serviceConfig;
1358
+ }
1359
+ if (hasText(data.decisionRef)) result.decisionRef = data.decisionRef;
1360
+ if (data.inlineDecisionTable) result.inlineDecisionTable = data.inlineDecisionTable;
1361
+ if (hasText(data.formKey)) result.formKey = data.formKey;
1362
+ if (hasText(data.candidateUsers)) result.candidateUsers = data.candidateUsers;
1363
+ if (hasText(data.candidateGroups)) result.candidateGroups = data.candidateGroups;
1364
+ if (hasText(data.dueDate)) result.dueDate = data.dueDate;
1365
+ if (hasText(data.skipExpression)) result.skipExpression = data.skipExpression;
1366
+ if (hasText(data.businessCalendarName)) {
1367
+ result.businessCalendarName = data.businessCalendarName;
1368
+ }
1369
+ return Object.keys(result).length > 0 ? result : void 0;
1370
+ }
1371
+ function getBpmnMessageFlowExecutionExtensions(data) {
1372
+ const result = {};
1373
+ if (hasText(data.payloadSchema)) result.payloadSchema = data.payloadSchema;
1374
+ if (hasText(data.correlationKey)) result.correlationKey = data.correlationKey;
1375
+ return Object.keys(result).length > 0 ? result : void 0;
1376
+ }
1377
+
1278
1378
  // src/xml/exporter.ts
1279
1379
  function uid(prefix, id) {
1280
1380
  return `${prefix}_${id}`;
@@ -1318,6 +1418,12 @@ function parseVariableType2(type) {
1318
1418
  return "xsd:string";
1319
1419
  }
1320
1420
  }
1421
+ function escapeXml(text) {
1422
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1423
+ }
1424
+ function escapeRegex(text) {
1425
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1426
+ }
1321
1427
  function buildGlobalDefinitions(moddle, definitionsSet) {
1322
1428
  if (!definitionsSet) return [];
1323
1429
  const rootElements = [];
@@ -1343,6 +1449,33 @@ function buildGlobalDefinitions(moddle, definitionsSet) {
1343
1449
  }
1344
1450
  return rootElements;
1345
1451
  }
1452
+ function collectReferencedDataStoreIds(nodes) {
1453
+ const ids = /* @__PURE__ */ new Set();
1454
+ for (const node of nodes) {
1455
+ if (node.data.elementType !== "DataStoreReference") continue;
1456
+ const explicitRef = typeof node.data.dataStoreRef === "string" ? node.data.dataStoreRef : `DataStore_${node.id}`;
1457
+ ids.add(explicitRef);
1458
+ }
1459
+ return ids;
1460
+ }
1461
+ function buildGlobalDataStores(moddle, nodes) {
1462
+ const referencedIds = collectReferencedDataStoreIds(nodes);
1463
+ if (referencedIds.size === 0) return [];
1464
+ const byId = new Map(nodes.map((node) => [node.id, node]));
1465
+ const rootElements = [];
1466
+ for (const id of referencedIds) {
1467
+ const existing = byId.get(id);
1468
+ if (existing?.data.elementType === "DataStore") {
1469
+ rootElements.push(moddle.create("bpmn:DataStore", {
1470
+ id,
1471
+ name: existing.data.label ?? ""
1472
+ }));
1473
+ continue;
1474
+ }
1475
+ rootElements.push(moddle.create("bpmn:DataStore", { id }));
1476
+ }
1477
+ return rootElements;
1478
+ }
1346
1479
  function buildItemDefinitions(moddle, variables) {
1347
1480
  return (variables ?? []).map(
1348
1481
  (variable) => moddle.create("bpmn:ItemDefinition", {
@@ -1376,38 +1509,41 @@ function buildEventDefinitions(moddle, node, eventDefinition) {
1376
1509
  return [moddle.create(defType, attrs)];
1377
1510
  }
1378
1511
  function buildAranzaExtensionElements(moddle, node) {
1379
- const { priority, owner, sla } = node.data;
1380
- const connector = typeof node.data.connector === "string" ? node.data.connector : void 0;
1381
- const action = typeof node.data.action === "string" ? node.data.action : void 0;
1382
- const flowableType = typeof node.data.flowableType === "string" ? node.data.flowableType : void 0;
1383
- const flowableDelegateExpression = typeof node.data.flowableDelegateExpression === "string" ? node.data.flowableDelegateExpression : void 0;
1384
- const decisionRef = typeof node.data.decisionRef === "string" ? node.data.decisionRef : void 0;
1385
- const formKey = typeof node.data.formKey === "string" ? node.data.formKey : void 0;
1386
- const candidateUsers = typeof node.data.candidateUsers === "string" ? node.data.candidateUsers : void 0;
1387
- const candidateGroups = typeof node.data.candidateGroups === "string" ? node.data.candidateGroups : void 0;
1388
- const dueDate = typeof node.data.dueDate === "string" ? node.data.dueDate : void 0;
1389
- const skipExpression = typeof node.data.skipExpression === "string" ? node.data.skipExpression : void 0;
1390
- const businessCalendarName = typeof node.data.businessCalendarName === "string" ? node.data.businessCalendarName : void 0;
1391
- if (!priority && !owner && !sla && !connector && !action && !flowableType && !flowableDelegateExpression && !decisionRef && !formKey && !candidateUsers && !candidateGroups && !dueDate && !skipExpression && !businessCalendarName) {
1512
+ const ext = getBpmnTaskExecutionExtensions(node.data);
1513
+ if (!ext) {
1392
1514
  return null;
1393
1515
  }
1394
1516
  const configAttrs = {};
1395
- if (priority) configAttrs.priority = priority;
1396
- if (owner) configAttrs.owner = owner;
1397
- if (sla) configAttrs.sla = sla;
1398
- if (connector) configAttrs.connector = connector;
1399
- if (action) configAttrs.action = action;
1400
- if (flowableType) configAttrs.flowableType = flowableType;
1401
- if (flowableDelegateExpression) configAttrs.flowableDelegateExpression = flowableDelegateExpression;
1402
- if (decisionRef) configAttrs.decisionRef = decisionRef;
1403
- if (formKey) configAttrs.formKey = formKey;
1404
- if (candidateUsers) configAttrs.candidateUsers = candidateUsers;
1405
- if (candidateGroups) configAttrs.candidateGroups = candidateGroups;
1406
- if (dueDate) configAttrs.dueDate = dueDate;
1407
- if (skipExpression) configAttrs.skipExpression = skipExpression;
1408
- if (businessCalendarName) configAttrs.businessCalendarName = businessCalendarName;
1517
+ if (ext.priority) configAttrs.priority = ext.priority;
1518
+ if (ext.owner) configAttrs.owner = ext.owner;
1519
+ if (ext.sla) configAttrs.sla = ext.sla;
1520
+ if (ext.serviceConfig?.implementation) configAttrs.implementation = ext.serviceConfig.implementation;
1521
+ if (ext.serviceConfig?.connectorInstanceId) {
1522
+ configAttrs.connectorInstanceId = ext.serviceConfig.connectorInstanceId;
1523
+ }
1524
+ if (ext.serviceConfig?.connectorId) configAttrs.connectorId = ext.serviceConfig.connectorId;
1525
+ if (ext.serviceConfig?.connectorAction) {
1526
+ configAttrs.connectorAction = ext.serviceConfig.connectorAction;
1527
+ }
1528
+ if (ext.serviceConfig?.connectorParams && Object.keys(ext.serviceConfig.connectorParams).length > 0) {
1529
+ configAttrs.connectorParamsJson = JSON.stringify(ext.serviceConfig.connectorParams);
1530
+ }
1531
+ if (ext.serviceConfig?.httpMethod) configAttrs.httpMethod = ext.serviceConfig.httpMethod;
1532
+ if (ext.serviceConfig?.endpoint) configAttrs.endpoint = ext.serviceConfig.endpoint;
1533
+ if (ext.serviceConfig?.operationRef) configAttrs.operationRef = ext.serviceConfig.operationRef;
1534
+ if (ext.connector) configAttrs.connector = ext.connector;
1535
+ if (ext.action) configAttrs.action = ext.action;
1536
+ if (ext.flowableType) configAttrs.flowableType = ext.flowableType;
1537
+ if (ext.flowableDelegateExpression) configAttrs.flowableDelegateExpression = ext.flowableDelegateExpression;
1538
+ if (ext.decisionRef) configAttrs.decisionRef = ext.decisionRef;
1539
+ if (ext.formKey) configAttrs.formKey = ext.formKey;
1540
+ if (ext.candidateUsers) configAttrs.candidateUsers = ext.candidateUsers;
1541
+ if (ext.candidateGroups) configAttrs.candidateGroups = ext.candidateGroups;
1542
+ if (ext.dueDate) configAttrs.dueDate = ext.dueDate;
1543
+ if (ext.skipExpression) configAttrs.skipExpression = ext.skipExpression;
1544
+ if (ext.businessCalendarName) configAttrs.businessCalendarName = ext.businessCalendarName;
1409
1545
  const values = [moddle.create("aranza:TaskConfig", configAttrs)];
1410
- const inlineDecisionTable = node.data.inlineDecisionTable;
1546
+ const inlineDecisionTable = ext.inlineDecisionTable;
1411
1547
  if (inlineDecisionTable && typeof inlineDecisionTable === "object") {
1412
1548
  const tbl = inlineDecisionTable;
1413
1549
  const { hitPolicy, ...rest } = tbl;
@@ -1427,13 +1563,15 @@ function buildSemanticModel(moddle, nodes, edges, opts) {
1427
1563
  const poolNodes = asNodes(nodes, ["Pool"]);
1428
1564
  const laneNodes = asNodes(nodes, ["Lane"]);
1429
1565
  const isCollaboration = poolNodes.length > 0;
1566
+ const referencedDataStoreIds = collectReferencedDataStoreIds(nodes);
1430
1567
  const definitions = moddle.create("bpmn:Definitions", {
1431
1568
  id: defId,
1432
1569
  targetNamespace: "http://bpmn.io/schema/bpmn",
1433
1570
  ...defName ? { name: defName } : {}
1434
1571
  });
1435
1572
  const rootElements = [
1436
- ...buildGlobalDefinitions(moddle, opts.process?.definitions)
1573
+ ...buildGlobalDefinitions(moddle, opts.process?.definitions),
1574
+ ...buildGlobalDataStores(moddle, nodes)
1437
1575
  ];
1438
1576
  const itemDefinitions = buildItemDefinitions(moddle, opts.process?.definitions?.variables);
1439
1577
  if (itemDefinitions.length > 0) {
@@ -1444,7 +1582,7 @@ function buildSemanticModel(moddle, nodes, edges, opts) {
1444
1582
  const processes = [];
1445
1583
  for (const pool of poolNodes) {
1446
1584
  const processId = `Process_${pool.id}`;
1447
- const process = buildProcess(moddle, nodes, edges, pool.id, laneNodes, processId, opts);
1585
+ const process = buildProcess(moddle, nodes, edges, pool.id, laneNodes, processId, opts, referencedDataStoreIds);
1448
1586
  processes.push(process);
1449
1587
  const participant = moddle.create("bpmn:Participant", {
1450
1588
  id: pool.id,
@@ -1456,18 +1594,17 @@ function buildSemanticModel(moddle, nodes, edges, opts) {
1456
1594
  const messageFlowEdges = edges.filter((e) => e.data?.edgeType === "messageFlow");
1457
1595
  const conversationLinkEdges = edges.filter((e) => e.data?.edgeType === "conversationLink");
1458
1596
  const messageFlows = messageFlowEdges.map((e) => {
1459
- const ps = typeof e.data?.payloadSchema === "string" ? e.data.payloadSchema : void 0;
1460
- const ck = typeof e.data?.correlationKey === "string" ? e.data.correlationKey : void 0;
1597
+ const ext = e.data ? getBpmnMessageFlowExecutionExtensions(e.data) : void 0;
1461
1598
  const mfAttrs = {
1462
1599
  id: e.id,
1463
1600
  name: e.data?.label ?? "",
1464
1601
  sourceRef: { id: e.source },
1465
1602
  targetRef: { id: e.target }
1466
1603
  };
1467
- if (ps || ck) {
1604
+ if (ext?.payloadSchema || ext?.correlationKey) {
1468
1605
  const cfg = moddle.create("aranza:MessageFlowConfig", {
1469
- ...ps ? { payloadSchema: ps } : {},
1470
- ...ck ? { correlationKey: ck } : {}
1606
+ ...ext.payloadSchema ? { payloadSchema: ext.payloadSchema } : {},
1607
+ ...ext.correlationKey ? { correlationKey: ext.correlationKey } : {}
1471
1608
  });
1472
1609
  mfAttrs.extensionElements = moddle.create("bpmn:ExtensionElements", { values: [cfg] });
1473
1610
  }
@@ -1495,14 +1632,15 @@ function buildSemanticModel(moddle, nodes, edges, opts) {
1495
1632
  void 0,
1496
1633
  laneNodes,
1497
1634
  opts.process?.processId ?? "Process_1",
1498
- opts
1635
+ opts,
1636
+ referencedDataStoreIds
1499
1637
  );
1500
1638
  rootElements.push(process);
1501
1639
  }
1502
1640
  definitions.rootElements = rootElements;
1503
1641
  return definitions;
1504
1642
  }
1505
- function buildProcess(moddle, allNodes, allEdges, poolId, laneNodes, processId, opts) {
1643
+ function buildProcess(moddle, allNodes, allEdges, poolId, laneNodes, processId, opts, referencedDataStoreIds) {
1506
1644
  const subProcessIds = new Set(
1507
1645
  allNodes.filter(
1508
1646
  (n) => n.data.elementType === "SubProcess" || n.data.elementType === "Transaction" || n.data.elementType === "EventSubProcess" || n.data.elementType === "AdHocSubProcess"
@@ -1524,7 +1662,7 @@ function buildProcess(moddle, allNodes, allEdges, poolId, laneNodes, processId,
1524
1662
  }
1525
1663
  return false;
1526
1664
  };
1527
- const myNodes = (poolId ? allNodes.filter((n) => belongsToPool(n)) : allNodes.filter((n) => n.data.elementType !== "Pool" && n.data.elementType !== "Lane")).filter((n) => !isInsideSubProcess(n));
1665
+ const myNodes = (poolId ? allNodes.filter((n) => belongsToPool(n)) : allNodes.filter((n) => n.data.elementType !== "Pool" && n.data.elementType !== "Lane")).filter((n) => !isInsideSubProcess(n)).filter((n) => !(n.data.elementType === "DataStore" && referencedDataStoreIds.has(n.id)));
1528
1666
  const myLanes = laneNodes.filter((l) => poolId ? l.parentId === poolId : true);
1529
1667
  const presentDataObjectIds = new Set(
1530
1668
  myNodes.filter((n) => n.data.elementType === "DataObject").map((n) => n.id)
@@ -1568,10 +1706,18 @@ function buildProcess(moddle, allNodes, allEdges, poolId, laneNodes, processId,
1568
1706
  const elementById = new Map(
1569
1707
  flowElements.filter((element) => typeof element.id === "string").map((element) => [element.id, element])
1570
1708
  );
1709
+ const defaultEdgeBySource = /* @__PURE__ */ new Map();
1710
+ for (const node of myNodes) {
1711
+ const defaultFlowId = typeof node.data.default === "string" ? node.data.default : void 0;
1712
+ if (defaultFlowId) defaultEdgeBySource.set(node.id, defaultFlowId);
1713
+ }
1571
1714
  for (const edge of myEdges) {
1572
- if (!edge.data?.isDefault) continue;
1573
- const sourceElement = elementById.get(edge.source);
1574
- const edgeElement = elementById.get(edge.id);
1715
+ if (!edge.data?.isDefault || defaultEdgeBySource.has(edge.source)) continue;
1716
+ defaultEdgeBySource.set(edge.source, edge.id);
1717
+ }
1718
+ for (const [sourceId, edgeId] of defaultEdgeBySource) {
1719
+ const sourceElement = elementById.get(sourceId);
1720
+ const edgeElement = elementById.get(edgeId);
1575
1721
  if (sourceElement && edgeElement) {
1576
1722
  sourceElement.default = edgeElement;
1577
1723
  }
@@ -1638,6 +1784,10 @@ function buildFlowElement(moddle, node, allNodes, allEdges) {
1638
1784
  const refId = typeof node.data.dataObjectRef === "string" ? node.data.dataObjectRef : `DataObject_${node.id}`;
1639
1785
  attrs.dataObjectRef = { id: refId };
1640
1786
  }
1787
+ if (elementType === "DataStoreReference") {
1788
+ const refId = typeof node.data.dataStoreRef === "string" ? node.data.dataStoreRef : `DataStore_${node.id}`;
1789
+ attrs.dataStoreRef = { id: refId };
1790
+ }
1641
1791
  if (elementType === "ScriptTask") {
1642
1792
  const scriptFormat = typeof node.data.scriptFormat === "string" ? node.data.scriptFormat : void 0;
1643
1793
  const script = typeof node.data.script === "string" ? node.data.script : void 0;
@@ -1699,7 +1849,8 @@ function buildFlowElement(moddle, node, allNodes, allEdges) {
1699
1849
  return element;
1700
1850
  }
1701
1851
  function buildNestedFlowElements(moddle, parent, allNodes, allEdges) {
1702
- const childNodes = allNodes.filter((node) => node.parentId === parent.id);
1852
+ const referencedDataStoreIds = collectReferencedDataStoreIds(allNodes);
1853
+ const childNodes = allNodes.filter((node) => node.parentId === parent.id).filter((node) => !(node.data.elementType === "DataStore" && referencedDataStoreIds.has(node.id)));
1703
1854
  const childNodeIds = new Set(childNodes.map((node) => node.id));
1704
1855
  const flowElements = [];
1705
1856
  const artifacts = [];
@@ -1853,6 +2004,124 @@ function buildAbsolutePositionMap(nodes) {
1853
2004
  for (const node of nodes) resolve(node);
1854
2005
  return absoluteById;
1855
2006
  }
2007
+ function getServiceTaskConfig(node, opts) {
2008
+ const override = opts.flowable?.serviceTaskConfigs?.[node.id];
2009
+ if (override) return override;
2010
+ const config = node.data.serviceConfig;
2011
+ return config && typeof config === "object" ? config : void 0;
2012
+ }
2013
+ function injectFlowableNamespace(xml) {
2014
+ if (xml.includes("xmlns:flowable=")) return xml;
2015
+ return xml.replace(
2016
+ "<bpmn:definitions",
2017
+ '<bpmn:definitions xmlns:flowable="http://flowable.org/bpmn"'
2018
+ );
2019
+ }
2020
+ function ensureOpeningTagAttribute(openTag, name, value) {
2021
+ if (new RegExp(`\\b${escapeRegex(name)}=`).test(openTag)) return openTag;
2022
+ return openTag.replace(/>$/, ` ${name}="${escapeXml(value)}">`);
2023
+ }
2024
+ function injectFlowableFieldsIntoElement(xml, elementTagName, nodeId, fieldsXml, flowableType) {
2025
+ const idPattern = escapeRegex(nodeId);
2026
+ const selfClosingPattern = new RegExp(
2027
+ `<bpmn:${elementTagName}\\b[^>]*?\\bid="${idPattern}"[^>]*/>`,
2028
+ "s"
2029
+ );
2030
+ const blockPattern = new RegExp(
2031
+ `<bpmn:${elementTagName}\\b[^>]*?\\bid="${idPattern}"[^>]*>[\\s\\S]*?<\\/bpmn:${elementTagName}>`,
2032
+ "s"
2033
+ );
2034
+ if (selfClosingPattern.test(xml)) {
2035
+ return xml.replace(selfClosingPattern, (match) => {
2036
+ const openTag = ensureOpeningTagAttribute(match.replace(/\/>$/, ">"), "flowable:type", flowableType);
2037
+ return `${openTag}
2038
+ <bpmn:extensionElements>
2039
+ ${fieldsXml}
2040
+ </bpmn:extensionElements>
2041
+ </bpmn:${elementTagName}>`;
2042
+ });
2043
+ }
2044
+ return xml.replace(blockPattern, (block) => {
2045
+ const openTagMatch = block.match(new RegExp(`^<bpmn:${elementTagName}\\b[^>]*>`, "s"));
2046
+ if (!openTagMatch) return block;
2047
+ const openTag = ensureOpeningTagAttribute(openTagMatch[0], "flowable:type", flowableType);
2048
+ let nextBlock = openTag + block.slice(openTagMatch[0].length);
2049
+ if (nextBlock.includes("<bpmn:extensionElements>")) {
2050
+ return nextBlock.replace(
2051
+ /<bpmn:extensionElements>([\s\S]*?)<\/bpmn:extensionElements>/,
2052
+ (_match, inner) => `<bpmn:extensionElements>${inner.trimEnd()}
2053
+ ${fieldsXml}
2054
+ </bpmn:extensionElements>`
2055
+ );
2056
+ }
2057
+ return nextBlock.replace(
2058
+ openTag,
2059
+ `${openTag}
2060
+ <bpmn:extensionElements>
2061
+ ${fieldsXml}
2062
+ </bpmn:extensionElements>`
2063
+ );
2064
+ });
2065
+ }
2066
+ function injectFlowableConnectorServiceTasks(xml, nodes, opts) {
2067
+ let result = xml;
2068
+ const backendUrlTemplate = opts.flowable?.backendUrlTemplate ?? "%%ARANZAFLOWS_BACKEND_URL%%";
2069
+ const responseVariableName = opts.flowable?.connectorResponseVariableName ?? "connectorResult";
2070
+ for (const node of nodes) {
2071
+ if (node.data.elementType !== "ServiceTask") continue;
2072
+ const cfg = getServiceTaskConfig(node, opts);
2073
+ if (cfg?.implementation !== "connector" || !cfg.connectorInstanceId || !cfg.connectorAction) {
2074
+ continue;
2075
+ }
2076
+ result = injectFlowableNamespace(result);
2077
+ const bodyObj = {
2078
+ action: cfg.connectorAction,
2079
+ params: cfg.connectorParams ?? {}
2080
+ };
2081
+ const url = `${backendUrlTemplate}/api/v1/integrations/${encodeURIComponent(cfg.connectorInstanceId)}/execute-internal`;
2082
+ const fieldsXml = [
2083
+ ' <flowable:field name="requestMethod"><flowable:string>POST</flowable:string></flowable:field>',
2084
+ ` <flowable:field name="requestUrl"><flowable:string>${escapeXml(url)}</flowable:string></flowable:field>`,
2085
+ ' <flowable:field name="requestHeaders"><flowable:string>Content-Type: application/json</flowable:string></flowable:field>',
2086
+ ` <flowable:field name="requestBody"><flowable:expression>${escapeXml(JSON.stringify(bodyObj))}</flowable:expression></flowable:field>`,
2087
+ ` <flowable:field name="responseVariableName"><flowable:string>${escapeXml(responseVariableName)}</flowable:string></flowable:field>`,
2088
+ ' <flowable:field name="saveResponseParameters"><flowable:string>false</flowable:string></flowable:field>'
2089
+ ].join("\n");
2090
+ result = injectFlowableFieldsIntoElement(result, "serviceTask", node.id, fieldsXml, "http");
2091
+ }
2092
+ return result;
2093
+ }
2094
+ function injectFlowableDecisionTasks(xml, nodes, opts) {
2095
+ let result = xml;
2096
+ const variables = opts.process?.definitions?.variables ?? [];
2097
+ const backendUrlTemplate = opts.flowable?.backendUrlTemplate ?? "%%ARANZAFLOWS_BACKEND_URL%%";
2098
+ const responseVariableName = opts.flowable?.decisionResponseVariableName ?? "decisionResult";
2099
+ for (const node of nodes) {
2100
+ if (node.data.elementType !== "BusinessRuleTask") continue;
2101
+ const decisionRef = typeof node.data.decisionRef === "string" ? node.data.decisionRef : void 0;
2102
+ if (!decisionRef) continue;
2103
+ result = injectFlowableNamespace(result);
2104
+ const url = `${backendUrlTemplate}/api/v1/decisions/${encodeURIComponent(decisionRef)}/evaluate-internal`;
2105
+ const bodyField = variables.length > 0 ? `<flowable:expression>${escapeXml(
2106
+ `{${variables.map((variable) => `"${variable.name}": \${${variable.name}}`).join(", ")}}`
2107
+ )}</flowable:expression>` : "<flowable:string>{}</flowable:string>";
2108
+ const fieldsXml = [
2109
+ ' <flowable:field name="requestMethod"><flowable:string>POST</flowable:string></flowable:field>',
2110
+ ` <flowable:field name="requestUrl"><flowable:string>${escapeXml(url)}</flowable:string></flowable:field>`,
2111
+ ' <flowable:field name="requestHeaders"><flowable:string>Content-Type: application/json</flowable:string></flowable:field>',
2112
+ ` <flowable:field name="requestBody">${bodyField}</flowable:field>`,
2113
+ ` <flowable:field name="responseVariableName"><flowable:string>${escapeXml(responseVariableName)}</flowable:string></flowable:field>`,
2114
+ ' <flowable:field name="saveResponseParameters"><flowable:string>false</flowable:string></flowable:field>'
2115
+ ].join("\n");
2116
+ result = injectFlowableFieldsIntoElement(result, "businessRuleTask", node.id, fieldsXml, "http");
2117
+ }
2118
+ return result;
2119
+ }
2120
+ function applyFlowableExportEnrichment(xml, nodes, opts) {
2121
+ if (!opts.flowable?.enabled) return xml;
2122
+ const withServiceTasks = injectFlowableConnectorServiceTasks(xml, nodes, opts);
2123
+ return injectFlowableDecisionTasks(withServiceTasks, nodes, opts);
2124
+ }
1856
2125
  async function serializeBpmnXml(nodes, edges, opts = {}) {
1857
2126
  const { BpmnModdle } = await import('bpmn-moddle');
1858
2127
  const moddle = new BpmnModdle({ aranza: ARANZA_DESCRIPTOR });
@@ -1861,9 +2130,10 @@ async function serializeBpmnXml(nodes, edges, opts = {}) {
1861
2130
  const { xml } = await moddle.toXML(definitions, {
1862
2131
  format: opts.format ?? true
1863
2132
  });
1864
- return xml;
2133
+ return applyFlowableExportEnrichment(xml, nodes, opts);
1865
2134
  }
1866
2135
 
2136
+ exports.ARANZA_DESCRIPTOR = ARANZA_DESCRIPTOR;
1867
2137
  exports.parseBpmnXml = parseBpmnXml;
1868
2138
  exports.serializeBpmnXml = serializeBpmnXml;
1869
2139
  //# sourceMappingURL=index.cjs.map