@orkestrel/rater 0.0.12 → 0.0.14
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/README.md +25 -17
- package/dist/src/core/index.cjs +185 -147
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +343 -293
- package/dist/src/core/index.d.ts +343 -293
- package/dist/src/core/index.js +178 -140
- package/dist/src/core/index.js.map +1 -1
- package/package.json +22 -19
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1,24 +1,45 @@
|
|
|
1
|
-
import { Aggregation } from '@orkestrel/reason';
|
|
2
|
-
import { Check } from '@orkestrel/reason';
|
|
3
|
-
import { CheckResult } from '@orkestrel/reason';
|
|
4
|
-
import { Comparison } from '@orkestrel/reason';
|
|
5
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
6
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
7
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
8
|
-
import { Factor } from '@orkestrel/reason';
|
|
9
|
-
import { FactorResult } from '@orkestrel/reason';
|
|
10
|
-
import { FieldPath } from '@orkestrel/contract';
|
|
11
|
-
import { GroupResult } from '@orkestrel/reason';
|
|
12
|
-
import { Guard } from '@orkestrel/contract';
|
|
13
|
-
import { JSONValue } from '@orkestrel/contract';
|
|
14
|
-
import { QuantitativeDefinition } from '@orkestrel/reason';
|
|
15
|
-
import { QuantitativeResult } from '@orkestrel/reason';
|
|
16
|
-
import { ReasonInterface } from '@orkestrel/reason';
|
|
17
|
-
import { Subject } from '@orkestrel/reason';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
1
|
+
import type { Aggregation } from '@orkestrel/reason';
|
|
2
|
+
import type { Check } from '@orkestrel/reason';
|
|
3
|
+
import type { CheckResult } from '@orkestrel/reason';
|
|
4
|
+
import type { Comparison } from '@orkestrel/reason';
|
|
5
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
6
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
7
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
8
|
+
import type { Factor } from '@orkestrel/reason';
|
|
9
|
+
import type { FactorResult } from '@orkestrel/reason';
|
|
10
|
+
import type { FieldPath } from '@orkestrel/contract';
|
|
11
|
+
import type { GroupResult } from '@orkestrel/reason';
|
|
12
|
+
import type { Guard } from '@orkestrel/contract';
|
|
13
|
+
import type { JSONValue } from '@orkestrel/contract';
|
|
14
|
+
import type { QuantitativeDefinition } from '@orkestrel/reason';
|
|
15
|
+
import type { QuantitativeResult } from '@orkestrel/reason';
|
|
16
|
+
import type { ReasonInterface } from '@orkestrel/reason';
|
|
17
|
+
import type { Subject } from '@orkestrel/reason';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Builds an {@link Evidence} row from an evaluated {@link Check}.
|
|
21
|
+
*
|
|
22
|
+
* @param check - The authored check
|
|
23
|
+
* @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
|
|
26
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
27
|
+
* @returns A fresh evidence row
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createCheck } from '@orkestrel/reason'
|
|
32
|
+
* import { buildEvidence } from '@orkestrel/rater'
|
|
33
|
+
*
|
|
34
|
+
* const entry = createCheck('age', 'above', 18)
|
|
35
|
+
* buildEvidence(entry, 25, true) // { field: 'age', comparison: 'above', expected: 18, actual: 25, met: true }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildEvidence(check: Check, actual: unknown, met: boolean | undefined, labels?: Readonly<Record<string, string>>): Evidence;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Builds one evidence row per authored check of a quantitative factor, joined
|
|
42
|
+
* to that check's evaluated result.
|
|
22
43
|
*
|
|
23
44
|
* @param checks - The factor's authored checks
|
|
24
45
|
* @param results - The corresponding {@link CheckResult}s, in the same order
|
|
@@ -27,22 +48,188 @@ import { Subject } from '@orkestrel/reason';
|
|
|
27
48
|
*
|
|
28
49
|
* @example
|
|
29
50
|
* ```ts
|
|
30
|
-
* import {
|
|
31
|
-
* import {
|
|
51
|
+
* import { createCheck } from '@orkestrel/reason'
|
|
52
|
+
* import { buildEvidenceRows } from '@orkestrel/rater'
|
|
53
|
+
*
|
|
54
|
+
* const checks = [createCheck('age', 'above', 18)]
|
|
55
|
+
* buildEvidenceRows(checks, [{ field: 'age', met: true, actual: 25 }])
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildEvidenceRows(checks: readonly Check[] | undefined, results: readonly CheckResult[] | undefined, labels?: Readonly<Record<string, string>>): readonly Evidence[];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Builds a fresh {@link LineDefinition} from a line id, a display name, and the
|
|
62
|
+
* line's quantitative rating definition, with `overrides` merged over those
|
|
63
|
+
* defaults.
|
|
64
|
+
*
|
|
65
|
+
* @param id - The line id
|
|
66
|
+
* @param name - The display name
|
|
67
|
+
* @param rate - The line's quantitative rating definition
|
|
68
|
+
* @param overrides - Optional {@link LineDefinition} fields merged over the defaults
|
|
69
|
+
* @returns A fresh line definition
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { createQuantitativeDefinition } from '@orkestrel/reason'
|
|
74
|
+
* import { buildLineDefinition } from '@orkestrel/rater'
|
|
75
|
+
*
|
|
76
|
+
* buildLineDefinition('base', 'Base Amount', createQuantitativeDefinition('base', 'Base', []))
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildLineDefinition(id: string, name: string, rate: QuantitativeDefinition, overrides?: Partial<Omit<LineDefinition, 'id' | 'name' | 'rate'>>): LineDefinition;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Builds a rated {@link LineResult} from a line's evaluated
|
|
83
|
+
* {@link QuantitativeResult}.
|
|
84
|
+
*
|
|
85
|
+
* @param definition - The authored line definition
|
|
86
|
+
* @param result - The evaluated quantitative result
|
|
87
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
88
|
+
* @returns A fresh line result
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { createQuantitativeDefinition, createQuantitativeReasoner, createReason } from '@orkestrel/reason'
|
|
93
|
+
* import { buildLineDefinition, buildLineResult } from '@orkestrel/rater'
|
|
94
|
+
*
|
|
95
|
+
* const line = buildLineDefinition('base', 'Base', createQuantitativeDefinition('base', 'Base', []))
|
|
96
|
+
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, line.rate)
|
|
97
|
+
* if (result.reasoning === 'quantitative') buildLineResult(line, result) // amount present only on a successful worksheet
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function buildLineResult(definition: LineDefinition, result: QuantitativeResult, labels?: Readonly<Record<string, string>>): LineResult;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Builds a fresh {@link RatingDefinition} from a rating id, a display name, and
|
|
104
|
+
* the rating's ordered lines, with `overrides` merged over those defaults.
|
|
105
|
+
*
|
|
106
|
+
* @param id - The rating id
|
|
107
|
+
* @param name - The display name
|
|
108
|
+
* @param lines - The rating's ordered lines
|
|
109
|
+
* @param overrides - Optional {@link RatingDefinition} fields merged over the defaults
|
|
110
|
+
* @returns A fresh rating definition
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { buildLineDefinition, buildRatingDefinition } from '@orkestrel/rater'
|
|
115
|
+
* import { createQuantitativeDefinition } from '@orkestrel/reason'
|
|
32
116
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
117
|
+
* buildRatingDefinition('r1', 'Rating', [
|
|
118
|
+
* buildLineDefinition('base', 'Base Amount', createQuantitativeDefinition('base', 'Base', [])),
|
|
119
|
+
* ])
|
|
35
120
|
* ```
|
|
36
121
|
*/
|
|
37
|
-
export declare function
|
|
122
|
+
export declare function buildRatingDefinition(id: string, name: string, lines: readonly LineDefinition[], overrides?: Partial<Omit<RatingDefinition, 'id' | 'name' | 'lines'>>): RatingDefinition;
|
|
38
123
|
|
|
39
124
|
/**
|
|
40
|
-
*
|
|
125
|
+
* Joins a {@link QuantitativeDefinition} and its {@link QuantitativeResult} into
|
|
126
|
+
* a {@link Worksheet} — the rating audit trail.
|
|
127
|
+
*
|
|
128
|
+
* @param definition - The authored quantitative definition
|
|
129
|
+
* @param result - The evaluated quantitative result
|
|
130
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
131
|
+
* @returns A fresh worksheet
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'
|
|
136
|
+
* import { buildWorksheet } from '@orkestrel/rater'
|
|
137
|
+
*
|
|
138
|
+
* const definition = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])
|
|
139
|
+
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)
|
|
140
|
+
* if (result.reasoning === 'quantitative') buildWorksheet(definition, result) // the full audit trail
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function buildWorksheet(definition: QuantitativeDefinition, result: QuantitativeResult, labels?: Readonly<Record<string, string>>): Worksheet;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Joins one authored quantitative factor to its evaluated {@link FactorResult}.
|
|
147
|
+
*
|
|
148
|
+
* @param definition - The authored factor
|
|
149
|
+
* @param results - The group's factor results
|
|
150
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
151
|
+
* @returns A fresh worksheet factor
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { createFieldFactor } from '@orkestrel/reason'
|
|
156
|
+
* import { buildWorksheetFactor } from '@orkestrel/rater'
|
|
157
|
+
*
|
|
158
|
+
* const factor = createFieldFactor('seats', 'seats')
|
|
159
|
+
* buildWorksheetFactor(factor, [{ id: 'seats', applied: true, value: 10 }])
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export declare function buildWorksheetFactor(definition: Factor, results: readonly FactorResult[], labels?: Readonly<Record<string, string>>): WorksheetFactor;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Joins one authored quantitative group to its evaluated {@link GroupResult}.
|
|
166
|
+
*
|
|
167
|
+
* @param definition - The authored group
|
|
168
|
+
* @param results - The definition's group results
|
|
169
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
170
|
+
* @returns A fresh worksheet group
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import { createFactorGroup, createStaticFactor } from '@orkestrel/reason'
|
|
175
|
+
* import { buildWorksheetGroup } from '@orkestrel/rater'
|
|
176
|
+
*
|
|
177
|
+
* const group = createFactorGroup('charge', 'sum', [createStaticFactor('base', 100)])
|
|
178
|
+
* buildWorksheetGroup(group, [{ id: 'charge', applied: true, value: 100, factors: [] }])
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export declare function buildWorksheetGroup(definition: QuantitativeDefinition['groups'][number], results: readonly GroupResult[], labels?: Readonly<Record<string, string>>): WorksheetGroup;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Builds one display-neutral {@link Step} row.
|
|
185
|
+
*
|
|
186
|
+
* @param stage - The step's stage
|
|
187
|
+
* @param id - The stage's authored id, when it has one
|
|
188
|
+
* @param name - The stage's authored name, when it has one
|
|
189
|
+
* @param value - The stage's resolved value
|
|
190
|
+
* @param expression - A display-neutral expression string
|
|
191
|
+
* @returns A fresh step
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* import { buildWorksheetStep } from '@orkestrel/rater'
|
|
196
|
+
*
|
|
197
|
+
* buildWorksheetStep('total', 'quote', 'Quote', 110, 'sum = 110')
|
|
198
|
+
* // { stage: 'total', id: 'quote', name: 'Quote', value: 110, expression: 'sum = 110' }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export declare function buildWorksheetStep(stage: Stage, id: string | undefined, name: string | undefined, value: number, expression: string): Step;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Builds the ordered {@link Step} rows for a resolved {@link Worksheet}.
|
|
205
|
+
*
|
|
206
|
+
* @param definition - The authored quantitative definition
|
|
207
|
+
* @param result - The evaluated quantitative result
|
|
208
|
+
* @param groups - The definition's already-joined worksheet groups
|
|
209
|
+
* @returns A fresh, ordered list of steps: applied factors, then groups, then the total
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'
|
|
214
|
+
* import { buildWorksheetGroup, buildWorksheetSteps } from '@orkestrel/rater'
|
|
215
|
+
*
|
|
216
|
+
* const definition = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])
|
|
217
|
+
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)
|
|
218
|
+
* if (result.reasoning === 'quantitative') {
|
|
219
|
+
* buildWorksheetSteps(definition, result, definition.groups.map((group) => buildWorksheetGroup(group, result.groups)))
|
|
220
|
+
* }
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
export declare function buildWorksheetSteps(definition: QuantitativeDefinition, result: QuantitativeResult, groups: readonly WorksheetGroup[]): readonly Step[];
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Creates a rating orchestrator over the shared quantitative engine, seeded
|
|
227
|
+
* from {@link RaterOptions} and returning a {@link RaterInterface}.
|
|
41
228
|
*
|
|
42
229
|
* @param options - Optional total handler, labels, injected engine, and emitter hooks
|
|
43
230
|
* @returns A {@link RaterInterface}
|
|
44
231
|
*
|
|
45
|
-
* @example
|
|
232
|
+
* @example Create a rater
|
|
46
233
|
* ```ts
|
|
47
234
|
* import { createRater } from '@orkestrel/rater'
|
|
48
235
|
*
|
|
@@ -52,7 +239,7 @@ export declare function checkEvidence(checks: readonly Check[] | undefined, resu
|
|
|
52
239
|
*/
|
|
53
240
|
export declare function createRater(options?: RaterOptions): RaterInterface;
|
|
54
241
|
|
|
55
|
-
/**
|
|
242
|
+
/** Represents a checked-evidence row rendered into a display-neutral sentence. */
|
|
56
243
|
export declare interface Evidence {
|
|
57
244
|
readonly field?: FieldPath;
|
|
58
245
|
readonly label?: string;
|
|
@@ -63,36 +250,19 @@ export declare interface Evidence {
|
|
|
63
250
|
}
|
|
64
251
|
|
|
65
252
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @param check - The authored check
|
|
69
|
-
* @param actual - The resolved subject value
|
|
70
|
-
* @param met - Whether the check was met (absent when not yet evaluated)
|
|
71
|
-
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
72
|
-
* @returns A fresh evidence row
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```ts
|
|
76
|
-
* import { check } from '@orkestrel/reason'
|
|
77
|
-
* import { evidenceCheck } from '@orkestrel/rater'
|
|
78
|
-
*
|
|
79
|
-
* const entry = check('age', 'above', 18)
|
|
80
|
-
* evidenceCheck(entry, 25, true) // { field: 'age', comparison: 'above', expected: 18, actual: 25, met: true }
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export declare function evidenceCheck(check: Check, actual: unknown, met: boolean | undefined, labels?: Readonly<Record<string, string>>): Evidence;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Determine whether a value is an open result-side {@link Evidence} object.
|
|
253
|
+
* Determines whether a value is an open result-side {@link Evidence} object.
|
|
87
254
|
*
|
|
88
255
|
* @remarks
|
|
256
|
+
* Optional `field` is checked as a `FieldPath`, `label` as a string,
|
|
257
|
+
* `comparison` as a `Comparison`, and `met` as a boolean, each when defined.
|
|
89
258
|
* Unknown members, prototypes, and class instances are admitted. Arrays are
|
|
90
259
|
* refused. `expected` and `actual` are `unknown`, so this guard does not read or
|
|
91
|
-
* check them
|
|
92
|
-
*
|
|
260
|
+
* check them and a borrowed result is never narrowed on them; either member may
|
|
261
|
+
* also be absent because `objectOf` reads declared members rather than
|
|
262
|
+
* requiring or enumerating own keys.
|
|
93
263
|
*
|
|
94
264
|
* @param value - The value to test
|
|
95
|
-
* @returns
|
|
265
|
+
* @returns True if every checked `Evidence` member conforms; false otherwise
|
|
96
266
|
*
|
|
97
267
|
* @example
|
|
98
268
|
* ```ts
|
|
@@ -104,50 +274,58 @@ export declare function evidenceCheck(check: Check, actual: unknown, met: boolea
|
|
|
104
274
|
export declare function isEvidence(value: unknown): value is Evidence;
|
|
105
275
|
|
|
106
276
|
/**
|
|
107
|
-
*
|
|
277
|
+
* Determines whether a value is an exact {@link LineDefinition} record.
|
|
108
278
|
*
|
|
109
279
|
* @remarks
|
|
110
|
-
*
|
|
111
|
-
*
|
|
280
|
+
* Every `LineDefinition` member is checked, including its quantitative
|
|
281
|
+
* definition. Total guard: adversarial input (cycles, hostile prototypes)
|
|
282
|
+
* returns `false`, never throws. The record shape is exact — this package owns
|
|
283
|
+
* the authored input record, so an extra key fails and nothing is left
|
|
284
|
+
* unchecked.
|
|
112
285
|
*
|
|
113
286
|
* @param value - The value to test
|
|
114
|
-
* @returns
|
|
287
|
+
* @returns True if `value` is a `LineDefinition`; false otherwise
|
|
115
288
|
*
|
|
116
289
|
* @example
|
|
117
290
|
* ```ts
|
|
118
|
-
* import {
|
|
291
|
+
* import { createQuantitativeDefinition } from '@orkestrel/reason'
|
|
119
292
|
* import { isLineDefinition } from '@orkestrel/rater'
|
|
120
293
|
*
|
|
121
|
-
* isLineDefinition({ id: 'base', name: 'Base', rate:
|
|
294
|
+
* isLineDefinition({ id: 'base', name: 'Base', rate: createQuantitativeDefinition('base', 'Base', []) }) // true
|
|
122
295
|
* ```
|
|
123
296
|
*/
|
|
124
297
|
export declare function isLineDefinition(value: unknown): value is LineDefinition;
|
|
125
298
|
|
|
126
299
|
/**
|
|
127
|
-
*
|
|
300
|
+
* Determines whether a value is an open {@link LineResult} object.
|
|
128
301
|
*
|
|
129
302
|
* @remarks
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
303
|
+
* Identity, an optional plain-number `amount`, and the nested `Worksheet` that
|
|
304
|
+
* carries the line's outcome are checked. Unknown members, prototypes, and
|
|
305
|
+
* class instances are admitted and left unchecked, because a borrowed result
|
|
306
|
+
* implementation may add them, and so is the relationship between `amount` and
|
|
307
|
+
* `worksheet.success`, which the published interface types independently.
|
|
308
|
+
* Arrays are refused. `amount` may be absent or read as `undefined`; when
|
|
309
|
+
* present it stays a plain JavaScript `number` without a finite or range
|
|
310
|
+
* refinement.
|
|
133
311
|
*
|
|
134
312
|
* @param value - The value to test
|
|
135
|
-
* @returns
|
|
313
|
+
* @returns True if every published line-result member conforms; false otherwise
|
|
136
314
|
*
|
|
137
315
|
* @example
|
|
138
316
|
* ```ts
|
|
139
317
|
* import { isLineResult } from '@orkestrel/rater'
|
|
140
318
|
*
|
|
141
|
-
* isLineResult({ id: 'base', name: 'Base', worksheet: { id: 'base', name: 'Base', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], errors: [], success: false }
|
|
319
|
+
* isLineResult({ id: 'base', name: 'Base', worksheet: { id: 'base', name: 'Base', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], errors: [], success: false } }) // true
|
|
142
320
|
* ```
|
|
143
321
|
*/
|
|
144
322
|
export declare function isLineResult(value: unknown): value is LineResult;
|
|
145
323
|
|
|
146
324
|
/**
|
|
147
|
-
*
|
|
325
|
+
* Narrows a caught value to a {@link RaterError}.
|
|
148
326
|
*
|
|
149
327
|
* @param value - The caught value to test
|
|
150
|
-
* @returns
|
|
328
|
+
* @returns True if `value` is a `RaterError`; false otherwise
|
|
151
329
|
*
|
|
152
330
|
* @example
|
|
153
331
|
* ```ts
|
|
@@ -163,14 +341,17 @@ export declare function isLineResult(value: unknown): value is LineResult;
|
|
|
163
341
|
export declare function isRaterError(value: unknown): value is RaterError;
|
|
164
342
|
|
|
165
343
|
/**
|
|
166
|
-
*
|
|
344
|
+
* Determines whether a value is an exact {@link RatingDefinition} record.
|
|
167
345
|
*
|
|
168
346
|
* @remarks
|
|
169
|
-
*
|
|
170
|
-
*
|
|
347
|
+
* Every `RatingDefinition` member is checked, including each nested line
|
|
348
|
+
* definition. Total guard: adversarial input (cycles, hostile prototypes)
|
|
349
|
+
* returns `false`, never throws. The record shape is exact — this package owns
|
|
350
|
+
* the authored input record, so an extra key fails and nothing is left
|
|
351
|
+
* unchecked.
|
|
171
352
|
*
|
|
172
353
|
* @param value - The value to test
|
|
173
|
-
* @returns
|
|
354
|
+
* @returns True if `value` is a `RatingDefinition`; false otherwise
|
|
174
355
|
*
|
|
175
356
|
* @example
|
|
176
357
|
* ```ts
|
|
@@ -182,16 +363,19 @@ export declare function isRaterError(value: unknown): value is RaterError;
|
|
|
182
363
|
export declare function isRatingDefinition(value: unknown): value is RatingDefinition;
|
|
183
364
|
|
|
184
365
|
/**
|
|
185
|
-
*
|
|
366
|
+
* Determines whether a value is an open {@link RatingResult} object.
|
|
186
367
|
*
|
|
187
368
|
* @remarks
|
|
188
|
-
* Use this guard for a result returned by a borrowed `RaterInterface`.
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
369
|
+
* Use this guard for a result returned by a borrowed `RaterInterface`. Every
|
|
370
|
+
* nested `LineResult`, an optional plain-number `total`, and a boolean `success`
|
|
371
|
+
* are checked. Unknown members, prototypes, and class instances are admitted and
|
|
372
|
+
* left unchecked, and so are the relationships among totals, lines, and success,
|
|
373
|
+
* because the borrowed interface publishes only their member types. Arrays are
|
|
374
|
+
* refused. `total` may be absent or read as `undefined`; when present it stays a
|
|
375
|
+
* plain JavaScript `number` without a finite or range refinement.
|
|
192
376
|
*
|
|
193
377
|
* @param value - The value to test
|
|
194
|
-
* @returns
|
|
378
|
+
* @returns True if every published rating-result member conforms; false otherwise
|
|
195
379
|
*
|
|
196
380
|
* @example
|
|
197
381
|
* ```ts
|
|
@@ -203,10 +387,14 @@ export declare function isRatingDefinition(value: unknown): value is RatingDefin
|
|
|
203
387
|
export declare function isRatingResult(value: unknown): value is RatingResult;
|
|
204
388
|
|
|
205
389
|
/**
|
|
206
|
-
*
|
|
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.
|
|
207
395
|
*
|
|
208
396
|
* @param value - The value to test
|
|
209
|
-
* @returns
|
|
397
|
+
* @returns True if `value` is `'factor'`, `'group'`, or `'total'`; false otherwise
|
|
210
398
|
*
|
|
211
399
|
* @example
|
|
212
400
|
* ```ts
|
|
@@ -219,14 +407,17 @@ export declare function isRatingResult(value: unknown): value is RatingResult;
|
|
|
219
407
|
export declare const isStage: Guard<Stage>;
|
|
220
408
|
|
|
221
409
|
/**
|
|
222
|
-
*
|
|
410
|
+
* Determines whether a value is an open {@link Step} result object.
|
|
223
411
|
*
|
|
224
412
|
* @remarks
|
|
225
|
-
*
|
|
226
|
-
*
|
|
413
|
+
* `stage` is checked through `isStage`, `id`, `name`, and `expression` when
|
|
414
|
+
* defined, and `value` as a plain number. Unknown members, prototypes, and
|
|
415
|
+
* class instances are admitted and left unchecked, because a borrowed result
|
|
416
|
+
* implementation may add them. Arrays are refused. Optional members may be
|
|
417
|
+
* absent or read as `undefined`.
|
|
227
418
|
*
|
|
228
419
|
* @param value - The value to test
|
|
229
|
-
* @returns
|
|
420
|
+
* @returns True if every published worksheet-step member conforms; false otherwise
|
|
230
421
|
*
|
|
231
422
|
* @example
|
|
232
423
|
* ```ts
|
|
@@ -238,14 +429,18 @@ export declare const isStage: Guard<Stage>;
|
|
|
238
429
|
export declare function isStep(value: unknown): value is Step;
|
|
239
430
|
|
|
240
431
|
/**
|
|
241
|
-
*
|
|
432
|
+
* Determines whether a value is an open {@link Worksheet} result object.
|
|
242
433
|
*
|
|
243
434
|
* @remarks
|
|
244
|
-
*
|
|
245
|
-
*
|
|
435
|
+
* Identity, `aggregation` through reason's `isAggregation`, an optional
|
|
436
|
+
* plain-number `precision`, a plain-number `value`, the nested groups and steps,
|
|
437
|
+
* `trace`, `errors`, and `success` are checked. Unknown members, prototypes, and
|
|
438
|
+
* class instances are admitted and left unchecked, because a borrowed result
|
|
439
|
+
* implementation may add them. Arrays are refused. Optional members may be
|
|
440
|
+
* absent or read as `undefined`.
|
|
246
441
|
*
|
|
247
442
|
* @param value - The value to test
|
|
248
|
-
* @returns
|
|
443
|
+
* @returns True if every published worksheet member conforms; false otherwise
|
|
249
444
|
*
|
|
250
445
|
* @example
|
|
251
446
|
* ```ts
|
|
@@ -257,14 +452,17 @@ export declare function isStep(value: unknown): value is Step;
|
|
|
257
452
|
export declare function isWorksheet(value: unknown): value is Worksheet;
|
|
258
453
|
|
|
259
454
|
/**
|
|
260
|
-
*
|
|
455
|
+
* Determines whether a value is an open {@link WorksheetFactor} result object.
|
|
261
456
|
*
|
|
262
457
|
* @remarks
|
|
263
|
-
*
|
|
264
|
-
*
|
|
458
|
+
* `id`, the optional authored text, `applied`, an optional plain-number
|
|
459
|
+
* `value`, and each `Evidence` entry are checked. Unknown members, prototypes,
|
|
460
|
+
* and class instances are admitted and left unchecked, because a borrowed
|
|
461
|
+
* result implementation may add them. Arrays are refused. Optional members may
|
|
462
|
+
* be absent or read as `undefined`.
|
|
265
463
|
*
|
|
266
464
|
* @param value - The value to test
|
|
267
|
-
* @returns
|
|
465
|
+
* @returns True if every published worksheet-factor member conforms; false otherwise
|
|
268
466
|
*
|
|
269
467
|
* @example
|
|
270
468
|
* ```ts
|
|
@@ -276,14 +474,17 @@ export declare function isWorksheet(value: unknown): value is Worksheet;
|
|
|
276
474
|
export declare function isWorksheetFactor(value: unknown): value is WorksheetFactor;
|
|
277
475
|
|
|
278
476
|
/**
|
|
279
|
-
*
|
|
477
|
+
* Determines whether a value is an open {@link WorksheetGroup} result object.
|
|
280
478
|
*
|
|
281
479
|
* @remarks
|
|
282
|
-
*
|
|
283
|
-
*
|
|
480
|
+
* `id`, the optional authored text, `applied`, a plain-number `value`, and each
|
|
481
|
+
* `WorksheetFactor` entry are checked. Unknown members, prototypes, and class
|
|
482
|
+
* instances are admitted and left unchecked, because a borrowed result
|
|
483
|
+
* implementation may add them. Arrays are refused. Optional members may be
|
|
484
|
+
* absent or read as `undefined`.
|
|
284
485
|
*
|
|
285
486
|
* @param value - The value to test
|
|
286
|
-
* @returns
|
|
487
|
+
* @returns True if every published worksheet-group member conforms; false otherwise
|
|
287
488
|
*
|
|
288
489
|
* @example
|
|
289
490
|
* ```ts
|
|
@@ -295,7 +496,7 @@ export declare function isWorksheetFactor(value: unknown): value is WorksheetFac
|
|
|
295
496
|
export declare function isWorksheetGroup(value: unknown): value is WorksheetGroup;
|
|
296
497
|
|
|
297
498
|
/**
|
|
298
|
-
*
|
|
499
|
+
* Represents one rateable line — a quantitative definition joined to display metadata.
|
|
299
500
|
*
|
|
300
501
|
* @remarks
|
|
301
502
|
* `rate` is a plain reason {@link QuantitativeDefinition}; Rater delegates every
|
|
@@ -310,73 +511,33 @@ export declare interface LineDefinition {
|
|
|
310
511
|
}
|
|
311
512
|
|
|
312
513
|
/**
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* @param id - The line id
|
|
316
|
-
* @param name - The display name
|
|
317
|
-
* @param rate - The line's quantitative rating definition
|
|
318
|
-
* @param overrides - Optional {@link LineDefinition} fields merged over the defaults
|
|
319
|
-
* @returns A fresh line definition
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* ```ts
|
|
323
|
-
* import { quantitativeDefinition } from '@orkestrel/reason'
|
|
324
|
-
* import { lineDefinition } from '@orkestrel/rater'
|
|
325
|
-
*
|
|
326
|
-
* lineDefinition('base', 'Base Amount', quantitativeDefinition('base', 'Base', []))
|
|
327
|
-
* ```
|
|
328
|
-
*/
|
|
329
|
-
export declare function lineDefinition(id: string, name: string, rate: QuantitativeDefinition, overrides?: Partial<Omit<LineDefinition, 'id' | 'name' | 'rate'>>): LineDefinition;
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* One line's rating outcome.
|
|
514
|
+
* Represents one line's rating outcome.
|
|
333
515
|
*
|
|
334
516
|
* @remarks
|
|
335
517
|
* `worksheet` is always present — even a failed evaluation resolves to a
|
|
336
518
|
* type-shaped failure worksheet, so a `LineResult` is always constructible.
|
|
337
|
-
*
|
|
519
|
+
* The worksheet also carries the line's outcome: `amount` is present only
|
|
520
|
+
* when `worksheet.success` is `true`.
|
|
338
521
|
*/
|
|
339
522
|
export declare interface LineResult {
|
|
340
523
|
readonly id: string;
|
|
341
524
|
readonly name: string;
|
|
342
525
|
readonly amount?: number;
|
|
343
526
|
readonly worksheet: Worksheet;
|
|
344
|
-
readonly success: boolean;
|
|
345
527
|
}
|
|
346
528
|
|
|
347
529
|
/**
|
|
348
|
-
*
|
|
349
|
-
* {@link QuantitativeResult}.
|
|
350
|
-
*
|
|
351
|
-
* @param definition - The authored line definition
|
|
352
|
-
* @param result - The evaluated quantitative result
|
|
353
|
-
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
354
|
-
* @returns A fresh line result
|
|
355
|
-
*
|
|
356
|
-
* @example
|
|
357
|
-
* ```ts
|
|
358
|
-
* import { createQuantitativeReasoner, createReason, quantitativeDefinition } from '@orkestrel/reason'
|
|
359
|
-
* import { lineDefinition, ratedLine } from '@orkestrel/rater'
|
|
360
|
-
*
|
|
361
|
-
* const line = lineDefinition('base', 'Base', quantitativeDefinition('base', 'Base', []))
|
|
362
|
-
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, line.rate)
|
|
363
|
-
* if (result.reasoning === 'quantitative') ratedLine(line, result) // amount present only when success
|
|
364
|
-
* ```
|
|
365
|
-
*/
|
|
366
|
-
export declare function ratedLine(definition: LineDefinition, result: QuantitativeResult, labels?: Readonly<Record<string, string>>): LineResult;
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* The rating orchestrator — owns (or receives) the shared quantitative
|
|
530
|
+
* Orchestrates rating — owns (or receives) the shared quantitative
|
|
370
531
|
* reasoning engine and projects results into the rating domain vocabulary.
|
|
371
532
|
*
|
|
372
533
|
* @remarks
|
|
373
|
-
* When no `engine` is injected, `Rater` builds and
|
|
374
|
-
* quantitative-only engine (`bail: false`) — Rater performs
|
|
534
|
+
* When no `engine` is injected, `Rater` builds and owns its own
|
|
535
|
+
* quantitative-only engine (`bail: false`) — Rater performs no evaluation
|
|
375
536
|
* arithmetic of its own; it only orchestrates and projects. The
|
|
376
|
-
* array-of-lines `rate` overload is declared
|
|
377
|
-
* destroys an
|
|
378
|
-
* engine is never destroyed. Afterwards every
|
|
379
|
-
* {@link RaterError} `'DESTROYED'`.
|
|
537
|
+
* array-of-lines `rate` overload is declared first so a plain line list
|
|
538
|
+
* resolves to that form. `destroy()` destroys an owned engine, then the
|
|
539
|
+
* emitter last; an injected engine is never destroyed. Afterwards every
|
|
540
|
+
* other method throws {@link RaterError} `'DESTROYED'`.
|
|
380
541
|
*
|
|
381
542
|
* @example
|
|
382
543
|
* ```ts
|
|
@@ -397,12 +558,13 @@ export declare class Rater implements RaterInterface {
|
|
|
397
558
|
}
|
|
398
559
|
|
|
399
560
|
/**
|
|
400
|
-
*
|
|
561
|
+
* Represents a coded programmer error thrown by the rating layer.
|
|
401
562
|
*
|
|
402
563
|
* @remarks
|
|
403
564
|
* `DEFINITION` — the `rate` input failed both the array-of-lines and rating
|
|
404
565
|
* definition validation. `MISMATCH` — a rated subject is not a record.
|
|
405
|
-
* `DESTROYED` — use of a destroyed entity.
|
|
566
|
+
* `DESTROYED` — use of a destroyed entity. `context` carries optional
|
|
567
|
+
* structured detail beside the message.
|
|
406
568
|
*
|
|
407
569
|
* @example
|
|
408
570
|
* ```ts
|
|
@@ -417,40 +579,50 @@ export declare class RaterError extends Error {
|
|
|
417
579
|
constructor(code: RaterErrorCode, message: string, context?: Readonly<Record<string, unknown>>);
|
|
418
580
|
}
|
|
419
581
|
|
|
420
|
-
/**
|
|
582
|
+
/** Names a coded {@link RaterError} programmer-error code. */
|
|
421
583
|
export declare type RaterErrorCode = 'DEFINITION' | 'MISMATCH' | 'DESTROYED';
|
|
422
584
|
|
|
423
585
|
/**
|
|
424
|
-
*
|
|
586
|
+
* Represents the push observation surface of a {@link RaterInterface}.
|
|
425
587
|
*
|
|
426
588
|
* @remarks
|
|
427
589
|
* `rate` fires once per `rate` call, carrying the rated subject and the result.
|
|
428
590
|
*/
|
|
429
591
|
export declare type RaterEventMap = {
|
|
430
|
-
/**
|
|
592
|
+
/** Fires when a subject is rated — carries the subject and its result. */
|
|
431
593
|
readonly rate: readonly [subject: Subject, result: RatingResult];
|
|
432
594
|
};
|
|
433
595
|
|
|
434
596
|
/**
|
|
435
|
-
*
|
|
597
|
+
* Represents the rating orchestrator over the shared quantitative reasoning engine.
|
|
436
598
|
*
|
|
437
599
|
* @remarks
|
|
438
|
-
* The array-of-lines `rate` overload is declared
|
|
439
|
-
*
|
|
600
|
+
* The array-of-lines `rate` overload is declared first so a plain line list
|
|
601
|
+
* resolves to that form. Each overload rates a single subject — there is no
|
|
602
|
+
* batch-of-subjects overload.
|
|
440
603
|
*/
|
|
441
604
|
export declare interface RaterInterface {
|
|
605
|
+
/** Holds the typed emitter every `rate` call fires its event through. */
|
|
442
606
|
readonly emitter: EmitterInterface<RaterEventMap>;
|
|
607
|
+
/**
|
|
608
|
+
* Rates an array of lines, or a {@link RatingDefinition}, against one subject over
|
|
609
|
+
* the shared quantitative engine.
|
|
610
|
+
*/
|
|
443
611
|
rate(lines: readonly LineDefinition[], subject: Subject): RatingResult;
|
|
444
612
|
rate(definition: RatingDefinition, subject: Subject): RatingResult;
|
|
613
|
+
/**
|
|
614
|
+
* Destroys an owned engine and then the emitter, and does nothing on a later
|
|
615
|
+
* call.
|
|
616
|
+
*/
|
|
445
617
|
destroy(): void;
|
|
446
618
|
}
|
|
447
619
|
|
|
448
620
|
/**
|
|
449
|
-
*
|
|
621
|
+
* Configures `createRater` and the `Rater` constructor.
|
|
450
622
|
*
|
|
451
623
|
* @remarks
|
|
452
624
|
* `engine` — an injected {@link ReasonInterface}; when omitted, `Rater` builds
|
|
453
|
-
* and
|
|
625
|
+
* and owns its own quantitative-only engine (`bail: false`), destroying it on
|
|
454
626
|
* `destroy()`. `total` — a {@link TotalHandler} overriding the default
|
|
455
627
|
* {@link sumAmounts} projection. `labels` — field-to-label display overrides
|
|
456
628
|
* threaded into every resolved {@link Evidence}.
|
|
@@ -464,7 +636,7 @@ export declare interface RaterOptions {
|
|
|
464
636
|
}
|
|
465
637
|
|
|
466
638
|
/**
|
|
467
|
-
*
|
|
639
|
+
* Represents a pure authored rating — a named, ordered set of lines.
|
|
468
640
|
*
|
|
469
641
|
* @remarks
|
|
470
642
|
* `rate` accepts either a plain `readonly LineDefinition[]` or a full
|
|
@@ -480,33 +652,12 @@ export declare interface RatingDefinition {
|
|
|
480
652
|
}
|
|
481
653
|
|
|
482
654
|
/**
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
* @param id - The rating id
|
|
486
|
-
* @param name - The display name
|
|
487
|
-
* @param lines - The rating's ordered lines
|
|
488
|
-
* @param overrides - Optional {@link RatingDefinition} fields merged over the defaults
|
|
489
|
-
* @returns A fresh rating definition
|
|
490
|
-
*
|
|
491
|
-
* @example
|
|
492
|
-
* ```ts
|
|
493
|
-
* import { lineDefinition, ratingDefinition } from '@orkestrel/rater'
|
|
494
|
-
* import { quantitativeDefinition } from '@orkestrel/reason'
|
|
495
|
-
*
|
|
496
|
-
* ratingDefinition('r1', 'Rating', [
|
|
497
|
-
* lineDefinition('base', 'Base Amount', quantitativeDefinition('base', 'Base', [])),
|
|
498
|
-
* ])
|
|
499
|
-
* ```
|
|
500
|
-
*/
|
|
501
|
-
export declare function ratingDefinition(id: string, name: string, lines: readonly LineDefinition[], overrides?: Partial<Omit<RatingDefinition, 'id' | 'name' | 'lines'>>): RatingDefinition;
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* A rated outcome across every line of one `rate` call.
|
|
655
|
+
* Represents a rated outcome across every line of one `rate` call.
|
|
505
656
|
*
|
|
506
657
|
* @remarks
|
|
507
658
|
* `total` is derived by the {@link TotalHandler} (default {@link sumAmounts})
|
|
508
659
|
* over `lines` — only successfully rated lines carry an `amount`. `success`
|
|
509
|
-
* is `true` only when every line
|
|
660
|
+
* is `true` only when every line's `worksheet.success` is `true`.
|
|
510
661
|
*/
|
|
511
662
|
export declare interface RatingResult {
|
|
512
663
|
readonly lines: readonly LineResult[];
|
|
@@ -514,31 +665,10 @@ export declare interface RatingResult {
|
|
|
514
665
|
readonly success: boolean;
|
|
515
666
|
}
|
|
516
667
|
|
|
517
|
-
/**
|
|
518
|
-
* Join a {@link QuantitativeDefinition} and its {@link QuantitativeResult} into
|
|
519
|
-
* a {@link Worksheet} — the rating audit trail.
|
|
520
|
-
*
|
|
521
|
-
* @param definition - The authored quantitative definition
|
|
522
|
-
* @param result - The evaluated quantitative result
|
|
523
|
-
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
524
|
-
* @returns A fresh worksheet
|
|
525
|
-
*
|
|
526
|
-
* @example
|
|
527
|
-
* ```ts
|
|
528
|
-
* import { createQuantitativeReasoner, createReason, factorGroup, quantitativeDefinition, staticFactor } from '@orkestrel/reason'
|
|
529
|
-
* import { resultsWorksheet } from '@orkestrel/rater'
|
|
530
|
-
*
|
|
531
|
-
* const definition = quantitativeDefinition('base', 'Base', [factorGroup('g', 'sum', [staticFactor('flat', 100)])])
|
|
532
|
-
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)
|
|
533
|
-
* if (result.reasoning === 'quantitative') resultsWorksheet(definition, result) // the full audit trail
|
|
534
|
-
* ```
|
|
535
|
-
*/
|
|
536
|
-
export declare function resultsWorksheet(definition: QuantitativeDefinition, result: QuantitativeResult, labels?: Readonly<Record<string, string>>): Worksheet;
|
|
537
|
-
|
|
538
|
-
/** A worksheet derivation step stage. */
|
|
668
|
+
/** Names a worksheet derivation step stage. */
|
|
539
669
|
export declare type Stage = 'factor' | 'group' | 'total';
|
|
540
670
|
|
|
541
|
-
/**
|
|
671
|
+
/** Represents a display-neutral worksheet derivation step. */
|
|
542
672
|
export declare interface Step {
|
|
543
673
|
readonly stage: Stage;
|
|
544
674
|
readonly id?: string;
|
|
@@ -548,28 +678,28 @@ export declare interface Step {
|
|
|
548
678
|
}
|
|
549
679
|
|
|
550
680
|
/**
|
|
551
|
-
*
|
|
681
|
+
* Sums defined line amounts.
|
|
552
682
|
*
|
|
553
683
|
* @param lines - The rated lines
|
|
554
684
|
* @returns The sum of every line's `amount`, or `undefined` when no line has one
|
|
555
685
|
*
|
|
556
686
|
* @example
|
|
557
687
|
* ```ts
|
|
558
|
-
* import {
|
|
559
|
-
* import {
|
|
688
|
+
* import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'
|
|
689
|
+
* import { buildLineDefinition, buildLineResult, sumAmounts } from '@orkestrel/rater'
|
|
560
690
|
*
|
|
561
|
-
* const rate =
|
|
562
|
-
* const line =
|
|
691
|
+
* const rate = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])
|
|
692
|
+
* const line = buildLineDefinition('base', 'Base', rate)
|
|
563
693
|
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, rate)
|
|
564
|
-
* if (result.reasoning === 'quantitative') sumAmounts([
|
|
694
|
+
* if (result.reasoning === 'quantitative') sumAmounts([buildLineResult(line, result)]) // 100
|
|
565
695
|
* ```
|
|
566
696
|
*/
|
|
567
697
|
export declare function sumAmounts(lines: readonly LineResult[]): number | undefined;
|
|
568
698
|
|
|
569
|
-
/**
|
|
699
|
+
/** Represents a pure total port over resolved lines. */
|
|
570
700
|
export declare type TotalHandler = (lines: readonly LineResult[]) => number | undefined;
|
|
571
701
|
|
|
572
|
-
/**
|
|
702
|
+
/** Represents a quantitative definition joined to its result — the rating audit trail. */
|
|
573
703
|
export declare interface Worksheet {
|
|
574
704
|
readonly id: string;
|
|
575
705
|
readonly name: string;
|
|
@@ -583,7 +713,7 @@ export declare interface Worksheet {
|
|
|
583
713
|
readonly success: boolean;
|
|
584
714
|
}
|
|
585
715
|
|
|
586
|
-
/**
|
|
716
|
+
/** Represents a resolved quantitative factor, joined to its authored metadata. */
|
|
587
717
|
export declare interface WorksheetFactor {
|
|
588
718
|
readonly id: string;
|
|
589
719
|
readonly name?: string;
|
|
@@ -593,26 +723,7 @@ export declare interface WorksheetFactor {
|
|
|
593
723
|
readonly evidence: readonly Evidence[];
|
|
594
724
|
}
|
|
595
725
|
|
|
596
|
-
/**
|
|
597
|
-
* Join one authored quantitative factor to its evaluated {@link FactorResult}.
|
|
598
|
-
*
|
|
599
|
-
* @param definition - The authored factor
|
|
600
|
-
* @param results - The group's factor results
|
|
601
|
-
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
602
|
-
* @returns A fresh worksheet factor
|
|
603
|
-
*
|
|
604
|
-
* @example
|
|
605
|
-
* ```ts
|
|
606
|
-
* import { fieldFactor } from '@orkestrel/reason'
|
|
607
|
-
* import { worksheetFactor } from '@orkestrel/rater'
|
|
608
|
-
*
|
|
609
|
-
* const factor = fieldFactor('seats', 'seats')
|
|
610
|
-
* worksheetFactor(factor, [{ id: 'seats', applied: true, value: 10 }])
|
|
611
|
-
* ```
|
|
612
|
-
*/
|
|
613
|
-
export declare function worksheetFactor(definition: Factor, results: readonly FactorResult[], labels?: Readonly<Record<string, string>>): WorksheetFactor;
|
|
614
|
-
|
|
615
|
-
/** A resolved quantitative group, joined to its authored metadata. */
|
|
726
|
+
/** Represents a resolved quantitative group, joined to its authored metadata. */
|
|
616
727
|
export declare interface WorksheetGroup {
|
|
617
728
|
readonly id: string;
|
|
618
729
|
readonly name?: string;
|
|
@@ -622,65 +733,4 @@ export declare interface WorksheetGroup {
|
|
|
622
733
|
readonly factors: readonly WorksheetFactor[];
|
|
623
734
|
}
|
|
624
735
|
|
|
625
|
-
/**
|
|
626
|
-
* Join one authored quantitative group to its evaluated {@link GroupResult}.
|
|
627
|
-
*
|
|
628
|
-
* @param definition - The authored group
|
|
629
|
-
* @param results - The definition's group results
|
|
630
|
-
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
631
|
-
* @returns A fresh worksheet group
|
|
632
|
-
*
|
|
633
|
-
* @example
|
|
634
|
-
* ```ts
|
|
635
|
-
* import { factorGroup, staticFactor } from '@orkestrel/reason'
|
|
636
|
-
* import { worksheetGroup } from '@orkestrel/rater'
|
|
637
|
-
*
|
|
638
|
-
* const group = factorGroup('charge', 'sum', [staticFactor('base', 100)])
|
|
639
|
-
* worksheetGroup(group, [{ id: 'charge', applied: true, value: 100, factors: [] }])
|
|
640
|
-
* ```
|
|
641
|
-
*/
|
|
642
|
-
export declare function worksheetGroup(definition: QuantitativeDefinition['groups'][number], results: readonly GroupResult[], labels?: Readonly<Record<string, string>>): WorksheetGroup;
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* Build one display-neutral {@link Step} row.
|
|
646
|
-
*
|
|
647
|
-
* @param stage - The step's stage
|
|
648
|
-
* @param id - The stage's authored id, when it has one
|
|
649
|
-
* @param name - The stage's authored name, when it has one
|
|
650
|
-
* @param value - The stage's resolved value
|
|
651
|
-
* @param expression - A display-neutral expression string
|
|
652
|
-
* @returns A fresh step
|
|
653
|
-
*
|
|
654
|
-
* @example
|
|
655
|
-
* ```ts
|
|
656
|
-
* import { worksheetStep } from '@orkestrel/rater'
|
|
657
|
-
*
|
|
658
|
-
* worksheetStep('total', 'quote', 'Quote', 110, 'sum = 110')
|
|
659
|
-
* // { stage: 'total', id: 'quote', name: 'Quote', value: 110, expression: 'sum = 110' }
|
|
660
|
-
* ```
|
|
661
|
-
*/
|
|
662
|
-
export declare function worksheetStep(stage: Stage, id: string | undefined, name: string | undefined, value: number, expression: string): Step;
|
|
663
|
-
|
|
664
|
-
/**
|
|
665
|
-
* Build the ordered {@link Step} rows for a resolved {@link Worksheet}.
|
|
666
|
-
*
|
|
667
|
-
* @param definition - The authored quantitative definition
|
|
668
|
-
* @param result - The evaluated quantitative result
|
|
669
|
-
* @param groups - The definition's already-joined worksheet groups
|
|
670
|
-
* @returns A fresh, ordered list of steps: applied factors, then groups, then the total
|
|
671
|
-
*
|
|
672
|
-
* @example
|
|
673
|
-
* ```ts
|
|
674
|
-
* import { createQuantitativeReasoner, createReason, factorGroup, quantitativeDefinition, staticFactor } from '@orkestrel/reason'
|
|
675
|
-
* import { worksheetGroup, worksheetSteps } from '@orkestrel/rater'
|
|
676
|
-
*
|
|
677
|
-
* const definition = quantitativeDefinition('base', 'Base', [factorGroup('g', 'sum', [staticFactor('flat', 100)])])
|
|
678
|
-
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)
|
|
679
|
-
* if (result.reasoning === 'quantitative') {
|
|
680
|
-
* worksheetSteps(definition, result, definition.groups.map((group) => worksheetGroup(group, result.groups)))
|
|
681
|
-
* }
|
|
682
|
-
* ```
|
|
683
|
-
*/
|
|
684
|
-
export declare function worksheetSteps(definition: QuantitativeDefinition, result: QuantitativeResult, groups: readonly WorksheetGroup[]): readonly Step[];
|
|
685
|
-
|
|
686
736
|
export { }
|