forked from mobxjs/serializr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
80 lines (73 loc) · 2.16 KB
/
types.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
77
78
79
80
import Context from "../core/Context"
import { SKIP } from "../constants"
/**
* Can be passed to function which create `PropSchema`s to set additional properties.
*/
export type AdditionalPropArgs = Pick<
PropSchema,
"beforeDeserialize" | "afterDeserialize" | "pattern"
>
export type PropSerializer = (
sourcePropertyValue: any,
key: string | number | symbol,
sourceObject: any
) => any | typeof SKIP
export type PropDeserializer = (
jsonValue: any,
callback: (err?: any, targetPropertyValue?: any | typeof SKIP) => void,
context: Context,
currentPropertyValue?: any
) => void
export interface PropSchema {
serializer: PropSerializer
deserializer: PropDeserializer
beforeDeserialize?: BeforeDeserializeFunc
afterDeserialize?: AfterDeserializeFunc
/**
* Filter properties to which this schema applies. Used with `ModelSchema.props["*"]`.
*/
pattern?: { test: (propName: string) => boolean }
jsonname?: string
identifier?: true
paramNumber?: number
}
export type AfterDeserializeFunc = (
callback: (err: any, value: any) => void,
err: any,
newValue: any,
jsonValue: any,
jsonParentValue: any,
propNameOrIndex: string | number | symbol,
context: Context,
propDef: PropSchema
) => void
export type BeforeDeserializeFunc = (
callback: (err: any, value: any) => void,
jsonValue: any,
jsonParentValue: any,
propNameOrIndex: string | number,
context: Context,
propDef: PropSchema
) => void
/**
* true is shorthand for `primitive().`
* false/undefined will be ignored
*/
export type Props<T = any> = {
[propName in keyof T]: PropDef
}
export type PropDef = PropSchema | boolean | undefined
export interface ModelSchema<T> {
targetClass?: Clazz<any>
factory: (context: Context) => T
props: Props<T>
extends?: ModelSchema<any>
}
export type Clazz<T> = new (...args: any[]) => T
export type ClazzOrModelSchema<T> = ModelSchema<T> | Clazz<T>
export type RefLookupFunction = (
id: string,
callback: (err: any, result: any) => void,
context: Context
) => void
export type RegisterFunction = (id: any, object: any, context: Context) => void