@orkestrel/rater 0.0.1 → 0.0.3

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 CHANGED
@@ -1,18 +1,13 @@
1
1
  # @orkestrel/rater
2
2
 
3
- A typed **rating engine**: programs compile line, pass, and ruling definitions
4
- into determinations, worksheets, and aggregates for rated subjects. Pure,
5
- authored **program definitions** — `lines` (quantitative rating), `passes`
6
- (ordered pre-rating overlays), `rulings` (rule id → effect routing), `notices`,
7
- and an optional `authority` (a final logical gate deriving a `decision`) — are
8
- compiled and rated over ONE shared [`@orkestrel/reason`](https://github.com/orkestrel/reason)
9
- engine (`quantitative` + `logical` reasoners). Rating never mutates its
10
- inputs: every result — `LineResult`, `ProgramResult`, `SubjectResult`,
11
- `AggregateResult` — is a fresh object carrying a `trace` and accumulated
12
- `errors`. Batch rating additionally supports per-program aggregate fields, an
13
- optional partition key, and gated aggregate determinations, plus per-`Status`
14
- tallies. Environment-agnostic — no I/O, no browser or server assumptions.
15
- Part of the `@orkestrel` line.
3
+ A typed **quantitative rating layer** over [`@orkestrel/reason`](https://github.com/orkestrel/reason):
4
+ authored **lines** — each a plain reason `QuantitativeDefinition` joined to display
5
+ metadata — are rated against a **subject** (a plain data record) to produce a
6
+ `LineResult` per line (an `amount` plus its `Worksheet` audit trail) and one
7
+ `RatingResult` (every line's outcome plus a derived `total`). The caller decides
8
+ which lines to rate; `Rater` only evaluates what it is given. Rating never mutates
9
+ its inputs — every result is a fresh object. Environment-agnostic — no I/O, no
10
+ browser or server assumptions. Part of the `@orkestrel` line.
16
11
 
17
12
  ## Install
18
13
 
@@ -23,12 +18,12 @@ npm install @orkestrel/rater
23
18
  ## Requirements
24
19
 
25
20
  - Node.js >= 24
26
- - ESM-only (no CommonJS build)
21
+ - ESM (`import`) and CommonJS (`require`) via the `exports` field
27
22
 
28
23
  ## Usage
29
24
 
30
25
  ```ts
31
- import { createRater, lineDefinition, programDefinition } from '@orkestrel/rater'
26
+ import { createRater, lineDefinition } from '@orkestrel/rater'
32
27
  import { factorGroup, quantitativeDefinition, staticFactor } from '@orkestrel/reason'
33
28
 
34
29
  const rater = createRater()
@@ -41,26 +36,23 @@ const base = lineDefinition(
41
36
  ]),
42
37
  )
43
38
 
44
- rater.programs.add(programDefinition('p1', 'Program', [base]))
39
+ const result = rater.rate([base], { id: 'subject-1' })
40
+ result.lines[0]?.amount // 100
41
+ result.total // 100
45
42
 
46
- const result = rater.rate({ id: 'subject-1' }) // one subject → one SubjectResult
47
- result.programs[0]?.eligibility // 'eligible'
48
-
49
- rater.rate([{ id: 'a' }, { id: 'b' }]) // an ARRAY resolves to the batch AggregateResult overload
43
+ rater.emitter.on('rate', (subject, rated) => rated.success)
50
44
 
51
45
  rater.destroy()
52
46
  ```
53
47
 
54
- `rate` dispatches by input shape — an ARRAY resolves to the batch
55
- `AggregateResult` overload, a single subject resolves to `SubjectResult`.
56
- Every applied determination and derived decision fires through
57
- `rater.emitter` (`rate` / `aggregate` / `determine` / `decide`).
48
+ `rate` accepts a plain `LineDefinition[]` or a full `RatingDefinition` plus one
49
+ subject — both overloads rate a single subject. Every `rate` call fires once
50
+ through `rater.emitter` (`rate`).
58
51
 
59
52
  ## Guide
60
53
 
61
- For the full surface — the `Rater` orchestrator, compiled `Program`s, the
62
- ordered `ProgramManager`, worksheet and determination helpers, validators,
63
- factories, errors, and the observation surface — see
54
+ For the full surface — `Rater`, `RatingResult`, worksheet types, validators,
55
+ factories, errors, and options — see
64
56
  [`guides/src/rater.md`](guides/src/rater.md).
65
57
 
66
58
  ## Package