@emaarco/bpmn-js-data-simulation 0.7.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/dist/index.js CHANGED
@@ -2469,6 +2469,7 @@ const NICE_STEPS = [1, 2, 5, 10];
2469
2469
  const RANGE_STEPS = 100;
2470
2470
  const NUMBER_LITERAL = /(?<![\w.])\d+(?:\.\d+)?/g;
2471
2471
  const COMPARISON = String.raw`(?:<=|>=|==|!=|<|>|=|\b(?:lt|gt|le|ge|eq|ne)\b)`;
2472
+ const RELATIONAL = String.raw`(?:<=|>=|<|>|\b(?:lt|gt|le|ge)\b)`;
2472
2473
  const EQUALITY = String.raw`(?:==|!=|=|\b(?:eq|ne)\b)`;
2473
2474
  const BOOLEAN_LEFT = String.raw`(?:^|(?<![\w$.])\(|\bnot\s*\(|!|&&|\|\||\b(?:and|or|not)\b)`;
2474
2475
  const BOOLEAN_RIGHT = String.raw`(?=$|\)|&&|\|\||\b(?:and|or)\b)`;
@@ -2477,24 +2478,28 @@ class PathVariableDeriver {
2477
2478
  const names = [...new Set(conditions.flatMap((condition) => condition.variableNames))];
2478
2479
  return names.map((name) => {
2479
2480
  const conditionsReadingName = conditions.filter((condition) => condition.variableNames.includes(name));
2480
- return this.variableFor(name, values[name], conditionsReadingName, rangeOverrides[name] ?? {});
2481
+ return this.variableFor(name, values, conditionsReadingName, rangeOverrides[name] ?? {});
2481
2482
  });
2482
2483
  }
2483
- variableFor(name, value, conditionsReadingName, rangeOverride) {
2484
+ variableFor(name, values, conditionsReadingName, rangeOverride) {
2485
+ const value = values[name];
2484
2486
  const type = value === void 0 ? this.typeFromConditions(name, conditionsReadingName) : typeof value;
2485
2487
  if (type === "boolean") return { name, type: "boolean" };
2486
2488
  if (type === "number") {
2487
- const comparedNumbers = conditionsReadingName.flatMap((condition) => this.numberLiterals(condition.expression));
2489
+ const comparedNumbers = conditionsReadingName.flatMap((condition) => [
2490
+ ...this.numberLiterals(condition.expression),
2491
+ ...this.numbersOfOtherVariables(name, condition, values)
2492
+ ]);
2488
2493
  return { name, type: "number", range: this.rangeAround(Number(value ?? 0), comparedNumbers, rangeOverride) };
2489
2494
  }
2490
2495
  if (value === void 0 || typeof value === "string") return { name, type: "text" };
2491
2496
  return { name, type: "json" };
2492
2497
  }
2493
- // Without a value the conditions tell the type: compared with a number, or used as a condition of its own.
2498
+ // Without a value the conditions tell the type: compared with a number or by <, <=, > or >=, or used as a condition of its own.
2494
2499
  typeFromConditions(name, conditions) {
2495
2500
  const variable = String.raw`(?<![\w.$])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\w.(])`;
2496
2501
  const comparedWithNumber = new RegExp(
2497
- String.raw`${variable}\s*${COMPARISON}\s*-?\d|\d\s*${COMPARISON}\s*${variable}`
2502
+ String.raw`${variable}\s*${COMPARISON}\s*-?\d|\d\s*${COMPARISON}\s*${variable}|${variable}\s*${RELATIONAL}|${RELATIONAL}\s*${variable}`
2498
2503
  );
2499
2504
  const usedAsBoolean = new RegExp(
2500
2505
  String.raw`${BOOLEAN_LEFT}\s*${variable}\s*${BOOLEAN_RIGHT}|${variable}\s*${EQUALITY}\s*(?:true|false)\b|\b(?:true|false)\s*${EQUALITY}\s*${variable}`
@@ -2522,6 +2527,10 @@ class PathVariableDeriver {
2522
2527
  const magnitude = 10 ** Math.floor(Math.log10(value));
2523
2528
  return NICE_STEPS.find((step) => step * magnitude >= value) * magnitude;
2524
2529
  }
2530
+ // The numbers the other variables of the condition hold, e.g. a minimum score the variable is compared with.
2531
+ numbersOfOtherVariables(name, condition, values) {
2532
+ return condition.variableNames.filter((otherName) => otherName !== name).map((otherName) => values[otherName]).filter((otherValue) => typeof otherValue === "number");
2533
+ }
2525
2534
  numberLiterals(expression) {
2526
2535
  return (expression.match(NUMBER_LITERAL) ?? []).map(Number);
2527
2536
  }