import { QueryClient } from '@tanstack/react-query'; /** * Computed field definition with dependency tracking */ export interface ComputedFieldDef { /** Field dependencies needed for computation */ needs: TDeps; /** Computation function receiving only needed fields */ compute: (data: Pick) => TResult; /** Enable memoization for expensive computations */ cache?: boolean; /** Cache key function for memoization (default: JSON.stringify) */ cacheKey?: (data: Pick) => string; } /** * Result transformer function type */ export type ResultTransformer = (result: T) => R; /** * Normalization schema for nested data structures */ export interface NormalizationSchema { /** Entity name for this schema */ entity: string; /** ID field name (default: 'id') */ idField?: keyof T; /** Nested entities to normalize */ relations?: Record; /** Array fields that should be normalized */ arrays?: (keyof T)[]; } /** * Normalized data structure */ export interface NormalizedData { /** Normalized entities by type */ entities: Record>; /** Root result reference */ result: string | number | (string | number)[]; } /** * Field masking configuration */ export interface FieldMaskConfig { /** Fields to mask completely (removed from output) */ remove?: string[]; /** Fields to redact (replaced with [REDACTED]) */ redact?: string[]; /** Custom masking functions */ custom?: Record unknown>; } /** * Field aliasing configuration */ export type FieldAliases = Record; /** * Result diff operation */ export interface DiffOperation { /** Operation type */ op: 'add' | 'remove' | 'replace' | 'update'; /** Path to the changed value */ path: string[]; /** Old value (for remove/replace/update) */ oldValue?: unknown; /** New value (for add/replace/update) */ newValue?: unknown; } /** * Result diff output */ export interface ResultDiff { /** List of changes */ changes: DiffOperation[]; /** Has any changes */ hasChanges: boolean; /** Number of changes */ changeCount: number; /** Changed fields */ changedFields: Set; } /** * Aggregation function type */ export type AggregationFn = (results: T[]) => R; /** * LRU cache for computed field memoization */ declare class MemoizationCache { private cache; private maxSize; private maxAge; constructor(maxSize?: number, maxAge?: number); get(key: string): T | undefined; set(key: string, value: T): void; clear(): void; size(): number; stats(): { size: number; hits: number; avgHits: number; }; } /** * Result enhancement engine with computed fields and transformations */ export declare class ResultEnhancer> { private computedFields; private transformers; private cache; /** * Define a computed field */ defineComputedField(name: string, definition: ComputedFieldDef): this; /** * Add a result transformer */ addTransformer(transformer: ResultTransformer): this; /** * Enhance a result with computed fields */ enhance(result: T): T & Record; /** * Enhance multiple results */ enhanceMany(results: T[]): (T & Record)[]; /** * Clear memoization cache */ clearCache(): void; /** * Get cache statistics */ getCacheStats(): ReturnType; } /** * Transform result using a pipeline of transformers */ export declare function transform(result: T, ...transformers: ResultTransformer[]): R; /** * Create a transformer that maps fields */ export declare function mapFields>(mapper: Partial unknown>>): ResultTransformer; /** * Create a transformer that filters fields */ export declare function pickFields>(fields: (keyof T)[]): ResultTransformer>; /** * Create a transformer that omits fields */ export declare function omitFields>(fields: (keyof T)[]): ResultTransformer; /** * Normalize nested data structures */ export declare function normalize(data: T, schema: NormalizationSchema): NormalizedData; /** * Denormalize data back to nested structure */ export declare function denormalize(normalized: NormalizedData, schema: NormalizationSchema): T | T[]; /** * Mask sensitive fields in results */ export declare function mask>(result: T, config: FieldMaskConfig): T; /** * Mask fields deeply (recursive) */ export declare function maskDeep(result: T, config: FieldMaskConfig): T; /** * Alias field names in result */ export declare function alias>(result: T, aliases: FieldAliases): Record; /** * Aggregate multiple results */ export declare function aggregate(results: T[], aggregator: AggregationFn): R; /** * Common aggregation functions */ export declare const aggregators: { /** Sum numeric field across results */ sum: >(field: keyof T) => AggregationFn; /** Average numeric field across results */ avg: >(field: keyof T) => AggregationFn; /** Find minimum value */ min: >(field: keyof T) => AggregationFn; /** Find maximum value */ max: >(field: keyof T) => AggregationFn; /** Count results */ count: () => AggregationFn; /** Group by field */ groupBy: >(field: keyof T) => AggregationFn>; /** Merge all results into one */ merge: >() => AggregationFn; }; /** * Compute diff between two results */ export declare function diff(oldResult: T, newResult: T): ResultDiff; /** * Apply a diff to a result */ export declare function applyDiff(result: T, resultDiff: ResultDiff): T; /** * React Query integration options */ export interface ReactQueryIntegrationOptions { /** Query client instance */ queryClient: QueryClient; /** Auto-enhance query results */ autoEnhance?: boolean; /** Result enhancer instance */ enhancer?: ResultEnhancer; } /** * Create React Query integration middleware */ export declare function createReactQueryMiddleware(options: ReactQueryIntegrationOptions): { /** * Enhance query data automatically */ enhanceQuery>(_queryKey: unknown[], data: T): T & Record; /** * Invalidate queries with diff detection */ invalidateWithDiff(queryKey: unknown[], newData: T): Promise; /** * Set query data with normalization */ setNormalizedData(queryKey: unknown[], data: T, schema: NormalizationSchema): void; /** * Get and denormalize query data */ getDenormalizedData(queryKey: unknown[], schema: NormalizationSchema): T | T[] | undefined; }; /** * Results extension for enzyme */ export declare const resultsExtension: { readonly name: "enzyme:results"; readonly version: "2.0.0"; readonly description: "Comprehensive result transformations and computed fields"; readonly client: { /** * Define a computed field for a model */ readonly $defineComputedField: , TDeps extends (keyof T)[] = (keyof T)[], TResult = unknown>(model: string, field: string, definition: ComputedFieldDef) => void; /** * Transform a result with multiple transformers */ readonly $transform: (result: T, ...transformers: ResultTransformer[]) => R; /** * Normalize nested data */ readonly $normalize: (data: T, schema: NormalizationSchema) => NormalizedData; /** * Denormalize data back to nested structure */ readonly $denormalize: (normalized: NormalizedData, schema: NormalizationSchema) => T | T[]; /** * Mask sensitive fields */ readonly $mask: >(result: T, config: FieldMaskConfig) => T; /** * Mask fields deeply (recursive) */ readonly $maskDeep: (result: T, config: FieldMaskConfig) => T; /** * Alias field names */ readonly $alias: >(result: T, aliases: FieldAliases) => Record; /** * Compute diff between two results */ readonly $diff: (oldResult: T, newResult: T) => ResultDiff; /** * Apply a diff to a result */ readonly $applyDiff: (result: T, resultDiff: ResultDiff) => T; /** * Aggregate multiple results */ readonly $aggregate: (results: T[], aggregator: AggregationFn) => R; /** * Enhance result with computed fields */ readonly $enhance: >(model: string, result: T) => T & Record; /** * Enhance multiple results */ readonly $enhanceMany: >(model: string, results: T[]) => (T & Record)[]; /** * Clear memoization cache for a model */ readonly $clearCache: (model?: string) => void; /** * Get cache statistics */ readonly $getCacheStats: (model?: string) => Record>; /** * Create React Query integration */ readonly $createReactQueryMiddleware: (options: ReactQueryIntegrationOptions) => { /** * Enhance query data automatically */ enhanceQuery>(_queryKey: unknown[], data: T): T & Record; /** * Invalidate queries with diff detection */ invalidateWithDiff(queryKey: unknown[], newData: T): Promise; /** * Set query data with normalization */ setNormalizedData(queryKey: unknown[], data: T, schema: NormalizationSchema): void; /** * Get and denormalize query data */ getDenormalizedData(queryKey: unknown[], schema: NormalizationSchema): T | T[] | undefined; }; }; readonly utils: { readonly ResultEnhancer: typeof ResultEnhancer; readonly mapFields: typeof mapFields; readonly pickFields: typeof pickFields; readonly omitFields: typeof omitFields; readonly aggregators: { /** Sum numeric field across results */ sum: >(field: keyof T) => AggregationFn; /** Average numeric field across results */ avg: >(field: keyof T) => AggregationFn; /** Find minimum value */ min: >(field: keyof T) => AggregationFn; /** Find maximum value */ max: >(field: keyof T) => AggregationFn; /** Count results */ count: () => AggregationFn; /** Group by field */ groupBy: >(field: keyof T) => AggregationFn>; /** Merge all results into one */ merge: >() => AggregationFn; }; }; }; /** * Type-safe extension type for TypeScript inference */ export type ResultsExtension = typeof resultsExtension; /** * Extended enzyme client type with result methods */ export interface EnzymeClientWithResults { $defineComputedField: typeof resultsExtension.client.$defineComputedField; $transform: typeof resultsExtension.client.$transform; $normalize: typeof resultsExtension.client.$normalize; $denormalize: typeof resultsExtension.client.$denormalize; $mask: typeof resultsExtension.client.$mask; $maskDeep: typeof resultsExtension.client.$maskDeep; $alias: typeof resultsExtension.client.$alias; $diff: typeof resultsExtension.client.$diff; $applyDiff: typeof resultsExtension.client.$applyDiff; $aggregate: typeof resultsExtension.client.$aggregate; $enhance: typeof resultsExtension.client.$enhance; $enhanceMany: typeof resultsExtension.client.$enhanceMany; $clearCache: typeof resultsExtension.client.$clearCache; $getCacheStats: typeof resultsExtension.client.$getCacheStats; $createReactQueryMiddleware: typeof resultsExtension.client.$createReactQueryMiddleware; } export default resultsExtension;