@orkestrel/rater 0.0.25 → 0.0.27
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/dist/src/core/index.cjs +346 -206
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +217 -108
- package/dist/src/core/index.d.ts +217 -108
- package/dist/src/core/index.js +343 -205
- package/dist/src/core/index.js.map +1 -1
- package/package.json +17 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["holds","INTRINSICS","isObject","isFunction","literalOf","recordOf","isString","isQuantitativeDefinition","isJSONValue","arrayOf","isContractShape","objectOf","isFieldPath","isComparison","isCheckState","isBoolean","isNumber","isAggregation","isAuditFault","formatField","projectValue","objectShape","stringShape","optionalShape","quantitativeDefinitionShape","jsonShape","arrayShape","shapeShape","fieldPathShape","literalShape","COMPARISONS","CHECK_STATES","booleanShape","nullableShape","numberShape","AGGREGATIONS","auditFaultShape","createContract","createSubjectDoor","Emitter","createReason","createQuantitativeReasoner","isRecord","isFiniteNumber","filterUniqueFaults","describeFaults","filterUniqueFields","arrayOf","scanShape","scanShapeReads","isQuantitativeResult","isString","isArray","isReasonError"],"sources":["../../../src/core/constants.ts","../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/shapers.ts","../../../src/core/contracts.ts","../../../src/core/Rater.ts","../../../src/core/factories.ts"],"sourcesContent":["/** Lists the stages a worksheet derivation step can belong to. */\nexport const WORKSHEET_STAGES = ['factor', 'group', 'total'] as const\n","import type { RaterErrorCode } from './types.js'\nimport { holds, INTRINSICS, isFunction, isObject } from '@orkestrel/contract'\n\n/**\n * Represents a coded programmer error thrown by the rating layer.\n *\n * @remarks\n * `DEFINITION` — the `rate` input failed both the array-of-lines and rating\n * definition validation. `MISMATCH` — a rated subject is not a record.\n * `DESTROYED` — use of a destroyed entity. `context` carries optional\n * structured detail beside the message.\n *\n * @example\n * ```ts\n * import { RaterError } from '@orkestrel/rater'\n *\n * throw new RaterError('MISMATCH', 'Subject must be a record')\n * ```\n */\nexport class RaterError extends Error {\n\treadonly code: RaterErrorCode\n\treadonly context?: Readonly<Record<string, unknown>>\n\n\tconstructor(code: RaterErrorCode, message: string, context?: Readonly<Record<string, unknown>>) {\n\t\tsuper(message)\n\t\tINTRINSICS.define(this, Symbol.for('@orkestrel/rater.RaterError'), { value: this })\n\t\tthis.name = 'RaterError'\n\t\tthis.code = code\n\t\tif (context !== undefined) this.context = context\n\t}\n}\n\n/**\n * Narrows a caught value to a {@link RaterError}.\n *\n * @param value - The caught value to test\n * @returns True if the error carries its own identity brand and declared members; false otherwise\n *\n * @example\n * ```ts\n * import { isRaterError, RaterError } from '@orkestrel/rater'\n *\n * try {\n * \tthrow new RaterError('DESTROYED', 'Rater has been destroyed')\n * } catch (error) {\n * \tif (isRaterError(error)) error.code // 'DESTROYED'\n * }\n * ```\n */\nexport function isRaterError(value: unknown): value is RaterError {\n\treturn holds(() => {\n\t\tif (!(value instanceof Error) || INTRINSICS.prototype(value) === Error.prototype) return false\n\t\tconst brand = INTRINSICS.describe(value, Symbol.for('@orkestrel/rater.RaterError'))\n\t\tif (brand?.value !== value) return false\n\t\tconst code: unknown = INTRINSICS.reflect.read(value, 'code')\n\t\tif (code !== 'DEFINITION' && code !== 'MISMATCH' && code !== 'DESTROYED') return false\n\t\tconst context: unknown = INTRINSICS.reflect.read(value, 'context')\n\t\treturn context === undefined || isObject(context) || isFunction(context)\n\t})\n}\n","import type { Guard } from '@orkestrel/contract'\nimport type {\n\tEvidence,\n\tLineDefinition,\n\tLineResult,\n\tRatingDefinition,\n\tRatingResult,\n\tStep,\n\tWorksheet,\n\tWorksheetFactor,\n\tWorksheetGroup,\n\tWorksheetStage,\n} from './types.js'\nimport {\n\tisAuditFault,\n\tarrayOf,\n\tisBoolean,\n\tisJSONValue,\n\tisNumber,\n\tisString,\n\tliteralOf,\n\tobjectOf,\n\trecordOf,\n} from '@orkestrel/contract'\nimport {\n\tisAggregation,\n\tisCheckState,\n\tisComparison,\n\tisContractShape,\n\tisFieldPath,\n\tisQuantitativeDefinition,\n} from '@orkestrel/reason'\n\n/**\n * Determines whether a value is a {@link WorksheetStage} literal.\n *\n * @remarks\n * A scalar union has no open or exact axis, so this guard accepts one of the\n * `WorksheetStage` literals and leaves nothing unchecked.\n *\n * @param value - The value to test\n * @returns True if `value` is `'factor'`, `'group'`, or `'total'`; false otherwise\n *\n * @example\n * ```ts\n * import { isWorksheetStage } from '@orkestrel/rater'\n *\n * isWorksheetStage('group') // true\n * isWorksheetStage('step') // false\n * ```\n */\nexport const isWorksheetStage: Guard<WorksheetStage> = literalOf('factor', 'group', 'total')\n\n/**\n * Determines whether a value is an exact {@link LineDefinition} record.\n *\n * @remarks\n * Every `LineDefinition` member is checked, including its quantitative\n * definition. Total guard: adversarial input (cycles, hostile prototypes)\n * returns `false`, never throws. The record shape is exact — this package owns\n * the authored input record, so an extra key fails and nothing is left\n * unchecked.\n *\n * @param value - The value to test\n * @returns True if `value` is a `LineDefinition`; false otherwise\n *\n * @example\n * ```ts\n * import { createQuantitativeDefinition } from '@orkestrel/reason'\n * import { isLineDefinition } from '@orkestrel/rater'\n *\n * isLineDefinition({ id: 'base', name: 'Base', rate: createQuantitativeDefinition('base', 'Base', []) }) // true\n * ```\n */\nexport function isLineDefinition(value: unknown): value is LineDefinition {\n\treturn recordOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\trate: isQuantitativeDefinition,\n\t\t\tmetadata: isJSONValue,\n\t\t},\n\t\t['description', 'metadata'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an exact {@link RatingDefinition} record.\n *\n * @remarks\n * Every `RatingDefinition` member is checked, including each nested line\n * definition. Total guard: adversarial input (cycles, hostile prototypes)\n * returns `false`, never throws. The record shape is exact — this package owns\n * the authored input record, so an extra key fails and nothing is left\n * unchecked.\n *\n * @param value - The value to test\n * @returns True if `value` is a `RatingDefinition`; false otherwise\n *\n * @example\n * ```ts\n * import { isRatingDefinition } from '@orkestrel/rater'\n *\n * isRatingDefinition({ id: 'r1', name: 'Rating', lines: [] }) // true\n * ```\n */\nexport function isRatingDefinition(value: unknown): value is RatingDefinition {\n\treturn recordOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\tlines: arrayOf(isLineDefinition),\n\t\t\tmetadata: isJSONValue,\n\t\t\tshape: isContractShape,\n\t\t},\n\t\t['description', 'metadata', 'shape'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open result-side {@link Evidence} object.\n *\n * @remarks\n * Optional `field` is checked as a `FieldPath`, `label` as a string,\n * `comparison` as a `Comparison`, and `state` as a `CheckState`, each when defined.\n * Unknown members, prototypes, and class instances are admitted. Arrays are\n * refused. `expected` and `actual` are `unknown`, so this guard does not read or\n * check them and a borrowed result is never narrowed on them; either member may\n * also be absent because `objectOf` reads declared members rather than\n * requiring or enumerating own keys.\n *\n * @param value - The value to test\n * @returns True if every checked `Evidence` member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isEvidence } from '@orkestrel/rater'\n *\n * isEvidence({ field: 'age', comparison: 'above', expected: 18, actual: 25, state: 'met' }) // true\n * ```\n */\nexport function isEvidence(value: unknown): value is Evidence {\n\treturn objectOf(\n\t\t{\n\t\t\tfield: isFieldPath,\n\t\t\tlabel: isString,\n\t\t\tcomparison: isComparison,\n\t\t\tstate: isCheckState,\n\t\t},\n\t\t['field', 'label', 'comparison', 'state'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link WorksheetFactor} result object.\n *\n * @remarks\n * `id`, the optional authored text, `applied`, an optional plain-number\n * `value`, and each `Evidence` entry are checked. Unknown members, prototypes,\n * and class instances are admitted and left unchecked, because a borrowed\n * result implementation may add them. Arrays are refused. Optional members may\n * be absent or read as `undefined`.\n *\n * @param value - The value to test\n * @returns True if every published worksheet-factor member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isWorksheetFactor } from '@orkestrel/rater'\n *\n * isWorksheetFactor({ id: 'base', applied: true, value: 100, evidence: [] }) // true\n * ```\n */\nexport function isWorksheetFactor(value: unknown): value is WorksheetFactor {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\tapplied: isBoolean,\n\t\t\tvalue: isNumber,\n\t\t\tevidence: arrayOf(isEvidence),\n\t\t},\n\t\t['name', 'description', 'value'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link WorksheetGroup} result object.\n *\n * @remarks\n * `id`, the optional authored text, `applied`, a plain-number `value`, and each\n * `WorksheetFactor` entry are checked. Unknown members, prototypes, and class\n * instances are admitted and left unchecked, because a borrowed result\n * implementation may add them. Arrays are refused. Optional members may be\n * absent or read as `undefined`.\n *\n * @param value - The value to test\n * @returns True if every published worksheet-group member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isWorksheetGroup } from '@orkestrel/rater'\n *\n * isWorksheetGroup({ id: 'charges', applied: true, value: 100, factors: [] }) // true\n * ```\n */\nexport function isWorksheetGroup(value: unknown): value is WorksheetGroup {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\tapplied: isBoolean,\n\t\t\tvalue: isNumber,\n\t\t\tfactors: arrayOf(isWorksheetFactor),\n\t\t},\n\t\t['name', 'description'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link Step} result object.\n *\n * @remarks\n * `stage` is checked through `isWorksheetStage`, `id`, `name`, and `expression` when\n * defined, and `value` as a plain number. Unknown members, prototypes, and\n * class instances are admitted and left unchecked, because a borrowed result\n * implementation may add them. Arrays are refused. Optional members may be\n * absent or read as `undefined`.\n *\n * @param value - The value to test\n * @returns True if every published worksheet-step member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isStep } from '@orkestrel/rater'\n *\n * isStep({ stage: 'total', value: 100 }) // true\n * ```\n */\nexport function isStep(value: unknown): value is Step {\n\treturn objectOf(\n\t\t{\n\t\t\tstage: isWorksheetStage,\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tvalue: isNumber,\n\t\t\texpression: isString,\n\t\t},\n\t\t['id', 'name', 'expression'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link Worksheet} result object.\n *\n * @remarks\n * Identity, `aggregation` through reason's `isAggregation`, an optional\n * plain-number `precision`, a plain-number `value`, the nested groups and steps,\n * `trace`, `errors`, and `success` are checked. Unknown members, prototypes, and\n * class instances are admitted and left unchecked, because a borrowed result\n * implementation may add them. Arrays are refused. Optional members may be\n * absent or read as `undefined`.\n *\n * @param value - The value to test\n * @returns True if every published worksheet member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isWorksheet } from '@orkestrel/rater'\n *\n * isWorksheet({ id: 'quote', name: 'Quote', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], errors: [], success: true, faults: [], repairs: [], defaulted: [] }) // true\n * ```\n */\nexport function isWorksheet(value: unknown): value is Worksheet {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\taggregation: isAggregation,\n\t\t\tprecision: isNumber,\n\t\t\tvalue: isNumber,\n\t\t\tgroups: arrayOf(isWorksheetGroup),\n\t\t\tsteps: arrayOf(isStep),\n\t\t\ttrace: arrayOf(isString),\n\t\t\terrors: arrayOf(isString),\n\t\t\tsuccess: isBoolean,\n\t\t\tfaults: arrayOf(isAuditFault),\n\t\t\trepairs: arrayOf(isAuditFault),\n\t\t\tdefaulted: arrayOf(isFieldPath),\n\t\t},\n\t\t['precision'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link LineResult} object.\n *\n * @remarks\n * Identity, an optional plain-number `amount`, and the nested `Worksheet` that\n * carries the line's outcome are checked. Unknown members, prototypes, and\n * class instances are admitted and left unchecked, because a borrowed result\n * implementation may add them, and so is the relationship between `amount` and\n * `worksheet.success`, which the published interface types independently.\n * Arrays are refused. `amount` may be absent or read as `undefined`; when\n * present it stays a plain JavaScript `number` without a finite or range\n * refinement.\n *\n * @param value - The value to test\n * @returns True if every published line-result member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isLineResult } from '@orkestrel/rater'\n *\n * isLineResult({ id: 'base', name: 'Base', worksheet: { id: 'base', name: 'Base', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], errors: [], success: false } }) // true\n * ```\n */\nexport function isLineResult(value: unknown): value is LineResult {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tamount: isNumber,\n\t\t\tworksheet: isWorksheet,\n\t\t},\n\t\t['amount'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link RatingResult} object.\n *\n * @remarks\n * Use this guard for a result returned by a borrowed `RaterInterface`. Every\n * nested `LineResult`, an optional plain-number `total`, and a boolean `success`\n * are checked. Unknown members, prototypes, and class instances are admitted and\n * left unchecked, and so are the relationships among totals, lines, and success,\n * because the borrowed interface publishes only their member types. Arrays are\n * refused. `total` may be absent or read as `undefined`; when present it stays a\n * plain JavaScript `number` without a finite or range refinement.\n *\n * @param value - The value to test\n * @returns True if every published rating-result member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isRatingResult } from '@orkestrel/rater'\n *\n * isRatingResult({ lines: [], success: true, errors: [], faults: [], repairs: [], defaulted: [] }) // true\n * ```\n */\nexport function isRatingResult(value: unknown): value is RatingResult {\n\treturn objectOf(\n\t\t{\n\t\t\tlines: arrayOf(isLineResult),\n\t\t\ttotal: isNumber,\n\t\t\tsuccess: isBoolean,\n\t\t\terrors: arrayOf(isString),\n\t\t\tfaults: arrayOf(isAuditFault),\n\t\t\trepairs: arrayOf(isAuditFault),\n\t\t\tdefaulted: arrayOf(isFieldPath),\n\t\t},\n\t\t['total'],\n\t)(value)\n}\n","import type { JSONValue } from '@orkestrel/contract'\nimport type {\n\tCheck,\n\tCheckResult,\n\tCheckState,\n\tFactor,\n\tFactorResult,\n\tGroupResult,\n\tQuantitativeDefinition,\n\tQuantitativeResult,\n} from '@orkestrel/reason'\nimport type {\n\tEvidence,\n\tLineDefinition,\n\tLineResult,\n\tRatingDefinition,\n\tRatingResult,\n\tStep,\n\tWorksheet,\n\tWorksheetFactor,\n\tWorksheetGroup,\n\tWorksheetStage,\n} from './types.js'\nimport { formatField, projectValue } from '@orkestrel/reason'\n\n/**\n * Builds a fresh {@link LineDefinition} from a line id, a display name, and the\n * line's quantitative rating definition, with `overrides` merged over those\n * defaults.\n *\n * @param id - The line id\n * @param name - The display name\n * @param rate - The line's quantitative rating definition\n * @param overrides - Optional {@link LineDefinition} fields merged over the defaults\n * @returns A fresh line definition\n *\n * @example\n * ```ts\n * import { createQuantitativeDefinition } from '@orkestrel/reason'\n * import { buildLineDefinition } from '@orkestrel/rater'\n *\n * buildLineDefinition('base', 'Base Amount', createQuantitativeDefinition('base', 'Base', []))\n * ```\n */\nexport function buildLineDefinition(\n\tid: string,\n\tname: string,\n\trate: QuantitativeDefinition,\n\toverrides?: Partial<Omit<LineDefinition, 'id' | 'name' | 'rate'>>,\n): LineDefinition {\n\treturn { id, name, rate, ...overrides }\n}\n\n/**\n * Builds a fresh {@link RatingDefinition} from a rating id, a display name, and\n * the rating's ordered lines, with `overrides` merged over those defaults.\n *\n * @param id - The rating id\n * @param name - The display name\n * @param lines - The rating's ordered lines\n * @param overrides - Optional {@link RatingDefinition} fields merged over the defaults\n * @returns A fresh rating definition\n *\n * @example\n * ```ts\n * import { buildLineDefinition, buildRatingDefinition } from '@orkestrel/rater'\n * import { createQuantitativeDefinition } from '@orkestrel/reason'\n *\n * buildRatingDefinition('r1', 'Rating', [\n * \tbuildLineDefinition('base', 'Base Amount', createQuantitativeDefinition('base', 'Base', [])),\n * ])\n * ```\n */\nexport function buildRatingDefinition(\n\tid: string,\n\tname: string,\n\tlines: readonly LineDefinition[],\n\toverrides?: Partial<Omit<RatingDefinition, 'id' | 'name' | 'lines'>>,\n): RatingDefinition {\n\treturn { id, name, lines, ...overrides }\n}\n\n/**\n * Builds an {@link Evidence} row from an evaluated {@link Check}.\n *\n * @param check - The authored check\n * @param actual - The resolved subject value\n * @param state - The check's state; absent when the check was not evaluated\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh evidence row\n *\n * @example\n * ```ts\n * import { createCheck } from '@orkestrel/reason'\n * import { buildEvidence } from '@orkestrel/rater'\n *\n * const entry = createCheck('age', 'above', 18)\n * buildEvidence(entry, 25, 'met') // { field: 'age', comparison: 'above', expected: 18, actual: 25, state: 'met' }\n * ```\n */\nexport function buildEvidence(\n\tcheck: Check,\n\tactual: unknown,\n\tstate: CheckState | undefined,\n\tlabels?: Readonly<Record<string, string>>,\n): Evidence {\n\tconst field = formatField(check.field)\n\t// Only a label the caller gave, so a field named `constructor` never reads the prototype's.\n\tconst label = labels !== undefined && Object.hasOwn(labels, field) ? labels[field] : undefined\n\treturn {\n\t\tfield: check.field,\n\t\t...(label === undefined ? {} : { label }),\n\t\tcomparison: check.operator,\n\t\texpected: check.value,\n\t\tactual,\n\t\t...(state === undefined ? {} : { state }),\n\t}\n}\n\n/**\n * Builds one evidence row per authored check of a quantitative factor, joined\n * to that check's evaluated result.\n *\n * @param checks - The factor's authored checks\n * @param results - The corresponding {@link CheckResult}s, in the same order\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh list of evidence rows, one per authored check\n *\n * @example\n * ```ts\n * import { createCheck } from '@orkestrel/reason'\n * import { buildEvidenceRows } from '@orkestrel/rater'\n *\n * const checks = [createCheck('age', 'above', 18)]\n * buildEvidenceRows(checks, [{ field: 'age', state: 'met', actual: 25 }])\n * ```\n */\nexport function buildEvidenceRows(\n\tchecks: readonly Check[] | undefined,\n\tresults: readonly CheckResult[] | undefined,\n\tlabels?: Readonly<Record<string, string>>,\n): readonly Evidence[] {\n\treturn (checks ?? []).map((check, index) => {\n\t\tconst result = results?.[index]\n\t\treturn buildEvidence(check, result?.actual, result?.state, labels)\n\t})\n}\n\n/**\n * Joins one authored quantitative factor to its evaluated {@link FactorResult}.\n *\n * @param definition - The authored factor\n * @param results - The group's factor results\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh worksheet factor\n *\n * @example\n * ```ts\n * import { createFieldFactor } from '@orkestrel/reason'\n * import { buildWorksheetFactor } from '@orkestrel/rater'\n *\n * const factor = createFieldFactor('seats', 'seats')\n * buildWorksheetFactor(factor, [{ id: 'seats', applied: true, value: 10 }])\n * ```\n */\nexport function buildWorksheetFactor(\n\tdefinition: Factor,\n\tresults: readonly FactorResult[],\n\tlabels?: Readonly<Record<string, string>>,\n): WorksheetFactor {\n\tconst result = results.find((entry) => entry.id === definition.id)\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name,\n\t\t...(definition.description === undefined ? {} : { description: definition.description }),\n\t\tapplied: result?.applied ?? false,\n\t\t...(result?.value === undefined ? {} : { value: result.value }),\n\t\tevidence: buildEvidenceRows(definition.checks, result?.checks, labels),\n\t}\n}\n\n/**\n * Joins one authored quantitative group to its evaluated {@link GroupResult}.\n *\n * @param definition - The authored group\n * @param results - The definition's group results\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh worksheet group\n *\n * @example\n * ```ts\n * import { createFactorGroup, createStaticFactor } from '@orkestrel/reason'\n * import { buildWorksheetGroup } from '@orkestrel/rater'\n *\n * const group = createFactorGroup('charge', 'sum', [createStaticFactor('base', 100)])\n * buildWorksheetGroup(group, [{ id: 'charge', applied: true, value: 100, factors: [] }])\n * ```\n */\nexport function buildWorksheetGroup(\n\tdefinition: QuantitativeDefinition['groups'][number],\n\tresults: readonly GroupResult[],\n\tlabels?: Readonly<Record<string, string>>,\n): WorksheetGroup {\n\tconst result = results.find((entry) => entry.id === definition.id)\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name,\n\t\t...(definition.description === undefined ? {} : { description: definition.description }),\n\t\tapplied: result?.applied ?? false,\n\t\tvalue: result?.value ?? 0,\n\t\tfactors: definition.factors.map((factor) =>\n\t\t\tbuildWorksheetFactor(factor, result?.factors ?? [], labels),\n\t\t),\n\t}\n}\n\n/**\n * Builds one display-neutral {@link Step} row.\n *\n * @param stage - The step's stage\n * @param id - The stage's authored id, when it has one\n * @param name - The stage's authored name, when it has one\n * @param value - The stage's resolved value\n * @param expression - A display-neutral expression string\n * @returns A fresh step\n *\n * @example\n * ```ts\n * import { buildWorksheetStep } from '@orkestrel/rater'\n *\n * buildWorksheetStep('total', 'quote', 'Quote', 110, 'sum = 110')\n * // { stage: 'total', id: 'quote', name: 'Quote', value: 110, expression: 'sum = 110' }\n * ```\n */\nexport function buildWorksheetStep(\n\tstage: WorksheetStage,\n\tid: string | undefined,\n\tname: string | undefined,\n\tvalue: number,\n\texpression: string,\n): Step {\n\treturn {\n\t\tstage,\n\t\t...(id === undefined ? {} : { id }),\n\t\t...(name === undefined ? {} : { name }),\n\t\tvalue,\n\t\texpression,\n\t}\n}\n\n/**\n * Builds the ordered {@link Step} rows for a resolved {@link Worksheet}.\n *\n * @param definition - The authored quantitative definition\n * @param result - The evaluated quantitative result\n * @param groups - The definition's already-joined worksheet groups\n * @returns A fresh, ordered list of steps: applied factors, then groups, then the total\n *\n * @example\n * ```ts\n * import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'\n * import { buildWorksheetGroup, buildWorksheetSteps } from '@orkestrel/rater'\n *\n * const definition = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])\n * const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)\n * if (result.reasoning === 'quantitative') {\n * \tbuildWorksheetSteps(definition, result, definition.groups.map((group) => buildWorksheetGroup(group, result.groups)))\n * }\n * ```\n */\nexport function buildWorksheetSteps(\n\tdefinition: QuantitativeDefinition,\n\tresult: QuantitativeResult,\n\tgroups: readonly WorksheetGroup[],\n): readonly Step[] {\n\tconst output: Step[] = []\n\tfor (const group of groups) {\n\t\tfor (const factor of group.factors) {\n\t\t\tif (factor.applied && factor.value !== undefined) {\n\t\t\t\toutput.push(\n\t\t\t\t\tbuildWorksheetStep(\n\t\t\t\t\t\t'factor',\n\t\t\t\t\t\tfactor.id,\n\t\t\t\t\t\tfactor.name,\n\t\t\t\t\t\tfactor.value,\n\t\t\t\t\t\t`${factor.id} = ${factor.value}`,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\toutput.push(\n\t\t\tbuildWorksheetStep(\n\t\t\t\t'group',\n\t\t\t\tgroup.id,\n\t\t\t\tgroup.name,\n\t\t\t\tgroup.value,\n\t\t\t\t`${group.id} = ${group.value}`,\n\t\t\t),\n\t\t)\n\t}\n\toutput.push(\n\t\tbuildWorksheetStep(\n\t\t\t'total',\n\t\t\tdefinition.id,\n\t\t\tdefinition.name,\n\t\t\tresult.value,\n\t\t\t`${definition.aggregation} = ${result.value}`,\n\t\t),\n\t)\n\treturn output\n}\n\n/**\n * Joins a {@link QuantitativeDefinition} and its {@link QuantitativeResult} into\n * a {@link Worksheet} — the rating audit trail.\n *\n * @param definition - The authored quantitative definition\n * @param result - The evaluated quantitative result\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh worksheet\n *\n * @example\n * ```ts\n * import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'\n * import { buildWorksheet } from '@orkestrel/rater'\n *\n * const definition = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])\n * const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)\n * if (result.reasoning === 'quantitative') buildWorksheet(definition, result) // the full audit trail\n * ```\n */\nexport function buildWorksheet(\n\tdefinition: QuantitativeDefinition,\n\tresult: QuantitativeResult,\n\tlabels?: Readonly<Record<string, string>>,\n): Worksheet {\n\tconst groups = definition.groups.map((group) => buildWorksheetGroup(group, result.groups, labels))\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name,\n\t\taggregation: definition.aggregation,\n\t\t...(definition.precision === undefined ? {} : { precision: definition.precision }),\n\t\tvalue: result.value,\n\t\tgroups,\n\t\tsteps: buildWorksheetSteps(definition, result, groups),\n\t\ttrace: result.trace,\n\t\terrors: result.errors,\n\t\tsuccess: result.success,\n\t\tfaults: result.faults,\n\t\trepairs: result.repairs,\n\t\tdefaulted: result.defaulted,\n\t}\n}\n\n/**\n * Builds a rated {@link LineResult} from a line's evaluated\n * {@link QuantitativeResult}.\n *\n * @param definition - The authored line definition\n * @param result - The evaluated quantitative result\n * @param labels - Optional field-to-label overrides, keyed by dot-joined field\n * @returns A fresh line result\n *\n * @example\n * ```ts\n * import { createQuantitativeDefinition, createQuantitativeReasoner, createReason } from '@orkestrel/reason'\n * import { buildLineDefinition, buildLineResult } from '@orkestrel/rater'\n *\n * const line = buildLineDefinition('base', 'Base', createQuantitativeDefinition('base', 'Base', []))\n * const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, line.rate)\n * if (result.reasoning === 'quantitative') buildLineResult(line, result) // amount present only on a successful worksheet\n * ```\n */\nexport function buildLineResult(\n\tdefinition: LineDefinition,\n\tresult: QuantitativeResult,\n\tlabels?: Readonly<Record<string, string>>,\n): LineResult {\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name,\n\t\t...(result.success ? { amount: result.value } : {}),\n\t\tworksheet: buildWorksheet(definition.rate, result, labels),\n\t}\n}\n\n/**\n * Sums defined line amounts.\n *\n * @param lines - The rated lines\n * @returns The sum, or `undefined` when no line has an amount or any line refused\n *\n * @example\n * ```ts\n * import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'\n * import { buildLineDefinition, buildLineResult, sumAmounts } from '@orkestrel/rater'\n *\n * const rate = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])\n * const line = buildLineDefinition('base', 'Base', rate)\n * const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, rate)\n * if (result.reasoning === 'quantitative') sumAmounts([buildLineResult(line, result)]) // 100\n * ```\n */\nexport function sumAmounts(lines: readonly LineResult[]): number | undefined {\n\t// A total over a line that refused would read as an answer for the whole subject.\n\tif (!lines.every((rated) => rated.worksheet.success)) return undefined\n\treturn Iterator.from(lines).reduce<number | undefined>(\n\t\t(total, rated) => (rated.amount === undefined ? total : (total ?? 0) + rated.amount),\n\t\tundefined,\n\t)\n}\n\n/**\n * Projects a result to the JSON its contract reads.\n *\n * @remarks\n * An evidence row's `actual` holds whatever the subject held and a worksheet's numbers may be\n * `NaN`, so a result crosses a boundary as this projection, each `actual` on its own budget.\n *\n * @param result - The rating result\n * @returns Its JSON projection, which `ratingResultContract` admits\n *\n * @example\n * ```ts\n * import { createRater, projectRatingResult, ratingResultContract } from '@orkestrel/rater'\n *\n * const rater = createRater()\n * ratingResultContract.is(projectRatingResult(rater.rate([], {}))) // true\n * rater.destroy()\n * ```\n */\nexport function projectRatingResult(result: RatingResult): JSONValue | undefined {\n\tconst lines = result.lines.map((line) => ({\n\t\t...line,\n\t\tworksheet: {\n\t\t\t...line.worksheet,\n\t\t\tgroups: line.worksheet.groups.map((group) => ({\n\t\t\t\t...group,\n\t\t\t\tfactors: group.factors.map((factor) => ({\n\t\t\t\t\t...factor,\n\t\t\t\t\tevidence: factor.evidence.map((row) => ({ ...row, actual: projectValue(row.actual) })),\n\t\t\t\t})),\n\t\t\t})),\n\t\t},\n\t}))\n\treturn projectValue({ ...result, lines }, new Set(), { left: Number.POSITIVE_INFINITY })\n}\n","import type { ContractShape } from '@orkestrel/contract'\nimport {\n\tarrayShape,\n\tauditFaultShape,\n\tbooleanShape,\n\tjsonShape,\n\tliteralShape,\n\tnullableShape,\n\tnumberShape,\n\tobjectShape,\n\toptionalShape,\n\tshapeShape,\n\tstringShape,\n} from '@orkestrel/contract'\nimport {\n\tAGGREGATIONS,\n\tCHECK_STATES,\n\tCOMPARISONS,\n\tfieldPathShape,\n\tquantitativeDefinitionShape,\n} from '@orkestrel/reason'\nimport { WORKSHEET_STAGES } from './constants.js'\n\n// A rating definition and result as shapes, so they reach an LLM, a tool, and MCP as JSON Schema. A\n// result is shaped in its JSON projection, where a non-finite number is `null`.\n\n/** Describes a `LineDefinition`. */\nexport const lineDefinitionShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: stringShape(),\n\tdescription: optionalShape(stringShape()),\n\trate: quantitativeDefinitionShape,\n\tmetadata: optionalShape(jsonShape()),\n})\n\n/**\n * Describes a `RatingDefinition`.\n */\nexport const ratingDefinitionShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: stringShape(),\n\tdescription: optionalShape(stringShape()),\n\tlines: arrayShape(lineDefinitionShape),\n\tmetadata: optionalShape(jsonShape()),\n\tshape: optionalShape(shapeShape()),\n})\n\n/** Describes an `Evidence` row in its JSON projection. */\nexport const evidenceShape: ContractShape = objectShape({\n\tfield: optionalShape(fieldPathShape),\n\tlabel: optionalShape(stringShape()),\n\tcomparison: optionalShape(literalShape(COMPARISONS)),\n\texpected: optionalShape(jsonShape()),\n\tactual: optionalShape(jsonShape()),\n\tstate: optionalShape(literalShape(CHECK_STATES)),\n})\n\n/** Describes a `WorksheetFactor` in its JSON projection. */\nexport const worksheetFactorShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: optionalShape(stringShape()),\n\tdescription: optionalShape(stringShape()),\n\tapplied: booleanShape(),\n\tvalue: optionalShape(nullableShape(numberShape())),\n\tevidence: arrayShape(evidenceShape),\n})\n\n/** Describes a `WorksheetGroup` in its JSON projection. */\nexport const worksheetGroupShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: optionalShape(stringShape()),\n\tdescription: optionalShape(stringShape()),\n\tapplied: booleanShape(),\n\tvalue: nullableShape(numberShape()),\n\tfactors: arrayShape(worksheetFactorShape),\n})\n\n/** Describes a `Step` in its JSON projection. */\nexport const worksheetStepShape: ContractShape = objectShape({\n\tstage: literalShape(WORKSHEET_STAGES),\n\tid: optionalShape(stringShape()),\n\tname: optionalShape(stringShape()),\n\tvalue: nullableShape(numberShape()),\n\texpression: optionalShape(stringShape()),\n})\n\n/** Describes a `Worksheet` in its JSON projection. */\nexport const worksheetShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: stringShape(),\n\taggregation: literalShape(AGGREGATIONS),\n\tprecision: optionalShape(numberShape()),\n\tvalue: nullableShape(numberShape()),\n\tgroups: arrayShape(worksheetGroupShape),\n\tsteps: arrayShape(worksheetStepShape),\n\ttrace: arrayShape(stringShape()),\n\terrors: arrayShape(stringShape()),\n\tsuccess: booleanShape(),\n\tfaults: arrayShape(auditFaultShape()),\n\trepairs: arrayShape(auditFaultShape()),\n\tdefaulted: arrayShape(fieldPathShape),\n})\n\n/** Describes a `LineResult` in its JSON projection. */\nexport const lineResultShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: stringShape(),\n\tamount: optionalShape(nullableShape(numberShape())),\n\tworksheet: worksheetShape,\n})\n\n/** Describes a `RatingResult` in its JSON projection. */\nexport const ratingResultShape: ContractShape = objectShape({\n\tlines: arrayShape(lineResultShape),\n\ttotal: optionalShape(nullableShape(numberShape())),\n\tsuccess: booleanShape(),\n\terrors: arrayShape(stringShape()),\n\tfaults: arrayShape(auditFaultShape()),\n\trepairs: arrayShape(auditFaultShape()),\n\tdefaulted: arrayShape(fieldPathShape),\n})\n","import type { ContractInterface } from '@orkestrel/contract'\nimport { createContract } from '@orkestrel/contract'\nimport { ratingDefinitionShape, ratingResultShape } from './shapers.js'\n\n/**\n * Publishes a `RatingDefinition` as a contract. Cross it on `is`, never `parse`.\n */\nexport const ratingDefinitionContract: ContractInterface<unknown> =\n\tcreateContract(ratingDefinitionShape)\n\n/** Publishes a `RatingResult`'s JSON projection as a contract, read through `projectRatingResult`. */\nexport const ratingResultContract: ContractInterface<unknown> = createContract(ratingResultShape)\n","import type { ContractShape } from '@orkestrel/contract'\nimport type { EmitterInterface } from '@orkestrel/emitter'\nimport type {\n\tQuantitativeDefinition,\n\tQuantitativeResult,\n\tReasonInterface,\n\tReasonResult,\n\tSubject,\n} from '@orkestrel/reason'\nimport type {\n\tLineDefinition,\n\tLineResult,\n\tRaterEventMap,\n\tRaterInterface,\n\tRaterOptions,\n\tRatingDefinition,\n\tRatingResult,\n\tTotalHandler,\n} from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport {\n\tarrayOf,\n\tdescribeFaults,\n\tisArray,\n\tisFiniteNumber,\n\tisRecord,\n\tisString,\n} from '@orkestrel/contract'\nimport {\n\tcreateQuantitativeReasoner,\n\tcreateReason,\n\tcreateSubjectDoor,\n\tfilterUniqueFaults,\n\tfilterUniqueFields,\n\tisQuantitativeResult,\n\tisReasonError,\n\tscanShape,\n\tscanShapeReads,\n} from '@orkestrel/reason'\nimport { RaterError } from './errors.js'\nimport { buildLineResult, sumAmounts } from './helpers.js'\nimport { isLineDefinition, isRatingDefinition } from './validators.js'\n\n/**\n * Orchestrates rating — owns (or receives) the shared quantitative\n * reasoning engine and projects results into the rating domain vocabulary.\n *\n * @remarks\n * When no `engine` is injected, `Rater` builds and owns its own\n * quantitative-only engine (`bail: false`) — Rater performs no evaluation\n * arithmetic of its own; it only orchestrates and projects. The\n * array-of-lines `rate` overload is declared first so a plain line list\n * resolves to that form. `destroy()` destroys an owned engine, then the\n * emitter last; an injected engine is never destroyed. Afterwards every\n * other method throws {@link RaterError} `'DESTROYED'`.\n *\n * @example\n * ```ts\n * import { Rater } from '@orkestrel/rater'\n *\n * const rater = new Rater()\n * rater.rate([], { id: 'subject-1' }).success // true\n * rater.destroy()\n * ```\n */\nexport class Rater implements RaterInterface {\n\treadonly #emitter: Emitter<RaterEventMap>\n\treadonly #engine: ReasonInterface\n\treadonly #owned: boolean\n\treadonly #total: TotalHandler | undefined\n\treadonly #labels: Readonly<Record<string, string>> | undefined\n\treadonly #door = createSubjectDoor()\n\treadonly #valid = new WeakSet<RatingDefinition>()\n\t#destroyed = false\n\n\tconstructor(options?: RaterOptions) {\n\t\tthis.#emitter = new Emitter<RaterEventMap>({\n\t\t\t...(options?.on === undefined ? {} : { on: options.on }),\n\t\t\t...(options?.error === undefined ? {} : { error: options.error }),\n\t\t})\n\t\tif (options?.engine === undefined) {\n\t\t\tthis.#engine = createReason({ reasoners: [createQuantitativeReasoner()], bail: false })\n\t\t\tthis.#owned = true\n\t\t} else {\n\t\t\tthis.#engine = options.engine\n\t\t\tthis.#owned = false\n\t\t}\n\t\tthis.#total = options?.total\n\t\tthis.#labels = options?.labels\n\t}\n\n\tget emitter(): EmitterInterface<RaterEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t// Array overload first so a plain line list resolves to that form.\n\trate(lines: readonly LineDefinition[], subject: Subject): RatingResult\n\trate(definition: RatingDefinition, subject: Subject): RatingResult\n\trate(input: readonly LineDefinition[] | RatingDefinition, subject: Subject): RatingResult {\n\t\tthis.#ensureAlive()\n\t\tconst lines = this.#normalize(input)\n\t\tif (!isRecord(subject)) throw new RaterError('MISMATCH', 'Subject must be a record')\n\t\tconst admission = this.#door.admit(subject, this.#readShape(input))\n\t\tconst admitted = admission.subject\n\t\tif (admitted === undefined) {\n\t\t\tconst refused: RatingResult = {\n\t\t\t\tlines: [],\n\t\t\t\tsuccess: false,\n\t\t\t\terrors: admission.errors,\n\t\t\t\tfaults: admission.faults,\n\t\t\t\trepairs: [],\n\t\t\t\tdefaulted: [],\n\t\t\t}\n\t\t\tthis.#emitter.emit('rate', subject, refused)\n\t\t\treturn refused\n\t\t}\n\t\tconst results = lines.map((line) => this.#rateLine(line, admitted))\n\t\tconst rated = results.every((entry) => entry.worksheet.success)\n\t\t// No handler totals a line that refused, because the total would read as an answer.\n\t\tconst summed = rated ? (this.#total ?? sumAmounts)(results) : undefined\n\t\t// A total past what a number holds is no answer either, and the sum alone can overflow.\n\t\tconst overflowed = summed !== undefined && !isFiniteNumber(summed)\n\t\tconst total = overflowed ? undefined : summed\n\t\tconst success = rated && !overflowed\n\t\tconst faults = filterUniqueFaults(results.flatMap((entry) => entry.worksheet.faults))\n\t\tconst said = new Set(faults.map((fault) => describeFaults([fault])))\n\t\t// `success` is the verdict, so a line that failed and said nothing still has to say so.\n\t\tconst other = results.flatMap((entry) => {\n\t\t\tconst { errors, success: settled } = entry.worksheet\n\t\t\tif (!settled && errors.length === 0) return [`${entry.id}: The line failed and said nothing`]\n\t\t\treturn errors.filter((error) => !said.has(error)).map((error) => `${entry.id}: ${error}`)\n\t\t})\n\t\tconst repairs = filterUniqueFaults([\n\t\t\t...admission.repairs,\n\t\t\t...results.flatMap((entry) => entry.worksheet.repairs),\n\t\t])\n\t\tconst defaulted = filterUniqueFields([\n\t\t\t...admission.defaulted,\n\t\t\t...results.flatMap((entry) => entry.worksheet.defaulted),\n\t\t])\n\t\tconst result: RatingResult = {\n\t\t\tlines: results,\n\t\t\t...(total === undefined ? {} : { total }),\n\t\t\tsuccess,\n\t\t\terrors: [...other, ...said, ...(overflowed ? ['The total is not a finite number'] : [])],\n\t\t\tfaults,\n\t\t\trepairs,\n\t\t\tdefaulted,\n\t\t}\n\t\tthis.#emitter.emit('rate', admitted, result)\n\t\treturn result\n\t}\n\n\tdestroy(): void {\n\t\tif (this.#destroyed) return\n\t\tthis.#destroyed = true\n\t\tif (this.#owned) this.#engine.destroy()\n\t\tthis.#emitter.destroy()\n\t}\n\n\t#normalize(input: readonly LineDefinition[] | RatingDefinition): readonly LineDefinition[] {\n\t\tif (arrayOf(isLineDefinition)(input)) return input\n\t\tif (isRatingDefinition(input)) return input.lines\n\t\tthrow new RaterError(\n\t\t\t'DEFINITION',\n\t\t\t'Rating input must be an array of line definitions or a rating definition',\n\t\t)\n\t}\n\n\t// A rating's shape is checked against what its lines read once per definition, by identity.\n\t#readShape(input: readonly LineDefinition[] | RatingDefinition): ContractShape | undefined {\n\t\tif (arrayOf(isLineDefinition)(input)) return undefined\n\t\tconst { shape, lines } = input\n\t\tif (shape === undefined || this.#valid.has(input)) return shape\n\t\tconst checks = lines.flatMap((line) =>\n\t\t\tline.rate.groups.flatMap((group) => group.factors.flatMap((factor) => factor.checks ?? [])),\n\t\t)\n\t\tconst fields = lines.flatMap((line) =>\n\t\t\tline.rate.groups.flatMap((group) =>\n\t\t\t\tgroup.factors.flatMap((factor) =>\n\t\t\t\t\tfactor.source.origin === 'static' ? [] : [factor.source.field],\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\t\tconst errors = [...scanShape(shape), ...scanShapeReads(shape, checks, fields, new Set()).errors]\n\t\tif (errors.length > 0) {\n\t\t\tthrow new RaterError('DEFINITION', `Rating shape is invalid: ${errors.join(', ')}`)\n\t\t}\n\t\tthis.#valid.add(input)\n\t\treturn shape\n\t}\n\n\t#rateLine(line: LineDefinition, subject: Subject): LineResult {\n\t\tconst result = this.#reasonQuantitative(subject, line.rate)\n\t\treturn buildLineResult(line, result, this.#labels)\n\t}\n\n\t// Narrows the engine's answer to a QuantitativeResult, and reads nothing it has not checked:\n\t// an injected engine can answer anything, null included, so this is total. An engine that\n\t// contradicts itself refuses, because `success` is the verdict and it has to be earned.\n\t#reasonQuantitative(subject: Subject, definition: QuantitativeDefinition): QuantitativeResult {\n\t\tconst result: unknown = this.#reason(subject, definition)\n\t\tif (isQuantitativeResult(result)) return this.#settle(result)\n\t\tconst answer = isRecord(result) ? result : {}\n\t\tconst named = isString(answer.reasoning) ? answer.reasoning : 'something else'\n\t\tconst said = isArray<unknown>(answer.errors) ? answer.errors.filter(isString) : []\n\t\treturn {\n\t\t\treasoning: 'quantitative',\n\t\t\tvalue: 0,\n\t\t\tgroups: [],\n\t\t\tcount: 0,\n\t\t\tsuccess: false,\n\t\t\ttrace: [],\n\t\t\terrors: [...said, `Expected quantitative result, got ${named}`],\n\t\t\tfaults: [],\n\t\t\trepairs: [],\n\t\t\tdefaulted: [],\n\t\t}\n\t}\n\n\t#settle(result: QuantitativeResult): QuantitativeResult {\n\t\tif (!result.success) return result\n\t\tconst clean = result.errors.length === 0 && result.faults.length === 0\n\t\tif (clean && isFiniteNumber(result.value)) return result\n\t\tconst said = result.errors.length > 0 ? [] : ['The line succeeded beside a fault or no value']\n\t\treturn { ...result, success: false, errors: [...result.errors, ...said] }\n\t}\n\n\t// An invalid line definition is an authoring error, so it reaches the caller as one.\n\t#reason(subject: Subject, definition: QuantitativeDefinition): ReasonResult {\n\t\ttry {\n\t\t\treturn this.#engine.reason(subject, definition)\n\t\t} catch (error) {\n\t\t\tif (isReasonError(error) && error.code === 'INVALID') {\n\t\t\t\tthrow new RaterError('DEFINITION', error.message)\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n\n\t#ensureAlive(): void {\n\t\tif (this.#destroyed) throw new RaterError('DESTROYED', 'Rater has been destroyed')\n\t}\n}\n","import type { RaterInterface, RaterOptions } from './types.js'\nimport { Rater } from './Rater.js'\n\n/**\n * Creates a rating orchestrator over the shared quantitative engine, seeded\n * from {@link RaterOptions} and returning a {@link RaterInterface}.\n *\n * @param options - Optional total handler, labels, injected engine, and emitter hooks\n * @returns A {@link RaterInterface}\n *\n * @example Create a rater\n * ```ts\n * import { createRater } from '@orkestrel/rater'\n *\n * const rater = createRater()\n * rater.destroy()\n * ```\n */\nexport function createRater(options?: RaterOptions): RaterInterface {\n\treturn new Rater(options)\n}\n"],"mappings":";;;;;;AACA,IAAa,mBAAmB;CAAC;CAAU;CAAS;AAAO;;;;;;;;;;;;;;;;;;ACkB3D,IAAa,aAAb,cAAgC,MAAM;CACrC;CACA;CAEA,YAAY,MAAsB,SAAiB,SAA6C;EAC/F,MAAM,OAAO;EACb,oBAAA,WAAW,OAAO,MAAM,OAAO,IAAI,6BAA6B,GAAG,EAAE,OAAO,KAAK,CAAC;EAClF,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,IAAI,YAAY,KAAA,GAAW,KAAK,UAAU;CAC3C;AACD;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aAAa,OAAqC;CACjE,QAAA,GAA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C,oBAAAA,QAAAA,CAAiB,OAAO,MAAM,IAAI,OAAO,OAAO,OAAOD,oBAAAA,QAAQ,IAAI,CAAC,GAQ9D,qCAAqC,OAAO;GAC9D,QAAQ,CAAC;GACT,SAAS,CAAC;GACV,WAAW,CAAC;EACb;CACD;CAEA,QAAQ,QAAgD;EACvD,IAAI,CAAC,OAAO,SAAS,OAAO;EAE5B,IADc,OAAO,OAAO,WAAW,KAAK,OAAO,OAAO,WAAW,MAAA,GACxDR,oBAAAA,eAAAA,CAAe,OAAO,KAAK,GAAG,OAAO;EAClD,MAAM,OAAO,OAAO,OAAO,SAAS,IAAI,CAAC,IAAI,CAAC,+CAA+C;EAC7F,OAAO;GAAE,GAAG;GAAQ,SAAS;GAAO,QAAQ,CAAC,GAAG,OAAO,QAAQ,GAAG,IAAI;EAAE;CACzE;CAGA,QAAQ,SAAkB,YAAkD;EAC3E,IAAI;GACH,OAAO,KAAK,QAAQ,OAAO,SAAS,UAAU;EAC/C,SAAS,OAAO;GACf,KAAA,GAAIU,kBAAAA,cAAAA,CAAc,KAAK,KAAK,MAAM,SAAS,WAC1C,MAAM,IAAI,WAAW,cAAc,MAAM,OAAO;GAEjD,MAAM;EACP;CACD;CAEA,eAAqB;EACpB,IAAI,KAAK,YAAY,MAAM,IAAI,WAAW,aAAa,0BAA0B;CAClF;AACD;;;;;;;;;;;;;;;;;ACjOA,SAAgB,YAAY,SAAwC;CACnE,OAAO,IAAI,MAAM,OAAO;AACzB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["INTRINSICS","holds","isObject","isFunction","literalOf","recordOf","isString","isQuantitativeDefinition","isJSONValue","arrayOf","isContractShape","objectOf","isBoolean","isNumber","isCheckResult","isAggregation","isReasonRefusal","isAuditFault","isFieldPath","findDuplicates","isQuantitativeResult","attempt","isSuccess","isFiniteNumber","projectRefusal","projectValue","projectCheck","objectShape","stringShape","optionalShape","quantitativeDefinitionShape","jsonShape","arrayShape","shapeShape","booleanShape","nullableShape","numberShape","checkResultShape","literalShape","AGGREGATIONS","reasonRefusalShape","auditFaultShape","fieldPathShape","createContract","createSubjectDoor","Emitter","createReason","createQuantitativeReasoner","isRecord","isFiniteNumber","filterUniqueFaults","nestRefusals","filterUniqueFields","arrayOf","scanShape","scanShapeReads","isReasonError"],"sources":["../../../src/core/constants.ts","../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/shapers.ts","../../../src/core/contracts.ts","../../../src/core/Rater.ts","../../../src/core/factories.ts"],"sourcesContent":["/** Lists the stages a worksheet derivation step can belong to. */\nexport const WORKSHEET_STAGES = ['factor', 'group', 'total'] as const\n","import type { RaterErrorCode } from './types.js'\nimport { holds, INTRINSICS, isFunction, isObject } from '@orkestrel/contract'\n\n/**\n * Represents a coded programmer error thrown by the rating layer.\n *\n * @remarks\n * `DEFINITION` — the `rate` input failed both the array-of-lines and rating\n * definition validation. `MISMATCH` — a rated subject is not a record.\n * `DESTROYED` — use of a destroyed entity. `context` carries optional\n * structured detail beside the message.\n *\n * @example\n * ```ts\n * import { RaterError } from '@orkestrel/rater'\n *\n * throw new RaterError('MISMATCH', 'Subject must be a record')\n * ```\n */\nexport class RaterError extends Error {\n\treadonly code: RaterErrorCode\n\treadonly context?: Readonly<Record<string, unknown>>\n\n\tconstructor(code: RaterErrorCode, message: string, context?: Readonly<Record<string, unknown>>) {\n\t\tsuper(message)\n\t\tINTRINSICS.define(this, Symbol.for('@orkestrel/rater.RaterError'), { value: this })\n\t\tthis.name = 'RaterError'\n\t\tthis.code = code\n\t\tif (context !== undefined) this.context = context\n\t}\n}\n\n/**\n * Narrows a caught value to a {@link RaterError}.\n *\n * @param value - The caught value to test\n * @returns True if the error carries its own identity brand and declared members; false otherwise\n *\n * @example\n * ```ts\n * import { isRaterError, RaterError } from '@orkestrel/rater'\n *\n * try {\n * \tthrow new RaterError('DESTROYED', 'Rater has been destroyed')\n * } catch (error) {\n * \tif (isRaterError(error)) error.code // 'DESTROYED'\n * }\n * ```\n */\nexport function isRaterError(value: unknown): value is RaterError {\n\treturn holds(() => {\n\t\tif (!(value instanceof Error) || INTRINSICS.prototype(value) === Error.prototype) return false\n\t\tconst brand = INTRINSICS.describe(value, Symbol.for('@orkestrel/rater.RaterError'))\n\t\tif (brand?.value !== value) return false\n\t\tconst code: unknown = INTRINSICS.reflect.read(value, 'code')\n\t\tif (code !== 'DEFINITION' && code !== 'MISMATCH' && code !== 'DESTROYED') return false\n\t\tconst context: unknown = INTRINSICS.reflect.read(value, 'context')\n\t\treturn context === undefined || isObject(context) || isFunction(context)\n\t})\n}\n","import type { Guard } from '@orkestrel/contract'\nimport type {\n\tLineDefinition,\n\tLineResult,\n\tRatingDefinition,\n\tRatingResult,\n\tStep,\n\tWorksheet,\n\tWorksheetFactor,\n\tWorksheetGroup,\n\tWorksheetStage,\n} from './types.js'\nimport {\n\tisAuditFault,\n\tarrayOf,\n\tisBoolean,\n\tisJSONValue,\n\tisNumber,\n\tisString,\n\tliteralOf,\n\tobjectOf,\n\trecordOf,\n} from '@orkestrel/contract'\nimport {\n\tisAggregation,\n\tisCheckResult,\n\tisContractShape,\n\tisFieldPath,\n\tisQuantitativeDefinition,\n\tisReasonRefusal,\n} from '@orkestrel/reason'\n\n/**\n * Determines whether a value is a {@link WorksheetStage} literal.\n *\n * @remarks\n * A scalar union has no open or exact axis, so this guard accepts one of the\n * `WorksheetStage` literals and leaves nothing unchecked.\n *\n * @param value - The value to test\n * @returns True if `value` is `'factor'`, `'group'`, or `'total'`; false otherwise\n *\n * @example\n * ```ts\n * import { isWorksheetStage } from '@orkestrel/rater'\n *\n * isWorksheetStage('group') // true\n * isWorksheetStage('step') // false\n * ```\n */\nexport const isWorksheetStage: Guard<WorksheetStage> = literalOf('factor', 'group', 'total')\n\n/**\n * Determines whether a value is an exact {@link LineDefinition} record.\n *\n * @remarks\n * Every `LineDefinition` member is checked, including its quantitative\n * definition. Total guard: adversarial input (cycles, hostile prototypes)\n * returns `false`, never throws. The record shape is exact — this package owns\n * the authored input record, so an extra key fails and nothing is left\n * unchecked.\n *\n * @param value - The value to test\n * @returns True if `value` is a `LineDefinition`; false otherwise\n *\n * @example\n * ```ts\n * import { createQuantitativeDefinition } from '@orkestrel/reason'\n * import { isLineDefinition } from '@orkestrel/rater'\n *\n * isLineDefinition({ id: 'base', name: 'Base', rate: createQuantitativeDefinition('base', 'Base', []) }) // true\n * ```\n */\nexport function isLineDefinition(value: unknown): value is LineDefinition {\n\treturn recordOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\trate: isQuantitativeDefinition,\n\t\t\tmetadata: isJSONValue,\n\t\t},\n\t\t['description', 'metadata'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an exact {@link RatingDefinition} record.\n *\n * @remarks\n * Every `RatingDefinition` member is checked, including each nested line\n * definition. Total guard: adversarial input (cycles, hostile prototypes)\n * returns `false`, never throws. The record shape is exact — this package owns\n * the authored input record, so an extra key fails and nothing is left\n * unchecked.\n *\n * @param value - The value to test\n * @returns True if `value` is a `RatingDefinition`; false otherwise\n *\n * @example\n * ```ts\n * import { isRatingDefinition } from '@orkestrel/rater'\n *\n * isRatingDefinition({ id: 'r1', name: 'Rating', lines: [] }) // true\n * ```\n */\nexport function isRatingDefinition(value: unknown): value is RatingDefinition {\n\treturn recordOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\tlines: arrayOf(isLineDefinition),\n\t\t\tmetadata: isJSONValue,\n\t\t\tshape: isContractShape,\n\t\t},\n\t\t['description', 'metadata', 'shape'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link WorksheetFactor} result object.\n *\n * @remarks\n * `id`, the optional authored text, `applied`, `fallback`, the optional plain-number\n * `value` and `raw`, and each `CheckResult` entry are checked. `actual` is `unknown`, so\n * this guard does not read it. Unknown members, prototypes, and class instances are\n * admitted and left unchecked, because a borrowed result implementation may add them. Arrays\n * are refused. Optional members may be absent or read as `undefined`.\n *\n * @param value - The value to test\n * @returns True if every published worksheet-factor member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isWorksheetFactor } from '@orkestrel/rater'\n *\n * isWorksheetFactor({ id: 'base', applied: true, value: 100, fallback: false, checks: [] }) // true\n * ```\n */\nexport function isWorksheetFactor(value: unknown): value is WorksheetFactor {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\tapplied: isBoolean,\n\t\t\tvalue: isNumber,\n\t\t\traw: isNumber,\n\t\t\tfallback: isBoolean,\n\t\t\tchecks: arrayOf(isCheckResult),\n\t\t},\n\t\t['name', 'description', 'value', 'raw'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link WorksheetGroup} result object.\n *\n * @remarks\n * `id`, the optional authored text, `applied`, an optional plain-number `value`, and each\n * `WorksheetFactor` entry are checked. Unknown members, prototypes, and class\n * instances are admitted and left unchecked, because a borrowed result\n * implementation may add them. Arrays are refused. Optional members may be\n * absent or read as `undefined`.\n *\n * @param value - The value to test\n * @returns True if every published worksheet-group member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isWorksheetGroup } from '@orkestrel/rater'\n *\n * isWorksheetGroup({ id: 'charges', applied: true, value: 100, factors: [] }) // true\n * ```\n */\nexport function isWorksheetGroup(value: unknown): value is WorksheetGroup {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tdescription: isString,\n\t\t\tapplied: isBoolean,\n\t\t\tvalue: isNumber,\n\t\t\tfactors: arrayOf(isWorksheetFactor),\n\t\t},\n\t\t['name', 'description', 'value'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link Step} result object.\n *\n * @remarks\n * `stage` is checked through `isWorksheetStage`, `id` and `name` when\n * defined, and `value` as a plain number. Unknown members, prototypes, and\n * class instances are admitted and left unchecked, because a borrowed result\n * implementation may add them. Arrays are refused. Optional members may be\n * absent or read as `undefined`.\n *\n * @param value - The value to test\n * @returns True if every published worksheet-step member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isStep } from '@orkestrel/rater'\n *\n * isStep({ stage: 'total', value: 100 }) // true\n * ```\n */\nexport function isStep(value: unknown): value is Step {\n\treturn objectOf(\n\t\t{\n\t\t\tstage: isWorksheetStage,\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tvalue: isNumber,\n\t\t},\n\t\t['id', 'name'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link Worksheet} result object.\n *\n * @remarks\n * Identity, `aggregation` through reason's `isAggregation`, an optional\n * plain-number `precision`, a plain-number `value`, the nested groups and steps,\n * `trace`, `refusals` through reason's `isReasonRefusal`, and `success` are checked. Unknown members, prototypes, and\n * class instances are admitted and left unchecked, because a borrowed result\n * implementation may add them. Arrays are refused. Optional members may be\n * absent or read as `undefined`.\n *\n * @param value - The value to test\n * @returns True if every published worksheet member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isWorksheet } from '@orkestrel/rater'\n *\n * isWorksheet({ id: 'quote', name: 'Quote', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], refusals: [], success: true, faults: [], repairs: [], defaulted: [] }) // true\n * ```\n */\nexport function isWorksheet(value: unknown): value is Worksheet {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\taggregation: isAggregation,\n\t\t\tprecision: isNumber,\n\t\t\tvalue: isNumber,\n\t\t\tgroups: arrayOf(isWorksheetGroup),\n\t\t\tsteps: arrayOf(isStep),\n\t\t\ttrace: arrayOf(isString),\n\t\t\trefusals: arrayOf(isReasonRefusal),\n\t\t\tsuccess: isBoolean,\n\t\t\tfaults: arrayOf(isAuditFault),\n\t\t\trepairs: arrayOf(isAuditFault),\n\t\t\tdefaulted: arrayOf(isFieldPath),\n\t\t},\n\t\t['precision'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link LineResult} object.\n *\n * @remarks\n * Identity, an optional plain-number `amount`, and the nested `Worksheet` that\n * carries the line's outcome are checked. Unknown members, prototypes, and\n * class instances are admitted and left unchecked, because a borrowed result\n * implementation may add them, and so is the relationship between `amount` and\n * `worksheet.success`, which the published interface types independently.\n * Arrays are refused. `amount` may be absent or read as `undefined`; when\n * present it stays a plain JavaScript `number` without a finite or range\n * refinement.\n *\n * @param value - The value to test\n * @returns True if every published line-result member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isLineResult } from '@orkestrel/rater'\n *\n * isLineResult({ id: 'base', name: 'Base', worksheet: { id: 'base', name: 'Base', aggregation: 'sum', value: 0, groups: [], steps: [], trace: [], refusals: [], success: false } }) // true\n * ```\n */\nexport function isLineResult(value: unknown): value is LineResult {\n\treturn objectOf(\n\t\t{\n\t\t\tid: isString,\n\t\t\tname: isString,\n\t\t\tamount: isNumber,\n\t\t\tworksheet: isWorksheet,\n\t\t},\n\t\t['amount'],\n\t)(value)\n}\n\n/**\n * Determines whether a value is an open {@link RatingResult} object.\n *\n * @remarks\n * Use this guard for a result returned by a borrowed `RaterInterface`. Every\n * nested `LineResult`, an optional plain-number `total`, and a boolean `success`\n * are checked. Unknown members, prototypes, and class instances are admitted and\n * left unchecked, and so are the relationships among totals, lines, and success,\n * because the borrowed interface publishes only their member types. Arrays are\n * refused. `total` may be absent or read as `undefined`; when present it stays a\n * plain JavaScript `number` without a finite or range refinement.\n *\n * @param value - The value to test\n * @returns True if every published rating-result member conforms; false otherwise\n *\n * @example\n * ```ts\n * import { isRatingResult } from '@orkestrel/rater'\n *\n * isRatingResult({ lines: [], success: true, refusals: [], faults: [], repairs: [], defaulted: [] }) // true\n * ```\n */\nexport function isRatingResult(value: unknown): value is RatingResult {\n\treturn objectOf(\n\t\t{\n\t\t\tlines: arrayOf(isLineResult),\n\t\t\ttotal: isNumber,\n\t\t\tsuccess: isBoolean,\n\t\t\trefusals: arrayOf(isReasonRefusal),\n\t\t\tfaults: arrayOf(isAuditFault),\n\t\t\trepairs: arrayOf(isAuditFault),\n\t\t\tdefaulted: arrayOf(isFieldPath),\n\t\t},\n\t\t['total'],\n\t)(value)\n}\n","import type { JSONValue } from '@orkestrel/contract'\nimport type {\n\tFactor,\n\tFactorResult,\n\tGroupResult,\n\tQuantitativeDefinition,\n\tQuantitativeResult,\n\tReasonRefusal,\n} from '@orkestrel/reason'\nimport type {\n\tLineDefinition,\n\tLineResult,\n\tRatingDefinition,\n\tRatingResult,\n\tStep,\n\tWorksheet,\n\tWorksheetFactor,\n\tWorksheetGroup,\n\tWorksheetStage,\n} from './types.js'\nimport { attempt, isFiniteNumber, isSuccess } from '@orkestrel/contract'\nimport {\n\tfindDuplicates,\n\tisQuantitativeResult,\n\tprojectCheck,\n\tprojectRefusal,\n\tprojectValue,\n} from '@orkestrel/reason'\n\n/**\n * Builds a fresh {@link LineDefinition} from a line id, a display name, and the\n * line's quantitative rating definition, with `overrides` merged over those\n * defaults.\n *\n * @param id - The line id\n * @param name - The display name\n * @param rate - The line's quantitative rating definition\n * @param overrides - Optional {@link LineDefinition} fields merged over the defaults\n * @returns A fresh line definition\n *\n * @example\n * ```ts\n * import { createQuantitativeDefinition } from '@orkestrel/reason'\n * import { buildLineDefinition } from '@orkestrel/rater'\n *\n * buildLineDefinition('base', 'Base Amount', createQuantitativeDefinition('base', 'Base', []))\n * ```\n */\nexport function buildLineDefinition(\n\tid: string,\n\tname: string,\n\trate: QuantitativeDefinition,\n\toverrides?: Partial<Omit<LineDefinition, 'id' | 'name' | 'rate'>>,\n): LineDefinition {\n\treturn { id, name, rate, ...overrides }\n}\n\n/**\n * Builds a fresh {@link RatingDefinition} from a rating id, a display name, and\n * the rating's ordered lines, with `overrides` merged over those defaults.\n *\n * @param id - The rating id\n * @param name - The display name\n * @param lines - The rating's ordered lines\n * @param overrides - Optional {@link RatingDefinition} fields merged over the defaults\n * @returns A fresh rating definition\n *\n * @example\n * ```ts\n * import { buildLineDefinition, buildRatingDefinition } from '@orkestrel/rater'\n * import { createQuantitativeDefinition } from '@orkestrel/reason'\n *\n * buildRatingDefinition('r1', 'Rating', [\n * \tbuildLineDefinition('base', 'Base Amount', createQuantitativeDefinition('base', 'Base', [])),\n * ])\n * ```\n */\nexport function buildRatingDefinition(\n\tid: string,\n\tname: string,\n\tlines: readonly LineDefinition[],\n\toverrides?: Partial<Omit<RatingDefinition, 'id' | 'name' | 'lines'>>,\n): RatingDefinition {\n\treturn { id, name, lines, ...overrides }\n}\n\n/**\n * Joins one authored quantitative factor to its evaluated {@link FactorResult}.\n *\n * @param definition - The authored factor\n * @param results - The group's factor results\n * @returns A fresh worksheet factor, its `checks` empty for a factor that never ran\n *\n * @example\n * ```ts\n * import { createFieldFactor } from '@orkestrel/reason'\n * import { buildWorksheetFactor } from '@orkestrel/rater'\n *\n * const factor = createFieldFactor('seats', 'seats')\n * buildWorksheetFactor(factor, [{ id: 'seats', applied: true, value: 10, fallback: false }])\n * ```\n */\nexport function buildWorksheetFactor(\n\tdefinition: Factor,\n\tresults: readonly FactorResult[],\n): WorksheetFactor {\n\tconst result = results.find((entry) => entry.id === definition.id)\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name,\n\t\t...(definition.description === undefined ? {} : { description: definition.description }),\n\t\tapplied: result?.applied ?? false,\n\t\t...(result?.value === undefined ? {} : { value: result.value }),\n\t\t...(result?.raw === undefined ? {} : { raw: result.raw }),\n\t\t...(result?.actual === undefined ? {} : { actual: result.actual }),\n\t\tfallback: result?.fallback ?? false,\n\t\tchecks: result?.checks ?? [],\n\t}\n}\n\n/**\n * Joins one authored quantitative group to its evaluated {@link GroupResult}.\n *\n * @param definition - The authored group\n * @param results - The definition's group results\n * @returns A fresh worksheet group\n *\n * @example\n * ```ts\n * import { createFactorGroup, createStaticFactor } from '@orkestrel/reason'\n * import { buildWorksheetGroup } from '@orkestrel/rater'\n *\n * const group = createFactorGroup('charge', 'sum', [createStaticFactor('base', 100)])\n * buildWorksheetGroup(group, [{ id: 'charge', applied: true, value: 100, factors: [] }])\n * ```\n */\nexport function buildWorksheetGroup(\n\tdefinition: QuantitativeDefinition['groups'][number],\n\tresults: readonly GroupResult[],\n): WorksheetGroup {\n\tconst result = results.find((entry) => entry.id === definition.id)\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name,\n\t\t...(definition.description === undefined ? {} : { description: definition.description }),\n\t\tapplied: result?.applied ?? false,\n\t\t...(result === undefined ? {} : { value: result.value }),\n\t\tfactors: definition.factors.map((factor) =>\n\t\t\tbuildWorksheetFactor(factor, result?.factors ?? []),\n\t\t),\n\t}\n}\n\n/**\n * Builds one display-neutral {@link Step} row.\n *\n * @param stage - The step's stage\n * @param id - The stage's authored id, when it has one\n * @param name - The stage's authored name, when it has one\n * @param value - The stage's resolved value\n * @returns A fresh step\n *\n * @example\n * ```ts\n * import { buildWorksheetStep } from '@orkestrel/rater'\n *\n * buildWorksheetStep('total', 'quote', 'Quote', 110)\n * // { stage: 'total', id: 'quote', name: 'Quote', value: 110 }\n * ```\n */\nexport function buildWorksheetStep(\n\tstage: WorksheetStage,\n\tid: string | undefined,\n\tname: string | undefined,\n\tvalue: number,\n): Step {\n\treturn {\n\t\tstage,\n\t\t...(id === undefined ? {} : { id }),\n\t\t...(name === undefined ? {} : { name }),\n\t\tvalue,\n\t}\n}\n\n/**\n * Builds the ordered {@link Step} rows for a resolved {@link Worksheet}.\n *\n * @param definition - The authored quantitative definition\n * @param result - The evaluated quantitative result\n * @param groups - The definition's already-joined worksheet groups\n * @returns A fresh, ordered list of steps: applied factors, then groups, then the total\n *\n * @example\n * ```ts\n * import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'\n * import { buildWorksheetGroup, buildWorksheetSteps } from '@orkestrel/rater'\n *\n * const definition = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])\n * const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)\n * if (result.reasoning === 'quantitative') {\n * \tbuildWorksheetSteps(definition, result, definition.groups.map((group) => buildWorksheetGroup(group, result.groups)))\n * }\n * ```\n */\nexport function buildWorksheetSteps(\n\tdefinition: QuantitativeDefinition,\n\tresult: QuantitativeResult,\n\tgroups: readonly WorksheetGroup[],\n): readonly Step[] {\n\tconst output: Step[] = []\n\tfor (const group of groups) {\n\t\tfor (const factor of group.factors) {\n\t\t\tif (factor.applied && factor.value !== undefined) {\n\t\t\t\toutput.push(buildWorksheetStep('factor', factor.id, factor.name, factor.value))\n\t\t\t}\n\t\t}\n\t\tif (group.value !== undefined) {\n\t\t\toutput.push(buildWorksheetStep('group', group.id, group.name, group.value))\n\t\t}\n\t}\n\toutput.push(buildWorksheetStep('total', definition.id, definition.name, result.value))\n\treturn output\n}\n\n/**\n * Joins a {@link QuantitativeDefinition} and its {@link QuantitativeResult} into\n * a {@link Worksheet} — the rating audit trail.\n *\n * @param definition - The authored quantitative definition\n * @param result - The evaluated quantitative result\n * @returns A fresh worksheet\n *\n * @example\n * ```ts\n * import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'\n * import { buildWorksheet } from '@orkestrel/rater'\n *\n * const definition = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])\n * const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, definition)\n * if (result.reasoning === 'quantitative') buildWorksheet(definition, result) // the full audit trail\n * ```\n */\nexport function buildWorksheet(\n\tdefinition: QuantitativeDefinition,\n\tresult: QuantitativeResult,\n): Worksheet {\n\tconst groups = definition.groups.map((group) => buildWorksheetGroup(group, result.groups))\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name,\n\t\taggregation: definition.aggregation,\n\t\t...(definition.precision === undefined ? {} : { precision: definition.precision }),\n\t\tvalue: result.value,\n\t\tgroups,\n\t\tsteps: buildWorksheetSteps(definition, result, groups),\n\t\ttrace: result.trace,\n\t\trefusals: result.refusals,\n\t\tsuccess: result.success,\n\t\tfaults: result.faults,\n\t\trepairs: result.repairs,\n\t\tdefaulted: result.defaulted,\n\t}\n}\n\n/**\n * Builds a rated {@link LineResult} from a line's evaluated\n * {@link QuantitativeResult}.\n *\n * @param definition - The authored line definition\n * @param result - The evaluated quantitative result\n * @returns A fresh line result\n *\n * @example\n * ```ts\n * import { createQuantitativeDefinition, createQuantitativeReasoner, createReason } from '@orkestrel/reason'\n * import { buildLineDefinition, buildLineResult } from '@orkestrel/rater'\n *\n * const line = buildLineDefinition('base', 'Base', createQuantitativeDefinition('base', 'Base', []))\n * const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, line.rate)\n * if (result.reasoning === 'quantitative') buildLineResult(line, result) // amount present only on a successful worksheet\n * ```\n */\nexport function buildLineResult(\n\tdefinition: LineDefinition,\n\tresult: QuantitativeResult,\n): LineResult {\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name,\n\t\t...(result.success ? { amount: result.value } : {}),\n\t\tworksheet: buildWorksheet(definition.rate, result),\n\t}\n}\n\n/**\n * Copies a quantitative result into plain objects and arrays this package owns, reading each\n * member of it once.\n *\n * @remarks\n * The copy reaches the result's groups, their factors, and each factor's checks. A check's own\n * `check` and `actual`, and the entries of `refusals`, `faults`, and `repairs`, are carried as\n * they were read.\n *\n * @param result - The quantitative result to copy\n * @returns A fresh result that holds each member as it read\n *\n * @example\n * ```ts\n * import { copyResult } from '@orkestrel/rater'\n *\n * const answer = {\n * \treasoning: 'quantitative',\n * \tvalue: 5,\n * \tgroups: [],\n * \tcount: 0,\n * \tsuccess: true,\n * \ttrace: [],\n * \trefusals: [],\n * \tfaults: [],\n * \trepairs: [],\n * \tdefaulted: [],\n * } as const\n * copyResult(answer) === answer // false\n * ```\n */\nexport function copyResult(result: QuantitativeResult): QuantitativeResult {\n\tconst { reasoning, value, groups, count, success, trace, refusals, faults, repairs, defaulted } =\n\t\tresult\n\treturn {\n\t\treasoning,\n\t\tvalue,\n\t\tgroups: groups.map(({ id, applied, value: held, factors }) => ({\n\t\t\tid,\n\t\t\tapplied,\n\t\t\tvalue: held,\n\t\t\tfactors: factors.map(\n\t\t\t\t({ id: key, applied: ran, value: scored, raw, actual, fallback, checks }) => ({\n\t\t\t\t\tid: key,\n\t\t\t\t\tapplied: ran,\n\t\t\t\t\tvalue: scored,\n\t\t\t\t\t...(raw === undefined ? {} : { raw }),\n\t\t\t\t\t...(actual === undefined ? {} : { actual }),\n\t\t\t\t\tfallback,\n\t\t\t\t\t...(checks === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tchecks: checks.map((read) => ({\n\t\t\t\t\t\t\t\t\tcheck: read.check,\n\t\t\t\t\t\t\t\t\tstate: read.state,\n\t\t\t\t\t\t\t\t\tactual: read.actual,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t),\n\t\t})),\n\t\tcount,\n\t\tsuccess,\n\t\ttrace: [...trace],\n\t\trefusals: [...refusals],\n\t\tfaults: [...faults],\n\t\trepairs: [...repairs],\n\t\tdefaulted: [...defaulted],\n\t}\n}\n\n/**\n * Finds each enabled group of a definition that a result omits, and each enabled factor an\n * answered group omits.\n *\n * @remarks\n * An omitted group is named alone, because its factors have no group to answer in.\n *\n * @param definition - The authored quantitative definition\n * @param result - The result the engine answered with\n * @returns The `group`, and the `factor` where one is omitted, of each omission, in definition order\n *\n * @example\n * ```ts\n * import { createFactorGroup, createQuantitativeDefinition, createStaticFactor } from '@orkestrel/reason'\n * import { findUnansweredParts } from '@orkestrel/rater'\n *\n * const definition = createQuantitativeDefinition('quote', 'Quote', [\n * \tcreateFactorGroup('charge', 'sum', [createStaticFactor('base', 100)]),\n * ])\n * findUnansweredParts(definition, {\n * \treasoning: 'quantitative',\n * \tvalue: 0,\n * \tgroups: [],\n * \tcount: 0,\n * \tsuccess: true,\n * \ttrace: [],\n * \trefusals: [],\n * \tfaults: [],\n * \trepairs: [],\n * \tdefaulted: [],\n * }) // [{ group: 'charge' }]\n * ```\n */\nexport function findUnansweredParts(\n\tdefinition: QuantitativeDefinition,\n\tresult: QuantitativeResult,\n): ReadonlyArray<Pick<ReasonRefusal, 'group' | 'factor'>> {\n\tconst answered = new Map(\n\t\tresult.groups.map((group): [string, ReadonlySet<string>] => [\n\t\t\tgroup.id,\n\t\t\tnew Set(group.factors.map((factor) => factor.id)),\n\t\t]),\n\t)\n\treturn definition.groups\n\t\t.filter((group) => group.enabled !== false)\n\t\t.flatMap((group): ReadonlyArray<Pick<ReasonRefusal, 'group' | 'factor'>> => {\n\t\t\tconst held = answered.get(group.id)\n\t\t\tif (held === undefined) return [{ group: group.id }]\n\t\t\treturn group.factors\n\t\t\t\t.filter((factor) => factor.enabled !== false && !held.has(factor.id))\n\t\t\t\t.map((factor) => ({ group: group.id, factor: factor.id }))\n\t\t})\n}\n\n/**\n * Finds each group id a result lists more than once, and each factor id one of its groups lists\n * more than once.\n *\n * @remarks\n * An entry that repeats an id is refused whatever it holds, because a worksheet reads the first\n * entry and a completeness check reads the last. Each repeated id is named once, however many\n * entries repeat it.\n *\n * @param result - The result the engine answered with\n * @returns The `group`, and the `factor` where a factor repeats, of each repeated id\n *\n * @example\n * ```ts\n * import { findRepeatedParts } from '@orkestrel/rater'\n *\n * const group = { id: 'charge', applied: true, value: 100, factors: [] }\n * findRepeatedParts({\n * \treasoning: 'quantitative',\n * \tvalue: 100,\n * \tgroups: [group, group],\n * \tcount: 1,\n * \tsuccess: true,\n * \ttrace: [],\n * \trefusals: [],\n * \tfaults: [],\n * \trepairs: [],\n * \tdefaulted: [],\n * }) // [{ group: 'charge' }]\n * ```\n */\nexport function findRepeatedParts(\n\tresult: QuantitativeResult,\n): ReadonlyArray<Pick<ReasonRefusal, 'group' | 'factor'>> {\n\tconst groups = findDuplicates(result.groups).map(\n\t\t(group): Pick<ReasonRefusal, 'group' | 'factor'> => ({ group }),\n\t)\n\tconst factors = result.groups.flatMap((group) =>\n\t\tfindDuplicates(group.factors).map((factor): Pick<ReasonRefusal, 'group' | 'factor'> => ({\n\t\t\tgroup: group.id,\n\t\t\tfactor,\n\t\t})),\n\t)\n\treturn [...groups, ...factors].filter(\n\t\t(part, index, all) =>\n\t\t\tall.findIndex((held) => held.group === part.group && held.factor === part.factor) === index,\n\t)\n}\n\n/**\n * Finds each line whose id an earlier line of the list holds.\n *\n * @param lines - The lines of one rating, in order\n * @returns One `definition` refusal for each such line, its `path` the id and its `index` the line's place\n *\n * @example\n * ```ts\n * import { createQuantitativeDefinition } from '@orkestrel/reason'\n * import { buildLineDefinition, findRepeatedLines } from '@orkestrel/rater'\n *\n * const rate = createQuantitativeDefinition('base', 'Base', [])\n * const line = buildLineDefinition('base', 'Base', rate)\n * findRepeatedLines([line, line]) // [{ cause: 'definition', path: ['base'], index: 1 }]\n * ```\n */\nexport function findRepeatedLines(lines: readonly LineDefinition[]): readonly ReasonRefusal[] {\n\tconst earliest = new Map(\n\t\tlines.map((line, index): [string, number] => [line.id, index]).toReversed(),\n\t)\n\treturn lines.flatMap((line, index): readonly ReasonRefusal[] =>\n\t\tearliest.get(line.id) === index ? [] : [{ cause: 'definition', path: [line.id], index }],\n\t)\n}\n\n/**\n * Holds an engine's answer to what its own members and the definition support.\n *\n * @remarks\n * The answer is read once, through {@link copyResult}, and every verdict follows from that copy.\n * An answer that is no quantitative result is `malformed` alone. A success beside a refusal or a\n * fault, beside each enabled group or factor the answer omits, beside each group or factor id it\n * lists more than once, and beside a value that is not a finite number, fails closed with one\n * `malformed` refusal for each, the part in `group` and `factor` and the value in `actual`. A failure that names no refusal and no fault is\n * `silent`. Any other answer returns as its copy.\n *\n * @param answer - What the engine answered\n * @param definition - The authored quantitative definition the engine ran\n * @returns A fresh result the package owns\n *\n * @example\n * ```ts\n * import { createQuantitativeDefinition } from '@orkestrel/reason'\n * import { settleResult } from '@orkestrel/rater'\n *\n * settleResult(\n * \t{\n * \t\treasoning: 'quantitative',\n * \t\tvalue: 5,\n * \t\tgroups: [],\n * \t\tcount: 0,\n * \t\tsuccess: false,\n * \t\ttrace: [],\n * \t\trefusals: [],\n * \t\tfaults: [],\n * \t\trepairs: [],\n * \t\tdefaulted: [],\n * \t},\n * \tcreateQuantitativeDefinition('base', 'Base', []),\n * ).refusals // [{ cause: 'silent' }]\n * ```\n */\nexport function settleResult(\n\tanswer: unknown,\n\tdefinition: QuantitativeDefinition,\n): QuantitativeResult {\n\tconst copied = isQuantitativeResult(answer) ? attempt(() => copyResult(answer)) : undefined\n\tif (copied === undefined || !isSuccess(copied) || !isQuantitativeResult(copied.value)) {\n\t\treturn buildMalformedResult()\n\t}\n\tconst result = copied.value\n\tconst { success, value, refusals, faults } = result\n\tconst named = refusals.length > 0 || faults.length > 0\n\tif (!success) return named ? result : { ...result, refusals: [{ cause: 'silent' }] }\n\tconst held: ReadonlyArray<Pick<ReasonRefusal, 'actual' | 'group' | 'factor'>> = [\n\t\t...(named ? [{}] : []),\n\t\t...findUnansweredParts(definition, result),\n\t\t...findRepeatedParts(result),\n\t\t...(isFiniteNumber(value) ? [] : [{ actual: value }]),\n\t]\n\tif (held.length === 0) return result\n\tconst contradictions = held.map((part): ReasonRefusal => ({ cause: 'malformed', ...part }))\n\treturn { ...result, success: false, refusals: [...refusals, ...contradictions] }\n}\n\n/**\n * Builds the failed {@link QuantitativeResult} for an engine answer that is no quantitative result.\n *\n * @returns A fresh failed result carrying one `malformed` refusal\n *\n * @example\n * ```ts\n * import { buildMalformedResult } from '@orkestrel/rater'\n *\n * buildMalformedResult().refusals // [{ cause: 'malformed' }]\n * ```\n */\nexport function buildMalformedResult(): QuantitativeResult {\n\treturn {\n\t\treasoning: 'quantitative',\n\t\tvalue: 0,\n\t\tgroups: [],\n\t\tcount: 0,\n\t\tsuccess: false,\n\t\ttrace: [],\n\t\trefusals: [{ cause: 'malformed' }],\n\t\tfaults: [],\n\t\trepairs: [],\n\t\tdefaulted: [],\n\t}\n}\n\n/**\n * Sums defined line amounts.\n *\n * @param lines - The rated lines\n * @returns The sum, or `undefined` when no line has an amount or any line refused\n *\n * @example\n * ```ts\n * import { createFactorGroup, createQuantitativeDefinition, createQuantitativeReasoner, createReason, createStaticFactor } from '@orkestrel/reason'\n * import { buildLineDefinition, buildLineResult, sumAmounts } from '@orkestrel/rater'\n *\n * const rate = createQuantitativeDefinition('base', 'Base', [createFactorGroup('g', 'sum', [createStaticFactor('flat', 100)])])\n * const line = buildLineDefinition('base', 'Base', rate)\n * const result = createReason({ reasoners: [createQuantitativeReasoner()] }).reason({}, rate)\n * if (result.reasoning === 'quantitative') sumAmounts([buildLineResult(line, result)]) // 100\n * ```\n */\nexport function sumAmounts(lines: readonly LineResult[]): number | undefined {\n\t// A total over a line that refused would read as an answer for the whole subject.\n\tif (!lines.every((rated) => rated.worksheet.success)) return undefined\n\treturn Iterator.from(lines).reduce<number | undefined>(\n\t\t(total, rated) => (rated.amount === undefined ? total : (total ?? 0) + rated.amount),\n\t\tundefined,\n\t)\n}\n\n/**\n * Projects a result to the JSON its contract reads.\n *\n * @remarks\n * A factor's `actual`, a check's `actual`, and a refusal's `actual` hold whatever the subject held\n * and a worksheet's numbers may be `NaN`, so a result crosses a boundary as this projection, each\n * `actual` on its own budget.\n *\n * @param result - The rating result\n * @returns Its JSON projection, which `ratingResultContract` admits\n *\n * @example\n * ```ts\n * import { createRater, projectRatingResult, ratingResultContract } from '@orkestrel/rater'\n *\n * const rater = createRater()\n * ratingResultContract.is(projectRatingResult(rater.rate([], {}))) // true\n * rater.destroy()\n * ```\n */\nexport function projectRatingResult(result: RatingResult): JSONValue | undefined {\n\tconst lines = result.lines.map((line) => ({\n\t\t...line,\n\t\tworksheet: {\n\t\t\t...line.worksheet,\n\t\t\trefusals: line.worksheet.refusals.map((refusal) => projectRefusal(refusal)),\n\t\t\tgroups: line.worksheet.groups.map((group) => ({\n\t\t\t\t...group,\n\t\t\t\tfactors: group.factors.map((factor) => ({\n\t\t\t\t\t...factor,\n\t\t\t\t\tactual: projectValue(factor.actual),\n\t\t\t\t\tchecks: factor.checks.map((check) => projectCheck(check)),\n\t\t\t\t})),\n\t\t\t})),\n\t\t},\n\t}))\n\tconst refusals = result.refusals.map((refusal) => projectRefusal(refusal))\n\treturn projectValue({ ...result, refusals, lines }, new Set(), { left: Number.POSITIVE_INFINITY })\n}\n","import type { ContractShape } from '@orkestrel/contract'\nimport {\n\tarrayShape,\n\tauditFaultShape,\n\tbooleanShape,\n\tjsonShape,\n\tliteralShape,\n\tnullableShape,\n\tnumberShape,\n\tobjectShape,\n\toptionalShape,\n\tshapeShape,\n\tstringShape,\n} from '@orkestrel/contract'\nimport {\n\tAGGREGATIONS,\n\tcheckResultShape,\n\tfieldPathShape,\n\tquantitativeDefinitionShape,\n\treasonRefusalShape,\n} from '@orkestrel/reason'\nimport { WORKSHEET_STAGES } from './constants.js'\n\n// A rating definition and result as shapes, so they reach an LLM, a tool, and MCP as JSON Schema. A\n// result is shaped in its JSON projection, where a non-finite number is `null`.\n\n/** Describes a `LineDefinition`. */\nexport const lineDefinitionShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: stringShape(),\n\tdescription: optionalShape(stringShape()),\n\trate: quantitativeDefinitionShape,\n\tmetadata: optionalShape(jsonShape()),\n})\n\n/**\n * Describes a `RatingDefinition`.\n */\nexport const ratingDefinitionShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: stringShape(),\n\tdescription: optionalShape(stringShape()),\n\tlines: arrayShape(lineDefinitionShape),\n\tmetadata: optionalShape(jsonShape()),\n\tshape: optionalShape(shapeShape()),\n})\n\n/** Describes a `WorksheetFactor` in its JSON projection. */\nexport const worksheetFactorShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: optionalShape(stringShape()),\n\tdescription: optionalShape(stringShape()),\n\tapplied: booleanShape(),\n\tvalue: optionalShape(nullableShape(numberShape())),\n\traw: optionalShape(nullableShape(numberShape())),\n\tactual: optionalShape(jsonShape()),\n\tfallback: booleanShape(),\n\tchecks: arrayShape(checkResultShape),\n})\n\n/** Describes a `WorksheetGroup` in its JSON projection. */\nexport const worksheetGroupShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: optionalShape(stringShape()),\n\tdescription: optionalShape(stringShape()),\n\tapplied: booleanShape(),\n\tvalue: optionalShape(nullableShape(numberShape())),\n\tfactors: arrayShape(worksheetFactorShape),\n})\n\n/** Describes a `Step` in its JSON projection. */\nexport const worksheetStepShape: ContractShape = objectShape({\n\tstage: literalShape(WORKSHEET_STAGES),\n\tid: optionalShape(stringShape()),\n\tname: optionalShape(stringShape()),\n\tvalue: nullableShape(numberShape()),\n})\n\n/** Describes a `Worksheet` in its JSON projection. */\nexport const worksheetShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: stringShape(),\n\taggregation: literalShape(AGGREGATIONS),\n\tprecision: optionalShape(numberShape()),\n\tvalue: nullableShape(numberShape()),\n\tgroups: arrayShape(worksheetGroupShape),\n\tsteps: arrayShape(worksheetStepShape),\n\ttrace: arrayShape(stringShape()),\n\trefusals: arrayShape(reasonRefusalShape),\n\tsuccess: booleanShape(),\n\tfaults: arrayShape(auditFaultShape()),\n\trepairs: arrayShape(auditFaultShape()),\n\tdefaulted: arrayShape(fieldPathShape),\n})\n\n/** Describes a `LineResult` in its JSON projection. */\nexport const lineResultShape: ContractShape = objectShape({\n\tid: stringShape(),\n\tname: stringShape(),\n\tamount: optionalShape(nullableShape(numberShape())),\n\tworksheet: worksheetShape,\n})\n\n/** Describes a `RatingResult` in its JSON projection. */\nexport const ratingResultShape: ContractShape = objectShape({\n\tlines: arrayShape(lineResultShape),\n\ttotal: optionalShape(nullableShape(numberShape())),\n\tsuccess: booleanShape(),\n\trefusals: arrayShape(reasonRefusalShape),\n\tfaults: arrayShape(auditFaultShape()),\n\trepairs: arrayShape(auditFaultShape()),\n\tdefaulted: arrayShape(fieldPathShape),\n})\n","import type { ContractInterface } from '@orkestrel/contract'\nimport { createContract } from '@orkestrel/contract'\nimport { ratingDefinitionShape, ratingResultShape } from './shapers.js'\n\n/**\n * Publishes a `RatingDefinition` as a contract. Cross it on `is`, never `parse`.\n */\nexport const ratingDefinitionContract: ContractInterface<unknown> =\n\tcreateContract(ratingDefinitionShape)\n\n/** Publishes a `RatingResult`'s JSON projection as a contract, read through `projectRatingResult`. */\nexport const ratingResultContract: ContractInterface<unknown> = createContract(ratingResultShape)\n","import type { ContractShape } from '@orkestrel/contract'\nimport type { EmitterInterface } from '@orkestrel/emitter'\nimport type {\n\tQuantitativeDefinition,\n\tQuantitativeResult,\n\tReasonInterface,\n\tReasonRefusal,\n\tReasonResult,\n\tSubject,\n} from '@orkestrel/reason'\nimport type {\n\tLineDefinition,\n\tLineResult,\n\tRaterEventMap,\n\tRaterInterface,\n\tRaterOptions,\n\tRatingDefinition,\n\tRatingResult,\n\tTotalHandler,\n} from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { arrayOf, isFiniteNumber, isRecord } from '@orkestrel/contract'\nimport {\n\tcreateQuantitativeReasoner,\n\tcreateReason,\n\tcreateSubjectDoor,\n\tfilterUniqueFaults,\n\tfilterUniqueFields,\n\tisReasonError,\n\tnestRefusals,\n\tscanShape,\n\tscanShapeReads,\n} from '@orkestrel/reason'\nimport { RaterError } from './errors.js'\nimport { buildLineResult, findRepeatedLines, settleResult, sumAmounts } from './helpers.js'\nimport { isLineDefinition, isRatingDefinition } from './validators.js'\n\n/**\n * Orchestrates rating — owns (or receives) the shared quantitative\n * reasoning engine and projects results into the rating domain vocabulary.\n *\n * @remarks\n * When no `engine` is injected, `Rater` builds and owns its own\n * quantitative-only engine (`bail: false`) — Rater performs no evaluation\n * arithmetic of its own; it only orchestrates and projects. The\n * array-of-lines `rate` overload is declared first so a plain line list\n * resolves to that form. `destroy()` destroys an owned engine, then the\n * emitter last; an injected engine is never destroyed. Afterwards every\n * other method throws {@link RaterError} `'DESTROYED'`.\n *\n * @example\n * ```ts\n * import { Rater } from '@orkestrel/rater'\n *\n * const rater = new Rater()\n * rater.rate([], { id: 'subject-1' }).success // true\n * rater.destroy()\n * ```\n */\nexport class Rater implements RaterInterface {\n\treadonly #emitter: Emitter<RaterEventMap>\n\treadonly #engine: ReasonInterface\n\treadonly #owned: boolean\n\treadonly #total: TotalHandler | undefined\n\treadonly #door = createSubjectDoor()\n\treadonly #valid = new WeakSet<RatingDefinition>()\n\t#destroyed = false\n\n\tconstructor(options?: RaterOptions) {\n\t\tthis.#emitter = new Emitter<RaterEventMap>({\n\t\t\t...(options?.on === undefined ? {} : { on: options.on }),\n\t\t\t...(options?.error === undefined ? {} : { error: options.error }),\n\t\t})\n\t\tif (options?.engine === undefined) {\n\t\t\tthis.#engine = createReason({ reasoners: [createQuantitativeReasoner()], bail: false })\n\t\t\tthis.#owned = true\n\t\t} else {\n\t\t\tthis.#engine = options.engine\n\t\t\tthis.#owned = false\n\t\t}\n\t\tthis.#total = options?.total\n\t}\n\n\tget emitter(): EmitterInterface<RaterEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t// Array overload first so a plain line list resolves to that form.\n\trate(lines: readonly LineDefinition[], subject: Subject): RatingResult\n\trate(definition: RatingDefinition, subject: Subject): RatingResult\n\trate(input: readonly LineDefinition[] | RatingDefinition, subject: Subject): RatingResult {\n\t\tthis.#ensureAlive()\n\t\tconst lines = this.#normalize(input)\n\t\tif (!isRecord(subject)) throw new RaterError('MISMATCH', 'Subject must be a record')\n\t\tconst admission = this.#door.admit(subject, this.#readShape(input))\n\t\tconst admitted = admission.subject\n\t\tif (admitted === undefined) {\n\t\t\tconst refused: RatingResult = {\n\t\t\t\tlines: [],\n\t\t\t\tsuccess: false,\n\t\t\t\trefusals: admission.refusals,\n\t\t\t\tfaults: admission.faults,\n\t\t\t\trepairs: [],\n\t\t\t\tdefaulted: [],\n\t\t\t}\n\t\t\tthis.#emitter.emit('rate', subject, refused)\n\t\t\treturn refused\n\t\t}\n\t\tconst results = lines.map((line) => this.#rateLine(line, admitted))\n\t\tconst repeated = findRepeatedLines(lines)\n\t\tconst rated = results.every((entry) => entry.worksheet.success) && repeated.length === 0\n\t\t// No handler totals a line that refused, because the total would read as an answer.\n\t\tconst summed = rated ? (this.#total ?? sumAmounts)(results) : undefined\n\t\t// A total past what a number holds is no answer either, and the sum alone can overflow.\n\t\tconst overflowed = summed !== undefined && !isFiniteNumber(summed)\n\t\tconst total = overflowed ? undefined : summed\n\t\tconst success = rated && !overflowed\n\t\tconst faults = filterUniqueFaults(results.flatMap((entry) => entry.worksheet.faults))\n\t\t// A line's refusals, each located under its id, then the total's, which belongs to no line.\n\t\tconst unfinite: readonly ReasonRefusal[] = overflowed\n\t\t\t? [{ cause: 'value', actual: summed }]\n\t\t\t: []\n\t\tconst refusals = [\n\t\t\t...results.flatMap((entry) => nestRefusals(entry.worksheet.refusals, entry.id)),\n\t\t\t...repeated,\n\t\t\t...unfinite,\n\t\t]\n\t\tconst repairs = filterUniqueFaults([\n\t\t\t...admission.repairs,\n\t\t\t...results.flatMap((entry) => entry.worksheet.repairs),\n\t\t])\n\t\tconst defaulted = filterUniqueFields([\n\t\t\t...admission.defaulted,\n\t\t\t...results.flatMap((entry) => entry.worksheet.defaulted),\n\t\t])\n\t\tconst result: RatingResult = {\n\t\t\tlines: results,\n\t\t\t...(total === undefined ? {} : { total }),\n\t\t\tsuccess,\n\t\t\trefusals,\n\t\t\tfaults,\n\t\t\trepairs,\n\t\t\tdefaulted,\n\t\t}\n\t\tthis.#emitter.emit('rate', admitted, result)\n\t\treturn result\n\t}\n\n\tdestroy(): void {\n\t\tif (this.#destroyed) return\n\t\tthis.#destroyed = true\n\t\tif (this.#owned) this.#engine.destroy()\n\t\tthis.#emitter.destroy()\n\t}\n\n\t#normalize(input: readonly LineDefinition[] | RatingDefinition): readonly LineDefinition[] {\n\t\tif (arrayOf(isLineDefinition)(input)) return input\n\t\tif (isRatingDefinition(input)) return input.lines\n\t\tthrow new RaterError(\n\t\t\t'DEFINITION',\n\t\t\t'Rating input must be an array of line definitions or a rating definition',\n\t\t)\n\t}\n\n\t// A rating's shape is checked against what its lines read once per definition, by identity.\n\t#readShape(input: readonly LineDefinition[] | RatingDefinition): ContractShape | undefined {\n\t\tif (arrayOf(isLineDefinition)(input)) return undefined\n\t\tconst { shape, lines } = input\n\t\tif (shape === undefined || this.#valid.has(input)) return shape\n\t\tconst checks = lines.flatMap((line) =>\n\t\t\tline.rate.groups.flatMap((group) => group.factors.flatMap((factor) => factor.checks ?? [])),\n\t\t)\n\t\tconst fields = lines.flatMap((line) =>\n\t\t\tline.rate.groups.flatMap((group) =>\n\t\t\t\tgroup.factors.flatMap((factor) =>\n\t\t\t\t\tfactor.source.origin === 'static' ? [] : [factor.source.field],\n\t\t\t\t),\n\t\t\t),\n\t\t)\n\t\tconst errors = [...scanShape(shape), ...scanShapeReads(shape, checks, fields, new Set()).errors]\n\t\tif (errors.length > 0) {\n\t\t\tthrow new RaterError('DEFINITION', `Rating shape is invalid: ${errors.join(', ')}`)\n\t\t}\n\t\tthis.#valid.add(input)\n\t\treturn shape\n\t}\n\n\t#rateLine(line: LineDefinition, subject: Subject): LineResult {\n\t\tconst result = this.#reasonQuantitative(subject, line.rate)\n\t\treturn buildLineResult(line, result)\n\t}\n\n\t// Narrows the engine's answer to a QuantitativeResult, and reads nothing it has not checked:\n\t// an injected engine can answer anything, null included, so this is total. An engine that\n\t// contradicts itself refuses, because `success` is the verdict and it has to be earned.\n\t#reasonQuantitative(subject: Subject, definition: QuantitativeDefinition): QuantitativeResult {\n\t\treturn settleResult(this.#reason(subject, definition), definition)\n\t}\n\n\t// An invalid line definition is an authoring error, so it reaches the caller as one.\n\t#reason(subject: Subject, definition: QuantitativeDefinition): ReasonResult {\n\t\ttry {\n\t\t\treturn this.#engine.reason(subject, definition)\n\t\t} catch (error) {\n\t\t\tif (isReasonError(error) && error.code === 'INVALID') {\n\t\t\t\tthrow new RaterError('DEFINITION', error.message)\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\t}\n\n\t#ensureAlive(): void {\n\t\tif (this.#destroyed) throw new RaterError('DESTROYED', 'Rater has been destroyed')\n\t}\n}\n","import type { RaterInterface, RaterOptions } from './types.js'\nimport { Rater } from './Rater.js'\n\n/**\n * Creates a rating orchestrator over the shared quantitative engine, seeded\n * from {@link RaterOptions} and returning a {@link RaterInterface}.\n *\n * @param options - Optional total handler, injected engine, and emitter hooks\n * @returns A {@link RaterInterface}\n *\n * @example Create a rater\n * ```ts\n * import { createRater } from '@orkestrel/rater'\n *\n * const rater = createRater()\n * rater.destroy()\n * ```\n */\nexport function createRater(options?: RaterOptions): RaterInterface {\n\treturn new Rater(options)\n}\n"],"mappings":";;;;;;AACA,IAAa,mBAAmB;CAAC;CAAU;CAAS;AAAO;;;;;;;;;;;;;;;;;;ACkB3D,IAAa,aAAb,cAAgC,MAAM;CAC5B;CACA;CAET,YAAY,MAAsB,SAAiB,SAA6C;EAC/F,MAAM,OAAO;EACbA,oBAAAA,WAAW,OAAO,MAAM,OAAO,IAAI,6BAA6B,GAAG,EAAE,OAAO,KAAK,CAAC;EAClF,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,IAAI,YAAY,KAAA,GAAW,KAAK,UAAU;CAC3C;AACD;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aAAa,OAAqC;CACjE,QAAA,GAAOC,oBAAAA,MAAAA,OAAY;EAClB,IAAI,EAAE,iBAAiB,UAAUD,oBAAAA,WAAW,UAAU,KAAK,MAAM,MAAM,WAAW,OAAO;EAEzF,IADcA,oBAAAA,WAAW,SAAS,OAAO,OAAO,IAAI,6BAA6B,CAC7E,CAAA,EAAO,UAAU,OAAO,OAAO;EACnC,MAAM,OAAgBA,oBAAAA,WAAW,QAAQ,KAAK,OAAO,MAAM;EAC3D,IAAI,SAAS,gBAAgB,SAAS,cAAc,SAAS,aAAa,OAAO;EACjF,MAAM,UAAmBA,oBAAAA,WAAW,QAAQ,KAAK,OAAO,SAAS;EACjE,OAAO,YAAY,KAAA,MAAA,GAAaE,oBAAAA,SAAAA,CAAS,OAAO,MAAA,GAAKC,oBAAAA,WAAAA,CAAW,OAAO;CACxE,C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