import { z } from 'zod'; import type { ObjectStoreWriter } from './objectStore.ts'; import type { ProjectionPosition } from './projection.ts'; import type { ProjectionPublicationObject, PublishedProjection, PublishedProjectionScope, PublishedProjectionSource } from './projectionPublication.ts'; export declare const ProjectionReplayCheckpointSchema: "network.xyo.dapp.projection.replay.checkpoint" & { readonly __schema: true; }; /** * The durable watermark the engine persists after a verified head advance. It * names the exact finalized position covered, the floor the replay started * from, and the last indexed block, so a fresh incarnation resumes from * finalized state rather than re-deriving blindly. */ export declare const ProjectionReplayCheckpointZod: z.ZodObject<{ generationId: z.ZodString; cursor: z.ZodObject<{ blockNumber: z.ZodNumber; blockHash: z.ZodString; transactionIndex: z.ZodNumber; transactionHash: z.ZodString; payloadIndex: z.ZodNumber; payloadHash: z.ZodString; recordIndex: z.ZodNumber; }, z.core.$strict>; floorBlock: z.ZodNumber; lastIndexedBlock: z.ZodNumber; dappId: z.ZodString; chainId: z.ZodString; projectionId: z.ZodString; projectionVersion: z.ZodString; schema: z.ZodLiteral<"network.xyo.dapp.projection.replay.checkpoint" & { readonly __schema: true; }>; schemaVersion: z.ZodLiteral<1>; }, z.core.$strict>; export type ProjectionReplayCheckpoint = z.infer; /** One finalized input, tagged with the canonical position that orders it. */ export interface ReplayRecord { readonly position: ProjectionPosition; readonly value: TRecord; } /** * A finalized-only forward source. `latest` reports the finalized position * through which the next read can prove coverage; `readAfter` returns every * finalized record strictly after the cursor through that position, in * canonical order. An empty result therefore proves that the entire range is * records-free. Both read finalized state alone — a replay must never observe * an unfinalized block. */ export interface FinalizedReplaySource { latest(): Promise; readAfter(cursor: ProjectionPosition | undefined): Promise[]>; } /** The immutable objects and provenance a reducer emits for one generation. */ export interface ProjectionReducerGeneration { readonly objects: readonly ProjectionPublicationObject[]; readonly source?: PublishedProjectionSource; } /** * The application-owned deterministic fold. The engine owns replay, checkpoint, * head-last publication, and rebuild; the reducer owns only what the state is, * how a record changes it, and how it materializes into published objects. It * must be a pure function of the finalized input: the same records always fold * to the same state and the same generation objects. */ export interface ProjectionReducer { readonly initialState: TState; deserialize(body: Uint8Array): TState; materialize(state: TState, target: ProjectionPosition): ProjectionReducerGeneration; reduce(state: TState, record: ReplayRecord): TState; /** Serialize the resumable state so a later incarnation can rehydrate it. */ serialize(state: TState): string; } export interface ProjectionReplayProgress { readonly finalizedHead: number; readonly lag: number; readonly processed: number; readonly target: number; } export type ProjectionReplayStatus = 'advanced' | 'idle'; export interface ProjectionReplayResult { readonly checkpoint?: ProjectionReplayCheckpoint; readonly generationId?: string; readonly head?: PublishedProjection; readonly progress: ProjectionReplayProgress; readonly status: ProjectionReplayStatus; } export interface ProjectionReplayEngineOptions { readonly checkpointKey: string; readonly checkpointStoreId: string; readonly floorBlock: number; /** Deterministic generation identity from the covered position. */ readonly generationId: (target: ProjectionPosition) => string; readonly headStoreId: string; readonly reducer: ProjectionReducer; readonly scope: PublishedProjectionScope; readonly source: FinalizedReplaySource; /** Reserved logical key for the resumable serialized state. */ readonly stateKey?: string; /** Store the resumable state lands in; defaults to the head store. */ readonly stateStoreId?: string; readonly stores: Readonly>; } export declare class ProjectionReplayError extends Error { readonly kind: string; constructor(kind: string, message: string); } /** * The productized finalized-replay projection engine (use case UC-05). * * It resumes from a durable checkpoint, folds finalized records forward through * a caller-supplied deterministic reducer, writes an immutable generation, and * advances the published head last. A crash between the generation write and * the head advance leaves the new generation invisible: the next incarnation * re-derives from the checkpoint and reproduces it. Deleting the head and * checkpoint and rebuilding reproduces the identical head from finalized input * alone, because both replay and reduction are pure functions of that input. * * The engine performs no chain, datalake, or filesystem I/O itself. Its only * effects run through the injected finalized source and object stores, so the * same neutral engine drives a local filesystem projection or a hosted * object-store projection without change. */ export declare class ProjectionReplayEngine { #private; constructor(options: ProjectionReplayEngineOptions); /** * Advance the projection to the current finalized head, publishing at most one * new generation. A records-free range publishes a deterministic no-state- * change generation at its covered position so the durable cursor can advance. * Returns `idle` only when the published head already covers the finalized * input and no new records exist. */ advance(signal?: AbortSignal): Promise; readCheckpoint(): Promise; /** * Delete the published head and durable checkpoint, then rebuild from the * floor. Immutable generation objects that already exist are rewritten with * identical bytes, and the reproduced head is byte-for-byte identical to the * head this projection last advanced to. */ rebuild(signal?: AbortSignal): Promise; } //# sourceMappingURL=projectionReplay.d.ts.map