import type { Schema, Infer } from '../schema/types.js'; import type { DB } from '../db/namespace.js'; import type { DecisionOutcome } from './decision.js'; /** * The two valve forms. A `handoff` moves a payload across a silo / ownership * boundary; a `transition-gate` modulates a state change within one silo. */ export type ValveKind = 'handoff' | 'transition-gate'; /** * Directional producer -> consumer topology. For a transition gate the * producer and consumer silo coincide — the crossing is an intra-silo edge. */ export interface ValveTopology { readonly producer: string; readonly consumer: string; } /** * A registered valve. The builders (`supply`, `gate`, `faucet`) produce * concrete definitions assignable to this base; the registry stores them * keyed by `name`, and the valve graph is assembled from their topology. */ export interface ValveDefinition { readonly name: string; readonly kind: ValveKind; readonly topology: ValveTopology; } /** * A handoff trigger — either a source state transition (`status: open -> frozen`) * or an explicit push. */ export type HandoffTrigger = { readonly on: string; readonly from: string; readonly to: string; } | { readonly push: true; }; /** * How a crossing executes — synchronously in the caller's transaction, or as a * durable retried job that dead-letters on retry exhaustion. */ export type CrossingMode = { readonly durable: false; } | { readonly durable: true; readonly retry: 'backoff' | 'fixed'; }; /** A contract shape — payload field name -> validation schema. */ export type ContractShape = Record; /** The payload type a contract shape validates to. */ export type ContractPayload = { readonly [K in keyof TShape]: Infer; }; /** * A handoff valve, produced by `supply(...).to(...)`. Carries the full anatomy * the crossing executor and the valve graph read back. */ export interface SupplyDefinition extends ValveDefinition { readonly kind: 'handoff'; readonly source: string; readonly trigger: HandoffTrigger; readonly contract: ContractShape; readonly guard: ((row: TSource) => boolean) | undefined; readonly project: (row: TSource) => TPayload; readonly invariants: readonly string[]; readonly lineageField: string | undefined; readonly idempotentBy: ((row: TSource) => string) | undefined; readonly crossing: CrossingMode; } /** * A transition-gate trigger. A gate fires on admission of a source row, on the * birth of a new instance version, or by an explicit operator action — the * manual trigger carrying a permission and batch semantics. */ export type GateTrigger = { readonly trigger: 'admission'; } | { readonly trigger: 'new-version'; } | { readonly trigger: 'manual'; readonly permission: string; readonly batch: boolean; }; /** Retraction config — which trigger supersedes and invalidates the prior crossing. */ export interface GateRetraction { readonly on: 'new-version'; } /** * The decision hook — the load-bearing seam (#307 field 13). Async, and returns * a partitioned outcome (`cross` / `held` / `failed`) — never a bare verdict. */ export type GateDecision = (event: TEvent, context: Readonly>) => Promise>; /** * A transition-gate valve, produced by `gate(...).decision(...)`. Its producer * and consumer silo coincide — it modulates an intra-silo state change. */ export interface GateDefinition extends ValveDefinition { readonly kind: 'transition-gate'; readonly source: string; readonly triggers: readonly GateTrigger[]; readonly context: Readonly>; readonly signals: readonly string[]; readonly fanOut: ((event: TEvent) => readonly unknown[]) | undefined; readonly decision: GateDecision; readonly retraction: GateRetraction | undefined; } /** * A faucet's intake handler — receives the re-validated payload and the * transaction the crossing runs in, and lands the payload in the consumer. */ export type FaucetHandler = (payload: TPayload, tx: DB) => Promise; /** * A faucet — the consumer side of a `supply -> faucet` edge. It binds to a * valve by name (never to the producer silo) and re-validates every payload. */ export interface FaucetDefinition { readonly valve: string; readonly target: string; readonly handler: FaucetHandler; } /** The crossing proceeded — `payload` was delivered. */ export interface CrossedResult { readonly kind: 'crossed'; readonly payload: unknown; } /** A handoff guard rejected the row — nothing crossed. */ export interface BlockedResult { readonly kind: 'blocked'; } /** A gate held the crossing in a provisional, reviewable state. */ export interface HeldResult { readonly kind: 'held'; readonly reason: unknown; } /** A gate's decision evaluation failed. */ export interface FailedResult { readonly kind: 'failed'; readonly error: Error; } /** A keyed crossing was replayed — its prior `crossed` outcome already landed. */ export interface SkippedResult { readonly kind: 'skipped'; } /** A handoff crossing resolves as crossed or blocked. */ export type SupplyCrossingResult = CrossedResult | BlockedResult; /** A transition-gate crossing resolves as crossed, held, or failed. */ export type GateCrossingResult = CrossedResult | HeldResult | FailedResult; /** Any crossing outcome — the recorded layer additionally yields `skipped`. */ export type CrossingResult = CrossedResult | BlockedResult | HeldResult | FailedResult | SkippedResult; //# sourceMappingURL=types.d.ts.map