This repository has been archived by the owner on Mar 20, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,66 @@ | ||
declare namespace schema { | ||
export type StrategyFunction = (value: any, parent: any, key: string) => any; | ||
export type StrategyFunction<T> = (value: any, parent: any, key: string) => T; | ||
export type SchemaFunction = (value: any, parent: any, key: string) => string; | ||
export type MergeFunction = (entityA: any, entityB: any) => any; | ||
|
||
export class Array { | ||
constructor(definition: Schema, schemaAttribute?: string | SchemaFunction) | ||
define(definition: Schema): void | ||
export class Array<T = any> { | ||
constructor(definition: Schema<T>, schemaAttribute?: string | SchemaFunction); | ||
define(definition: Schema): void; | ||
} | ||
|
||
export interface EntityOptions { | ||
idAttribute?: string | SchemaFunction | ||
mergeStrategy?: MergeFunction | ||
processStrategy?: StrategyFunction | ||
export interface EntityOptions<T = any> { | ||
idAttribute?: string | SchemaFunction; | ||
mergeStrategy?: MergeFunction; | ||
processStrategy?: StrategyFunction<T>; | ||
} | ||
|
||
export class Entity { | ||
constructor(key: string | symbol, definition?: Schema, options?: EntityOptions) | ||
define(definition: Schema): void | ||
key: string | ||
export class Entity<T = any> { | ||
constructor(key: string | symbol, definition?: Schema, options?: EntityOptions<T>); | ||
define(definition: Schema): void; | ||
key: string; | ||
getId: SchemaFunction; | ||
_processStrategy: StrategyFunction<T>; | ||
} | ||
|
||
export class Object { | ||
constructor(definition: {[key: string]: Schema}) | ||
define(definition: Schema): void | ||
export class Object<T = any> { | ||
constructor(definition: { [key: string]: Schema<T> }); | ||
define(definition: Schema): void; | ||
} | ||
|
||
export class Union { | ||
constructor(definition: Schema, schemaAttribute?: string | SchemaFunction) | ||
define(definition: Schema): void | ||
export class Union<T = any> { | ||
constructor(definition: Schema<T>, schemaAttribute?: string | SchemaFunction); | ||
define(definition: Schema): void; | ||
} | ||
|
||
export class Values { | ||
constructor(definition: Schema, schemaAttribute?: string | SchemaFunction) | ||
define(definition: Schema): void | ||
export class Values<T = any> { | ||
constructor(definition: Schema<T>, schemaAttribute?: string | SchemaFunction); | ||
define(definition: Schema): void; | ||
} | ||
} | ||
|
||
export type Schema = | ||
schema.Array | | ||
schema.Entity | | ||
schema.Object | | ||
schema.Union | | ||
schema.Values | | ||
schema.Array[] | | ||
schema.Entity[] | | ||
schema.Object[] | | ||
schema.Union[] | | ||
schema.Values[] | | ||
{[key: string]: Schema | Schema[]}; | ||
|
||
export type NormalizedSchema<E, R> = { entities: E, result: R }; | ||
|
||
export function normalize<E = any, R = any>( | ||
interface SimpleObject { | ||
[key: string]: SimpleObject | string | number | boolean | void; | ||
} | ||
|
||
export type Schema<T = any> = | ||
| schema.Entity<T> | ||
| schema.Object<T> | ||
| schema.Union<T> | ||
| schema.Values<T> | ||
| SchemaObject<T> | ||
| SchemaArray<T>; | ||
|
||
export interface SchemaObject<T> { | ||
[key: string]: Schema<T> | string | number | boolean | void | SimpleObject; | ||
} | ||
|
||
export interface SchemaArray<T> extends Array<Schema<T>> {} | ||
|
||
export type NormalizedSchema<E, R> = { entities: E; result: R }; | ||
|
||
export function normalize<T = any, E = { [key: string]: { [key: string]: T } }, R = any>( | ||
data: any, | ||
schema: Schema | ||
schema: Schema<T> | ||
): NormalizedSchema<E, R>; | ||
|
||
export function denormalize( | ||
input: any, | ||
schema: Schema, | ||
entities: any | ||
): any; | ||
export function denormalize(input: any, schema: Schema, entities: any): any; |
This file contains 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
This file contains 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
This file contains 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