UNPKG

@data-client/normalizr

Version:

Normalizes and denormalizes JSON according to schema for Redux and Flux applications

68 lines (67 loc) 2.8 kB
export type Schema = null | string | { [K: string]: any; } | Schema[] | SchemaSimple | Serializable; export interface Queryable<Args extends readonly any[] = readonly any[]> { queryKey(args: Args, queryKey: (...args: any) => any, getEntity: GetEntity, getIndex: GetIndex): {}; } export type Serializable<T extends { toJSON(): string; } = { toJSON(): string; }> = (value: any) => T; export interface SchemaSimple<T = any, Args extends readonly any[] = any[]> { normalize(input: any, parent: any, key: any, args: any[], visit: (...args: any) => any, addEntity: (...args: any) => any, getEntity: (...args: any) => any, checkLoop: (...args: any) => any): any; denormalize(input: {}, args: readonly any[], unvisit: (schema: any, input: any) => any): T; queryKey(args: Args, queryKey: (...args: any) => any, getEntity: GetEntity, getIndex: GetIndex): any; } export interface SchemaClass<T = any, Args extends readonly any[] = any[]> extends SchemaSimple<T, Args> { _normalizeNullable(): any; _denormalizeNullable(): any; } export interface EntityInterface<T = any> extends SchemaSimple { createIfValid(props: any): any; pk(params: any, parent?: any, key?: string, args?: readonly any[]): string | number | undefined; readonly key: string; merge(existing: any, incoming: any): any; mergeWithStore(existingMeta: any, incomingMeta: any, existing: any, incoming: any): any; mergeMetaWithStore(existingMeta: any, incomingMeta: any, existing: any, incoming: any): any; indexes?: any; schema: Record<string, Schema>; cacheWith?: object; prototype: T; } export interface NormalizedIndex { readonly [entityKey: string]: { readonly [indexName: string]: { readonly [lookup: string]: string; }; }; } export interface EntityTable { [entityKey: string]: { [pk: string]: unknown; } | undefined; } /** Visits next data + schema while recurisvely normalizing */ export interface Visit { (schema: any, value: any, parent: any, key: any, args: readonly any[]): any; } /** Returns true if a circular reference is found */ export interface CheckLoop { (entityKey: string, pk: string, input: object): boolean; } /** Get Array of entities with map function applied */ export interface GetEntity { (entityKey: string | symbol): { readonly [pk: string]: any; } | undefined; (entityKey: string | symbol, pk: string | number): any; } /** Get PK using an Entity Index */ export interface GetIndex { /** getIndex('User', 'username', 'ntucker') */ (entityKey: string, field: string, value: string): { readonly [indexKey: string]: string | undefined; }; } //# sourceMappingURL=interface.d.ts.map