|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | /** |
18 | | - * @template {string} [TypeName=never] Default is `never` |
19 | | - * @template {{ [K: string]: any }} [Extensions={}] Default is `{}` |
20 | | - * @template [Context=unknown] Default is `unknown` |
| 18 | + * @template {string} TypeName |
| 19 | + * @template {{ [K: string]: any }} Extensions |
| 20 | + * @template Context |
| 21 | + * @typedef {{ |
| 22 | + * [K in TypeName]: Type< |
| 23 | + * Schema<TypeName, Extensions, Context>, |
| 24 | + * any, |
| 25 | + * any, |
| 26 | + * any, |
| 27 | + * any |
| 28 | + * >; |
| 29 | + * }} Schema |
| 30 | + */ |
| 31 | + |
| 32 | +/** |
| 33 | + * @template {Schema<any, any, any>} S |
| 34 | + * @typedef {S extends Schema<infer TypeName, any, any> ? TypeName : never} SchemaTypeName |
| 35 | + */ |
| 36 | + |
| 37 | +/** |
| 38 | + * @template {Schema<any, any, any>} S |
| 39 | + * @typedef {S extends Schema<any, infer Extensions, any> ? Extensions : never} SchemaExtensions |
| 40 | + */ |
| 41 | + |
| 42 | +/** |
| 43 | + * @template {Schema<any, any, any>} S |
| 44 | + * @typedef {S extends Schema<any, any, infer Context> ? Context : never} SchemaContext |
| 45 | + */ |
| 46 | + |
| 47 | +/** |
| 48 | + * @template {Schema<any, any, any>} [S=Schema<never, {}, unknown>] Default is |
| 49 | + * `Schema<never, {}, unknown>` |
21 | 50 | * @template [Input=unknown] Default is `unknown` |
22 | 51 | * @template [Object=unknown] Default is `unknown` |
23 | 52 | * @template [Value=unknown] Default is. Default is `unknown` |
24 | 53 | * @template [ResolvedValue=NonNullable<unknown>] Default is |
25 | 54 | * `NonNullable<unknown>` |
26 | 55 | * @typedef {Recursive< |
27 | | - * | TypeName |
| 56 | + * | SchemaTypeName<S> |
28 | 57 | * | (( |
29 | | - * | { optional: Type<TypeName, Extensions, Context> } |
30 | | - * | { nullable: Type<TypeName, Extensions, Context> } |
31 | | - * | { |
32 | | - * arrayOf: Type<TypeName, Extensions, Context>; |
33 | | - * minLength?: number; |
34 | | - * maxLength?: number; |
35 | | - * } |
| 58 | + * | { optional: Type<S> } |
| 59 | + * | { nullable: Type<S> } |
| 60 | + * | { arrayOf: Type<S>; minLength?: number; maxLength?: number } |
36 | 61 | * | { |
37 | | - * oneOf: { [K: string]: Type<TypeName, Extensions, Context> }; |
| 62 | + * oneOf: { [K: string]: Type<S> }; |
38 | 63 | * resolveType: (value: NonNullable<unknown>) => string; |
39 | 64 | * } |
| 65 | + * | { object: { [K: string]: Type<S> }; defaultType?: Type<S> } |
40 | 66 | * | { |
41 | | - * object: { [K: string]: Type<TypeName, Extensions, Context> }; |
42 | | - * defaultType?: Type<TypeName, Extensions, Context>; |
43 | | - * } |
44 | | - * | { |
45 | | - * input?: Type<TypeName, Extensions, Context>; |
46 | | - * type?: Type<TypeName, Extensions, Context>; |
| 67 | + * input?: Type<S>; |
| 68 | + * type?: Type<S>; |
47 | 69 | * typeInput?: any; |
48 | 70 | * resolve?: |
49 | 71 | * | ((options: { |
50 | | - * context: Context; |
| 72 | + * context: SchemaContext<S>; |
51 | 73 | * input: Input; |
52 | 74 | * object: Object; |
53 | 75 | * path: string[]; |
54 | 76 | * query: Query; |
55 | | - * schema: Schema<TypeName, Extensions, Context>; |
56 | | - * type: Type<TypeName, Extensions, Context>; |
| 77 | + * schema: S; |
| 78 | + * type: Type<S>; |
57 | 79 | * value: Value; |
58 | 80 | * }) => any) |
59 | 81 | * | {} |
|
63 | 85 | * cost?: |
64 | 86 | * | number |
65 | 87 | * | ((options: { |
66 | | - * context: Context; |
| 88 | + * context: SchemaContext<S>; |
67 | 89 | * cost: number; |
68 | 90 | * input: Input; |
69 | 91 | * object: Object; |
70 | 92 | * path: string[]; |
71 | 93 | * query: Query; |
72 | | - * schema: Schema<TypeName, Extensions, Context>; |
73 | | - * type: Type<TypeName, Extensions, Context>; |
| 94 | + * schema: S; |
| 95 | + * type: Type<S>; |
74 | 96 | * value: Value; |
75 | 97 | * }) => number); |
76 | 98 | * defaultValue?: any; |
77 | 99 | * validate?: (options: { |
78 | | - * context: Context; |
| 100 | + * context: SchemaContext<S>; |
79 | 101 | * input: Input; |
80 | 102 | * object: Object; |
81 | 103 | * path: string[]; |
82 | 104 | * query: Query; |
83 | | - * schema: Schema<TypeName, Extensions, Context>; |
84 | | - * type: Type<TypeName, Extensions, Context>; |
| 105 | + * schema: S; |
| 106 | + * type: Type<S>; |
85 | 107 | * value: ResolvedValue; |
86 | 108 | * }) => any; |
87 | | - * } & Extensions) |
| 109 | + * } & SchemaExtensions<S>) |
88 | 110 | * >} Type |
89 | 111 | */ |
90 | 112 |
|
91 | | -/** |
92 | | - * @template {string} TypeName |
93 | | - * @template {{ [K: string]: any }} Extensions |
94 | | - * @template Context |
95 | | - * @typedef {{ |
96 | | - * [K in TypeName]: Type<TypeName, Extensions, Context, any, any, any, any>; |
97 | | - * }} Schema |
98 | | - */ |
99 | | - |
100 | 113 | export { Context } from '#src/context.js'; |
101 | 114 | export { createClient } from '#src/create-client.js'; |
102 | 115 | export { execute } from '#src/execute.js'; |
|
0 commit comments