@orkestrel/reason 0.0.9 → 0.0.10
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 +15 -19
- package/dist/src/core/index.cjs +243 -218
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +610 -281
- package/dist/src/core/index.d.ts +610 -281
- package/dist/src/core/index.js +243 -218
- package/dist/src/core/index.js.map +1 -1
- package/package.json +9 -10
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
4
|
-
import { FieldPath } from '@orkestrel/contract';
|
|
5
|
-
import { Guard } from '@orkestrel/contract';
|
|
1
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
2
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
3
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
4
|
+
import type { FieldPath } from '@orkestrel/contract';
|
|
5
|
+
import type { Guard } from '@orkestrel/contract';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Upserts one entry of a {@link SymbolicDefinition}'s `variables`.
|
|
@@ -40,11 +40,11 @@ export declare type Aggregation = 'sum' | 'product' | 'average' | 'minimum' | 'm
|
|
|
40
40
|
* reasoner's group and definition combiner.
|
|
41
41
|
*
|
|
42
42
|
* @remarks
|
|
43
|
-
*
|
|
43
|
+
* Total: never throws. Empty-input identities: `sum` / `average` → `0`,
|
|
44
44
|
* `product` → `1`, `minimum` / `maximum` → `NaN` (the deliberate "no data"
|
|
45
|
-
* signal). Weights are honored
|
|
45
|
+
* signal). Weights are honored only when their length matches `values` exactly
|
|
46
46
|
* (otherwise silently unweighted): a weight multiplies into a `sum`, acts as an
|
|
47
|
-
*
|
|
47
|
+
* exponent for a `product`, is the weight of a weighted mean for `average`
|
|
48
48
|
* (a zero total weight yields `0`, never a division blow-up), and is ignored by
|
|
49
49
|
* `minimum` / `maximum`. An unknown aggregation yields `0`. Stateless and
|
|
50
50
|
* deterministic.
|
|
@@ -72,11 +72,15 @@ export declare const AGGREGATOR_ID = "aggregator";
|
|
|
72
72
|
*
|
|
73
73
|
* @remarks
|
|
74
74
|
* Total: never throws. Empty-input identities: `sum` / `average` → `0`,
|
|
75
|
-
* `product` → `1`, `minimum` / `maximum` → `NaN`. `weights` are honored
|
|
75
|
+
* `product` → `1`, `minimum` / `maximum` → `NaN`. `weights` are honored only
|
|
76
76
|
* when their length matches `values` exactly (otherwise silently unweighted).
|
|
77
77
|
*/
|
|
78
78
|
export declare interface AggregatorInterface {
|
|
79
79
|
readonly id: string;
|
|
80
|
+
/**
|
|
81
|
+
* Reduces the values per aggregation; `weights` are honored only on an exact length match,
|
|
82
|
+
* and `minimum` / `maximum` ignore them.
|
|
83
|
+
*/
|
|
80
84
|
aggregate(values: readonly number[], aggregation: Aggregation, weights?: readonly number[]): number;
|
|
81
85
|
}
|
|
82
86
|
|
|
@@ -92,15 +96,15 @@ export declare interface AggregatorOptions {
|
|
|
92
96
|
|
|
93
97
|
/**
|
|
94
98
|
* Inserts `item` into an id-keyed collection, deduping any existing element
|
|
95
|
-
* sharing its id, then placing it at the
|
|
99
|
+
* sharing its id, then placing it at the end, or immediately after `target`.
|
|
96
100
|
*
|
|
97
101
|
* @remarks
|
|
98
|
-
* Insertion
|
|
102
|
+
* Insertion dedupes on the id first: `filtered` is `items` with every `item.id`
|
|
99
103
|
* twin removed, because an input array may already carry same-id twins.
|
|
100
|
-
* Re-appending an existing id therefore
|
|
104
|
+
* Re-appending an existing id therefore repositions it rather than updating it
|
|
101
105
|
* in place — {@link replaceById} is the position-preserving alternative. With
|
|
102
106
|
* no `target`, `item` lands at the end; with a `target`, it lands immediately
|
|
103
|
-
* after the element whose `id === target` (searched in the
|
|
107
|
+
* after the element whose `id === target` (searched in the deduped array). A
|
|
104
108
|
* `target` naming no element throws {@link ReasonError} (`'TARGET'`).
|
|
105
109
|
*
|
|
106
110
|
* @typeParam T - An id-carrying element type
|
|
@@ -127,8 +131,8 @@ export declare interface AggregatorOptions {
|
|
|
127
131
|
* then-insert at the end, or immediately after `target`.
|
|
128
132
|
*
|
|
129
133
|
* @remarks
|
|
130
|
-
* Order is
|
|
131
|
-
*
|
|
134
|
+
* Order is load-bearing: equations solve strictly in order and each rounded
|
|
135
|
+
* solution feeds forward.
|
|
132
136
|
*
|
|
133
137
|
* @param definition - The definition to insert into
|
|
134
138
|
* @param equation - The equation to insert
|
|
@@ -150,7 +154,7 @@ export declare interface AggregatorOptions {
|
|
|
150
154
|
* insert at the end, or immediately after `target`.
|
|
151
155
|
*
|
|
152
156
|
* @remarks
|
|
153
|
-
* `Fact.id` is an
|
|
157
|
+
* `Fact.id` is an authoring label — the runtime content-dedups facts by
|
|
154
158
|
* predicate+arity+terms ({@link factToKey}), independently of this helper's
|
|
155
159
|
* id-keyed dedup.
|
|
156
160
|
*
|
|
@@ -174,9 +178,9 @@ export declare interface AggregatorOptions {
|
|
|
174
178
|
* at the end, or immediately after `target`.
|
|
175
179
|
*
|
|
176
180
|
* @remarks
|
|
177
|
-
* Factor order is
|
|
181
|
+
* Factor order is load-bearing: the same-priority tiebreak is declaration
|
|
178
182
|
* order ({@link sortByPriority} is a stable ascending sort). Operates on the
|
|
179
|
-
* factor's
|
|
183
|
+
* factor's direct container — compose into a definition through
|
|
180
184
|
* `appendGroup(def, appendFactor(group, factor))`.
|
|
181
185
|
*
|
|
182
186
|
* @param group - The group to insert into
|
|
@@ -199,7 +203,7 @@ export declare interface AggregatorOptions {
|
|
|
199
203
|
* insert at the end, or immediately after `target`.
|
|
200
204
|
*
|
|
201
205
|
* @remarks
|
|
202
|
-
* Group order is
|
|
206
|
+
* Group order is cosmetic (group aggregation is order-independent) but honored
|
|
203
207
|
* uniformly, same as every `append*` helper. Composes with {@link appendFactor}:
|
|
204
208
|
* `appendGroup(def, appendFactor(group, factor))`.
|
|
205
209
|
*
|
|
@@ -223,7 +227,7 @@ export declare interface AggregatorOptions {
|
|
|
223
227
|
* dedup-then-insert at the end, or immediately after `target`.
|
|
224
228
|
*
|
|
225
229
|
* @remarks
|
|
226
|
-
* Order is
|
|
230
|
+
* Order is load-bearing: backward proving iterates in declaration order and
|
|
227
231
|
* returns on first success.
|
|
228
232
|
*
|
|
229
233
|
* @param definition - The definition to insert into
|
|
@@ -249,7 +253,7 @@ export declare interface AggregatorOptions {
|
|
|
249
253
|
* at the end, or immediately after `target`.
|
|
250
254
|
*
|
|
251
255
|
* @remarks
|
|
252
|
-
* Order is
|
|
256
|
+
* Order is load-bearing: the forward conclusion is the last declared
|
|
253
257
|
* non-disabled rule, so `appendRule` without a `target` makes the new rule the
|
|
254
258
|
* conclusion.
|
|
255
259
|
*
|
|
@@ -277,7 +281,7 @@ export declare interface AggregatorOptions {
|
|
|
277
281
|
* by zero is `NaN` (never a throw), the unary operations (`round` / `ceil` /
|
|
278
282
|
* `floor` / `abs`) ignore `right`, and `percentage` is `left * (right / 100)`.
|
|
279
283
|
* `operator` is typed `string` because untrusted definitions reach here
|
|
280
|
-
* unchecked; the
|
|
284
|
+
* unchecked; the only throwing path is the unknown-operator default, which
|
|
281
285
|
* throws `ReasonError('OPERATOR', …, { operator })` and is caught per equation
|
|
282
286
|
* upstream.
|
|
283
287
|
*
|
|
@@ -301,7 +305,7 @@ export declare interface AggregatorOptions {
|
|
|
301
305
|
* Upserts one field of a {@link Subject} — copy-on-write spread.
|
|
302
306
|
*
|
|
303
307
|
* @remarks
|
|
304
|
-
* Named `assignField` rather than `setField` because it
|
|
308
|
+
* Named `assignField` rather than `setField` because it returns a fresh subject
|
|
305
309
|
* instead of writing into the one it is given — `set*` reads as an in-place
|
|
306
310
|
* write. Id-agnostic: overwrites an `id` key like any other field — id
|
|
307
311
|
* protection is an entity's job, not this helper's.
|
|
@@ -371,7 +375,7 @@ export declare interface AggregatorOptions {
|
|
|
371
375
|
* to `value` with `operator`.
|
|
372
376
|
*
|
|
373
377
|
* @remarks
|
|
374
|
-
* `field` follows the {@link FieldPath} idiom — a string is
|
|
378
|
+
* `field` follows the {@link FieldPath} idiom — a string is a single key (never
|
|
375
379
|
* dot-split), an array descends into nested objects. `value` is unconstrained
|
|
376
380
|
* (`unknown`): the operator decides what shapes are meaningful.
|
|
377
381
|
*/
|
|
@@ -386,7 +390,7 @@ export declare interface AggregatorOptions {
|
|
|
386
390
|
*
|
|
387
391
|
* @remarks
|
|
388
392
|
* `actual` is the resolved subject value (possibly `undefined`); `error` is set
|
|
389
|
-
*
|
|
393
|
+
* only when evaluation itself failed (an unknown operator) — a merely-unmet
|
|
390
394
|
* check carries no `error`.
|
|
391
395
|
*/
|
|
392
396
|
export declare interface CheckResult {
|
|
@@ -491,12 +495,12 @@ export declare interface AggregatorOptions {
|
|
|
491
495
|
*
|
|
492
496
|
* @remarks
|
|
493
497
|
* `equals` / `not` — strict `===` / `!==` (no coercion). `above` / `below` /
|
|
494
|
-
* `from` / `to` — `>` / `<` / `>=` / `<=`, requiring
|
|
498
|
+
* `from` / `to` — `>` / `<` / `>=` / `<=`, requiring a number on each side
|
|
495
499
|
* (anything else is not met). `any` / `none` — array membership / non-membership
|
|
496
|
-
* (a non-array expected value is
|
|
500
|
+
* (a non-array expected value is met by neither — `none` is not the raw
|
|
497
501
|
* complement of `any` on malformed input). `between` / `outside` — inclusive
|
|
498
502
|
* range test on the first two numeric elements of the expected array; `outside`
|
|
499
|
-
*
|
|
503
|
+
* is the pure negation of `between`, so a malformed range is `outside`.
|
|
500
504
|
*/
|
|
501
505
|
export declare type Comparison = 'equals' | 'not' | 'above' | 'below' | 'from' | 'to' | 'any' | 'none' | 'between' | 'outside';
|
|
502
506
|
|
|
@@ -509,7 +513,7 @@ export declare interface AggregatorOptions {
|
|
|
509
513
|
|
|
510
514
|
/**
|
|
511
515
|
* Computes the confidence a set of matched premises contributes to a derived
|
|
512
|
-
* fact — the product of each premise's
|
|
516
|
+
* fact — the product of each premise's first matching fact's confidence.
|
|
513
517
|
*
|
|
514
518
|
* @remarks
|
|
515
519
|
* The confidence half of the inferential reasoner's forward derivation: each
|
|
@@ -541,7 +545,7 @@ export declare interface AggregatorOptions {
|
|
|
541
545
|
* inferential chaining.
|
|
542
546
|
*
|
|
543
547
|
* @remarks
|
|
544
|
-
* Fixed — unlike {@link DEFAULT_PRECISION} it is
|
|
548
|
+
* Fixed — unlike {@link DEFAULT_PRECISION} it is not overridable per
|
|
545
549
|
* definition, so confidence products stay comparable across derivations.
|
|
546
550
|
*/
|
|
547
551
|
export declare const CONFIDENCE_PRECISION = 4;
|
|
@@ -553,21 +557,21 @@ export declare interface AggregatorOptions {
|
|
|
553
557
|
}
|
|
554
558
|
|
|
555
559
|
/**
|
|
556
|
-
* Determines whether a symbolic expression contains an
|
|
560
|
+
* Determines whether a symbolic expression contains an unbound occurrence of a
|
|
557
561
|
* target variable.
|
|
558
562
|
*
|
|
559
563
|
* @remarks
|
|
560
564
|
* The variable-presence probe of the symbolic reasoner's isolation: a `variable`
|
|
561
|
-
* node matches only when its name is `target`
|
|
565
|
+
* node matches only when its name is `target` and `target` is not already in
|
|
562
566
|
* `bindings` (a pre-bound target is a known value, not an unknown to isolate); a
|
|
563
567
|
* `constant` never matches; an `operation` recurses into both operands (the
|
|
564
|
-
* `right` operand may be absent on a unary node). The walk is an
|
|
568
|
+
* `right` operand may be absent on a unary node). The walk is an iterative
|
|
565
569
|
* worklist (never recursive) with short-circuit `true` on the first hit, so it
|
|
566
570
|
* stays total on pathologically deep expression trees.
|
|
567
571
|
*
|
|
568
572
|
* @param expression - The expression to probe
|
|
569
573
|
* @param target - The variable name being sought
|
|
570
|
-
* @param bindings - The known bindings (a bound target does
|
|
574
|
+
* @param bindings - The known bindings (a bound target does not count as present)
|
|
571
575
|
* @returns True if an unbound `target` occurs in the expression; false otherwise
|
|
572
576
|
*
|
|
573
577
|
* @example
|
|
@@ -620,7 +624,7 @@ export declare interface AggregatorOptions {
|
|
|
620
624
|
* Creates a {@link Bounds} — an inclusive numeric clamp.
|
|
621
625
|
*
|
|
622
626
|
* @remarks
|
|
623
|
-
* Absent sides are
|
|
627
|
+
* Absent sides are omitted (never set to `undefined`) — an absent bound is
|
|
624
628
|
* unbounded on that side.
|
|
625
629
|
*
|
|
626
630
|
* @param minimum - The inclusive lower bound
|
|
@@ -640,7 +644,7 @@ export declare interface AggregatorOptions {
|
|
|
640
644
|
/**
|
|
641
645
|
* Creates a {@link Check} — one field predicate.
|
|
642
646
|
*
|
|
643
|
-
* @param field - The subject field to resolve (a string is
|
|
647
|
+
* @param field - The subject field to resolve (a string is a single key; an array descends)
|
|
644
648
|
* @param operator - The comparison to apply
|
|
645
649
|
* @param value - The expected value (any type — the operator decides what is meaningful)
|
|
646
650
|
* @returns A fresh check
|
|
@@ -692,15 +696,14 @@ export declare interface AggregatorOptions {
|
|
|
692
696
|
* `variables`, `facts`, and `inferences` self-owning manager properties.
|
|
693
697
|
*
|
|
694
698
|
* @remarks
|
|
695
|
-
* `id`. Default: `seed.id`. Each manager slot
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
* @param seed - The starting definition (any of the four reasoning kinds)
|
|
699
|
+
* `id`. Default: `seed.id`. Each manager slot takes the manager the caller
|
|
700
|
+
* supplies, or a fresh one seeded from the seed's matching collection. `on` —
|
|
701
|
+
* initial event listeners. `error` — the emitter's listener-error handler.
|
|
702
|
+
* Mutate through the manager properties (`groups` / `factors` / `rules` /
|
|
703
|
+
* `equations` / `variables` / `facts` / `inferences`) and `merge` / `clear`,
|
|
704
|
+
* then call `build()` to produce a fresh, plain {@link Definition} snapshot.
|
|
705
|
+
*
|
|
706
|
+
* @param seed - The starting definition, of any reasoning
|
|
704
707
|
* @param options - Optional `id` override, manager injections, and emitter hooks
|
|
705
708
|
* @returns A {@link DefinitionBuilderInterface}
|
|
706
709
|
*
|
|
@@ -932,7 +935,7 @@ export declare interface AggregatorOptions {
|
|
|
932
935
|
* `enabled` through `overrides`.
|
|
933
936
|
*
|
|
934
937
|
* @param id - The inference id
|
|
935
|
-
* @param premises - The fact patterns that must
|
|
938
|
+
* @param premises - The fact patterns that must all unify
|
|
936
939
|
* @param conclusion - The fact pattern derived when they do
|
|
937
940
|
* @param overrides - Optional {@link Inference} fields merged over the defaults
|
|
938
941
|
* @returns A fresh inference
|
|
@@ -1102,7 +1105,7 @@ export declare interface AggregatorOptions {
|
|
|
1102
1105
|
* Creates an operation {@link SymbolicExpression} node.
|
|
1103
1106
|
*
|
|
1104
1107
|
* @remarks
|
|
1105
|
-
* The `right` key is
|
|
1108
|
+
* The `right` key is omitted when absent — correct for the unary operations
|
|
1106
1109
|
* (`round` / `ceil` / `floor` / `abs`); a binary operation with no `right`
|
|
1107
1110
|
* treats it as the constant `0`.
|
|
1108
1111
|
*
|
|
@@ -1213,7 +1216,7 @@ export declare interface AggregatorOptions {
|
|
|
1213
1216
|
*
|
|
1214
1217
|
* @remarks
|
|
1215
1218
|
* `reasoners` — the initial registry (a later entry of the same reasoning
|
|
1216
|
-
* replaces an earlier one; the orchestrator ships with
|
|
1219
|
+
* replaces an earlier one; the orchestrator ships with no defaults). `bail` —
|
|
1217
1220
|
* `true` (the default) rethrows a reasoner throw after the `error` emit;
|
|
1218
1221
|
* `false` converts it to a failure result. `validate` — validate every
|
|
1219
1222
|
* definition before running it, throwing `INVALID` on failure (default
|
|
@@ -1223,16 +1226,32 @@ export declare interface AggregatorOptions {
|
|
|
1223
1226
|
* @param options - Optional registry, policies, and emitter hooks
|
|
1224
1227
|
* @returns A {@link ReasonInterface}
|
|
1225
1228
|
*
|
|
1226
|
-
* @example
|
|
1229
|
+
* @example Create an orchestrator and score a subject
|
|
1227
1230
|
* ```ts
|
|
1228
|
-
* import {
|
|
1231
|
+
* import {
|
|
1232
|
+
* createFactorGroup,
|
|
1233
|
+
* createFieldFactor,
|
|
1234
|
+
* createQuantitativeDefinition,
|
|
1235
|
+
* createQuantitativeReasoner,
|
|
1236
|
+
* createReason,
|
|
1237
|
+
* createStaticFactor,
|
|
1238
|
+
* } from '@orkestrel/reason'
|
|
1229
1239
|
*
|
|
1230
|
-
* const reason = createReason({
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1240
|
+
* const reason = createReason({ reasoners: [createQuantitativeReasoner()] })
|
|
1241
|
+
*
|
|
1242
|
+
* const definition = createQuantitativeDefinition('risk', 'Risk score', [
|
|
1243
|
+
* createFactorGroup('drivers', 'sum', [
|
|
1244
|
+
* createFieldFactor('age', 'age'), // reads subject.age, parseNumber-coerced
|
|
1245
|
+
* createStaticFactor('floor', 10), // a fixed contribution
|
|
1246
|
+
* ]),
|
|
1247
|
+
* ])
|
|
1248
|
+
*
|
|
1249
|
+
* const result = reason.reason({ age: 25 }, definition) // one subject → one result
|
|
1250
|
+
* if (result.reasoning === 'quantitative') result.value // 35 — narrow by the discriminant
|
|
1251
|
+
* result.trace // the step-by-step account of how the value came to be
|
|
1252
|
+
*
|
|
1253
|
+
* reason.supports('quantitative') // true — a reasoner is registered for this reasoning
|
|
1254
|
+
* reason.reasoner('quantitative')?.supports(definition) // the reasoner's own guard, same check
|
|
1236
1255
|
* ```
|
|
1237
1256
|
*/
|
|
1238
1257
|
export declare function createReason(options?: ReasonOptions): ReasonInterface;
|
|
@@ -1245,7 +1264,7 @@ export declare interface AggregatorOptions {
|
|
|
1245
1264
|
* `enabled` through `overrides`.
|
|
1246
1265
|
*
|
|
1247
1266
|
* @param id - The rule id
|
|
1248
|
-
* @param premises - The expressions that must
|
|
1267
|
+
* @param premises - The expressions that must all hold
|
|
1249
1268
|
* @param conclusion - The expression whose atoms are asserted when they do
|
|
1250
1269
|
* @param overrides - Optional {@link Rule} fields merged over the defaults
|
|
1251
1270
|
* @returns A fresh rule
|
|
@@ -1322,8 +1341,8 @@ export declare interface AggregatorOptions {
|
|
|
1322
1341
|
* {@link Subject}.
|
|
1323
1342
|
*
|
|
1324
1343
|
* @remarks
|
|
1325
|
-
* `id`. Default: `seed.id`;
|
|
1326
|
-
* a string `seed.id` is present the builder is
|
|
1344
|
+
* `id`. Default: `seed.id`; it is optional — when neither `options.id` nor
|
|
1345
|
+
* a string `seed.id` is present the builder is anonymous (`.id` is
|
|
1327
1346
|
* `undefined`, `build()` emits no `id` key). `on` — initial event listeners.
|
|
1328
1347
|
* `error` — the emitter's listener-error handler.
|
|
1329
1348
|
* Mutate through `set` / `remove` / `merge` / `clear`, then call `build()` to
|
|
@@ -1396,7 +1415,7 @@ export declare interface AggregatorOptions {
|
|
|
1396
1415
|
* Creates a {@link Transform} — one math step.
|
|
1397
1416
|
*
|
|
1398
1417
|
* @remarks
|
|
1399
|
-
* The `operand` key is
|
|
1418
|
+
* The `operand` key is omitted when absent (never set to `undefined`), so the
|
|
1400
1419
|
* transform stays exact-record valid; the transformer then applies its
|
|
1401
1420
|
* per-operation default (`1` for `multiply` / `divide` / `power`, `0` otherwise).
|
|
1402
1421
|
*
|
|
@@ -1535,22 +1554,22 @@ export declare interface AggregatorOptions {
|
|
|
1535
1554
|
|
|
1536
1555
|
/**
|
|
1537
1556
|
* Implements a stateful workspace builder accumulating a {@link Definition}
|
|
1538
|
-
* through always-present self-owning manager properties: a private
|
|
1539
|
-
*
|
|
1557
|
+
* through always-present self-owning manager properties: a private scalar
|
|
1558
|
+
* envelope (reasoning / id / name plus the kind's scalars) composed with each
|
|
1540
1559
|
* collection read from its manager.
|
|
1541
1560
|
*
|
|
1542
1561
|
* @remarks
|
|
1543
|
-
* Each manager is
|
|
1544
|
-
*
|
|
1545
|
-
*
|
|
1546
|
-
*
|
|
1547
|
-
*
|
|
1562
|
+
* Each manager is the one the caller supplies, or a fresh one seeded from the
|
|
1563
|
+
* seed's matching collection (empty for off-kind collections). Managers are
|
|
1564
|
+
* kind-free — `build()` ignores an off-kind manager, never a `MISMATCH`.
|
|
1565
|
+
* `build()` is total, deterministic, and returns a fresh plain
|
|
1566
|
+
* {@link Definition} each call. `merge(incoming)` requires the same
|
|
1548
1567
|
* `reasoning` (else `MISMATCH`) and distributes incoming scalars into the
|
|
1549
1568
|
* envelope and collections into the managers through the matching `merge*`
|
|
1550
1569
|
* helper. `clear(key)` deletes one optional field of the envelope for the
|
|
1551
1570
|
* instance's `reasoning` (a non-clearable key throws `MISMATCH`). `destroy()`
|
|
1552
1571
|
* cascades to every manager, emits `destroy`, then tears the builder emitter
|
|
1553
|
-
* down
|
|
1572
|
+
* down last; it is idempotent, and post-destroy mutation / build throws
|
|
1554
1573
|
* `ReasonError('DESTROYED', …)`.
|
|
1555
1574
|
*
|
|
1556
1575
|
* @example
|
|
@@ -1618,17 +1637,17 @@ export declare interface AggregatorOptions {
|
|
|
1618
1637
|
* envelope plus one manager per collection.
|
|
1619
1638
|
*
|
|
1620
1639
|
* @remarks
|
|
1621
|
-
* `build()` is
|
|
1640
|
+
* `build()` is total, deterministic, and returns a fresh plain
|
|
1622
1641
|
* {@link Definition} each call (the scalar envelope composed with the kind's
|
|
1623
1642
|
* collections, read from the relevant managers' plural accessors — off-kind
|
|
1624
|
-
* managers are ignored). `merge(incoming)` requires the
|
|
1643
|
+
* managers are ignored). `merge(incoming)` requires the same `reasoning`,
|
|
1625
1644
|
* distributes incoming scalars into the envelope and collections into the
|
|
1626
1645
|
* managers through the matching `merge*` helper (a cross-reasoning `incoming`
|
|
1627
1646
|
* throws `ReasonError('MISMATCH', …)`). `clear(key)` is the uniform
|
|
1628
1647
|
* optional-key selector over the scalar envelope; a `key` that
|
|
1629
1648
|
* is not a clearable optional field for the current kind throws
|
|
1630
1649
|
* `ReasonError('MISMATCH', …, { key, reasoning })`. `destroy()` cascades to
|
|
1631
|
-
* every manager, emits `destroy`, then tears the builder emitter down
|
|
1650
|
+
* every manager, emits `destroy`, then tears the builder emitter down last;
|
|
1632
1651
|
* it is idempotent, and post-destroy mutation / build throws
|
|
1633
1652
|
* `ReasonError('DESTROYED', …)` — only the `emitter` / manager getters and
|
|
1634
1653
|
* `destroy` keep working.
|
|
@@ -1645,9 +1664,25 @@ export declare interface AggregatorOptions {
|
|
|
1645
1664
|
readonly variables: VariableManagerInterface;
|
|
1646
1665
|
readonly facts: FactManagerInterface;
|
|
1647
1666
|
readonly inferences: InferenceManagerInterface;
|
|
1667
|
+
/**
|
|
1668
|
+
* Returns a fresh plain `Definition` snapshot — the envelope plus the kind's managers —
|
|
1669
|
+
* total and deterministic on every call.
|
|
1670
|
+
*/
|
|
1648
1671
|
build(): Definition;
|
|
1672
|
+
/**
|
|
1673
|
+
* Reconciles with an incoming plain `Definition` of the same `reasoning`, distributing
|
|
1674
|
+
* scalars into the envelope and collections into the managers.
|
|
1675
|
+
*/
|
|
1649
1676
|
merge(incoming: Definition): void;
|
|
1677
|
+
/**
|
|
1678
|
+
* Deletes one optional envelope field for the instance's `reasoning`; a key the reasoning
|
|
1679
|
+
* cannot clear throws `MISMATCH`.
|
|
1680
|
+
*/
|
|
1650
1681
|
clear(key: string): void;
|
|
1682
|
+
/**
|
|
1683
|
+
* Tears the builder down idempotently — cascades `destroy` to every manager, then destroys
|
|
1684
|
+
* the builder emitter last.
|
|
1685
|
+
*/
|
|
1651
1686
|
destroy(): void;
|
|
1652
1687
|
}
|
|
1653
1688
|
|
|
@@ -1656,10 +1691,9 @@ export declare interface AggregatorOptions {
|
|
|
1656
1691
|
*
|
|
1657
1692
|
* @remarks
|
|
1658
1693
|
* `id` — overrides the seed definition's `id`. Default: `seed.id`. Every
|
|
1659
|
-
* manager slot
|
|
1660
|
-
*
|
|
1661
|
-
*
|
|
1662
|
-
* listener-error handler.
|
|
1694
|
+
* manager slot takes the manager the caller supplies, or one constructed and
|
|
1695
|
+
* seeded from the seed's matching collection. `on` — initial event listeners.
|
|
1696
|
+
* `error` — the emitter's listener-error handler.
|
|
1663
1697
|
*/
|
|
1664
1698
|
export declare interface DefinitionBuilderOptions {
|
|
1665
1699
|
readonly id?: string;
|
|
@@ -1734,7 +1768,7 @@ export declare interface AggregatorOptions {
|
|
|
1734
1768
|
* @remarks
|
|
1735
1769
|
* This is the derivation-bookkeeping equality of the chaining reasoners: the
|
|
1736
1770
|
* logical overlay and the inferential fact-dedupe compare with it so a
|
|
1737
|
-
* NaN-valued conclusion or fact term derives exactly
|
|
1771
|
+
* NaN-valued conclusion or fact term derives exactly once and the fixpoint
|
|
1738
1772
|
* converges (raw `===` would re-derive it every iteration, never converging).
|
|
1739
1773
|
* It matches `Array.prototype.includes` semantics — the same membership test
|
|
1740
1774
|
* the `any` / `none` comparisons use.
|
|
@@ -1776,17 +1810,17 @@ export declare interface AggregatorOptions {
|
|
|
1776
1810
|
* kind-free manager over a symbolic definition's `equations`.
|
|
1777
1811
|
*
|
|
1778
1812
|
* @remarks
|
|
1779
|
-
*
|
|
1813
|
+
* Owns its `equations` as a private {@link Collection} — copy-on-write state
|
|
1780
1814
|
* shared by composition with the other list managers — plus its own
|
|
1781
1815
|
* {@link Emitter} over {@link EquationManagerEventMap}. Equation order is
|
|
1782
|
-
*
|
|
1783
|
-
*
|
|
1784
|
-
*
|
|
1816
|
+
* load-bearing — equations solve strictly in order and each rounded solution
|
|
1817
|
+
* feeds forward. `remove` is the batch family (array form declared
|
|
1818
|
+
* first): no argument removes every equation, one id removes that equation, an
|
|
1785
1819
|
* id list removes those equations and returns true only when every named id
|
|
1786
1820
|
* existed. It emits one `remove` per equation actually removed.
|
|
1787
1821
|
* `seat` is the owning builder's silent bulk re-seat
|
|
1788
1822
|
* channel (used by `merge`). `destroy()` is idempotent and tears the emitter
|
|
1789
|
-
* down
|
|
1823
|
+
* down last; any other call after it throws `ReasonError('DESTROYED', …)`.
|
|
1790
1824
|
*
|
|
1791
1825
|
* @example
|
|
1792
1826
|
* ```ts
|
|
@@ -1852,15 +1886,42 @@ export declare interface AggregatorOptions {
|
|
|
1852
1886
|
*/
|
|
1853
1887
|
export declare interface EquationManagerInterface {
|
|
1854
1888
|
readonly emitter: EmitterInterface<EquationManagerEventMap>;
|
|
1889
|
+
/**
|
|
1890
|
+
* Returns the one equation carrying an id, or `undefined` when none does.
|
|
1891
|
+
*/
|
|
1855
1892
|
equation(id: string): Equation | undefined;
|
|
1893
|
+
/**
|
|
1894
|
+
* Lists every equation in solve order.
|
|
1895
|
+
*/
|
|
1856
1896
|
equations(): readonly Equation[];
|
|
1897
|
+
/**
|
|
1898
|
+
* Inserts an equation at the end, or after `target`, removing a same-id equation first.
|
|
1899
|
+
*/
|
|
1857
1900
|
append(equation: Equation, target?: string): void;
|
|
1901
|
+
/**
|
|
1902
|
+
* Inserts an equation at the start, or before `target`, removing a same-id equation first.
|
|
1903
|
+
*/
|
|
1858
1904
|
prepend(equation: Equation, target?: string): void;
|
|
1905
|
+
/**
|
|
1906
|
+
* Swaps a same-id equation in place, appending it when the collection carries none.
|
|
1907
|
+
*/
|
|
1859
1908
|
replace(equation: Equation): void;
|
|
1909
|
+
/**
|
|
1910
|
+
* Removes equations: every equation with no argument, one equation by id, or the equations
|
|
1911
|
+
* an id list names; the id forms report whether every named id existed.
|
|
1912
|
+
*/
|
|
1860
1913
|
remove(ids: readonly string[]): boolean;
|
|
1861
1914
|
remove(id: string): boolean;
|
|
1862
1915
|
remove(): void;
|
|
1916
|
+
/**
|
|
1917
|
+
* Replaces the whole collection in one silent call — the owning builder's bulk re-seat
|
|
1918
|
+
* channel.
|
|
1919
|
+
*/
|
|
1863
1920
|
seat(equations: readonly Equation[]): void;
|
|
1921
|
+
/**
|
|
1922
|
+
* Tears the manager down idempotently — emits the `destroy` event, then destroys the
|
|
1923
|
+
* emitter last.
|
|
1924
|
+
*/
|
|
1864
1925
|
destroy(): void;
|
|
1865
1926
|
}
|
|
1866
1927
|
|
|
@@ -1882,14 +1943,14 @@ export declare interface AggregatorOptions {
|
|
|
1882
1943
|
* quantitative and logical reasoners.
|
|
1883
1944
|
*
|
|
1884
1945
|
* @remarks
|
|
1885
|
-
*
|
|
1946
|
+
* Total and strict: `evaluate` never throws (an unknown operator is caught and
|
|
1886
1947
|
* surfaced as `CheckResult.error` with `met: false`) and never coerces —
|
|
1887
1948
|
* `equals` / `not` are raw `===` / `!==`, the ordering operators demand numbers
|
|
1888
|
-
* on
|
|
1889
|
-
* not met for either — `none` is
|
|
1890
|
-
* input), while `outside`
|
|
1949
|
+
* on each side, `any` / `none` demand an array expected value (a non-array is
|
|
1950
|
+
* not met for either — `none` is not the raw complement of `any` on malformed
|
|
1951
|
+
* input), while `outside` is the pure negation of `between` (so a malformed
|
|
1891
1952
|
* range is `outside`). Fields resolve through the core `resolveField` — a string
|
|
1892
|
-
* is
|
|
1953
|
+
* is a single key, an array descends. Stateless and deterministic.
|
|
1893
1954
|
*
|
|
1894
1955
|
* @example
|
|
1895
1956
|
* ```ts
|
|
@@ -1921,7 +1982,14 @@ export declare interface AggregatorOptions {
|
|
|
1921
1982
|
*/
|
|
1922
1983
|
export declare interface EvaluatorInterface {
|
|
1923
1984
|
readonly id: string;
|
|
1985
|
+
/**
|
|
1986
|
+
* Resolves `check.field` from the subject and compares it; an unknown operator becomes an
|
|
1987
|
+
* in-result `error`.
|
|
1988
|
+
*/
|
|
1924
1989
|
evaluate(check: Check, subject: Subject): CheckResult;
|
|
1990
|
+
/**
|
|
1991
|
+
* Evaluates many checks positionally against one subject.
|
|
1992
|
+
*/
|
|
1925
1993
|
batch(checks: readonly Check[], subject: Subject): readonly CheckResult[];
|
|
1926
1994
|
}
|
|
1927
1995
|
|
|
@@ -1945,7 +2013,7 @@ export declare interface AggregatorOptions {
|
|
|
1945
2013
|
* The shared atom-walk behind both {@link extractConclusions} and the raters'
|
|
1946
2014
|
* conclusion merge: an `atom` yields itself; a compound flattens its operands in
|
|
1947
2015
|
* authored order, so a later operand's atoms follow an earlier one's. The walk is
|
|
1948
|
-
* an
|
|
2016
|
+
* an iterative explicit-stack traversal (never recursive), so it stays total on
|
|
1949
2017
|
* pathologically deep expression trees; a hole in an `operands` array is skipped,
|
|
1950
2018
|
* matching `flatMap`'s hole-skipping behavior.
|
|
1951
2019
|
*
|
|
@@ -1964,13 +2032,13 @@ export declare interface AggregatorOptions {
|
|
|
1964
2032
|
|
|
1965
2033
|
/**
|
|
1966
2034
|
* Flattens a logical conclusion expression into its asserted `field = value`
|
|
1967
|
-
* pairs
|
|
2035
|
+
* pairs, ignoring the connectives.
|
|
1968
2036
|
*
|
|
1969
2037
|
* @remarks
|
|
1970
2038
|
* The conclusion-extraction step of the logical reasoner's chaining: every
|
|
1971
2039
|
* `atom` inside the expression asserts its `formatField(check.field) =
|
|
1972
2040
|
* check.value` pair, and compounds are walked without regard to the connective
|
|
1973
|
-
* (an atom under `not` / `or` is asserted the same way).
|
|
2041
|
+
* (an atom under `not` / `or` is asserted the same way). A later operand wins on
|
|
1974
2042
|
* a key clash (`Object.assign` order). Recursion runs through this exported
|
|
1975
2043
|
* function itself; the derived-overlay keys are `formatField` strings (an array
|
|
1976
2044
|
* field path flattens to its dot-joined form).
|
|
@@ -2008,17 +2076,17 @@ export declare interface AggregatorOptions {
|
|
|
2008
2076
|
* manager over an inferential definition's `facts`.
|
|
2009
2077
|
*
|
|
2010
2078
|
* @remarks
|
|
2011
|
-
*
|
|
2079
|
+
* Owns its `facts` as a private {@link Collection} — copy-on-write state shared
|
|
2012
2080
|
* by composition with the other list managers — plus its own {@link Emitter}
|
|
2013
|
-
* over {@link FactManagerEventMap}. `Fact.id` is an
|
|
2081
|
+
* over {@link FactManagerEventMap}. `Fact.id` is an authoring label — the
|
|
2014
2082
|
* runtime content-dedups facts by predicate+arity+terms, independently of this
|
|
2015
2083
|
* manager's id-keyed dedup. `remove` is the batch family (array form declared
|
|
2016
|
-
*
|
|
2084
|
+
* first): no argument removes every fact, one id removes that fact, an id list
|
|
2017
2085
|
* removes those facts and returns true only when every named id existed. It
|
|
2018
2086
|
* emits one `remove` per fact actually removed.
|
|
2019
2087
|
* `seat` is the owning builder's silent bulk re-seat
|
|
2020
2088
|
* channel (used by `merge`). `destroy()` is idempotent and tears the emitter
|
|
2021
|
-
* down
|
|
2089
|
+
* down last; any other call after it throws `ReasonError('DESTROYED', …)`.
|
|
2022
2090
|
*
|
|
2023
2091
|
* @example
|
|
2024
2092
|
* ```ts
|
|
@@ -2077,15 +2145,42 @@ export declare interface AggregatorOptions {
|
|
|
2077
2145
|
*/
|
|
2078
2146
|
export declare interface FactManagerInterface {
|
|
2079
2147
|
readonly emitter: EmitterInterface<FactManagerEventMap>;
|
|
2148
|
+
/**
|
|
2149
|
+
* Returns the one fact carrying an id, or `undefined` when none does.
|
|
2150
|
+
*/
|
|
2080
2151
|
fact(id: string): Fact | undefined;
|
|
2152
|
+
/**
|
|
2153
|
+
* Lists every fact in order.
|
|
2154
|
+
*/
|
|
2081
2155
|
facts(): readonly Fact[];
|
|
2156
|
+
/**
|
|
2157
|
+
* Inserts a fact at the end, or after `target`, removing a same-id fact first.
|
|
2158
|
+
*/
|
|
2082
2159
|
append(fact: Fact, target?: string): void;
|
|
2160
|
+
/**
|
|
2161
|
+
* Inserts a fact at the start, or before `target`, removing a same-id fact first.
|
|
2162
|
+
*/
|
|
2083
2163
|
prepend(fact: Fact, target?: string): void;
|
|
2164
|
+
/**
|
|
2165
|
+
* Swaps a same-id fact in place, appending it when the collection carries none.
|
|
2166
|
+
*/
|
|
2084
2167
|
replace(fact: Fact): void;
|
|
2168
|
+
/**
|
|
2169
|
+
* Removes facts: every fact with no argument, one fact by id, or the facts an id list
|
|
2170
|
+
* names; the id forms report whether every named id existed.
|
|
2171
|
+
*/
|
|
2085
2172
|
remove(ids: readonly string[]): boolean;
|
|
2086
2173
|
remove(id: string): boolean;
|
|
2087
2174
|
remove(): void;
|
|
2175
|
+
/**
|
|
2176
|
+
* Replaces the whole collection in one silent call — the owning builder's bulk re-seat
|
|
2177
|
+
* channel.
|
|
2178
|
+
*/
|
|
2088
2179
|
seat(facts: readonly Fact[]): void;
|
|
2180
|
+
/**
|
|
2181
|
+
* Tears the manager down idempotently — emits the `destroy` event, then destroys the
|
|
2182
|
+
* emitter last.
|
|
2183
|
+
*/
|
|
2089
2184
|
destroy(): void;
|
|
2090
2185
|
}
|
|
2091
2186
|
|
|
@@ -2106,13 +2201,13 @@ export declare interface AggregatorOptions {
|
|
|
2106
2201
|
* Represents one scored input of a quantitative group.
|
|
2107
2202
|
*
|
|
2108
2203
|
* @remarks
|
|
2109
|
-
* Evaluated as a pipeline: `checks` gate (
|
|
2110
|
-
* (`fallback` when unresolvable) → finite check →
|
|
2111
|
-
* `bounds` clamp → finite recheck. `weight` participates
|
|
2112
|
-
* aggregation. Default: `1`. `priority` orders evaluation
|
|
2113
|
-
* Default: `0`. `enabled: false` skips the factor entirely
|
|
2114
|
-
* results); `required: true` promotes a gate / resolution failure
|
|
2115
|
-
* error (making `success` false) without aborting the run.
|
|
2204
|
+
* Evaluated as a pipeline: `checks` gate (every check must be met) →
|
|
2205
|
+
* `source` resolve (`fallback` when unresolvable) → finite check →
|
|
2206
|
+
* `transforms` chain → `bounds` clamp → finite recheck. `weight` participates
|
|
2207
|
+
* only at group aggregation. Default: `1`. `priority` orders evaluation
|
|
2208
|
+
* ascending, stable. Default: `0`. `enabled: false` skips the factor entirely
|
|
2209
|
+
* (omitted from results); `required: true` promotes a gate / resolution failure
|
|
2210
|
+
* to a result error (making `success` false) without aborting the run.
|
|
2116
2211
|
*/
|
|
2117
2212
|
export declare interface Factor {
|
|
2118
2213
|
readonly id: string;
|
|
@@ -2134,7 +2229,7 @@ export declare interface AggregatorOptions {
|
|
|
2134
2229
|
*
|
|
2135
2230
|
* @remarks
|
|
2136
2231
|
* `base` is added before aggregation. Default: `0`.
|
|
2137
|
-
* The group value is `base` plus the aggregation of its
|
|
2232
|
+
* The group value is `base` plus the aggregation of its applied
|
|
2138
2233
|
* factors' values (with per-factor weights), clamped to `bounds` — never
|
|
2139
2234
|
* rounded. `strict: true` makes the group all-or-nothing: if any evaluated
|
|
2140
2235
|
* factor did not apply, the group contributes only its `base` and reports
|
|
@@ -2154,24 +2249,25 @@ export declare interface AggregatorOptions {
|
|
|
2154
2249
|
}
|
|
2155
2250
|
|
|
2156
2251
|
/**
|
|
2157
|
-
* Implements the {@link FactorManagerInterface} — the
|
|
2158
|
-
* manager: factors nest inside groups, so it holds
|
|
2252
|
+
* Implements the {@link FactorManagerInterface} — the one divergent
|
|
2253
|
+
* manager: factors nest inside groups, so it holds no collection state of its
|
|
2159
2254
|
* own and threads a required `groupId` locator.
|
|
2160
2255
|
*
|
|
2161
2256
|
* @remarks
|
|
2162
2257
|
* Constructor-injected with the sibling {@link GroupManagerInterface}: each
|
|
2163
2258
|
* write verb reads the located group (`groups.group(groupId)`), applies the
|
|
2164
|
-
* factor-level pure helper ({@link appendFactor}
|
|
2259
|
+
* factor-level pure helper ({@link appendFactor}, {@link prependFactor},
|
|
2260
|
+
* {@link replaceFactor}, or {@link removeFactor}), and writes the updated
|
|
2165
2261
|
* group back through `groups.replace(…)`. A `groupId` naming no existing group
|
|
2166
|
-
* throws `ReasonError('TARGET', …, { groupId })`. It still owns its
|
|
2262
|
+
* throws `ReasonError('TARGET', …, { groupId })`. It still owns its own
|
|
2167
2263
|
* {@link Emitter} over {@link FactorManagerEventMap} (factor-id payloads).
|
|
2168
2264
|
* `remove` is the batch family behind the leading `groupId` locator (array form
|
|
2169
|
-
* declared
|
|
2265
|
+
* declared first): the locator alone removes every factor of that group, a
|
|
2170
2266
|
* further id removes that factor, a further id list removes those factors and
|
|
2171
2267
|
* returns true only when every named id existed. It emits one `remove` per
|
|
2172
2268
|
* factor actually removed, each paired with a `replace` on the sibling
|
|
2173
2269
|
* `GroupManagerInterface` for the containing group.
|
|
2174
|
-
* `destroy()` is idempotent and tears the emitter down
|
|
2270
|
+
* `destroy()` is idempotent and tears the emitter down last; any other call
|
|
2175
2271
|
* after it throws `ReasonError('DESTROYED', …)`.
|
|
2176
2272
|
*
|
|
2177
2273
|
* @example
|
|
@@ -2231,12 +2327,12 @@ export declare interface AggregatorOptions {
|
|
|
2231
2327
|
*
|
|
2232
2328
|
* @remarks
|
|
2233
2329
|
* Divergent from the other managers: factors nest inside groups, so this
|
|
2234
|
-
* manager holds
|
|
2330
|
+
* manager holds no collection state of its own — it reads and writes through
|
|
2235
2331
|
* the sibling {@link GroupManagerInterface} (`groups.group(groupId)` then
|
|
2236
2332
|
* `groups.replace(…)`). A `groupId` naming no existing group throws
|
|
2237
2333
|
* `ReasonError('TARGET', …, { groupId })`. `append` / `prepend` additionally
|
|
2238
2334
|
* take an optional `target` factor id (a naming miss throws
|
|
2239
|
-
* `ReasonError('TARGET', …)`). It still owns its
|
|
2335
|
+
* `ReasonError('TARGET', …)`). It still owns its own emitter (factor-id
|
|
2240
2336
|
* payloads). `remove` is the batch family behind the leading `groupId`
|
|
2241
2337
|
* locator: the locator alone removes every factor of that group, a further id
|
|
2242
2338
|
* removes that factor, a further id list removes those factors and returns
|
|
@@ -2246,14 +2342,41 @@ export declare interface AggregatorOptions {
|
|
|
2246
2342
|
*/
|
|
2247
2343
|
export declare interface FactorManagerInterface {
|
|
2248
2344
|
readonly emitter: EmitterInterface<FactorManagerEventMap>;
|
|
2345
|
+
/**
|
|
2346
|
+
* Returns the one factor of a named group carrying an id, or `undefined` when none does.
|
|
2347
|
+
*/
|
|
2249
2348
|
factor(groupId: string, id: string): Factor | undefined;
|
|
2349
|
+
/**
|
|
2350
|
+
* Lists every factor of one named group in order.
|
|
2351
|
+
*/
|
|
2250
2352
|
factors(groupId: string): readonly Factor[];
|
|
2353
|
+
/**
|
|
2354
|
+
* Inserts a factor into the named group at the end, or after `target`, removing a same-id
|
|
2355
|
+
* factor first.
|
|
2356
|
+
*/
|
|
2251
2357
|
append(groupId: string, factor: Factor, target?: string): void;
|
|
2358
|
+
/**
|
|
2359
|
+
* Inserts a factor into the named group at the start, or before `target`, removing a
|
|
2360
|
+
* same-id factor first.
|
|
2361
|
+
*/
|
|
2252
2362
|
prepend(groupId: string, factor: Factor, target?: string): void;
|
|
2363
|
+
/**
|
|
2364
|
+
* Swaps a same-id factor in place within the named group, appending it when the group
|
|
2365
|
+
* carries none.
|
|
2366
|
+
*/
|
|
2253
2367
|
replace(groupId: string, factor: Factor): void;
|
|
2368
|
+
/**
|
|
2369
|
+
* Removes factors of the named group: every factor with the locator alone, one factor by a
|
|
2370
|
+
* further id, or the factors a further id list names; the id forms report whether every
|
|
2371
|
+
* named id existed.
|
|
2372
|
+
*/
|
|
2254
2373
|
remove(groupId: string, ids: readonly string[]): boolean;
|
|
2255
2374
|
remove(groupId: string, id: string): boolean;
|
|
2256
2375
|
remove(groupId: string): void;
|
|
2376
|
+
/**
|
|
2377
|
+
* Tears the manager down idempotently — emits the `destroy` event, then destroys the
|
|
2378
|
+
* emitter last.
|
|
2379
|
+
*/
|
|
2257
2380
|
destroy(): void;
|
|
2258
2381
|
}
|
|
2259
2382
|
|
|
@@ -2300,7 +2423,7 @@ export declare interface AggregatorOptions {
|
|
|
2300
2423
|
* @remarks
|
|
2301
2424
|
* Keys both stored facts and premise patterns (both are `Fact`-shaped) for
|
|
2302
2425
|
* {@link indexByArity}: `matchFacts` already rejects an arity mismatch, so
|
|
2303
|
-
* narrowing a same-predicate bucket to same
|
|
2426
|
+
* narrowing a same-predicate bucket to one of the same predicate and arity only
|
|
2304
2427
|
* excludes candidates that could never unify anyway. Only `predicate` — the
|
|
2305
2428
|
* one free-form, adversary-controlled part — is length-prefixed
|
|
2306
2429
|
* (`length + ':' + predicate`), mirroring {@link factToKey}'s framing so a
|
|
@@ -2323,14 +2446,14 @@ export declare interface AggregatorOptions {
|
|
|
2323
2446
|
|
|
2324
2447
|
/**
|
|
2325
2448
|
* Derives a fact's canonical dedup key — predicate + arity + per-term
|
|
2326
|
-
* SameValueZero identity
|
|
2449
|
+
* SameValueZero identity, with confidence excluded from it.
|
|
2327
2450
|
*
|
|
2328
2451
|
* @remarks
|
|
2329
2452
|
* The dedup key of the inferential reasoner's forward fixpoint: two facts with
|
|
2330
2453
|
* the same predicate, arity, and SameValueZero-equal terms share a key (so a
|
|
2331
2454
|
* NaN-term fact derives once and ±0 collapse keeping the first), while
|
|
2332
2455
|
* confidence never enters the key. Each part — the predicate, the stringified
|
|
2333
|
-
* arity, and every {@link termToKey} — is
|
|
2456
|
+
* arity, and every {@link termToKey} — is length-prefixed (`length + ':' + part`)
|
|
2334
2457
|
* before joining, so the delimiter can never be forged by an adversarial string
|
|
2335
2458
|
* term embedding it: two distinct facts always produce distinct keys, even when
|
|
2336
2459
|
* a term string contains the delimiter (an injective framing raw joining lacked).
|
|
@@ -2365,12 +2488,12 @@ export declare interface AggregatorOptions {
|
|
|
2365
2488
|
}
|
|
2366
2489
|
|
|
2367
2490
|
/**
|
|
2368
|
-
* Collects the ids that appear
|
|
2491
|
+
* Collects the ids that appear more than once in an id-carrying list — each
|
|
2369
2492
|
* duplicated id reported once, in first-occurrence order.
|
|
2370
2493
|
*
|
|
2371
2494
|
* @remarks
|
|
2372
2495
|
* The shared uniqueness scan behind every reasoner's `validate()` duplicate-id
|
|
2373
|
-
*
|
|
2496
|
+
* warnings (rules, groups, factors, equations, inferences). Runtime stays
|
|
2374
2497
|
* permissive about duplicates (first/last-wins artifacts) — this helper only
|
|
2375
2498
|
* surfaces them.
|
|
2376
2499
|
*
|
|
@@ -2394,13 +2517,13 @@ export declare interface AggregatorOptions {
|
|
|
2394
2517
|
*
|
|
2395
2518
|
* @remarks
|
|
2396
2519
|
* The reported keys are the `formatField`-flattened overlay keys an array-path
|
|
2397
|
-
* conclusion atom writes
|
|
2398
|
-
* also reads
|
|
2520
|
+
* conclusion atom writes anywhere among `rules` that an array-path premise atom
|
|
2521
|
+
* also reads anywhere among `rules`. The cross-rule authoring-time footgun
|
|
2399
2522
|
* probe behind `LogicalReasoner.validate`'s overlay-key-mismatch warning: a
|
|
2400
|
-
* logical conclusion's derived overlay is a
|
|
2523
|
+
* logical conclusion's derived overlay is a flat record keyed by
|
|
2401
2524
|
* `formatField(check.field)` — an array `FieldPath` dot-joins into one string
|
|
2402
|
-
* key. A premise that reads the same field through a
|
|
2403
|
-
* that flat key correctly, but a premise that reads it through an
|
|
2525
|
+
* key. A premise that reads the same field through a dotted-string path resolves
|
|
2526
|
+
* that flat key correctly, but a premise that reads it through an array path
|
|
2404
2527
|
* calls `resolveField`, which descends key-by-key into nesting the flat
|
|
2405
2528
|
* overlay never created, so the chain silently fails to connect. Collects the
|
|
2406
2529
|
* flattened keys of every array-path conclusion atom across `rules` (once
|
|
@@ -2458,7 +2581,7 @@ export declare interface AggregatorOptions {
|
|
|
2458
2581
|
*
|
|
2459
2582
|
* @remarks
|
|
2460
2583
|
* Display-only: the joined form is how a field appears in traces and derived
|
|
2461
|
-
* overlays; it is
|
|
2584
|
+
* overlays; it is never re-parsed into a path (a string stays a single key).
|
|
2462
2585
|
*
|
|
2463
2586
|
* @param field - The field path to format
|
|
2464
2587
|
* @returns The display string
|
|
@@ -2476,16 +2599,16 @@ export declare interface AggregatorOptions {
|
|
|
2476
2599
|
* manager over a quantitative definition's `groups`.
|
|
2477
2600
|
*
|
|
2478
2601
|
* @remarks
|
|
2479
|
-
*
|
|
2602
|
+
* Owns its `groups` as a private {@link Collection} — copy-on-write state
|
|
2480
2603
|
* shared by composition with the other list managers — plus its own
|
|
2481
2604
|
* {@link Emitter} over {@link GroupManagerEventMap}. Every write verb delegates
|
|
2482
|
-
* to the collection, then emits (the affected group id)
|
|
2483
|
-
* `remove` is the batch family (array form declared
|
|
2605
|
+
* to the collection, then emits (the affected group id) after the mutation.
|
|
2606
|
+
* `remove` is the batch family (array form declared first): no argument removes
|
|
2484
2607
|
* every group, one id removes that group, an id list removes those groups and
|
|
2485
2608
|
* returns true only when every named id existed. It emits one `remove` per
|
|
2486
2609
|
* group actually removed.
|
|
2487
2610
|
* `seat` is the owning builder's silent bulk re-seat channel (used by `merge`).
|
|
2488
|
-
* `destroy()` is idempotent and tears the emitter down
|
|
2611
|
+
* `destroy()` is idempotent and tears the emitter down last; any other call
|
|
2489
2612
|
* after it throws `ReasonError('DESTROYED', …)`.
|
|
2490
2613
|
*
|
|
2491
2614
|
* @example
|
|
@@ -2548,15 +2671,47 @@ export declare interface AggregatorOptions {
|
|
|
2548
2671
|
*/
|
|
2549
2672
|
export declare interface GroupManagerInterface {
|
|
2550
2673
|
readonly emitter: EmitterInterface<GroupManagerEventMap>;
|
|
2674
|
+
/**
|
|
2675
|
+
* Returns the one group carrying an id, or `undefined` when none does.
|
|
2676
|
+
*/
|
|
2551
2677
|
group(id: string): FactorGroup | undefined;
|
|
2678
|
+
/**
|
|
2679
|
+
* Lists every group in order.
|
|
2680
|
+
*/
|
|
2552
2681
|
groups(): readonly FactorGroup[];
|
|
2682
|
+
/**
|
|
2683
|
+
* Inserts a group at the end, or after `target`, removing a same-id group first; a `target`
|
|
2684
|
+
* naming no group throws `TARGET`.
|
|
2685
|
+
*/
|
|
2553
2686
|
append(group: FactorGroup, target?: string): void;
|
|
2687
|
+
/**
|
|
2688
|
+
* Inserts a group at the start, or before `target`, removing a same-id group first; a
|
|
2689
|
+
* `target` naming no group throws `TARGET`.
|
|
2690
|
+
*/
|
|
2554
2691
|
prepend(group: FactorGroup, target?: string): void;
|
|
2692
|
+
/**
|
|
2693
|
+
* Swaps a same-id group in place, appending it when the collection carries none.
|
|
2694
|
+
*/
|
|
2555
2695
|
replace(group: FactorGroup): void;
|
|
2696
|
+
/**
|
|
2697
|
+
* Removes groups: every group with no argument, one group by id, or the groups an id list
|
|
2698
|
+
* names; the id forms report whether every named id existed.
|
|
2699
|
+
*
|
|
2700
|
+
* @remarks
|
|
2701
|
+
* Each removal emits one `remove` event carrying the group id.
|
|
2702
|
+
*/
|
|
2556
2703
|
remove(ids: readonly string[]): boolean;
|
|
2557
2704
|
remove(id: string): boolean;
|
|
2558
2705
|
remove(): void;
|
|
2706
|
+
/**
|
|
2707
|
+
* Replaces the whole collection in one silent call — the owning builder's bulk re-seat
|
|
2708
|
+
* channel.
|
|
2709
|
+
*/
|
|
2559
2710
|
seat(groups: readonly FactorGroup[]): void;
|
|
2711
|
+
/**
|
|
2712
|
+
* Tears the manager down idempotently — emits the `destroy` event, then destroys the
|
|
2713
|
+
* emitter last.
|
|
2714
|
+
*/
|
|
2560
2715
|
destroy(): void;
|
|
2561
2716
|
}
|
|
2562
2717
|
|
|
@@ -2578,9 +2733,9 @@ export declare interface AggregatorOptions {
|
|
|
2578
2733
|
* results (disabled factors omitted entirely).
|
|
2579
2734
|
*
|
|
2580
2735
|
* @remarks
|
|
2581
|
-
* An
|
|
2736
|
+
* An unapplied group's `value` may be non-finite (a `minimum` / `maximum`
|
|
2582
2737
|
* aggregation over zero applied factors is `base + NaN`) — it is excluded from
|
|
2583
|
-
* the definition-level aggregation, so only an
|
|
2738
|
+
* the definition-level aggregation, so only an applied non-finite value reaches
|
|
2584
2739
|
* the definition-level finite check.
|
|
2585
2740
|
*/
|
|
2586
2741
|
export declare interface GroupResult {
|
|
@@ -2596,7 +2751,7 @@ export declare interface AggregatorOptions {
|
|
|
2596
2751
|
* @remarks
|
|
2597
2752
|
* The index behind the inferential reasoner's same-predicate-and-arity join
|
|
2598
2753
|
* scans (`#findAllBindings` / `#calculatePremiseConfidence`): `matchFacts`
|
|
2599
|
-
* already rejects a predicate
|
|
2754
|
+
* already rejects a predicate or an arity mismatch, so restricting a premise's
|
|
2600
2755
|
* search to its own predicate+arity bucket changes nothing but the cost — the
|
|
2601
2756
|
* surviving matches and their append order are identical to a predicate-only
|
|
2602
2757
|
* index. Append order within a bucket is preserved, so a "first match wins"
|
|
@@ -2640,16 +2795,16 @@ export declare interface AggregatorOptions {
|
|
|
2640
2795
|
* kind-free manager over an inferential definition's `inferences`.
|
|
2641
2796
|
*
|
|
2642
2797
|
* @remarks
|
|
2643
|
-
*
|
|
2798
|
+
* Owns its `inferences` as a private {@link Collection} — copy-on-write state
|
|
2644
2799
|
* shared by composition with the other list managers — plus its own
|
|
2645
2800
|
* {@link Emitter} over {@link InferenceManagerEventMap}. Inference order is
|
|
2646
|
-
*
|
|
2647
|
-
* first success. `remove` is the batch family (array form declared
|
|
2801
|
+
* load-bearing — backward proving iterates in declaration order and returns on
|
|
2802
|
+
* first success. `remove` is the batch family (array form declared first): no
|
|
2648
2803
|
* argument removes every inference, one id removes that inference, an id list
|
|
2649
2804
|
* removes those inferences and returns true only when every named id existed.
|
|
2650
2805
|
* It emits one `remove` per inference actually removed.
|
|
2651
2806
|
* `seat` is the owning builder's silent bulk re-seat channel
|
|
2652
|
-
* (used by `merge`). `destroy()` is idempotent and tears the emitter down
|
|
2807
|
+
* (used by `merge`). `destroy()` is idempotent and tears the emitter down last;
|
|
2653
2808
|
* any other call after it throws `ReasonError('DESTROYED', …)`.
|
|
2654
2809
|
*
|
|
2655
2810
|
* @example
|
|
@@ -2721,15 +2876,43 @@ export declare interface AggregatorOptions {
|
|
|
2721
2876
|
*/
|
|
2722
2877
|
export declare interface InferenceManagerInterface {
|
|
2723
2878
|
readonly emitter: EmitterInterface<InferenceManagerEventMap>;
|
|
2879
|
+
/**
|
|
2880
|
+
* Returns the one inference carrying an id, or `undefined` when none does.
|
|
2881
|
+
*/
|
|
2724
2882
|
inference(id: string): Inference | undefined;
|
|
2883
|
+
/**
|
|
2884
|
+
* Lists every inference in order.
|
|
2885
|
+
*/
|
|
2725
2886
|
inferences(): readonly Inference[];
|
|
2887
|
+
/**
|
|
2888
|
+
* Inserts an inference at the end, or after `target`, removing a same-id inference first.
|
|
2889
|
+
*/
|
|
2726
2890
|
append(inference: Inference, target?: string): void;
|
|
2891
|
+
/**
|
|
2892
|
+
* Inserts an inference at the start, or before `target`, removing a same-id inference
|
|
2893
|
+
* first.
|
|
2894
|
+
*/
|
|
2727
2895
|
prepend(inference: Inference, target?: string): void;
|
|
2896
|
+
/**
|
|
2897
|
+
* Swaps a same-id inference in place, appending it when the collection carries none.
|
|
2898
|
+
*/
|
|
2728
2899
|
replace(inference: Inference): void;
|
|
2900
|
+
/**
|
|
2901
|
+
* Removes inferences: every inference with no argument, one inference by id, or the
|
|
2902
|
+
* inferences an id list names; the id forms report whether every named id existed.
|
|
2903
|
+
*/
|
|
2729
2904
|
remove(ids: readonly string[]): boolean;
|
|
2730
2905
|
remove(id: string): boolean;
|
|
2731
2906
|
remove(): void;
|
|
2907
|
+
/**
|
|
2908
|
+
* Replaces the whole collection in one silent call — the owning builder's bulk re-seat
|
|
2909
|
+
* channel.
|
|
2910
|
+
*/
|
|
2732
2911
|
seat(inferences: readonly Inference[]): void;
|
|
2912
|
+
/**
|
|
2913
|
+
* Tears the manager down idempotently — emits the `destroy` event, then destroys the
|
|
2914
|
+
* emitter last.
|
|
2915
|
+
*/
|
|
2733
2916
|
destroy(): void;
|
|
2734
2917
|
}
|
|
2735
2918
|
|
|
@@ -2795,7 +2978,7 @@ export declare interface AggregatorOptions {
|
|
|
2795
2978
|
*
|
|
2796
2979
|
* @remarks
|
|
2797
2980
|
* A string term starting with `?` is a unification variable — matching is
|
|
2798
|
-
* positional and
|
|
2981
|
+
* positional and bidirectional (variables may sit in facts as well as
|
|
2799
2982
|
* patterns), with binding consistency enforced within one match and across
|
|
2800
2983
|
* premises through pre-instantiation. Scalar subject fields (except `id`;
|
|
2801
2984
|
* `null` / `undefined` / objects / arrays skipped) inject as
|
|
@@ -2806,8 +2989,8 @@ export declare interface AggregatorOptions {
|
|
|
2806
2989
|
* duplicate facts (same predicate, arity, and SameValueZero-equal terms — a
|
|
2807
2990
|
* NaN term derives once and converges) are never re-derived. Backward chaining
|
|
2808
2991
|
* proves each inference's conclusion in
|
|
2809
|
-
* declaration order and
|
|
2810
|
-
* (confidence = the inference's own — premise confidences are
|
|
2992
|
+
* declaration order and returns on the first success with one derived fact
|
|
2993
|
+
* (confidence = the inference's own — premise confidences are not propagated)
|
|
2811
2994
|
* plus its {@link ProofNode} tree; recursion is guarded only by the depth cap.
|
|
2812
2995
|
* Deriving nothing is still success. Nothing mutates its inputs; fully
|
|
2813
2996
|
* deterministic.
|
|
@@ -2885,7 +3068,7 @@ export declare interface AggregatorOptions {
|
|
|
2885
3068
|
* @remarks
|
|
2886
3069
|
* The pattern-instantiation step of the inferential reasoner: a `'?'`-prefixed
|
|
2887
3070
|
* string term that is present in `bindings` is replaced by its bound value;
|
|
2888
|
-
* every other term (constants and
|
|
3071
|
+
* every other term (constants and unbound variables alike) is kept verbatim. The
|
|
2889
3072
|
* returned fact is a fresh copy (`{ ...fact, terms }`) — the input is never
|
|
2890
3073
|
* mutated.
|
|
2891
3074
|
*
|
|
@@ -2910,7 +3093,7 @@ export declare interface AggregatorOptions {
|
|
|
2910
3093
|
export declare const INVERTIBLE_OPERATIONS: ReadonlySet<MathOperation>;
|
|
2911
3094
|
|
|
2912
3095
|
/**
|
|
2913
|
-
* Inverts a `x op right = value` step, solving for the
|
|
3096
|
+
* Inverts a `x op right = value` step, solving for the left operand `x`.
|
|
2914
3097
|
*
|
|
2915
3098
|
* @remarks
|
|
2916
3099
|
* The left-operand inverse of the symbolic reasoner's isolation: `add` inverts
|
|
@@ -2938,7 +3121,7 @@ export declare interface AggregatorOptions {
|
|
|
2938
3121
|
export declare function invertLeft(operator: MathOperation, value: number, rightValue: number): number;
|
|
2939
3122
|
|
|
2940
3123
|
/**
|
|
2941
|
-
* Inverts a `left op x = value` step, solving for the
|
|
3124
|
+
* Inverts a `left op x = value` step, solving for the right operand `x`.
|
|
2942
3125
|
*
|
|
2943
3126
|
* @remarks
|
|
2944
3127
|
* The right-operand inverse of the symbolic reasoner's isolation: `add` inverts
|
|
@@ -2968,7 +3151,7 @@ export declare interface AggregatorOptions {
|
|
|
2968
3151
|
* Determines whether a value is an {@link Aggregation} literal.
|
|
2969
3152
|
*
|
|
2970
3153
|
* @param value - The value to test
|
|
2971
|
-
* @returns True if `value`
|
|
3154
|
+
* @returns True if `value` names an aggregation; false otherwise
|
|
2972
3155
|
*
|
|
2973
3156
|
* @example
|
|
2974
3157
|
* ```ts
|
|
@@ -3018,8 +3201,8 @@ export declare interface AggregatorOptions {
|
|
|
3018
3201
|
* predicate.
|
|
3019
3202
|
*
|
|
3020
3203
|
* @remarks
|
|
3021
|
-
* `value` may be
|
|
3022
|
-
*
|
|
3204
|
+
* `value` may be anything (including `null` / `undefined`) but the key must be
|
|
3205
|
+
* present — exact-record semantics reject a check that lost its `value` key.
|
|
3023
3206
|
*
|
|
3024
3207
|
* @param value - The value to test
|
|
3025
3208
|
* @returns True if `value` is a well-formed check; false otherwise
|
|
@@ -3037,6 +3220,12 @@ export declare interface AggregatorOptions {
|
|
|
3037
3220
|
/**
|
|
3038
3221
|
* Determines whether a value is a {@link CheckResult}.
|
|
3039
3222
|
*
|
|
3223
|
+
* @remarks
|
|
3224
|
+
* `actual` must be present and may hold anything, including `undefined` — the
|
|
3225
|
+
* guard reads its presence, never its value. A result whose `actual` is
|
|
3226
|
+
* `undefined` therefore does not survive a JSON round trip: `JSON.stringify`
|
|
3227
|
+
* drops the key, and the parsed record is refused here.
|
|
3228
|
+
*
|
|
3040
3229
|
* @param value - The value to test
|
|
3041
3230
|
* @returns True if every published check-result member is valid; false otherwise
|
|
3042
3231
|
*
|
|
@@ -3054,7 +3243,7 @@ export declare interface AggregatorOptions {
|
|
|
3054
3243
|
* Determines whether a value is a {@link Comparison} literal.
|
|
3055
3244
|
*
|
|
3056
3245
|
* @param value - The value to test
|
|
3057
|
-
* @returns True if `value`
|
|
3246
|
+
* @returns True if `value` names a comparison operator; false otherwise
|
|
3058
3247
|
*
|
|
3059
3248
|
* @example
|
|
3060
3249
|
* ```ts
|
|
@@ -3067,8 +3256,8 @@ export declare interface AggregatorOptions {
|
|
|
3067
3256
|
export declare const isComparison: Guard<Comparison>;
|
|
3068
3257
|
|
|
3069
3258
|
/**
|
|
3070
|
-
* Determines whether a value is a {@link Definition} —
|
|
3071
|
-
* definition
|
|
3259
|
+
* Determines whether a value is a {@link Definition} — a quantitative, logical,
|
|
3260
|
+
* symbolic, or inferential definition shape, discriminated by `reasoning`.
|
|
3072
3261
|
*
|
|
3073
3262
|
* @param value - The value to test
|
|
3074
3263
|
* @returns True if `value` is a well-formed definition of any reasoning; false otherwise
|
|
@@ -3084,13 +3273,13 @@ export declare interface AggregatorOptions {
|
|
|
3084
3273
|
export declare function isDefinition(value: unknown): value is Definition;
|
|
3085
3274
|
|
|
3086
3275
|
/**
|
|
3087
|
-
* Determines whether a value is a `DefinitionBuilder`
|
|
3276
|
+
* Determines whether a value is a `DefinitionBuilder` entity — the brand-guarded
|
|
3088
3277
|
* stateful workspace, not the plain {@link Definition} data union.
|
|
3089
3278
|
*
|
|
3090
3279
|
* @remarks
|
|
3091
3280
|
* A `unique symbol` brand check (`Reflect.get`): a plain subject
|
|
3092
3281
|
* is an open record whose values may legally be functions, so a
|
|
3093
|
-
* method-presence check (`typeof value.build === 'function'`) is
|
|
3282
|
+
* method-presence check (`typeof value.build === 'function'`) is forgeable —
|
|
3094
3283
|
* this guard is not. A module-owned `unique symbol` cannot be produced by
|
|
3095
3284
|
* `JSON.parse` or written by any consumer that does not import
|
|
3096
3285
|
* `DEFINITION_BUILDER_BRAND`, so plain data can never forge it. Total: a
|
|
@@ -3134,9 +3323,9 @@ export declare interface AggregatorOptions {
|
|
|
3134
3323
|
* tree of atoms and compounds, discriminated by `form`.
|
|
3135
3324
|
*
|
|
3136
3325
|
* @remarks
|
|
3137
|
-
* Recursive through `lazyOf` — recursion is
|
|
3326
|
+
* Recursive through `lazyOf` — recursion is bounded by the stack, not
|
|
3138
3327
|
* unbounded: nesting beyond the engine's stack budget (roughly 1000 levels)
|
|
3139
|
-
* and cyclic input are
|
|
3328
|
+
* and cyclic input are contained as `false`, never a throw. Input past that
|
|
3140
3329
|
* bound is rejected, not validated.
|
|
3141
3330
|
*
|
|
3142
3331
|
* @param value - The value to test
|
|
@@ -3228,6 +3417,10 @@ export declare interface AggregatorOptions {
|
|
|
3228
3417
|
/**
|
|
3229
3418
|
* Determines whether a value is a {@link FactorResult}.
|
|
3230
3419
|
*
|
|
3420
|
+
* @remarks
|
|
3421
|
+
* The optional `raw` and `checks` members are absent-or-valid: an absent key
|
|
3422
|
+
* passes, a present key is checked in full.
|
|
3423
|
+
*
|
|
3231
3424
|
* @param value - The value to test
|
|
3232
3425
|
* @returns True if every published factor-result member is valid; false otherwise
|
|
3233
3426
|
*
|
|
@@ -3252,7 +3445,7 @@ export declare interface AggregatorOptions {
|
|
|
3252
3445
|
* ```ts
|
|
3253
3446
|
* import { isFieldPath } from '@src/core'
|
|
3254
3447
|
*
|
|
3255
|
-
* isFieldPath('age') // true —
|
|
3448
|
+
* isFieldPath('age') // true — a single key (never dot-split)
|
|
3256
3449
|
* isFieldPath(['address', 'city']) // true — descends
|
|
3257
3450
|
* isFieldPath(42) // false
|
|
3258
3451
|
* ```
|
|
@@ -3378,7 +3571,7 @@ export declare interface AggregatorOptions {
|
|
|
3378
3571
|
* Determines whether a value is a {@link LogicalOperator} literal.
|
|
3379
3572
|
*
|
|
3380
3573
|
* @param value - The value to test
|
|
3381
|
-
* @returns True if `value`
|
|
3574
|
+
* @returns True if `value` names a logical connective; false otherwise
|
|
3382
3575
|
*
|
|
3383
3576
|
* @example
|
|
3384
3577
|
* ```ts
|
|
@@ -3533,7 +3726,7 @@ export declare interface AggregatorOptions {
|
|
|
3533
3726
|
* Determines whether a value is a {@link Reasoning} literal.
|
|
3534
3727
|
*
|
|
3535
3728
|
* @param value - The value to test
|
|
3536
|
-
* @returns True if `value`
|
|
3729
|
+
* @returns True if `value` names a reasoning strategy; false otherwise
|
|
3537
3730
|
*
|
|
3538
3731
|
* @example
|
|
3539
3732
|
* ```ts
|
|
@@ -3630,8 +3823,8 @@ export declare interface AggregatorOptions {
|
|
|
3630
3823
|
export declare function isRuleResult(value: unknown): value is RuleResult;
|
|
3631
3824
|
|
|
3632
3825
|
/**
|
|
3633
|
-
* Determines whether a value is a {@link Source} —
|
|
3634
|
-
*
|
|
3826
|
+
* Determines whether a value is a {@link Source} — a static, field, lookup, or
|
|
3827
|
+
* range factor source, discriminated by `origin`.
|
|
3635
3828
|
*
|
|
3636
3829
|
* @param value - The value to test
|
|
3637
3830
|
* @returns True if `value` is a well-formed static / field / lookup / range source; false otherwise
|
|
@@ -3648,12 +3841,12 @@ export declare interface AggregatorOptions {
|
|
|
3648
3841
|
export declare function isSource(value: unknown): value is Source;
|
|
3649
3842
|
|
|
3650
3843
|
/**
|
|
3651
|
-
* Determines whether a value is a `SubjectBuilder`
|
|
3844
|
+
* Determines whether a value is a `SubjectBuilder` entity — the brand-guarded
|
|
3652
3845
|
* stateful workspace, not the plain {@link Subject} data record.
|
|
3653
3846
|
*
|
|
3654
3847
|
* @remarks
|
|
3655
3848
|
* A `unique symbol` brand check (`Reflect.get`), distinct from
|
|
3656
|
-
* {@link isDefinitionBuilder} —
|
|
3849
|
+
* {@link isDefinitionBuilder} — neither entity can ever match the other's
|
|
3657
3850
|
* guard. Total: a non-object, a missing brand, or a hostile prototype all
|
|
3658
3851
|
* return `false`, never throw.
|
|
3659
3852
|
*
|
|
@@ -3711,9 +3904,9 @@ export declare interface AggregatorOptions {
|
|
|
3711
3904
|
* `form`.
|
|
3712
3905
|
*
|
|
3713
3906
|
* @remarks
|
|
3714
|
-
* Recursive through `lazyOf` — recursion is
|
|
3907
|
+
* Recursive through `lazyOf` — recursion is bounded by the stack, not
|
|
3715
3908
|
* unbounded: nesting beyond the engine's stack budget (roughly 1000 levels)
|
|
3716
|
-
* and cyclic input are
|
|
3909
|
+
* and cyclic input are contained as `false`, never a throw. Input past that
|
|
3717
3910
|
* bound is rejected, not validated.
|
|
3718
3911
|
*
|
|
3719
3912
|
* @param value - The value to test
|
|
@@ -3733,7 +3926,7 @@ export declare interface AggregatorOptions {
|
|
|
3733
3926
|
* Determines whether a value is a {@link SymbolicResult}.
|
|
3734
3927
|
*
|
|
3735
3928
|
* @remarks
|
|
3736
|
-
* `solutions` is checked across its
|
|
3929
|
+
* `solutions` is checked across its own string-named members, enumerable or
|
|
3737
3930
|
* not. Inherited members are deliberately unread: they belong to the
|
|
3738
3931
|
* accepted-prototype property, not to the record this guard certifies.
|
|
3739
3932
|
*
|
|
@@ -3822,18 +4015,18 @@ export declare interface AggregatorOptions {
|
|
|
3822
4015
|
* @remarks
|
|
3823
4016
|
* Forward chaining is a naive fixpoint capped at `depth` iterations: rules run
|
|
3824
4017
|
* in ascending `priority` order each pass, and a firing rule's conclusion atoms
|
|
3825
|
-
* become a derived overlay that
|
|
4018
|
+
* become a derived overlay that shadows same-named subject fields on later
|
|
3826
4019
|
* passes (derived keys are `formatField(check.field)` strings). Convergence —
|
|
3827
4020
|
* one full pass with no new derivation — appends a trace containing
|
|
3828
4021
|
* `converged`. Final rule results re-evaluate against the settled overlay in
|
|
3829
|
-
*
|
|
3830
|
-
* overall `conclusion` is whether the
|
|
3831
|
-
* proves
|
|
4022
|
+
* original rule order (forward) / priority-sorted order (backward), and the
|
|
4023
|
+
* overall `conclusion` is whether the last result applied. Backward chaining
|
|
4024
|
+
* proves every rule goal-first: an unmet premise triggers sub-goal search
|
|
3832
4025
|
* through rules whose conclusion atoms assert the needed `field = value` pair,
|
|
3833
4026
|
* guarded by a visited-rule set (cycle-safe) plus the depth cap; `not` succeeds
|
|
3834
4027
|
* when its operand cannot be established (negation-as-failure) and `implies` is
|
|
3835
|
-
* vacuously true on an unprovable antecedent. Expression evaluation is
|
|
3836
|
-
* (no short-circuit); conclusion extraction
|
|
4028
|
+
* vacuously true on an unprovable antecedent. Expression evaluation is eager
|
|
4029
|
+
* (no short-circuit); conclusion extraction ignores connectives — every atom
|
|
3837
4030
|
* inside a conclusion is asserted, even under `not` / `or`. Overlay bookkeeping
|
|
3838
4031
|
* compares with SameValueZero (`equalValues`), so a NaN-valued conclusion
|
|
3839
4032
|
* derives once and the fixpoint converges. Nothing mutates its inputs; fully
|
|
@@ -3885,7 +4078,7 @@ export declare interface AggregatorOptions {
|
|
|
3885
4078
|
* Represents the outcome of logical reasoning.
|
|
3886
4079
|
*
|
|
3887
4080
|
* @remarks
|
|
3888
|
-
* `conclusion` is the
|
|
4081
|
+
* `conclusion` is the last evaluated rule's `applied` (`false` when no rule
|
|
3889
4082
|
* was evaluated); `count` tallies the applied rules; disabled rules are
|
|
3890
4083
|
* omitted from `rules` entirely.
|
|
3891
4084
|
*/
|
|
@@ -3904,9 +4097,9 @@ export declare interface AggregatorOptions {
|
|
|
3904
4097
|
*
|
|
3905
4098
|
* @remarks
|
|
3906
4099
|
* A missing or `null` field takes the factor's `fallback` directly (never the
|
|
3907
|
-
* `''` table key); a
|
|
3908
|
-
* `42` finds the key `'42'`, a real `''` value may hit a `''` key). Only
|
|
3909
|
-
* table keys hit — an absent or inherited key falls back.
|
|
4100
|
+
* `''` table key); a present value is stringified into a `table` key (a numeric
|
|
4101
|
+
* `42` finds the key `'42'`, a real `''` value may hit a `''` key). Only the
|
|
4102
|
+
* table's own keys hit — an absent or inherited key falls back.
|
|
3910
4103
|
*/
|
|
3911
4104
|
export declare interface LookupSource {
|
|
3912
4105
|
readonly origin: 'lookup';
|
|
@@ -3919,7 +4112,7 @@ export declare interface AggregatorOptions {
|
|
|
3919
4112
|
*
|
|
3920
4113
|
* @remarks
|
|
3921
4114
|
* The range test behind the `between` and `outside` `Comparison` operators: only
|
|
3922
|
-
* the
|
|
4115
|
+
* the first two elements of `range` are read, each end is inclusive, and a
|
|
3923
4116
|
* non-numeric `value`, a non-array `range`, a `range` shorter than two
|
|
3924
4117
|
* elements, or a non-numeric bound all report `false`. `outside` is the pure
|
|
3925
4118
|
* negation of this predicate, so a malformed range reads as outside.
|
|
@@ -3944,10 +4137,10 @@ export declare interface AggregatorOptions {
|
|
|
3944
4137
|
*
|
|
3945
4138
|
* @remarks
|
|
3946
4139
|
* The bidirectional unification of the inferential reasoner: a `'?'`-prefixed
|
|
3947
|
-
* string term on
|
|
4140
|
+
* string term on either side (pattern or candidate) is a variable that binds to
|
|
3948
4141
|
* the opposite term (the `'?'` prefix is kept in the binding key), while
|
|
3949
4142
|
* consistency is enforced within the match — a variable seen twice must bind the
|
|
3950
|
-
*
|
|
4143
|
+
* same value (raw `!==`) or the whole match fails. A predicate mismatch or an
|
|
3951
4144
|
* arity (term-count) mismatch fails immediately; non-variable terms must be
|
|
3952
4145
|
* strictly (`===`) equal.
|
|
3953
4146
|
*
|
|
@@ -3981,11 +4174,11 @@ export declare interface AggregatorOptions {
|
|
|
3981
4174
|
*
|
|
3982
4175
|
* @remarks
|
|
3983
4176
|
* A Strategic-Merge-Patch-style id-keyed upsert:
|
|
3984
|
-
* the result is ordered by `incoming`'s id order
|
|
4177
|
+
* the result is ordered by `incoming`'s id order first (each element resolved
|
|
3985
4178
|
* through `resolve` when its id also exists in `base`, defaulting to
|
|
3986
|
-
* incoming-wins-wholesale),
|
|
4179
|
+
* incoming-wins-wholesale), then the `base`-only survivors in `base`'s own
|
|
3987
4180
|
* order (retained, never deleted — merge is additive). Same-id twins within
|
|
3988
|
-
*
|
|
4181
|
+
* either input are deduped to their first occurrence.
|
|
3989
4182
|
*
|
|
3990
4183
|
* @typeParam T - An id-carrying element type
|
|
3991
4184
|
* @param base - The base collection
|
|
@@ -4009,7 +4202,7 @@ export declare interface AggregatorOptions {
|
|
|
4009
4202
|
* Reconciles two {@link InferentialDefinition}s onto `base`'s id.
|
|
4010
4203
|
*
|
|
4011
4204
|
* @remarks
|
|
4012
|
-
* The merge is
|
|
4205
|
+
* The merge is additive: a base-only inference or fact survives into the result
|
|
4013
4206
|
* and is never deleted, and a scalar absent from `incoming` keeps its base
|
|
4014
4207
|
* value — merge never clears a field, which is what
|
|
4015
4208
|
* {@link clearInferentialDefinition} is for. `inferences` and `facts` each
|
|
@@ -4035,7 +4228,7 @@ export declare interface AggregatorOptions {
|
|
|
4035
4228
|
* Reconciles two {@link LogicalDefinition}s onto `base`'s id.
|
|
4036
4229
|
*
|
|
4037
4230
|
* @remarks
|
|
4038
|
-
* The merge is
|
|
4231
|
+
* The merge is additive: a base-only rule survives into the result and is never
|
|
4039
4232
|
* deleted, and a scalar absent from `incoming` keeps its base value — merge
|
|
4040
4233
|
* never clears a field, which is what {@link clearLogicalDefinition} is for.
|
|
4041
4234
|
* `rules` merges through {@link mergeById} (incoming-wins-wholesale on a matched
|
|
@@ -4060,10 +4253,10 @@ export declare interface AggregatorOptions {
|
|
|
4060
4253
|
* Reconciles two {@link QuantitativeDefinition}s onto `base`'s id.
|
|
4061
4254
|
*
|
|
4062
4255
|
* @remarks
|
|
4063
|
-
* The merge is
|
|
4256
|
+
* The merge is additive: a base-only group survives into the result and is
|
|
4064
4257
|
* never deleted, and a scalar absent from `incoming` keeps its base value —
|
|
4065
4258
|
* merge never clears a field, which is what {@link clearQuantitativeDefinition}
|
|
4066
|
-
* is for. `groups` merges through {@link mergeById}; a matched (same-id)
|
|
4259
|
+
* is for. `groups` merges through {@link mergeById}; a matched (same-id) pair of
|
|
4067
4260
|
* groups recurses one level deeper — their `factors` also merge through
|
|
4068
4261
|
* `mergeById` — the one exception to incoming-wins-wholesale. Every other
|
|
4069
4262
|
* scalar / value-object field is incoming-wins-when-present, else base kept.
|
|
@@ -4109,7 +4302,7 @@ export declare interface AggregatorOptions {
|
|
|
4109
4302
|
* Reconciles two {@link SymbolicDefinition}s onto `base`'s id.
|
|
4110
4303
|
*
|
|
4111
4304
|
* @remarks
|
|
4112
|
-
* The merge is
|
|
4305
|
+
* The merge is additive: a base-only equation or variable survives into the
|
|
4113
4306
|
* result and is never deleted, and a scalar absent from `incoming` keeps its
|
|
4114
4307
|
* base value — merge never clears a field, which is what
|
|
4115
4308
|
* {@link clearSymbolicDefinition} is for. `equations` merges through
|
|
@@ -4153,8 +4346,8 @@ export declare interface AggregatorOptions {
|
|
|
4153
4346
|
*
|
|
4154
4347
|
* @remarks
|
|
4155
4348
|
* The safe inverse of the builders: `parseJSONAs` composed with the data guard
|
|
4156
|
-
* {@link isDefinition}. A built definition body
|
|
4157
|
-
* `JSON.stringify(definition)` round-trips through `parseDefinition`.
|
|
4349
|
+
* {@link isDefinition}. A built definition body is the durable JSON payload —
|
|
4350
|
+
* `JSON.stringify(definition)` round-trips through `parseDefinition`. The
|
|
4158
4351
|
* authoring hazards: a required `Check.value: undefined` drops its key on
|
|
4159
4352
|
* `JSON.stringify` (author `null` instead), and a `Fact.terms` element of
|
|
4160
4353
|
* `undefined` serializes to `null` (terms must be JSON-safe scalars/strings).
|
|
@@ -4175,7 +4368,7 @@ export declare interface AggregatorOptions {
|
|
|
4175
4368
|
|
|
4176
4369
|
/**
|
|
4177
4370
|
* Inserts `item` into an id-keyed collection, deduping any existing element
|
|
4178
|
-
* sharing its id, then placing it at the
|
|
4371
|
+
* sharing its id, then placing it at the start, or immediately before `target`.
|
|
4179
4372
|
*
|
|
4180
4373
|
* @remarks
|
|
4181
4374
|
* Mirrors {@link appendById}'s dedup-then-insert semantics exactly, only the
|
|
@@ -4351,7 +4544,7 @@ export declare interface AggregatorOptions {
|
|
|
4351
4544
|
* @remarks
|
|
4352
4545
|
* `base` is added before aggregation. Default: `0`.
|
|
4353
4546
|
* The final value is `base` plus the aggregation of the applied
|
|
4354
|
-
* groups' values (
|
|
4547
|
+
* groups' values (no weights at this level), clamped to `bounds`, then rounded
|
|
4355
4548
|
* to `precision` decimal places. Default: `4`.
|
|
4356
4549
|
*/
|
|
4357
4550
|
export declare interface QuantitativeDefinition {
|
|
@@ -4370,21 +4563,21 @@ export declare interface AggregatorOptions {
|
|
|
4370
4563
|
* Performs factor-based numeric scoring.
|
|
4371
4564
|
*
|
|
4372
4565
|
* @remarks
|
|
4373
|
-
* Each factor runs a fixed pipeline: checks gate (
|
|
4374
|
-
* (`fallback` when unresolvable) → finite check → transforms chain →
|
|
4375
|
-
* clamp → finite recheck. Factors evaluate in stable ascending `priority`
|
|
4566
|
+
* Each factor runs a fixed pipeline: checks gate (every check met) → source
|
|
4567
|
+
* resolve (`fallback` when unresolvable) → finite check → transforms chain →
|
|
4568
|
+
* bounds clamp → finite recheck. Factors evaluate in stable ascending `priority`
|
|
4376
4569
|
* order; a `strict` group is all-or-nothing; a group's value is its `base` plus
|
|
4377
|
-
* the weighted aggregation of its
|
|
4570
|
+
* the weighted aggregation of its applied factors, clamped (never rounded); the
|
|
4378
4571
|
* definition's value is its `base` plus the unweighted aggregation of the
|
|
4379
|
-
*
|
|
4572
|
+
* applied groups' values, clamped, then rounded to `precision`. A
|
|
4380
4573
|
* required-factor failure or non-finite value appends an error (`success:
|
|
4381
4574
|
* false`) without aborting — the numeric `value` is always computed. The
|
|
4382
|
-
* definition-level value is finite-checked
|
|
4575
|
+
* definition-level value is finite-checked after rounding: a non-finite
|
|
4383
4576
|
* aggregate (a `minimum` / `maximum` over zero applied groups) appends an error
|
|
4384
4577
|
* while the `NaN` stays visible in `value`. Field sources coerce through the
|
|
4385
4578
|
* contracts `parseNumberField`: a non-finite subject number or a non-numeric
|
|
4386
4579
|
* string is unresolvable and takes the fallback path. Lookup sources read only
|
|
4387
|
-
*
|
|
4580
|
+
* the table's own keys, and a missing / `null` field falls back directly. Nothing
|
|
4388
4581
|
* mutates its inputs; fully deterministic.
|
|
4389
4582
|
*
|
|
4390
4583
|
* @example
|
|
@@ -4454,7 +4647,7 @@ export declare interface AggregatorOptions {
|
|
|
4454
4647
|
* Represents a factor source banding a numeric subject field through ordered ranges.
|
|
4455
4648
|
*
|
|
4456
4649
|
* @remarks
|
|
4457
|
-
* Ranges are scanned in order and the
|
|
4650
|
+
* Ranges are scanned in order and the first match wins. A range without
|
|
4458
4651
|
* `bounds` matches anything (a catch-all); an absent bound side is open. No
|
|
4459
4652
|
* match falls back to the factor's `fallback`.
|
|
4460
4653
|
*/
|
|
@@ -4469,16 +4662,16 @@ export declare interface AggregatorOptions {
|
|
|
4469
4662
|
* {@link ReasonerInterface}s.
|
|
4470
4663
|
*
|
|
4471
4664
|
* @remarks
|
|
4472
|
-
* Holds
|
|
4665
|
+
* Holds no strategy-specific logic: dispatch is purely a registry lookup by
|
|
4473
4666
|
* `definition.reasoning` (one reasoner per reasoning; re-registration
|
|
4474
4667
|
* replaces). A missing reasoner throws `MISSING` and a pre-run validation
|
|
4475
|
-
* failure (when the `validate` option is on) throws `INVALID` —
|
|
4476
|
-
* `bail` and
|
|
4668
|
+
* failure (when the `validate` option is on) throws `INVALID` — each bypasses
|
|
4669
|
+
* `bail` and emits nothing. A reasoner throw emits `error` with the raw thrown
|
|
4477
4670
|
* value, then rethrows under `bail: true` (the default) or converts to a
|
|
4478
|
-
* type-shaped failure result under `bail: false`; only
|
|
4671
|
+
* type-shaped failure result under `bail: false`; only a successful result emits
|
|
4479
4672
|
* `reason` (synchronously, before returning). The batch overload maps subjects
|
|
4480
4673
|
* in order (validation, when on, repeats per subject). `destroy()` clears the
|
|
4481
|
-
* registry, emits `destroy`, then destroys the emitter
|
|
4674
|
+
* registry, emits `destroy`, then destroys the emitter last and is
|
|
4482
4675
|
* idempotent; every other method afterwards throws `DESTROYED` — only the
|
|
4483
4676
|
* {@link emitter} getter keeps working.
|
|
4484
4677
|
*
|
|
@@ -4529,7 +4722,7 @@ export declare interface AggregatorOptions {
|
|
|
4529
4722
|
*
|
|
4530
4723
|
* @remarks
|
|
4531
4724
|
* `reason` throws a `ReasonError` (`MISMATCH`) when handed a definition of a
|
|
4532
|
-
* different reasoning; every other malformation yields a failure
|
|
4725
|
+
* different reasoning; every other malformation yields a failure result, not a
|
|
4533
4726
|
* throw — the runtime never assumes `validate` ran. `supports` / `validate` /
|
|
4534
4727
|
* `reason` each take plain data only — a {@link DefinitionBuilderInterface} /
|
|
4535
4728
|
* {@link SubjectBuilderInterface}'s `build()` output is passed instead, by the
|
|
@@ -4538,8 +4731,18 @@ export declare interface AggregatorOptions {
|
|
|
4538
4731
|
export declare interface ReasonerInterface {
|
|
4539
4732
|
readonly id: string;
|
|
4540
4733
|
readonly reasoning: Reasoning;
|
|
4734
|
+
/**
|
|
4735
|
+
* Reports whether the definition's `reasoning` equals this adapter's own.
|
|
4736
|
+
*/
|
|
4541
4737
|
supports(definition: Definition): boolean;
|
|
4738
|
+
/**
|
|
4739
|
+
* Reports a definition's structural errors and soft warnings, evaluating nothing.
|
|
4740
|
+
*/
|
|
4542
4741
|
validate(definition: Definition): ReasonValidationResult;
|
|
4742
|
+
/**
|
|
4743
|
+
* Evaluates one subject against a definition, throwing only `MISMATCH` for a wrong
|
|
4744
|
+
* reasoning — a malformed definition yields a failure result.
|
|
4745
|
+
*/
|
|
4543
4746
|
reason(subject: Subject, definition: Definition): ReasonResult;
|
|
4544
4747
|
}
|
|
4545
4748
|
|
|
@@ -4592,11 +4795,12 @@ export declare interface AggregatorOptions {
|
|
|
4592
4795
|
*
|
|
4593
4796
|
* @remarks
|
|
4594
4797
|
* `register` fires when a reasoner is registered (carrying its reasoning);
|
|
4595
|
-
* `reason` fires once per
|
|
4798
|
+
* `reason` fires once per successful result, synchronously before it returns
|
|
4596
4799
|
* (bail-suppressed failure results do not fire it); `error` fires with the raw
|
|
4597
4800
|
* thrown value when a reasoner throws (regardless of `bail`); `destroy` fires
|
|
4598
4801
|
* once on teardown. Listener isolation is the emitter's own — a throwing
|
|
4599
|
-
* listener routes to the `error`
|
|
4802
|
+
* listener routes to the handler passed as the `error` option, never onto
|
|
4803
|
+
* this map.
|
|
4600
4804
|
*/
|
|
4601
4805
|
export declare type ReasonEventMap = {
|
|
4602
4806
|
/** Fires when a reasoner is registered — carries its reasoning. */
|
|
@@ -4610,8 +4814,8 @@ export declare interface AggregatorOptions {
|
|
|
4610
4814
|
};
|
|
4611
4815
|
|
|
4612
4816
|
/**
|
|
4613
|
-
* Names the
|
|
4614
|
-
* {@link ReasonResult}
|
|
4817
|
+
* Names the reasoning strategies — the axis a {@link Definition} and a
|
|
4818
|
+
* {@link ReasonResult} discriminate on.
|
|
4615
4819
|
*
|
|
4616
4820
|
* @remarks
|
|
4617
4821
|
* `quantitative` — factor-based numeric scoring. `logical` — rule-based boolean
|
|
@@ -4628,7 +4832,7 @@ export declare interface AggregatorOptions {
|
|
|
4628
4832
|
* @remarks
|
|
4629
4833
|
* Dispatch is purely by `definition.reasoning` registry lookup; a missing
|
|
4630
4834
|
* reasoner throws `MISSING` (never subject to `bail`, no `error` emit). The
|
|
4631
|
-
* batch `reason` overload maps subjects in order
|
|
4835
|
+
* batch `reason` overload maps subjects in order onto an equal-length result
|
|
4632
4836
|
* array. After `destroy()` every method except the `emitter` getter and
|
|
4633
4837
|
* `destroy` itself throws `DESTROYED`. `reason` and `validate` each take
|
|
4634
4838
|
* plain data only — a {@link DefinitionBuilderInterface} /
|
|
@@ -4637,13 +4841,40 @@ export declare interface AggregatorOptions {
|
|
|
4637
4841
|
*/
|
|
4638
4842
|
export declare interface ReasonInterface {
|
|
4639
4843
|
readonly emitter: EmitterInterface<ReasonEventMap>;
|
|
4844
|
+
/**
|
|
4845
|
+
* Dispatches one subject — or maps a subject array in order — to the registered reasoner.
|
|
4846
|
+
*
|
|
4847
|
+
* @remarks
|
|
4848
|
+
* A reasoning with no registered reasoner throws `MISSING`.
|
|
4849
|
+
*/
|
|
4640
4850
|
reason(subjects: readonly Subject[], definition: Definition): readonly ReasonResult[];
|
|
4641
4851
|
reason(subject: Subject, definition: Definition): ReasonResult;
|
|
4852
|
+
/**
|
|
4853
|
+
* Registers a reasoner, replacing one already registered for the same reasoning, and emits
|
|
4854
|
+
* the `register` event.
|
|
4855
|
+
*/
|
|
4642
4856
|
register(reasoner: ReasonerInterface): void;
|
|
4857
|
+
/**
|
|
4858
|
+
* Returns the one reasoner registered for a reasoning, or `undefined` when none is.
|
|
4859
|
+
*/
|
|
4643
4860
|
reasoner(reasoning: Reasoning): ReasonerInterface | undefined;
|
|
4861
|
+
/**
|
|
4862
|
+
* Lists every registered reasoner as a fresh array.
|
|
4863
|
+
*/
|
|
4644
4864
|
reasoners(): readonly ReasonerInterface[];
|
|
4865
|
+
/**
|
|
4866
|
+
* Reports whether a reasoner is registered for a reasoning.
|
|
4867
|
+
*/
|
|
4645
4868
|
supports(reasoning: Reasoning): boolean;
|
|
4869
|
+
/**
|
|
4870
|
+
* Delegates validation to the registered reasoner — a missing reasoner is an invalid result
|
|
4871
|
+
* here rather than a throw.
|
|
4872
|
+
*/
|
|
4646
4873
|
validate(definition: Definition): ReasonValidationResult;
|
|
4874
|
+
/**
|
|
4875
|
+
* Clears the registry, emits the `destroy` event, and destroys the emitter last; the call
|
|
4876
|
+
* is idempotent.
|
|
4877
|
+
*/
|
|
4647
4878
|
destroy(): void;
|
|
4648
4879
|
}
|
|
4649
4880
|
|
|
@@ -4769,7 +5000,7 @@ export declare interface AggregatorOptions {
|
|
|
4769
5000
|
* Deletes one field of a {@link Subject} — destructure-rest omit.
|
|
4770
5001
|
*
|
|
4771
5002
|
* @remarks
|
|
4772
|
-
* The key is
|
|
5003
|
+
* The key is deleted entirely (never set to `undefined`), keeping the result
|
|
4773
5004
|
* exact-record valid. A no-op (fresh copy) when `key` is absent.
|
|
4774
5005
|
*
|
|
4775
5006
|
* @param subject - The subject to update
|
|
@@ -4843,7 +5074,7 @@ export declare interface AggregatorOptions {
|
|
|
4843
5074
|
* Removes one entry of a {@link SymbolicDefinition}'s `variables`.
|
|
4844
5075
|
*
|
|
4845
5076
|
* @remarks
|
|
4846
|
-
* The destructure-rest form
|
|
5077
|
+
* The destructure-rest form omits the key entirely (never sets it to
|
|
4847
5078
|
* `undefined`), keeping the result exact-record valid. A no-op (fresh copy)
|
|
4848
5079
|
* when `name` is absent.
|
|
4849
5080
|
*
|
|
@@ -4867,8 +5098,8 @@ export declare interface AggregatorOptions {
|
|
|
4867
5098
|
* When `subject.id` is a string, each clone's id is minted
|
|
4868
5099
|
* `` `${baseId}-${index}` `` (index from `0`); with no string `id`, the clones
|
|
4869
5100
|
* pass through unchanged (still fresh copies). Pure and deterministic — the
|
|
4870
|
-
* same input always produces the same output (run-twice equality) — and
|
|
4871
|
-
*
|
|
5101
|
+
* same input always produces the same output (run-twice equality) — and emits
|
|
5102
|
+
* nothing. `count <= 0` yields an empty array.
|
|
4872
5103
|
*
|
|
4873
5104
|
* @param subject - The subject to clone
|
|
4874
5105
|
* @param count - How many clones to produce
|
|
@@ -4885,7 +5116,7 @@ export declare interface AggregatorOptions {
|
|
|
4885
5116
|
export declare function repeatSubject(subject: Subject, count: number): readonly Subject[];
|
|
4886
5117
|
|
|
4887
5118
|
/**
|
|
4888
|
-
* Swaps the element sharing `item.id`
|
|
5119
|
+
* Swaps the element sharing `item.id` in place, preserving its position.
|
|
4889
5120
|
*
|
|
4890
5121
|
* @remarks
|
|
4891
5122
|
* The position-preserving update primitive — unlike {@link appendById}, which
|
|
@@ -4910,8 +5141,8 @@ export declare interface AggregatorOptions {
|
|
|
4910
5141
|
}>(items: readonly T[], item: T): readonly T[];
|
|
4911
5142
|
|
|
4912
5143
|
/**
|
|
4913
|
-
* Swaps the equation sharing `equation.id` in a {@link SymbolicDefinition}
|
|
4914
|
-
*
|
|
5144
|
+
* Swaps the equation sharing `equation.id` in a {@link SymbolicDefinition} in
|
|
5145
|
+
* place, preserving its position (appended when absent).
|
|
4915
5146
|
*
|
|
4916
5147
|
* @param definition - The definition to update
|
|
4917
5148
|
* @param equation - The replacement equation
|
|
@@ -4928,8 +5159,8 @@ export declare interface AggregatorOptions {
|
|
|
4928
5159
|
export declare function replaceEquation(definition: SymbolicDefinition, equation: Equation): SymbolicDefinition;
|
|
4929
5160
|
|
|
4930
5161
|
/**
|
|
4931
|
-
* Swaps the fact sharing `fact.id` in an {@link InferentialDefinition}
|
|
4932
|
-
*
|
|
5162
|
+
* Swaps the fact sharing `fact.id` in an {@link InferentialDefinition} in
|
|
5163
|
+
* place, preserving its position (appended when absent).
|
|
4933
5164
|
*
|
|
4934
5165
|
* @param definition - The definition to update
|
|
4935
5166
|
* @param fact - The replacement fact
|
|
@@ -4946,8 +5177,8 @@ export declare interface AggregatorOptions {
|
|
|
4946
5177
|
export declare function replaceFact(definition: InferentialDefinition, fact: Fact): InferentialDefinition;
|
|
4947
5178
|
|
|
4948
5179
|
/**
|
|
4949
|
-
* Swaps the factor sharing `factor.id` in a {@link FactorGroup}
|
|
4950
|
-
* preserving its position (
|
|
5180
|
+
* Swaps the factor sharing `factor.id` in a {@link FactorGroup} in place,
|
|
5181
|
+
* preserving its position (appended when absent).
|
|
4951
5182
|
*
|
|
4952
5183
|
* @param group - The group to update
|
|
4953
5184
|
* @param factor - The replacement factor
|
|
@@ -4964,8 +5195,8 @@ export declare interface AggregatorOptions {
|
|
|
4964
5195
|
export declare function replaceFactor(group: FactorGroup, factor: Factor): FactorGroup;
|
|
4965
5196
|
|
|
4966
5197
|
/**
|
|
4967
|
-
* Swaps the group sharing `group.id` in a {@link QuantitativeDefinition}
|
|
4968
|
-
*
|
|
5198
|
+
* Swaps the group sharing `group.id` in a {@link QuantitativeDefinition} in
|
|
5199
|
+
* place, preserving its position (appended when absent).
|
|
4969
5200
|
*
|
|
4970
5201
|
* @param definition - The definition to update
|
|
4971
5202
|
* @param group - The replacement group
|
|
@@ -4983,7 +5214,7 @@ export declare interface AggregatorOptions {
|
|
|
4983
5214
|
|
|
4984
5215
|
/**
|
|
4985
5216
|
* Swaps the inference sharing `inference.id` in an {@link InferentialDefinition}
|
|
4986
|
-
*
|
|
5217
|
+
* in place, preserving its position (appended when absent).
|
|
4987
5218
|
*
|
|
4988
5219
|
* @param definition - The definition to update
|
|
4989
5220
|
* @param inference - The replacement inference
|
|
@@ -5001,8 +5232,8 @@ export declare interface AggregatorOptions {
|
|
|
5001
5232
|
export declare function replaceInference(definition: InferentialDefinition, inference: Inference): InferentialDefinition;
|
|
5002
5233
|
|
|
5003
5234
|
/**
|
|
5004
|
-
* Swaps the rule sharing `rule.id` in a {@link LogicalDefinition}
|
|
5005
|
-
* preserving its position (
|
|
5235
|
+
* Swaps the rule sharing `rule.id` in a {@link LogicalDefinition} in place,
|
|
5236
|
+
* preserving its position (appended when absent).
|
|
5006
5237
|
*
|
|
5007
5238
|
* @param definition - The definition to update
|
|
5008
5239
|
* @param rule - The replacement rule
|
|
@@ -5052,9 +5283,9 @@ export declare interface AggregatorOptions {
|
|
|
5052
5283
|
* source passes its value through; `field` and `range` coerce through the
|
|
5053
5284
|
* contracts `parseNumberField`, so a non-finite subject number or a
|
|
5054
5285
|
* non-numeric string is unresolvable and takes `fallback`; `lookup` reads only
|
|
5055
|
-
*
|
|
5286
|
+
* the table's own keys, and a missing or `null` field takes `fallback` directly
|
|
5056
5287
|
* rather than letting a `''` key intercept absent data. A `range` scans its
|
|
5057
|
-
* bands in order and the
|
|
5288
|
+
* bands in order and the first match wins — a band without `bounds` is a
|
|
5058
5289
|
* catch-all and an absent bound side is open. A malformed factor carrying no
|
|
5059
5290
|
* source at all takes `fallback` rather than crashing.
|
|
5060
5291
|
*
|
|
@@ -5079,9 +5310,9 @@ export declare interface AggregatorOptions {
|
|
|
5079
5310
|
* @remarks
|
|
5080
5311
|
* `Math.round` semantics — halves round toward `+∞` (`2.5` → `3`, `-2.5` → `-2`).
|
|
5081
5312
|
* A negative precision rounds at whole-number scales (`-1` → tens, `-2` →
|
|
5082
|
-
* hundreds).
|
|
5313
|
+
* hundreds). A precision whose scale factor overflows the double range
|
|
5083
5314
|
* (`10^p` → `Infinity` at roughly `p > 308`, `0` at roughly `p < -323`) returns
|
|
5084
|
-
* the value
|
|
5315
|
+
* the value unchanged — passthrough, never `NaN`.
|
|
5085
5316
|
*
|
|
5086
5317
|
* @param value - The number to round
|
|
5087
5318
|
* @param precision - Decimal places to keep (defaults to `0`)
|
|
@@ -5100,13 +5331,13 @@ export declare interface AggregatorOptions {
|
|
|
5100
5331
|
export declare function roundTo(value: number, precision?: number): number;
|
|
5101
5332
|
|
|
5102
5333
|
/**
|
|
5103
|
-
* Represents one deduction rule: when
|
|
5334
|
+
* Represents one deduction rule: when every premise holds, the `conclusion`'s atoms are
|
|
5104
5335
|
* asserted as derived facts.
|
|
5105
5336
|
*
|
|
5106
5337
|
* @remarks
|
|
5107
5338
|
* `priority` orders evaluation ascending, lower first. Default: `0`.
|
|
5108
5339
|
* `enabled: false` skips the rule (omitted from results). Conclusion extraction
|
|
5109
|
-
* ignores connectives —
|
|
5340
|
+
* ignores connectives — every atom inside the conclusion is asserted as a
|
|
5110
5341
|
* `field = value` fact, even under `not` / `or`.
|
|
5111
5342
|
*/
|
|
5112
5343
|
export declare interface Rule {
|
|
@@ -5124,17 +5355,17 @@ export declare interface AggregatorOptions {
|
|
|
5124
5355
|
* manager over a logical definition's `rules`.
|
|
5125
5356
|
*
|
|
5126
5357
|
* @remarks
|
|
5127
|
-
*
|
|
5358
|
+
* Owns its `rules` as a private {@link Collection} — copy-on-write state shared
|
|
5128
5359
|
* by composition with the other list managers — plus its own {@link Emitter}
|
|
5129
|
-
* over {@link RuleManagerEventMap}. Rule order is
|
|
5130
|
-
* conclusion is the
|
|
5360
|
+
* over {@link RuleManagerEventMap}. Rule order is load-bearing — the forward
|
|
5361
|
+
* conclusion is the last declared non-disabled rule, so `append` without a
|
|
5131
5362
|
* `target` makes the new rule the conclusion. `remove` is the batch family
|
|
5132
|
-
* (array form declared
|
|
5363
|
+
* (array form declared first): no argument removes every rule, one id removes
|
|
5133
5364
|
* that rule, an id list removes those rules and returns true only when every
|
|
5134
5365
|
* named id existed. It emits one `remove` per rule actually removed. `seat` is
|
|
5135
5366
|
* the owning builder's
|
|
5136
5367
|
* silent bulk re-seat channel (used by `merge`). `destroy()` is idempotent and
|
|
5137
|
-
* tears the emitter down
|
|
5368
|
+
* tears the emitter down last; any other call after it throws
|
|
5138
5369
|
* `ReasonError('DESTROYED', …)`.
|
|
5139
5370
|
*
|
|
5140
5371
|
* @example
|
|
@@ -5189,7 +5420,7 @@ export declare interface AggregatorOptions {
|
|
|
5189
5420
|
* `rules` — a self-owning, kind-free collection manager.
|
|
5190
5421
|
*
|
|
5191
5422
|
* @remarks
|
|
5192
|
-
* Rule order is load-bearing — the forward conclusion is the
|
|
5423
|
+
* Rule order is load-bearing — the forward conclusion is the last declared
|
|
5193
5424
|
* non-disabled rule, so `append` without a `target` makes a new rule the
|
|
5194
5425
|
* conclusion. `remove` is the batch family: no argument removes every rule,
|
|
5195
5426
|
* one id removes that rule, an id list removes those rules and returns true
|
|
@@ -5198,15 +5429,43 @@ export declare interface AggregatorOptions {
|
|
|
5198
5429
|
*/
|
|
5199
5430
|
export declare interface RuleManagerInterface {
|
|
5200
5431
|
readonly emitter: EmitterInterface<RuleManagerEventMap>;
|
|
5432
|
+
/**
|
|
5433
|
+
* Returns the one rule carrying an id, or `undefined` when none does.
|
|
5434
|
+
*/
|
|
5201
5435
|
rule(id: string): Rule | undefined;
|
|
5436
|
+
/**
|
|
5437
|
+
* Lists every rule in order.
|
|
5438
|
+
*/
|
|
5202
5439
|
rules(): readonly Rule[];
|
|
5440
|
+
/**
|
|
5441
|
+
* Inserts a rule at the end, or after `target`, removing a same-id rule first — an absent
|
|
5442
|
+
* `target` makes it the new forward conclusion.
|
|
5443
|
+
*/
|
|
5203
5444
|
append(rule: Rule, target?: string): void;
|
|
5445
|
+
/**
|
|
5446
|
+
* Inserts a rule at the start, or before `target`, removing a same-id rule first.
|
|
5447
|
+
*/
|
|
5204
5448
|
prepend(rule: Rule, target?: string): void;
|
|
5449
|
+
/**
|
|
5450
|
+
* Swaps a same-id rule in place, appending it when the collection carries none.
|
|
5451
|
+
*/
|
|
5205
5452
|
replace(rule: Rule): void;
|
|
5453
|
+
/**
|
|
5454
|
+
* Removes rules: every rule with no argument, one rule by id, or the rules an id list
|
|
5455
|
+
* names; the id forms report whether every named id existed.
|
|
5456
|
+
*/
|
|
5206
5457
|
remove(ids: readonly string[]): boolean;
|
|
5207
5458
|
remove(id: string): boolean;
|
|
5208
5459
|
remove(): void;
|
|
5460
|
+
/**
|
|
5461
|
+
* Replaces the whole collection in one silent call — the owning builder's bulk re-seat
|
|
5462
|
+
* channel.
|
|
5463
|
+
*/
|
|
5209
5464
|
seat(rules: readonly Rule[]): void;
|
|
5465
|
+
/**
|
|
5466
|
+
* Tears the manager down idempotently — emits the `destroy` event, then destroys the
|
|
5467
|
+
* emitter last.
|
|
5468
|
+
*/
|
|
5210
5469
|
destroy(): void;
|
|
5211
5470
|
}
|
|
5212
5471
|
|
|
@@ -5242,7 +5501,7 @@ export declare interface AggregatorOptions {
|
|
|
5242
5501
|
* @remarks
|
|
5243
5502
|
* The shared evaluation-order helper of the quantitative (factors) and logical
|
|
5244
5503
|
* (rules) reasoners: lower priorities run first, an absent `priority` defaults
|
|
5245
|
-
* to `0`, equal priorities keep
|
|
5504
|
+
* to `0`, equal priorities keep declaration order (stable), and the input array
|
|
5246
5505
|
* is never mutated. An array hole, `null`, or other non-record entry is dropped
|
|
5247
5506
|
* rather than sorted — the output may be shorter than the input.
|
|
5248
5507
|
*
|
|
@@ -5261,7 +5520,7 @@ export declare interface AggregatorOptions {
|
|
|
5261
5520
|
readonly priority?: number;
|
|
5262
5521
|
}>(items: readonly T[]): readonly T[];
|
|
5263
5522
|
|
|
5264
|
-
/** Represents
|
|
5523
|
+
/** Represents a static, field, lookup, or range factor source, discriminated by `origin`. */
|
|
5265
5524
|
export declare type Source = StaticSource | FieldSource | LookupSource | RangeSource;
|
|
5266
5525
|
|
|
5267
5526
|
/** Represents a factor source yielding a fixed number. */
|
|
@@ -5282,8 +5541,8 @@ export declare interface AggregatorOptions {
|
|
|
5282
5541
|
*
|
|
5283
5542
|
* @remarks
|
|
5284
5543
|
* Only `isSubjectBuilder` (`validators.ts`) reads this key, through `Reflect.get`.
|
|
5285
|
-
* Distinct from {@link DEFINITION_BUILDER_BRAND}, so
|
|
5286
|
-
* match
|
|
5544
|
+
* Distinct from {@link DEFINITION_BUILDER_BRAND}, so neither entity can ever
|
|
5545
|
+
* match the other's guard.
|
|
5287
5546
|
*/
|
|
5288
5547
|
export declare const SUBJECT_BUILDER_BRAND: unique symbol;
|
|
5289
5548
|
|
|
@@ -5292,27 +5551,26 @@ export declare interface AggregatorOptions {
|
|
|
5292
5551
|
* flat key-value collection, no managers.
|
|
5293
5552
|
*
|
|
5294
5553
|
* @remarks
|
|
5295
|
-
* `id` is
|
|
5554
|
+
* `id` is optional (`options?.id ?? seed.id`). When present, the builder is
|
|
5296
5555
|
* id-ful: `build()` carries that `id` and `clear()` restores it. When absent,
|
|
5297
|
-
* the builder is
|
|
5298
|
-
*
|
|
5299
|
-
*
|
|
5300
|
-
*
|
|
5301
|
-
*
|
|
5302
|
-
*
|
|
5303
|
-
*
|
|
5304
|
-
*
|
|
5305
|
-
*
|
|
5306
|
-
* `
|
|
5307
|
-
*
|
|
5308
|
-
* `
|
|
5309
|
-
*
|
|
5310
|
-
*
|
|
5311
|
-
*
|
|
5312
|
-
* durable payload each call. Post-destroy mutation throws
|
|
5556
|
+
* the builder is anonymous — `.id` is `undefined` and the accumulated subject
|
|
5557
|
+
* carries no `id` key. `field(key)` / `fields()` are the singular / plural
|
|
5558
|
+
* accessor pair over top-level keys only. `set(key, value)` delegates to
|
|
5559
|
+
* `assignField`; setting `id` throws `ReasonError('MISMATCH', …)`, because the
|
|
5560
|
+
* id is immutable through the entity, id-ful or anonymous alike. `remove` is
|
|
5561
|
+
* the batch family (array form declared first): no argument removes every
|
|
5562
|
+
* non-id field and emits one `remove` per key in key order, one key removes
|
|
5563
|
+
* that field, and a key list removes those fields. Removing `'id'` through a
|
|
5564
|
+
* keyed form throws the same `MISMATCH` for the same reason. `merge(incoming)`
|
|
5565
|
+
* delegates to `mergeSubjects` (incoming-wins, base `id` preserved — plain
|
|
5566
|
+
* {@link Subject} data only). `clear()` removes every non-id field, restoring
|
|
5567
|
+
* `{ id }` when id-ful or an empty record when anonymous. `repeat(count)`
|
|
5568
|
+
* returns `count` deterministic minted-id clones as plain payloads — a pure
|
|
5569
|
+
* read that emits nothing. `build(): Subject` is total, deterministic, and
|
|
5570
|
+
* returns a fresh durable payload each call. Post-destroy mutation throws
|
|
5313
5571
|
* `ReasonError('DESTROYED', …)` — only the `emitter` getter and `destroy`
|
|
5314
5572
|
* itself keep working, mirroring `Reason`. `destroy()` is idempotent and
|
|
5315
|
-
* tears the emitter down
|
|
5573
|
+
* tears the emitter down last.
|
|
5316
5574
|
*
|
|
5317
5575
|
* @example
|
|
5318
5576
|
* ```ts
|
|
@@ -5321,7 +5579,7 @@ export declare interface AggregatorOptions {
|
|
|
5321
5579
|
* const applicant = createSubjectBuilder({ id: 'alice', age: 25 })
|
|
5322
5580
|
* applicant.set('region', 'CA')
|
|
5323
5581
|
* applicant.merge({ licensed: true, accidents: 0 }) // incoming wins, id kept
|
|
5324
|
-
* applicant.remove(['accidents']) // batch form first — true when
|
|
5582
|
+
* applicant.remove(['accidents']) // batch form first — true when every key existed
|
|
5325
5583
|
* applicant.field('region') // 'CA'
|
|
5326
5584
|
* applicant.fields() // the live record
|
|
5327
5585
|
* applicant.repeat(2) // ids 'alice-0', 'alice-1'
|
|
@@ -5350,8 +5608,9 @@ export declare interface AggregatorOptions {
|
|
|
5350
5608
|
}
|
|
5351
5609
|
|
|
5352
5610
|
/**
|
|
5353
|
-
* Represents the push observation surface of a {@link SubjectBuilderInterface} —
|
|
5354
|
-
* verb-named
|
|
5611
|
+
* Represents the push observation surface of a {@link SubjectBuilderInterface} — the
|
|
5612
|
+
* verb-named `set`, `remove`, `merge`, `clear`, and `destroy` events, no generic
|
|
5613
|
+
* `change` / `status`.
|
|
5355
5614
|
*/
|
|
5356
5615
|
export declare type SubjectBuilderEventMap = {
|
|
5357
5616
|
/** Fires when a field is upserted — carries its key and new value. */
|
|
@@ -5371,41 +5630,80 @@ export declare interface AggregatorOptions {
|
|
|
5371
5630
|
* flat key-value collection, no managers.
|
|
5372
5631
|
*
|
|
5373
5632
|
* @remarks
|
|
5374
|
-
* `id` is
|
|
5633
|
+
* `id` is optional on the entity (`options?.id ?? seed.id`). When present,
|
|
5375
5634
|
* the builder is id-ful — `build()`'s output carries that `id` and `clear()`
|
|
5376
|
-
* restores it. When absent, the builder is
|
|
5377
|
-
* `build()`'s output carries
|
|
5635
|
+
* restores it. When absent, the builder is anonymous — `.id` is `undefined`,
|
|
5636
|
+
* `build()`'s output carries no `id` key, and `clear()` empties the record
|
|
5378
5637
|
* entirely. `field` / `fields` are the singular / plural accessor pair over
|
|
5379
|
-
*
|
|
5380
|
-
* `
|
|
5638
|
+
* top-level keys only. `set(key, value)` delegates to `assignField`; setting
|
|
5639
|
+
* `id` throws, because the id is immutable through the entity, id-ful or
|
|
5381
5640
|
* anonymous alike. `remove` is the batch family: no argument removes every
|
|
5382
5641
|
* non-id field and emits one `remove` per key in the builder's key order, one
|
|
5383
5642
|
* key removes that field, and a key list removes those fields and returns true
|
|
5384
|
-
* only when every named key existed. The array form is declared
|
|
5643
|
+
* only when every named key existed. The array form is declared first.
|
|
5385
5644
|
* `merge(incoming)` delegates to `mergeSubjects` (incoming-wins, base `id`
|
|
5386
5645
|
* preserved — plain {@link Subject} data only). `clear()` removes every
|
|
5387
5646
|
* non-id field. `repeat(count)` returns `count`
|
|
5388
|
-
* deterministic minted-id clones as
|
|
5389
|
-
*
|
|
5647
|
+
* deterministic minted-id clones as plain payloads — a pure read that emits
|
|
5648
|
+
* nothing. `build(): Subject` is total, deterministic, and returns a fresh
|
|
5390
5649
|
* durable payload each call — `fields()` returns the live record and `build()`
|
|
5391
5650
|
* returns a fresh copy of it. Post-destroy
|
|
5392
5651
|
* mutation throws `ReasonError('DESTROYED', …)`; `destroy()` is idempotent
|
|
5393
|
-
* and tears the emitter down
|
|
5652
|
+
* and tears the emitter down last.
|
|
5394
5653
|
*/
|
|
5395
5654
|
export declare interface SubjectBuilderInterface {
|
|
5396
5655
|
readonly [SUBJECT_BUILDER_BRAND]: true;
|
|
5397
5656
|
readonly id: string | undefined;
|
|
5398
5657
|
readonly emitter: EmitterInterface<SubjectBuilderEventMap>;
|
|
5658
|
+
/**
|
|
5659
|
+
* Reads one top-level field by key.
|
|
5660
|
+
*/
|
|
5399
5661
|
field(key: string): unknown;
|
|
5662
|
+
/**
|
|
5663
|
+
* Reads the whole current record live.
|
|
5664
|
+
*/
|
|
5400
5665
|
fields(): Subject;
|
|
5666
|
+
/**
|
|
5667
|
+
* Upserts one field; setting `id` throws, because the id is immutable for an id-ful and
|
|
5668
|
+
* an anonymous builder alike.
|
|
5669
|
+
*
|
|
5670
|
+
* @remarks
|
|
5671
|
+
* The write goes through the exported `assignField` helper, so the builder and the pure
|
|
5672
|
+
* helper family agree on what a field write is.
|
|
5673
|
+
*/
|
|
5401
5674
|
set(key: string, value: unknown): void;
|
|
5675
|
+
/**
|
|
5676
|
+
* Removes non-id fields: every field with no argument, one field by key, or the fields a
|
|
5677
|
+
* key list names; the keyed forms report whether every named key existed.
|
|
5678
|
+
*
|
|
5679
|
+
* @remarks
|
|
5680
|
+
* The no-argument form emits one `remove` event per key, in the builder's key order.
|
|
5681
|
+
*/
|
|
5402
5682
|
remove(keys: readonly string[]): boolean;
|
|
5403
5683
|
remove(key: string): boolean;
|
|
5404
5684
|
remove(): void;
|
|
5685
|
+
/**
|
|
5686
|
+
* Reconciles with an incoming plain `Subject`; the incoming record wins and the base `id`
|
|
5687
|
+
* is kept.
|
|
5688
|
+
*/
|
|
5405
5689
|
merge(incoming: Subject): void;
|
|
5690
|
+
/**
|
|
5691
|
+
* Removes every non-id field.
|
|
5692
|
+
*/
|
|
5406
5693
|
clear(): void;
|
|
5694
|
+
/**
|
|
5695
|
+
* Produces `count` deterministic minted-id clones as plain payloads — a pure read that
|
|
5696
|
+
* emits nothing.
|
|
5697
|
+
*/
|
|
5407
5698
|
repeat(count: number): readonly Subject[];
|
|
5699
|
+
/**
|
|
5700
|
+
* Returns a fresh durable payload snapshot of the current state — total and deterministic
|
|
5701
|
+
* on every call.
|
|
5702
|
+
*/
|
|
5408
5703
|
build(): Subject;
|
|
5704
|
+
/**
|
|
5705
|
+
* Tears the builder down idempotently — destroys the emitter last.
|
|
5706
|
+
*/
|
|
5409
5707
|
destroy(): void;
|
|
5410
5708
|
}
|
|
5411
5709
|
|
|
@@ -5413,9 +5711,9 @@ export declare interface AggregatorOptions {
|
|
|
5413
5711
|
* Configures `createSubjectBuilder` / the `SubjectBuilder` constructor.
|
|
5414
5712
|
*
|
|
5415
5713
|
* @remarks
|
|
5416
|
-
* `id` — overrides the seed subject's `id`. Default: `seed.id`.
|
|
5714
|
+
* `id` — overrides the seed subject's `id`. Default: `seed.id`. It is optional
|
|
5417
5715
|
* — when neither `options.id` nor a string `seed.id` is present the builder
|
|
5418
|
-
* is
|
|
5716
|
+
* is anonymous (`.id` is `undefined`, `build()` emits no `id` key). `on` —
|
|
5419
5717
|
* initial event listeners. `error` — the emitter's listener-error handler.
|
|
5420
5718
|
*/
|
|
5421
5719
|
export declare interface SubjectBuilderOptions {
|
|
@@ -5429,7 +5727,7 @@ export declare interface AggregatorOptions {
|
|
|
5429
5727
|
* inferential reasoner's subject-injection step.
|
|
5430
5728
|
*
|
|
5431
5729
|
* @remarks
|
|
5432
|
-
* Every own subject field
|
|
5730
|
+
* Every own subject field except `id` becomes a `has(key, value)` fact at full
|
|
5433
5731
|
* `DEFAULT_CONFIDENCE`; `null` / `undefined` and any `object` (including arrays)
|
|
5434
5732
|
* value is skipped. The returned `trace` carries one line per injection plus a
|
|
5435
5733
|
* final count when at least one fact was produced, so no caller-owned
|
|
@@ -5463,9 +5761,9 @@ export declare interface AggregatorOptions {
|
|
|
5463
5761
|
* Defines equation-solving.
|
|
5464
5762
|
*
|
|
5465
5763
|
* @remarks
|
|
5466
|
-
* `variables` seeds the bindings; numeric subject fields
|
|
5764
|
+
* `variables` seeds the bindings; numeric subject fields override same-named
|
|
5467
5765
|
* variables. Equations solve strictly in order, each solution rounded to
|
|
5468
|
-
* `precision` decimal places
|
|
5766
|
+
* `precision` decimal places before feeding forward into later equations.
|
|
5469
5767
|
* Default: `4`.
|
|
5470
5768
|
*/
|
|
5471
5769
|
export declare interface SymbolicDefinition {
|
|
@@ -5487,16 +5785,16 @@ export declare interface AggregatorOptions {
|
|
|
5487
5785
|
* @remarks
|
|
5488
5786
|
* Bindings seed from `definition.variables`, then numeric subject fields (a
|
|
5489
5787
|
* finite number or a numeric string, coerced through the contracts
|
|
5490
|
-
* `parseNumber`)
|
|
5788
|
+
* `parseNumber`) override same-named variables — the `id` field is skipped.
|
|
5491
5789
|
* Equations solve strictly in order: when the `target` is unbound and appears
|
|
5492
|
-
* on exactly
|
|
5790
|
+
* on exactly one side, it is isolated by peeling invertible operations (`add` /
|
|
5493
5791
|
* `subtract` / `multiply` / `divide`); a non-invertible operation, a target on
|
|
5494
5792
|
* both sides of an operation, or an unbound variable throws internally — the
|
|
5495
|
-
* throw is caught
|
|
5793
|
+
* throw is caught per equation and surfaced as a result error (`Equation
|
|
5496
5794
|
* "<id>": <message>` plus a `FAILED` trace) while later equations still run.
|
|
5497
5795
|
* Inversion or division by zero yields `NaN`, caught by the non-finite check.
|
|
5498
|
-
* A solved value is rounded to `precision`
|
|
5499
|
-
* see the rounded value; `solutions` reads
|
|
5796
|
+
* A solved value is rounded to `precision` before binding, so later equations
|
|
5797
|
+
* see the rounded value; `solutions` reads the settled bindings keyed by each
|
|
5500
5798
|
* equation's target (a failed equation's target still appears when bound
|
|
5501
5799
|
* elsewhere). Nothing mutates its inputs; fully deterministic.
|
|
5502
5800
|
*
|
|
@@ -5561,9 +5859,9 @@ export declare interface AggregatorOptions {
|
|
|
5561
5859
|
* forward-chaining dedupe. Primitives (and `null`) key by value, typeof-prefixed
|
|
5562
5860
|
* so `1` (`number:1`) never collides with `'1'` (`string:1`); `-0` folds to `+0`
|
|
5563
5861
|
* (both `number:0`) and `NaN` is self-consistent (`number:NaN`), matching
|
|
5564
|
-
* SameValueZero. Objects and functions key by
|
|
5862
|
+
* SameValueZero. Objects and functions key by reference through `identities` — a
|
|
5565
5863
|
* first sighting is assigned the map's current size as its id, so distinct
|
|
5566
|
-
* objects never collide and the
|
|
5864
|
+
* objects never collide and the same reference always reproduces its key.
|
|
5567
5865
|
*
|
|
5568
5866
|
* @param term - The term to key
|
|
5569
5867
|
* @param identities - The caller-created reference-identity ledger, threaded across a dedupe pass (a newly seen object/function is registered in it)
|
|
@@ -5598,7 +5896,7 @@ export declare interface AggregatorOptions {
|
|
|
5598
5896
|
* per-factor pipeline stage.
|
|
5599
5897
|
*
|
|
5600
5898
|
* @remarks
|
|
5601
|
-
*
|
|
5899
|
+
* Total: never throws. Absent-`operand` defaults are operation-specific —
|
|
5602
5900
|
* identity-preserving `1` for `multiply` / `divide` / `power`, `0` for every
|
|
5603
5901
|
* other binary operation; `round` / `ceil` / `floor` / `abs` are unary and
|
|
5604
5902
|
* ignore the operand. `divide` by zero yields `NaN` (deliberately not JS's
|
|
@@ -5637,7 +5935,14 @@ export declare interface AggregatorOptions {
|
|
|
5637
5935
|
*/
|
|
5638
5936
|
export declare interface TransformerInterface {
|
|
5639
5937
|
readonly id: string;
|
|
5938
|
+
/**
|
|
5939
|
+
* Applies one math step — an absent operand defaults to `1` for `multiply` / `divide` /
|
|
5940
|
+
* `power`, and to `0` otherwise.
|
|
5941
|
+
*/
|
|
5640
5942
|
apply(value: number, transform: Transform): number;
|
|
5943
|
+
/**
|
|
5944
|
+
* Left-folds a transform list over the value; `NaN` flows through and no step is skipped.
|
|
5945
|
+
*/
|
|
5641
5946
|
chain(value: number, transforms: readonly Transform[]): number;
|
|
5642
5947
|
}
|
|
5643
5948
|
|
|
@@ -5663,17 +5968,17 @@ export declare interface AggregatorOptions {
|
|
|
5663
5968
|
* unordered record.
|
|
5664
5969
|
*
|
|
5665
5970
|
* @remarks
|
|
5666
|
-
*
|
|
5971
|
+
* Owns its `#variables` record as private copy-on-write state and its own
|
|
5667
5972
|
* {@link Emitter} over {@link VariableManagerEventMap}. The record has no
|
|
5668
5973
|
* placement, so only `add` / `remove` exist (no `append` / `prepend`): `add`
|
|
5669
5974
|
* upserts and emits `add(name)`, `remove` omits the key entirely (never sets
|
|
5670
5975
|
* `undefined`) and emits `remove(name)`. `remove` is the batch family over
|
|
5671
|
-
*
|
|
5976
|
+
* names (array form declared first): no argument removes every variable, one
|
|
5672
5977
|
* name removes that variable, a name list removes those variables and returns
|
|
5673
5978
|
* true only when every named variable existed. It emits one `remove` per
|
|
5674
5979
|
* variable actually removed. `seat` is the owning builder's silent
|
|
5675
5980
|
* bulk re-seat channel (used by `merge`). `destroy()` is idempotent and tears
|
|
5676
|
-
* the emitter down
|
|
5981
|
+
* the emitter down last; any other call after it throws
|
|
5677
5982
|
* `ReasonError('DESTROYED', …)`.
|
|
5678
5983
|
*
|
|
5679
5984
|
* @example
|
|
@@ -5709,7 +6014,7 @@ export declare interface AggregatorOptions {
|
|
|
5709
6014
|
*
|
|
5710
6015
|
* @remarks
|
|
5711
6016
|
* `variables` is a name-keyed record with no placement, so the honest verbs
|
|
5712
|
-
* are `add` / `remove` — each carries the variable
|
|
6017
|
+
* are `add` / `remove` — each carries the variable name.
|
|
5713
6018
|
*/
|
|
5714
6019
|
export declare type VariableManagerEventMap = {
|
|
5715
6020
|
/** Fires when a variable is upserted — carries its name. */
|
|
@@ -5726,7 +6031,7 @@ export declare interface AggregatorOptions {
|
|
|
5726
6031
|
* only write verbs (no placement). A self-owning, kind-free manager.
|
|
5727
6032
|
*
|
|
5728
6033
|
* @remarks
|
|
5729
|
-
* The record is keyed by
|
|
6034
|
+
* The record is keyed by name, so `remove`'s batch family is over names: no
|
|
5730
6035
|
* argument removes every variable, one name removes that variable, a name list
|
|
5731
6036
|
* removes those variables and returns true only when every named variable
|
|
5732
6037
|
* existed. It emits one `remove` per variable actually removed — a name
|
|
@@ -5734,13 +6039,37 @@ export declare interface AggregatorOptions {
|
|
|
5734
6039
|
*/
|
|
5735
6040
|
export declare interface VariableManagerInterface {
|
|
5736
6041
|
readonly emitter: EmitterInterface<VariableManagerEventMap>;
|
|
6042
|
+
/**
|
|
6043
|
+
* Returns the one variable's value carrying a name, or `undefined` when none does.
|
|
6044
|
+
*/
|
|
5737
6045
|
variable(name: string): number | undefined;
|
|
6046
|
+
/**
|
|
6047
|
+
* Returns the whole name-keyed record.
|
|
6048
|
+
*/
|
|
5738
6049
|
variables(): Readonly<Record<string, number>>;
|
|
6050
|
+
/**
|
|
6051
|
+
* Upserts one entry and emits the `add` event with the variable name.
|
|
6052
|
+
*/
|
|
5739
6053
|
add(name: string, value: number): void;
|
|
6054
|
+
/**
|
|
6055
|
+
* Removes variables: every variable with no argument, one variable by name, or the
|
|
6056
|
+
* variables a name list names; the name forms report whether every named variable existed.
|
|
6057
|
+
*
|
|
6058
|
+
* @remarks
|
|
6059
|
+
* Each removal omits the key rather than setting it to `undefined`, and emits the `remove`
|
|
6060
|
+
* event carrying the variable name.
|
|
6061
|
+
*/
|
|
5740
6062
|
remove(names: readonly string[]): boolean;
|
|
5741
6063
|
remove(name: string): boolean;
|
|
5742
6064
|
remove(): void;
|
|
6065
|
+
/**
|
|
6066
|
+
* Replaces the whole record in one silent call — the owning builder's bulk re-seat channel.
|
|
6067
|
+
*/
|
|
5743
6068
|
seat(variables: Readonly<Record<string, number>>): void;
|
|
6069
|
+
/**
|
|
6070
|
+
* Tears the manager down idempotently — emits the `destroy` event, then destroys the
|
|
6071
|
+
* emitter last.
|
|
6072
|
+
*/
|
|
5744
6073
|
destroy(): void;
|
|
5745
6074
|
}
|
|
5746
6075
|
|