|
1 |
| -import type { ValidationSource } from './types'; |
2 |
| -export type TStandardSchemaValidatorValue<TData, TSource extends ValidationSource = ValidationSource> = { |
3 |
| - value: TData; |
4 |
| - validationSource: TSource; |
5 |
| -}; |
6 |
| -export type TStandardSchemaValidatorIssue<TSource extends ValidationSource = ValidationSource> = TSource extends 'form' ? { |
7 |
| - form: Record<string, StandardSchemaV1Issue[]>; |
8 |
| - fields: Record<string, StandardSchemaV1Issue[]>; |
9 |
| -} : TSource extends 'field' ? StandardSchemaV1Issue[] : never; |
| 1 | +import type { ValidationSource } from './types' |
| 2 | +export type TStandardSchemaValidatorValue< |
| 3 | + TData, |
| 4 | + TSource extends ValidationSource = ValidationSource, |
| 5 | +> = { |
| 6 | + value: TData |
| 7 | + validationSource: TSource |
| 8 | +} |
| 9 | +export type TStandardSchemaValidatorIssue< |
| 10 | + TSource extends ValidationSource = ValidationSource, |
| 11 | +> = TSource extends 'form' |
| 12 | + ? { |
| 13 | + form: Record<string, StandardSchemaV1Issue[]> |
| 14 | + fields: Record<string, StandardSchemaV1Issue[]> |
| 15 | + } |
| 16 | + : TSource extends 'field' |
| 17 | + ? StandardSchemaV1Issue[] |
| 18 | + : never |
10 | 19 | export declare const standardSchemaValidators: {
|
11 |
| - validate<TSource extends ValidationSource = ValidationSource>({ value, validationSource, }: TStandardSchemaValidatorValue<unknown, TSource>, schema: StandardSchemaV1): TStandardSchemaValidatorIssue<TSource> | undefined; |
12 |
| - validateAsync<TSource extends ValidationSource>({ value, validationSource, }: TStandardSchemaValidatorValue<unknown, TSource>, schema: StandardSchemaV1): Promise<TStandardSchemaValidatorIssue<TSource> | undefined>; |
13 |
| -}; |
14 |
| -export declare const isStandardSchemaValidator: (validator: unknown) => validator is StandardSchemaV1; |
| 20 | + validate<TSource extends ValidationSource = ValidationSource>( |
| 21 | + { |
| 22 | + value, |
| 23 | + validationSource, |
| 24 | + }: TStandardSchemaValidatorValue<unknown, TSource>, |
| 25 | + schema: StandardSchemaV1, |
| 26 | + ): TStandardSchemaValidatorIssue<TSource> | undefined |
| 27 | + validateAsync<TSource extends ValidationSource>( |
| 28 | + { |
| 29 | + value, |
| 30 | + validationSource, |
| 31 | + }: TStandardSchemaValidatorValue<unknown, TSource>, |
| 32 | + schema: StandardSchemaV1, |
| 33 | + ): Promise<TStandardSchemaValidatorIssue<TSource> | undefined> |
| 34 | +} |
| 35 | +export declare const isStandardSchemaValidator: ( |
| 36 | + validator: unknown, |
| 37 | +) => validator is StandardSchemaV1 |
15 | 38 | /**
|
16 | 39 | * The Standard Schema interface.
|
17 | 40 | */
|
18 | 41 | export type StandardSchemaV1<Input = unknown, Output = Input> = {
|
19 |
| - /** |
20 |
| - * The Standard Schema properties. |
21 |
| - */ |
22 |
| - readonly '~standard': StandardSchemaV1Props<Input, Output>; |
23 |
| -}; |
| 42 | + /** |
| 43 | + * The Standard Schema properties. |
| 44 | + */ |
| 45 | + readonly '~standard': StandardSchemaV1Props<Input, Output> |
| 46 | +} |
24 | 47 | /**
|
25 | 48 | * The Standard Schema properties interface.
|
26 | 49 | */
|
27 | 50 | interface StandardSchemaV1Props<Input = unknown, Output = Input> {
|
28 |
| - /** |
29 |
| - * The version number of the standard. |
30 |
| - */ |
31 |
| - readonly version: 1; |
32 |
| - /** |
33 |
| - * The vendor name of the schema library. |
34 |
| - */ |
35 |
| - readonly vendor: string; |
36 |
| - /** |
37 |
| - * Validates unknown input values. |
38 |
| - */ |
39 |
| - readonly validate: (value: unknown) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>>; |
40 |
| - /** |
41 |
| - * Inferred types associated with the schema. |
42 |
| - */ |
43 |
| - readonly types?: StandardSchemaV1Types<Input, Output> | undefined; |
| 51 | + /** |
| 52 | + * The version number of the standard. |
| 53 | + */ |
| 54 | + readonly version: 1 |
| 55 | + /** |
| 56 | + * The vendor name of the schema library. |
| 57 | + */ |
| 58 | + readonly vendor: string |
| 59 | + /** |
| 60 | + * Validates unknown input values. |
| 61 | + */ |
| 62 | + readonly validate: ( |
| 63 | + value: unknown, |
| 64 | + ) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>> |
| 65 | + /** |
| 66 | + * Inferred types associated with the schema. |
| 67 | + */ |
| 68 | + readonly types?: StandardSchemaV1Types<Input, Output> | undefined |
44 | 69 | }
|
45 | 70 | /**
|
46 | 71 | * The result interface of the validate function.
|
47 | 72 | */
|
48 |
| -type StandardSchemaV1Result<Output> = StandardSchemaV1SuccessResult<Output> | StandardSchemaV1FailureResult; |
| 73 | +type StandardSchemaV1Result<Output> = |
| 74 | + | StandardSchemaV1SuccessResult<Output> |
| 75 | + | StandardSchemaV1FailureResult |
49 | 76 | /**
|
50 | 77 | * The result interface if validation succeeds.
|
51 | 78 | */
|
52 | 79 | interface StandardSchemaV1SuccessResult<Output> {
|
53 |
| - /** |
54 |
| - * The typed output value. |
55 |
| - */ |
56 |
| - readonly value: Output; |
57 |
| - /** |
58 |
| - * The non-existent issues. |
59 |
| - */ |
60 |
| - readonly issues?: undefined; |
| 80 | + /** |
| 81 | + * The typed output value. |
| 82 | + */ |
| 83 | + readonly value: Output |
| 84 | + /** |
| 85 | + * The non-existent issues. |
| 86 | + */ |
| 87 | + readonly issues?: undefined |
61 | 88 | }
|
62 | 89 | /**
|
63 | 90 | * The result interface if validation fails.
|
64 | 91 | */
|
65 | 92 | interface StandardSchemaV1FailureResult {
|
66 |
| - /** |
67 |
| - * The issues of failed validation. |
68 |
| - */ |
69 |
| - readonly issues: ReadonlyArray<StandardSchemaV1Issue>; |
| 93 | + /** |
| 94 | + * The issues of failed validation. |
| 95 | + */ |
| 96 | + readonly issues: ReadonlyArray<StandardSchemaV1Issue> |
70 | 97 | }
|
71 | 98 | /**
|
72 | 99 | * The issue interface of the failure output.
|
73 | 100 | */
|
74 | 101 | export interface StandardSchemaV1Issue {
|
75 |
| - /** |
76 |
| - * The error message of the issue. |
77 |
| - */ |
78 |
| - readonly message: string; |
79 |
| - /** |
80 |
| - * The path of the issue, if any. |
81 |
| - */ |
82 |
| - readonly path?: ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment> | undefined; |
| 102 | + /** |
| 103 | + * The error message of the issue. |
| 104 | + */ |
| 105 | + readonly message: string |
| 106 | + /** |
| 107 | + * The path of the issue, if any. |
| 108 | + */ |
| 109 | + readonly path?: |
| 110 | + | ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment> |
| 111 | + | undefined |
83 | 112 | }
|
84 | 113 | /**
|
85 | 114 | * The path segment interface of the issue.
|
86 | 115 | */
|
87 | 116 | interface StandardSchemaV1PathSegment {
|
88 |
| - /** |
89 |
| - * The key representing a path segment. |
90 |
| - */ |
91 |
| - readonly key: PropertyKey; |
| 117 | + /** |
| 118 | + * The key representing a path segment. |
| 119 | + */ |
| 120 | + readonly key: PropertyKey |
92 | 121 | }
|
93 | 122 | /**
|
94 | 123 | * The Standard Schema types interface.
|
95 | 124 | */
|
96 | 125 | interface StandardSchemaV1Types<Input = unknown, Output = Input> {
|
97 |
| - /** |
98 |
| - * The input type of the schema. |
99 |
| - */ |
100 |
| - readonly input: Input; |
101 |
| - /** |
102 |
| - * The output type of the schema. |
103 |
| - */ |
104 |
| - readonly output: Output; |
| 126 | + /** |
| 127 | + * The input type of the schema. |
| 128 | + */ |
| 129 | + readonly input: Input |
| 130 | + /** |
| 131 | + * The output type of the schema. |
| 132 | + */ |
| 133 | + readonly output: Output |
105 | 134 | }
|
106 |
| -export {}; |
| 135 | +export {} |
0 commit comments