@emaarco/bpmn-js-data-simulation 0.3.0 → 0.4.0

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { Evaluation, FlowEvaluation, FlowOutcome, GatewayKind, Mapping, OutgoingFlow, RoutingDecision, Scenario, StartField, StartFieldType, Variables, } from './domain/model.js';
1
+ export type { Evaluation, FlowEvaluation, FlowOutcome, GatewayKind, Mapping, OutgoingFlow, RoutingDecision, Scenario, SimulatedPath, StartField, StartFieldType, Variables, } from './domain/model.js';
2
2
  export { GatewayRouter } from './domain/GatewayRouter.js';
3
3
  export { ScenarioError } from './domain/ScenarioError.js';
4
4
  export { ScenarioParser } from './domain/ScenarioParser.js';
@@ -13,5 +13,6 @@ export type { ConditionInput, DecisionLogEntry, InstanceState, InstanceStatus, L
13
13
  export type { FormValues, RenderedStartForm, StartFormRenderer } from './ui/startForm.js';
14
14
  export { SimpleStartFormRenderer } from './ui/SimpleStartFormRenderer.js';
15
15
  export type { DataSimulation, DataSimulationConfig } from './integration/DataSimulation.js';
16
- export { default, type DataSimulationModuleDeclaration } from './integration/index.js';
16
+ export { DataSimulationModule, DataSimulationModule as default, type DataSimulationModuleDeclaration, PathSimulationModule, } from './integration/index.js';
17
+ export type { PathSimulation, PathSimulationConfig, PathSimulationOptions } from './integration/PathSimulation.js';
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,EACX,OAAO,EACP,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,UAAU,EACV,cAAc,EACd,SAAS,GACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,M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;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AACvG,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AACzE,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,QAAQ,EACR,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,qCAAqC,CAAA;AAE5C,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACzF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAA;AAEzE,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AAC3F,OAAO,EACL,oBAAoB,EACpB,oBAAoB,IAAI,OAAO,EAC/B,KAAK,+BAA+B,EACpC,oBAAoB,GACrB,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA"}
package/dist/index.js CHANGED
@@ -1045,6 +1045,18 @@ function gatewayOf(element) {
1045
1045
  if (element.type === "bpmn:SequenceFlow" && element.source && isGateway(element.source)) return element.source.id;
1046
1046
  return void 0;
1047
1047
  }
1048
+ function outgoingSequenceFlows(element) {
1049
+ return (element.outgoing ?? []).filter((flow) => is(flow, "bpmn:SequenceFlow"));
1050
+ }
1051
+ function readOutgoingFlow(sequenceFlow, engine) {
1052
+ const name = sequenceFlow.businessObject.name;
1053
+ return {
1054
+ id: sequenceFlow.id,
1055
+ ...typeof name === "string" && name ? { name } : {},
1056
+ expression: engine.readCondition(sequenceFlow.businessObject),
1057
+ isDefault: sequenceFlow.source?.businessObject.default === sequenceFlow.businessObject
1058
+ };
1059
+ }
1048
1060
 
1049
1061
  class DataGateways {
1050
1062
  constructor(dataSimulation, store, simulator) {
@@ -1066,7 +1078,7 @@ class DataGateways {
1066
1078
  return;
1067
1079
  }
1068
1080
  for (const flowId of decision.takenFlowIds) {
1069
- const flow = this.sequenceFlows(gateway).find((candidate) => candidate.id === flowId);
1081
+ const flow = outgoingSequenceFlows(gateway).find((candidate) => candidate.id === flowId);
1070
1082
  this.simulator.enter({ element: flow, scope: scope.parent });
1071
1083
  }
1072
1084
  }
@@ -1124,19 +1136,7 @@ class DataGateways {
1124
1136
  }
1125
1137
  outgoingFlows(gateway) {
1126
1138
  const engine = this.dataSimulation.getEngine();
1127
- const defaultFlow = gateway.businessObject.default;
1128
- return this.sequenceFlows(gateway).map((flow) => {
1129
- const name = flow.businessObject.name;
1130
- return {
1131
- id: flow.id,
1132
- ...typeof name === "string" && name ? { name } : {},
1133
- expression: engine.readCondition(flow.businessObject),
1134
- isDefault: flow.businessObject === defaultFlow
1135
- };
1136
- });
1137
- }
1138
- sequenceFlows(gateway) {
1139
- return (gateway.outgoing ?? []).filter((flow) => is(flow, "bpmn:SequenceFlow"));
1139
+ return outgoingSequenceFlows(gateway).map((flow) => readOutgoingFlow(flow, engine));
1140
1140
  }
1141
1141
  }
1142
1142
  DataGateways.$inject = ["dataSimulation", "dataSimulationStore", "simulator"];
@@ -1192,10 +1192,15 @@ const TRACE_EVENT = "tokenSimulation.simulator.trace";
1192
1192
  const DATA_TOGGLE_EVENT = "dataSimulation.toggle";
1193
1193
 
1194
1194
  class DataSimulation {
1195
- constructor(config, eventBus, store) {
1195
+ constructor(config, eventBus, store, injector) {
1196
1196
  this.eventBus = eventBus;
1197
1197
  this.store = store;
1198
1198
  this.scenarioParser = new ScenarioParser();
1199
+ if (!injector.get("simulator", false)) {
1200
+ throw new Error(
1201
+ "DataSimulationModule needs bpmn-js-token-simulation; for the path alone use PathSimulationModule"
1202
+ );
1203
+ }
1199
1204
  this.engine = new EngineRegistry().resolve(config?.engine ?? "zeebe");
1200
1205
  this.ioMappings = new IoMappings(this.engine, store);
1201
1206
  this.enabled = config?.enabled ?? true;
@@ -1258,7 +1263,7 @@ class DataSimulation {
1258
1263
  if (this.store.hasInstance(instanceId)) this.ioMappings.apply(element, instanceId);
1259
1264
  }
1260
1265
  }
1261
- DataSimulation.$inject = ["config.dataSimulation", "eventBus", "dataSimulationStore"];
1266
+ DataSimulation.$inject = ["config.dataSimulation", "eventBus", "dataSimulationStore", "injector"];
1262
1267
 
1263
1268
  class GatewayDecisionView {
1264
1269
  constructor(snapshot) {
@@ -1428,7 +1433,7 @@ function createSheet() {
1428
1433
 
1429
1434
  const OUTCOME_OVERLAY = "bds-flow-outcome";
1430
1435
  const DECIDED_MARKER = "bds-gateway--decided";
1431
- const STUCK_MARKER = "bds-gateway--stuck";
1436
+ const STUCK_MARKER$1 = "bds-gateway--stuck";
1432
1437
  const BADGE_DISTANCE = 38;
1433
1438
  const BADGE_MIN_SCALE = 1;
1434
1439
  class DataSimulationOverlays {
@@ -1483,13 +1488,13 @@ class DataSimulationOverlays {
1483
1488
  markGateway({ elementId, decision }) {
1484
1489
  const gateway = this.elementRegistry.get(elementId);
1485
1490
  if (!gateway) return;
1486
- this.canvas.addMarker(gateway, decision.stuckReason ? STUCK_MARKER : DECIDED_MARKER);
1491
+ this.canvas.addMarker(gateway, decision.stuckReason ? STUCK_MARKER$1 : DECIDED_MARKER);
1487
1492
  this.markedGateways.push(gateway);
1488
1493
  }
1489
1494
  unmarkGateways() {
1490
1495
  for (const gateway of this.markedGateways) {
1491
1496
  this.canvas.removeMarker(gateway, DECIDED_MARKER);
1492
- this.canvas.removeMarker(gateway, STUCK_MARKER);
1497
+ this.canvas.removeMarker(gateway, STUCK_MARKER$1);
1493
1498
  }
1494
1499
  this.markedGateways = [];
1495
1500
  }
@@ -2056,7 +2061,150 @@ class DataStartForm {
2056
2061
  }
2057
2062
  DataStartForm.$inject = ["config.dataSimulation", "eventBus", "dataSimulation", "dataSimulationStore"];
2058
2063
 
2064
+ class PathResolver {
2065
+ constructor() {
2066
+ this.router = new GatewayRouter();
2067
+ }
2068
+ resolve(graph, evaluateCondition) {
2069
+ const nodes = new Map(graph.nodes.map((node) => [node.id, node]));
2070
+ const takenIds = /* @__PURE__ */ new Set();
2071
+ const decisions = {};
2072
+ const pendingIds = [...graph.startIds];
2073
+ while (pendingIds.length) {
2074
+ const node = nodes.get(pendingIds.shift());
2075
+ if (!node || takenIds.has(node.id)) continue;
2076
+ takenIds.add(node.id);
2077
+ pendingIds.push(...node.nestedStartIds);
2078
+ for (const flow of this.leave(node, evaluateCondition, decisions)) {
2079
+ takenIds.add(flow.id);
2080
+ pendingIds.push(flow.targetId);
2081
+ }
2082
+ }
2083
+ const elementIds = graph.nodes.flatMap((node) => [node.id, ...node.outgoing.map((flow) => flow.id)]);
2084
+ return {
2085
+ taken: elementIds.filter((id) => takenIds.has(id)),
2086
+ skipped: elementIds.filter((id) => !takenIds.has(id)),
2087
+ decisions,
2088
+ measures: this.sumMeasures(graph.nodes.filter((node) => takenIds.has(node.id)))
2089
+ };
2090
+ }
2091
+ leave(node, evaluateCondition, decisions) {
2092
+ if (!node.gatewayKind || node.outgoing.length < 2) return node.outgoing;
2093
+ const decision = this.router.route(node.gatewayKind, node.outgoing, evaluateCondition);
2094
+ decisions[node.id] = decision;
2095
+ return node.outgoing.filter((flow) => decision.takenFlowIds.includes(flow.id));
2096
+ }
2097
+ sumMeasures(nodes) {
2098
+ const totals = {};
2099
+ for (const node of nodes) {
2100
+ for (const [name, value] of Object.entries(node.measures)) totals[name] = (totals[name] ?? 0) + value;
2101
+ }
2102
+ return totals;
2103
+ }
2104
+ }
2105
+
2106
+ const GATEWAY_KINDS = {
2107
+ "bpmn:ExclusiveGateway": "exclusive",
2108
+ "bpmn:InclusiveGateway": "inclusive"
2109
+ };
2110
+ class PathGraphReader {
2111
+ constructor(elementRegistry, engine) {
2112
+ this.elementRegistry = elementRegistry;
2113
+ this.engine = engine;
2114
+ }
2115
+ read(measureNames) {
2116
+ const flowNodes = this.elementRegistry.filter(
2117
+ (element) => element.id === element.businessObject.id && is(element, "bpmn:FlowNode")
2118
+ );
2119
+ const startEventsIn = (container) => flowNodes.filter((node) => is(node, "bpmn:StartEvent") && node.businessObject.$parent === container);
2120
+ const processStartIds = flowNodes.filter((node) => is(node, "bpmn:StartEvent") && this.isProcess(node.businessObject.$parent)).map((node) => node.id);
2121
+ return {
2122
+ startIds: processStartIds,
2123
+ nodes: flowNodes.map((node) => this.toPathNode(node, startEventsIn, measureNames))
2124
+ };
2125
+ }
2126
+ toPathNode(node, startEventsIn, measureNames) {
2127
+ const entersSubProcess = is(node, "bpmn:SubProcess") && !node.businessObject.triggeredByEvent;
2128
+ return {
2129
+ id: node.id,
2130
+ ...GATEWAY_KINDS[node.type] ? { gatewayKind: GATEWAY_KINDS[node.type] } : {},
2131
+ outgoing: outgoingSequenceFlows(node).map((flow) => ({
2132
+ ...readOutgoingFlow(flow, this.engine),
2133
+ targetId: flow.target.id
2134
+ })),
2135
+ nestedStartIds: entersSubProcess ? startEventsIn(node.businessObject).map((start) => start.id) : [],
2136
+ measures: Object.fromEntries(measureNames.map((name) => [name, this.readMeasure(node.businessObject, name)]))
2137
+ };
2138
+ }
2139
+ isProcess(element) {
2140
+ return element?.$type === "bpmn:Process";
2141
+ }
2142
+ readMeasure(businessObject, name) {
2143
+ const attribute = businessObject.$attrs?.[name];
2144
+ const value = typeof attribute === "string" && attribute.trim() ? Number(attribute) : Number.NaN;
2145
+ return Number.isFinite(value) ? value : 0;
2146
+ }
2147
+ }
2148
+
2149
+ const TAKEN_MARKER = "bds-path--taken";
2150
+ const SKIPPED_MARKER = "bds-path--skipped";
2151
+ const STUCK_MARKER = "bds-path--stuck";
2152
+ class PathMarkers {
2153
+ constructor(canvas, elementRegistry) {
2154
+ this.canvas = canvas;
2155
+ this.elementRegistry = elementRegistry;
2156
+ this.marked = [];
2157
+ }
2158
+ show(path) {
2159
+ this.clear();
2160
+ for (const id of path.taken) this.mark(id, TAKEN_MARKER);
2161
+ for (const id of path.skipped) this.mark(id, SKIPPED_MARKER);
2162
+ for (const [gatewayId, decision] of Object.entries(path.decisions)) {
2163
+ if (decision.stuckReason) this.mark(gatewayId, STUCK_MARKER);
2164
+ }
2165
+ }
2166
+ clear() {
2167
+ for (const { element, marker } of this.marked) this.canvas.removeMarker(element, marker);
2168
+ this.marked = [];
2169
+ }
2170
+ mark(id, marker) {
2171
+ const element = this.elementRegistry.get(id);
2172
+ if (!element) return;
2173
+ for (const markedElement of [element, ...element.labels ?? []]) {
2174
+ this.canvas.addMarker(markedElement, marker);
2175
+ this.marked.push({ element: markedElement, marker });
2176
+ }
2177
+ }
2178
+ }
2179
+
2180
+ class PathSimulation {
2181
+ constructor(config, elementRegistry, canvas) {
2182
+ this.pathResolver = new PathResolver();
2183
+ this.engine = new EngineRegistry().resolve(config?.engine ?? "zeebe");
2184
+ this.pathGraphReader = new PathGraphReader(elementRegistry, this.engine);
2185
+ this.pathMarkers = new PathMarkers(canvas, elementRegistry);
2186
+ }
2187
+ getEngine() {
2188
+ return this.engine;
2189
+ }
2190
+ simulate(variables, options = {}) {
2191
+ const graph = this.pathGraphReader.read(options.measures ?? []);
2192
+ const path = this.pathResolver.resolve(graph, (expression) => this.engine.evaluate(expression, variables));
2193
+ this.pathMarkers.show(path);
2194
+ return path;
2195
+ }
2196
+ clear() {
2197
+ this.pathMarkers.clear();
2198
+ }
2199
+ }
2200
+ PathSimulation.$inject = ["config.dataSimulation", "elementRegistry", "canvas"];
2201
+
2202
+ const PathSimulationModule = {
2203
+ __init__: [],
2204
+ pathSimulation: ["type", PathSimulation]
2205
+ };
2059
2206
  const DataSimulationModule = {
2207
+ __depends__: [PathSimulationModule],
2060
2208
  __init__: [
2061
2209
  "dataSimulation",
2062
2210
  "dataSimulationOverlays",
@@ -2078,5 +2226,5 @@ const DataSimulationModule = {
2078
2226
  dataContextPads: ["type", DataContextPads]
2079
2227
  };
2080
2228
 
2081
- export { Camunda7Engine, DataSimulationStore, EngineRegistry, GatewayRouter, ScenarioError, ScenarioParser, SimpleStartFormRenderer, StartFieldCodec, ZeebeEngine, camunda7Engine, DataSimulationModule as default, zeebeEngine };
2229
+ export { Camunda7Engine, DataSimulationModule, DataSimulationStore, EngineRegistry, GatewayRouter, PathSimulationModule, ScenarioError, ScenarioParser, SimpleStartFormRenderer, StartFieldCodec, ZeebeEngine, camunda7Engine, DataSimulationModule as default, zeebeEngine };
2082
2230
  //# sourceMappingURL=index.js.map