-
Notifications
You must be signed in to change notification settings - Fork 93
/
swiz.d.ts
187 lines (167 loc) · 5.91 KB
/
swiz.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
declare module "swiz" {
export class Cidr {
constructor(x:string, y?:string);
isInCIDR(x:any):bool;
}
export class Valve {
constructor(schema:IValveSchema, baton?:any);
setSchema(schema:IValveSchema):Valve;
addFinalValidator(func:(obj:any, callback:(err, cleaned) => void) => void):Valve;
addChainValidator(name:string, description:string, func:(value:any, callback:(err, cleaned) => void) => void):void;
check(obj:any, options:ICheckOptions, callback:(err:any, cleaned:any) => void);
check(obj:any, callback:(err:any, cleaned:any) => void);
checkUpdate(existing:any, obj:any, callback:(err:any, cleaned:any) => void);
help(schema:IValveSchema):any;
}
export interface ICheckOptions {
strict? : bool;
}
interface IValveSchema {
[index: string] : IValveSchemaMember;
}
interface IValveSchemaMember {}
interface IValveSchemaMemberArray extends IValveSchemaMember{
[index: string] : IValveSchemaMember;
}
export function Chain():IChain;
export function chain():IChain;
interface IChain extends IValveSchemaMember {
getValidatorPos(name:string) : number;
hasValidator(name:string) : number;
getValidatorAtPos(pos:number) : IValidator;
isUnique() : IChain;
toUnique() : IChain;
notIPBlacklisted() : IChain;
isCIDR() : IChain;
isEmail() : IChain;
isUrl() : IChain;
isAddressPair() : IChain;
isIP() : IChain;
isIPv4() : IChain;
isIPv6() : IChain;
isHostnameOrIp() : IChain;
isAllowedFQDNOrIP(blacklist?:string[]) : IChain;
isHostname() : IChain;
isAlpha() : IChain;
isAlphanumeric() : IChain;
isNumeric() : IChain;
isInt() : IChain;
isLowercase() : IChain;
isUppercase() : IChain;
isDecimal() : IChain;
isFloat() : IChain;
notNull() : IChain;
isNull() : IChain;
notEmpty() : IChain;
equals(arg:any) : IChain;
contains(arg:any): IChain;
notContains(arg): IChain;
notIn(values:any[], caseSensitive?:bool): IChain;
regex(pattern:string, modifiers);
is(pattern:string, modifiers?:string): IChain;
notRegex(pattern:string, modifiers?:string): IChain;
not(pattern:string, modifiers:string) : IChain;
len(min:number, max?:number): IChain;
numItems(min:number, max:number): IChain;
toFloat(): IChain;
toInt(): IChain;
toBoolean(): IChain;
toBooleanStrict(): IChain;
entityDecode(): IChain;
entityEncode(): IChain;
trim(chars?:string): IChain;
ltrim(chars?:string): IChain;
rtrim(chars:string): IChain;
ifNull(replace:string): IChain;
xss(is_image?:bool) : IChain;
enumerated(map:any) : IChain;
inArray(array:any[]) : IChain;
isString() : IChain;
isBoolean() : IChain;
range(min:any, max:any) : IChain;
optional() : IChain;
isPort() : IChain;
isV1UUID() : IChain;
immutable() : IChain;
updateRequired() : IChain;
isArray(chain:IChain) : IChain;
isHash(keyChain:IChain, valueChain:IChain) : IChain;
rename(target:string) : IChain;
custom(name:string) : IChain;
}
export function defToValve(def:struct.IObj[]):IValveSchema[];
export class Swiz {
constructor(defs:struct.IObj[], options?:ISwizOptions);
buildObject(obj:any, callback:(err:any, result:any) => void):void;
buildObjectSync(obj:any):any;
serializeJson(obj:any):string;
serializeXml(obj:any):string;
deserializeXml(xml:string):any;
serialize(mode:SERIALIZATION, version:number, obj: ISerializable, callback:(err:any, result:string) => void);
serializeForPagination(mode:SERIALIZATION, array:any[], metadata:any, callback:(err:any, result:string) => void);
deserialize(mode:SERIALIZATION, version:number, raw:string, callback:(err:any, result:any) => void);
getFieldDefinition(stype:string, name:string):struct.IField;
}
export interface ISerializable {
getSerializerType() : string;
}
export interface ISwizOptions {
stripNulls?: bool;
stripSerializerType?: bool;
for? : string;
}
interface IValidator {
name: string;
func(value, baton, callback) : void;
help: string;
}
export function stripSerializerTypes(obj:any):any;
export module struct
{
export function Obj(name:string, options?:IObjOptions):IObj;
export function Field(name:string, options?:IFieldOptions):IField;
export function coerce(value:any, coerceTo:string):any;
interface IObj {
name : string;
options : IObjOptions;
singular : string;
plural : string;
fields : IField[];
}
interface IField {
name : string;
options : IFieldOptions;
src : string;
singular : string;
plural : string;
desc? : string;
val? : IChain;
attribute : bool;
enumerated : bool;
ignorePublic : bool;
filterFrom : string[];
coerceTo :any;
}
export interface IObjOptions {
singular? : string;
plural? : string;
fields? : IField[];
}
export interface IFieldOptions {
src? : string;
singular? : string;
plural? : string;
desc? : string;
val? : IChain;
attribute? : bool;
enumerated? : any;
ignorePublic? : bool;
filterFrom? : string[];
coerceTo? : string;
}
}
export enum SERIALIZATION {
SERIALIZATION_JSON,
SERIALIZATION_XML
}
}