@data-client/normalizr
Version:
Normalizes and denormalizes JSON according to schema for Redux and Flux applications
38 lines • 1.92 kB
TypeScript
import WeakDependencyMap from './WeakDependencyMap.js';
import { GetEntityCache } from './entitiesCache.js';
import type { INVALID } from '../denormalize/symbol.js';
import type { EntityPath, NormalizedIndex, QueryPath, Schema } from '../interface.js';
import type { DenormalizeNullable, NormalizeNullable } from '../types.js';
import type { IMemoPolicy, EndpointsCache } from './types.js';
/** Singleton to store the memoization cache for denormalization methods */
export default class MemoCache {
/** Cache for every entity based on its dependencies and its own input */
protected _getCache: GetEntityCache;
/** Caches the final denormalized form based on input, entities */
protected endpoints: EndpointsCache;
/** Caches the queryKey based on schema, args, and any used entities or indexes */
protected queryKeys: Map<string, WeakDependencyMap<QueryPath>>;
protected policy: IMemoPolicy;
constructor(policy?: IMemoPolicy);
/** Compute denormalized form maintaining referential equality for same inputs */
denormalize<S extends Schema>(schema: S | undefined, input: unknown, entities: any, args?: readonly any[]): {
data: DenormalizeNullable<S> | typeof INVALID;
paths: EntityPath[];
};
/** Compute denormalized form maintaining referential equality for same inputs */
query<S extends Schema>(schema: S, args: readonly any[], state: StateInterface, argsKey?: string): {
data: DenormalizeNullable<S> | typeof INVALID;
paths: EntityPath[];
};
buildQueryKey<S extends Schema>(schema: S, args: readonly any[], state: StateInterface, argsKey?: string): NormalizeNullable<S>;
}
type StateInterface = {
entities: Record<string, Record<string, any> | undefined> | {
getIn(k: string[]): any;
};
indexes: NormalizedIndex | {
getIn(k: string[]): any;
};
};
export {};
//# sourceMappingURL=MemoCache.d.ts.map