vest 4.0.0-dev-31f012 → 4.0.0-dev-e266d9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -52
- package/README.md +2 -112
- package/dist/cjs/compose.js +7 -0
- package/dist/cjs/compounds.js +7 -0
- package/dist/cjs/enforce/compose.development.js +139 -0
- package/dist/cjs/enforce/compose.production.js +1 -0
- package/dist/cjs/enforce/compounds.development.js +132 -0
- package/dist/cjs/enforce/compounds.production.js +1 -0
- package/dist/cjs/enforce/package.json +1 -0
- package/dist/cjs/enforce/schema.development.js +144 -0
- package/dist/cjs/enforce/schema.production.js +1 -0
- package/dist/cjs/schema.js +7 -0
- package/dist/cjs/vest.development.js +504 -1034
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/enforce/compose.development.js +137 -0
- package/dist/es/enforce/compose.production.js +1 -0
- package/dist/es/enforce/compounds.development.js +130 -0
- package/dist/es/enforce/compounds.production.js +1 -0
- package/dist/es/enforce/package.json +1 -0
- package/dist/es/enforce/schema.development.js +140 -0
- package/dist/es/enforce/schema.production.js +1 -0
- package/dist/es/vest.development.js +497 -1033
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +143 -0
- package/dist/umd/enforce/compose.production.js +1 -0
- package/dist/umd/enforce/compounds.development.js +136 -0
- package/dist/umd/enforce/compounds.production.js +1 -0
- package/dist/umd/enforce/schema.development.js +148 -0
- package/dist/umd/enforce/schema.production.js +1 -0
- package/dist/umd/vest.development.js +1693 -2226
- package/dist/umd/vest.production.js +1 -1
- package/enforce/compose/package.json +7 -0
- package/enforce/compounds/package.json +7 -0
- package/enforce/schema/package.json +7 -0
- package/package.json +107 -13
- package/testUtils/mockThrowError.ts +16 -0
- package/types/enforce/compose.d.ts +134 -0
- package/types/enforce/compounds.d.ts +146 -0
- package/types/enforce/schema.d.ts +151 -0
- package/types/vest.d.ts +31 -203
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
type DropFirst<T extends unknown[]> = T extends [
|
|
2
|
+
unknown,
|
|
3
|
+
...infer U
|
|
4
|
+
] ? U : never;
|
|
5
|
+
type TStringable = string | ((...args: any[]) => string);
|
|
6
|
+
type TRuleReturn = boolean | {
|
|
7
|
+
pass: boolean;
|
|
8
|
+
message?: TStringable;
|
|
9
|
+
};
|
|
10
|
+
type TRuleDetailedResult = {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message?: string;
|
|
13
|
+
};
|
|
14
|
+
type TArgs = any[];
|
|
15
|
+
type TBaseRules = typeof baseRules;
|
|
16
|
+
type KBaseRules = keyof TBaseRules;
|
|
17
|
+
declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
|
|
18
|
+
declare function endsWith(value: string, arg1: string): boolean;
|
|
19
|
+
declare function equals(value: unknown, arg1: unknown): boolean;
|
|
20
|
+
declare function greaterThan(value: number | string, gt: number | string): boolean;
|
|
21
|
+
declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
|
|
22
|
+
declare function inside(value: unknown, arg1: string | unknown[]): boolean;
|
|
23
|
+
// The module is named "isArrayValue" since it
|
|
24
|
+
// is conflicting with a nested npm dependency.
|
|
25
|
+
// We may need to revisit this in the future.
|
|
26
|
+
declare function isArray(value: unknown): value is Array<unknown>;
|
|
27
|
+
declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
|
|
28
|
+
declare function isBlank(value: unknown): boolean;
|
|
29
|
+
declare function isBoolean(value: unknown): value is boolean;
|
|
30
|
+
declare function isEmpty(value: unknown): boolean;
|
|
31
|
+
declare function isNaN(value: unknown): boolean;
|
|
32
|
+
declare function isNegative(value: number | string): boolean;
|
|
33
|
+
declare function isNull(value: unknown): value is null;
|
|
34
|
+
declare function isNullish(value: any): value is null | undefined;
|
|
35
|
+
declare function isNumber(value: unknown): value is number;
|
|
36
|
+
declare function isNumeric(value: string | number): boolean;
|
|
37
|
+
declare function isStringValue(v: unknown): v is string;
|
|
38
|
+
declare function isTruthy(value: unknown): boolean;
|
|
39
|
+
declare function isUndefined(value?: unknown): boolean;
|
|
40
|
+
declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
41
|
+
declare function lessThan(value: string | number, lt: string | number): boolean;
|
|
42
|
+
declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
|
|
43
|
+
declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
|
|
44
|
+
declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
45
|
+
declare function matches(value: string, regex: RegExp | string): boolean;
|
|
46
|
+
declare function numberEquals(value: string | number, eq: string | number): boolean;
|
|
47
|
+
declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
|
|
48
|
+
declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
49
|
+
declare function startsWith(value: string, arg1: string): boolean;
|
|
50
|
+
declare const baseRules: {
|
|
51
|
+
condition: typeof condition;
|
|
52
|
+
doesNotEndWith: (value: string, arg1: string) => boolean;
|
|
53
|
+
doesNotStartWith: (value: string, arg1: string) => boolean;
|
|
54
|
+
endsWith: typeof endsWith;
|
|
55
|
+
equals: typeof equals;
|
|
56
|
+
greaterThan: typeof greaterThan;
|
|
57
|
+
greaterThanOrEquals: typeof greaterThanOrEquals;
|
|
58
|
+
gt: typeof greaterThan;
|
|
59
|
+
gte: typeof greaterThanOrEquals;
|
|
60
|
+
inside: typeof inside;
|
|
61
|
+
isArray: typeof isArray;
|
|
62
|
+
isBetween: typeof isBetween;
|
|
63
|
+
isBlank: typeof isBlank;
|
|
64
|
+
isBoolean: typeof isBoolean;
|
|
65
|
+
isEmpty: typeof isEmpty;
|
|
66
|
+
isEven: (value: any) => boolean;
|
|
67
|
+
isFalsy: (value: unknown) => boolean;
|
|
68
|
+
isNaN: typeof isNaN;
|
|
69
|
+
isNegative: typeof isNegative;
|
|
70
|
+
isNotArray: (value: unknown) => boolean;
|
|
71
|
+
isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
|
|
72
|
+
isNotBlank: (value: unknown) => boolean;
|
|
73
|
+
isNotBoolean: (value: unknown) => boolean;
|
|
74
|
+
isNotEmpty: (value: unknown) => boolean;
|
|
75
|
+
isNotNaN: (value: unknown) => boolean;
|
|
76
|
+
isNotNull: (value: unknown) => boolean;
|
|
77
|
+
isNotNullish: (value: any) => boolean;
|
|
78
|
+
isNotNumber: (value: unknown) => boolean;
|
|
79
|
+
isNotNumeric: (value: string | number) => boolean;
|
|
80
|
+
isNotString: (v: unknown) => boolean;
|
|
81
|
+
isNotUndefined: (value?: unknown) => boolean;
|
|
82
|
+
isNull: typeof isNull;
|
|
83
|
+
isNullish: typeof isNullish;
|
|
84
|
+
isNumber: typeof isNumber;
|
|
85
|
+
isNumeric: typeof isNumeric;
|
|
86
|
+
isOdd: (value: any) => boolean;
|
|
87
|
+
isPositive: (value: string | number) => boolean;
|
|
88
|
+
isString: typeof isStringValue;
|
|
89
|
+
isTruthy: typeof isTruthy;
|
|
90
|
+
isUndefined: typeof isUndefined;
|
|
91
|
+
lengthEquals: typeof lengthEquals;
|
|
92
|
+
lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
|
|
93
|
+
lessThan: typeof lessThan;
|
|
94
|
+
lessThanOrEquals: typeof lessThanOrEquals;
|
|
95
|
+
longerThan: typeof longerThan;
|
|
96
|
+
longerThanOrEquals: typeof longerThanOrEquals;
|
|
97
|
+
lt: typeof lessThan;
|
|
98
|
+
lte: typeof lessThanOrEquals;
|
|
99
|
+
matches: typeof matches;
|
|
100
|
+
notEquals: (value: unknown, arg1: unknown) => boolean;
|
|
101
|
+
notInside: (value: unknown, arg1: string | unknown[]) => boolean;
|
|
102
|
+
notMatches: (value: string, regex: string | RegExp) => boolean;
|
|
103
|
+
numberEquals: typeof numberEquals;
|
|
104
|
+
numberNotEquals: (value: string | number, eq: string | number) => boolean;
|
|
105
|
+
shorterThan: typeof shorterThan;
|
|
106
|
+
shorterThanOrEquals: typeof shorterThanOrEquals;
|
|
107
|
+
startsWith: typeof startsWith;
|
|
108
|
+
};
|
|
109
|
+
type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
|
|
110
|
+
[P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
|
|
111
|
+
};
|
|
112
|
+
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
|
|
113
|
+
declare global {
|
|
114
|
+
namespace n4s {
|
|
115
|
+
interface IRules<E> extends TRules<E> {
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
type TLazyRules = n4s.IRules<TLazyRuleMethods>;
|
|
120
|
+
type TLazy = TLazyRules & TLazyRuleMethods &
|
|
121
|
+
// This is a "catch all" hack to make TS happy while not
|
|
122
|
+
// losing type hints
|
|
123
|
+
Record<string, (...args: any[]) => any>;
|
|
124
|
+
interface IShapeObject extends Record<string, any>, Record<string, TLazyRuleRunners> {
|
|
125
|
+
}
|
|
126
|
+
type TLazyRuleMethods = TLazyRuleRunners & {
|
|
127
|
+
message: (message: TLazyMessage) => TLazy;
|
|
128
|
+
};
|
|
129
|
+
type TLazyRuleRunners = {
|
|
130
|
+
test: (value: unknown) => boolean;
|
|
131
|
+
run: (value: unknown) => TRuleDetailedResult;
|
|
132
|
+
};
|
|
133
|
+
type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
|
|
134
|
+
declare function isArrayOf(inputArray: any[], currentRule: TLazy): TRuleDetailedResult;
|
|
135
|
+
declare function loose(inputObject: Record<string, any>, shapeObject: IShapeObject): TRuleDetailedResult;
|
|
136
|
+
declare function optional(value: any, ruleChain: TLazy): TRuleDetailedResult;
|
|
137
|
+
declare function shape(inputObject: Record<string, any>, shapeObject: IShapeObject): TRuleDetailedResult;
|
|
138
|
+
// Help needed improving the typings of this file.
|
|
139
|
+
// Ideally, we'd be able to extend IShapeObject, but that's not possible.
|
|
140
|
+
declare function partial<T extends Record<any, any>>(shapeObject: T): T;
|
|
141
|
+
declare global {
|
|
142
|
+
namespace n4s {
|
|
143
|
+
interface EnforceCustomMatchers<R> {
|
|
144
|
+
isArrayOf: (...args: DropFirst<Parameters<typeof isArrayOf>>) => R;
|
|
145
|
+
loose: (...args: DropFirst<Parameters<typeof loose>>) => R;
|
|
146
|
+
shape: (...args: DropFirst<Parameters<typeof shape>>) => R;
|
|
147
|
+
optional: (...args: DropFirst<Parameters<typeof optional>>) => R;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export { partial };
|
package/types/vest.d.ts
CHANGED
|
@@ -1,181 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
meta: Record<string, any>;
|
|
3
|
-
value: any;
|
|
4
|
-
parent: () => TEnforceContext;
|
|
5
|
-
};
|
|
6
|
-
type DropFirst<T extends unknown[]> = T extends [
|
|
7
|
-
unknown,
|
|
8
|
-
...infer U
|
|
9
|
-
] ? U : never;
|
|
10
|
-
type TStringable = string | ((...args: any[]) => string);
|
|
11
|
-
type TRuleReturn = boolean | {
|
|
12
|
-
pass: boolean;
|
|
13
|
-
message?: TStringable;
|
|
14
|
-
};
|
|
15
|
-
type TRuleDetailedResult = {
|
|
16
|
-
pass: boolean;
|
|
17
|
-
message?: string;
|
|
18
|
-
};
|
|
19
|
-
type TLazyRules = TRules<TLazyRuleMethods>;
|
|
20
|
-
type TLazy = TLazyRules & TLazyRuleMethods;
|
|
21
|
-
type TShapeObject = Record<any, TLazy>;
|
|
22
|
-
type TLazyRuleMethods = TLazyRuleRunners & {
|
|
23
|
-
message: (message: TLazyMessage) => TLazy;
|
|
24
|
-
};
|
|
25
|
-
type TLazyRuleRunners = {
|
|
26
|
-
test: (value: unknown) => boolean;
|
|
27
|
-
run: (value: unknown) => TRuleDetailedResult;
|
|
28
|
-
};
|
|
29
|
-
type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
|
|
30
|
-
declare function allOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
|
|
31
|
-
declare function anyOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
|
|
32
|
-
declare function noneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
|
|
33
|
-
declare function oneOf(value: unknown, ...rules: TLazy[]): TRuleDetailedResult;
|
|
34
|
-
declare function optional(value: any, ruleChain: TLazy): TRuleDetailedResult;
|
|
35
|
-
declare function compounds(): {
|
|
36
|
-
allOf: typeof allOf;
|
|
37
|
-
anyOf: typeof anyOf;
|
|
38
|
-
noneOf: typeof noneOf;
|
|
39
|
-
oneOf: typeof oneOf;
|
|
40
|
-
optional: typeof optional;
|
|
41
|
-
};
|
|
42
|
-
type TCompounds = ReturnType<typeof compounds>;
|
|
43
|
-
type KCompounds = keyof TCompounds;
|
|
44
|
-
type TArgs = any[];
|
|
45
|
-
type TRuleValue = any;
|
|
46
|
-
type TRuleBase = (value: TRuleValue, ...args: TArgs) => TRuleReturn;
|
|
47
|
-
type TRule = Record<string, TRuleBase>;
|
|
48
|
-
type TBaseRules = typeof baseRules;
|
|
49
|
-
type KBaseRules = keyof TBaseRules;
|
|
50
|
-
declare function condition(value: any, callback: (value: any) => TRuleReturn): TRuleReturn;
|
|
51
|
-
declare function endsWith(value: string, arg1: string): boolean;
|
|
52
|
-
declare function equals(value: unknown, arg1: unknown): boolean;
|
|
53
|
-
declare function greaterThan(value: number | string, gt: number | string): boolean;
|
|
54
|
-
declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
|
|
55
|
-
declare function inside(value: unknown, arg1: string | unknown[]): boolean;
|
|
56
|
-
// The module is named "isArrayValue" since it
|
|
57
|
-
// is conflicting with a nested npm dependency.
|
|
58
|
-
// We may need to revisit this in the future.
|
|
59
|
-
declare function isArray(value: unknown): value is Array<unknown>;
|
|
60
|
-
declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
|
|
61
|
-
declare function isBlank(value: unknown): boolean;
|
|
62
|
-
declare function isBoolean(value: unknown): value is boolean;
|
|
63
|
-
declare function isEmpty(value: unknown): boolean;
|
|
64
|
-
declare function isNaN(value: unknown): boolean;
|
|
65
|
-
declare function isNegative(value: number | string): boolean;
|
|
66
|
-
declare function isNull(value: unknown): value is null;
|
|
67
|
-
declare function isNumber(value: unknown): value is number;
|
|
68
|
-
declare function isNumeric(value: string | number): boolean;
|
|
69
|
-
declare function isStringValue(v: unknown): v is string;
|
|
70
|
-
declare function isTruthy(value: unknown): boolean;
|
|
71
|
-
declare function isUndefined(value?: unknown): boolean;
|
|
72
|
-
declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
73
|
-
declare function lessThan(value: string | number, lt: string | number): boolean;
|
|
74
|
-
declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
|
|
75
|
-
declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
|
|
76
|
-
declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
77
|
-
declare function matches(value: string, regex: RegExp | string): boolean;
|
|
78
|
-
declare function numberEquals(value: string | number, eq: string | number): boolean;
|
|
79
|
-
declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
|
|
80
|
-
declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
81
|
-
declare function startsWith(value: string, arg1: string): boolean;
|
|
82
|
-
declare function shape(inputObject: Record<string, any>, shapeObject: TShapeObject): TRuleDetailedResult;
|
|
83
|
-
declare function loose(inputObject: Record<string, any>, shapeObject: TShapeObject): TRuleDetailedResult;
|
|
84
|
-
declare function isArrayOf(inputArray: any[], currentRule: TLazy): TRuleDetailedResult;
|
|
85
|
-
declare const baseRules: {
|
|
86
|
-
condition: typeof condition;
|
|
87
|
-
doesNotEndWith: (value: string, arg1: string) => boolean;
|
|
88
|
-
doesNotStartWith: (value: string, arg1: string) => boolean;
|
|
89
|
-
endsWith: typeof endsWith;
|
|
90
|
-
equals: typeof equals;
|
|
91
|
-
greaterThan: typeof greaterThan;
|
|
92
|
-
greaterThanOrEquals: typeof greaterThanOrEquals;
|
|
93
|
-
gt: typeof greaterThan;
|
|
94
|
-
gte: typeof greaterThanOrEquals;
|
|
95
|
-
inside: typeof inside;
|
|
96
|
-
isArray: typeof isArray;
|
|
97
|
-
isBetween: typeof isBetween;
|
|
98
|
-
isBlank: typeof isBlank;
|
|
99
|
-
isBoolean: typeof isBoolean;
|
|
100
|
-
isEmpty: typeof isEmpty;
|
|
101
|
-
isEven: (value: any) => boolean;
|
|
102
|
-
isFalsy: (value: unknown) => boolean;
|
|
103
|
-
isNaN: typeof isNaN;
|
|
104
|
-
isNegative: typeof isNegative;
|
|
105
|
-
isNotArray: (value: unknown) => boolean;
|
|
106
|
-
isNotBetween: (value: string | number, min: string | number, max: string | number) => boolean;
|
|
107
|
-
isNotBlank: (value: unknown) => boolean;
|
|
108
|
-
isNotBoolean: (value: unknown) => boolean;
|
|
109
|
-
isNotEmpty: (value: unknown) => boolean;
|
|
110
|
-
isNotNaN: (value: unknown) => boolean;
|
|
111
|
-
isNotNull: (value: unknown) => boolean;
|
|
112
|
-
isNotNumber: (value: unknown) => boolean;
|
|
113
|
-
isNotNumeric: (value: string | number) => boolean;
|
|
114
|
-
isNotString: (v: unknown) => boolean;
|
|
115
|
-
isNotUndefined: (value?: unknown) => boolean;
|
|
116
|
-
isNull: typeof isNull;
|
|
117
|
-
isNumber: typeof isNumber;
|
|
118
|
-
isNumeric: typeof isNumeric;
|
|
119
|
-
isOdd: (value: any) => boolean;
|
|
120
|
-
isPositive: (value: string | number) => boolean;
|
|
121
|
-
isString: typeof isStringValue;
|
|
122
|
-
isTruthy: typeof isTruthy;
|
|
123
|
-
isUndefined: typeof isUndefined;
|
|
124
|
-
lengthEquals: typeof lengthEquals;
|
|
125
|
-
lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
|
|
126
|
-
lessThan: typeof lessThan;
|
|
127
|
-
lessThanOrEquals: typeof lessThanOrEquals;
|
|
128
|
-
longerThan: typeof longerThan;
|
|
129
|
-
longerThanOrEquals: typeof longerThanOrEquals;
|
|
130
|
-
lt: typeof lessThan;
|
|
131
|
-
lte: typeof lessThanOrEquals;
|
|
132
|
-
matches: typeof matches;
|
|
133
|
-
notEquals: (value: unknown, arg1: unknown) => boolean;
|
|
134
|
-
notInside: (value: unknown, arg1: string | unknown[]) => boolean;
|
|
135
|
-
notMatches: (value: string, regex: string | RegExp) => boolean;
|
|
136
|
-
numberEquals: typeof numberEquals;
|
|
137
|
-
numberNotEquals: (value: string | number, eq: string | number) => boolean;
|
|
138
|
-
shorterThan: typeof shorterThan;
|
|
139
|
-
shorterThanOrEquals: typeof shorterThanOrEquals;
|
|
140
|
-
startsWith: typeof startsWith;
|
|
141
|
-
} & {
|
|
142
|
-
allOf: typeof allOf;
|
|
143
|
-
anyOf: typeof anyOf;
|
|
144
|
-
noneOf: typeof noneOf;
|
|
145
|
-
oneOf: typeof oneOf;
|
|
146
|
-
optional: typeof optional;
|
|
147
|
-
} & {
|
|
148
|
-
shape: typeof shape;
|
|
149
|
-
loose: typeof loose;
|
|
150
|
-
isArrayOf: typeof isArrayOf;
|
|
151
|
-
};
|
|
152
|
-
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
|
|
153
|
-
declare global {
|
|
154
|
-
namespace n4s {
|
|
155
|
-
interface EnforceCustomMatchers<R> {
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules & E> & Record<string, (...args: TArgs) => TRules & E> & {
|
|
160
|
-
[P in KCompounds]: (...args: DropFirst<Parameters<TCompounds[P]>> | TArgs) => TRules & E;
|
|
161
|
-
} & {
|
|
162
|
-
[P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules & E;
|
|
163
|
-
};
|
|
164
|
-
declare function enforceEager(value: TRuleValue): TRules;
|
|
165
|
-
type TEnforceEager = typeof enforceEager;
|
|
166
|
-
// Help needed improving the typings of this file.
|
|
167
|
-
// Ideally, we'd be able to extend TShapeObject, but that's not possible.
|
|
168
|
-
declare function partial<T extends Record<any, any>>(shapeObject: T): T;
|
|
169
|
-
declare function modifiers(): {
|
|
170
|
-
partial: typeof partial;
|
|
171
|
-
};
|
|
172
|
-
type TModifiers = ReturnType<typeof modifiers>;
|
|
173
|
-
declare const enforce: TEnforce;
|
|
174
|
-
type TEnforce = TEnforceEager & TLazyRules & TEnforceMethods;
|
|
175
|
-
type TEnforceMethods = TModifiers & {
|
|
176
|
-
context: () => TEnforceContext;
|
|
177
|
-
extend: (customRules: TRule) => void;
|
|
178
|
-
};
|
|
1
|
+
import { enforce } from 'n4s';
|
|
179
2
|
/**
|
|
180
3
|
* Reads the testObjects list and gets full validation result from it.
|
|
181
4
|
*/
|
|
@@ -234,34 +57,46 @@ interface IDone {
|
|
|
234
57
|
cb: (res: TDraftResult) => void
|
|
235
58
|
]): IVestResult;
|
|
236
59
|
}
|
|
237
|
-
|
|
238
|
-
declare function create<T extends (...args: any[]) => void>(suiteCallback: T): {
|
|
239
|
-
(...args: Parameters<T>): IVestResult;
|
|
60
|
+
type CreateProperties = {
|
|
240
61
|
get: () => TDraftResult;
|
|
241
62
|
reset: () => void;
|
|
242
63
|
remove: (fieldName: string) => void;
|
|
243
64
|
};
|
|
65
|
+
type CB = (...args: any[]) => void;
|
|
66
|
+
type SuiteReturnType<T extends CB> = {
|
|
67
|
+
(...args: Parameters<T>): IVestResult;
|
|
68
|
+
} & CreateProperties;
|
|
69
|
+
declare function create<T extends CB>(suiteName: string, suiteCallback: T): SuiteReturnType<T>;
|
|
70
|
+
declare function create<T extends CB>(suiteCallback: T): SuiteReturnType<T>;
|
|
71
|
+
declare function each<T>(list: T[], callback: (arg: T, index: number) => void): void;
|
|
72
|
+
declare enum TestSeverity {
|
|
73
|
+
Error = "error",
|
|
74
|
+
Warning = "warning"
|
|
75
|
+
}
|
|
244
76
|
declare class VestTest {
|
|
245
77
|
fieldName: string;
|
|
246
78
|
testFn: TTestFn;
|
|
247
79
|
asyncTest?: TAsyncTest;
|
|
248
80
|
groupName?: string;
|
|
249
81
|
message?: string;
|
|
82
|
+
key?: null | string;
|
|
250
83
|
id: string;
|
|
251
|
-
|
|
84
|
+
severity: TestSeverity;
|
|
252
85
|
status: KStatus;
|
|
253
|
-
constructor(fieldName: string, testFn: TTestFn, { message, groupName }?: {
|
|
86
|
+
constructor(fieldName: string, testFn: TTestFn, { message, groupName, key }?: {
|
|
254
87
|
message?: string;
|
|
255
88
|
groupName?: string;
|
|
89
|
+
key?: string;
|
|
256
90
|
});
|
|
257
91
|
run(): TTestResult;
|
|
258
92
|
setStatus(status: KStatus): void;
|
|
93
|
+
warns(): boolean;
|
|
259
94
|
setPending(): void;
|
|
260
95
|
fail(): void;
|
|
261
96
|
done(): void;
|
|
262
97
|
warn(): void;
|
|
263
98
|
isFinalStatus(): boolean;
|
|
264
|
-
skip(): void;
|
|
99
|
+
skip(force?: boolean): void;
|
|
265
100
|
cancel(): void;
|
|
266
101
|
omit(): void;
|
|
267
102
|
valueOf(): boolean;
|
|
@@ -295,35 +130,28 @@ declare function skip(item: TExclusionItem): void;
|
|
|
295
130
|
declare namespace skip {
|
|
296
131
|
var group: (item: TExclusionItem) => void;
|
|
297
132
|
}
|
|
298
|
-
declare function skipWhen(conditional: boolean | ((...args: any[]) => boolean), callback: (...args: any[]) => void): void;
|
|
299
|
-
/**
|
|
300
|
-
* Sets a running test to warn only mode.
|
|
301
|
-
*/
|
|
302
|
-
declare function warn(): void;
|
|
303
133
|
/**
|
|
304
134
|
* Runs a group callback.
|
|
305
135
|
*/
|
|
306
136
|
declare function group(groupName: string, tests: () => void): void;
|
|
307
|
-
declare function optional
|
|
137
|
+
declare function optional(optionals: TOptionalsInput): void;
|
|
308
138
|
type TOptionalsInput = string | string[] | TOptionalsObject;
|
|
309
139
|
type TOptionalsObject = Record<string, () => boolean>;
|
|
310
|
-
declare function
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
declare function testBase(fieldName: string,
|
|
315
|
-
cb: TTestFn
|
|
316
|
-
]): VestTest;
|
|
140
|
+
declare function skipWhen(conditional: boolean | ((draft: TDraftResult) => boolean), callback: (...args: any[]) => void): void;
|
|
141
|
+
declare function testBase(fieldName: string, message: string, cb: TTestFn): VestTest;
|
|
142
|
+
declare function testBase(fieldName: string, cb: TTestFn): VestTest;
|
|
143
|
+
declare function testBase(fieldName: string, message: string, cb: TTestFn, key: string): VestTest;
|
|
144
|
+
declare function testBase(fieldName: string, cb: TTestFn, key: string): VestTest;
|
|
317
145
|
declare const _default: typeof testBase & {
|
|
318
|
-
each: (table: any[]) => {
|
|
319
|
-
(fieldName: TStringable, message: TStringable, cb: (...args: any[]) => TTestResult): VestTest[];
|
|
320
|
-
(fieldName: TStringable, cb: (...args: any[]) => TTestResult): VestTest[];
|
|
321
|
-
};
|
|
322
146
|
memo: {
|
|
323
147
|
(fieldName: string, test: TTestFn, deps: unknown[]): VestTest;
|
|
324
148
|
(fieldName: string, message: string, test: TTestFn, deps: unknown[]): VestTest;
|
|
325
149
|
};
|
|
326
150
|
};
|
|
327
151
|
declare const test: typeof _default;
|
|
328
|
-
|
|
329
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Sets a running test to warn only mode.
|
|
154
|
+
*/
|
|
155
|
+
declare function warn(): void;
|
|
156
|
+
declare const VERSION = "4.0.0-dev-e266d9";
|
|
157
|
+
export { test, create, each, only, skip, warn, group, optional, skipWhen, enforce, VERSION };
|