import { AuditEntry, AuditLedger, QueryFilter, SingleModuleSystem, ModuleSchema, InferSelectorState, HistoryState, ModuleDef, Plugin, TraceOption, ErrorBoundaryConfig, InferFacts, InferDerivations, createRequirementStatusPlugin, InferEvents, ModulesMap, NamespacedSystem, RequirementTypeStatus, CreateSystemOptionsSingle } from '@directive-run/core'; export { RequirementTypeStatus } from '@directive-run/core'; import { ConstraintInfo, InspectState } from '@directive-run/core/adapter-utils'; export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils'; import { ReactiveController, ReactiveControllerHost } from 'lit'; /** * Lit Adapter - Consolidated Web Components integration for Directive * * Controllers: DerivedController, FactController, * InspectController (with throttle), RequirementStatusController, * DirectiveSelectorController, * WatchController (with fact mode), SystemController, * ExplainController, ConstraintStatusController, OptimisticUpdateController, ModuleController * * Factories: createDerived, createFact, createInspect, * createRequirementStatus, createWatch, * createDirectiveSelector, useDispatch, useEvents, useHistory, * getDerived, getFact, createTypedHooks, shallowEqual */ /** Type for the requirement status plugin return value */ type StatusPlugin = ReturnType; /** * Context key for Directive system. * Use with @lit/context for dependency injection across shadow DOM boundaries. */ declare const directiveContext: unique symbol; /** * Base controller that manages system subscription lifecycle. */ declare abstract class DirectiveController implements ReactiveController { protected host: ReactiveControllerHost; protected system: SingleModuleSystem; protected unsubscribe?: () => void; constructor(host: ReactiveControllerHost, system: SingleModuleSystem); hostConnected(): void; hostDisconnected(): void; protected abstract subscribe(): void; protected requestUpdate(): void; } /** * Reactive controller for derivations. * Accepts a single key (string) or an array of keys (string[]). * - Single key: `.value` returns `T` * - Array of keys: `.value` returns `Record` */ declare class DerivedController extends DirectiveController { private keys; private isMulti; value: T; constructor(host: ReactiveControllerHost, system: SingleModuleSystem, key: string | string[]); private getValues; protected subscribe(): void; } /** * Reactive controller for a single fact value. */ declare class FactController extends DirectiveController { private factKey; value: T | undefined; constructor(host: ReactiveControllerHost, system: SingleModuleSystem, factKey: string); protected subscribe(): void; } /** * Consolidated inspection controller. * Returns InspectState with optional throttling. */ declare class InspectController extends DirectiveController { value: InspectState; private throttleMs; private throttleCleanup?; private unsubSettled?; constructor(host: ReactiveControllerHost, system: SingleModuleSystem, options?: { throttleMs?: number; }); protected subscribe(): void; hostDisconnected(): void; } /** * Reactive controller for requirement status. */ declare class RequirementStatusController implements ReactiveController { private host; private statusPlugin; private type; private unsubscribe?; value: RequirementTypeStatus; constructor(host: ReactiveControllerHost, statusPlugin: StatusPlugin, type: string); hostConnected(): void; hostDisconnected(): void; } /** * Reactive controller for selecting across all facts. * Uses `withTracking()` for auto-tracking when constructed with `autoTrack: true`. */ declare class DirectiveSelectorController extends DirectiveController { private selector; private equalityFn; private autoTrack; private deriveKeySet; private trackedFactKeys; private trackedDeriveKeys; private unsubs; value: R; constructor(host: ReactiveControllerHost, system: SingleModuleSystem, selector: (state: InferSelectorState) => R, equalityFn?: (a: R, b: R) => boolean, options?: { autoTrack?: boolean; }); private runWithTracking; private resubscribe; protected subscribe(): void; hostDisconnected(): void; } /** * Reactive controller that watches a fact or derivation and calls a callback on change. * The key is auto-detected — works with both fact keys and derivation keys. */ declare class WatchController extends DirectiveController { private key; private callback; /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */ constructor(host: ReactiveControllerHost, system: SingleModuleSystem, key: string, callback: (newValue: T, previousValue: T | undefined) => void); protected subscribe(): void; } /** * Reactive controller for requirement explanations. */ declare class ExplainController extends DirectiveController { private requirementId; value: string | null; private unsubSettled?; constructor(host: ReactiveControllerHost, system: SingleModuleSystem, requirementId: string); protected subscribe(): void; hostDisconnected(): void; } /** * Reactive controller for constraint status. */ declare class ConstraintStatusController extends DirectiveController { private constraintId?; value: ConstraintInfo[] | ConstraintInfo | null; private unsubSettled?; constructor(host: ReactiveControllerHost, system: SingleModuleSystem, constraintId?: string); private getVal; protected subscribe(): void; hostDisconnected(): void; } /** * Reactive controller for optimistic updates. */ declare class OptimisticUpdateController implements ReactiveController { private host; private system; private statusPlugin?; private requirementType?; private snapshot; private statusUnsub; isPending: boolean; error: Error | null; constructor(host: ReactiveControllerHost, system: SingleModuleSystem, statusPlugin?: StatusPlugin, requirementType?: string); hostConnected(): void; hostDisconnected(): void; rollback(): void; mutate(updateFn: () => void): void; } /** * Reactive controller that creates and manages a Directive system. * The system is automatically started when the host connects and destroyed when it disconnects. */ declare class SystemController implements ReactiveController { private options; private _system; constructor(host: ReactiveControllerHost, options: ModuleDef | CreateSystemOptionsSingle); get system(): SingleModuleSystem; hostConnected(): void; hostDisconnected(): void; } /** * Module controller — zero-config all-in-one. * Creates system, starts it, subscribes to all facts/derivations. */ declare class ModuleController implements ReactiveController { private host; private moduleDef; private config?; private _system; private unsubFacts?; private unsubDerived?; facts: InferFacts; derived: InferDerivations; statusPlugin?: StatusPlugin; get system(): SingleModuleSystem; get events(): SingleModuleSystem["events"]; constructor(host: ReactiveControllerHost, moduleDef: ModuleDef, config?: { plugins?: Plugin[]; trace?: TraceOption; errorBoundary?: ErrorBoundaryConfig; tickMs?: number; zeroConfig?: boolean; initialFacts?: Record; status?: boolean; }); hostConnected(): void; hostDisconnected(): void; dispatch(event: InferEvents): void; } declare function createDerived(host: ReactiveControllerHost, system: SingleModuleSystem, key: string | string[]): DerivedController; declare function createFact(host: ReactiveControllerHost, system: SingleModuleSystem, factKey: string): FactController; /** * Create an inspect controller. * Returns InspectState; pass `{ throttleMs }` for throttled updates. */ declare function createInspect(host: ReactiveControllerHost, system: SingleModuleSystem, options?: { throttleMs?: number; }): InspectController; declare function createRequirementStatus(host: ReactiveControllerHost, statusPlugin: StatusPlugin, type: string): RequirementStatusController; declare function createWatch(host: ReactiveControllerHost, system: SingleModuleSystem, derivationId: string, callback: (newValue: T, previousValue: T | undefined) => void): WatchController; declare function createDirectiveSelector(host: ReactiveControllerHost, system: SingleModuleSystem, selector: (state: InferSelectorState) => R, equalityFn?: (a: R, b: R) => boolean, options?: { autoTrack?: boolean; }): DirectiveSelectorController; declare function createExplain(host: ReactiveControllerHost, system: SingleModuleSystem, requirementId: string): ExplainController; declare function createConstraintStatus(host: ReactiveControllerHost, system: SingleModuleSystem, constraintId?: string): ConstraintStatusController; declare function createOptimisticUpdate(host: ReactiveControllerHost, system: SingleModuleSystem, statusPlugin?: StatusPlugin, requirementType?: string): OptimisticUpdateController; /** * Build a `ModuleController` from a Directive module definition. * * The function is exported as both `createModuleController` (preferred) * and `createModule` (legacy alias). The original `createModule` name * collides with `@directive-run/core`'s `createModule` — importing * both into the same scope shadows whichever lands last in editor * auto-import order. New code should use `createModuleController`; * the `createModule` alias remains so existing imports still resolve. */ declare function createModuleController(host: ReactiveControllerHost, moduleDef: ModuleDef, config?: { plugins?: Plugin[]; trace?: TraceOption; errorBoundary?: ErrorBoundaryConfig; tickMs?: number; zeroConfig?: boolean; initialFacts?: Record; status?: boolean; }): ModuleController; /** * Legacy alias for `createModuleController`. Collides by name with * `@directive-run/core`'s `createModule`. New code should prefer * `createModuleController`. * * @deprecated Renamed to `createModuleController` — same shape, no * import collision with `@directive-run/core`. The function-wrapper * shape (vs `export const x = y`) ensures the `@deprecated` JSDoc * tag renders the strikethrough in every TS-aware editor. */ declare function createModule(host: ReactiveControllerHost, moduleDef: ModuleDef, config?: Parameters>[2]): ModuleController; declare function useDispatch(system: SingleModuleSystem): (event: InferEvents) => void; /** * Returns the system's events dispatcher. */ declare function useEvents(system: SingleModuleSystem): SingleModuleSystem["events"]; /** * Reactive controller for history state. * Triggers host updates when snapshots change or navigation occurs. * * @example * ```typescript * class MyElement extends LitElement { * private _history = new HistoryController(this, system); * render() { * const h = this._history.value; * return html``; * } * } * ``` */ declare class HistoryController implements ReactiveController { private _host; private _system; value: HistoryState | null; private _unsub?; constructor(_host: ReactiveControllerHost, _system: SingleModuleSystem); hostConnected(): void; hostDisconnected(): void; } /** * Snapshot-only history helper. Returns the current `HistoryState` * once and does not re-fire when history mutates. * * **Named `getHistory` to match the snapshot semantics.** The Lit * adapter intentionally provides a non-reactive variant alongside * the reactive `HistoryController` so callers reading history once * (e.g. logging the last snapshot before a destroy) don't have to * spin up a controller. The previous name `useHistory` collided * with the reactive `useHistory` semantics in * `@directive-run/{react,vue,svelte,solid}` where the hook IS * reactive — same name, opposite contract. * * For reactive history, use `HistoryController`. */ declare function getHistory(system: SingleModuleSystem): HistoryState | null; /** * @deprecated Renamed to `getHistory`. The Lit functional helper is * snapshot-only; React/Vue/Svelte/Solid `useHistory` is reactive. * Use `HistoryController` for the reactive Lit equivalent. The * function-wrapper shape (vs `export const x = y`) ensures the * `@deprecated` JSDoc tag renders in every TS-aware editor. */ declare function useHistory(system: SingleModuleSystem): HistoryState | null; declare function getDerived(system: SingleModuleSystem, derivationId: string): () => T; declare function getFact(system: SingleModuleSystem, factKey: string): () => T | undefined; declare function createTypedHooks(): { createDerived: >(host: ReactiveControllerHost, system: SingleModuleSystem, derivationId: K) => DerivedController[K]>; createFact: >(host: ReactiveControllerHost, system: SingleModuleSystem, factKey: K) => FactController[K]>; useDispatch: (system: SingleModuleSystem) => (event: InferEvents) => void; useEvents: (system: SingleModuleSystem) => SingleModuleSystem["events"]; createWatch: (host: ReactiveControllerHost, system: SingleModuleSystem, key: K, callback: (newValue: unknown, previousValue: unknown) => void) => WatchController; }; /** * Reactive controller that selects from a NamespacedSystem. * Subscribes to specified keys and triggers host updates. * * @example * ```typescript * class MyElement extends LitElement { * private token = new NamespacedSelectorController( * this, system, ["auth.token"], (s) => s.facts.auth.token, * ); * render() { * return html`${this.token.value}`; * } * } * ``` */ declare class NamespacedSelectorController implements ReactiveController { private host; private system; private keys; private selector; private unsubscribe?; value: R; constructor(host: ReactiveControllerHost, system: NamespacedSystem, keys: string[], selector: (system: NamespacedSystem) => R); hostConnected(): void; hostDisconnected(): void; } declare function createNamespacedSelector(host: ReactiveControllerHost, system: NamespacedSystem, keys: string[], selector: (system: NamespacedSystem) => R): NamespacedSelectorController; /** * Lit reactive controller that creates and manages a query system. * Starts on connect, destroys on disconnect. * * @example * ```typescript * import { LitElement, html } from "lit"; * import { QuerySystemController } from "@directive-run/lit"; * import { createQuerySystem } from "@directive-run/query"; * * class MyApp extends LitElement { * private app = new QuerySystemController(this, () => * createQuerySystem({ * facts: { userId: "" }, * queries: { user: { key: ..., fetcher: ... } }, * autoStart: false, * }) * ); * * render() { * const user = this.app.system.read("user"); * return html`
${user.data?.name}
`; * } * } * ``` */ declare class QuerySystemController void; destroy: () => void; isRunning?: boolean; [key: string]: any; }> implements ReactiveController { private _system; private factory; constructor(host: ReactiveControllerHost, factory: () => T); get system(): T; hostConnected(): void; hostDisconnected(): void; } /** * Lit reactive controller for SSR hydration. * Accepts a DistributableSnapshot and creates a hydrated system. * * @example * ```typescript * class MyElement extends LitElement { * private hydration = new HydrationController(this, serverSnapshot); * private system = this.hydration.createSystem(myModule); * } * ``` */ declare class HydrationController implements ReactiveController { private snapshot; private systems; constructor(host: ReactiveControllerHost, snapshot?: Record); hostConnected(): void; hostDisconnected(): void; createSystem(moduleDef: ModuleDef, config?: { plugins?: Plugin[]; trace?: TraceOption; errorBoundary?: ErrorBoundaryConfig; tickMs?: number; zeroConfig?: boolean; initialFacts?: Record; }): SingleModuleSystem; } /** * Reactive controller exposing the latest audit-ledger entries matching * `filter` as `.value`. Polls (default 250 ms — override with `pollMs`) * and re-renders the host on each tick that brings new matches. * * **Polling floor:** `pollMs` is clamped to a minimum of 50 ms to prevent * accidental DoS from typos like `pollMs: 5`. Values below the floor are * silently clamped in production; dev mode logs a warning. * * @example * ```ts * import { AuditLedgerController } from "@directive-run/lit"; * * class AuditLog extends LitElement { * private ledgerCtrl = new AuditLedgerController( * this, * ledger, * { kind: "constraint.evaluate", limit: 20 }, * ); * * render() { * return html`
    * ${this.ledgerCtrl.value.map(e => html`
  • ${e.kind} @ ${e.ts}
  • `)} *
`; * } * } * ``` */ declare class AuditLedgerController implements ReactiveController { private host; private ledger; private filter; private pollMs; private intervalId; /** * Latest matching audit entries. Updates on each poll tick when the * seq-window (first/last entry seq) changes. Lit `requestUpdate()` is * only called when the window moves — in-place tombstone replacement * within the visible window does NOT trigger re-render (use the ledger's * onWrite hook for revision-level updates when added). */ value: readonly AuditEntry[]; constructor(host: ReactiveControllerHost, ledger: AuditLedger, filter?: QueryFilter, opts?: { pollMs?: number; }); hostConnected(): void; hostDisconnected(): void; } export { AuditLedgerController, ConstraintStatusController, DerivedController, DirectiveSelectorController, ExplainController, FactController, HistoryController, HydrationController, InspectController, ModuleController, NamespacedSelectorController, OptimisticUpdateController, QuerySystemController, RequirementStatusController, type StatusPlugin, SystemController, WatchController, createConstraintStatus, createDerived, createDirectiveSelector, createExplain, createFact, createInspect, createModule, createModuleController, createNamespacedSelector, createOptimisticUpdate, createRequirementStatus, createTypedHooks, createWatch, directiveContext, getDerived, getFact, getHistory, useDispatch, useEvents, useHistory };