@emaarco/bpmn-js-data-simulation 0.6.0 → 0.7.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/README.md +1 -1
- package/dist/domain/GatewayRouter.d.ts.map +1 -1
- package/dist/domain/PathVariableDeriver.d.ts +2 -0
- package/dist/domain/PathVariableDeriver.d.ts.map +1 -1
- package/dist/domain/model.d.ts +3 -0
- package/dist/domain/model.d.ts.map +1 -1
- package/dist/index.cjs +43 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/dist/integration/PathSimulation.d.ts +1 -0
- package/dist/integration/PathSimulation.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://github.com/emaarco/bpmn-js-data-simulation/actions/workflows/ci.yml)
|
|
5
5
|
[](https://github.com/emaarco/bpmn-js-data-simulation/blob/main/LICENSE)
|
|
6
6
|
|
|
7
|
-
[](https://emaarco.github.io/bpmn-js-data-simulation/)
|
|
7
|
+
[](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;
|
|
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,6 +2,8 @@ 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;
|
|
7
9
|
private numberLiterals;
|
|
@@ -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;
|
|
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;AAWtF,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;IAiBnB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,cAAc;CAGvB"}
|
package/dist/domain/model.d.ts
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/domain/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GA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A;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
|
-
|
|
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
|
-
|
|
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,6 +2472,10 @@ 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 EQUALITY = String.raw`(?:==|!=|=|\b(?:eq|ne)\b)`;
|
|
2477
|
+
const BOOLEAN_LEFT = String.raw`(?:^|(?<![\w$.])\(|\bnot\s*\(|!|&&|\|\||\b(?:and|or|not)\b)`;
|
|
2478
|
+
const BOOLEAN_RIGHT = String.raw`(?=$|\)|&&|\|\||\b(?:and|or)\b)`;
|
|
2472
2479
|
class PathVariableDeriver {
|
|
2473
2480
|
derive(conditions, values, rangeOverrides = {}) {
|
|
2474
2481
|
const names = [...new Set(conditions.flatMap((condition) => condition.variableNames))];
|
|
@@ -2478,14 +2485,36 @@ class PathVariableDeriver {
|
|
|
2478
2485
|
});
|
|
2479
2486
|
}
|
|
2480
2487
|
variableFor(name, value, conditionsReadingName, rangeOverride) {
|
|
2481
|
-
|
|
2482
|
-
if (
|
|
2488
|
+
const type = value === void 0 ? this.typeFromConditions(name, conditionsReadingName) : typeof value;
|
|
2489
|
+
if (type === "boolean") return { name, type: "boolean" };
|
|
2490
|
+
if (type === "number") {
|
|
2483
2491
|
const comparedNumbers = conditionsReadingName.flatMap((condition) => this.numberLiterals(condition.expression));
|
|
2484
|
-
return { name, type: "number", range: this.rangeAround(value, comparedNumbers, rangeOverride) };
|
|
2492
|
+
return { name, type: "number", range: this.rangeAround(Number(value ?? 0), comparedNumbers, rangeOverride) };
|
|
2485
2493
|
}
|
|
2486
2494
|
if (value === void 0 || typeof value === "string") return { name, type: "text" };
|
|
2487
2495
|
return { name, type: "json" };
|
|
2488
2496
|
}
|
|
2497
|
+
// Without a value the conditions tell the type: compared with a number, or used as a condition of its own.
|
|
2498
|
+
typeFromConditions(name, conditions) {
|
|
2499
|
+
const variable = String.raw`(?<![\w.$])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\w.(])`;
|
|
2500
|
+
const comparedWithNumber = new RegExp(
|
|
2501
|
+
String.raw`${variable}\s*${COMPARISON}\s*-?\d|\d\s*${COMPARISON}\s*${variable}`
|
|
2502
|
+
);
|
|
2503
|
+
const usedAsBoolean = new RegExp(
|
|
2504
|
+
String.raw`${BOOLEAN_LEFT}\s*${variable}\s*${BOOLEAN_RIGHT}|${variable}\s*${EQUALITY}\s*(?:true|false)\b|\b(?:true|false)\s*${EQUALITY}\s*${variable}`
|
|
2505
|
+
);
|
|
2506
|
+
const bodies = conditions.map((condition) => this.body(condition.expression));
|
|
2507
|
+
if (bodies.some((body) => comparedWithNumber.test(body))) return "number";
|
|
2508
|
+
if (bodies.some((body) => usedAsBoolean.test(body))) return "boolean";
|
|
2509
|
+
return void 0;
|
|
2510
|
+
}
|
|
2511
|
+
// The expression without its FEEL `=` or its JUEL `${…}`.
|
|
2512
|
+
body(expression) {
|
|
2513
|
+
const trimmed = expression.trim();
|
|
2514
|
+
const juel = /^\$\{([\s\S]*)\}$/.exec(trimmed);
|
|
2515
|
+
if (juel) return juel[1].trim();
|
|
2516
|
+
return trimmed.replace(/^=/, "").trim();
|
|
2517
|
+
}
|
|
2489
2518
|
// The value itself is not doubled: a slider dragged to the end then keeps its range when derived again.
|
|
2490
2519
|
rangeAround(value, comparedNumbers, override) {
|
|
2491
2520
|
const min = override.min ?? 0;
|
|
@@ -2569,7 +2598,7 @@ class PathMarkers {
|
|
|
2569
2598
|
for (const id of path.taken) this.mark(id, TAKEN_MARKER);
|
|
2570
2599
|
for (const id of path.skipped) this.mark(id, SKIPPED_MARKER);
|
|
2571
2600
|
for (const [gatewayId, decision] of Object.entries(path.decisions)) {
|
|
2572
|
-
if (decision.stuckReason) this.mark(gatewayId, STUCK_MARKER);
|
|
2601
|
+
if (decision.stuckReason && !decision.missingVariables) this.mark(gatewayId, STUCK_MARKER);
|
|
2573
2602
|
}
|
|
2574
2603
|
}
|
|
2575
2604
|
clear() {
|
|
@@ -2621,7 +2650,7 @@ class PathSimulation {
|
|
|
2621
2650
|
}
|
|
2622
2651
|
simulate(variables, options = {}) {
|
|
2623
2652
|
const graph = this.pathGraphReader.read(options.measures ?? []);
|
|
2624
|
-
const path = this.pathResolver.resolve(graph, (expression) => this.
|
|
2653
|
+
const path = this.pathResolver.resolve(graph, (expression) => this.evaluate(expression, variables));
|
|
2625
2654
|
this.pathMarkers.show(path);
|
|
2626
2655
|
return path;
|
|
2627
2656
|
}
|
|
@@ -2634,6 +2663,13 @@ class PathSimulation {
|
|
|
2634
2663
|
clear() {
|
|
2635
2664
|
this.pathMarkers.clear();
|
|
2636
2665
|
}
|
|
2666
|
+
// A failed condition names the variables it reads that are not set: the gateway then waits for data.
|
|
2667
|
+
evaluate(expression, variables) {
|
|
2668
|
+
const evaluation = this.engine.evaluate(expression, variables);
|
|
2669
|
+
if (evaluation.ok) return evaluation;
|
|
2670
|
+
const missingVariables = this.engine.readVariableNames(expression).filter((name) => variables[name] === void 0);
|
|
2671
|
+
return missingVariables.length ? { ...evaluation, missingVariables } : evaluation;
|
|
2672
|
+
}
|
|
2637
2673
|
evaluableConditions() {
|
|
2638
2674
|
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
2675
|
}
|