@orkestrel/rater 0.0.19 → 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.
- package/dist/src/core/index.cjs +280 -44
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +109 -37
- package/dist/src/core/index.d.ts +109 -37
- package/dist/src/core/index.js +269 -46
- package/dist/src/core/index.js.map +1 -1
- package/package.json +13 -13
package/dist/src/core/index.d.ts
CHANGED
|
@@ -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
|
|
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,
|
|
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,
|
|
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',
|
|
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[];
|
|
@@ -198,7 +201,7 @@ export declare function buildWorksheetGroup(definition: QuantitativeDefinition['
|
|
|
198
201
|
* // { stage: 'total', id: 'quote', name: 'Quote', value: 110, expression: 'sum = 110' }
|
|
199
202
|
* ```
|
|
200
203
|
*/
|
|
201
|
-
export declare function buildWorksheetStep(stage:
|
|
204
|
+
export declare function buildWorksheetStep(stage: WorksheetStage, id: string | undefined, name: string | undefined, value: number, expression: string): Step;
|
|
202
205
|
|
|
203
206
|
/**
|
|
204
207
|
* Builds the ordered {@link Step} rows for a resolved {@link Worksheet}.
|
|
@@ -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
|
|
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 `
|
|
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,
|
|
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,36 +387,16 @@ 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;
|
|
388
394
|
|
|
389
|
-
/**
|
|
390
|
-
* Determines whether a value is a {@link Stage} literal.
|
|
391
|
-
*
|
|
392
|
-
* @remarks
|
|
393
|
-
* A scalar union has no open or exact axis, so this guard accepts one of the
|
|
394
|
-
* `Stage` literals and leaves nothing unchecked.
|
|
395
|
-
*
|
|
396
|
-
* @param value - The value to test
|
|
397
|
-
* @returns True if `value` is `'factor'`, `'group'`, or `'total'`; false otherwise
|
|
398
|
-
*
|
|
399
|
-
* @example
|
|
400
|
-
* ```ts
|
|
401
|
-
* import { isStage } from '@orkestrel/rater'
|
|
402
|
-
*
|
|
403
|
-
* isStage('group') // true
|
|
404
|
-
* isStage('step') // false
|
|
405
|
-
* ```
|
|
406
|
-
*/
|
|
407
|
-
export declare const isStage: Guard<Stage>;
|
|
408
|
-
|
|
409
395
|
/**
|
|
410
396
|
* Determines whether a value is an open {@link Step} result object.
|
|
411
397
|
*
|
|
412
398
|
* @remarks
|
|
413
|
-
* `stage` is checked through `
|
|
399
|
+
* `stage` is checked through `isWorksheetStage`, `id`, `name`, and `expression` when
|
|
414
400
|
* defined, and `value` as a plain number. Unknown members, prototypes, and
|
|
415
401
|
* class instances are admitted and left unchecked, because a borrowed result
|
|
416
402
|
* implementation may add them. Arrays are refused. Optional members may be
|
|
@@ -446,7 +432,7 @@ export declare function isStep(value: unknown): value is Step;
|
|
|
446
432
|
* ```ts
|
|
447
433
|
* import { isWorksheet } from '@orkestrel/rater'
|
|
448
434
|
*
|
|
449
|
-
* 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
|
|
450
436
|
* ```
|
|
451
437
|
*/
|
|
452
438
|
export declare function isWorksheet(value: unknown): value is Worksheet;
|
|
@@ -495,6 +481,26 @@ export declare function isWorksheetFactor(value: unknown): value is WorksheetFac
|
|
|
495
481
|
*/
|
|
496
482
|
export declare function isWorksheetGroup(value: unknown): value is WorksheetGroup;
|
|
497
483
|
|
|
484
|
+
/**
|
|
485
|
+
* Determines whether a value is a {@link WorksheetStage} literal.
|
|
486
|
+
*
|
|
487
|
+
* @remarks
|
|
488
|
+
* A scalar union has no open or exact axis, so this guard accepts one of the
|
|
489
|
+
* `WorksheetStage` literals and leaves nothing unchecked.
|
|
490
|
+
*
|
|
491
|
+
* @param value - The value to test
|
|
492
|
+
* @returns True if `value` is `'factor'`, `'group'`, or `'total'`; false otherwise
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* import { isWorksheetStage } from '@orkestrel/rater'
|
|
497
|
+
*
|
|
498
|
+
* isWorksheetStage('group') // true
|
|
499
|
+
* isWorksheetStage('step') // false
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
export declare const isWorksheetStage: Guard<WorksheetStage>;
|
|
503
|
+
|
|
498
504
|
/**
|
|
499
505
|
* Represents one rateable line — a quantitative definition joined to display metadata.
|
|
500
506
|
*
|
|
@@ -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' }) //
|
|
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,14 +707,21 @@ 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
|
|
|
668
|
-
/**
|
|
669
|
-
export declare
|
|
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;
|
|
670
721
|
|
|
671
722
|
/** Represents a display-neutral worksheet derivation step. */
|
|
672
723
|
export declare interface Step {
|
|
673
|
-
readonly stage:
|
|
724
|
+
readonly stage: WorksheetStage;
|
|
674
725
|
readonly id?: string;
|
|
675
726
|
readonly name?: string;
|
|
676
727
|
readonly value: number;
|
|
@@ -681,7 +732,7 @@ export declare interface Step {
|
|
|
681
732
|
* Sums defined line amounts.
|
|
682
733
|
*
|
|
683
734
|
* @param lines - The rated lines
|
|
684
|
-
* @returns The sum
|
|
735
|
+
* @returns The sum, or `undefined` when no line has an amount or any line refused
|
|
685
736
|
*
|
|
686
737
|
* @example
|
|
687
738
|
* ```ts
|
|
@@ -711,8 +762,14 @@ export declare interface Worksheet {
|
|
|
711
762
|
readonly trace: readonly string[];
|
|
712
763
|
readonly errors: readonly string[];
|
|
713
764
|
readonly success: boolean;
|
|
765
|
+
readonly faults: readonly AuditFault[];
|
|
766
|
+
readonly repairs: readonly AuditFault[];
|
|
767
|
+
readonly defaulted: readonly FieldPath[];
|
|
714
768
|
}
|
|
715
769
|
|
|
770
|
+
/** Lists the stages a worksheet derivation step can belong to. */
|
|
771
|
+
export declare const WORKSHEET_STAGES: readonly ['factor', 'group', 'total'];
|
|
772
|
+
|
|
716
773
|
/** Represents a resolved quantitative factor, joined to its authored metadata. */
|
|
717
774
|
export declare interface WorksheetFactor {
|
|
718
775
|
readonly id: string;
|
|
@@ -723,6 +780,9 @@ export declare interface WorksheetFactor {
|
|
|
723
780
|
readonly evidence: readonly Evidence[];
|
|
724
781
|
}
|
|
725
782
|
|
|
783
|
+
/** Describes a `WorksheetFactor` in its JSON projection. */
|
|
784
|
+
export declare const worksheetFactorShape: ContractShape;
|
|
785
|
+
|
|
726
786
|
/** Represents a resolved quantitative group, joined to its authored metadata. */
|
|
727
787
|
export declare interface WorksheetGroup {
|
|
728
788
|
readonly id: string;
|
|
@@ -733,4 +793,16 @@ export declare interface WorksheetGroup {
|
|
|
733
793
|
readonly factors: readonly WorksheetFactor[];
|
|
734
794
|
}
|
|
735
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
|
+
|
|
802
|
+
/** Names a worksheet derivation step stage. */
|
|
803
|
+
export declare type WorksheetStage = 'factor' | 'group' | 'total';
|
|
804
|
+
|
|
805
|
+
/** Describes a `Step` in its JSON projection. */
|
|
806
|
+
export declare const worksheetStepShape: ContractShape;
|
|
807
|
+
|
|
736
808
|
export { }
|