|
12 | 12 | * @typedef {{ |
13 | 13 | * context?: any; |
14 | 14 | * extensions?: { [K: string]: any }; |
15 | | - * typeName?: string; |
16 | | - * }} SchemaOptions |
| 15 | + * input?: any; |
| 16 | + * object?: any; |
| 17 | + * resolvedValue?: {}; |
| 18 | + * typeName?: string | unknown; |
| 19 | + * value?: any; |
| 20 | + * }} TypeOptions |
17 | 21 | */ |
18 | 22 |
|
19 | 23 | /** |
20 | | - * @template {SchemaOptions} [O={}] Default is `{}` |
21 | | - * @template [_Context=O['context'] extends undefined ? unknown: O['context']] |
22 | | - * Default is `O['context'] extends undefined ? unknown: O['context']` |
23 | | - * @template [_Extensions=O['extensions'] extends undefined ? {} : O['extensions']] |
24 | | - * Default is `O['extensions'] extends undefined ? {} : O['extensions']` |
25 | | - * @template {string} [TypeName=O['typeName'] extends string ? O['typeName'] : never] |
26 | | - * Default is `O['typeName'] extends string ? O['typeName'] : never` |
27 | | - * @typedef {{ [K in TypeName]: Type<Schema<O>, any> }} Schema |
28 | | - */ |
29 | | - |
30 | | -/** |
31 | | - * @template {Schema<any>} S |
32 | | - * @typedef {S extends Schema<infer _, infer Context> ? Context : never} SchemaContext |
| 24 | + * @typedef {{ |
| 25 | + * context: unknown; |
| 26 | + * extensions: {}; |
| 27 | + * input: unknown; |
| 28 | + * object: unknown; |
| 29 | + * resolvedValue: {}; |
| 30 | + * typeName: unknown; |
| 31 | + * value: unknown; |
| 32 | + * }} DefaultTypeOptions |
33 | 33 | */ |
34 | 34 |
|
35 | 35 | /** |
36 | | - * @template {Schema<any>} S |
37 | | - * @typedef {S extends Schema<infer _, infer __, infer Extensions> ? Extensions : never} SchemaExtensions |
| 36 | + * @template {TypeOptions} Obj |
| 37 | + * @template {keyof TypeOptions} Key |
| 38 | + * @typedef {undefined extends Obj[Key] ? DefaultTypeOptions[Key] : Obj[Key]} GetTypeOption |
38 | 39 | */ |
39 | 40 |
|
40 | 41 | /** |
41 | | - * @template {Schema<any>} S |
42 | | - * @typedef {S extends Schema<infer _, infer __, infer ___, infer TypeName> |
43 | | - * ? TypeName |
44 | | - * : never} SchemaTypeName |
| 42 | + * @template {TypeOptions} O |
| 43 | + * @typedef {Pick<O, 'context' | 'extensions' | 'typeName'>} SharedTypeOptions |
45 | 44 | */ |
46 | 45 |
|
47 | | -/** @typedef {{ input?: any; object?: any; resolvedValue?: {}; value?: any }} TypeOptions */ |
48 | | - |
49 | 46 | /** |
50 | | - * @template {Schema<any>} [S=Schema] Default is `Schema` |
51 | | - * @template {TypeOptions} [O={}] Default is `{}` |
52 | | - * @template [Input=O['input'] extends undefined ? unknown : O['input']] |
53 | | - * Default is `O['input'] extends undefined ? unknown : O['input']` |
54 | | - * @template [Object=O['object'] extends undefined ? unknown : O['object']] |
55 | | - * Default is `O['object'] extends undefined ? unknown : O['object']` |
56 | | - * @template [ResolvedValue=O['resolvedValue'] extends undefined ? {} : O['resolvedValue']] |
57 | | - * Default is `O['resolvedValue'] extends undefined ? {} : O['resolvedValue']` |
58 | | - * @template [Value=O['value'] extends undefined ? undefined : O['value']] |
59 | | - * Default is `O['value'] extends undefined ? undefined : O['value']` |
| 47 | + * @template {TypeOptions} [O=DefaultTypeOptions] Default is |
| 48 | + * `DefaultTypeOptions` |
60 | 49 | * @typedef {Recursive< |
61 | | - * | SchemaTypeName<S> |
| 50 | + * | GetTypeOption<O, 'typeName'> |
62 | 51 | * | (( |
63 | | - * | { optional: Type<S, any> } |
64 | | - * | { nullable: Type<S, any> } |
65 | | - * | { arrayOf: Type<S, any>; minLength?: number; maxLength?: number } |
| 52 | + * | { optional: Type<SharedTypeOptions<O>> } |
| 53 | + * | { nullable: Type<SharedTypeOptions<O>> } |
| 54 | + * | { |
| 55 | + * arrayOf: Type<SharedTypeOptions<O>>; |
| 56 | + * minLength?: number; |
| 57 | + * maxLength?: number; |
| 58 | + * } |
66 | 59 | * | { |
67 | | - * oneOf: { [K: string]: Type<S, any> }; |
| 60 | + * oneOf: { [K: string]: Type<SharedTypeOptions<O>> }; |
68 | 61 | * resolveType: (value: {}) => string; |
69 | 62 | * } |
70 | | - * | { object: { [K: string]: Type<S, any> }; defaultType?: Type<S, any> } |
71 | 63 | * | { |
72 | | - * input?: Type<S, any>; |
73 | | - * type?: Type<S, any>; |
| 64 | + * object: { [K: string]: Type<SharedTypeOptions<O>> }; |
| 65 | + * defaultType?: Type<SharedTypeOptions<O>>; |
| 66 | + * } |
| 67 | + * | { |
| 68 | + * input?: Type<SharedTypeOptions<O>>; |
| 69 | + * type?: Type<SharedTypeOptions<O>>; |
74 | 70 | * typeInput?: any; |
75 | 71 | * resolve?: |
76 | 72 | * | ((options: { |
77 | | - * context: SchemaContext<S>; |
78 | | - * input: Input; |
79 | | - * object: Object; |
| 73 | + * context: GetTypeOption<O, 'context'>; |
| 74 | + * input: GetTypeOption<O, 'input'>; |
| 75 | + * object: GetTypeOption<O, 'object'>; |
80 | 76 | * path: string[]; |
81 | 77 | * query: Query; |
82 | | - * schema: S; |
83 | | - * type: Type<S, any>; |
84 | | - * value: Value; |
| 78 | + * schema: Schema<SharedTypeOptions<O>>; |
| 79 | + * type: Type<SharedTypeOptions<O>>; |
| 80 | + * value: GetTypeOption<O, 'typeName'>; |
85 | 81 | * }) => any) |
86 | 82 | * | {} |
87 | 83 | * | null; |
|
90 | 86 | * cost?: |
91 | 87 | * | number |
92 | 88 | * | ((options: { |
93 | | - * context: SchemaContext<S>; |
| 89 | + * context: GetTypeOption<O, 'context'>; |
94 | 90 | * cost: number; |
95 | | - * input: Input; |
96 | | - * object: Object; |
| 91 | + * input: GetTypeOption<O, 'input'>; |
| 92 | + * object: GetTypeOption<O, 'object'>; |
97 | 93 | * path: string[]; |
98 | 94 | * query: Query; |
99 | | - * schema: S; |
100 | | - * type: Type<S, any>; |
101 | | - * value: Value; |
| 95 | + * schema: Schema<SharedTypeOptions<O>>; |
| 96 | + * type: Type<SharedTypeOptions<O>>; |
| 97 | + * value: GetTypeOption<O, 'typeName'>; |
102 | 98 | * }) => number); |
103 | 99 | * defaultValue?: any; |
104 | 100 | * validate?: (options: { |
105 | | - * context: SchemaContext<S>; |
106 | | - * input: Input; |
107 | | - * object: Object; |
| 101 | + * context: GetTypeOption<O, 'context'>; |
| 102 | + * input: GetTypeOption<O, 'input'>; |
| 103 | + * object: GetTypeOption<O, 'object'>; |
108 | 104 | * path: string[]; |
109 | 105 | * query: Query; |
110 | | - * schema: S; |
111 | | - * type: Type<S, any>; |
112 | | - * value: ResolvedValue; |
| 106 | + * schema: Schema<SharedTypeOptions<O>>; |
| 107 | + * type: Type<SharedTypeOptions<O>>; |
| 108 | + * value: GetTypeOption<O, 'resolvedValue'>; |
113 | 109 | * }) => any; |
114 | | - * } & SchemaExtensions<S>) |
| 110 | + * } & GetTypeOption<O, 'extensions'>) |
115 | 111 | * >} Type |
116 | 112 | */ |
117 | 113 |
|
| 114 | +/** |
| 115 | + * @template {TypeOptions} [O=DefaultTypeOptions] Default is |
| 116 | + * `DefaultTypeOptions` |
| 117 | + * @typedef {GetTypeOption<O, 'typeName'> extends string |
| 118 | + * ? { [K in GetTypeOption<O, 'typeName'>]: Type<SharedTypeOptions<O>> } |
| 119 | + * : { [K in keyof any]: never }} Schema |
| 120 | + */ |
| 121 | + |
118 | 122 | /** |
119 | 123 | * @template [T=any] Default is `any` |
120 | 124 | * @typedef {{ _?: string; $?: any; _type?: { [K in keyof any]: never } } |
|
0 commit comments