@orkestrel/rater 0.0.20 → 0.0.21

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.
@@ -1,7 +1,11 @@
1
1
  import type { Aggregation } from '@orkestrel/reason';
2
+ import type { AuditFault } from '@orkestrel/contract';
2
3
  import type { Check } from '@orkestrel/reason';
3
4
  import type { CheckResult } from '@orkestrel/reason';
5
+ import type { CheckState } from '@orkestrel/reason';
4
6
  import type { Comparison } from '@orkestrel/reason';
7
+ import type { ContractInterface } from '@orkestrel/contract';
8
+ import type { ContractShape } from '@orkestrel/contract';
5
9
  import type { EmitterErrorHandler } from '@orkestrel/emitter';
6
10
  import type { EmitterHooks } from '@orkestrel/emitter';
7
11
  import type { EmitterInterface } from '@orkestrel/emitter';
@@ -21,8 +25,7 @@ import type { Subject } from '@orkestrel/reason';
21
25
  *
22
26
  * @param check - The authored check
23
27
  * @param actual - The resolved subject value
24
- * @param met - If `true`, the check was met; if `false`, it was not; absent when the check
25
- * was not yet evaluated
28
+ * @param state - The check's state; absent when the check was not evaluated
26
29
  * @param labels - Optional field-to-label overrides, keyed by dot-joined field
27
30
  * @returns A fresh evidence row
28
31
  *
@@ -32,10 +35,10 @@ import type { Subject } from '@orkestrel/reason';
32
35
  * import { buildEvidence } from '@orkestrel/rater'
33
36
  *
34
37
  * const entry = createCheck('age', 'above', 18)
35
- * buildEvidence(entry, 25, true) // { field: 'age', comparison: 'above', expected: 18, actual: 25, met: true }
38
+ * buildEvidence(entry, 25, 'met') // { field: 'age', comparison: 'above', expected: 18, actual: 25, state: 'met' }
36
39
  * ```
37
40
  */
38
- export declare function buildEvidence(check: Check, actual: unknown, met: boolean | undefined, labels?: Readonly<Record<string, string>>): Evidence;
41
+ export declare function buildEvidence(check: Check, actual: unknown, state: CheckState | undefined, labels?: Readonly<Record<string, string>>): Evidence;
39
42
 
40
43
  /**
41
44
  * Builds one evidence row per authored check of a quantitative factor, joined
@@ -52,7 +55,7 @@ export declare function buildEvidence(check: Check, actual: unknown, met: boolea
52
55
  * import { buildEvidenceRows } from '@orkestrel/rater'
53
56
  *
54
57
  * const checks = [createCheck('age', 'above', 18)]
55
- * buildEvidenceRows(checks, [{ field: 'age', met: true, actual: 25 }])
58
+ * buildEvidenceRows(checks, [{ field: 'age', state: 'met', actual: 25 }])
56
59
  * ```
57
60
  */
58
61
  export declare function buildEvidenceRows(checks: readonly Check[] | undefined, results: readonly CheckResult[] | undefined, labels?: Readonly<Record<string, string>>): readonly Evidence[];
@@ -246,15 +249,18 @@ export declare interface Evidence {
246
249
  readonly comparison?: Comparison;
247
250
  readonly expected?: unknown;
248
251
  readonly actual?: unknown;
249
- readonly met?: boolean;
252
+ readonly state?: CheckState;
250
253
  }
251
254
 
255
+ /** Describes an `Evidence` row in its JSON projection. */
256
+ export declare const evidenceShape: ContractShape;
257
+
252
258
  /**
253
259
  * Determines whether a value is an open result-side {@link Evidence} object.
254
260
  *
255
261
  * @remarks
256
262
  * Optional `field` is checked as a `FieldPath`, `label` as a string,
257
- * `comparison` as a `Comparison`, and `met` as a boolean, each when defined.
263
+ * `comparison` as a `Comparison`, and `state` as a `CheckState`, each when defined.
258
264
  * Unknown members, prototypes, and class instances are admitted. Arrays are
259
265
  * refused. `expected` and `actual` are `unknown`, so this guard does not read or
260
266
  * check them and a borrowed result is never narrowed on them; either member may
@@ -268,7 +274,7 @@ export declare interface Evidence {
268
274
  * ```ts
269
275
  * import { isEvidence } from '@orkestrel/rater'
270
276
  *
271
- * isEvidence({ field: 'age', comparison: 'above', expected: 18, actual: 25, met: true }) // true
277
+ * isEvidence({ field: 'age', comparison: 'above', expected: 18, actual: 25, state: 'met' }) // true
272
278
  * ```
273
279
  */
274
280
  export declare function isEvidence(value: unknown): value is Evidence;
@@ -381,7 +387,7 @@ export declare function isRatingDefinition(value: unknown): value is RatingDefin
381
387
  * ```ts
382
388
  * import { isRatingResult } from '@orkestrel/rater'
383
389
  *
384
- * isRatingResult({ lines: [], success: true }) // true
390
+ * isRatingResult({ lines: [], success: true, errors: [], faults: [], repairs: [], defaulted: [] }) // true
385
391
  * ```
386
392
  */
387
393
  export declare function isRatingResult(value: unknown): value is RatingResult;
@@ -426,7 +432,7 @@ export declare function isStep(value: unknown): value is Step;
426
432
  * ```ts
427
433
  * import { isWorksheet } from '@orkestrel/rater'
428
434
  *
429
- * isWorksheet({ id: 'quote', name: 'Quote', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], errors: [], success: true }) // true
435
+ * isWorksheet({ id: 'quote', name: 'Quote', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], errors: [], success: true, faults: [], repairs: [], defaulted: [] }) // true
430
436
  * ```
431
437
  */
432
438
  export declare function isWorksheet(value: unknown): value is Worksheet;
@@ -510,6 +516,9 @@ export declare interface LineDefinition {
510
516
  readonly metadata?: JSONValue;
511
517
  }
512
518
 
519
+ /** Describes a `LineDefinition`. */
520
+ export declare const lineDefinitionShape: ContractShape;
521
+
513
522
  /**
514
523
  * Represents one line's rating outcome.
515
524
  *
@@ -526,6 +535,30 @@ export declare interface LineResult {
526
535
  readonly worksheet: Worksheet;
527
536
  }
528
537
 
538
+ /** Describes a `LineResult` in its JSON projection. */
539
+ export declare const lineResultShape: ContractShape;
540
+
541
+ /**
542
+ * Projects a result to the JSON its contract reads.
543
+ *
544
+ * @remarks
545
+ * An evidence row's `actual` holds whatever the subject held and a worksheet's numbers may be
546
+ * `NaN`, so a result crosses a boundary as this projection, each `actual` on its own budget.
547
+ *
548
+ * @param result - The rating result
549
+ * @returns Its JSON projection, which `ratingResultContract` admits
550
+ *
551
+ * @example
552
+ * ```ts
553
+ * import { createRater, projectRatingResult, ratingResultContract } from '@orkestrel/rater'
554
+ *
555
+ * const rater = createRater()
556
+ * ratingResultContract.is(projectRatingResult(rater.rate([], {}))) // true
557
+ * rater.destroy()
558
+ * ```
559
+ */
560
+ export declare function projectRatingResult(result: RatingResult): JSONValue | undefined;
561
+
529
562
  /**
530
563
  * Orchestrates rating — owns (or receives) the shared quantitative
531
564
  * reasoning engine and projects results into the rating domain vocabulary.
@@ -544,7 +577,7 @@ export declare interface LineResult {
544
577
  * import { Rater } from '@orkestrel/rater'
545
578
  *
546
579
  * const rater = new Rater()
547
- * rater.rate([], { id: 'subject-1' }) // { lines: [], success: true }
580
+ * rater.rate([], { id: 'subject-1' }).success // true
548
581
  * rater.destroy()
549
582
  * ```
550
583
  */
@@ -649,8 +682,19 @@ export declare interface RatingDefinition {
649
682
  readonly description?: string;
650
683
  readonly lines: readonly LineDefinition[];
651
684
  readonly metadata?: JSONValue;
685
+ readonly shape?: ContractShape;
652
686
  }
653
687
 
688
+ /**
689
+ * Publishes a `RatingDefinition` as a contract. Cross it on `is`, never `parse`.
690
+ */
691
+ export declare const ratingDefinitionContract: ContractInterface<unknown>;
692
+
693
+ /**
694
+ * Describes a `RatingDefinition`.
695
+ */
696
+ export declare const ratingDefinitionShape: ContractShape;
697
+
654
698
  /**
655
699
  * Represents a rated outcome across every line of one `rate` call.
656
700
  *
@@ -663,8 +707,18 @@ export declare interface RatingResult {
663
707
  readonly lines: readonly LineResult[];
664
708
  readonly total?: number;
665
709
  readonly success: boolean;
710
+ readonly errors: readonly string[];
711
+ readonly faults: readonly AuditFault[];
712
+ readonly repairs: readonly AuditFault[];
713
+ readonly defaulted: readonly FieldPath[];
666
714
  }
667
715
 
716
+ /** Publishes a `RatingResult`'s JSON projection as a contract, read through `projectRatingResult`. */
717
+ export declare const ratingResultContract: ContractInterface<unknown>;
718
+
719
+ /** Describes a `RatingResult` in its JSON projection. */
720
+ export declare const ratingResultShape: ContractShape;
721
+
668
722
  /** Represents a display-neutral worksheet derivation step. */
669
723
  export declare interface Step {
670
724
  readonly stage: WorksheetStage;
@@ -678,7 +732,7 @@ export declare interface Step {
678
732
  * Sums defined line amounts.
679
733
  *
680
734
  * @param lines - The rated lines
681
- * @returns The sum of every line's `amount`, or `undefined` when no line has one
735
+ * @returns The sum, or `undefined` when no line has an amount or any line refused
682
736
  *
683
737
  * @example
684
738
  * ```ts
@@ -708,8 +762,14 @@ export declare interface Worksheet {
708
762
  readonly trace: readonly string[];
709
763
  readonly errors: readonly string[];
710
764
  readonly success: boolean;
765
+ readonly faults: readonly AuditFault[];
766
+ readonly repairs: readonly AuditFault[];
767
+ readonly defaulted: readonly FieldPath[];
711
768
  }
712
769
 
770
+ /** Lists the stages a worksheet derivation step can belong to. */
771
+ export declare const WORKSHEET_STAGES: readonly ['factor', 'group', 'total'];
772
+
713
773
  /** Represents a resolved quantitative factor, joined to its authored metadata. */
714
774
  export declare interface WorksheetFactor {
715
775
  readonly id: string;
@@ -720,6 +780,9 @@ export declare interface WorksheetFactor {
720
780
  readonly evidence: readonly Evidence[];
721
781
  }
722
782
 
783
+ /** Describes a `WorksheetFactor` in its JSON projection. */
784
+ export declare const worksheetFactorShape: ContractShape;
785
+
723
786
  /** Represents a resolved quantitative group, joined to its authored metadata. */
724
787
  export declare interface WorksheetGroup {
725
788
  readonly id: string;
@@ -730,7 +793,16 @@ export declare interface WorksheetGroup {
730
793
  readonly factors: readonly WorksheetFactor[];
731
794
  }
732
795
 
796
+ /** Describes a `WorksheetGroup` in its JSON projection. */
797
+ export declare const worksheetGroupShape: ContractShape;
798
+
799
+ /** Describes a `Worksheet` in its JSON projection. */
800
+ export declare const worksheetShape: ContractShape;
801
+
733
802
  /** Names a worksheet derivation step stage. */
734
803
  export declare type WorksheetStage = 'factor' | 'group' | 'total';
735
804
 
805
+ /** Describes a `Step` in its JSON projection. */
806
+ export declare const worksheetStepShape: ContractShape;
807
+
736
808
  export { }