import { Entity, EntitySchema, NormalizationResult, NormalizedEntities, Schema } from '../normalization/normalizer'; import { DenormalizeOptions } from '../normalization/denormalizer'; import { SchemaRegistry } from '../normalization/schema-registry'; /** * Normalized data store */ export interface NormalizedStore { /** Get current entities */ getEntities: () => NormalizedEntities; /** Set entities */ setEntities: (entities: NormalizedEntities) => void; /** Subscribe to changes */ subscribe: (listener: () => void) => () => void; } /** * Normalized data state */ export interface NormalizedDataState { /** Current entities */ entities: NormalizedEntities; /** Entity counts by type */ entityCounts: Record; /** Last update timestamp */ lastUpdatedAt: number | null; /** Is loading */ isLoading: boolean; } /** * Validation function type */ export type ValidationFunction = (data: T) => boolean | { valid: boolean; errors?: string[]; }; /** * Validation error thrown when data fails validation */ export declare class ValidationError extends Error { readonly errors: string[]; constructor(message: string, errors?: string[]); } /** * Hook options */ export interface UseNormalizedDataOptions { /** Schema registry for denormalization */ registry?: SchemaRegistry; /** Default denormalization options */ denormalizeOptions?: DenormalizeOptions; /** Enable change tracking */ trackChanges?: boolean; /** Callback on entity change */ onEntityChange?: (entityType: string, entityId: string, entity: Entity | null) => void; /** Optional validation function to run before writes */ validate?: ValidationFunction; /** Whether to throw on validation failure (default: true) */ throwOnValidationError?: boolean; } /** * Hook return type */ export interface UseNormalizedDataReturn { /** Current state */ state: NormalizedDataState; /** Current entities */ entities: NormalizedEntities; /** Get entity by type and ID */ getEntity: (entityType: string, entityId: string) => T | undefined; /** Get multiple entities */ getEntities: (entityType: string, ids: string[]) => T[]; /** Get all entities of type */ getAllOfType: (entityType: string) => T[]; /** Get denormalized entity */ getDenormalized: (entityType: string, entityId: string, schema: EntitySchema) => T | null; /** Get multiple denormalized entities */ getDenormalizedMany: (entityType: string, ids: string[], schema: EntitySchema) => T[]; /** Normalize and add data */ addData: (data: unknown, schema: Schema) => NormalizationResult; /** Update entity */ updateEntity: (entityType: string, entityId: string, updates: Partial) => void; /** Remove entity */ removeEntity: (entityType: string, entityId: string) => void; /** Merge entities */ mergeData: (source: NormalizedEntities, strategy?: 'overwrite' | 'keep' | 'merge') => void; /** Clear all entities */ clearAll: () => void; /** Clear entities of type */ clearType: (entityType: string) => void; /** Get entity count */ getCount: (entityType: string) => number; /** Check if entity exists */ hasEntity: (entityType: string, entityId: string) => boolean; } /** * Hook for working with normalized data * * @param store - Normalized data store * @param options - Hook options * @returns Normalized data state and methods */ export declare function useNormalizedData(store: NormalizedStore, options?: UseNormalizedDataOptions): UseNormalizedDataReturn; /** * Hook for selecting a single entity * * @param entities - Normalized entities * @param entityType - Entity type * @param entityId - Entity ID * @param schema - Optional schema for denormalization * @param options - Denormalization options * @returns Entity or null */ export declare function useEntity(entities: NormalizedEntities, entityType: string, entityId: string | null | undefined, schema?: EntitySchema, options?: DenormalizeOptions): T | null; /** * Hook for selecting multiple entities * * @param entities - Normalized entities * @param entityType - Entity type * @param ids - Entity IDs * @param schema - Optional schema for denormalization * @param options - Denormalization options * @returns Array of entities */ export declare function useEntities(entities: NormalizedEntities, entityType: string, ids: string[], schema?: EntitySchema, options?: DenormalizeOptions): T[]; /** * Hook for selecting all entities of a type * * @param entities - Normalized entities * @param entityType - Entity type * @param filter - Optional filter function * @param sort - Optional sort function * @returns Array of entities */ export declare function useAllEntities(entities: NormalizedEntities, entityType: string, filter?: (entity: T) => boolean, sort?: (a: T, b: T) => number): T[]; /** * Hook for entity selector with memoization * * @param entities - Normalized entities * @param selector - Selector function * @param _deps * @returns Selected value */ export declare function useEntitySelector(entities: NormalizedEntities, selector: (entities: NormalizedEntities) => T, _deps?: unknown[]): T; /** * Hook for normalized CRUD operations * * @param store - Normalized store * @param entityType - Entity type * @param schema - Entity schema * @returns CRUD operations */ export declare function useNormalizedCrud(store: NormalizedStore, entityType: string, schema: EntitySchema): { items: T[]; getById: (id: string) => T | null; create: (data: Omit & { id?: string; }) => T; update: (id: string, data: Partial) => T | null; remove: (id: string) => void; upsert: (data: T) => T; upsertMany: (items: T[]) => T[]; }; /** * Create a simple normalized store */ export declare function createNormalizedStore(initialEntities?: NormalizedEntities): NormalizedStore;