@orkestrel/rater
v0.0.16
Published
A typed quantitative rating layer: authored lines are rated against a subject to produce per-line amounts, worksheets, and a derived total. Part of the @orkestrel line.
Maintainers
Readme
@orkestrel/rater
A typed quantitative rating layer over
@orkestrel/reason's shared engine: authored lines, each a plain reasonQuantitativeDefinitionjoined to display metadata, rated against one subject to produce aLineResultper line — anamountand itsWorksheetaudit trail — and oneRatingResultcarrying every line's outcome and a derivedtotal.
Create a rater with the createRater function, hand it the lines a subject is rated
against, and read the LineResult rows and the total it derives. Inject a
@orkestrel/reason ReasonInterface where the
rating shares an engine with the rest of your reasoning, and call destroy() when the
rater's work is done. Environment-agnostic — no I/O, no browser or server assumptions.
Part of the @orkestrel line.
Install
npm install @orkestrel/raterRequirements
- Node.js >= 22.12.0
- ESM (
import) and CommonJS (require) through theexportsfield
Usage
import { buildLineDefinition, createRater } from '@orkestrel/rater'
import {
createFactorGroup,
createQuantitativeDefinition,
createStaticFactor,
} from '@orkestrel/reason'
const rater = createRater()
const base = buildLineDefinition(
'base',
'Base Amount',
createQuantitativeDefinition('base', 'Base', [
createFactorGroup('amount', 'sum', [createStaticFactor('flat', 100)]),
]),
)
const result = rater.rate([base], { id: 'subject-1' })
result.lines[0]?.amount // 100
result.total // 100
rater.emitter.on('rate', (subject, rated) => rated.success)
rater.destroy()rate accepts a plain LineDefinition[] or a full RatingDefinition plus one
subject, and each overload rates that single subject. Every rate call fires once
through rater.emitter (rate).
Guide
For the full surface — Rater, RatingResult, worksheet types, validators,
factories, errors, and options — see
guides/rater.md.
Package
Published as a single typed entry point per the exports field in
package.json.
