vest 4.3.0 → 4.3.1

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.
@@ -2,19 +2,19 @@ type DropFirst<T extends unknown[]> = T extends [
2
2
  unknown,
3
3
  ...infer U
4
4
  ] ? U : never;
5
- type TStringable = string | ((...args: any[]) => string);
6
- type TRuleReturn = boolean | {
5
+ type Stringable = string | ((...args: any[]) => string);
6
+ type RuleReturn = boolean | {
7
7
  pass: boolean;
8
- message?: TStringable;
8
+ message?: Stringable;
9
9
  };
10
- type TRuleDetailedResult = {
10
+ type RuleDetailedResult = {
11
11
  pass: boolean;
12
12
  message?: string;
13
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;
14
+ type Args = any[];
15
+ type BaseRules = typeof baseRules;
16
+ type KBaseRules = keyof BaseRules;
17
+ declare function condition(value: any, callback: (value: any) => RuleReturn): RuleReturn;
18
18
  declare function endsWith(value: string, arg1: string): boolean;
19
19
  declare function equals(value: unknown, arg1: unknown): boolean;
20
20
  declare function greaterThan(value: number | string, gt: number | string): boolean;
@@ -113,37 +113,37 @@ declare const baseRules: {
113
113
  shorterThanOrEquals: typeof shorterThanOrEquals;
114
114
  startsWith: typeof startsWith;
115
115
  };
116
- type TRules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<TRules<E> & E> & Record<string, (...args: TArgs) => TRules<E> & E> & {
117
- [P in KBaseRules]: (...args: DropFirst<Parameters<TBaseRules[P]>> | TArgs) => TRules<E> & E;
116
+ type Rules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<Rules<E> & E> & Record<string, (...args: Args) => Rules<E> & E> & {
117
+ [P in KBaseRules]: (...args: DropFirst<Parameters<BaseRules[P]>> | Args) => Rules<E> & E;
118
118
  };
119
119
  /* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
120
120
  declare global {
121
121
  namespace n4s {
122
- interface IRules<E> extends TRules<E> {
122
+ interface IRules<E> extends Rules<E> {
123
123
  }
124
124
  }
125
125
  }
126
- type TLazyRules = n4s.IRules<TLazyRuleMethods>;
127
- type TLazy = TLazyRules & TLazyRuleMethods &
126
+ type LazyRules = n4s.IRules<LazyRuleMethods>;
127
+ type Lazy = LazyRules & LazyRuleMethods &
128
128
  // This is a "catch all" hack to make TS happy while not
129
129
  // losing type hints
130
130
  Record<string, (...args: any[]) => any>;
131
- type TLazyRuleMethods = TLazyRuleRunners & {
132
- message: (message: TLazyMessage) => TLazy;
131
+ type LazyRuleMethods = LazyRuleRunners & {
132
+ message: (message: LazyMessage) => Lazy;
133
133
  };
134
- type TLazyRuleRunners = {
134
+ type LazyRuleRunners = {
135
135
  test: (value: unknown) => boolean;
136
- run: (value: unknown) => TRuleDetailedResult;
136
+ run: (value: unknown) => RuleDetailedResult;
137
137
  };
138
- type TLazyMessage = string | ((value: unknown, originalMessage?: TStringable) => string);
139
- declare function isArrayOf(inputArray: any[], currentRule: TLazyRuleRunners): TRuleDetailedResult;
140
- interface IShapeObject extends Record<string, any>, Record<string, TLazyRuleRunners> {
138
+ type LazyMessage = string | ((value: unknown, originalMessage?: Stringable) => string);
139
+ declare function isArrayOf(inputArray: any[], currentRule: LazyRuleRunners): RuleDetailedResult;
140
+ interface ShapeObject extends Record<string, any>, Record<string, LazyRuleRunners> {
141
141
  }
142
- declare function loose(inputObject: Record<string, any>, shapeObject: IShapeObject): TRuleDetailedResult;
143
- declare function optional(value: any, ruleChain: TLazy): TRuleDetailedResult;
144
- declare function shape(inputObject: Record<string, any>, shapeObject: IShapeObject): TRuleDetailedResult;
142
+ declare function loose(inputObject: Record<string, any>, shapeObject: ShapeObject): RuleDetailedResult;
143
+ declare function optional(value: any, ruleChain: Lazy): RuleDetailedResult;
144
+ declare function shape(inputObject: Record<string, any>, shapeObject: ShapeObject): RuleDetailedResult;
145
145
  // Help needed improving the typings of this file.
146
- // Ideally, we'd be able to extend IShapeObject, but that's not possible.
146
+ // Ideally, we'd be able to extend ShapeObject, but that's not possible.
147
147
  declare function partial<T extends Record<any, any>>(shapeObject: T): T;
148
148
  declare global {
149
149
  namespace n4s {
@@ -19,13 +19,14 @@ type SummaryBase = {
19
19
  warnCount: number;
20
20
  testCount: number;
21
21
  };
22
- declare function getErrors(): Record<string, string[]>;
22
+ type FailureMessages = Record<string, string[]>;
23
+ declare function getErrors(): FailureMessages;
23
24
  declare function getErrors(fieldName?: string): string[];
24
- declare function getWarnings(): Record<string, string[]>;
25
+ declare function getWarnings(): FailureMessages;
25
26
  declare function getWarnings(fieldName?: string): string[];
26
- declare function getErrorsByGroup(groupName: string): Record<string, string[]>;
27
+ declare function getErrorsByGroup(groupName: string): FailureMessages;
27
28
  declare function getErrorsByGroup(groupName: string, fieldName: string): string[];
28
- declare function getWarningsByGroup(groupName: string): Record<string, string[]>;
29
+ declare function getWarningsByGroup(groupName: string): FailureMessages;
29
30
  declare function getWarningsByGroup(groupName: string, fieldName: string): string[];
30
31
  declare function hasErrors(fieldName?: string): boolean;
31
32
  declare function hasWarnings(fieldName?: string): boolean;
@@ -48,9 +49,9 @@ type SuiteResult = ReturnType<typeof genTestsSummary> & {
48
49
  getWarningsByGroup: typeof getWarningsByGroup;
49
50
  };
50
51
  type SuiteRunResult = SuiteResult & {
51
- done: IDone;
52
+ done: Done;
52
53
  };
53
- interface IDone {
54
+ interface Done {
54
55
  (...args: [
55
56
  cb: (res: SuiteResult) => void
56
57
  ]): SuiteRunResult;
package/types/vest.d.ts CHANGED
@@ -5,20 +5,20 @@ declare enum TestSeverity {
5
5
  }
6
6
  declare class VestTest {
7
7
  fieldName: string;
8
- testFn: TTestFn;
9
- asyncTest?: TAsyncTest;
8
+ testFn: TestFn;
9
+ asyncTest?: AsyncTest;
10
10
  groupName?: string;
11
11
  message?: string;
12
12
  key?: null | string;
13
13
  id: string;
14
14
  severity: TestSeverity;
15
15
  status: KStatus;
16
- constructor(fieldName: string, testFn: TTestFn, { message, groupName, key }?: {
16
+ constructor(fieldName: string, testFn: TestFn, { message, groupName, key }?: {
17
17
  message?: string;
18
18
  groupName?: string;
19
19
  key?: string;
20
20
  });
21
- run(): TTestResult;
21
+ run(): TestResult;
22
22
  setStatus(status: KStatus): void;
23
23
  warns(): boolean;
24
24
  setPending(): void;
@@ -44,10 +44,11 @@ declare class VestTest {
44
44
  isWarning(): boolean;
45
45
  statusEquals(status: KStatus): boolean;
46
46
  }
47
- type TAsyncTest = Promise<string | void>;
48
- type TTestResult = TAsyncTest | boolean | void;
49
- type TTestFn = () => TTestResult;
47
+ type AsyncTest = Promise<string | void>;
48
+ type TestResult = AsyncTest | boolean | void;
49
+ type TestFn = () => TestResult;
50
50
  type KStatus = "UNTESTED" | "SKIPPED" | "FAILED" | "WARNING" | "PASSING" | "PENDING" | "CANCELED" | "OMITTED";
51
+ type CB = (...args: any[]) => void;
51
52
  /**
52
53
  * Reads the testObjects list and gets full validation result from it.
53
54
  */
@@ -69,13 +70,14 @@ type SummaryBase = {
69
70
  warnCount: number;
70
71
  testCount: number;
71
72
  };
72
- declare function getErrors(): Record<string, string[]>;
73
+ type FailureMessages = Record<string, string[]>;
74
+ declare function getErrors(): FailureMessages;
73
75
  declare function getErrors(fieldName?: string): string[];
74
- declare function getWarnings(): Record<string, string[]>;
76
+ declare function getWarnings(): FailureMessages;
75
77
  declare function getWarnings(fieldName?: string): string[];
76
- declare function getErrorsByGroup(groupName: string): Record<string, string[]>;
78
+ declare function getErrorsByGroup(groupName: string): FailureMessages;
77
79
  declare function getErrorsByGroup(groupName: string, fieldName: string): string[];
78
- declare function getWarningsByGroup(groupName: string): Record<string, string[]>;
80
+ declare function getWarningsByGroup(groupName: string): FailureMessages;
79
81
  declare function getWarningsByGroup(groupName: string, fieldName: string): string[];
80
82
  declare function hasErrors(fieldName?: string): boolean;
81
83
  declare function hasWarnings(fieldName?: string): boolean;
@@ -98,9 +100,9 @@ type SuiteResult = ReturnType<typeof genTestsSummary> & {
98
100
  getWarningsByGroup: typeof getWarningsByGroup;
99
101
  };
100
102
  type SuiteRunResult = SuiteResult & {
101
- done: IDone;
103
+ done: Done;
102
104
  };
103
- interface IDone {
105
+ interface Done {
104
106
  (...args: [
105
107
  cb: (res: SuiteResult) => void
106
108
  ]): SuiteRunResult;
@@ -115,7 +117,6 @@ type CreateProperties = {
115
117
  resetField: (fieldName: string) => void;
116
118
  remove: (fieldName: string) => void;
117
119
  };
118
- type CB = (...args: any[]) => void;
119
120
  type Suite<T extends CB> = {
120
121
  (...args: Parameters<T>): SuiteRunResult;
121
122
  } & CreateProperties;
@@ -158,35 +159,35 @@ declare enum Modes {
158
159
  }
159
160
  type NestedArray<T> = Array<NestedArray<T> | T>;
160
161
  // eslint-disable-next-line max-lines-per-function
161
- declare function createState(onStateChange?: (...args: unknown[]) => unknown): TCreateStateReturn;
162
- type TStateInput<S> = S | ((prevState?: S) => S);
163
- type TSetStateInput<S> = S | ((prevState: S) => S);
164
- type TState = ReturnType<typeof createState>;
165
- type TStateHandlerReturn<S> = [
162
+ declare function createState(onStateChange?: (...args: unknown[]) => unknown): CreateStateReturn;
163
+ type StateInput<S> = S | ((prevState?: S) => S);
164
+ type SetStateInput<S> = S | ((prevState: S) => S);
165
+ type State = ReturnType<typeof createState>;
166
+ type StateHandlerReturn<S> = [
166
167
  S,
167
- (nextState: TSetStateInput<S>) => void
168
+ (nextState: SetStateInput<S>) => void
168
169
  ];
169
- type TCreateStateReturn = {
170
+ type CreateStateReturn = {
170
171
  reset: () => void;
171
- registerStateKey: <S>(initialState?: TStateInput<S> | undefined, onUpdate?: (() => void) | undefined) => () => TStateHandlerReturn<S>;
172
+ registerStateKey: <S>(initialState?: StateInput<S> | undefined, onUpdate?: (() => void) | undefined) => () => StateHandlerReturn<S>;
172
173
  };
173
- declare function createStateRef(state: TState, { suiteId, suiteName }: {
174
+ declare function createStateRef(state: State, { suiteId, suiteName }: {
174
175
  suiteId: string;
175
176
  suiteName?: void | string;
176
177
  }): {
177
- optionalFields: () => TStateHandlerReturn<Record<string, boolean | (() => boolean)>>;
178
- suiteId: () => TStateHandlerReturn<string>;
179
- suiteName: () => TStateHandlerReturn<string | void>;
180
- testCallbacks: () => TStateHandlerReturn<{
178
+ optionalFields: () => StateHandlerReturn<Record<string, boolean | (() => boolean)>>;
179
+ suiteId: () => StateHandlerReturn<string>;
180
+ suiteName: () => StateHandlerReturn<string | void>;
181
+ testCallbacks: () => StateHandlerReturn<{
181
182
  fieldCallbacks: Record<string, ((res: SuiteResult) => void)[]>;
182
183
  doneCallbacks: ((res: SuiteResult) => void)[];
183
184
  }>;
184
- testObjects: () => TStateHandlerReturn<{
185
+ testObjects: () => StateHandlerReturn<{
185
186
  prev: NestedArray<VestTest>;
186
187
  current: NestedArray<VestTest>;
187
188
  }>;
188
189
  };
189
- type TStateRef = ReturnType<typeof createStateRef>;
190
+ type StateRef = ReturnType<typeof createStateRef>;
190
191
  declare const _default: {
191
192
  run: <R>(ctxRef: Partial<CTXType>, fn: (context: CTXType) => R) => R;
192
193
  bind: <Fn extends (...args: any[]) => any>(ctxRef: Partial<CTXType>, fn: Fn) => Fn;
@@ -199,7 +200,7 @@ type CTXType = {
199
200
  keys: IsolateKeys;
200
201
  };
201
202
  testCursor: ReturnType<typeof createCursor>;
202
- stateRef?: TStateRef;
203
+ stateRef?: StateRef;
203
204
  exclusion: {
204
205
  tests: Record<string, boolean>;
205
206
  groups: Record<string, boolean>;
@@ -213,11 +214,12 @@ type CTXType = {
213
214
  Modes
214
215
  ];
215
216
  bus?: {
216
- on: (event: string, handler: (...args: any[]) => void) => {
217
+ on: (event: string, handler: CB) => {
217
218
  off: () => void;
218
219
  };
219
220
  emit: (event: string, ...args: any[]) => void;
220
221
  };
222
+ summary?: SuiteSummary;
221
223
  };
222
224
  declare const context: typeof _default;
223
225
  /**
@@ -234,7 +236,7 @@ declare const context: typeof _default;
234
236
  * })
235
237
  */
236
238
  declare function each<T>(list: T[], callback: (arg: T, index: number) => void): void;
237
- type TExclusionItem = string | string[] | undefined;
239
+ type ExclusionItem = string | string[] | undefined;
238
240
  /**
239
241
  * Adds a field or a list of fields into the inclusion list
240
242
  *
@@ -242,9 +244,9 @@ type TExclusionItem = string | string[] | undefined;
242
244
  *
243
245
  * only('username');
244
246
  */
245
- declare function only(item: TExclusionItem): void;
247
+ declare function only(item: ExclusionItem): void;
246
248
  declare namespace only {
247
- var group: (item: TExclusionItem) => void;
249
+ var group: (item: ExclusionItem) => void;
248
250
  }
249
251
  /**
250
252
  * Adds a field or a list of fields into the exclusion list
@@ -253,9 +255,9 @@ declare namespace only {
253
255
  *
254
256
  * skip('username');
255
257
  */
256
- declare function skip(item: TExclusionItem): void;
258
+ declare function skip(item: ExclusionItem): void;
257
259
  declare namespace skip {
258
- var group: (item: TExclusionItem) => void;
260
+ var group: (item: ExclusionItem) => void;
259
261
  }
260
262
  /**
261
263
  * Runs tests within a group so that they can be controlled or queried separately.
@@ -299,7 +301,7 @@ declare function eager(): void;
299
301
  * test('username', 'User already taken', async () => await doesUserExist(username)
300
302
  * });
301
303
  */
302
- declare function omitWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback: (...args: any[]) => void): void;
304
+ declare function omitWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback: CB): void;
303
305
  /**
304
306
  * Marks a field as optional, either just by name, or by a given condition.
305
307
  *
@@ -311,9 +313,9 @@ declare function omitWhen(conditional: boolean | ((draft: SuiteResult) => boolea
311
313
  * username: () => allowUsernameEmpty,
312
314
  * });
313
315
  */
314
- declare function optional(optionals: TOptionalsInput): void;
315
- type TOptionalsInput = string | string[] | TOptionalsObject;
316
- type TOptionalsObject = Record<string, () => boolean>;
316
+ declare function optional(optionals: OptionalsInput): void;
317
+ type OptionalsInput = string | string[] | OptionalsObject;
318
+ type OptionalsObject = Record<string, () => boolean>;
317
319
  /**
318
320
  * Conditionally skips running tests within the callback.
319
321
  *
@@ -323,11 +325,11 @@ type TOptionalsObject = Record<string, () => boolean>;
323
325
  * test('username', 'User already taken', async () => await doesUserExist(username)
324
326
  * });
325
327
  */
326
- declare function skipWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback: (...args: any[]) => void): void;
327
- declare function testBase(fieldName: string, message: string, cb: TTestFn): VestTest;
328
- declare function testBase(fieldName: string, cb: TTestFn): VestTest;
329
- declare function testBase(fieldName: string, message: string, cb: TTestFn, key: string): VestTest;
330
- declare function testBase(fieldName: string, cb: TTestFn, key: string): VestTest;
328
+ declare function skipWhen(conditional: boolean | ((draft: SuiteResult) => boolean), callback: CB): void;
329
+ declare function testBase(fieldName: string, message: string, cb: TestFn): VestTest;
330
+ declare function testBase(fieldName: string, cb: TestFn): VestTest;
331
+ declare function testBase(fieldName: string, message: string, cb: TestFn, key: string): VestTest;
332
+ declare function testBase(fieldName: string, cb: TestFn, key: string): VestTest;
331
333
  /**
332
334
  * Represents a single case in a validation suite.
333
335
  *
@@ -339,14 +341,14 @@ declare function testBase(fieldName: string, cb: TTestFn, key: string): VestTest
339
341
  */
340
342
  declare const test: typeof testBase & {
341
343
  memo: {
342
- (fieldName: string, test: TTestFn, deps: unknown[]): VestTest;
343
- (fieldName: string, message: string, test: TTestFn, deps: unknown[]): VestTest;
344
+ (fieldName: string, test: TestFn, deps: unknown[]): VestTest;
345
+ (fieldName: string, message: string, test: TestFn, deps: unknown[]): VestTest;
344
346
  };
345
347
  };
346
348
  /**
347
349
  * Sets a running test to warn only mode.
348
350
  */
349
351
  declare function warn(): void;
350
- declare const VERSION = "4.3.0";
352
+ declare const VERSION = "4.3.1";
351
353
  export { test, create, each, only, skip, warn, group, optional, skipWhen, omitWhen, enforce, VERSION, context, include, eager };
352
354
  export type { SuiteResult, SuiteRunResult, SuiteSummary, VestTest, Suite };