@orkestrel/reason 0.0.5 → 0.0.7
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/src/core/index.cjs +318 -8
- package/dist/src/core/index.d.cts +211 -2
- package/dist/src/core/index.d.ts +211 -2
- package/dist/src/core/index.js +308 -10
- package/package.json +12 -10
- package/dist/src/core/index.cjs.map +0 -1
- package/dist/src/core/index.js.map +0 -1
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1844,9 +1844,9 @@ export declare interface AggregatorOptions {
|
|
|
1844
1844
|
* findDuplicates([{ id: 'a' }, { id: 'b' }, { id: 'a' }, { id: 'a' }]) // ['a']
|
|
1845
1845
|
* ```
|
|
1846
1846
|
*/
|
|
1847
|
-
export declare function findDuplicates(items:
|
|
1847
|
+
export declare function findDuplicates(items: ReadonlyArray<{
|
|
1848
1848
|
readonly id: string;
|
|
1849
|
-
}
|
|
1849
|
+
}>): readonly string[];
|
|
1850
1850
|
|
|
1851
1851
|
/**
|
|
1852
1852
|
* The `formatField`-flattened overlay keys an array-path conclusion atom
|
|
@@ -2427,6 +2427,22 @@ export declare interface AggregatorOptions {
|
|
|
2427
2427
|
*/
|
|
2428
2428
|
export declare function isCheck(value: unknown): value is Check;
|
|
2429
2429
|
|
|
2430
|
+
/**
|
|
2431
|
+
* Determine whether a value is a {@link CheckResult}.
|
|
2432
|
+
*
|
|
2433
|
+
* @param value - The value to test
|
|
2434
|
+
* @returns `true` when every published check-result member is valid
|
|
2435
|
+
*
|
|
2436
|
+
* @example
|
|
2437
|
+
* ```ts
|
|
2438
|
+
* import { isCheckResult } from '@src/core'
|
|
2439
|
+
*
|
|
2440
|
+
* isCheckResult({ field: 'age', met: true, actual: 30 }) // true
|
|
2441
|
+
* isCheckResult({ field: 'age', met: 'yes', actual: 30 }) // false
|
|
2442
|
+
* ```
|
|
2443
|
+
*/
|
|
2444
|
+
export declare function isCheckResult(value: unknown): value is CheckResult;
|
|
2445
|
+
|
|
2430
2446
|
/**
|
|
2431
2447
|
* Determine whether a value is a {@link Comparison} literal.
|
|
2432
2448
|
*
|
|
@@ -2602,6 +2618,22 @@ export declare interface AggregatorOptions {
|
|
|
2602
2618
|
*/
|
|
2603
2619
|
export declare function isFactorRange(value: unknown): value is FactorRange;
|
|
2604
2620
|
|
|
2621
|
+
/**
|
|
2622
|
+
* Determine whether a value is a {@link FactorResult}.
|
|
2623
|
+
*
|
|
2624
|
+
* @param value - The value to test
|
|
2625
|
+
* @returns `true` when every published factor-result member is valid
|
|
2626
|
+
*
|
|
2627
|
+
* @example
|
|
2628
|
+
* ```ts
|
|
2629
|
+
* import { isFactorResult } from '@src/core'
|
|
2630
|
+
*
|
|
2631
|
+
* isFactorResult({ id: 'age', applied: true, value: 5 }) // true
|
|
2632
|
+
* isFactorResult({ id: 'age', applied: true, value: '5' }) // false
|
|
2633
|
+
* ```
|
|
2634
|
+
*/
|
|
2635
|
+
export declare function isFactorResult(value: unknown): value is FactorResult;
|
|
2636
|
+
|
|
2605
2637
|
/**
|
|
2606
2638
|
* Determine whether a value is a {@link FieldPath} — a single string key or an
|
|
2607
2639
|
* array of keys descending into nested objects.
|
|
@@ -2620,6 +2652,22 @@ export declare interface AggregatorOptions {
|
|
|
2620
2652
|
*/
|
|
2621
2653
|
export declare const isFieldPath: Guard<FieldPath>;
|
|
2622
2654
|
|
|
2655
|
+
/**
|
|
2656
|
+
* Determine whether a value is a {@link GroupResult}.
|
|
2657
|
+
*
|
|
2658
|
+
* @param value - The value to test
|
|
2659
|
+
* @returns `true` when every published group-result member is valid
|
|
2660
|
+
*
|
|
2661
|
+
* @example
|
|
2662
|
+
* ```ts
|
|
2663
|
+
* import { isGroupResult } from '@src/core'
|
|
2664
|
+
*
|
|
2665
|
+
* isGroupResult({ id: 'risk', applied: true, value: 5, factors: [] }) // true
|
|
2666
|
+
* isGroupResult({ id: 'risk', applied: true, value: 5 }) // false
|
|
2667
|
+
* ```
|
|
2668
|
+
*/
|
|
2669
|
+
export declare function isGroupResult(value: unknown): value is GroupResult;
|
|
2670
|
+
|
|
2623
2671
|
/**
|
|
2624
2672
|
* Determine whether a value is an {@link Inference} — premise patterns and a
|
|
2625
2673
|
* conclusion pattern.
|
|
@@ -2653,6 +2701,22 @@ export declare interface AggregatorOptions {
|
|
|
2653
2701
|
*/
|
|
2654
2702
|
export declare function isInferentialDefinition(value: unknown): value is InferentialDefinition;
|
|
2655
2703
|
|
|
2704
|
+
/**
|
|
2705
|
+
* Determine whether a value is an {@link InferentialResult}.
|
|
2706
|
+
*
|
|
2707
|
+
* @param value - The value to test
|
|
2708
|
+
* @returns `true` when every published inferential-result member is valid
|
|
2709
|
+
*
|
|
2710
|
+
* @example
|
|
2711
|
+
* ```ts
|
|
2712
|
+
* import { isInferentialResult } from '@src/core'
|
|
2713
|
+
*
|
|
2714
|
+
* isInferentialResult({ reasoning: 'inferential', derived: [], success: true, trace: [], errors: [] }) // true
|
|
2715
|
+
* isInferentialResult({ reasoning: 'inferential', derived: [null], success: true, trace: [], errors: [] }) // false
|
|
2716
|
+
* ```
|
|
2717
|
+
*/
|
|
2718
|
+
export declare function isInferentialResult(value: unknown): value is InferentialResult;
|
|
2719
|
+
|
|
2656
2720
|
/**
|
|
2657
2721
|
* Determine whether a value is a {@link LogicalDefinition}.
|
|
2658
2722
|
*
|
|
@@ -2685,6 +2749,22 @@ export declare interface AggregatorOptions {
|
|
|
2685
2749
|
*/
|
|
2686
2750
|
export declare const isLogicalOperator: Guard<LogicalOperator>;
|
|
2687
2751
|
|
|
2752
|
+
/**
|
|
2753
|
+
* Determine whether a value is a {@link LogicalResult}.
|
|
2754
|
+
*
|
|
2755
|
+
* @param value - The value to test
|
|
2756
|
+
* @returns `true` when every published logical-result member is valid
|
|
2757
|
+
*
|
|
2758
|
+
* @example
|
|
2759
|
+
* ```ts
|
|
2760
|
+
* import { isLogicalResult } from '@src/core'
|
|
2761
|
+
*
|
|
2762
|
+
* isLogicalResult({ reasoning: 'logical', conclusion: false, rules: [], count: 0, success: true, trace: [], errors: [] }) // true
|
|
2763
|
+
* isLogicalResult({ reasoning: 'logical', rules: [] }) // false
|
|
2764
|
+
* ```
|
|
2765
|
+
*/
|
|
2766
|
+
export declare function isLogicalResult(value: unknown): value is LogicalResult;
|
|
2767
|
+
|
|
2688
2768
|
/**
|
|
2689
2769
|
* Determine whether a value is a {@link MathOperation} literal.
|
|
2690
2770
|
*
|
|
@@ -2718,6 +2798,30 @@ export declare interface AggregatorOptions {
|
|
|
2718
2798
|
*/
|
|
2719
2799
|
export declare const isNumberRecord: Guard<Readonly<Record<string, number>>>;
|
|
2720
2800
|
|
|
2801
|
+
/**
|
|
2802
|
+
* Determine whether a value is a depth-bounded, acyclic {@link ProofNode} tree.
|
|
2803
|
+
*
|
|
2804
|
+
* @remarks
|
|
2805
|
+
* Traversal is iterative and reuses `GUARD_DEPTH_LIMIT`. Active ancestors refuse cycles, and a
|
|
2806
|
+
* settled-depth record prevents repeated validation of shared subtrees while keeping the bound
|
|
2807
|
+
* exact: a node revisited no deeper than its validated depth is skipped, and one reached deeper
|
|
2808
|
+
* is walked again. The traversal accepts an acyclic graph only when every reachable node is
|
|
2809
|
+
* valid and every root-to-node path contains at most `GUARD_DEPTH_LIMIT` nodes; shared aliases
|
|
2810
|
+
* and sibling order do not affect the verdict.
|
|
2811
|
+
*
|
|
2812
|
+
* @param value - The value to test
|
|
2813
|
+
* @returns `true` when every proof node is valid within the runtime guard bound
|
|
2814
|
+
*
|
|
2815
|
+
* @example
|
|
2816
|
+
* ```ts
|
|
2817
|
+
* import { isProofNode } from '@src/core'
|
|
2818
|
+
*
|
|
2819
|
+
* isProofNode({ fact: 'bird', depth: 0, children: [{ fact: 'feathers', depth: 1 }] }) // true
|
|
2820
|
+
* isProofNode({ fact: 'bird', children: [] }) // false
|
|
2821
|
+
* ```
|
|
2822
|
+
*/
|
|
2823
|
+
export declare function isProofNode(value: unknown): value is ProofNode;
|
|
2824
|
+
|
|
2721
2825
|
/**
|
|
2722
2826
|
* Determine whether a value is a {@link QuantitativeDefinition}.
|
|
2723
2827
|
*
|
|
@@ -2734,6 +2838,22 @@ export declare interface AggregatorOptions {
|
|
|
2734
2838
|
*/
|
|
2735
2839
|
export declare function isQuantitativeDefinition(value: unknown): value is QuantitativeDefinition;
|
|
2736
2840
|
|
|
2841
|
+
/**
|
|
2842
|
+
* Determine whether a value is a {@link QuantitativeResult}.
|
|
2843
|
+
*
|
|
2844
|
+
* @param value - The value to test
|
|
2845
|
+
* @returns `true` when every published quantitative-result member is valid
|
|
2846
|
+
*
|
|
2847
|
+
* @example
|
|
2848
|
+
* ```ts
|
|
2849
|
+
* import { isQuantitativeResult } from '@src/core'
|
|
2850
|
+
*
|
|
2851
|
+
* isQuantitativeResult({ reasoning: 'quantitative', value: 0, groups: [], count: 0, success: true, trace: [], errors: [] }) // true
|
|
2852
|
+
* isQuantitativeResult({ reasoning: 'quantitative' }) // false
|
|
2853
|
+
* ```
|
|
2854
|
+
*/
|
|
2855
|
+
export declare function isQuantitativeResult(value: unknown): value is QuantitativeResult;
|
|
2856
|
+
|
|
2737
2857
|
/**
|
|
2738
2858
|
* Narrow an unknown caught value to a {@link ReasonError}.
|
|
2739
2859
|
*
|
|
@@ -2767,6 +2887,58 @@ export declare interface AggregatorOptions {
|
|
|
2767
2887
|
*/
|
|
2768
2888
|
export declare const isReasoning: Guard<Reasoning>;
|
|
2769
2889
|
|
|
2890
|
+
/**
|
|
2891
|
+
* Determine whether a value is any {@link ReasonResult} arm.
|
|
2892
|
+
*
|
|
2893
|
+
* @param value - The value to test
|
|
2894
|
+
* @returns `true` when one complete reasoning-result guard accepts the value
|
|
2895
|
+
*
|
|
2896
|
+
* @example
|
|
2897
|
+
* ```ts
|
|
2898
|
+
* import { isReasonResult } from '@src/core'
|
|
2899
|
+
*
|
|
2900
|
+
* isReasonResult({ reasoning: 'symbolic', solutions: {}, success: true, trace: [], errors: [] }) // true
|
|
2901
|
+
* isReasonResult({ reasoning: 'unknown' }) // false
|
|
2902
|
+
* ```
|
|
2903
|
+
*/
|
|
2904
|
+
export declare function isReasonResult(value: unknown): value is ReasonResult;
|
|
2905
|
+
|
|
2906
|
+
/**
|
|
2907
|
+
* Determine whether a value is a {@link ReasonValidationResult}.
|
|
2908
|
+
*
|
|
2909
|
+
* @param value - The value to test
|
|
2910
|
+
* @returns `true` when every published validation-result member is valid
|
|
2911
|
+
*
|
|
2912
|
+
* @example
|
|
2913
|
+
* ```ts
|
|
2914
|
+
* import { isReasonValidationResult } from '@src/core'
|
|
2915
|
+
*
|
|
2916
|
+
* isReasonValidationResult({ valid: true, errors: [], warnings: [] }) // true
|
|
2917
|
+
* isReasonValidationResult({ valid: true, errors: [] }) // false
|
|
2918
|
+
* ```
|
|
2919
|
+
*/
|
|
2920
|
+
export declare function isReasonValidationResult(value: unknown): value is ReasonValidationResult;
|
|
2921
|
+
|
|
2922
|
+
/**
|
|
2923
|
+
* Determine whether a value is a result-side {@link Fact}.
|
|
2924
|
+
*
|
|
2925
|
+
* @remarks
|
|
2926
|
+
* Unlike the exact input guard {@link isFact}, this guard accepts unknown
|
|
2927
|
+
* members, class instances, and every JavaScript `number` confidence.
|
|
2928
|
+
*
|
|
2929
|
+
* @param value - The value to test
|
|
2930
|
+
* @returns `true` when every published fact member is valid for a result
|
|
2931
|
+
*
|
|
2932
|
+
* @example
|
|
2933
|
+
* ```ts
|
|
2934
|
+
* import { isResultFact } from '@src/core'
|
|
2935
|
+
*
|
|
2936
|
+
* isResultFact({ id: 'f1', predicate: 'bird', terms: ['tweety'], note: 'derived' }) // true
|
|
2937
|
+
* isResultFact({ id: 'f1', predicate: 'bird' }) // false
|
|
2938
|
+
* ```
|
|
2939
|
+
*/
|
|
2940
|
+
export declare function isResultFact(value: unknown): value is Fact;
|
|
2941
|
+
|
|
2770
2942
|
/**
|
|
2771
2943
|
* Determine whether a value is a {@link Rule} — premises and a conclusion.
|
|
2772
2944
|
*
|
|
@@ -2783,6 +2955,22 @@ export declare interface AggregatorOptions {
|
|
|
2783
2955
|
*/
|
|
2784
2956
|
export declare function isRule(value: unknown): value is Rule;
|
|
2785
2957
|
|
|
2958
|
+
/**
|
|
2959
|
+
* Determine whether a value is a {@link RuleResult}.
|
|
2960
|
+
*
|
|
2961
|
+
* @param value - The value to test
|
|
2962
|
+
* @returns `true` when every published rule-result member is valid
|
|
2963
|
+
*
|
|
2964
|
+
* @example
|
|
2965
|
+
* ```ts
|
|
2966
|
+
* import { isRuleResult } from '@src/core'
|
|
2967
|
+
*
|
|
2968
|
+
* isRuleResult({ id: 'adult', applied: true, premises: [true], conclusion: true }) // true
|
|
2969
|
+
* isRuleResult({ id: 'adult', applied: true, premises: [1], conclusion: true }) // false
|
|
2970
|
+
* ```
|
|
2971
|
+
*/
|
|
2972
|
+
export declare function isRuleResult(value: unknown): value is RuleResult;
|
|
2973
|
+
|
|
2786
2974
|
/**
|
|
2787
2975
|
* Determine whether a value is a {@link Source} — any of the four factor
|
|
2788
2976
|
* sources, discriminated by `origin`.
|
|
@@ -2883,6 +3071,27 @@ export declare interface AggregatorOptions {
|
|
|
2883
3071
|
*/
|
|
2884
3072
|
export declare function isSymbolicExpression(value: unknown): value is SymbolicExpression;
|
|
2885
3073
|
|
|
3074
|
+
/**
|
|
3075
|
+
* Determine whether a value is a {@link SymbolicResult}.
|
|
3076
|
+
*
|
|
3077
|
+
* @remarks
|
|
3078
|
+
* `solutions` is checked across its OWN string-named members, enumerable or
|
|
3079
|
+
* not. Inherited members are deliberately unread: they belong to the
|
|
3080
|
+
* accepted-prototype property, not to the record this guard certifies.
|
|
3081
|
+
*
|
|
3082
|
+
* @param value - The value to test
|
|
3083
|
+
* @returns `true` when every published symbolic-result member is valid
|
|
3084
|
+
*
|
|
3085
|
+
* @example
|
|
3086
|
+
* ```ts
|
|
3087
|
+
* import { isSymbolicResult } from '@src/core'
|
|
3088
|
+
*
|
|
3089
|
+
* isSymbolicResult({ reasoning: 'symbolic', solutions: { x: 4 }, success: true, trace: [], errors: [] }) // true
|
|
3090
|
+
* isSymbolicResult({ reasoning: 'symbolic', solutions: { x: '4' }, success: true, trace: [], errors: [] }) // false
|
|
3091
|
+
* ```
|
|
3092
|
+
*/
|
|
3093
|
+
export declare function isSymbolicResult(value: unknown): value is SymbolicResult;
|
|
3094
|
+
|
|
2886
3095
|
/**
|
|
2887
3096
|
* Determine whether a value is a {@link Transform} — one math step.
|
|
2888
3097
|
*
|
package/dist/src/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrayOf, isArray, isBoolean, isFiniteNumber, isNumber, isObject, isRecord, isString, lazyOf, literalOf, notOf, orOf, parseJSONAs, parseNumber, parseNumberField, recordOf, resolveField, unionOf, whereOf } from "@orkestrel/contract";
|
|
1
|
+
import { GUARD_DEPTH_LIMIT, arrayOf, holds, isArray, isBoolean, isFiniteNumber, isNumber, isObject, isRecord, isString, lazyOf, literalOf, notOf, orOf, parseJSONAs, parseNumber, parseNumberField, readArrayEntries, recordOf, resolveField, unionOf, whereOf } from "@orkestrel/contract";
|
|
2
2
|
import { Emitter } from "@orkestrel/emitter";
|
|
3
3
|
//#region src/core/constants.ts
|
|
4
4
|
/**
|
|
@@ -769,6 +769,303 @@ function isDefinition(value) {
|
|
|
769
769
|
return isQuantitativeDefinition(value) || isLogicalDefinition(value) || isSymbolicDefinition(value) || isInferentialDefinition(value);
|
|
770
770
|
}
|
|
771
771
|
/**
|
|
772
|
+
* Determine whether a value is a result-side {@link Fact}.
|
|
773
|
+
*
|
|
774
|
+
* @remarks
|
|
775
|
+
* Unlike the exact input guard {@link isFact}, this guard accepts unknown
|
|
776
|
+
* members, class instances, and every JavaScript `number` confidence.
|
|
777
|
+
*
|
|
778
|
+
* @param value - The value to test
|
|
779
|
+
* @returns `true` when every published fact member is valid for a result
|
|
780
|
+
*
|
|
781
|
+
* @example
|
|
782
|
+
* ```ts
|
|
783
|
+
* import { isResultFact } from '@src/core'
|
|
784
|
+
*
|
|
785
|
+
* isResultFact({ id: 'f1', predicate: 'bird', terms: ['tweety'], note: 'derived' }) // true
|
|
786
|
+
* isResultFact({ id: 'f1', predicate: 'bird' }) // false
|
|
787
|
+
* ```
|
|
788
|
+
*/
|
|
789
|
+
function isResultFact(value) {
|
|
790
|
+
return whereOf(isObject, (result) => {
|
|
791
|
+
if (isArray(result)) return false;
|
|
792
|
+
const confidence = Reflect.get(result, "confidence");
|
|
793
|
+
return isString(Reflect.get(result, "id")) && isString(Reflect.get(result, "predicate")) && isArray(Reflect.get(result, "terms")) && (confidence === void 0 || isNumber(confidence));
|
|
794
|
+
})(value);
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Determine whether a value is a {@link CheckResult}.
|
|
798
|
+
*
|
|
799
|
+
* @param value - The value to test
|
|
800
|
+
* @returns `true` when every published check-result member is valid
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* ```ts
|
|
804
|
+
* import { isCheckResult } from '@src/core'
|
|
805
|
+
*
|
|
806
|
+
* isCheckResult({ field: 'age', met: true, actual: 30 }) // true
|
|
807
|
+
* isCheckResult({ field: 'age', met: 'yes', actual: 30 }) // false
|
|
808
|
+
* ```
|
|
809
|
+
*/
|
|
810
|
+
function isCheckResult(value) {
|
|
811
|
+
return whereOf(isObject, (result) => {
|
|
812
|
+
if (isArray(result)) return false;
|
|
813
|
+
const error = Reflect.get(result, "error");
|
|
814
|
+
return isFieldPath(Reflect.get(result, "field")) && isBoolean(Reflect.get(result, "met")) && Reflect.has(result, "actual") && (error === void 0 || isString(error));
|
|
815
|
+
})(value);
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Determine whether a value is a {@link FactorResult}.
|
|
819
|
+
*
|
|
820
|
+
* @param value - The value to test
|
|
821
|
+
* @returns `true` when every published factor-result member is valid
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* ```ts
|
|
825
|
+
* import { isFactorResult } from '@src/core'
|
|
826
|
+
*
|
|
827
|
+
* isFactorResult({ id: 'age', applied: true, value: 5 }) // true
|
|
828
|
+
* isFactorResult({ id: 'age', applied: true, value: '5' }) // false
|
|
829
|
+
* ```
|
|
830
|
+
*/
|
|
831
|
+
function isFactorResult(value) {
|
|
832
|
+
return whereOf(isObject, (result) => {
|
|
833
|
+
if (isArray(result)) return false;
|
|
834
|
+
const raw = Reflect.get(result, "raw");
|
|
835
|
+
const checks = Reflect.get(result, "checks");
|
|
836
|
+
return isString(Reflect.get(result, "id")) && isBoolean(Reflect.get(result, "applied")) && isNumber(Reflect.get(result, "value")) && (raw === void 0 || isNumber(raw)) && (checks === void 0 || arrayOf(isCheckResult)(checks));
|
|
837
|
+
})(value);
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Determine whether a value is a {@link GroupResult}.
|
|
841
|
+
*
|
|
842
|
+
* @param value - The value to test
|
|
843
|
+
* @returns `true` when every published group-result member is valid
|
|
844
|
+
*
|
|
845
|
+
* @example
|
|
846
|
+
* ```ts
|
|
847
|
+
* import { isGroupResult } from '@src/core'
|
|
848
|
+
*
|
|
849
|
+
* isGroupResult({ id: 'risk', applied: true, value: 5, factors: [] }) // true
|
|
850
|
+
* isGroupResult({ id: 'risk', applied: true, value: 5 }) // false
|
|
851
|
+
* ```
|
|
852
|
+
*/
|
|
853
|
+
function isGroupResult(value) {
|
|
854
|
+
return whereOf(isObject, (result) => {
|
|
855
|
+
return !isArray(result) && isString(Reflect.get(result, "id")) && isBoolean(Reflect.get(result, "applied")) && isNumber(Reflect.get(result, "value")) && arrayOf(isFactorResult)(Reflect.get(result, "factors"));
|
|
856
|
+
})(value);
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Determine whether a value is a {@link RuleResult}.
|
|
860
|
+
*
|
|
861
|
+
* @param value - The value to test
|
|
862
|
+
* @returns `true` when every published rule-result member is valid
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```ts
|
|
866
|
+
* import { isRuleResult } from '@src/core'
|
|
867
|
+
*
|
|
868
|
+
* isRuleResult({ id: 'adult', applied: true, premises: [true], conclusion: true }) // true
|
|
869
|
+
* isRuleResult({ id: 'adult', applied: true, premises: [1], conclusion: true }) // false
|
|
870
|
+
* ```
|
|
871
|
+
*/
|
|
872
|
+
function isRuleResult(value) {
|
|
873
|
+
return whereOf(isObject, (result) => {
|
|
874
|
+
return !isArray(result) && isString(Reflect.get(result, "id")) && isBoolean(Reflect.get(result, "applied")) && arrayOf(isBoolean)(Reflect.get(result, "premises")) && isBoolean(Reflect.get(result, "conclusion"));
|
|
875
|
+
})(value);
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Determine whether a value is a depth-bounded, acyclic {@link ProofNode} tree.
|
|
879
|
+
*
|
|
880
|
+
* @remarks
|
|
881
|
+
* Traversal is iterative and reuses `GUARD_DEPTH_LIMIT`. Active ancestors refuse cycles, and a
|
|
882
|
+
* settled-depth record prevents repeated validation of shared subtrees while keeping the bound
|
|
883
|
+
* exact: a node revisited no deeper than its validated depth is skipped, and one reached deeper
|
|
884
|
+
* is walked again. The traversal accepts an acyclic graph only when every reachable node is
|
|
885
|
+
* valid and every root-to-node path contains at most `GUARD_DEPTH_LIMIT` nodes; shared aliases
|
|
886
|
+
* and sibling order do not affect the verdict.
|
|
887
|
+
*
|
|
888
|
+
* @param value - The value to test
|
|
889
|
+
* @returns `true` when every proof node is valid within the runtime guard bound
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* ```ts
|
|
893
|
+
* import { isProofNode } from '@src/core'
|
|
894
|
+
*
|
|
895
|
+
* isProofNode({ fact: 'bird', depth: 0, children: [{ fact: 'feathers', depth: 1 }] }) // true
|
|
896
|
+
* isProofNode({ fact: 'bird', children: [] }) // false
|
|
897
|
+
* ```
|
|
898
|
+
*/
|
|
899
|
+
function isProofNode(value) {
|
|
900
|
+
return holds(() => {
|
|
901
|
+
if (!isObject(value) || isArray(value)) return false;
|
|
902
|
+
const active = /* @__PURE__ */ new WeakSet();
|
|
903
|
+
const settled = /* @__PURE__ */ new WeakMap();
|
|
904
|
+
const worklist = [[
|
|
905
|
+
value,
|
|
906
|
+
1,
|
|
907
|
+
false
|
|
908
|
+
]];
|
|
909
|
+
while (worklist.length > 0) {
|
|
910
|
+
const frame = worklist.pop();
|
|
911
|
+
if (frame === void 0) continue;
|
|
912
|
+
const node = frame[0];
|
|
913
|
+
const depth = frame[1];
|
|
914
|
+
if (frame[2]) {
|
|
915
|
+
active.delete(node);
|
|
916
|
+
const known = settled.get(node);
|
|
917
|
+
settled.set(node, known === void 0 || depth > known ? depth : known);
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
if (depth > GUARD_DEPTH_LIMIT || active.has(node)) return false;
|
|
921
|
+
const known = settled.get(node);
|
|
922
|
+
if (known !== void 0 && depth <= known) continue;
|
|
923
|
+
active.add(node);
|
|
924
|
+
worklist.push([
|
|
925
|
+
node,
|
|
926
|
+
depth,
|
|
927
|
+
true
|
|
928
|
+
]);
|
|
929
|
+
const inference = Reflect.get(node, "inference");
|
|
930
|
+
const children = Reflect.get(node, "children");
|
|
931
|
+
if (!isString(Reflect.get(node, "fact")) || !isNumber(Reflect.get(node, "depth")) || inference !== void 0 && !isString(inference)) return false;
|
|
932
|
+
if (children === void 0) continue;
|
|
933
|
+
if (!isArray(children)) return false;
|
|
934
|
+
const entries = readArrayEntries(children);
|
|
935
|
+
if (!entries.success || !entries.value.dense) return false;
|
|
936
|
+
for (let index = entries.value.entries.length - 1; index >= 0; index -= 1) {
|
|
937
|
+
const child = entries.value.entries[index];
|
|
938
|
+
if (!isObject(child) || isArray(child)) return false;
|
|
939
|
+
worklist.push([
|
|
940
|
+
child,
|
|
941
|
+
depth + 1,
|
|
942
|
+
false
|
|
943
|
+
]);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return true;
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Determine whether a value is a {@link QuantitativeResult}.
|
|
951
|
+
*
|
|
952
|
+
* @param value - The value to test
|
|
953
|
+
* @returns `true` when every published quantitative-result member is valid
|
|
954
|
+
*
|
|
955
|
+
* @example
|
|
956
|
+
* ```ts
|
|
957
|
+
* import { isQuantitativeResult } from '@src/core'
|
|
958
|
+
*
|
|
959
|
+
* isQuantitativeResult({ reasoning: 'quantitative', value: 0, groups: [], count: 0, success: true, trace: [], errors: [] }) // true
|
|
960
|
+
* isQuantitativeResult({ reasoning: 'quantitative' }) // false
|
|
961
|
+
* ```
|
|
962
|
+
*/
|
|
963
|
+
function isQuantitativeResult(value) {
|
|
964
|
+
return whereOf(isObject, (result) => {
|
|
965
|
+
return !isArray(result) && Reflect.get(result, "reasoning") === "quantitative" && isNumber(Reflect.get(result, "value")) && arrayOf(isGroupResult)(Reflect.get(result, "groups")) && isNumber(Reflect.get(result, "count")) && isBoolean(Reflect.get(result, "success")) && arrayOf(isString)(Reflect.get(result, "trace")) && arrayOf(isString)(Reflect.get(result, "errors"));
|
|
966
|
+
})(value);
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Determine whether a value is a {@link LogicalResult}.
|
|
970
|
+
*
|
|
971
|
+
* @param value - The value to test
|
|
972
|
+
* @returns `true` when every published logical-result member is valid
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
* ```ts
|
|
976
|
+
* import { isLogicalResult } from '@src/core'
|
|
977
|
+
*
|
|
978
|
+
* isLogicalResult({ reasoning: 'logical', conclusion: false, rules: [], count: 0, success: true, trace: [], errors: [] }) // true
|
|
979
|
+
* isLogicalResult({ reasoning: 'logical', rules: [] }) // false
|
|
980
|
+
* ```
|
|
981
|
+
*/
|
|
982
|
+
function isLogicalResult(value) {
|
|
983
|
+
return whereOf(isObject, (result) => {
|
|
984
|
+
return !isArray(result) && Reflect.get(result, "reasoning") === "logical" && isBoolean(Reflect.get(result, "conclusion")) && arrayOf(isRuleResult)(Reflect.get(result, "rules")) && isNumber(Reflect.get(result, "count")) && isBoolean(Reflect.get(result, "success")) && arrayOf(isString)(Reflect.get(result, "trace")) && arrayOf(isString)(Reflect.get(result, "errors"));
|
|
985
|
+
})(value);
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Determine whether a value is a {@link SymbolicResult}.
|
|
989
|
+
*
|
|
990
|
+
* @remarks
|
|
991
|
+
* `solutions` is checked across its OWN string-named members, enumerable or
|
|
992
|
+
* not. Inherited members are deliberately unread: they belong to the
|
|
993
|
+
* accepted-prototype property, not to the record this guard certifies.
|
|
994
|
+
*
|
|
995
|
+
* @param value - The value to test
|
|
996
|
+
* @returns `true` when every published symbolic-result member is valid
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* ```ts
|
|
1000
|
+
* import { isSymbolicResult } from '@src/core'
|
|
1001
|
+
*
|
|
1002
|
+
* isSymbolicResult({ reasoning: 'symbolic', solutions: { x: 4 }, success: true, trace: [], errors: [] }) // true
|
|
1003
|
+
* isSymbolicResult({ reasoning: 'symbolic', solutions: { x: '4' }, success: true, trace: [], errors: [] }) // false
|
|
1004
|
+
* ```
|
|
1005
|
+
*/
|
|
1006
|
+
function isSymbolicResult(value) {
|
|
1007
|
+
return whereOf(isObject, (result) => {
|
|
1008
|
+
return !isArray(result) && Reflect.get(result, "reasoning") === "symbolic" && whereOf(isObject, (solutions) => !isArray(solutions) && Object.getOwnPropertyNames(solutions).every((key) => isNumber(Reflect.get(solutions, key))))(Reflect.get(result, "solutions")) && isBoolean(Reflect.get(result, "success")) && arrayOf(isString)(Reflect.get(result, "trace")) && arrayOf(isString)(Reflect.get(result, "errors"));
|
|
1009
|
+
})(value);
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Determine whether a value is an {@link InferentialResult}.
|
|
1013
|
+
*
|
|
1014
|
+
* @param value - The value to test
|
|
1015
|
+
* @returns `true` when every published inferential-result member is valid
|
|
1016
|
+
*
|
|
1017
|
+
* @example
|
|
1018
|
+
* ```ts
|
|
1019
|
+
* import { isInferentialResult } from '@src/core'
|
|
1020
|
+
*
|
|
1021
|
+
* isInferentialResult({ reasoning: 'inferential', derived: [], success: true, trace: [], errors: [] }) // true
|
|
1022
|
+
* isInferentialResult({ reasoning: 'inferential', derived: [null], success: true, trace: [], errors: [] }) // false
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
function isInferentialResult(value) {
|
|
1026
|
+
return whereOf(isObject, (result) => {
|
|
1027
|
+
if (isArray(result)) return false;
|
|
1028
|
+
const proof = Reflect.get(result, "proof");
|
|
1029
|
+
return Reflect.get(result, "reasoning") === "inferential" && arrayOf(isResultFact)(Reflect.get(result, "derived")) && (proof === void 0 || isProofNode(proof)) && isBoolean(Reflect.get(result, "success")) && arrayOf(isString)(Reflect.get(result, "trace")) && arrayOf(isString)(Reflect.get(result, "errors"));
|
|
1030
|
+
})(value);
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Determine whether a value is any {@link ReasonResult} arm.
|
|
1034
|
+
*
|
|
1035
|
+
* @param value - The value to test
|
|
1036
|
+
* @returns `true` when one complete reasoning-result guard accepts the value
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```ts
|
|
1040
|
+
* import { isReasonResult } from '@src/core'
|
|
1041
|
+
*
|
|
1042
|
+
* isReasonResult({ reasoning: 'symbolic', solutions: {}, success: true, trace: [], errors: [] }) // true
|
|
1043
|
+
* isReasonResult({ reasoning: 'unknown' }) // false
|
|
1044
|
+
* ```
|
|
1045
|
+
*/
|
|
1046
|
+
function isReasonResult(value) {
|
|
1047
|
+
return isQuantitativeResult(value) || isLogicalResult(value) || isSymbolicResult(value) || isInferentialResult(value);
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Determine whether a value is a {@link ReasonValidationResult}.
|
|
1051
|
+
*
|
|
1052
|
+
* @param value - The value to test
|
|
1053
|
+
* @returns `true` when every published validation-result member is valid
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```ts
|
|
1057
|
+
* import { isReasonValidationResult } from '@src/core'
|
|
1058
|
+
*
|
|
1059
|
+
* isReasonValidationResult({ valid: true, errors: [], warnings: [] }) // true
|
|
1060
|
+
* isReasonValidationResult({ valid: true, errors: [] }) // false
|
|
1061
|
+
* ```
|
|
1062
|
+
*/
|
|
1063
|
+
function isReasonValidationResult(value) {
|
|
1064
|
+
return whereOf(isObject, (result) => {
|
|
1065
|
+
return !isArray(result) && isBoolean(Reflect.get(result, "valid")) && arrayOf(isString)(Reflect.get(result, "errors")) && arrayOf(isString)(Reflect.get(result, "warnings"));
|
|
1066
|
+
})(value);
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
772
1069
|
* Determine whether a value is a `DefinitionBuilder` ENTITY — the brand-guarded
|
|
773
1070
|
* stateful workspace, not the plain {@link Definition} data union.
|
|
774
1071
|
*
|
|
@@ -1797,13 +2094,15 @@ function matchFacts(pattern, candidate) {
|
|
|
1797
2094
|
for (let index = 0; index < pattern.terms.length; index++) {
|
|
1798
2095
|
const patternTerm = pattern.terms[index];
|
|
1799
2096
|
const factTerm = candidate.terms[index];
|
|
1800
|
-
if (typeof patternTerm === "string" && patternTerm.startsWith("?"))
|
|
1801
|
-
if (
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
2097
|
+
if (typeof patternTerm === "string" && patternTerm.startsWith("?")) {
|
|
2098
|
+
if (patternTerm in bindings) {
|
|
2099
|
+
if (bindings[patternTerm] !== factTerm) return void 0;
|
|
2100
|
+
} else bindings[patternTerm] = factTerm;
|
|
2101
|
+
} else if (typeof factTerm === "string" && factTerm.startsWith("?")) {
|
|
2102
|
+
if (factTerm in bindings) {
|
|
2103
|
+
if (bindings[factTerm] !== patternTerm) return void 0;
|
|
2104
|
+
} else bindings[factTerm] = patternTerm;
|
|
2105
|
+
} else if (patternTerm !== factTerm) return;
|
|
1807
2106
|
}
|
|
1808
2107
|
return bindings;
|
|
1809
2108
|
}
|
|
@@ -5314,7 +5613,6 @@ var DefinitionBuilder = class {
|
|
|
5314
5613
|
case "inferential":
|
|
5315
5614
|
this.facts.collection = definition.facts;
|
|
5316
5615
|
this.inferences.collection = definition.inferences;
|
|
5317
|
-
break;
|
|
5318
5616
|
}
|
|
5319
5617
|
this.#envelope = this.#strip(definition);
|
|
5320
5618
|
}
|
|
@@ -5880,6 +6178,6 @@ function createInferenceManager(options) {
|
|
|
5880
6178
|
return new InferenceManager(options);
|
|
5881
6179
|
}
|
|
5882
6180
|
//#endregion
|
|
5883
|
-
export { AGGREGATOR_ID, Aggregator, CONFIDENCE_PRECISION, DEFAULT_BASE, DEFAULT_CONFIDENCE, DEFAULT_DEPTH, DEFAULT_PRECISION, DEFAULT_PRIORITY, DEFAULT_REASON_BAIL, DEFAULT_VALIDATE, DEFAULT_WEIGHT, DEFINITION_BUILDER_BRAND, DefinitionBuilder, EVALUATOR_ID, EquationManager, Evaluator, FactManager, FactorManager, GroupManager, INFERENTIAL_ID, INVERTIBLE_OPERATIONS, InferenceManager, InferentialReasoner, LOGICAL_ID, LogicalReasoner, QUANTITATIVE_ID, QuantitativeReasoner, Reason, ReasonError, RuleManager, SUBJECT_BUILDER_BRAND, SYMBOLIC_ID, SubjectBuilder, SymbolicReasoner, TRANSFORMER_ID, Transformer, VariableManager, addVariable, appendById, appendEquation, appendFact, appendFactor, appendGroup, appendInference, appendRule, applyOperation, assignField, atom, bounds, buildErrorResult, check, clamp, clearInferentialDefinition, clearLogicalDefinition, clearQuantitativeDefinition, clearSymbolicDefinition, compound, constant, containsVariable, createAggregator, createDefinitionBuilder, createEquationManager, createEvaluator, createFactManager, createFactorManager, createGroupManager, createInferenceManager, createInferentialReasoner, createLogicalReasoner, createQuantitativeReasoner, createReason, createRuleManager, createSubjectBuilder, createSymbolicReasoner, createTransformer, createVariableManager, equalValues, equation, extractAtoms, extractConclusions, fact, factToArityKey, factToKey, factorGroup, fieldFactor, fieldSource, findDuplicates, findOverlayMismatches, findUnboundVariables, formatField, indexByArity, inference, inferentialDefinition, instantiateFact, invertLeft, invertRight, isAggregation, isBounds, isChainingStrategy, isCheck, isComparison, isDefinition, isDefinitionBuilder, isEquation, isExpression, isFact, isFactor, isFactorGroup, isFactorRange, isFieldPath, isInference, isInferentialDefinition, isLogicalDefinition, isLogicalOperator, isMathOperation, isNumberRecord, isQuantitativeDefinition, isReasonError, isReasoning, isRule, isSource, isSubject, isSubjectBuilder, isSymbolicDefinition, isSymbolicExpression, isTransform, logicalDefinition, lookupFactor, lookupSource, matchFacts, mergeById, mergeInferentialDefinition, mergeLogicalDefinition, mergeQuantitativeDefinition, mergeSubjects, mergeSymbolicDefinition, operation, parseDefinition, prependById, prependEquation, prependFact, prependFactor, prependGroup, prependInference, prependRule, quantitativeDefinition, rangeFactor, rangeSource, removeById, removeEquation, removeFact, removeFactor, removeField, removeGroup, removeInference, removeRule, removeVariable, repeatSubject, replaceById, replaceEquation, replaceFact, replaceFactor, replaceGroup, replaceInference, replaceRule, roundTo, rule, sortByPriority, staticFactor, staticSource, subjectToFacts, symbolicDefinition, termToKey, transform, variable };
|
|
6181
|
+
export { AGGREGATOR_ID, Aggregator, CONFIDENCE_PRECISION, DEFAULT_BASE, DEFAULT_CONFIDENCE, DEFAULT_DEPTH, DEFAULT_PRECISION, DEFAULT_PRIORITY, DEFAULT_REASON_BAIL, DEFAULT_VALIDATE, DEFAULT_WEIGHT, DEFINITION_BUILDER_BRAND, DefinitionBuilder, EVALUATOR_ID, EquationManager, Evaluator, FactManager, FactorManager, GroupManager, INFERENTIAL_ID, INVERTIBLE_OPERATIONS, InferenceManager, InferentialReasoner, LOGICAL_ID, LogicalReasoner, QUANTITATIVE_ID, QuantitativeReasoner, Reason, ReasonError, RuleManager, SUBJECT_BUILDER_BRAND, SYMBOLIC_ID, SubjectBuilder, SymbolicReasoner, TRANSFORMER_ID, Transformer, VariableManager, addVariable, appendById, appendEquation, appendFact, appendFactor, appendGroup, appendInference, appendRule, applyOperation, assignField, atom, bounds, buildErrorResult, check, clamp, clearInferentialDefinition, clearLogicalDefinition, clearQuantitativeDefinition, clearSymbolicDefinition, compound, constant, containsVariable, createAggregator, createDefinitionBuilder, createEquationManager, createEvaluator, createFactManager, createFactorManager, createGroupManager, createInferenceManager, createInferentialReasoner, createLogicalReasoner, createQuantitativeReasoner, createReason, createRuleManager, createSubjectBuilder, createSymbolicReasoner, createTransformer, createVariableManager, equalValues, equation, extractAtoms, extractConclusions, fact, factToArityKey, factToKey, factorGroup, fieldFactor, fieldSource, findDuplicates, findOverlayMismatches, findUnboundVariables, formatField, indexByArity, inference, inferentialDefinition, instantiateFact, invertLeft, invertRight, isAggregation, isBounds, isChainingStrategy, isCheck, isCheckResult, isComparison, isDefinition, isDefinitionBuilder, isEquation, isExpression, isFact, isFactor, isFactorGroup, isFactorRange, isFactorResult, isFieldPath, isGroupResult, isInference, isInferentialDefinition, isInferentialResult, isLogicalDefinition, isLogicalOperator, isLogicalResult, isMathOperation, isNumberRecord, isProofNode, isQuantitativeDefinition, isQuantitativeResult, isReasonError, isReasonResult, isReasonValidationResult, isReasoning, isResultFact, isRule, isRuleResult, isSource, isSubject, isSubjectBuilder, isSymbolicDefinition, isSymbolicExpression, isSymbolicResult, isTransform, logicalDefinition, lookupFactor, lookupSource, matchFacts, mergeById, mergeInferentialDefinition, mergeLogicalDefinition, mergeQuantitativeDefinition, mergeSubjects, mergeSymbolicDefinition, operation, parseDefinition, prependById, prependEquation, prependFact, prependFactor, prependGroup, prependInference, prependRule, quantitativeDefinition, rangeFactor, rangeSource, removeById, removeEquation, removeFact, removeFactor, removeField, removeGroup, removeInference, removeRule, removeVariable, repeatSubject, replaceById, replaceEquation, replaceFact, replaceFactor, replaceGroup, replaceInference, replaceRule, roundTo, rule, sortByPriority, staticFactor, staticSource, subjectToFacts, symbolicDefinition, termToKey, transform, variable };
|
|
5884
6182
|
|
|
5885
6183
|
//# sourceMappingURL=index.js.map
|