import { ReactNode } from 'react'; import { TreePath } from '@elaraai/e3-types'; import { ReactiveDatasetCacheInterface } from './dataset-store.js'; /** * Props for {@link ReactiveDatasetProvider}. * * @property children - Subtree that should see the dataset cache. */ export interface ReactiveDatasetProviderProps { children: ReactNode; } /** * Provide a {@link ReactiveDatasetCache} to the component tree. * * @remarks * Reads server identity from the surrounding `` to build a * default {@link DatasetApi} adapter, then constructs a workspace-scoped * cache. Configures the cache's scheduler to use `queueMicrotask` so * cache notifications never fire during a React render pass. * * Must be mounted inside an `` (which also owns the * `` wrap that this package's TanStack hooks * depend on). Throws otherwise. * * @example * ```tsx * * * * * * ``` */ export declare function ReactiveDatasetProvider({ children, }: ReactiveDatasetProviderProps): import("react/jsx-runtime").JSX.Element; /** * Hook to access the ReactiveDatasetCache from context. * * @returns The ReactiveDatasetCache instance * @throws Error if used outside of a ReactiveDatasetProvider */ export declare function useReactiveDatasetCache(): ReactiveDatasetCacheInterface; /** * Like {@link useReactiveDatasetCache} but returns `null` instead of throwing * when used outside a ``. Use this when a component * has a graceful fallback (e.g. accepts an explicit config prop too). */ export declare function useReactiveDatasetCacheOptional(): ReactiveDatasetCacheInterface | null; /** * Hook to subscribe to reactive dataset cache changes using React 18's useSyncExternalStore. * * @returns The current snapshot version */ export declare function useReactiveDatasetCacheSubscription(): number; /** * Hook to subscribe to a specific reactive dataset key. * * @param workspace - The workspace name * @param path - The dataset path * @returns The cached value, or undefined if not loaded */ export declare function useReactiveDatasetKey(workspace: string, path: TreePath): Uint8Array | undefined; /** * Reactive dataset to preload. */ export interface ReactiveDatasetToPreload { workspace: string; path: TreePath; } /** * Result of usePreloadReactiveDatasets hook. */ export interface PreloadReactiveDatasetsResult { /** True while preloading */ loading: boolean; /** Error if preloading failed */ error: Error | null; /** Reload all datasets */ reload: () => void; } /** * Hook to preload reactive datasets before rendering. * * @param datasets - Array of datasets to preload * @returns Loading state and error * * @example * ```tsx * import { variant } from "@elaraai/east"; * * function MyComponent() { * const { loading, error } = usePreloadReactiveDatasets([ * { workspace: "production", path: [variant("field", "inputs"), variant("field", "config")] }, * { workspace: "production", path: [variant("field", "data")] }, * ]); * * if (loading) return ; * if (error) return ; * * return ; * } * ``` */ export declare function usePreloadReactiveDatasets(datasets: ReactiveDatasetToPreload[]): PreloadReactiveDatasetsResult; /** * Props for the ReactiveDatasetLoader component. */ export interface ReactiveDatasetLoaderProps { /** Datasets to preload */ datasets: ReactiveDatasetToPreload[]; /** Children to render when loaded */ children: ReactNode; /** Loading fallback */ fallback?: ReactNode; /** Error render function */ onError?: (error: Error, reload: () => void) => ReactNode; } /** * Component that preloads reactive datasets before rendering children. * * @example * ```tsx * import { variant } from "@elaraai/east"; * * function App() { * return ( * * } * onError={(err, reload) => } * > * * * * ); * } * ``` */ export declare function ReactiveDatasetLoader({ datasets, children, fallback, onError, }: ReactiveDatasetLoaderProps): import("react/jsx-runtime").JSX.Element; /** * Hook to write to a reactive dataset from React code. * * @returns A function to write to a dataset * * @example * ```tsx * import { encodeBeast2For, IntegerType, variant } from "@elaraai/east"; * * function UpdateButton() { * const writeDataset = useReactiveDatasetWrite(); * * const handleUpdate = async () => { * await writeDataset( * "production", * [variant("field", "inputs"), variant("field", "count")], * encodeBeast2For(IntegerType)(42n) * ); * }; * * return ; * } * ``` */ export declare function useReactiveDatasetWrite(): (workspace: string, path: TreePath, value: Uint8Array) => Promise; /** * Hook to check if a reactive dataset is cached. * * @param workspace - The workspace name * @param path - The dataset path * @returns True if the dataset is cached */ export declare function useReactiveDatasetHas(workspace: string, path: TreePath): boolean; //# sourceMappingURL=dataset-hooks.d.ts.map