/** Source-neutral contracts for building a fresh projection generation. */ interface SourcePosition { /** Stable logical stream identifier. */ source: string; /** Continuity epoch. Cursors from different epochs are never comparable. */ epoch: string; /** Opaque cursor interpreted only by the source adapter. */ cursor: string; } interface SourceSemantics { ordinaryRecords: boolean; ordinaryDeletes: boolean; accountLifecycle: boolean; repositoryReplacement: boolean; verifiedCommits: boolean; explicitHead: boolean; } type CollectionCoverage = { state: "complete"; } | { state: "partial"; reason: string; unresolved?: number; } | { state: "gap"; reason: string; }; interface SnapshotRecord { uri: string; did: string; collection: string; rkey: string; cid: string; value: unknown; } interface PreparedSnapshot { /** Provider-owned immutable snapshot identifier. */ id: string; provider: string; consistency: "sampled-current-state" | "point-in-time"; collections: Record; semantics: SourceSemantics; /** Upstream position represented by a point-in-time snapshot, when known. */ through?: SourcePosition; /** Bounded plain-JSON provider descriptor needed to resume this exact pinned * snapshot and its matching change stream after process restart. */ providerData?: unknown; } interface SnapshotProgress { /** Stable provider-owned partition, such as one collection/repository pair. */ partition: string; /** Opaque resume token within this partition, or null once complete. */ cursor: string | null; complete: boolean; } interface SnapshotBatch { records: SnapshotRecord[]; /** Source observation time for ordering snapshot rows against later changes. */ sourceTimeUs: number; /** Progress for the partition represented by this batch. */ progress: SnapshotProgress; /** True only after every requested snapshot partition has completed. */ done: boolean; } interface SnapshotSource { readonly id: string; /** Prepare and pin a snapshot. Record acquisition must not begin before this * call; the bootstrap coordinator marks the change source first. */ prepare(options: { collections: string[]; signal?: AbortSignal; }): Promise; read(options: { snapshot: PreparedSnapshot; progress?: SnapshotProgress[]; signal?: AbortSignal; }): AsyncIterable; } interface MutationBase { uri: string; did: string; collection: string; rkey: string; revision?: string; sourceTimeUs: number; /** Per-event position when the source exposes one. */ position?: SourcePosition; } type SourceMutation = (MutationBase & { operation: "put"; cid: string; value: unknown; }) | (MutationBase & { operation: "delete"; }); interface MutationBatch { mutations: SourceMutation[]; /** Everything through this position has been accounted for, including * filtered events and an otherwise empty batch. */ checkpoint: SourcePosition; /** True when the requested through-position has been reached exactly. */ caughtUp: boolean; } interface ChangeSource { readonly id: string; readonly semantics: SourceSemantics; /** Return a durable replay coordinate near the current source head. */ mark(options: { collections: string[]; /** Exact prepared descriptor when selecting the post-snapshot catch-up * boundary. The preliminary capture mark has no snapshot yet. */ snapshot?: PreparedSnapshot; signal?: AbortSignal; }): Promise; read(options: { collections: string[]; /** Exact prepared source descriptor paired with this replay. Sources that * do not need provider context may ignore it. */ snapshot?: PreparedSnapshot; after: SourcePosition; through: SourcePosition; signal?: AbortSignal; }): AsyncIterable; } type BootstrapPhase = "preparing" | "snapshot" | "catchup" | "complete"; /** Durable coordinator state. Snapshot progress and mutation checkpoints are * separate because they belong to different cursor namespaces. */ interface BootstrapRunState { phase: BootstrapPhase; snapshot: PreparedSnapshot | null; captureFrom: SourcePosition; snapshotProgress: SnapshotProgress[]; snapshotComplete: boolean; catchupThrough: SourcePosition | null; changeCheckpoint: SourcePosition | null; } /** Projection-owned persistence seam. Implementations commit records and the * accompanying progress/checkpoint atomically in the destination database. */ type BootstrapFailureCategory = "snapshot-incomplete" | "catchup-incomplete" | "source-history-expired" | "verification-failed" | "bootstrap-failed"; interface BootstrapTarget { load(): Promise; /** Persist the capture boundary before snapshot preparation performs network work. */ beginCapture(captureFrom: SourcePosition): Promise; /** Pin the prepared snapshot, optionally replacing capture with its own boundary. */ setSnapshot(snapshot: PreparedSnapshot, captureFrom: SourcePosition): Promise; applySnapshotBatch(snapshot: PreparedSnapshot, batch: SnapshotBatch): Promise; beginCatchup(through: SourcePosition): Promise; applyMutationBatch(batch: MutationBatch): Promise; complete(): Promise; /** Persist only a bounded category; raw upstream errors stay private. */ recordFailure?(category: BootstrapFailureCategory): Promise; } interface BootstrapResult { snapshot: PreparedSnapshot; captureFrom: SourcePosition; through: SourcePosition; } declare function bootstrapFreshProjection(options: { collections: string[]; snapshotSource: SnapshotSource; changeSource: ChangeSource; target: BootstrapTarget; allowPartial?: boolean; requiredSemantics?: Partial; signal?: AbortSignal; }): Promise; export { type BootstrapFailureCategory as B, type ChangeSource as C, type MutationBatch as M, type PreparedSnapshot as P, type SourcePosition as S, type SnapshotSource as a, type SnapshotProgress as b, type SnapshotBatch as c, type SourceSemantics as d, type BootstrapTarget as e, type BootstrapRunState as f, type BootstrapPhase as g, type BootstrapResult as h, type CollectionCoverage as i, type SnapshotRecord as j, type SourceMutation as k, bootstrapFreshProjection as l };