/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * TrackedChannelStore — shared base for the `Func.bind` / `Record.bind` * runtimes. Both expose one tracked channel per `(workspace, name)`: a * latest-wins async operation whose settling state is gated by a monotonic * `launchSeq`, plus a per-key reactive subscription shim that the renderer's * `Reactive.Root` machinery reads through (the same contract the dataset * cache uses). * * Subclasses supply their own API seam, per-channel entry shape, and the * operation body; the base owns the entries map, the tracking context, the * subscription shim, and the launch / settle / cancel latch. * * @packageDocumentation */ /** The minimal per-channel state the base manages. */ export interface ChannelEntry { /** Lifecycle tag — at least `"idle"` | `"running"` | `"cancelled"`, plus * whatever terminal states the subclass adds. */ status: string; /** Monotonic launch counter; a settling op whose seq is no longer current * is discarded (latest-wins, and `cancel` orphans by bumping it). */ launchSeq: number; } /** * Base for a runtime that manages latest-wins channels keyed by string, with * per-key reactive subscriptions. * * @typeParam E - The per-channel entry type (extends {@link ChannelEntry}). */ export declare abstract class TrackedChannelStore { protected readonly entries: Map; private readonly keySubscribers; private readonly keyVersions; private trackingContext; /** Build a fresh channel entry in its initial (idle) state. */ protected abstract createEntry(): E; /** * Start recording the channels an evaluation reads. * * @returns What it records: each channel read, with its version as first read */ enableTracking(): ReadonlyMap; /** * Stop recording. * * @returns Each channel the evaluation read, with its version as it first read it — a channel a launch it made * notified since stands at another */ disableTracking(): ReadonlyMap; isTracking(): boolean; /** Whether the CURRENT evaluation has already read this channel. A cache * that evicts by least-recently-read must never drop one of these: a read * pass longer than the cache would otherwise evict its own head, and the * next pass would find it gone (#581). */ protected isTracked(key: string): boolean; /** Record a channel-key dependency for the current render, at its version * as it is read now unless the render read it before (no-op when not * tracking). */ protected track(key: string): void; subscribe(key: string, callback: () => void): () => void; getKeyVersion(key: string): number; /** How many channels' versions the store keeps: what a spec holds its bounds to, beside its channels. */ protected versionsKept(): number; /** * Let a channel's version go, once nothing subscribes to it: a channel a * subclass let go is versioned no longer, so the versions kept are those * of the channels it holds and those a reader subscribes to. A reader * still subscribed keeps the version it read until it lets the channel go. * * @param key - The channel */ protected forgetVersion(key: string): void; /** Whether anything is subscribed to a channel. */ protected isSubscribed(key: string): boolean; /** * Called as a channel's last subscriber leaves, synchronously — a * subclass that holds something for the channel's readers can let it go. * A reader re-subscribing drops its subscriptions first (a tracked read's * run, React's), so what is let go should be let go only if the channel * is still unsubscribed once that is done. * * @param _key - The channel */ protected unsubscribed(_key: string): void; protected notify(key: string): void; /** * Notify several channels as one (#1360): every channel's version moves * first, then each subscriber is called once, however many of the * channels it reads — a reader of a window's fifty-five searches runs * again once as they land together, not once a search. * * @param keys - The channels */ protected notifyAll(keys: Iterable): void; protected entry(key: string): E; /** * Open a latest-wins launch on a channel: bump the seq, mark the entry * `running`, optionally `reset` it (e.g. clear a prior error), notify, and * return a `settle` that applies a terminal mutation only if this launch is * still the current one (a superseded / cancelled launch settles to a * no-op). */ protected beginLaunch(key: string, reset?: (entry: E) => void): { entry: E; settle: (mutate: (entry: E) => void) => void; }; /** * Client-side cancel: if the channel is running, orphan the in-flight wait * (bump the seq) and mark it `cancelled`. `after` runs before the notify, * for subclass-specific cleanup (e.g. dropping an in-flight handle). */ protected cancelChannel(key: string, after?: (entry: E) => void): void; /** Drop all channel state (entries + subscriptions + versions). */ protected clearChannels(): void; } //# sourceMappingURL=tracked-channel.d.ts.map