mirror of
https://github.com/honojs/hono.git
synced 2024-12-01 11:51:01 +01:00
8627010094
* refactor(types): refactor and add tests for checking Types * remove unused * uncomment * use `Handler` in validator middleware * remove unused * create `src/validator` dir and move some files into it * add the case that the context is in `validator` * rename `D` to `S`
55 lines
1.1 KiB
TypeScript
55 lines
1.1 KiB
TypeScript
import type {
|
|
VString,
|
|
VNumber,
|
|
VBoolean,
|
|
VObject,
|
|
VNumberArray,
|
|
VStringArray,
|
|
VBooleanArray,
|
|
VArray,
|
|
VObjectBase,
|
|
} from './validator.ts'
|
|
|
|
export type Schema = {
|
|
[key: string]:
|
|
| VString
|
|
| VNumber
|
|
| VBoolean
|
|
| VStringArray
|
|
| VNumberArray
|
|
| VBooleanArray
|
|
| Schema
|
|
| VObject<Schema>
|
|
| VArray<Schema>
|
|
}
|
|
|
|
export type SchemaToProp<T> = {
|
|
[K in keyof T]: T[K] extends VNumberArray
|
|
? number[]
|
|
: T[K] extends VBooleanArray
|
|
? boolean[]
|
|
: T[K] extends VStringArray
|
|
? string[]
|
|
: T[K] extends VNumber
|
|
? number
|
|
: T[K] extends VBoolean
|
|
? boolean
|
|
: T[K] extends VString
|
|
? string
|
|
: T[K] extends VObjectBase<Schema>
|
|
? T[K]['container'] extends VNumber
|
|
? number
|
|
: T[K]['container'] extends VString
|
|
? string
|
|
: T[K]['container'] extends VBoolean
|
|
? boolean
|
|
: T[K] extends VArray<Schema>
|
|
? SchemaToProp<ReadonlyArray<T[K]['container']>>
|
|
: T[K] extends VObject<Schema>
|
|
? SchemaToProp<T[K]['container']>
|
|
: T[K] extends Schema
|
|
? SchemaToProp<T[K]>
|
|
: never
|
|
: SchemaToProp<T[K]>
|
|
}
|