mirror of
https://github.com/honojs/hono.git
synced 2024-11-29 17:46:30 +01:00
chore: denoify
This commit is contained in:
parent
35ab653f1b
commit
9f7b5de9aa
@ -88,27 +88,28 @@ export class VArray<T extends Schema> extends VObjectBase<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Validator {
|
export class Validator {
|
||||||
isArray: boolean = false
|
constructor(private inArray: boolean = false) {}
|
||||||
|
|
||||||
query = (key: string): VString => new VString({ target: 'query', key: key })
|
query = (key: string): VString => new VString({ target: 'query', key: key })
|
||||||
queries = (key: string): VStringArray => new VStringArray({ target: 'queries', key: key })
|
queries = (key: string): VStringArray => new VStringArray({ target: 'queries', key: key })
|
||||||
header = (key: string): VString => new VString({ target: 'header', key: key })
|
header = (key: string): VString => new VString({ target: 'header', key: key })
|
||||||
body = (key: string): VString => new VString({ target: 'body', key: key })
|
body = (key: string): VString => new VString({ target: 'body', key: key })
|
||||||
json = (key: string) => {
|
json = (key: string) => {
|
||||||
if (this.isArray) {
|
if (this.inArray) {
|
||||||
return new VStringArray({ target: 'json', key: key })
|
return new VStringArray({ target: 'json', key: key })
|
||||||
} else {
|
} else {
|
||||||
return new VString({ target: 'json', key: key })
|
return new VString({ target: 'json', key: key })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
array = <T extends Schema>(path: string, validator: (v: Validator) => T): VArray<T> => {
|
array = <T extends Schema>(path: string, validatorFn: (v: Validator) => T): VArray<T> => {
|
||||||
this.isArray = true
|
const validator = new Validator(true)
|
||||||
const res = validator(this)
|
const res = validatorFn(validator)
|
||||||
const arr = new VArray(res, path)
|
const arr = new VArray(res, path)
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
object = <T extends Schema>(path: string, validator: (v: Validator) => T): VObject<T> => {
|
object = <T extends Schema>(path: string, validatorFn: (v: Validator) => T): VObject<T> => {
|
||||||
this.isArray = false
|
const validator = new Validator(this.inArray)
|
||||||
const res = validator(this)
|
const res = validatorFn(validator)
|
||||||
const obj = new VObject(res, path)
|
const obj = new VObject(res, path)
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user