@webergency-utils/typechecker 0.1.10 → 0.2.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.
@@ -3,27 +3,48 @@ export interface IValidationError {
3
3
  path: string;
4
4
  value: any;
5
5
  error: string;
6
+ /** Nested failures (e.g. per-arm errors for a failed union). */
7
+ issues?: IValidationError[];
6
8
  }
9
+ /** Internal expected-type labels for custom `from` callbacks. Not exported from the package. */
10
+ type BaseType = 'string' | 'number' | 'boolean' | 'bigint' | 'function' | 'symbol' | 'never' | 'Date' | 'RegExp' | 'Set' | 'Map' | 'Array' | 'Object' | 'instance' | 'null' | 'undefined' | 'tuple' | 'literal';
11
+ type FromOption = 'json' | 'query' | ((key: string, value: any, type: BaseType) => any);
7
12
  export interface ValidationContext {
8
13
  success: boolean;
9
14
  errors: IValidationError[];
10
15
  mode: ValidationMode;
11
- tryConvert?: boolean;
16
+ from?: FromOption;
12
17
  wrapArrays?: boolean;
18
+ mutate?: boolean;
13
19
  root?: any;
14
20
  }
15
21
  export interface ValidationOptions {
16
22
  mode?: ValidationMode;
17
- tryConvert?: boolean;
23
+ from?: FromOption;
18
24
  wrapArrays?: boolean;
25
+ /** When true, write validated/coerced values onto the input. Default false: always return new containers. */
26
+ mutate?: boolean;
19
27
  schema?: any;
20
28
  errorFactory?: (errors: IValidationError[]) => Error;
21
29
  }
30
+ /** Query-style number coercion — shared by `from: 'query'` and `transform.ToNumber`. */
31
+ export declare function coerceQueryNumber(v: any): any;
32
+ /** Query-style boolean coercion — shared by `from: 'query'` and `transform.ToBoolean`. */
33
+ export declare function coerceQueryBoolean(v: any): any;
34
+ /** JSON-wire Date revival (ISO / date-parseable strings only). */
35
+ export declare function coerceJsonDate(v: any): any;
36
+ /** Query-style Date coercion — shared by `from: 'query'` and `transform.ToDate`. */
37
+ export declare function coerceQueryDate(v: any): any;
22
38
  export declare const validators: {
39
+ coerceQueryNumber: typeof coerceQueryNumber;
40
+ coerceQueryBoolean: typeof coerceQueryBoolean;
41
+ coerceQueryDate: typeof coerceQueryDate;
42
+ coerceJsonDate: typeof coerceJsonDate;
23
43
  string: (v: any, path: string, ctx: ValidationContext) => any;
24
44
  number: (v: any, path: string, ctx: ValidationContext) => any;
25
45
  bigint: (v: any, path: string, ctx: ValidationContext) => any;
26
46
  boolean: (v: any, path: string, ctx: ValidationContext) => any;
47
+ function: (v: any, path: string, ctx: ValidationContext) => any;
27
48
  date: (v: any, path: string, ctx: ValidationContext) => any;
28
49
  regexp: (v: any, path: string, ctx: ValidationContext) => any;
29
50
  null: (v: any, path: string, ctx: ValidationContext) => null;
@@ -31,7 +52,10 @@ export declare const validators: {
31
52
  literal: (v: any, path: string, ctx: ValidationContext, expected: any) => any;
32
53
  array: (v: any, path: string, ctx: ValidationContext, childValidator: Function) => any;
33
54
  props: (v: any, data: any, path: string, ctx: ValidationContext, props: [string, boolean, Function][]) => void;
34
- object: (v: any, path: string, ctx: ValidationContext, allowedKeys?: string[], expected?: string) => boolean;
55
+ objectShell: (v: any, ctx: ValidationContext) => any;
56
+ stripExtras: (data: any, ctx: ValidationContext, allowedKeys?: string[]) => any;
57
+ additionalProps: (v: any, data: any, path: string, ctx: ValidationContext, knownKeys: string[], childValidator: Function) => void;
58
+ object: (v: any, path: string, ctx: ValidationContext, allowedKeys?: string[], expected?: string) => any;
35
59
  templateLiteral: (v: any, path: string, ctx: ValidationContext, regex: RegExp, expected: string) => any;
36
60
  minLength: (v: string, path: string, ctx: ValidationContext, min: number, message?: string) => string;
37
61
  maxLength: (v: string, path: string, ctx: ValidationContext, max: number, message?: string) => string;
@@ -41,7 +65,7 @@ export declare const validators: {
41
65
  exclusiveMaximum: (v: number | bigint, path: string, ctx: ValidationContext, max: number | bigint, message?: string) => number | bigint;
42
66
  multipleOf: (v: number | bigint, path: string, ctx: ValidationContext, n: number | bigint, message?: string) => number | bigint;
43
67
  pattern: (v: string, path: string, ctx: ValidationContext, regex: RegExp, expected: string, message?: string) => string;
44
- format: (v: string, path: string, ctx: ValidationContext, format: string, message?: string) => string;
68
+ format: (v: string, path: string, ctx: ValidationContext, format: string, message?: string) => any;
45
69
  minItems: (v: any[], path: string, ctx: ValidationContext, min: number, message?: string) => any[];
46
70
  maxItems: (v: any[], path: string, ctx: ValidationContext, max: number, message?: string) => any[];
47
71
  uniqueItems: (v: any[], path: string, ctx: ValidationContext, message?: string) => any[];
@@ -49,6 +73,9 @@ export declare const validators: {
49
73
  union: (v: any, path: string, ctx: ValidationContext, checks: Function[], expected?: string) => any;
50
74
  tuple: (v: any, path: string, ctx: ValidationContext, checks: Function[]) => any;
51
75
  any: (v: any) => any;
76
+ never: (v: any, path: string, ctx: ValidationContext) => any;
77
+ symbol: (v: any, path: string, ctx: ValidationContext) => any;
78
+ instanceOf: (v: any, path: string, ctx: ValidationContext, typeName: string) => any;
52
79
  requires: (v: any, path: string, ctx: ValidationContext, reqs: string[], message?: string) => any;
53
80
  record: (v: any, path: string, ctx: ValidationContext, childValidator: Function) => any;
54
81
  set: (v: any, path: string, ctx: ValidationContext, childValidator: Function, message?: string) => any;
@@ -65,6 +92,7 @@ export declare class MetadataStoreClass {
65
92
  getOrCompileSchema(schema: any): Function;
66
93
  is(validator: Function, value: any, options?: ValidationMode | ValidationOptions): boolean;
67
94
  assert(validator: Function, value: any, options?: ValidationMode | ValidationOptions): any;
95
+ assertGuard(validator: Function, value: any, options?: ValidationMode | ValidationOptions): void;
68
96
  validate(validator: Function, value: any, options?: ValidationMode | ValidationOptions): {
69
97
  success: boolean;
70
98
  errors: IValidationError[];
@@ -77,13 +105,9 @@ export declare function groupErrorsByPath(errors: IValidationError[]): Record<st
77
105
  }>;
78
106
  export declare const MetadataStore: MetadataStoreClass;
79
107
  export declare function compileSchema(schema: any): (v: any, path: string, ctx: any) => any;
80
- export declare function toZodIssues(errors: IValidationError[]): {
81
- code: string;
82
- path: (string | number)[];
83
- message: string;
84
- received: any;
85
- }[];
108
+ export declare function toZodIssues(errors: IValidationError[]): any[];
86
109
  export declare class ZodLikeError extends Error {
87
110
  issues: any[];
88
111
  constructor(errors: IValidationError[]);
89
112
  }
113
+ export {};