forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swiz.d.ts
195 lines (173 loc) · 5.5 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
188
189
190
191
192
193
194
195
// Type definitions for swiz
// Project: https://github.com/racker/node-swiz
// Definitions by: Jeff Goddard <https://github.com/jedigo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Imported from: https://github.com/soywiz/typescript-node-definitions/swiz.d.ts
declare module "swiz" {
export class Cidr {
constructor(x: string, y?: string);
isInCIDR(x: any): boolean;
}
export class Valve {
constructor(schema: IValveSchema, baton?: any);
setSchema(schema: IValveSchema): Valve;
addFinalValidator(func: (obj: any, callback: (err: Error, cleaned: any) => void) => void): Valve;
addChainValidator(name: string, description: string, func: (value: any, callback: (err: Error, cleaned: any) => void) => void): void;
check(obj: any, options: ICheckOptions, callback: (err: any, cleaned: any) => void): void;
check(obj: any, callback: (err: any, cleaned: any) => void): void;
checkUpdate(existing: any, obj: any, callback: (err: any, cleaned: any) => void): void;
help(schema: IValveSchema): any;
}
export interface ICheckOptions {
strict?: boolean;
}
export interface IValveSchema {
[index: string]: IValveSchemaMember;
}
export interface IValveSchemaMember {}
export interface IValveSchemaMemberArray extends IValveSchemaMember {
[index: string]: IValveSchemaMember;
}
export function Chain(): IChain;
export function chain(): IChain;
export 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: any): IChain;
notIn(values: any[], caseSensitive?: boolean): IChain;
regex(pattern: RegExp): IChain;
regex(pattern: string, modifiers?: string): IChain;
is(pattern: string, modifiers?: string): IChain;
notRegex(pattern: RegExp): 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?: boolean): 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): void;
serializeForPagination(mode: SERIALIZATION, array: any[], metadata: any, callback: (err: any, result: string) => void): void;
deserialize(mode: SERIALIZATION, version: number, raw: string, callback: (err: any, result: any) => void): void;
getFieldDefinition(stype: string, name: string): struct.IField;
}
export interface ISerializable {
getSerializerType(): string;
}
export interface ISwizOptions {
stripNulls?: boolean;
stripSerializerType?: boolean;
for?: string;
}
interface IValidator {
name: string;
func(value: any, baton: any, callback: Function): 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;
export interface IObj {
name: string;
options: IObjOptions;
singular: string;
plural: string;
fields: IField[];
}
export interface IField {
name: string;
options: IFieldOptions;
src: string;
singular: string;
plural: string;
desc?: string;
val?: IChain;
attribute: boolean;
enumerated: boolean;
ignorePublic: boolean;
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?: boolean;
enumerated?: any;
ignorePublic?: boolean;
filterFrom?: string[];
coerceTo?: string;
}
}
export enum SERIALIZATION {
SERIALIZATION_JSON,
SERIALIZATION_XML
}
}