import type { PersistenceDriver } from "../persistence/types.js"; import type { Component } from "svelte"; /** * Factory function signature for creating a store. * Receives the resolved config, driver, and a map of already-created store instances. * The `stores` map enables dependency injection between stores. */ export type StoreFactory = ( config: TConfig, driver: PersistenceDriver, stores: Map, ) => TStore | null; /** * An entry in the Store Registry. * Maps a context key to its factory function and metadata. */ export interface StoreRegistryEntry { /** Unique id (previously key) matching the RUNE_LAB_CONTEXT key */ id: string; /** The symbol used for Svelte context (e.g., RUNE_LAB_CONTEXT.theme) */ contextKey?: symbol; /** The ID of the plugin that registered this store */ pluginId?: string; /** Factory function that creates the store */ factory: StoreFactory; /** If true, the store is optional — null return from factory means "skip" */ optional?: boolean; /** If true, the store does not use persistence at all */ noPersistence?: boolean; /** * Keys of other stores that must be created before this one. * The registry initializer topologically sorts entries by this field. */ dependsOn?: string[]; /** * Config key that must be present for this store to be created. * Used for opt-in stores (e.g., "cart", "auth"). * When undefined, the store is always created. */ conditional?: string; } /** * A RunePlugin is a collection of stores and overlays. */ export interface RunePlugin { /** dot-namespaced: "rune-lab.layout" */ id: string; /** one or more store slots */ stores: StoreRegistryEntry[]; /** Svelte components, no required props */ overlays?: Component>[]; } /** * The global store registry. * Pre-populated with built-in stores by RuneProvider. * Third-party plugins can register additional entries before mounting. * * @example * ```ts * // Plugin registration (before RuneProvider mounts) * registerStore({ * id: "analytics", * factory: (config, driver) => createAnalyticsStore(config), * optional: true, * noPersistence: true, * }); * ``` */ declare const STORE_REGISTRY: Map; /** * Register a store entry in the global registry. * Must be called before RuneProvider mounts for the store to be auto-wired. * * @param entry - Store registry entry with id, factory, and options. * @throws Error if a store with the same id is already registered. */ export declare function registerStore( entry: StoreRegistryEntry, ): void; /** * Define a Rune plugin and register its stores. */ export declare function defineRune(plugin: RunePlugin): RunePlugin; /** * Get a registered store entry by key. */ export declare function getRegisteredStore( key: string, ): StoreRegistryEntry | undefined; /** * Get all registered store entries. */ export declare function getAllRegisteredStores(): Map< string, StoreRegistryEntry >; /** * Remove a store registration (primarily useful for testing). */ export declare function unregisterStore(key: string): boolean; /** * Clear all store registrations (primarily useful for testing). */ export declare function clearRegistry(): void; /** * Initialize all registered stores using the provided plugins, config, and driver. * Resolves dependencies via topological sort and returns a map of key → store instance. * * @param _plugins - The list of active RunePlugins (unused but kept for API stability) * @param config - The RuneLabConfig (Record) * @param driver - The resolved PersistenceDriver * @returns Map of store key → created store instance */ export declare function initializeStores( _plugins: unknown[], // RunePlugin[] - avoid circular import if possible config: Record, driver: PersistenceDriver, ): Map; export { STORE_REGISTRY };