@masterteam/components 0.0.93 → 0.0.94
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.
|
@@ -2097,14 +2097,62 @@ const CONDITION_FUNCTION_CATEGORIES = [
|
|
|
2097
2097
|
},
|
|
2098
2098
|
];
|
|
2099
2099
|
const CONDITION_OPERATORS = [
|
|
2100
|
-
{
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
{
|
|
2100
|
+
{
|
|
2101
|
+
symbol: '==',
|
|
2102
|
+
name: 'Equal',
|
|
2103
|
+
type: 'comparison',
|
|
2104
|
+
description: 'Equal to',
|
|
2105
|
+
precedence: 3,
|
|
2106
|
+
},
|
|
2107
|
+
{
|
|
2108
|
+
symbol: '!=',
|
|
2109
|
+
name: 'Not Equal',
|
|
2110
|
+
type: 'comparison',
|
|
2111
|
+
description: 'Not equal to',
|
|
2112
|
+
precedence: 3,
|
|
2113
|
+
},
|
|
2114
|
+
{
|
|
2115
|
+
symbol: '>',
|
|
2116
|
+
name: 'Greater Than',
|
|
2117
|
+
type: 'comparison',
|
|
2118
|
+
description: 'Greater than',
|
|
2119
|
+
precedence: 4,
|
|
2120
|
+
},
|
|
2121
|
+
{
|
|
2122
|
+
symbol: '<',
|
|
2123
|
+
name: 'Less Than',
|
|
2124
|
+
type: 'comparison',
|
|
2125
|
+
description: 'Less than',
|
|
2126
|
+
precedence: 4,
|
|
2127
|
+
},
|
|
2128
|
+
{
|
|
2129
|
+
symbol: '>=',
|
|
2130
|
+
name: 'Greater or Equal',
|
|
2131
|
+
type: 'comparison',
|
|
2132
|
+
description: 'Greater than or equal',
|
|
2133
|
+
precedence: 4,
|
|
2134
|
+
},
|
|
2135
|
+
{
|
|
2136
|
+
symbol: '<=',
|
|
2137
|
+
name: 'Less or Equal',
|
|
2138
|
+
type: 'comparison',
|
|
2139
|
+
description: 'Less than or equal',
|
|
2140
|
+
precedence: 4,
|
|
2141
|
+
},
|
|
2142
|
+
{
|
|
2143
|
+
symbol: '&&',
|
|
2144
|
+
name: 'And',
|
|
2145
|
+
type: 'logical',
|
|
2146
|
+
description: 'Logical AND',
|
|
2147
|
+
precedence: 2,
|
|
2148
|
+
},
|
|
2149
|
+
{
|
|
2150
|
+
symbol: '||',
|
|
2151
|
+
name: 'Or',
|
|
2152
|
+
type: 'logical',
|
|
2153
|
+
description: 'Logical OR',
|
|
2154
|
+
precedence: 1,
|
|
2155
|
+
},
|
|
2108
2156
|
];
|
|
2109
2157
|
const VALIDATION_FUNCTION_CATEGORIES = [
|
|
2110
2158
|
{
|
|
@@ -2323,18 +2371,90 @@ const VALIDATION_FUNCTION_CATEGORIES = [
|
|
|
2323
2371
|
},
|
|
2324
2372
|
];
|
|
2325
2373
|
const VALIDATION_OPERATORS = [
|
|
2326
|
-
{
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
{
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2374
|
+
{
|
|
2375
|
+
symbol: '+',
|
|
2376
|
+
name: 'Add',
|
|
2377
|
+
type: 'arithmetic',
|
|
2378
|
+
description: 'Addition',
|
|
2379
|
+
precedence: 4,
|
|
2380
|
+
},
|
|
2381
|
+
{
|
|
2382
|
+
symbol: '-',
|
|
2383
|
+
name: 'Subtract',
|
|
2384
|
+
type: 'arithmetic',
|
|
2385
|
+
description: 'Subtraction',
|
|
2386
|
+
precedence: 4,
|
|
2387
|
+
},
|
|
2388
|
+
{
|
|
2389
|
+
symbol: '*',
|
|
2390
|
+
name: 'Multiply',
|
|
2391
|
+
type: 'arithmetic',
|
|
2392
|
+
description: 'Multiplication',
|
|
2393
|
+
precedence: 5,
|
|
2394
|
+
},
|
|
2395
|
+
{
|
|
2396
|
+
symbol: '/',
|
|
2397
|
+
name: 'Divide',
|
|
2398
|
+
type: 'arithmetic',
|
|
2399
|
+
description: 'Division',
|
|
2400
|
+
precedence: 5,
|
|
2401
|
+
},
|
|
2402
|
+
{
|
|
2403
|
+
symbol: '==',
|
|
2404
|
+
name: 'Equal',
|
|
2405
|
+
type: 'comparison',
|
|
2406
|
+
description: 'Equal to',
|
|
2407
|
+
precedence: 3,
|
|
2408
|
+
},
|
|
2409
|
+
{
|
|
2410
|
+
symbol: '!=',
|
|
2411
|
+
name: 'Not Equal',
|
|
2412
|
+
type: 'comparison',
|
|
2413
|
+
description: 'Not equal to',
|
|
2414
|
+
precedence: 3,
|
|
2415
|
+
},
|
|
2416
|
+
{
|
|
2417
|
+
symbol: '>',
|
|
2418
|
+
name: 'Greater Than',
|
|
2419
|
+
type: 'comparison',
|
|
2420
|
+
description: 'Greater than',
|
|
2421
|
+
precedence: 3,
|
|
2422
|
+
},
|
|
2423
|
+
{
|
|
2424
|
+
symbol: '<',
|
|
2425
|
+
name: 'Less Than',
|
|
2426
|
+
type: 'comparison',
|
|
2427
|
+
description: 'Less than',
|
|
2428
|
+
precedence: 3,
|
|
2429
|
+
},
|
|
2430
|
+
{
|
|
2431
|
+
symbol: '>=',
|
|
2432
|
+
name: 'Greater or Equal',
|
|
2433
|
+
type: 'comparison',
|
|
2434
|
+
description: 'Greater than or equal',
|
|
2435
|
+
precedence: 3,
|
|
2436
|
+
},
|
|
2437
|
+
{
|
|
2438
|
+
symbol: '<=',
|
|
2439
|
+
name: 'Less or Equal',
|
|
2440
|
+
type: 'comparison',
|
|
2441
|
+
description: 'Less than or equal',
|
|
2442
|
+
precedence: 3,
|
|
2443
|
+
},
|
|
2444
|
+
{
|
|
2445
|
+
symbol: '&&',
|
|
2446
|
+
name: 'And',
|
|
2447
|
+
type: 'logical',
|
|
2448
|
+
description: 'Logical AND',
|
|
2449
|
+
precedence: 2,
|
|
2450
|
+
},
|
|
2451
|
+
{
|
|
2452
|
+
symbol: '||',
|
|
2453
|
+
name: 'Or',
|
|
2454
|
+
type: 'logical',
|
|
2455
|
+
description: 'Logical OR',
|
|
2456
|
+
precedence: 1,
|
|
2457
|
+
},
|
|
2338
2458
|
];
|
|
2339
2459
|
const CONDITION_RUNTIME_CATALOG = {
|
|
2340
2460
|
domain: 'condition',
|
|
@@ -2524,53 +2644,73 @@ class FormulaRuntimeEngine {
|
|
|
2524
2644
|
};
|
|
2525
2645
|
}
|
|
2526
2646
|
evaluateCondition(config, context) {
|
|
2647
|
+
let compiled;
|
|
2527
2648
|
try {
|
|
2528
|
-
|
|
2529
|
-
const rawValue = this.evaluateAst(compiled.ast, context.values);
|
|
2530
|
-
const action = this.resolveConditionAction(config.mode, compiled);
|
|
2531
|
-
const conditionValue = toBoolean(rawValue);
|
|
2532
|
-
switch (action) {
|
|
2533
|
-
case 'show':
|
|
2534
|
-
return {
|
|
2535
|
-
hidden: !conditionValue,
|
|
2536
|
-
dependencies: compiled.dependencies,
|
|
2537
|
-
errors: [],
|
|
2538
|
-
};
|
|
2539
|
-
case 'hide':
|
|
2540
|
-
return {
|
|
2541
|
-
hidden: conditionValue,
|
|
2542
|
-
dependencies: compiled.dependencies,
|
|
2543
|
-
errors: [],
|
|
2544
|
-
};
|
|
2545
|
-
case 'enable':
|
|
2546
|
-
return {
|
|
2547
|
-
disabled: !conditionValue,
|
|
2548
|
-
dependencies: compiled.dependencies,
|
|
2549
|
-
errors: [],
|
|
2550
|
-
};
|
|
2551
|
-
case 'disable':
|
|
2552
|
-
return {
|
|
2553
|
-
disabled: conditionValue,
|
|
2554
|
-
dependencies: compiled.dependencies,
|
|
2555
|
-
errors: [],
|
|
2556
|
-
};
|
|
2557
|
-
default:
|
|
2558
|
-
return {
|
|
2559
|
-
dependencies: compiled.dependencies,
|
|
2560
|
-
errors: [],
|
|
2561
|
-
};
|
|
2562
|
-
}
|
|
2649
|
+
compiled = this.getCompiledFormula(config.formulaTokens);
|
|
2563
2650
|
}
|
|
2564
2651
|
catch (error) {
|
|
2565
2652
|
return {
|
|
2566
2653
|
dependencies: [],
|
|
2567
|
-
errors: [
|
|
2654
|
+
errors: [createRuntimeError('FORMULA_PARSE_ERROR', error)],
|
|
2568
2655
|
};
|
|
2569
2656
|
}
|
|
2657
|
+
let rawValue;
|
|
2658
|
+
try {
|
|
2659
|
+
rawValue = this.evaluateAst(compiled.ast, context.values);
|
|
2660
|
+
}
|
|
2661
|
+
catch (error) {
|
|
2662
|
+
return {
|
|
2663
|
+
dependencies: compiled.dependencies,
|
|
2664
|
+
errors: [createRuntimeError('FORMULA_EVALUATION_ERROR', error)],
|
|
2665
|
+
};
|
|
2666
|
+
}
|
|
2667
|
+
const action = this.resolveConditionAction(config.mode, compiled);
|
|
2668
|
+
const conditionValue = toBoolean(rawValue);
|
|
2669
|
+
switch (action) {
|
|
2670
|
+
case 'show':
|
|
2671
|
+
return {
|
|
2672
|
+
hidden: !conditionValue,
|
|
2673
|
+
dependencies: compiled.dependencies,
|
|
2674
|
+
errors: [],
|
|
2675
|
+
};
|
|
2676
|
+
case 'hide':
|
|
2677
|
+
return {
|
|
2678
|
+
hidden: conditionValue,
|
|
2679
|
+
dependencies: compiled.dependencies,
|
|
2680
|
+
errors: [],
|
|
2681
|
+
};
|
|
2682
|
+
case 'enable':
|
|
2683
|
+
return {
|
|
2684
|
+
disabled: !conditionValue,
|
|
2685
|
+
dependencies: compiled.dependencies,
|
|
2686
|
+
errors: [],
|
|
2687
|
+
};
|
|
2688
|
+
case 'disable':
|
|
2689
|
+
return {
|
|
2690
|
+
disabled: conditionValue,
|
|
2691
|
+
dependencies: compiled.dependencies,
|
|
2692
|
+
errors: [],
|
|
2693
|
+
};
|
|
2694
|
+
default:
|
|
2695
|
+
return {
|
|
2696
|
+
dependencies: compiled.dependencies,
|
|
2697
|
+
errors: [],
|
|
2698
|
+
};
|
|
2699
|
+
}
|
|
2570
2700
|
}
|
|
2571
2701
|
evaluateValidation(rule, context) {
|
|
2702
|
+
let compiled;
|
|
2703
|
+
try {
|
|
2704
|
+
compiled = this.getCompiledFormula(rule.formulaTokens);
|
|
2705
|
+
}
|
|
2706
|
+
catch (error) {
|
|
2707
|
+
return {
|
|
2708
|
+
valid: false,
|
|
2709
|
+
dependencies: [],
|
|
2710
|
+
errors: [createRuntimeError('FORMULA_PARSE_ERROR', error)],
|
|
2711
|
+
};
|
|
2712
|
+
}
|
|
2572
2713
|
try {
|
|
2573
|
-
const compiled = this.getCompiledFormula(rule.formulaTokens);
|
|
2574
2714
|
const value = this.evaluateAst(compiled.ast, context.values);
|
|
2575
2715
|
return {
|
|
2576
2716
|
valid: toBoolean(value),
|
|
@@ -2581,11 +2721,53 @@ class FormulaRuntimeEngine {
|
|
|
2581
2721
|
catch (error) {
|
|
2582
2722
|
return {
|
|
2583
2723
|
valid: false,
|
|
2584
|
-
dependencies:
|
|
2585
|
-
errors: [
|
|
2724
|
+
dependencies: compiled.dependencies,
|
|
2725
|
+
errors: [createRuntimeError('FORMULA_EVALUATION_ERROR', error)],
|
|
2586
2726
|
};
|
|
2587
2727
|
}
|
|
2588
2728
|
}
|
|
2729
|
+
evaluateValidationRules(rules, context, options) {
|
|
2730
|
+
const errors = [];
|
|
2731
|
+
const warnings = [];
|
|
2732
|
+
const isDependencyActive = options?.isDependencyActive ?? (() => true);
|
|
2733
|
+
rules.forEach((rule) => {
|
|
2734
|
+
if (!rule.enabled)
|
|
2735
|
+
return;
|
|
2736
|
+
const result = this.evaluateValidation(rule, context);
|
|
2737
|
+
const hasInactiveDependency = result.dependencies.some((dependency) => !isDependencyActive(dependency));
|
|
2738
|
+
if (hasInactiveDependency)
|
|
2739
|
+
return;
|
|
2740
|
+
if (result.errors.length > 0) {
|
|
2741
|
+
const firstError = result.errors[0];
|
|
2742
|
+
const message = {
|
|
2743
|
+
code: firstError.code,
|
|
2744
|
+
severity: rule.severity,
|
|
2745
|
+
message: firstError.message,
|
|
2746
|
+
formulaText: rule.formulaText,
|
|
2747
|
+
ruleId: rule.id,
|
|
2748
|
+
};
|
|
2749
|
+
if (rule.severity === 'error')
|
|
2750
|
+
errors.push(message);
|
|
2751
|
+
else
|
|
2752
|
+
warnings.push(message);
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2755
|
+
if (!result.valid) {
|
|
2756
|
+
const message = {
|
|
2757
|
+
code: 'FORMULA_FALSE',
|
|
2758
|
+
severity: rule.severity,
|
|
2759
|
+
message: rule.message || 'Validation rule failed',
|
|
2760
|
+
formulaText: rule.formulaText,
|
|
2761
|
+
ruleId: rule.id,
|
|
2762
|
+
};
|
|
2763
|
+
if (rule.severity === 'error')
|
|
2764
|
+
errors.push(message);
|
|
2765
|
+
else
|
|
2766
|
+
warnings.push(message);
|
|
2767
|
+
}
|
|
2768
|
+
});
|
|
2769
|
+
return { errors, warnings };
|
|
2770
|
+
}
|
|
2589
2771
|
extractDependencies(formulaTokens) {
|
|
2590
2772
|
try {
|
|
2591
2773
|
return this.getCompiledFormula(formulaTokens).dependencies;
|
|
@@ -2903,6 +3085,12 @@ function toErrorMessage(error) {
|
|
|
2903
3085
|
return error.message;
|
|
2904
3086
|
return 'Formula evaluation failed';
|
|
2905
3087
|
}
|
|
3088
|
+
function createRuntimeError(code, error) {
|
|
3089
|
+
return {
|
|
3090
|
+
code,
|
|
3091
|
+
message: toErrorMessage(error),
|
|
3092
|
+
};
|
|
3093
|
+
}
|
|
2906
3094
|
|
|
2907
3095
|
// Formula components public API
|
|
2908
3096
|
|