import * as solid_js from 'solid-js'; import { Accessor } from 'solid-js'; import { createRequirementStatusPlugin, SingleModuleSystem, ModuleSchema, InferFacts, 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): Accessor[K] | undefined>; /** Multi-key overload */ declare function useFact & string>(system: SingleModuleSystem, factKeys: K[]): Accessor, K>>; /** Single key overload */ declare function useDerived & string>(system: SingleModuleSystem, derivationId: K): Accessor[K]>; /** Multi-key overload */ declare function useDerived & string>(system: SingleModuleSystem, derivationIds: K[]): Accessor, 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): Accessor; 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 Accessor with optional throttling. */ declare function useInspect(system: SingleModuleSystem, options?: UseInspectOptions): Accessor; /** Single type overload */ declare function useRequirementStatus(statusPlugin: StatusPlugin, type: string): Accessor; /** Multi-type overload */ declare function useRequirementStatus(statusPlugin: StatusPlugin, types: string[]): Accessor>; /** * Reactively returns the explanation string for a requirement. */ declare function useExplain(system: SingleModuleSystem, requirementId: string): Accessor; /** Get all constraints */ declare function useConstraintStatus(system: SingleModuleSystem): Accessor; /** Get a single constraint by ID */ declare function useConstraintStatus(system: SingleModuleSystem, constraintId: string): Accessor; interface OptimisticUpdateResult { mutate: (updateFn: () => void) => void; isPending: Accessor; error: Accessor; 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; /** * Single type: throws a promise while the requirement is pending (Suspense). */ declare function useSuspenseRequirement(statusPlugin: StatusPlugin, type: string): Accessor; /** * Multi-type: throws a promise while any of the requirements are pending. */ declare function useSuspenseRequirement(statusPlugin: StatusPlugin, types: string[]): Accessor>; /** * Reactive history signal. Returns an Accessor that updates * when snapshots are taken or navigation occurs. * * @example * ```tsx * const history = useHistory(system); * * ``` */ declare function useHistory(system: SingleModuleSystem): Accessor>; /** 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[]; } /** * Create a scoped Directive system with automatic lifecycle management. * When no `facts` or `derived` keys are specified, subscribes to ALL * facts and derivations and returns reactive signals. * * @example * ```tsx * // Subscribe to everything * const { facts, derived, events, dispatch } = useDirective(counterModule); * * // Selective keys * const { facts, derived } = useDirective(counterModule, { facts: ["count"], derived: ["doubled"] }); * ``` */ declare function useDirective(moduleDef: ModuleDef, config?: UseDirectiveConfig): { system: SingleModuleSystem; facts: Accessor>; derived: Accessor>; 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; }; /** * Create a derivation signal outside of a component. */ declare function createDerivedSignal(system: SingleModuleSystem, derivationId: string): [Accessor, () => void]; /** * Create a fact signal outside of a component. */ declare function createFactSignal(system: SingleModuleSystem, factKey: string): [Accessor, () => void]; declare function createTypedHooks(): { useFact: & string>(system: SingleModuleSystem, factKey: K) => Accessor[K] | undefined>; useDerived: & string>(system: SingleModuleSystem, derivationId: K) => Accessor[K]>; useDispatch: (system: SingleModuleSystem) => (event: InferEvents) => void; useEvents: (system: SingleModuleSystem) => SingleModuleSystem["events"]; useWatch: (system: SingleModuleSystem, key: K, callback: (newValue: unknown, previousValue: unknown) => void) => void; }; /** * SolidJS accessor that selects from a NamespacedSystem. * Subscribes to specified keys and provides reactive updates. * * @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 * ```tsx * const token = useNamespacedSelector(system, ["auth.token"], (s) => s.facts.auth.token); * ``` */ declare function useNamespacedSelector(system: NamespacedSystem, keys: string[], selector: (system: NamespacedSystem) => R): Accessor; /** * Solid 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 via onCleanup. * * @example * ```tsx * import { useQuerySystem, useDerived } from "@directive-run/solid"; * * function App() { * const app = useQuerySystem({ * facts: { userId: "" }, * queries: { user: { key: ..., fetcher: ... } }, * }); * * const user = useDerived(app, "user"); * return
{user().data?.name}
; * } * ``` */ declare function useQuerySystem void; destroy: () => void; isRunning?: boolean; [key: string]: any; }>(config: Record): T; /** * Solid component that provides a DistributableSnapshot to child components. * Uses `HydrationContext.Provider` under the hood — pass `value` as the snapshot. * * @example * ```tsx * * * * ``` */ declare const DirectiveHydrator: solid_js.ContextProviderComponent | undefined>; /** * Create a system hydrated from a server snapshot. * Must be used inside a `` ancestor. */ declare function useHydratedSystem(moduleDef: ModuleDef, config?: UseDirectiveConfig): SingleModuleSystem; /** * Subscribe to an audit ledger and return the latest entries matching * `filter` as a Solid `Accessor`. 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. * * @example * ```tsx * import { useAuditLedger } from "@directive-run/solid"; * * function AuditLog(props: { ledger: AuditLedger }) { * const entries = useAuditLedger(props.ledger, { kind: "constraint.evaluate", limit: 20 }); * return ( *
    * * {(e) =>
  • {e.kind} @ {new Date(e.ts).toISOString()}
  • } *
    *
* ); * } * ``` */ declare function useAuditLedger(ledger: AuditLedger, filter?: QueryFilter, opts?: { pollMs?: number; }): Accessor; export { DirectiveHydrator, type OptimisticUpdateResult, type StatusPlugin, type UseInspectOptions, createDerivedSignal, createFactSignal, createTypedHooks, useAuditLedger, useConstraintStatus, useDerived, useDirective, useDispatch, useEvents, useExplain, useFact, useHistory, useHydratedSystem, useInspect, useNamespacedSelector, useOptimisticUpdate, useQuerySystem, useRequirementStatus, useSelector, useSuspenseRequirement, useWatch };