Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

Commit

Permalink
Add type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
unindented committed Apr 8, 2016
1 parent 81d95dd commit 443b079
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
70 changes: 70 additions & 0 deletions typings.d.ts
Original file line number Diff line number Diff line change
@@ -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<Object>;

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;

0 comments on commit 443b079

Please sign in to comment.