@orkestrel/rater 0.0.11 → 0.0.13
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 +12 -8
- package/dist/src/core/index.cjs +127 -127
- package/dist/src/core/index.cjs.map +1 -0
- package/dist/src/core/index.d.cts +256 -253
- package/dist/src/core/index.d.ts +256 -253
- package/dist/src/core/index.js +120 -120
- package/dist/src/core/index.js.map +1 -0
- package/package.json +23 -18
|
@@ -17,8 +17,29 @@ import { ReasonInterface } from '@orkestrel/reason';
|
|
|
17
17
|
import { Subject } from '@orkestrel/reason';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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,17 +48,179 @@ 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 {@link LineDefinition}.
|
|
62
|
+
*
|
|
63
|
+
* @param id - The line id
|
|
64
|
+
* @param name - The display name
|
|
65
|
+
* @param rate - The line's quantitative rating definition
|
|
66
|
+
* @param overrides - Optional {@link LineDefinition} fields merged over the defaults
|
|
67
|
+
* @returns A fresh line definition
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { createQuantitativeDefinition } from '@orkestrel/reason'
|
|
72
|
+
* import { buildLineDefinition } from '@orkestrel/rater'
|
|
73
|
+
*
|
|
74
|
+
* buildLineDefinition('base', 'Base Amount', createQuantitativeDefinition('base', 'Base', []))
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function buildLineDefinition(id: string, name: string, rate: QuantitativeDefinition, overrides?: Partial<Omit<LineDefinition, 'id' | 'name' | 'rate'>>): LineDefinition;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Builds a rated {@link LineResult} from a line's evaluated
|
|
81
|
+
* {@link QuantitativeResult}.
|
|
82
|
+
*
|
|
83
|
+
* @param definition - The authored line definition
|
|
84
|
+
* @param result - The evaluated quantitative result
|
|
85
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
86
|
+
* @returns A fresh line result
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { createQuantitativeDefinition, createQuantitativeReasoner, createReason } from '@orkestrel/reason'
|
|
91
|
+
* import { buildLineDefinition, buildLineResult } from '@orkestrel/rater'
|
|
32
92
|
*
|
|
33
|
-
* const
|
|
34
|
-
*
|
|
93
|
+
* const line = buildLineDefinition('base', 'Base', createQuantitativeDefinition('base', 'Base', []))
|
|
94
|
+
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, line.rate)
|
|
95
|
+
* if (result.reasoning === 'quantitative') buildLineResult(line, result) // amount present only on a successful worksheet
|
|
35
96
|
* ```
|
|
36
97
|
*/
|
|
37
|
-
export declare function
|
|
98
|
+
export declare function buildLineResult(definition: LineDefinition, result: QuantitativeResult, labels?: Readonly<Record<string, string>>): LineResult;
|
|
38
99
|
|
|
39
100
|
/**
|
|
40
|
-
*
|
|
101
|
+
* Builds a {@link RatingDefinition}.
|
|
102
|
+
*
|
|
103
|
+
* @param id - The rating id
|
|
104
|
+
* @param name - The display name
|
|
105
|
+
* @param lines - The rating's ordered lines
|
|
106
|
+
* @param overrides - Optional {@link RatingDefinition} fields merged over the defaults
|
|
107
|
+
* @returns A fresh rating definition
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { buildLineDefinition, buildRatingDefinition } from '@orkestrel/rater'
|
|
112
|
+
* import { createQuantitativeDefinition } from '@orkestrel/reason'
|
|
113
|
+
*
|
|
114
|
+
* buildRatingDefinition('r1', 'Rating', [
|
|
115
|
+
* buildLineDefinition('base', 'Base Amount', createQuantitativeDefinition('base', 'Base', [])),
|
|
116
|
+
* ])
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function buildRatingDefinition(id: string, name: string, lines: readonly LineDefinition[], overrides?: Partial<Omit<RatingDefinition, 'id' | 'name' | 'lines'>>): RatingDefinition;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Joins a {@link QuantitativeDefinition} and its {@link QuantitativeResult} into
|
|
123
|
+
* a {@link Worksheet} — the rating audit trail.
|
|
124
|
+
*
|
|
125
|
+
* @param definition - The authored quantitative definition
|
|
126
|
+
* @param result - The evaluated quantitative result
|
|
127
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
128
|
+
* @returns A fresh worksheet
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'
|
|
133
|
+
* import { buildWorksheet } from '@orkestrel/rater'
|
|
134
|
+
*
|
|
135
|
+
* const definition = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])
|
|
136
|
+
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)
|
|
137
|
+
* if (result.reasoning === 'quantitative') buildWorksheet(definition, result) // the full audit trail
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function buildWorksheet(definition: QuantitativeDefinition, result: QuantitativeResult, labels?: Readonly<Record<string, string>>): Worksheet;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Joins one authored quantitative factor to its evaluated {@link FactorResult}.
|
|
144
|
+
*
|
|
145
|
+
* @param definition - The authored factor
|
|
146
|
+
* @param results - The group's factor results
|
|
147
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
148
|
+
* @returns A fresh worksheet factor
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import { createFieldFactor } from '@orkestrel/reason'
|
|
153
|
+
* import { buildWorksheetFactor } from '@orkestrel/rater'
|
|
154
|
+
*
|
|
155
|
+
* const factor = createFieldFactor('seats', 'seats')
|
|
156
|
+
* buildWorksheetFactor(factor, [{ id: 'seats', applied: true, value: 10 }])
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export declare function buildWorksheetFactor(definition: Factor, results: readonly FactorResult[], labels?: Readonly<Record<string, string>>): WorksheetFactor;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Joins one authored quantitative group to its evaluated {@link GroupResult}.
|
|
163
|
+
*
|
|
164
|
+
* @param definition - The authored group
|
|
165
|
+
* @param results - The definition's group results
|
|
166
|
+
* @param labels - Optional field-to-label overrides, keyed by dot-joined field
|
|
167
|
+
* @returns A fresh worksheet group
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* import { createFactorGroup, createStaticFactor } from '@orkestrel/reason'
|
|
172
|
+
* import { buildWorksheetGroup } from '@orkestrel/rater'
|
|
173
|
+
*
|
|
174
|
+
* const group = createFactorGroup('charge', 'sum', [createStaticFactor('base', 100)])
|
|
175
|
+
* buildWorksheetGroup(group, [{ id: 'charge', applied: true, value: 100, factors: [] }])
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function buildWorksheetGroup(definition: QuantitativeDefinition['groups'][number], results: readonly GroupResult[], labels?: Readonly<Record<string, string>>): WorksheetGroup;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Builds one display-neutral {@link Step} row.
|
|
182
|
+
*
|
|
183
|
+
* @param stage - The step's stage
|
|
184
|
+
* @param id - The stage's authored id, when it has one
|
|
185
|
+
* @param name - The stage's authored name, when it has one
|
|
186
|
+
* @param value - The stage's resolved value
|
|
187
|
+
* @param expression - A display-neutral expression string
|
|
188
|
+
* @returns A fresh step
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* import { buildWorksheetStep } from '@orkestrel/rater'
|
|
193
|
+
*
|
|
194
|
+
* buildWorksheetStep('total', 'quote', 'Quote', 110, 'sum = 110')
|
|
195
|
+
* // { stage: 'total', id: 'quote', name: 'Quote', value: 110, expression: 'sum = 110' }
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function buildWorksheetStep(stage: Stage, id: string | undefined, name: string | undefined, value: number, expression: string): Step;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Builds the ordered {@link Step} rows for a resolved {@link Worksheet}.
|
|
202
|
+
*
|
|
203
|
+
* @param definition - The authored quantitative definition
|
|
204
|
+
* @param result - The evaluated quantitative result
|
|
205
|
+
* @param groups - The definition's already-joined worksheet groups
|
|
206
|
+
* @returns A fresh, ordered list of steps: applied factors, then groups, then the total
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'
|
|
211
|
+
* import { buildWorksheetGroup, buildWorksheetSteps } from '@orkestrel/rater'
|
|
212
|
+
*
|
|
213
|
+
* const definition = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])
|
|
214
|
+
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)
|
|
215
|
+
* if (result.reasoning === 'quantitative') {
|
|
216
|
+
* buildWorksheetSteps(definition, result, definition.groups.map((group) => buildWorksheetGroup(group, result.groups)))
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function buildWorksheetSteps(definition: QuantitativeDefinition, result: QuantitativeResult, groups: readonly WorksheetGroup[]): readonly Step[];
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Creates a rating orchestrator.
|
|
41
224
|
*
|
|
42
225
|
* @param options - Optional total handler, labels, injected engine, and emitter hooks
|
|
43
226
|
* @returns A {@link RaterInterface}
|
|
@@ -52,7 +235,7 @@ export declare function checkEvidence(checks: readonly Check[] | undefined, resu
|
|
|
52
235
|
*/
|
|
53
236
|
export declare function createRater(options?: RaterOptions): RaterInterface;
|
|
54
237
|
|
|
55
|
-
/**
|
|
238
|
+
/** Represents a checked-evidence row rendered into a display-neutral sentence. */
|
|
56
239
|
export declare interface Evidence {
|
|
57
240
|
readonly field?: FieldPath;
|
|
58
241
|
readonly label?: string;
|
|
@@ -63,27 +246,7 @@ export declare interface Evidence {
|
|
|
63
246
|
}
|
|
64
247
|
|
|
65
248
|
/**
|
|
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.
|
|
249
|
+
* Determines whether a value is an open result-side {@link Evidence} object.
|
|
87
250
|
*
|
|
88
251
|
* @remarks
|
|
89
252
|
* Unknown members, prototypes, and class instances are admitted. Arrays are
|
|
@@ -92,7 +255,7 @@ export declare function evidenceCheck(check: Check, actual: unknown, met: boolea
|
|
|
92
255
|
* members rather than requiring or enumerating own keys.
|
|
93
256
|
*
|
|
94
257
|
* @param value - The value to test
|
|
95
|
-
* @returns
|
|
258
|
+
* @returns True if every checked `Evidence` member conforms; false otherwise
|
|
96
259
|
*
|
|
97
260
|
* @example
|
|
98
261
|
* ```ts
|
|
@@ -104,50 +267,51 @@ export declare function evidenceCheck(check: Check, actual: unknown, met: boolea
|
|
|
104
267
|
export declare function isEvidence(value: unknown): value is Evidence;
|
|
105
268
|
|
|
106
269
|
/**
|
|
107
|
-
*
|
|
270
|
+
* Determines whether a value is an exact {@link LineDefinition} record.
|
|
108
271
|
*
|
|
109
272
|
* @remarks
|
|
110
|
-
* Total guard
|
|
111
|
-
*
|
|
273
|
+
* Total guard: adversarial input (cycles, hostile prototypes) returns `false`,
|
|
274
|
+
* never throws. The record shape is EXACT — an extra key fails.
|
|
112
275
|
*
|
|
113
276
|
* @param value - The value to test
|
|
114
|
-
* @returns
|
|
277
|
+
* @returns True if `value` is a `LineDefinition`; false otherwise
|
|
115
278
|
*
|
|
116
279
|
* @example
|
|
117
280
|
* ```ts
|
|
118
|
-
* import {
|
|
281
|
+
* import { createQuantitativeDefinition } from '@orkestrel/reason'
|
|
119
282
|
* import { isLineDefinition } from '@orkestrel/rater'
|
|
120
283
|
*
|
|
121
|
-
* isLineDefinition({ id: 'base', name: 'Base', rate:
|
|
284
|
+
* isLineDefinition({ id: 'base', name: 'Base', rate: createQuantitativeDefinition('base', 'Base', []) }) // true
|
|
122
285
|
* ```
|
|
123
286
|
*/
|
|
124
287
|
export declare function isLineDefinition(value: unknown): value is LineDefinition;
|
|
125
288
|
|
|
126
289
|
/**
|
|
127
|
-
*
|
|
290
|
+
* Determines whether a value is an open {@link LineResult} object.
|
|
128
291
|
*
|
|
129
292
|
* @remarks
|
|
130
293
|
* Unknown members, prototypes, and class instances are admitted. Arrays are
|
|
131
294
|
* refused. `amount` may be absent or read as `undefined`; when present it stays
|
|
132
|
-
* a plain JavaScript `number` without a finite or range refinement.
|
|
295
|
+
* a plain JavaScript `number` without a finite or range refinement. The line's
|
|
296
|
+
* outcome lives on `worksheet`, so `worksheet.success` carries it.
|
|
133
297
|
*
|
|
134
298
|
* @param value - The value to test
|
|
135
|
-
* @returns
|
|
299
|
+
* @returns True if every published line-result member conforms; false otherwise
|
|
136
300
|
*
|
|
137
301
|
* @example
|
|
138
302
|
* ```ts
|
|
139
303
|
* import { isLineResult } from '@orkestrel/rater'
|
|
140
304
|
*
|
|
141
|
-
* isLineResult({ id: 'base', name: 'Base', worksheet: { id: 'base', name: 'Base', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], errors: [], success: false }
|
|
305
|
+
* isLineResult({ id: 'base', name: 'Base', worksheet: { id: 'base', name: 'Base', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], errors: [], success: false } }) // true
|
|
142
306
|
* ```
|
|
143
307
|
*/
|
|
144
308
|
export declare function isLineResult(value: unknown): value is LineResult;
|
|
145
309
|
|
|
146
310
|
/**
|
|
147
|
-
*
|
|
311
|
+
* Narrows a caught value to a {@link RaterError}.
|
|
148
312
|
*
|
|
149
313
|
* @param value - The caught value to test
|
|
150
|
-
* @returns
|
|
314
|
+
* @returns True if `value` is a `RaterError`; false otherwise
|
|
151
315
|
*
|
|
152
316
|
* @example
|
|
153
317
|
* ```ts
|
|
@@ -163,14 +327,14 @@ export declare function isLineResult(value: unknown): value is LineResult;
|
|
|
163
327
|
export declare function isRaterError(value: unknown): value is RaterError;
|
|
164
328
|
|
|
165
329
|
/**
|
|
166
|
-
*
|
|
330
|
+
* Determines whether a value is an exact {@link RatingDefinition} record.
|
|
167
331
|
*
|
|
168
332
|
* @remarks
|
|
169
|
-
* Total guard
|
|
170
|
-
*
|
|
333
|
+
* Total guard: adversarial input (cycles, hostile prototypes) returns `false`,
|
|
334
|
+
* never throws. The record shape is EXACT — an extra key fails.
|
|
171
335
|
*
|
|
172
336
|
* @param value - The value to test
|
|
173
|
-
* @returns
|
|
337
|
+
* @returns True if `value` is a `RatingDefinition`; false otherwise
|
|
174
338
|
*
|
|
175
339
|
* @example
|
|
176
340
|
* ```ts
|
|
@@ -182,7 +346,7 @@ export declare function isRaterError(value: unknown): value is RaterError;
|
|
|
182
346
|
export declare function isRatingDefinition(value: unknown): value is RatingDefinition;
|
|
183
347
|
|
|
184
348
|
/**
|
|
185
|
-
*
|
|
349
|
+
* Determines whether a value is an open {@link RatingResult} object.
|
|
186
350
|
*
|
|
187
351
|
* @remarks
|
|
188
352
|
* Use this guard for a result returned by a borrowed `RaterInterface`. Unknown
|
|
@@ -191,7 +355,7 @@ export declare function isRatingDefinition(value: unknown): value is RatingDefin
|
|
|
191
355
|
* JavaScript `number` without a finite or range refinement.
|
|
192
356
|
*
|
|
193
357
|
* @param value - The value to test
|
|
194
|
-
* @returns
|
|
358
|
+
* @returns True if every published rating-result member conforms; false otherwise
|
|
195
359
|
*
|
|
196
360
|
* @example
|
|
197
361
|
* ```ts
|
|
@@ -203,10 +367,10 @@ export declare function isRatingDefinition(value: unknown): value is RatingDefin
|
|
|
203
367
|
export declare function isRatingResult(value: unknown): value is RatingResult;
|
|
204
368
|
|
|
205
369
|
/**
|
|
206
|
-
*
|
|
370
|
+
* Determines whether a value is a {@link Stage} literal.
|
|
207
371
|
*
|
|
208
372
|
* @param value - The value to test
|
|
209
|
-
* @returns
|
|
373
|
+
* @returns True if `value` is `'factor'`, `'group'`, or `'total'`; false otherwise
|
|
210
374
|
*
|
|
211
375
|
* @example
|
|
212
376
|
* ```ts
|
|
@@ -219,14 +383,14 @@ export declare function isRatingResult(value: unknown): value is RatingResult;
|
|
|
219
383
|
export declare const isStage: Guard<Stage>;
|
|
220
384
|
|
|
221
385
|
/**
|
|
222
|
-
*
|
|
386
|
+
* Determines whether a value is an open {@link Step} result object.
|
|
223
387
|
*
|
|
224
388
|
* @remarks
|
|
225
389
|
* Unknown members, prototypes, and class instances are admitted. Arrays are
|
|
226
390
|
* refused. Optional members may be absent or read as `undefined`.
|
|
227
391
|
*
|
|
228
392
|
* @param value - The value to test
|
|
229
|
-
* @returns
|
|
393
|
+
* @returns True if every published worksheet-step member conforms; false otherwise
|
|
230
394
|
*
|
|
231
395
|
* @example
|
|
232
396
|
* ```ts
|
|
@@ -238,14 +402,14 @@ export declare const isStage: Guard<Stage>;
|
|
|
238
402
|
export declare function isStep(value: unknown): value is Step;
|
|
239
403
|
|
|
240
404
|
/**
|
|
241
|
-
*
|
|
405
|
+
* Determines whether a value is an open {@link Worksheet} result object.
|
|
242
406
|
*
|
|
243
407
|
* @remarks
|
|
244
408
|
* Unknown members, prototypes, and class instances are admitted. Arrays are
|
|
245
409
|
* refused. Optional members may be absent or read as `undefined`.
|
|
246
410
|
*
|
|
247
411
|
* @param value - The value to test
|
|
248
|
-
* @returns
|
|
412
|
+
* @returns True if every published worksheet member conforms; false otherwise
|
|
249
413
|
*
|
|
250
414
|
* @example
|
|
251
415
|
* ```ts
|
|
@@ -257,14 +421,14 @@ export declare function isStep(value: unknown): value is Step;
|
|
|
257
421
|
export declare function isWorksheet(value: unknown): value is Worksheet;
|
|
258
422
|
|
|
259
423
|
/**
|
|
260
|
-
*
|
|
424
|
+
* Determines whether a value is an open {@link WorksheetFactor} result object.
|
|
261
425
|
*
|
|
262
426
|
* @remarks
|
|
263
427
|
* Unknown members, prototypes, and class instances are admitted. Arrays are
|
|
264
428
|
* refused. Optional members may be absent or read as `undefined`.
|
|
265
429
|
*
|
|
266
430
|
* @param value - The value to test
|
|
267
|
-
* @returns
|
|
431
|
+
* @returns True if every published worksheet-factor member conforms; false otherwise
|
|
268
432
|
*
|
|
269
433
|
* @example
|
|
270
434
|
* ```ts
|
|
@@ -276,14 +440,14 @@ export declare function isWorksheet(value: unknown): value is Worksheet;
|
|
|
276
440
|
export declare function isWorksheetFactor(value: unknown): value is WorksheetFactor;
|
|
277
441
|
|
|
278
442
|
/**
|
|
279
|
-
*
|
|
443
|
+
* Determines whether a value is an open {@link WorksheetGroup} result object.
|
|
280
444
|
*
|
|
281
445
|
* @remarks
|
|
282
446
|
* Unknown members, prototypes, and class instances are admitted. Arrays are
|
|
283
447
|
* refused. Optional members may be absent or read as `undefined`.
|
|
284
448
|
*
|
|
285
449
|
* @param value - The value to test
|
|
286
|
-
* @returns
|
|
450
|
+
* @returns True if every published worksheet-group member conforms; false otherwise
|
|
287
451
|
*
|
|
288
452
|
* @example
|
|
289
453
|
* ```ts
|
|
@@ -295,7 +459,7 @@ export declare function isWorksheetFactor(value: unknown): value is WorksheetFac
|
|
|
295
459
|
export declare function isWorksheetGroup(value: unknown): value is WorksheetGroup;
|
|
296
460
|
|
|
297
461
|
/**
|
|
298
|
-
*
|
|
462
|
+
* Represents one rateable line — a quantitative definition joined to display metadata.
|
|
299
463
|
*
|
|
300
464
|
* @remarks
|
|
301
465
|
* `rate` is a plain reason {@link QuantitativeDefinition}; Rater delegates every
|
|
@@ -310,73 +474,33 @@ export declare interface LineDefinition {
|
|
|
310
474
|
}
|
|
311
475
|
|
|
312
476
|
/**
|
|
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.
|
|
477
|
+
* Represents one line's rating outcome.
|
|
333
478
|
*
|
|
334
479
|
* @remarks
|
|
335
480
|
* `worksheet` is always present — even a failed evaluation resolves to a
|
|
336
481
|
* type-shaped failure worksheet, so a `LineResult` is always constructible.
|
|
337
|
-
*
|
|
482
|
+
* The worksheet also carries the line's outcome: `amount` is present ONLY
|
|
483
|
+
* when `worksheet.success` is `true`.
|
|
338
484
|
*/
|
|
339
485
|
export declare interface LineResult {
|
|
340
486
|
readonly id: string;
|
|
341
487
|
readonly name: string;
|
|
342
488
|
readonly amount?: number;
|
|
343
489
|
readonly worksheet: Worksheet;
|
|
344
|
-
readonly success: boolean;
|
|
345
490
|
}
|
|
346
491
|
|
|
347
492
|
/**
|
|
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
|
|
493
|
+
* Orchestrates rating — owns (or receives) the shared quantitative
|
|
370
494
|
* reasoning engine and projects results into the rating domain vocabulary.
|
|
371
495
|
*
|
|
372
496
|
* @remarks
|
|
373
497
|
* When no `engine` is injected, `Rater` builds and OWNS its own
|
|
374
498
|
* quantitative-only engine (`bail: false`) — Rater performs NO evaluation
|
|
375
499
|
* arithmetic of its own; it only orchestrates and projects. The
|
|
376
|
-
* array-of-lines `rate` overload is declared FIRST
|
|
377
|
-
* destroys an OWNED engine, then the
|
|
378
|
-
* engine is never destroyed. Afterwards every
|
|
379
|
-
* {@link RaterError} `'DESTROYED'`.
|
|
500
|
+
* array-of-lines `rate` overload is declared FIRST so a plain line list
|
|
501
|
+
* resolves to that form. `destroy()` destroys an OWNED engine, then the
|
|
502
|
+
* emitter LAST; an INJECTED engine is never destroyed. Afterwards every
|
|
503
|
+
* other method throws {@link RaterError} `'DESTROYED'`.
|
|
380
504
|
*
|
|
381
505
|
* @example
|
|
382
506
|
* ```ts
|
|
@@ -397,7 +521,7 @@ export declare class Rater implements RaterInterface {
|
|
|
397
521
|
}
|
|
398
522
|
|
|
399
523
|
/**
|
|
400
|
-
*
|
|
524
|
+
* Represents a coded programmer error thrown by the rating layer.
|
|
401
525
|
*
|
|
402
526
|
* @remarks
|
|
403
527
|
* `DEFINITION` — the `rate` input failed both the array-of-lines and rating
|
|
@@ -417,26 +541,27 @@ export declare class RaterError extends Error {
|
|
|
417
541
|
constructor(code: RaterErrorCode, message: string, context?: Readonly<Record<string, unknown>>);
|
|
418
542
|
}
|
|
419
543
|
|
|
420
|
-
/**
|
|
544
|
+
/** Names a coded {@link RaterError} programmer-error code. */
|
|
421
545
|
export declare type RaterErrorCode = 'DEFINITION' | 'MISMATCH' | 'DESTROYED';
|
|
422
546
|
|
|
423
547
|
/**
|
|
424
|
-
*
|
|
548
|
+
* Represents the push observation surface of a {@link RaterInterface}.
|
|
425
549
|
*
|
|
426
550
|
* @remarks
|
|
427
551
|
* `rate` fires once per `rate` call, carrying the rated subject and the result.
|
|
428
552
|
*/
|
|
429
553
|
export declare type RaterEventMap = {
|
|
430
|
-
/**
|
|
554
|
+
/** Fires when a subject is rated — carries the subject and its result. */
|
|
431
555
|
readonly rate: readonly [subject: Subject, result: RatingResult];
|
|
432
556
|
};
|
|
433
557
|
|
|
434
558
|
/**
|
|
435
|
-
*
|
|
559
|
+
* Represents the rating orchestrator over the shared quantitative reasoning engine.
|
|
436
560
|
*
|
|
437
561
|
* @remarks
|
|
438
|
-
* The array-of-lines `rate` overload is declared FIRST
|
|
439
|
-
* overloads rate a SINGLE subject — there is no
|
|
562
|
+
* The array-of-lines `rate` overload is declared FIRST so a plain line list
|
|
563
|
+
* resolves to that form. Both overloads rate a SINGLE subject — there is no
|
|
564
|
+
* batch-of-subjects overload.
|
|
440
565
|
*/
|
|
441
566
|
export declare interface RaterInterface {
|
|
442
567
|
readonly emitter: EmitterInterface<RaterEventMap>;
|
|
@@ -446,7 +571,7 @@ export declare interface RaterInterface {
|
|
|
446
571
|
}
|
|
447
572
|
|
|
448
573
|
/**
|
|
449
|
-
*
|
|
574
|
+
* Configures `createRater` and the `Rater` constructor.
|
|
450
575
|
*
|
|
451
576
|
* @remarks
|
|
452
577
|
* `engine` — an injected {@link ReasonInterface}; when omitted, `Rater` builds
|
|
@@ -464,7 +589,7 @@ export declare interface RaterOptions {
|
|
|
464
589
|
}
|
|
465
590
|
|
|
466
591
|
/**
|
|
467
|
-
*
|
|
592
|
+
* Represents a pure authored rating — a named, ordered set of lines.
|
|
468
593
|
*
|
|
469
594
|
* @remarks
|
|
470
595
|
* `rate` accepts either a plain `readonly LineDefinition[]` or a full
|
|
@@ -480,33 +605,12 @@ export declare interface RatingDefinition {
|
|
|
480
605
|
}
|
|
481
606
|
|
|
482
607
|
/**
|
|
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.
|
|
608
|
+
* Represents a rated outcome across every line of one `rate` call.
|
|
505
609
|
*
|
|
506
610
|
* @remarks
|
|
507
611
|
* `total` is derived by the {@link TotalHandler} (default {@link sumAmounts})
|
|
508
612
|
* over `lines` — only successfully rated lines carry an `amount`. `success`
|
|
509
|
-
* is `true` only when every line
|
|
613
|
+
* is `true` only when every line's `worksheet.success` is `true`.
|
|
510
614
|
*/
|
|
511
615
|
export declare interface RatingResult {
|
|
512
616
|
readonly lines: readonly LineResult[];
|
|
@@ -514,31 +618,10 @@ export declare interface RatingResult {
|
|
|
514
618
|
readonly success: boolean;
|
|
515
619
|
}
|
|
516
620
|
|
|
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. */
|
|
621
|
+
/** Names a worksheet derivation step stage. */
|
|
539
622
|
export declare type Stage = 'factor' | 'group' | 'total';
|
|
540
623
|
|
|
541
|
-
/**
|
|
624
|
+
/** Represents a display-neutral worksheet derivation step. */
|
|
542
625
|
export declare interface Step {
|
|
543
626
|
readonly stage: Stage;
|
|
544
627
|
readonly id?: string;
|
|
@@ -548,28 +631,28 @@ export declare interface Step {
|
|
|
548
631
|
}
|
|
549
632
|
|
|
550
633
|
/**
|
|
551
|
-
*
|
|
634
|
+
* Sums defined line amounts.
|
|
552
635
|
*
|
|
553
636
|
* @param lines - The rated lines
|
|
554
637
|
* @returns The sum of every line's `amount`, or `undefined` when no line has one
|
|
555
638
|
*
|
|
556
639
|
* @example
|
|
557
640
|
* ```ts
|
|
558
|
-
* import {
|
|
559
|
-
* import {
|
|
641
|
+
* import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'
|
|
642
|
+
* import { buildLineDefinition, buildLineResult, sumAmounts } from '@orkestrel/rater'
|
|
560
643
|
*
|
|
561
|
-
* const rate =
|
|
562
|
-
* const line =
|
|
644
|
+
* const rate = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])
|
|
645
|
+
* const line = buildLineDefinition('base', 'Base', rate)
|
|
563
646
|
* const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, rate)
|
|
564
|
-
* if (result.reasoning === 'quantitative') sumAmounts([
|
|
647
|
+
* if (result.reasoning === 'quantitative') sumAmounts([buildLineResult(line, result)]) // 100
|
|
565
648
|
* ```
|
|
566
649
|
*/
|
|
567
650
|
export declare function sumAmounts(lines: readonly LineResult[]): number | undefined;
|
|
568
651
|
|
|
569
|
-
/**
|
|
652
|
+
/** Represents a pure total port over resolved lines. */
|
|
570
653
|
export declare type TotalHandler = (lines: readonly LineResult[]) => number | undefined;
|
|
571
654
|
|
|
572
|
-
/**
|
|
655
|
+
/** Represents a quantitative definition joined to its result — the rating audit trail. */
|
|
573
656
|
export declare interface Worksheet {
|
|
574
657
|
readonly id: string;
|
|
575
658
|
readonly name: string;
|
|
@@ -583,7 +666,7 @@ export declare interface Worksheet {
|
|
|
583
666
|
readonly success: boolean;
|
|
584
667
|
}
|
|
585
668
|
|
|
586
|
-
/**
|
|
669
|
+
/** Represents a resolved quantitative factor, joined to its authored metadata. */
|
|
587
670
|
export declare interface WorksheetFactor {
|
|
588
671
|
readonly id: string;
|
|
589
672
|
readonly name?: string;
|
|
@@ -593,26 +676,7 @@ export declare interface WorksheetFactor {
|
|
|
593
676
|
readonly evidence: readonly Evidence[];
|
|
594
677
|
}
|
|
595
678
|
|
|
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. */
|
|
679
|
+
/** Represents a resolved quantitative group, joined to its authored metadata. */
|
|
616
680
|
export declare interface WorksheetGroup {
|
|
617
681
|
readonly id: string;
|
|
618
682
|
readonly name?: string;
|
|
@@ -622,65 +686,4 @@ export declare interface WorksheetGroup {
|
|
|
622
686
|
readonly factors: readonly WorksheetFactor[];
|
|
623
687
|
}
|
|
624
688
|
|
|
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
689
|
export { }
|