-
-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathschema.ts
118 lines (114 loc) · 2.41 KB
/
schema.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
import type { Config } from './config.ts';
import type { Dataset } from './dataset.ts';
import type { BaseIssue } from './issue.ts';
/**
* Base schema type.
*/
export interface BaseSchema<
TInput,
TOutput,
TIssue extends BaseIssue<unknown>,
> {
/**
* The object kind.
*/
readonly kind: 'schema';
/**
* The schema type.
*/
readonly type: string;
/**
* The schema reference.
*/
readonly reference: (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
) => BaseSchema<unknown, unknown, BaseIssue<unknown>>;
/**
* The expected property.
*/
readonly expects: string;
/**
* Whether it's async.
*/
readonly async: false;
/**
* Parses unknown input.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
_run(
dataset: Dataset<unknown, never>,
config: Config<TIssue>
): Dataset<TOutput, TIssue>;
/**
* Input, output and issue type.
*
* @internal
*/
readonly _types?: {
readonly input: TInput;
readonly output: TOutput;
readonly issue: TIssue;
};
}
/**
* Base schema async type.
*/
export interface BaseSchemaAsync<
TInput,
TOutput,
TIssue extends BaseIssue<unknown>,
> extends Omit<
BaseSchema<TInput, TOutput, TIssue>,
'reference' | 'async' | '_run'
> {
/**
* The schema reference.
*/
readonly reference: (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
) =>
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>;
/**
* Whether it's async.
*/
readonly async: true;
/**
* Parses unknown input.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
_run(
dataset: Dataset<unknown, never>,
config: Config<TIssue>
): Promise<Dataset<TOutput, TIssue>>;
}
/**
* Generic schema type.
*/
export interface GenericSchema<
TInput = unknown,
TOutput = TInput,
TIssue extends BaseIssue<unknown> = BaseIssue<unknown>,
> extends BaseSchema<TInput, TOutput, TIssue> {}
/**
* Generic schema async type.
*/
export interface GenericSchemaAsync<
TInput = unknown,
TOutput = TInput,
TIssue extends BaseIssue<unknown> = BaseIssue<unknown>,
> extends BaseSchemaAsync<TInput, TOutput, TIssue> {}