Skip to content

reckon

reckon

Classes

CycleError

Defined in: reckon/deps.ts:163

Cycle error thrown when topo-sort detects a cycle.

Extends

  • Error

Constructors

Constructor
new CycleError(nodes): CycleError;

Defined in: reckon/deps.ts:165

Parameters
Parameter Type
nodes string[]
Returns

CycleError

Overrides
Error.constructor

Properties

nodes
readonly nodes: string[];

Defined in: reckon/deps.ts:164


ReckonEngine

Defined in: reckon/register.server.ts:35

Reckon computation engine — declarative, auditable, pure.

Create an instance via createReckonEngine(). Register custom ops for domain-specific calculations. Validate and run computation definitions.

Example

const engine = createReckonEngine();

const def: ComputationDefinition = {
  id: 'pcb',
  tables: { pcbTable: { kind: 'progressive', rows: [...] } },
  exprs: { pcb: 'round(applyProgressive(income * 12, "pcbTable") / 12, "NEAREST_CENT")' },
  outputs: ['pcb'],
};

const { outputs, manifest } = engine.runComputation<{ income: number }, { pcb: number }>(def, { income: 5000 });
console.log(outputs.pcb); // typed as number
console.log(manifest.nodes[0].opAudit); // { op: 'applyProgressive', audit: { matchedTier: {...} } }

Constructors

Constructor
new ReckonEngine(): ReckonEngine;
Returns

ReckonEngine

Methods

registerFunction()
registerFunction(
   name, 
   signature, 
   handler): this;

Defined in: reckon/register.server.ts:40

Register a custom op available in all computations. Invalidates the env cache.

Parameters
Parameter Type
name string
signature string
handler (...args) => unknown
Returns

this

replayManifest()
replayManifest(manifest, def): ReplayResult;

Defined in: reckon/register.server.ts:73

Replay a manifest to verify integrity against a stored definition.

Parameters
Parameter Type
manifest ComputationManifest
def ComputationDefinition
Returns

ReplayResult

runComputation()
runComputation<TInput, TOutput>(def, input): ReckonResult<TOutput>;

Defined in: reckon/register.server.ts:64

Run a computation and return typed outputs + a full replayable manifest.

The compiled environment is cached by definition hash, so repeated runs with different inputs reuse the parsed/topo-sorted CEL expressions.

Type Parameters
Type Parameter Default type Description
TInput extends object Record<string, unknown> The input shape
TOutput Record<string, unknown> The output shape
Parameters
Parameter Type
def ComputationDefinition
input TInput
Returns

ReckonResult<TOutput>

validateDefinition()
validateDefinition(def): ValidationResult;

Defined in: reckon/register.server.ts:51

Validate a computation definition without executing it.

Parameters
Parameter Type
def ComputationDefinition
Returns

ValidationResult

Type Aliases

AuditEntry

type AuditEntry = object;

Defined in: reckon/ops.ts:4

A single audit entry pushed by an op during evaluation.

Properties

Property Type Defined in
audit unknown reckon/ops.ts:4
op string reckon/ops.ts:4

AuditRef

type AuditRef = object;

Defined in: reckon/ops.ts:7

Mutable audit sink — ops push entries here as a side effect.

Properties

Property Type Defined in
sink AuditEntry[] reckon/ops.ts:7

ComputationDefinition

type ComputationDefinition = object;

Defined in: reckon/definition.ts:60

A declarative computation graph.

No input schema is declared — the caller passes any object and optionally types it via the generic <TInput> on runComputation. The engine resolves expr dependencies by walking CEL ASTs, topo-sorts, and evaluates.

Example

const def: ComputationDefinition = {
  id: 'my-pcb-2026',
  tables: {
    pcbTable: {
      kind: 'progressive',
      rows: [
        { max: 5000, rate: 0.0, base: 0 },
        { max: 20000, rate: 0.01, base: 0 },
      ],
    },
  },
  exprs: {
    annualized: 'taxableEarnings * 12',
    pcb: 'round(applyProgressive(annualized, "pcbTable") / 12, "NEAREST_CENT")',
  },
  outputs: ['pcb'],
};

Properties

Property Type Description Defined in
components? Record<string, ComputationComponent> Optional mapping from output expr ids to payslip component metadata. reckon/definition.ts:70
dependsOn? string[] Other computation definition ids whose outputs feed into this one's inputs. reckon/definition.ts:72
exprs Record<string, string> Named CEL expressions. Each expr can reference inputs, other exprs, and registered ops. reckon/definition.ts:66
id string Unique identifier for this definition. reckon/definition.ts:62
outputs string[] Which expr names are exposed as outputs. reckon/definition.ts:68
tables Record<string, InlinedTable> Inlined rate/classification tables, keyed by name. Referenced in exprs via string literals. reckon/definition.ts:64

ComputationManifest

type ComputationManifest = object;

Defined in: reckon/definition.ts:102

Structured, replayable record of a computation run.

Properties

Property Type Description Defined in
computationId string The computation definition id. reckon/definition.ts:104
definitionHash string SHA-256 hash of the canonicalized definition (exprs + inlined tables). reckon/definition.ts:106
inputSnapshot Record<string, unknown> Snapshot of input values — enables replay without live source records. reckon/definition.ts:108
nodes ComputationManifestNode[] One node per named expr, in evaluation order. reckon/definition.ts:110
outputs Record<string, { nodeId: string; value: unknown; }> The declared outputs with their values and source node ids. reckon/definition.ts:112

ComputationManifestNode

type ComputationManifestNode = object;

Defined in: reckon/definition.ts:86

A single node in the computation manifest — one per named expr.

Properties

Property Type Description Defined in
expr string The CEL source string. reckon/definition.ts:90
id string The expr name. reckon/definition.ts:88
inputs Record<string, unknown> Values of referenced identifiers at evaluation time. reckon/definition.ts:92
iterations? object[] Per-iteration traces for fold nodes. Collapsed by default in viewers. reckon/definition.ts:98
opAudit? unknown Structured audit from registered ops (e.g. matched tier, rounding before/after). reckon/definition.ts:96
output unknown The computed result (scalar or list). reckon/definition.ts:94

CustomOp

type CustomOp = object;

Defined in: reckon/cel.server.ts:37

Custom op registered via the engine's public extension API.

Properties

Property Type Defined in
handler (...args) => unknown reckon/cel.server.ts:37
signature string reckon/cel.server.ts:37

InlinedTable

type InlinedTable = 
  | {
  kind: "flat";
  rows: FlatTableRow[];
}
  | {
  kind: "tier";
  rows: TierTableRow[];
}
  | {
  kind: "progressive";
  rows: ProgressiveTableRow[];
}
  | {
  dimensions: MatrixDimension[];
  kind: "matrix";
  rows: FlatTableRow[];
};

Defined in: reckon/definition.ts:26

Rate tables inlined directly into the computation definition. The definition hash covers exprs + tables, so old results always reference the exact table that was used.


OpRegistration

type OpRegistration = object;

Defined in: reckon/ops.ts:13

Spec for registering an op on the CEL environment.

Properties

Property Type Defined in
handler (...args) => unknown reckon/ops.ts:13
signature OpSignature reckon/ops.ts:13

ReckonEnvironment

type ReckonEnvironment = object;

Defined in: reckon/cel.server.ts:22

A compiled CEL environment bound to a specific computation definition.

Properties

Property Modifier Type Defined in
allRefs readonly Map<string, Set<string>> reckon/cel.server.ts:29
auditRef readonly AuditRef reckon/cel.server.ts:32
compiled readonly Map<string, ParseResult> reckon/cel.server.ts:31
definitionHash readonly string reckon/cel.server.ts:30
exprDeps readonly Map<string, Set<string>> reckon/cel.server.ts:28
exprOrder readonly string[] reckon/cel.server.ts:27
exprs readonly Record<string, string> reckon/cel.server.ts:25
id readonly string reckon/cel.server.ts:23
outputs readonly string[] reckon/cel.server.ts:24
scopeRef readonly ScopeRef reckon/cel.server.ts:33
tables readonly Record<string, InlinedTable> reckon/cel.server.ts:26

ReckonResult

type ReckonResult<TOutput> = object;

Defined in: reckon/definition.ts:116

Result of running a computation — typed outputs + full manifest.

Type Parameters

Type Parameter Default type
TOutput Record<string, unknown>

Properties

Property Type Description Defined in
manifest ComputationManifest Full structured manifest for audit and replay. reckon/definition.ts:120
outputs TOutput The declared outputs, typed by the caller via <TOutput>. reckon/definition.ts:118

ReplayResult

type ReplayResult = object;

Defined in: reckon/replay.ts:6

Result of replaying a manifest.

Properties

Property Type Description Defined in
matches boolean Whether the replayed outputs match the manifest's recorded outputs. reckon/replay.ts:10
mismatches? Record<string, { actual: unknown; expected: unknown; }> Per-output comparison (only included when there's a mismatch). reckon/replay.ts:12
outputs Record<string, unknown> The outputs produced by replaying. reckon/replay.ts:8

RoundingMethod

type RoundingMethod = 
  | "NONE"
  | "NEAREST_CENT"
  | "NEAREST_5_CENTS"
  | "TRUNCATE_CENT"
  | "UP_5_CENTS";

Defined in: reckon/definition.ts:82

Rounding modes for the round op.


ValidationError

type ValidationError = object;

Defined in: reckon/definition.ts:124

Validation error for a computation definition.

Properties

Property Type Defined in
expr? string reckon/definition.ts:125
message string reckon/definition.ts:126

ValidationResult

type ValidationResult = 
  | {
  definitionHash: string;
  ok: true;
  order: string[];
}
  | {
  errors: ValidationError[];
  ok: false;
};

Defined in: reckon/definition.ts:130

Result of validating a computation definition.

Functions

createEnvironment()

function createEnvironment(def, customOps?): ReckonEnvironment;

Defined in: reckon/cel.server.ts:47

Create a Reckon environment for a computation definition.

Parses all exprs, extracts dependencies via AST walk, topo-sorts, and registers all ops (scalar + table-aware + fold) with audit/scope side channels.

Parameters

Parameter Type Default value
def ComputationDefinition undefined
customOps CustomOp[] []

Returns

ReckonEnvironment

Throws

on parse errors or dependency cycles


createReckonEngine()

function createReckonEngine(): ReckonEngine;

Defined in: reckon/register.server.ts:90

Create a new Reckon engine instance.

Returns

ReckonEngine


extractIdentifiers()

function extractIdentifiers(ast): Set<string>;

Defined in: reckon/deps.ts:130

Extract all free identifiers from a CEL AST. Returns identifiers that are NOT bound by macros.

Parameters

Parameter Type
ast ASTNode

Returns

Set<string>


hashDefinition()

function hashDefinition(def): string;

Defined in: reckon/hash.ts:13

Parameters

Parameter Type
def ComputationDefinition

Returns

string


partitionDependencies()

function partitionDependencies(identifiers, exprNames): object;

Defined in: reckon/deps.ts:145

Given a set of identifiers, separate them into expr dependencies and other references.

Parameters

Parameter Type Description
identifiers Set<string> All free identifiers from an expr's AST
exprNames Set<string> The set of all expr names in the definition

Returns

object

{ exprDeps, others } where exprDeps are identifiers that match other expr names (topo-sort dependencies), and others are input field references or unknown identifiers.

exprDeps
exprDeps: Set<string>;
others
others: Set<string>;

replayManifest()

function replayManifest(manifest, def): ReplayResult;

Defined in: reckon/replay.ts:35

Replay a computation manifest to verify integrity.

Re-runs the computation using the manifest's inputSnapshot and the provided definition, then compares the outputs to the manifest's recorded outputs. This is the core audit verification — if matches is true, the recorded result is provably correct for the recorded inputs and definition.

The caller must provide the ComputationDefinition that corresponds to the manifest's definitionHash. In production, definitions are stored as DB records keyed by hash, so the caller looks up the def by hash then replays.

Parameters

Parameter Type
manifest ComputationManifest
def ComputationDefinition

Returns

ReplayResult

Example

const result = replayManifest(manifest, storedDefinition);
if (!result.matches) {
  console.error('Audit failure:', result.mismatches);
}

runComputation()

function runComputation<TInput, TOutput>(
   def, 
   input, 
env?): ReckonResult<TOutput>;

Defined in: reckon/runtime.server.ts:30

Execute a computation against an input and produce typed outputs + a full manifest.

If no environment is provided, one is created from the definition (and should be cached by the caller for repeated runs with different inputs). Each expr is evaluated in topo-sorted order. Results accumulate into the scope so dependent exprs can reference them. The audit sink is cleared before each expr and read after to capture structured op audit.

Type Parameters

Type Parameter Default type Description
TInput extends object Record<string, unknown> The input shape (defaults to Record<string, unknown>)
TOutput Record<string, unknown> The output shape (defaults to Record<string, unknown>)

Parameters

Parameter Type
def ComputationDefinition
input TInput
env? ReckonEnvironment

Returns

ReckonResult<TOutput>

Example

const { outputs, manifest } = runComputation<PayrollInput, PayrollOutput>(def, input);
// outputs.netPay: number  (typed by PayrollOutput)
// manifest.nodes: [{ id: 'pcb', expr: '...', inputs: {...}, output: 416.67, opAudit: {...} }]

runComputationWithEnv()

function runComputationWithEnv<TInput, TOutput>(env, input): ReckonResult<TOutput>;

Defined in: reckon/runtime.server.ts:39

Execute using a pre-created environment (avoids re-parsing for repeated runs).

Type Parameters

Type Parameter Default type
TInput extends object Record<string, unknown>
TOutput Record<string, unknown>

Parameters

Parameter Type
env ReckonEnvironment
input TInput

Returns

ReckonResult<TOutput>


topoSort()

function topoSort(exprs): string[];

Defined in: reckon/deps.ts:179

Topologically sort expr names by their dependencies.

Parameters

Parameter Type Description
exprs Map<string, Set<string>> Map of expr name → set of expr names it depends on

Returns

string[]

Evaluation order (dependencies first)

Throws

if a cycle is detected


validateDefinition()

function validateDefinition(def, customOps?): ValidationResult;

Defined in: reckon/cel.server.ts:120

Validate a computation definition without executing it.

Checks:

  1. All exprs parse as valid CEL
  2. No dependency cycles
  3. All declared outputs exist as exprs

Parameters

Parameter Type Default value
def ComputationDefinition undefined
customOps CustomOp[] []

Returns

ValidationResult