@orkestrel/qualifier 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 +576 -113
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +349 -53
- package/dist/src/core/index.d.ts +349 -53
- package/dist/src/core/index.js +559 -116
- package/dist/src/core/index.js.map +1 -1
- package/package.json +13 -13
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import type { AuditFault } from '@orkestrel/contract';
|
|
1
2
|
import type { Check } from '@orkestrel/reason';
|
|
2
3
|
import type { CheckResult } from '@orkestrel/reason';
|
|
4
|
+
import type { CheckState } from '@orkestrel/reason';
|
|
3
5
|
import type { Comparison } from '@orkestrel/reason';
|
|
6
|
+
import type { ContractInterface } from '@orkestrel/contract';
|
|
7
|
+
import type { ContractShape } from '@orkestrel/contract';
|
|
4
8
|
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
5
9
|
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
6
10
|
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
7
|
-
import type { EvaluatorInterface } from '@orkestrel/reason';
|
|
8
11
|
import type { FieldPath } from '@orkestrel/contract';
|
|
9
12
|
import { Guard } from '@orkestrel/contract';
|
|
10
13
|
import type { JSONValue } from '@orkestrel/contract';
|
|
@@ -16,6 +19,8 @@ import type { ReasonInterface } from '@orkestrel/reason';
|
|
|
16
19
|
import type { ReasonResult } from '@orkestrel/reason';
|
|
17
20
|
import type { ReasonValidationResult } from '@orkestrel/reason';
|
|
18
21
|
import type { Rule } from '@orkestrel/reason';
|
|
22
|
+
import type { RuleResult } from '@orkestrel/reason';
|
|
23
|
+
import type { ShapeScan } from '@orkestrel/reason';
|
|
19
24
|
import type { Subject } from '@orkestrel/reason';
|
|
20
25
|
|
|
21
26
|
/**
|
|
@@ -39,7 +44,7 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
39
44
|
* `CheckResult`.
|
|
40
45
|
*
|
|
41
46
|
* @param check - The authored check
|
|
42
|
-
* @param result - The evaluated check result carrying the resolved `actual` and `
|
|
47
|
+
* @param result - The evaluated check result carrying the resolved `actual` and `state`
|
|
43
48
|
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
44
49
|
* @returns A fresh premise
|
|
45
50
|
*
|
|
@@ -49,8 +54,8 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
49
54
|
* import { createCheck } from '@orkestrel/reason'
|
|
50
55
|
*
|
|
51
56
|
* const authored = createCheck('age', 'above', 18)
|
|
52
|
-
* checkToPremise(authored, { field: 'age', actual: 25,
|
|
53
|
-
* // { field: 'age', comparison: 'above', expected: 18, actual: 25,
|
|
57
|
+
* checkToPremise(authored, { field: 'age', actual: 25, state: 'met' })
|
|
58
|
+
* // { field: 'age', comparison: 'above', expected: 18, actual: 25, state: 'met' }
|
|
54
59
|
* ```
|
|
55
60
|
*/
|
|
56
61
|
export declare function checkToPremise(check: Check, result: CheckResult, labels?: Readonly<Record<string, string>>): Premise;
|
|
@@ -80,7 +85,7 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
80
85
|
* @param id - The definition id
|
|
81
86
|
* @param name - The display name
|
|
82
87
|
* @param passes - The ordered qualification passes
|
|
83
|
-
* @param input - Optional description, rulings, and
|
|
88
|
+
* @param input - Optional description, rulings, metadata, and subject shape
|
|
84
89
|
* @returns A fresh qualification definition
|
|
85
90
|
*
|
|
86
91
|
* @example
|
|
@@ -92,6 +97,43 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
92
97
|
*/
|
|
93
98
|
export declare function createQualificationDefinition(id: string, name: string, passes: readonly QualificationPass[], input?: QualificationInput): QualificationDefinition;
|
|
94
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Creates the contract of a `QualificationDefinition`, its `schema` for an LLM, a tool, or MCP.
|
|
102
|
+
*
|
|
103
|
+
* @remarks
|
|
104
|
+
* Cross a definition on `is`, never `parse`, and hold the result, because building it walks the
|
|
105
|
+
* recursive expressions of its logical passes. `is` checks nested contract shapes;
|
|
106
|
+
* semantic validation remains the qualifier's responsibility.
|
|
107
|
+
*
|
|
108
|
+
* @returns A contract over a qualification definition
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { createQualificationDefinition, createQualificationDefinitionContract } from '@orkestrel/qualifier'
|
|
113
|
+
*
|
|
114
|
+
* createQualificationDefinitionContract().is(createQualificationDefinition('d', 'd', [])) // true
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function createQualificationDefinitionContract(): ContractInterface<unknown>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Creates the shape of a `QualificationDefinition`.
|
|
121
|
+
*
|
|
122
|
+
* @remarks
|
|
123
|
+
* `shape` is checked as a recursive contract shape.
|
|
124
|
+
*
|
|
125
|
+
* @returns A shape holding quantitative and logical passes and rulings
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* import { createContract } from '@orkestrel/contract'
|
|
130
|
+
* import { createQualificationDefinition, createQualificationDefinitionShape } from '@orkestrel/qualifier'
|
|
131
|
+
*
|
|
132
|
+
* createContract(createQualificationDefinitionShape()).is(createQualificationDefinition('d', 'd', [])) // true
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function createQualificationDefinitionShape(): ContractShape;
|
|
136
|
+
|
|
95
137
|
/**
|
|
96
138
|
* Creates one {@link QualifierInterface} over a reason engine.
|
|
97
139
|
*
|
|
@@ -176,11 +218,14 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
176
218
|
readonly errors: readonly string[];
|
|
177
219
|
}
|
|
178
220
|
|
|
221
|
+
/** Describes a `Derivation` in its JSON projection, where a non-finite number is `null`. */
|
|
222
|
+
export declare const derivationShape: ContractShape;
|
|
223
|
+
|
|
179
224
|
/**
|
|
180
|
-
* Derives global eligibility from
|
|
225
|
+
* Derives global eligibility from unscoped findings whose rule is met.
|
|
181
226
|
*
|
|
182
227
|
* @remarks
|
|
183
|
-
* Only findings that
|
|
228
|
+
* Only findings that are `met` and carry no `scope` shape global eligibility.
|
|
184
229
|
* A failed pass contributes a synthetic `referral` (fail-closed), passed through
|
|
185
230
|
* `failed`.
|
|
186
231
|
*
|
|
@@ -193,7 +238,7 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
193
238
|
* ```ts
|
|
194
239
|
* import { deriveFindingEligibility } from '@orkestrel/qualifier'
|
|
195
240
|
*
|
|
196
|
-
* const finding = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const,
|
|
241
|
+
* const finding = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const, state: 'met' as const, premises: [] }
|
|
197
242
|
* deriveFindingEligibility([finding]) // 'ineligible'
|
|
198
243
|
* ```
|
|
199
244
|
*/
|
|
@@ -203,7 +248,7 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
203
248
|
* Derives one eligibility per finding scope.
|
|
204
249
|
*
|
|
205
250
|
* @remarks
|
|
206
|
-
* Only
|
|
251
|
+
* Only scoped findings that are `met` contribute. Each named scope combines its own
|
|
207
252
|
* findings' impacts by severity. An unmentioned scope is absent (eligible by
|
|
208
253
|
* default at the program layer).
|
|
209
254
|
*
|
|
@@ -214,7 +259,7 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
214
259
|
* ```ts
|
|
215
260
|
* import { deriveScopeEligibilities } from '@orkestrel/qualifier'
|
|
216
261
|
*
|
|
217
|
-
* const finding = { id: 'coastal', pass: 'wind', rule: 'coastal', effect: 'restriction' as const, scope: 'wind',
|
|
262
|
+
* const finding = { id: 'coastal', pass: 'wind', rule: 'coastal', effect: 'restriction' as const, scope: 'wind', state: 'met' as const, premises: [] }
|
|
218
263
|
* deriveScopeEligibilities([finding]) // { wind: 'ineligible' }
|
|
219
264
|
* ```
|
|
220
265
|
*/
|
|
@@ -271,6 +316,47 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
271
316
|
*/
|
|
272
317
|
export declare function describeMissingReferences(definition: QualificationDefinition): readonly string[];
|
|
273
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Describes each rule concluding `conclusion`, which a pass's projection reserves for itself.
|
|
321
|
+
*
|
|
322
|
+
* @param definition - The definition
|
|
323
|
+
* @returns One message per such rule
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
* import { createQualificationDefinition, describeReservedConclusions } from '@orkestrel/qualifier'
|
|
328
|
+
* import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'
|
|
329
|
+
*
|
|
330
|
+
* const pass = createLogicalDefinition('gates', 'Gates', [
|
|
331
|
+
* createRule('r', [createAtom('a', 'equals', 1)], createAtom('conclusion', 'equals', true)),
|
|
332
|
+
* ])
|
|
333
|
+
* describeReservedConclusions(createQualificationDefinition('d', 'd', [pass])).length // 1
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
export declare function describeReservedConclusions(definition: QualificationDefinition): readonly string[];
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Describes each message token no field of the definition's shape answers.
|
|
340
|
+
*
|
|
341
|
+
* @remarks
|
|
342
|
+
* A token under `qualification` reads a pass's projection, which no shape declares.
|
|
343
|
+
*
|
|
344
|
+
* @param definition - The definition
|
|
345
|
+
* @returns One message per unknown token, empty with no shape
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* import { numberShape, objectShape } from '@orkestrel/contract'
|
|
350
|
+
* import { createQualificationDefinition, createRuling, describeUnknownTokens } from '@orkestrel/qualifier'
|
|
351
|
+
*
|
|
352
|
+
* const ruling = createRuling('r', 'gates', 'licensed', 'referral', { message: 'Age {{agee}}' })
|
|
353
|
+
* const shape = objectShape({ age: numberShape() })
|
|
354
|
+
* describeUnknownTokens(createQualificationDefinition('d', 'd', [], { rulings: [ruling], shape }))
|
|
355
|
+
* // ['Ruling \'r\' message reads "agee", and the shape does not declare it']
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
export declare function describeUnknownTokens(definition: QualificationDefinition): readonly string[];
|
|
359
|
+
|
|
274
360
|
/**
|
|
275
361
|
* Describes each quantitative pass never read by a later pass.
|
|
276
362
|
*
|
|
@@ -305,24 +391,75 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
305
391
|
*/
|
|
306
392
|
export declare const EFFECT_ELIGIBILITIES: Readonly<Record<QualificationEffect, Eligibility>>;
|
|
307
393
|
|
|
394
|
+
/** Lists the eligibility outcomes. */
|
|
395
|
+
export declare const ELIGIBILITIES: readonly ['eligible', 'ineligible', 'referral'];
|
|
396
|
+
|
|
308
397
|
/** Represents the eligibility outcome axis. */
|
|
309
398
|
export declare type Eligibility = 'eligible' | 'ineligible' | 'referral';
|
|
310
399
|
|
|
311
400
|
/** Lists the eligibility severities most to least severe: `ineligible`, `referral`, `eligible`. */
|
|
312
401
|
export declare const ELIGIBILITY_PRECEDENCE: readonly Eligibility[];
|
|
313
402
|
|
|
314
|
-
/**
|
|
403
|
+
/**
|
|
404
|
+
* Replaces a read of an unread pass's projection with what that pass could not read.
|
|
405
|
+
*
|
|
406
|
+
* @remarks
|
|
407
|
+
* A pass reading `qualification.gates.blocked` is unread because `gates` projected nothing, so
|
|
408
|
+
* the question to ask is the one `gates` could not answer. A read of a pass that settled stays,
|
|
409
|
+
* because that pass holds no such key. Passes run in order and each stores its expanded faults,
|
|
410
|
+
* so a chain of unread passes reaches the input that started it.
|
|
411
|
+
*
|
|
412
|
+
* @param faults - The faults every pass reported, in order
|
|
413
|
+
* @param unread - The faults of each unread pass, by pass id
|
|
414
|
+
* @returns The input faults, once per field
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```ts
|
|
418
|
+
* import { expandPassFaults } from '@orkestrel/qualifier'
|
|
419
|
+
*
|
|
420
|
+
* const leaf = { reason: 'missing', path: 'age', expected: 'number' } as const
|
|
421
|
+
* const read = { reason: 'missing', path: ['qualification', 'gates', 'ok'], expected: 'boolean' } as const
|
|
422
|
+
* expandPassFaults([read], new Map([['gates', [leaf]]])) // [leaf]
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
export declare function expandPassFaults(faults: readonly AuditFault[], unread: ReadonlyMap<string, readonly AuditFault[]>): readonly AuditFault[];
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Represents one resolved ruling.
|
|
429
|
+
*
|
|
430
|
+
* @remarks
|
|
431
|
+
* `state` is the state of the ruling's rule, so only `met` applies the ruling's effect. A rule
|
|
432
|
+
* left `unread` is no answer either way, and the pass it sits in reads `referral`.
|
|
433
|
+
*/
|
|
315
434
|
export declare interface Finding {
|
|
316
435
|
readonly id: string;
|
|
317
436
|
readonly pass: string;
|
|
318
437
|
readonly rule: string;
|
|
319
438
|
readonly effect: QualificationEffect;
|
|
320
439
|
readonly scope?: string;
|
|
321
|
-
readonly
|
|
440
|
+
readonly state: CheckState;
|
|
322
441
|
readonly message?: string;
|
|
323
442
|
readonly premises: readonly Premise[];
|
|
324
443
|
}
|
|
325
444
|
|
|
445
|
+
/** Describes a `Finding` in its JSON projection. */
|
|
446
|
+
export declare const findingShape: ContractShape;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Finds the `{{dotted.path}}` tokens a message template reads.
|
|
450
|
+
*
|
|
451
|
+
* @param template - The message template
|
|
452
|
+
* @returns Each token's dotted path, trimmed, in order, repeats included
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* import { findMessageTokens } from '@orkestrel/qualifier'
|
|
457
|
+
*
|
|
458
|
+
* findMessageTokens('Age {{ age }} in {{home.city}}') // ['age', 'home.city']
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
export declare function findMessageTokens(template: string): readonly string[];
|
|
462
|
+
|
|
326
463
|
/**
|
|
327
464
|
* Locates an authored {@link Rule} by id.
|
|
328
465
|
*
|
|
@@ -359,6 +496,33 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
359
496
|
*/
|
|
360
497
|
export declare function hasReservedKey(subject: Subject): boolean;
|
|
361
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Determines whether a logical result holds a rule left unread.
|
|
501
|
+
*
|
|
502
|
+
* @param result - The result of a pass
|
|
503
|
+
* @returns True when a logical result holds such a rule; false otherwise
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```ts
|
|
507
|
+
* import { hasUnreadRule } from '@orkestrel/qualifier'
|
|
508
|
+
*
|
|
509
|
+
* const rule = { id: 'r', state: 'unread' as const, premises: [], checks: [] }
|
|
510
|
+
* hasUnreadRule({
|
|
511
|
+
* reasoning: 'logical',
|
|
512
|
+
* conclusion: 'unread',
|
|
513
|
+
* rules: [rule],
|
|
514
|
+
* count: 0,
|
|
515
|
+
* success: false,
|
|
516
|
+
* trace: [],
|
|
517
|
+
* errors: [],
|
|
518
|
+
* faults: [],
|
|
519
|
+
* repairs: [],
|
|
520
|
+
* defaulted: [],
|
|
521
|
+
* }) // true
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
export declare function hasUnreadRule(result: ReasonResult): boolean;
|
|
525
|
+
|
|
362
526
|
/**
|
|
363
527
|
* Interpolates `{{dotted.path}}` tokens in a message template against a subject.
|
|
364
528
|
*
|
|
@@ -383,6 +547,22 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
383
547
|
*/
|
|
384
548
|
export declare function interpolateMessage(template: string, subject: Readonly<Record<string, unknown>>): string;
|
|
385
549
|
|
|
550
|
+
/**
|
|
551
|
+
* Determines whether a value is a definition's `metadata`: a record of JSON values.
|
|
552
|
+
*
|
|
553
|
+
* @param value - The value to test
|
|
554
|
+
* @returns True for a record whose every value is JSON; false otherwise
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```ts
|
|
558
|
+
* import { isDefinitionMetadata } from '@orkestrel/qualifier'
|
|
559
|
+
*
|
|
560
|
+
* isDefinitionMetadata({ a: 1 }) // true
|
|
561
|
+
* isDefinitionMetadata({ a: Number.NaN }) // false
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
export declare const isDefinitionMetadata: Guard<Record<string, unknown>>;
|
|
565
|
+
|
|
386
566
|
/**
|
|
387
567
|
* Determines whether a value is an open result-side {@link Derivation}.
|
|
388
568
|
*
|
|
@@ -567,6 +747,9 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
567
747
|
*/
|
|
568
748
|
export declare function mergeQualificationContext(context: QualificationContext, id: string, projection: QualificationProjection): QualificationContext;
|
|
569
749
|
|
|
750
|
+
/** Matches each `{{dotted.path}}` token of a message template, with the path as its one group. */
|
|
751
|
+
export declare const MESSAGE_TOKEN: RegExp;
|
|
752
|
+
|
|
570
753
|
/**
|
|
571
754
|
* Represents display-neutral evidence for one condition, authored as a checked or a
|
|
572
755
|
* described premise.
|
|
@@ -576,8 +759,9 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
576
759
|
* carries neither and renders from `description` instead. The checked form
|
|
577
760
|
* renders only when `field` and `comparison` are both present, and
|
|
578
761
|
* `description` then goes unused; a premise missing either half of the
|
|
579
|
-
* checked pair renders as described instead. `
|
|
580
|
-
*
|
|
762
|
+
* checked pair renders as described instead. `state` is what the rule read: `met`,
|
|
763
|
+
* `unmet`, or `unread`. It is absent when the rule never ran, because it was disabled or
|
|
764
|
+
* the premise is only described, and both `unread` and absent render as unknown.
|
|
581
765
|
*/
|
|
582
766
|
export declare interface Premise {
|
|
583
767
|
readonly field?: FieldPath;
|
|
@@ -586,9 +770,37 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
586
770
|
readonly comparison?: Comparison;
|
|
587
771
|
readonly expected?: unknown;
|
|
588
772
|
readonly actual?: unknown;
|
|
589
|
-
readonly
|
|
773
|
+
readonly state?: CheckState;
|
|
590
774
|
}
|
|
591
775
|
|
|
776
|
+
/** Describes a `Premise` in its JSON projection. */
|
|
777
|
+
export declare const premiseShape: ContractShape;
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Projects a result to the JSON its contract reads.
|
|
781
|
+
*
|
|
782
|
+
* @remarks
|
|
783
|
+
* A premise's `actual` holds whatever the subject held and a derivation's `value` may be `NaN`,
|
|
784
|
+
* so a result crosses a boundary as this projection, each `actual` on its own budget.
|
|
785
|
+
*
|
|
786
|
+
* @param result - The qualification result
|
|
787
|
+
* @returns Its JSON projection, which `qualificationResultContract` admits
|
|
788
|
+
*
|
|
789
|
+
* @example
|
|
790
|
+
* ```ts
|
|
791
|
+
* import { createQualificationDefinition, createQualifier, projectQualificationResult, qualificationResultContract } from '@orkestrel/qualifier'
|
|
792
|
+
*
|
|
793
|
+
* const qualifier = createQualifier()
|
|
794
|
+
* const result = qualifier.qualify({}, createQualificationDefinition('d', 'd', []))
|
|
795
|
+
* qualificationResultContract.is(projectQualificationResult(result)) // true
|
|
796
|
+
* qualifier.destroy()
|
|
797
|
+
* ```
|
|
798
|
+
*/
|
|
799
|
+
export declare function projectQualificationResult(result: QualificationResult): JSONValue | undefined;
|
|
800
|
+
|
|
801
|
+
/** Lists the effects a ruling can carry. */
|
|
802
|
+
export declare const QUALIFICATION_EFFECTS: readonly ['restriction', 'referral', 'condition'];
|
|
803
|
+
|
|
592
804
|
/**
|
|
593
805
|
* Names `'qualification'`, the reserved internal projection namespace a pass's working
|
|
594
806
|
* projection is written under.
|
|
@@ -598,7 +810,13 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
598
810
|
/** Represents the internal projection record stored under `QUALIFICATION_KEY`. */
|
|
599
811
|
export declare type QualificationContext = Readonly<Record<string, QualificationProjection>>;
|
|
600
812
|
|
|
601
|
-
/**
|
|
813
|
+
/**
|
|
814
|
+
* Represents a pure authored qualification definition.
|
|
815
|
+
*
|
|
816
|
+
* @remarks
|
|
817
|
+
* `shape` declares the subject, which then passes a door before any pass reads it. A pass
|
|
818
|
+
* carries no shape of its own, because the subject it reads holds `qualification` too.
|
|
819
|
+
*/
|
|
602
820
|
export declare interface QualificationDefinition {
|
|
603
821
|
readonly id: string;
|
|
604
822
|
readonly name: string;
|
|
@@ -606,6 +824,7 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
606
824
|
readonly passes: readonly QualificationPass[];
|
|
607
825
|
readonly rulings?: readonly Ruling[];
|
|
608
826
|
readonly metadata?: Readonly<Record<string, JSONValue>>;
|
|
827
|
+
readonly shape?: ContractShape;
|
|
609
828
|
}
|
|
610
829
|
|
|
611
830
|
/** Represents an authored ruling's eligibility impact. */
|
|
@@ -616,6 +835,7 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
616
835
|
readonly description?: string;
|
|
617
836
|
readonly rulings?: readonly Ruling[];
|
|
618
837
|
readonly metadata?: Readonly<Record<string, JSONValue>>;
|
|
838
|
+
readonly shape?: ContractShape;
|
|
619
839
|
}
|
|
620
840
|
|
|
621
841
|
/** Represents one ordered derivation or rule pass. */
|
|
@@ -624,7 +844,16 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
624
844
|
/** Represents one pass's internal working projection. */
|
|
625
845
|
export declare type QualificationProjection = number | boolean | Readonly<Record<string, unknown>>;
|
|
626
846
|
|
|
627
|
-
/**
|
|
847
|
+
/**
|
|
848
|
+
* Represents one subject's complete qualification outcome.
|
|
849
|
+
*
|
|
850
|
+
* @remarks
|
|
851
|
+
* `success` is false exactly when `errors` holds an entry, and then `eligibility` carries at
|
|
852
|
+
* least a `referral`. `faults` names each input the run could not read, with a read of an
|
|
853
|
+
* unread pass's projection replaced by what that pass could not read, and `errors` holds one
|
|
854
|
+
* string per fault plus what no fault can say. `repairs` and `defaulted` report what the door
|
|
855
|
+
* changed.
|
|
856
|
+
*/
|
|
628
857
|
export declare interface QualificationResult {
|
|
629
858
|
readonly id: string;
|
|
630
859
|
readonly name: string;
|
|
@@ -635,8 +864,17 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
635
864
|
readonly success: boolean;
|
|
636
865
|
readonly trace: readonly string[];
|
|
637
866
|
readonly errors: readonly string[];
|
|
867
|
+
readonly faults: readonly AuditFault[];
|
|
868
|
+
readonly repairs: readonly AuditFault[];
|
|
869
|
+
readonly defaulted: readonly FieldPath[];
|
|
638
870
|
}
|
|
639
871
|
|
|
872
|
+
/** Publishes a `QualificationResult`'s JSON projection as a contract, read through `projectQualificationResult`. */
|
|
873
|
+
export declare const qualificationResultContract: ContractInterface<unknown>;
|
|
874
|
+
|
|
875
|
+
/** Describes a `QualificationResult` in its JSON projection. */
|
|
876
|
+
export declare const qualificationResultShape: ContractShape;
|
|
877
|
+
|
|
640
878
|
/**
|
|
641
879
|
* Wraps a {@link QualificationContext} under {@link QUALIFICATION_KEY}.
|
|
642
880
|
*
|
|
@@ -687,9 +925,11 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
687
925
|
* @remarks
|
|
688
926
|
* Semantic validation runs first when the `validate` option is on, so an invalid
|
|
689
927
|
* definition throws before any pass runs. Passes run in authored order over a
|
|
690
|
-
* copy-on-write working subject, and the caller's `subject` is never mutated.
|
|
691
|
-
*
|
|
692
|
-
* more severe.
|
|
928
|
+
* copy-on-write working subject, and the caller's `subject` is never mutated. A
|
|
929
|
+
* `shape` on the definition admits the subject through a door first. An unscoped
|
|
930
|
+
* restriction stops the remaining passes because no later finding can be more severe.
|
|
931
|
+
* A pass left unread projects nothing and reads `referral`, and the run goes on, so a later
|
|
932
|
+
* restriction can still outrank it. An error no fault can say stops the run.
|
|
693
933
|
*
|
|
694
934
|
* @param subject - The record to qualify
|
|
695
935
|
* @param definition - The authored qualification definition
|
|
@@ -725,8 +965,10 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
725
965
|
* Structural shape is `isQualificationDefinition`'s job. This checks the meaning:
|
|
726
966
|
* non-empty id and name, valid and uniquely identified passes and rulings, every
|
|
727
967
|
* ruling reference resolving to a logical pass and one of its rules, and no pass id
|
|
728
|
-
* shadowing `QUALIFICATION_KEY`.
|
|
729
|
-
*
|
|
968
|
+
* shadowing `QUALIFICATION_KEY`. The engine validates each pass, whose errors carry the
|
|
969
|
+
* pass id. A pass may carry no shape, and a `shape` on the definition must stand and
|
|
970
|
+
* declare every message token. An empty definition, a logical pass carrying no ruling,
|
|
971
|
+
* and a derivation no later pass reads are warnings rather than errors.
|
|
730
972
|
*
|
|
731
973
|
* @param definition - The authored qualification definition
|
|
732
974
|
* @returns A fresh validation result carrying `valid`, `errors`, and `warnings`
|
|
@@ -933,6 +1175,24 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
933
1175
|
*/
|
|
934
1176
|
export declare function quantitativeResultToDerivation(id: string, result: QuantitativeResult): Derivation;
|
|
935
1177
|
|
|
1178
|
+
/**
|
|
1179
|
+
* Determines whether a field reads a pass's projection under `qualification`, or a key the host projects.
|
|
1180
|
+
*
|
|
1181
|
+
* @param field - The field
|
|
1182
|
+
* @param projections - Further keys the host projects onto the subject. Default: none
|
|
1183
|
+
* @returns True for an array path starting at the reserved key or a projected key; false otherwise
|
|
1184
|
+
*
|
|
1185
|
+
* @example
|
|
1186
|
+
* ```ts
|
|
1187
|
+
* import { readsProjection } from '@orkestrel/qualifier'
|
|
1188
|
+
*
|
|
1189
|
+
* readsProjection(['qualification', 'gates', 'ok']) // true
|
|
1190
|
+
* readsProjection(['aggregate', 'count'], ['aggregate']) // true
|
|
1191
|
+
* readsProjection('age') // false
|
|
1192
|
+
* ```
|
|
1193
|
+
*/
|
|
1194
|
+
export declare function readsProjection(field: FieldPath, projections?: readonly string[]): boolean;
|
|
1195
|
+
|
|
936
1196
|
/**
|
|
937
1197
|
* Projects one reason result into the internal qualification namespace.
|
|
938
1198
|
*
|
|
@@ -999,10 +1259,10 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
999
1259
|
* ```ts
|
|
1000
1260
|
* import { renderPremise } from '@orkestrel/qualifier'
|
|
1001
1261
|
*
|
|
1002
|
-
* renderPremise({ field: 'age', comparison: 'above', expected: 18, actual: 25,
|
|
1262
|
+
* renderPremise({ field: 'age', comparison: 'above', expected: 18, actual: 25, state: 'met' })
|
|
1003
1263
|
* // 'age is more than 18 → met'
|
|
1004
1264
|
*
|
|
1005
|
-
* renderPremise({ description: 'Applicant is enrolled',
|
|
1265
|
+
* renderPremise({ description: 'Applicant is enrolled', state: 'met' })
|
|
1006
1266
|
* // 'Applicant is enrolled → met'
|
|
1007
1267
|
* ```
|
|
1008
1268
|
*/
|
|
@@ -1035,36 +1295,34 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
1035
1295
|
|
|
1036
1296
|
/**
|
|
1037
1297
|
* Builds rich premises for one fired {@link Rule} by walking its premise atoms
|
|
1038
|
-
* and
|
|
1298
|
+
* and reading each from what the rule read.
|
|
1039
1299
|
*
|
|
1040
1300
|
* @remarks
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
* the injected `evaluator`. A membership check (`any` / `none`) over an empty
|
|
1045
|
-
* array value is content-free and is skipped.
|
|
1301
|
+
* Each authored premise expression is flattened to its atom leaves through `extractAtoms`,
|
|
1302
|
+
* which lines up with the `checks` the rule result carries, so a premise cannot disagree with
|
|
1303
|
+
* the pass. A rule with no result never ran, so its premises carry no `state` or `actual`.
|
|
1046
1304
|
*
|
|
1047
1305
|
* @param rule - The authored rule
|
|
1048
|
-
* @param
|
|
1049
|
-
* @param evaluator - The shared reason check evaluator
|
|
1306
|
+
* @param resolved - The rule's result, absent when it never ran
|
|
1050
1307
|
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
1051
1308
|
* @returns A fresh, ordered list of rich premises
|
|
1052
1309
|
*
|
|
1053
1310
|
* @example
|
|
1054
1311
|
* ```ts
|
|
1055
1312
|
* import { ruleToPremises } from '@orkestrel/qualifier'
|
|
1056
|
-
* import { createAtom,
|
|
1313
|
+
* import { createAtom, createRule } from '@orkestrel/reason'
|
|
1057
1314
|
*
|
|
1058
|
-
* const
|
|
1059
|
-
*
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1315
|
+
* const rule = createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true))
|
|
1316
|
+
* const resolved = {
|
|
1317
|
+
* id: 'licensed',
|
|
1318
|
+
* state: 'met' as const,
|
|
1319
|
+
* premises: ['met' as const],
|
|
1320
|
+
* checks: [{ field: 'licensed', state: 'met' as const, actual: false }],
|
|
1321
|
+
* }
|
|
1322
|
+
* ruleToPremises(rule, resolved)[0]?.state // 'met'
|
|
1065
1323
|
* ```
|
|
1066
1324
|
*/
|
|
1067
|
-
export declare function ruleToPremises(rule: Rule,
|
|
1325
|
+
export declare function ruleToPremises(rule: Rule, resolved: RuleResult | undefined, labels?: Readonly<Record<string, string>>): readonly Premise[];
|
|
1068
1326
|
|
|
1069
1327
|
/** Represents an authored consequence for one rule in one logical pass. */
|
|
1070
1328
|
export declare interface Ruling {
|
|
@@ -1082,39 +1340,77 @@ import type { Subject } from '@orkestrel/reason';
|
|
|
1082
1340
|
readonly message?: string;
|
|
1083
1341
|
}
|
|
1084
1342
|
|
|
1343
|
+
/** Describes a `Ruling`. */
|
|
1344
|
+
export declare const rulingShape: ContractShape;
|
|
1345
|
+
|
|
1085
1346
|
/**
|
|
1086
|
-
* Joins a ruling, its logical rule result, the pass, the pre-projection subject
|
|
1087
|
-
*
|
|
1347
|
+
* Joins a ruling, its logical rule result, the pass, and the pre-projection subject into a
|
|
1348
|
+
* {@link Finding}.
|
|
1088
1349
|
*
|
|
1089
1350
|
* @remarks
|
|
1090
|
-
* `
|
|
1091
|
-
*
|
|
1092
|
-
*
|
|
1093
|
-
* against that snapshot.
|
|
1351
|
+
* `state` is the state of the ruling's rule. A rule the result omits reads `unmet` when it is
|
|
1352
|
+
* disabled, which is authored, and `unread` otherwise, because a refused pass evaluated no rule.
|
|
1353
|
+
* Premises come from what the rule read. The message interpolates against the subject.
|
|
1094
1354
|
*
|
|
1095
1355
|
* @param ruling - The authored ruling
|
|
1096
1356
|
* @param pass - The pass the ruling's rule lives in
|
|
1097
1357
|
* @param result - The pass's evaluated logical result
|
|
1098
1358
|
* @param subject - The pre-projection subject snapshot the pass evaluated
|
|
1099
|
-
* @param evaluator - The shared reason check evaluator
|
|
1100
1359
|
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
1101
1360
|
* @returns A fresh finding
|
|
1102
1361
|
*
|
|
1103
1362
|
* @example
|
|
1104
1363
|
* ```ts
|
|
1105
1364
|
* import { rulingToFinding } from '@orkestrel/qualifier'
|
|
1106
|
-
* import { createAtom,
|
|
1365
|
+
* import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'
|
|
1107
1366
|
*
|
|
1108
1367
|
* const gates = createLogicalDefinition('gates', 'Gates', [
|
|
1109
1368
|
* createRule('licensed', [createAtom('licensed', 'equals', false)], createAtom('blocked', 'equals', true)),
|
|
1110
1369
|
* ])
|
|
1111
1370
|
* const ruling = { id: 'license', pass: 'gates', rule: 'licensed', effect: 'restriction' as const }
|
|
1112
|
-
* const result = {
|
|
1113
|
-
*
|
|
1371
|
+
* const result = {
|
|
1372
|
+
* reasoning: 'logical' as const,
|
|
1373
|
+
* conclusion: 'met' as const,
|
|
1374
|
+
* rules: [{ id: 'licensed', state: 'met' as const, premises: ['met' as const], checks: [] }],
|
|
1375
|
+
* count: 1,
|
|
1376
|
+
* success: true,
|
|
1377
|
+
* trace: [],
|
|
1378
|
+
* errors: [],
|
|
1379
|
+
* faults: [],
|
|
1380
|
+
* repairs: [],
|
|
1381
|
+
* defaulted: [],
|
|
1382
|
+
* }
|
|
1383
|
+
* rulingToFinding(ruling, gates, result, { licensed: false }).state // 'met'
|
|
1384
|
+
* ```
|
|
1385
|
+
*/
|
|
1386
|
+
export declare function rulingToFinding(ruling: Ruling, pass: QualificationPass, result: LogicalResult, subject: Subject, labels?: Readonly<Record<string, string>>): Finding;
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* Describes what the definition's shape cannot stand for: a read of a field it does not declare,
|
|
1390
|
+
* and the reserved `qualification` key, which a default could otherwise fill.
|
|
1391
|
+
*
|
|
1392
|
+
* @remarks
|
|
1393
|
+
* A read under `qualification` reads a pass's projection, and a pass's own conclusion keys are
|
|
1394
|
+
* its own, so neither needs a declaration. A host that projects a key of its own names it in
|
|
1395
|
+
* `projections`. A `raw` or `json` read is a warning.
|
|
1396
|
+
*
|
|
1397
|
+
* @param definition - The definition
|
|
1398
|
+
* @param projections - Further keys the host projects onto the subject. Default: none
|
|
1399
|
+
* @returns The errors and warnings, empty with no shape
|
|
1114
1400
|
*
|
|
1115
|
-
*
|
|
1401
|
+
* @example
|
|
1402
|
+
* ```ts
|
|
1403
|
+
* import { numberShape, objectShape } from '@orkestrel/contract'
|
|
1404
|
+
* import { createQualificationDefinition, scanDefinitionShape } from '@orkestrel/qualifier'
|
|
1405
|
+
* import { createAtom, createLogicalDefinition, createRule } from '@orkestrel/reason'
|
|
1406
|
+
*
|
|
1407
|
+
* const pass = createLogicalDefinition('gates', 'Gates', [
|
|
1408
|
+
* createRule('r', [createAtom('agee', 'above', 1)], createAtom('ok', 'equals', true)),
|
|
1409
|
+
* ])
|
|
1410
|
+
* const shape = objectShape({ age: numberShape() })
|
|
1411
|
+
* scanDefinitionShape(createQualificationDefinition('d', 'd', [pass], { shape })).errors.length // 1
|
|
1116
1412
|
* ```
|
|
1117
1413
|
*/
|
|
1118
|
-
export declare function
|
|
1414
|
+
export declare function scanDefinitionShape(definition: QualificationDefinition, projections?: readonly string[]): ShapeScan;
|
|
1119
1415
|
|
|
1120
1416
|
export { }
|