diff --git a/package.json b/package.json index 1c1ced92..5fc6902d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.0.1", "description": "Normalizes JSON according to schema for Flux application", "main": "lib/index.js", + "typings": "typings.d.ts", "repository": { "type": "git", "url": "https://github.com/gaearon/normalizr.git" diff --git a/typings.d.ts b/typings.d.ts new file mode 100644 index 00000000..de2afba0 --- /dev/null +++ b/typings.d.ts @@ -0,0 +1,70 @@ +export type SchemaOptions = { + idAttribute?: string | Function; +} + +export type IterableSchemaOptions = { + schemaAttribute?: string | Function; +} + +export type UnionSchemaOptions = { + schemaAttribute: string | Function; +} + +export type NormalizeOptions = { + assignEntity?: Function; + mergeIntoEntity?: Function; +} + +export type NormalizeInput = Object | Array; + +export type NormalizeOutput = { + result: any; + entities?: any; +} + +export class Schema { + constructor (key: string, options?: SchemaOptions); + + define(schema: SchemaMap): void; + getKey(): string; + getIdAttribute(): string; +} + +export class IterableSchema { + constructor (schema: SchemaValue, options?: IterableSchemaOptions); + + getItemSchema(): SchemaValue; +} + +export class UnionSchema { + constructor (schema: SchemaValue, options: UnionSchemaOptions); + + getItemSchema(): SchemaValue; +} + +export type SchemaValue = Schema | IterableSchema | UnionSchema | SchemaMap; + +export type SchemaMap = { + [key: string]: SchemaValue; +} + +export function arrayOf( + schema: SchemaValue, + options?: IterableSchemaOptions +): IterableSchema; + +export function valuesOf( + schema: SchemaValue, + options?: IterableSchemaOptions +): IterableSchema; + +export function unionOf( + schema: SchemaValue, + options?: UnionSchemaOptions +): UnionSchema; + +export function normalize( + input: NormalizeInput, + schema: SchemaValue, + options?: NormalizeOptions +): NormalizeOutput;