@orkestrel/program 0.0.1
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/LICENSE +21 -0
- package/README.md +114 -0
- package/dist/src/core/index.cjs +1435 -0
- package/dist/src/core/index.cjs.map +1 -0
- package/dist/src/core/index.d.cts +1137 -0
- package/dist/src/core/index.d.ts +1137 -0
- package/dist/src/core/index.js +1390 -0
- package/dist/src/core/index.js.map +1 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Orkestrel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# @orkestrel/program
|
|
2
|
+
|
|
3
|
+
A **program composition layer** over
|
|
4
|
+
[`@orkestrel/qualifier`](https://github.com/orkestrel/qualifier) and
|
|
5
|
+
[`@orkestrel/rater`](https://github.com/orkestrel/rater): a pure,
|
|
6
|
+
JSON-serializable `ProgramDefinition` composes one qualification with an optional
|
|
7
|
+
rating, plus optional notices, authority, and batch aggregate policy. `Program` executes
|
|
8
|
+
the workflow in one direction — qualify the subject, stop on terminal
|
|
9
|
+
qualification, select eligible rating lines, rate only those lines, derive status,
|
|
10
|
+
then evaluate optional authority — returning a nested `ProgramResult` (or
|
|
11
|
+
`AggregateResult` for batch `execute`). Globally ineligible or referred subjects
|
|
12
|
+
never reach the rater. Execution never mutates its inputs — every result is a
|
|
13
|
+
fresh object. Environment-agnostic — no I/O, no browser or server assumptions.
|
|
14
|
+
Part of the `@orkestrel` line.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @orkestrel/program
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
- Node.js >= 24
|
|
25
|
+
- ESM (`import`) and CommonJS (`require`) via the `exports` field
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { createProgram, programDefinition } from '@orkestrel/program'
|
|
31
|
+
import { qualificationDefinition, rulingDefinition } from '@orkestrel/qualifier'
|
|
32
|
+
import { lineDefinition, ratingDefinition } from '@orkestrel/rater'
|
|
33
|
+
import {
|
|
34
|
+
atom,
|
|
35
|
+
factorGroup,
|
|
36
|
+
logicalDefinition,
|
|
37
|
+
quantitativeDefinition,
|
|
38
|
+
rule,
|
|
39
|
+
staticFactor,
|
|
40
|
+
} from '@orkestrel/reason'
|
|
41
|
+
|
|
42
|
+
const gates = logicalDefinition('gates', 'Eligibility gates', [
|
|
43
|
+
rule('licensed', [atom('licensed', 'equals', false)], atom('blocked', 'equals', true)),
|
|
44
|
+
])
|
|
45
|
+
|
|
46
|
+
const qualification = qualificationDefinition(
|
|
47
|
+
'standard-qualification',
|
|
48
|
+
'Standard qualification',
|
|
49
|
+
[gates],
|
|
50
|
+
{
|
|
51
|
+
rulings: [
|
|
52
|
+
rulingDefinition('license', 'gates', 'licensed', 'restriction', {
|
|
53
|
+
message: 'A license is required',
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const base = lineDefinition(
|
|
60
|
+
'base',
|
|
61
|
+
'Base premium',
|
|
62
|
+
quantitativeDefinition('base-rate', 'Base rate', [
|
|
63
|
+
factorGroup('amount', 'sum', [staticFactor('minimum', 100)]),
|
|
64
|
+
]),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
const rating = ratingDefinition('standard-rating', 'Standard rating', [base])
|
|
68
|
+
|
|
69
|
+
const definition = programDefinition('standard', 'Standard program', qualification, rating)
|
|
70
|
+
|
|
71
|
+
const program = createProgram(definition)
|
|
72
|
+
|
|
73
|
+
const eligible = program.execute({
|
|
74
|
+
id: 'risk-1',
|
|
75
|
+
licensed: true,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
eligible.eligibility // 'eligible'
|
|
79
|
+
eligible.status // 'eligible'
|
|
80
|
+
eligible.rating?.total // 100
|
|
81
|
+
|
|
82
|
+
const ineligible = program.execute({
|
|
83
|
+
id: 'risk-2',
|
|
84
|
+
licensed: false,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
ineligible.eligibility // 'ineligible'
|
|
88
|
+
ineligible.status // 'ineligible'
|
|
89
|
+
ineligible.rating // undefined — the rater was not called
|
|
90
|
+
|
|
91
|
+
program.emitter.on('execute', (result) => result.success)
|
|
92
|
+
|
|
93
|
+
program.destroy()
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`execute` accepts one subject or a subject array — the array overload performs
|
|
97
|
+
one aggregate-aware batch and returns an `AggregateResult`. Every single-subject
|
|
98
|
+
`execute` call fires through `program.emitter` (`qualify`, `rate`, `determine`,
|
|
99
|
+
`decide`, `execute`).
|
|
100
|
+
|
|
101
|
+
## Guide
|
|
102
|
+
|
|
103
|
+
For the full surface — `Program`, `ProgramManager`, `ProgramResult`,
|
|
104
|
+
`AggregateResult`, validators, factories, errors, and options — see
|
|
105
|
+
[`guides/src/program.md`](guides/src/program.md).
|
|
106
|
+
|
|
107
|
+
## Package
|
|
108
|
+
|
|
109
|
+
Published as a single typed entry point per the `exports` field in
|
|
110
|
+
`package.json`.
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT © [Orkestrel](https://github.com/orkestrel) — see [LICENSE](./LICENSE).
|