import { r as WirestatePlugin, t as Container } from "./lib.js"; /** * Configuration for {@link DevToolsPlugin}. * * @group DevTools */ interface DevToolsPluginOptions { /** * Optional human label for this root, shown by the inspector to tell it apart from other roots on * the page (a root is otherwise identified only by a numeric id). When omitted, a consumer may * derive a hint from the root's contents instead. */ readonly label?: string; } /** * Read-only observer plugin that exposes a container subtree to an inspector * backend (a Chrome extension or a standalone dev panel). * * @group DevTools * * @example * ```typescript * import { Container, type WirestatePlugin } from "@wirestate/core"; * import { DevToolsPlugin } from "@wirestate/core/devtools"; * * const plugins: Array = process.env.NODE_ENV === "production" ? [] : [new DevToolsPlugin()]; * * new Container({ plugins }); * ``` */ declare class DevToolsPlugin implements WirestatePlugin { private hook; /** * Root id every delta of this plugin is tagged with. * * @remarks * `0` only until the first registration, and never reset afterwards. Teardown keeps emitting * after the root is deregistered - `container.destroy()` deactivates instances once the * container already deprovisioned - and a consumer filters the delta stream by root id, so a * delta that dropped back to `0` would belong to no root and never reach a panel. Holding the * last id keeps those final deltas attributable to the root that produced them. */ private rootId; /** * Whether {@link DevToolsPlugin.rootId} is currently registered on the hook. * * @remarks * Tracked apart from the id, which outlives the registration. */ private registered; /** * Currently-provisioned (live) containers, keyed by id for dedupe and held weakly so * the plugin never extends a container's lifetime. Populated on provision, drained on * deprovision. Dead entries are pruned lazily on snapshot as a backstop. */ private readonly observed; /** * Optional human label for this root, surfaced in the snapshot. See {@link DevToolsPluginOptions.label}. */ private readonly label; /** * Lifecycle deltas produced before the root first registered. * * @remarks * A container activates services at construction, before any provider mounts it, and a root only * registers once a container provisions. Those early deltas are held here and flushed under the * root id at registration, so the timeline still starts at the first activation. A container that * is never provisioned takes them down with the plugin instead of leaving a root behind. */ private readonly pending; /** * @param options - Optional plugin options (see {@link DevToolsPluginOptions}). */ constructor(options?: DevToolsPluginOptions); install(): void; onContainerProvision(container: Container): void; onContainerDeprovision(container: Container): void; /** * Registers this plugin's root on the hook unless one is already registered. * Exactly one root per plugin instance at a time. */ private ensureRoot; /** * Deregisters this plugin's root once its last observed container has deprovisioned. * This drops the root from snapshots and releases the registration the hook held, so repeated HMR cycles (unload a * root, mount a fresh one) don't accumulate empty roots over a long dev session. */ private releaseRoot; onActivate(instance: object, container: Container): void; onDeactivate(instance: object, container: Container): void; onProvision(instance: object, container: Container): void; onDeprovision(instance: object, container: Container): void; /** * Emits one lifecycle delta to the hook. * * @param container - Container the phase fired on. * @param phase - Lifecycle phase being reported. * @param instance - The instance involved, for instance-level phases. */ private report; /** * Taps the container's messaging buses so dispatches and handler registrations flow to * the hook (idempotent). * * @param container - Container being provisioned. */ private tapMessages; /** * Adds a provisioned container to the live set so it appears in snapshots. * * @param container - Container that completed provision. */ private observe; /** * Removes a container from the live set when it deprovisions, so a torn-down or discarded container drops out of * snapshots immediately. * * @param container - Container that completed deprovision. */ private unobserve; /** * Snapshots every still-live observed container, pruning any the app has dropped. * * @returns The root snapshot. */ private snapshot; /** * Snapshots one container's bindings and active instances. * * @param container - Container to snapshot. * @returns The container snapshot. */ private snapshotContainer; /** * Reads the raw live value at `path` within the instance identified by `instanceId`, scanning the observed containers' * active instances. It never mutates application state. * * @param instanceId - Instance to read from. * @param path - Object keys / array indices from the instance to the value. * @returns The raw value, or `undefined` when the instance is not (or no longer) live. */ private inspect; /** * Reads the raw value at `path` within the `Value` binding identified by `bindingId`, scanning the observed * containers' own bindings. It reads the stored value directly and never resolves or constructs a service, so it is * side-effect-free and works even before the binding is first resolved. Only `Value` bindings are addressable here. * An `Instance` or `Factory` binding's id never matches. * * @param bindingId - Binding to read from. * @param path - Object keys / array indices from the binding's value to the target. * @returns The raw value at the path, or `undefined` when no live `Value` binding has that id. */ private inspectBinding; /** * If `value` is one of this root's tracked active instances, returns a reference to it (so the * inspector can mark a field that points at another service and offer a jump). Otherwise `undefined`. * * @param value - Raw value at an inspected field. * @returns A service reference, or `undefined`. */ private serviceRefOf; } export { DevToolsPlugin, type DevToolsPluginOptions };