forked from mobxjs/serializr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serializr.d.ts
76 lines (50 loc) · 3.25 KB
/
serializr.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// TODO: put this in the source files, and extract it, to preserve comments
export interface Context {
json: any;
target: any;
parentContext: Context;
args: any;
}
export type Factory<T> = (context: Context) => T
export interface PropSchema {
serializer(sourcePropertyValue: any): any;
deserializer(jsonValue: any, callback: (err: any, targetPropertyValue: any) => void, context: Context, currentPropertyValue: any): void;
}
export type Props = {
[propName:string]: boolean | PropSchema
}
export interface ModelSchema<T> {
factory: Factory<T>,
props: Props
}
export type Clazz<T> = new(...args: any[]) => T;
export type ClazzOrModelSchema<T> = ModelSchema<T> | Clazz<T>;
export function createSimpleSchema<T extends Object>(props: Props): ModelSchema<T>;
export function createModelSchema<T extends Object>(clazz: Clazz<T>, props: Props, factory?: Factory<T>): ModelSchema<T>;
export function serializable(propSchema: PropSchema | boolean): (target: Object, key: string, baseDescriptor?: PropertyDescriptor) => void;
export function serializable(target: Object, key: string, baseDescriptor?: PropertyDescriptor): void;
export function getDefaultModelSchema<T>(clazz: Clazz<T>): ModelSchema<T>;
export function setDefaultModelSchema<T>(clazz: Clazz<T>, modelschema: ModelSchema<T>): void;
export function serialize<T>(modelschema: ClazzOrModelSchema<T>, instance: T): any;
export function serialize<T>(instance: T): any;
export function deserialize<T>(modelschema: ClazzOrModelSchema<T>, jsonArray: any[], callback?: (err: any, result: T[]) => void, customArgs?: any): T[];
export function deserialize<T>(modelschema: ClazzOrModelSchema<T>, json: any, callback?: (err: any, result: T) => void, customArgs?: any): T;
export function update<T>(modelschema: ClazzOrModelSchema<T>, instance:T, json: any, callback?: (err: any, result: T) => void, customArgs?: any): void;
export function update<T>(instance:T, json: any, callback?: (err: any, result: T) => void, customArgs?: any): void;
export function primitive(): PropSchema;
export function identifier(registerFn?: (id: any, value: any, context: Context) => void): PropSchema;
export function date(): PropSchema;
export function alias(jsonName: string, propSchema?: PropSchema | boolean): PropSchema;
export function child(modelschema: ClazzOrModelSchema<any>): PropSchema;
export function object(modelschema: ClazzOrModelSchema<any>): PropSchema;
export type RefLookupFunction = (id: string, callback: (err: any, result: any) => void) => void;
export type RegisterFunction = (id: any, object: any, context: Context) => void;
export function ref(modelschema: ClazzOrModelSchema<any>, lookupFn?: RefLookupFunction): PropSchema;
export function ref(identifierAttr: string, lookupFn: RefLookupFunction): PropSchema;
export function reference(modelschema: ClazzOrModelSchema<any>, lookupFn?: RefLookupFunction): PropSchema;
export function reference(identifierAttr: string, lookupFn: RefLookupFunction): PropSchema;
export function list(propSchema: PropSchema): PropSchema;
export function map(propSchema: PropSchema): PropSchema;
export function custom(serializer: (value: any) => any, deserializer: (jsonValue: any) => any): PropSchema;
export function serializeAll<T extends Function>(clazz: T): T
export const SKIP: {}