import * as vue from 'vue'; import { Ref, ShallowRef, ComputedRef } from 'vue'; import { createRequirementStatusPlugin, ModuleSchema, InferFacts, SingleModuleSystem, InferDerivations, InferEvents, AuditLedger, QueryFilter, AuditEntry, ModuleDef, Plugin, TraceOption, ErrorBoundaryConfig, RequirementTypeStatus, ModulesMap, NamespacedSystem, InferSelectorState } from '@directive-run/core'; export { RequirementTypeStatus } from '@directive-run/core'; import { ConstraintInfo, buildHistoryState, InspectState } from '@directive-run/core/adapter-utils'; export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils'; /** Type for the requirement status plugin return value */ type StatusPlugin = ReturnType; /** Single key overload */ declare function useFact & string>(system: SingleModuleSystem, factKey: K): Ref[K] | undefined>; /** Multi-key overload */ declare function useFact & string>(system: SingleModuleSystem, factKeys: K[]): ShallowRef, K>>; /** Single key overload */ declare function useDerived & string>(system: SingleModuleSystem, derivationId: K): Ref[K]>; /** Multi-key overload */ declare function useDerived & string>(system: SingleModuleSystem, derivationIds: K[]): ShallowRef, K>>; /** * Auto-tracking selector over facts and derivations. * Uses `withTracking()` to detect which facts the selector accesses, * then subscribes only to those keys. */ declare function useSelector(system: SingleModuleSystem, selector: (state: InferSelectorState) => R, equalityFn?: (a: R, b: R) => boolean): Ref; declare function useDispatch(system: SingleModuleSystem): (event: InferEvents) => void; /** * Returns the system's events dispatcher. */ declare function useEvents(system: SingleModuleSystem): SingleModuleSystem["events"]; /** Watch a derivation or fact by key (auto-detected). When a key exists in both facts and derivations, the derivation overload takes priority. */ declare function useWatch & string>(system: SingleModuleSystem, key: K, callback: (newValue: InferDerivations[K], previousValue: InferDerivations[K] | undefined) => void): void; /** Watch a fact key with auto-detection. */ declare function useWatch & string>(system: SingleModuleSystem, key: K, callback: (newValue: InferFacts[K] | undefined, previousValue: InferFacts[K] | undefined) => void): void; /** Options for useInspect */ interface UseInspectOptions { throttleMs?: number; } /** * Consolidated system inspection hook. * Returns InspectState with optional throttling. */ declare function useInspect(system: SingleModuleSystem, options?: UseInspectOptions): ShallowRef; /** Single type overload */ declare function useRequirementStatus(statusPlugin: StatusPlugin, type: string): ShallowRef; /** Multi-type overload */ declare function useRequirementStatus(statusPlugin: StatusPlugin, types: string[]): ShallowRef>; /** * Returns a promise that resolves when a requirement type settles. * Designed for Vue's async `setup()` with ``. * * - If the requirement is loading, the returned promise suspends the component. * - If the requirement has an error, the promise rejects with that error. * - If the requirement is already settled, resolves immediately. * * @example * ```vue * * * * ``` */ /** Single type overload */ declare function useSuspenseRequirement(statusPlugin: StatusPlugin, type: string): Promise>; /** Multi-type overload */ declare function useSuspenseRequirement(statusPlugin: StatusPlugin, types: string[]): Promise>>; /** * Reactively returns the explanation string for a requirement. */ declare function useExplain(system: SingleModuleSystem, requirementId: string): Ref; /** Get all constraints */ declare function useConstraintStatus(system: SingleModuleSystem): ComputedRef; /** Get a single constraint by ID */ declare function useConstraintStatus(system: SingleModuleSystem, constraintId: string): ComputedRef; interface OptimisticUpdateResult { mutate: (updateFn: () => void) => void; isPending: Ref; error: Ref; rollback: () => void; } /** * Optimistic update hook. Saves a snapshot before mutating, monitors * a requirement type via statusPlugin, and rolls back on failure. */ declare function useOptimisticUpdate(system: SingleModuleSystem, statusPlugin?: StatusPlugin, requirementType?: string): OptimisticUpdateResult; /** * Reactive history composable. Returns a ShallowRef that updates * when snapshots are taken or navigation occurs. * * @example * ```vue * const history = useHistory(system); * * ``` */ declare function useHistory(system: SingleModuleSystem): ShallowRef>; /** Configuration for useDirective */ interface UseDirectiveConfig { plugins?: Plugin[]; trace?: TraceOption; errorBoundary?: ErrorBoundaryConfig; tickMs?: number; zeroConfig?: boolean; initialFacts?: Record; status?: boolean; /** Fact keys to subscribe to (omit for all) */ facts?: string[]; /** Derivation keys to subscribe to (omit for all) */ derived?: string[]; } declare function useDirective(moduleDef: ModuleDef, config?: UseDirectiveConfig): { system: SingleModuleSystem; facts: ShallowRef>; derived: ShallowRef>; events: M["events"] extends Record ? { [E in keyof M["events"]]: M["events"][E] extends Record ? keyof M["events"][E] extends never ? () => void : (payload: M["events"][E] extends infer T ? T extends M["events"][E] ? T extends Record ? { [K in keyof T]: T[K] extends { _type: infer T_1; } ? T_1 : T[K]; } : never : never : never) => void : () => void; } : Record; dispatch: (event: InferEvents) => void; statusPlugin: { plugin: Plugin; getStatus: (type: string) => RequirementTypeStatus; getAllStatus: () => Map; subscribe: (listener: () => void) => () => void; reset: () => void; } | undefined; }; declare function createTypedHooks(): { useFact: & string>(system: SingleModuleSystem, factKey: K) => Ref[K] | undefined>; useDerived: & string>(system: SingleModuleSystem, derivationId: K) => Ref[K]>; useDispatch: (system: SingleModuleSystem) => (event: InferEvents) => void; useEvents: (system: SingleModuleSystem) => SingleModuleSystem["events"]; useWatch: (system: SingleModuleSystem, key: K, callback: (newValue: unknown, previousValue: unknown) => void) => void; }; /** * Reactive composable to select from a NamespacedSystem. * Subscribes to specified keys and returns a Vue ref. * * @param system - The namespaced system * @param keys - Namespaced keys to subscribe to (e.g., ["auth.token", "data.count"]) * @param selector - Function that reads from system.facts / system.derive * * @example * ```vue * const system = useDirectiveRef({ modules: { auth, data } }); * const token = useNamespacedSelector(system, ["auth.token"], (s) => s.facts.auth.token); * ``` */ declare function useNamespacedSelector(system: NamespacedSystem, keys: string[], selector: (system: NamespacedSystem) => R): Ref; /** * Vue composable to create and manage a query system with proper lifecycle. * * Accepts a config object or a factory function that creates the system. * Handles cleanup on scope disposal. * * @example * ```vue * * ``` */ declare function useQuerySystem void; destroy: () => void; isRunning?: boolean; [key: string]: any; }>(config: Record): T; /** * Vue component that provides a DistributableSnapshot to child components. * Use with `useHydratedSystem` for SSR hydration in Nuxt or Vue SSR apps. * * @example * ```vue * * ``` */ declare const DirectiveHydrator: vue.DefineComponent, () => vue.VNode[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>; /** * Vue composable that creates a system hydrated from a server snapshot. * Must be used inside a `` ancestor. * * @example * ```vue * * ``` */ declare function useHydratedSystem(moduleDef: ModuleDef, config?: UseDirectiveConfig): SingleModuleSystem; /** * Subscribe to an audit ledger and return the latest entries matching * `filter` as a reactive `Ref`. Re-evaluates on each poll tick (default * 250 ms — override with `pollMs`). * * **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. * * **First-paint freshness:** the interval starts immediately at setup * time (not gated on `onMounted`), so the first ledger query lands * before the component paints. Cleanup uses `onScopeDispose`, which * is correct for both component scopes and ad-hoc effect scopes. * * @example * ```vue * * * ``` */ declare function useAuditLedger(ledger: AuditLedger, filter?: QueryFilter, opts?: { pollMs?: number; }): ShallowRef; export { DirectiveHydrator, type OptimisticUpdateResult, type StatusPlugin, type UseInspectOptions, createTypedHooks, useAuditLedger, useConstraintStatus, useDerived, useDirective, useDispatch, useEvents, useExplain, useFact, useHistory, useHydratedSystem, useInspect, useNamespacedSelector, useOptimisticUpdate, useQuerySystem, useRequirementStatus, useSelector, useSuspenseRequirement, useWatch };