@emaarco/bpmn-js-data-simulation 0.6.0 → 0.7.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.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![CI](https://github.com/emaarco/bpmn-js-data-simulation/actions/workflows/ci.yml/badge.svg)](https://github.com/emaarco/bpmn-js-data-simulation/actions/workflows/ci.yml)
5
5
  [![License: MIT](https://img.shields.io/github/license/emaarco/bpmn-js-data-simulation)](https://github.com/emaarco/bpmn-js-data-simulation/blob/main/LICENSE)
6
6
 
7
- [![A Bike Order process starts from a scenario, its gateways decide by the data and a card shows why "Credit OK?" took "yes"; then, in the demo's what-if panel, dragging the order total above 5,000 sends the path through the manual review](https://github.com/emaarco/bpmn-js-data-simulation/blob/main/docs/screenshots/simulation.gif)](https://emaarco.github.io/bpmn-js-data-simulation/)
7
+ [![A Bike Order process starts from a scenario, its gateways decide by the data and a card shows why "Credit OK?" took "yes"; a Fleet Order then assembles four bikes in parallel and delivers to two sites one after the other, with a tag counting the instances; finally, in the demo's what-if panel, dragging the order total above 5,000 sends the path through the manual review](https://github.com/emaarco/bpmn-js-data-simulation/blob/main/docs/screenshots/simulation.gif)](https://emaarco.github.io/bpmn-js-data-simulation/)
8
8
 
9
9
  **Show which path a process takes for real data, right in bpmn-js.**
10
10
 
@@ -1 +1 @@
1
- {"version":3,"file":"GatewayRouter.d.ts","sourceRoot":"","sources":["../../src/domain/GatewayRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA+B,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAErH,MAAM,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,UAAU,CAAA;AAElE,qBAAa,aAAa;IACxB,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,iBAAiB,EAAE,iBAAiB,GAAG,eAAe;IAoCzG,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe;IASjE,OAAO,CAAC,YAAY;IAqBpB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,KAAK;IAQb,OAAO,CAAC,QAAQ;CAIjB"}
1
+ {"version":3,"file":"GatewayRouter.d.ts","sourceRoot":"","sources":["../../src/domain/GatewayRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA+B,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAErH,MAAM,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,UAAU,CAAA;AAElE,qBAAa,aAAa;IACxB,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,iBAAiB,EAAE,iBAAiB,GAAG,eAAe;IAsCzG,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe;IASjE,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,KAAK;IAQb,OAAO,CAAC,QAAQ;CAIjB"}
@@ -2,8 +2,11 @@ import type { ConditionReads, NumberRange, PathVariable, Variables } from './mod
2
2
  export declare class PathVariableDeriver {
3
3
  derive(conditions: readonly ConditionReads[], values: Variables, rangeOverrides?: Readonly<Record<string, Partial<NumberRange>>>): PathVariable[];
4
4
  private variableFor;
5
+ private typeFromConditions;
6
+ private body;
5
7
  private rangeAround;
6
8
  private niceCeiling;
9
+ private numbersOfOtherVariables;
7
10
  private numberLiterals;
8
11
  }
9
12
  //# sourceMappingURL=PathVariableDeriver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PathVariableDeriver.d.ts","sourceRoot":"","sources":["../../src/domain/PathVariableDeriver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAMtF,qBAAa,mBAAmB;IAC9B,MAAM,CACJ,UAAU,EAAE,SAAS,cAAc,EAAE,EACrC,MAAM,EAAE,SAAS,EACjB,cAAc,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAM,GAClE,YAAY,EAAE;IAQjB,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,cAAc;CAGvB"}
1
+ {"version":3,"file":"PathVariableDeriver.d.ts","sourceRoot":"","sources":["../../src/domain/PathVariableDeriver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAYtF,qBAAa,mBAAmB;IAC9B,MAAM,CACJ,UAAU,EAAE,SAAS,cAAc,EAAE,EACrC,MAAM,EAAE,SAAS,EACjB,cAAc,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAM,GAClE,YAAY,EAAE;IAQjB,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,uBAAuB;IAO/B,OAAO,CAAC,cAAc;CAGvB"}
@@ -5,6 +5,7 @@ export type Evaluation = {
5
5
  } | {
6
6
  ok: false;
7
7
  reason: string;
8
+ missingVariables?: string[];
8
9
  };
9
10
  export interface Mapping {
10
11
  source: string;
@@ -24,11 +25,13 @@ export interface FlowEvaluation {
24
25
  outcome: FlowOutcome;
25
26
  value?: unknown;
26
27
  reason?: string;
28
+ missingVariables?: string[];
27
29
  }
28
30
  export interface RoutingDecision {
29
31
  flows: FlowEvaluation[];
30
32
  takenFlowIds: string[];
31
33
  stuckReason?: string;
34
+ missingVariables?: string[];
32
35
  refusedByEngine?: boolean;
33
36
  }
34
37
  export interface Scenario {
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/domain/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE/C,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAErF,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,WAAW,CAAA;AAEnD,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,CAAA;AAElD,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,CAAA;AAErE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAA;IAClB,OAAO,EAAE,WAAW,CAAA;IACpB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,cAAc,EAAE,CAAA;IACvB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,eAAe,CAAC,EAA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AAW,iBAAiB;IAChC,IAAI,EAAE,QAAQ,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,aAAa,GAAG,YAAY,GAAG,SAAS,CAAA;IAChD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAA"}
package/dist/index.cjs CHANGED
@@ -15,11 +15,13 @@ class GatewayRouter {
15
15
  }
16
16
  const failed = evaluations.find((evaluation) => evaluation.outcome === "error");
17
17
  if (failed) {
18
- return this.stuck(
18
+ const decision = this.stuck(
19
19
  evaluations,
20
20
  defaultFlow,
21
21
  `Condition of "${failed.flow.name ?? failed.flow.id}" failed: ${failed.reason}`
22
22
  );
23
+ const missingVariables = [...new Set(evaluations.flatMap((evaluation) => evaluation.missingVariables ?? []))];
24
+ return missingVariables.length ? { ...decision, missingVariables } : decision;
23
25
  }
24
26
  const taken = evaluations.filter((evaluation) => evaluation.outcome === "taken");
25
27
  if (taken.length) {
@@ -49,7 +51,8 @@ class GatewayRouter {
49
51
  }
50
52
  const evaluation = evaluateCondition(flow.expression);
51
53
  if (!evaluation.ok) {
52
- return { flow, outcome: "error", reason: evaluation.reason };
54
+ const { reason, missingVariables } = evaluation;
55
+ return missingVariables ? { flow, outcome: "error", reason, missingVariables } : { flow, outcome: "error", reason };
53
56
  }
54
57
  if (typeof evaluation.value !== "boolean") {
55
58
  return {
@@ -2469,23 +2472,54 @@ class PathResolver {
2469
2472
  const NICE_STEPS = [1, 2, 5, 10];
2470
2473
  const RANGE_STEPS = 100;
2471
2474
  const NUMBER_LITERAL = /(?<![\w.])\d+(?:\.\d+)?/g;
2475
+ const COMPARISON = String.raw`(?:<=|>=|==|!=|<|>|=|\b(?:lt|gt|le|ge|eq|ne)\b)`;
2476
+ const RELATIONAL = String.raw`(?:<=|>=|<|>|\b(?:lt|gt|le|ge)\b)`;
2477
+ const EQUALITY = String.raw`(?:==|!=|=|\b(?:eq|ne)\b)`;
2478
+ const BOOLEAN_LEFT = String.raw`(?:^|(?<![\w$.])\(|\bnot\s*\(|!|&&|\|\||\b(?:and|or|not)\b)`;
2479
+ const BOOLEAN_RIGHT = String.raw`(?=$|\)|&&|\|\||\b(?:and|or)\b)`;
2472
2480
  class PathVariableDeriver {
2473
2481
  derive(conditions, values, rangeOverrides = {}) {
2474
2482
  const names = [...new Set(conditions.flatMap((condition) => condition.variableNames))];
2475
2483
  return names.map((name) => {
2476
2484
  const conditionsReadingName = conditions.filter((condition) => condition.variableNames.includes(name));
2477
- return this.variableFor(name, values[name], conditionsReadingName, rangeOverrides[name] ?? {});
2485
+ return this.variableFor(name, values, conditionsReadingName, rangeOverrides[name] ?? {});
2478
2486
  });
2479
2487
  }
2480
- variableFor(name, value, conditionsReadingName, rangeOverride) {
2481
- if (typeof value === "boolean") return { name, type: "boolean" };
2482
- if (typeof value === "number") {
2483
- const comparedNumbers = conditionsReadingName.flatMap((condition) => this.numberLiterals(condition.expression));
2484
- return { name, type: "number", range: this.rangeAround(value, comparedNumbers, rangeOverride) };
2488
+ variableFor(name, values, conditionsReadingName, rangeOverride) {
2489
+ const value = values[name];
2490
+ const type = value === void 0 ? this.typeFromConditions(name, conditionsReadingName) : typeof value;
2491
+ if (type === "boolean") return { name, type: "boolean" };
2492
+ if (type === "number") {
2493
+ const comparedNumbers = conditionsReadingName.flatMap((condition) => [
2494
+ ...this.numberLiterals(condition.expression),
2495
+ ...this.numbersOfOtherVariables(name, condition, values)
2496
+ ]);
2497
+ return { name, type: "number", range: this.rangeAround(Number(value ?? 0), comparedNumbers, rangeOverride) };
2485
2498
  }
2486
2499
  if (value === void 0 || typeof value === "string") return { name, type: "text" };
2487
2500
  return { name, type: "json" };
2488
2501
  }
2502
+ // Without a value the conditions tell the type: compared with a number or by <, <=, > or >=, or used as a condition of its own.
2503
+ typeFromConditions(name, conditions) {
2504
+ const variable = String.raw`(?<![\w.$])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\w.(])`;
2505
+ const comparedWithNumber = new RegExp(
2506
+ String.raw`${variable}\s*${COMPARISON}\s*-?\d|\d\s*${COMPARISON}\s*${variable}|${variable}\s*${RELATIONAL}|${RELATIONAL}\s*${variable}`
2507
+ );
2508
+ const usedAsBoolean = new RegExp(
2509
+ String.raw`${BOOLEAN_LEFT}\s*${variable}\s*${BOOLEAN_RIGHT}|${variable}\s*${EQUALITY}\s*(?:true|false)\b|\b(?:true|false)\s*${EQUALITY}\s*${variable}`
2510
+ );
2511
+ const bodies = conditions.map((condition) => this.body(condition.expression));
2512
+ if (bodies.some((body) => comparedWithNumber.test(body))) return "number";
2513
+ if (bodies.some((body) => usedAsBoolean.test(body))) return "boolean";
2514
+ return void 0;
2515
+ }
2516
+ // The expression without its FEEL `=` or its JUEL `${…}`.
2517
+ body(expression) {
2518
+ const trimmed = expression.trim();
2519
+ const juel = /^\$\{([\s\S]*)\}$/.exec(trimmed);
2520
+ if (juel) return juel[1].trim();
2521
+ return trimmed.replace(/^=/, "").trim();
2522
+ }
2489
2523
  // The value itself is not doubled: a slider dragged to the end then keeps its range when derived again.
2490
2524
  rangeAround(value, comparedNumbers, override) {
2491
2525
  const min = override.min ?? 0;
@@ -2497,6 +2531,10 @@ class PathVariableDeriver {
2497
2531
  const magnitude = 10 ** Math.floor(Math.log10(value));
2498
2532
  return NICE_STEPS.find((step) => step * magnitude >= value) * magnitude;
2499
2533
  }
2534
+ // The numbers the other variables of the condition hold, e.g. a minimum score the variable is compared with.
2535
+ numbersOfOtherVariables(name, condition, values) {
2536
+ return condition.variableNames.filter((otherName) => otherName !== name).map((otherName) => values[otherName]).filter((otherValue) => typeof otherValue === "number");
2537
+ }
2500
2538
  numberLiterals(expression) {
2501
2539
  return (expression.match(NUMBER_LITERAL) ?? []).map(Number);
2502
2540
  }
@@ -2569,7 +2607,7 @@ class PathMarkers {
2569
2607
  for (const id of path.taken) this.mark(id, TAKEN_MARKER);
2570
2608
  for (const id of path.skipped) this.mark(id, SKIPPED_MARKER);
2571
2609
  for (const [gatewayId, decision] of Object.entries(path.decisions)) {
2572
- if (decision.stuckReason) this.mark(gatewayId, STUCK_MARKER);
2610
+ if (decision.stuckReason && !decision.missingVariables) this.mark(gatewayId, STUCK_MARKER);
2573
2611
  }
2574
2612
  }
2575
2613
  clear() {
@@ -2621,7 +2659,7 @@ class PathSimulation {
2621
2659
  }
2622
2660
  simulate(variables, options = {}) {
2623
2661
  const graph = this.pathGraphReader.read(options.measures ?? []);
2624
- const path = this.pathResolver.resolve(graph, (expression) => this.engine.evaluate(expression, variables));
2662
+ const path = this.pathResolver.resolve(graph, (expression) => this.evaluate(expression, variables));
2625
2663
  this.pathMarkers.show(path);
2626
2664
  return path;
2627
2665
  }
@@ -2634,6 +2672,13 @@ class PathSimulation {
2634
2672
  clear() {
2635
2673
  this.pathMarkers.clear();
2636
2674
  }
2675
+ // A failed condition names the variables it reads that are not set: the gateway then waits for data.
2676
+ evaluate(expression, variables) {
2677
+ const evaluation = this.engine.evaluate(expression, variables);
2678
+ if (evaluation.ok) return evaluation;
2679
+ const missingVariables = this.engine.readVariableNames(expression).filter((name) => variables[name] === void 0);
2680
+ return missingVariables.length ? { ...evaluation, missingVariables } : evaluation;
2681
+ }
2637
2682
  evaluableConditions() {
2638
2683
  return this.pathGraphReader.read([]).nodes.flatMap((node) => node.outgoing.map((flow) => flow.expression)).filter((expression) => expression !== void 0 && this.engine.canEvaluate(expression)).map((expression) => ({ expression, variableNames: this.engine.readVariableNames(expression) }));
2639
2684
  }