import { Applog, ApplogForInsert } from '../applog/datom-types.ts'; import { Thread, ThreadEvent } from './basic.ts'; /** Delta event — only incremental changes (no init) */ export type DeltaEvent = { added: readonly Applog[]; removed: readonly Applog[] | null; }; /** Context passed to mapDelta — explicit deps, no `this` needed */ export interface DeltaContext { /** The parent thread that emitted the delta */ source: Thread; /** All current parent threads */ parents: readonly Thread[]; /** The mapped thread's output before this delta is applied */ state: readonly Applog[]; } /** * Derivation for a MappedThread — separates full recomputation from incremental updates. * * - `compute` produces full state from parents (construction, reset, parent reinit) * - `mapDelta` transforms a parent's incremental delta (optional — falls back to compute) */ export interface ThreadDerivation { /** Compute full state from parents. Called at construction, triggerRemap, and parent reinit. */ compute(parents: readonly Thread[]): Applog[]; /** * Transform an incremental delta from a parent. * Return null to fall back to full recompute via compute(). * Optional — if omitted, every parent change triggers compute(). */ mapDelta?: (delta: DeltaEvent, ctx: DeltaContext) => DeltaEvent | null; } export type ApplogWriteMapper = (this: MappedThread, applogs: Applog[] | ApplogForInsert[]) => Applog[] | ApplogForInsert[] | null; export declare class MappedThread extends Thread { readonly name: string; private _derivation; private _writeMapper; private _readOnly?; static mapWrites(parent: Thread, name: string, mapper: ApplogWriteMapper): MappedThread; static asReadOnly(parent: Thread): Thread; private _parentSubscriptions; constructor(name: string, parents: Thread | readonly Thread[], filters: readonly string[], _derivation: ThreadDerivation | null, _writeMapper?: ApplogWriteMapper, _readOnly?: boolean); insert(appLogsToInsert: ApplogForInsert[]): void; insertRaw(appLogsToInsert: Applog[]): void; private subscribeToParents; /** Tear down parent subscriptions and clear internal state */ dispose(): void; /** Swap parents at runtime — re-subscribes and recomputes applogs, notifying downstream */ setParents(newParents: readonly Thread[]): void; subscribe(callback: (event: ThreadEvent) => void, type?: 'derived' | 'reaction'): () => void; /** Recompute full state from parents via compute() */ triggerRemap(): void; protected onParentUpdate(sourceThread: Thread, event: ThreadEvent): void; get readOnly(): boolean; } //# sourceMappingURL=mapped.d.ts.map