UNPKG

drizzle-cube

Version:

Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.

58 lines (57 loc) 2.43 kB
import { ReactNode } from 'react'; import { useCubeApi } from './CubeApiProvider'; import { useCubeMeta } from './CubeMetaProvider'; import { useCubeFeatures } from './CubeFeaturesProvider'; import { CubeQueryOptions, CubeApiOptions, FeaturesConfig, DashboardLayoutMode } from '../types'; import { CubeMeta, FieldLabelMap } from '../hooks/useCubeMeta'; import { CubeClient } from '../client/CubeClient'; import { BatchCoordinator } from '../client/BatchCoordinator'; interface CubeContextValue { cubeApi: CubeClient; options?: CubeQueryOptions; meta: CubeMeta | null; labelMap: FieldLabelMap; metaLoading: boolean; metaError: string | null; getFieldLabel: (fieldName: string) => string; refetchMeta: () => void; updateApiConfig: (apiOptions: CubeApiOptions, token?: string) => void; features: FeaturesConfig; batchCoordinator: BatchCoordinator | null; enableBatching: boolean; dashboardModes: DashboardLayoutMode[]; } interface CubeProviderProps { cubeApi?: CubeClient; apiOptions?: CubeApiOptions; token?: string; options?: CubeQueryOptions; features?: FeaturesConfig; dashboardModes?: DashboardLayoutMode[]; enableBatching?: boolean; batchDelayMs?: number; children: ReactNode; } /** * CubeProvider - Three-layer context wrapper * * Wraps children in three isolated context providers for optimal performance: * 1. CubeApiProvider - Stable API layer (changes only on auth) * 2. CubeMetaProvider - Metadata layer (changes on metadata load) * 3. CubeFeaturesProvider - Feature flags layer (changes on feature updates) */ export declare function CubeProvider({ cubeApi: _initialCubeApi, // Intentionally unused - for backward compatibility apiOptions, token, options, features, dashboardModes, enableBatching, batchDelayMs, children }: CubeProviderProps): import("react/jsx-runtime").JSX.Element; /** * useCubeContext - Backward compatible hook * * Merges all three contexts into a single object for backward compatibility. * Components using this hook will re-render when ANY context changes. * * For better performance, use specialized hooks: * - useCubeApi() - Only re-renders on API changes * - useCubeMeta() - Only re-renders on metadata changes * - useCubeFeatures() - Only re-renders on feature changes */ export declare function useCubeContext(): CubeContextValue; export { useCubeApi, useCubeMeta, useCubeFeatures };