@orkestrel/program 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -33
- package/dist/src/core/index.cjs +452 -225
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +1846 -1201
- package/dist/src/core/index.d.ts +1846 -1201
- package/dist/src/core/index.js +445 -217
- package/dist/src/core/index.js.map +1 -1
- package/package.json +17 -19
package/README.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
# @orkestrel/program
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
> The program composition layer: a pure, JSON-serializable `ProgramDefinition`
|
|
4
|
+
> that composes one qualification with an optional rating, plus notices,
|
|
5
|
+
> authority, and batch aggregate policy, and a `Program` that executes that
|
|
6
|
+
> definition in one direction — qualify, select, rate, derive status, then decide.
|
|
7
|
+
|
|
8
|
+
Build a definition with the `buildProgramDefinition` function, compile it with
|
|
9
|
+
`createProgram`, and call `execute` with one subject for a `ProgramResult` or
|
|
10
|
+
with a subject array for an `AggregateResult`. Execution never mutates its
|
|
11
|
+
inputs; every result is a fresh object. Injected qualifier, rater, and reason
|
|
12
|
+
instances stay caller-owned, and a standalone program owns the engine it creates.
|
|
13
|
+
Built over [`@orkestrel/qualifier`](https://github.com/orkestrel/qualifier),
|
|
14
|
+
[`@orkestrel/rater`](https://github.com/orkestrel/rater), and the shared
|
|
15
|
+
[`@orkestrel/reason`](https://github.com/orkestrel/reason) engine.
|
|
16
|
+
Environment-agnostic — no I/O, no browser or server assumptions. Part of the
|
|
17
|
+
`@orkestrel` line.
|
|
15
18
|
|
|
16
19
|
## Install
|
|
17
20
|
|
|
@@ -21,52 +24,56 @@ npm install @orkestrel/program
|
|
|
21
24
|
|
|
22
25
|
## Requirements
|
|
23
26
|
|
|
24
|
-
- Node.js >=
|
|
25
|
-
- ESM (`import`) and CommonJS (`require`)
|
|
27
|
+
- Node.js >= 22.12.0
|
|
28
|
+
- ESM (`import`) and CommonJS (`require`) through the `exports` field
|
|
26
29
|
|
|
27
30
|
## Usage
|
|
28
31
|
|
|
29
32
|
```ts
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
+
import { buildProgramDefinition, createProgram } from '@orkestrel/program'
|
|
34
|
+
import { createQualificationDefinition, createRuling } from '@orkestrel/qualifier'
|
|
35
|
+
import { buildLineDefinition, buildRatingDefinition } from '@orkestrel/rater'
|
|
33
36
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
createAtom,
|
|
38
|
+
createFactorGroup,
|
|
39
|
+
createLogicalDefinition,
|
|
40
|
+
createQuantitativeDefinition,
|
|
41
|
+
createRule,
|
|
42
|
+
createStaticFactor,
|
|
40
43
|
} from '@orkestrel/reason'
|
|
41
44
|
|
|
42
|
-
const gates =
|
|
43
|
-
|
|
45
|
+
const gates = createLogicalDefinition('gates', 'Eligibility gates', [
|
|
46
|
+
createRule(
|
|
47
|
+
'licensed',
|
|
48
|
+
[createAtom('licensed', 'equals', false)],
|
|
49
|
+
createAtom('blocked', 'equals', true),
|
|
50
|
+
),
|
|
44
51
|
])
|
|
45
52
|
|
|
46
|
-
const qualification =
|
|
53
|
+
const qualification = createQualificationDefinition(
|
|
47
54
|
'standard-qualification',
|
|
48
55
|
'Standard qualification',
|
|
49
56
|
[gates],
|
|
50
57
|
{
|
|
51
58
|
rulings: [
|
|
52
|
-
|
|
59
|
+
createRuling('license', 'gates', 'licensed', 'restriction', {
|
|
53
60
|
message: 'A license is required',
|
|
54
61
|
}),
|
|
55
62
|
],
|
|
56
63
|
},
|
|
57
64
|
)
|
|
58
65
|
|
|
59
|
-
const base =
|
|
66
|
+
const base = buildLineDefinition(
|
|
60
67
|
'base',
|
|
61
68
|
'Base premium',
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
createQuantitativeDefinition('base-rate', 'Base rate', [
|
|
70
|
+
createFactorGroup('amount', 'sum', [createStaticFactor('minimum', 100)]),
|
|
64
71
|
]),
|
|
65
72
|
)
|
|
66
73
|
|
|
67
|
-
const rating =
|
|
74
|
+
const rating = buildRatingDefinition('standard-rating', 'Standard rating', [base])
|
|
68
75
|
|
|
69
|
-
const definition =
|
|
76
|
+
const definition = buildProgramDefinition('standard', 'Standard program', qualification, rating)
|
|
70
77
|
|
|
71
78
|
const program = createProgram(definition)
|
|
72
79
|
|
|
@@ -102,7 +109,7 @@ one aggregate-aware batch and returns an `AggregateResult`. Every single-subject
|
|
|
102
109
|
|
|
103
110
|
For the full surface — `Program`, `ProgramManager`, `ProgramResult`,
|
|
104
111
|
`AggregateResult`, validators, factories, errors, and options — see
|
|
105
|
-
[`guides/
|
|
112
|
+
[`guides/program.md`](guides/program.md).
|
|
106
113
|
|
|
107
114
|
## Package
|
|
108
115
|
|