@data-client/normalizr
Version:
Normalizes and denormalizes JSON according to schema for Redux and Flux applications
44 lines • 2.3 kB
TypeScript
import { EndpointsCache, EntityCache } from './types.js';
import WeakDependencyMap from './WeakDependencyMap.js';
import type { EntityTable, NormalizedIndex, Schema } from '../interface.js';
import type { DenormalizeNullable, EntityPath, NormalizeNullable } 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 entities: EntityCache;
/** 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>>;
/** 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> | symbol;
paths: EntityPath[];
};
/** Compute denormalized form maintaining referential equality for same inputs */
query<S extends Schema>(schema: S, args: readonly any[], entities: Record<string, Record<string, any> | undefined> | {
getIn(k: string[]): any;
}, indexes: NormalizedIndex | {
getIn(k: string[]): any;
}, argsKey?: string): DenormalizeNullable<S> | undefined;
buildQueryKey<S extends Schema>(schema: S, args: readonly any[], entities: Record<string, Record<string, any> | undefined> | {
getIn(k: string[]): any;
}, indexes: NormalizedIndex | {
getIn(k: string[]): any;
}, argsKey?: string): NormalizeNullable<S>;
}
type IndexPath = [key: string, field: string, value: string];
type EntitySchemaPath = [key: string] | [key: string, pk: string];
type QueryPath = IndexPath | EntitySchemaPath;
export declare function createGetEntity(entities: EntityTable | {
getIn(k: string[]): {
toJS(): any;
} | undefined;
}): (...args: any[]) => any;
export declare function createGetIndex(indexes: NormalizedIndex | {
getIn(k: string[]): any;
}): (key: string, field: string, value: string) => {
readonly [indexKey: string]: string | undefined;
};
export {};
//# sourceMappingURL=MemoCache.d.ts.map