import { ZodType } from 'zod'; import { BlueNode, Blue } from '@blue-labs/language'; import { ScopeContractsIndex } from '../types/scope-contracts.js'; import { JsonPatch } from '../model/shared/json-patch.js'; import { MarkerContract } from '../model/index.js'; import { ChannelContractEntry } from '../types/channel-contract-entry.js'; import { GasMeter } from '../runtime/gas-meter.js'; export type ContractProcessorKind = 'handler' | 'channel' | 'marker'; export interface ContractProcessor { readonly kind: ContractProcessorKind; readonly blueIds: readonly string[]; readonly schema: ZodType; } export interface ContractProcessorContext { readonly scopePath: string; readonly blue: Blue; event(): BlueNode | null; applyPatch(patch: JsonPatch): Promise; emitEvent(emission: BlueNode): void; consumeGas(units: number): void; gasMeter(): GasMeter; throwFatal(reason: string): never; resolvePointer(relativePointer: string): string; documentAt(absolutePointer: string): BlueNode | null; documentContains(absolutePointer: string): boolean; terminateGracefully(reason: string | null): Promise; terminateFatally(reason: string | null): Promise; } export interface HandlerExecutionMetadata { readonly contractKey: string; readonly contractNode: BlueNode; } export interface HandlerProcessor extends ContractProcessor { readonly kind: 'handler'; /** * Optional sync hook to compute channel key when contract omitted it. */ deriveChannel?(contract: TContract, deps: { blue: Blue; scopeContracts: ScopeContractsIndex; }): string | null | undefined; /** * Optional guard to determine whether the handler should execute * for the provided event within the current context. */ matches?(contract: TContract, context: ContractProcessorContext): boolean | Promise; execute(contract: TContract, context: ContractProcessorContext, metadata?: HandlerExecutionMetadata): void | Promise; } export interface ChannelEvaluationContext { readonly scopePath: string; readonly blue: Blue; /** * Mutable clone of the inbound event. Channel processors may adapt it in-place. */ readonly event: BlueNode | null; readonly markers: ReadonlyMap; /** * Key assigned to the contract within the scope's contract map. */ readonly bindingKey: string; /** * Optional resolver for channel contracts within the same scope. */ readonly resolveChannel?: (key: string) => ChannelContractEntry | null; /** * Optional lookup for channel processors by node. */ readonly channelProcessorFor?: (node: BlueNode) => ChannelProcessor | null; } export interface ChannelDelivery { readonly eventNode: BlueNode; readonly eventId?: string | null; readonly checkpointKey?: string | null; readonly shouldProcess?: boolean; } export interface ChannelMatch { readonly matches: boolean; readonly eventId?: string | null; readonly eventNode?: BlueNode | null; readonly deliveries?: readonly ChannelDelivery[]; } export interface ChannelProcessor extends ContractProcessor { readonly kind: 'channel'; matches(contract: TContract, context: ChannelEvaluationContext): boolean | Promise; /** * Optional: Provide a channelized event for handlers without mutating the inbound event. * When provided, the engine will deliver this node to handlers while computing * checkpoint signatures and storage from the original external event. */ channelize?(contract: TContract, context: ChannelEvaluationContext): BlueNode | null | undefined; /** * Optional: Provide custom evaluation details, including multi-delivery * channel matches. */ evaluate?(contract: TContract, context: ChannelEvaluationContext): ChannelMatch | Promise; /** * Optional: Determine whether an event should be processed relative to the * last checkpointed event for this channel. */ isNewerEvent?(contract: TContract, context: ChannelEvaluationContext, lastEvent: BlueNode): boolean | Promise; } export interface MarkerProcessor extends ContractProcessor { readonly kind: 'marker'; } export type AnyContractProcessor = HandlerProcessor | ChannelProcessor | MarkerProcessor; //# sourceMappingURL=types.d.ts.map