Created
October 26, 2017 10:52
-
-
Save 8th713/e044ea64a5b2add16c0d4370edee7def to your computer and use it in GitHub Desktop.
type defs for normalizr v3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'normalizr' { | |
declare type Dict<T> = {[key: string]: T} | |
declare type StrategyFunction = (value: any, parent: any, key: string) => any; | |
declare type SchemaFunction = (value: any, parent: any, key: string) => string; | |
declare type MergeFunction = (entityA: any, entityB: any) => any; | |
declare export type EntityOptions = { | |
idAttribute?: string | SchemaFunction; | |
mergeStrategy?: MergeFunction; | |
processStrategy?: StrategyFunction; | |
} | |
declare class EntitySchema { | |
constructor( | |
key: string, | |
definition?: Schema, | |
options?: EntityOptions | |
): EntitySchema; | |
define(definition: Schema): void; | |
key: string; | |
} | |
declare class ArraySchema { | |
constructor( | |
definition: Schema, | |
schemaAttribute?: string | SchemaFunction | |
): ArraySchema; | |
define(definition: Schema): void; | |
} | |
declare class ObjectSchema { | |
constructor( | |
definition: Dict<Schema> | |
): ObjectSchema; | |
define(definition: Schema): void; | |
} | |
declare class UnionSchema { | |
constructor( | |
definition: Schema, | |
schemaAttribute?: string | SchemaFunction | |
): UnionSchema; | |
define(definition: Schema): void; | |
} | |
declare class ValuesSchema { | |
constructor( | |
definition: Schema, | |
schemaAttribute?: string | SchemaFunction | |
): ValuesSchema; | |
define(definition: Schema): void; | |
} | |
declare export type Schema = | |
| EntitySchema | |
| ArraySchema | |
| ObjectSchema | |
| UnionSchema | |
| ValuesSchema | |
| Array<Schema> | |
| Dict<Schema> | |
declare export var schema: { | |
Entity: Class<EntitySchema>, | |
Array: Class<ArraySchema>, | |
Object: Class<ObjectSchema>, | |
Union: Class<UnionSchema>, | |
Values: Class<ValuesSchema>, | |
} | |
declare export function normalize( | |
data: any, | |
schema: Schema | |
): { | |
entities: { | |
[key: string]: { | |
[key: string]: any | |
} | |
}, | |
result: any | |
}; | |
declare export function denormalize( | |
input: any, | |
schema: Schema, | |
entities: any | |
): any; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment