import type { QueryKey } from '@tanstack/react-query'; import type { DataEvent, DataEventHandler, RealtimeAPI, RealtimeStatus, RealtimeSubscribeOptions } from '@asteby/metacore-sdk'; export interface RealtimeContextValue { /** Host-provided client, or null when the host has no realtime. */ client: RealtimeAPI | null; /** * When true, `DynamicTable` / `DynamicKanban` refetch on data events * unless a component passes `realtime={false}`. Default false (opt-in). */ defaultRealtime: boolean; } export interface RealtimeProviderProps { client: RealtimeAPI | null | undefined; /** Turn realtime refetch on for every dynamic table/kanban below. Default false. */ defaultRealtime?: boolean; children: React.ReactNode; } /** * Mount once, inside the host's WebSocket provider and QueryClientProvider. * `client` may be null while the host is still connecting — hooks become * no-ops and re-subscribe when a client appears. */ export declare function RealtimeProvider({ client, defaultRealtime, children }: RealtimeProviderProps): import("react").JSX.Element; /** The host realtime client from context (null when none is mounted). */ export declare function useRealtimeClient(explicit?: RealtimeAPI | null): RealtimeAPI | null; /** Whether dynamic components should refetch on data events by default. */ export declare function useRealtimeDefault(): boolean; export interface UseRealtimeOptions extends RealtimeSubscribeOptions { /** Pass `host.realtime` / `api.realtime` to bypass the context. */ client?: RealtimeAPI | null; /** Set false to pause the subscription without unmounting. Default true. */ enabled?: boolean; } /** * Subscribe to data events for the given models. The handler is kept in a * ref so callers don't need to memoise it; the subscription is torn down on * unmount and re-created when models/events/client change. * * useRealtime({ models: ['SalesOrder'], client: host.realtime }, (e) => { * if (e.action === 'resync' || e.id === currentId) refetch() * }) */ export declare function useRealtime(options: UseRealtimeOptions, handler: DataEventHandler): void; /** Live status of the realtime client ('closed' when none). */ export declare function useRealtimeStatus(explicit?: RealtimeAPI | null): RealtimeStatus; /** Default matcher: any string segment of the query key (case-insensitive) * equals the event's model, table or `addon.model`, or contains the model * as a path segment (`/data/sales_orders`). */ export declare function queryKeyMatchesEvent(queryKey: QueryKey, event: DataEvent): boolean; export interface UseRealtimeInvalidateOptions extends UseRealtimeOptions { /** Override which queries a given event invalidates. Default: `queryKeyMatchesEvent`. */ match?: (queryKey: QueryKey, event: DataEvent) => boolean; /** Coalesce bursts before invalidating (ms). Default 250. */ debounceMs?: number; /** Observe each event after it was scheduled for invalidation. */ onEvent?: DataEventHandler; } /** * Invalidate every react-query query whose key mentions the event's model / * table (see `queryKeyMatchesEvent`). Uses the host's QueryClient. Bursts * are debounced so a coalesced frame storm becomes a single refetch round. * * useRealtimeInvalidate({ models: ['SalesOrder', 'sales_order_items'], client: host.realtime }) */ export declare function useRealtimeInvalidate(options: UseRealtimeInvalidateOptions): void; export interface UseRealtimeTickOptions { /** Models/tables to watch. */ models: string[]; /** Explicit client (federated addons). */ client?: RealtimeAPI | null; /** Master switch — the caller resolves prop vs provider default. */ enabled: boolean; /** Coalesce bursts before ticking (ms). Default 300. */ debounceMs?: number; } /** * A counter that increments (debounced) whenever a data event lands for one * of `models`. Fold it into a refetch effect's dependencies — that is exactly * what `DynamicTable` / `DynamicKanban` do behind their `realtime` prop. */ export declare function useRealtimeTick(options: UseRealtimeTickOptions): number; //# sourceMappingURL=realtime-context.d.ts.map