feat: Add Schema any

This commit is contained in:
Florian Bouillon 2025-03-25 13:59:04 +01:00
parent 817b7d6774
commit 780423ab47
Signed by: Florian Bouillon
GPG Key ID: 7676FF78F3BC40EC
2 changed files with 15 additions and 3 deletions

View File

@ -1,5 +1,6 @@
/* eslint-disable id-blacklist */
import { parseForm, parseFormData, parseQuery } from 'helpers'
import SchemaAny from 'items/any'
import SchemaDate from 'items/date'
import SchemaRecord from 'items/record'
import SchemaArray from './items/array'
@ -45,6 +46,7 @@ export function parceable() {
type SchemaItemStatic = new (...args: Array<any>) => SchemaItem
export const Types = {
Any: SchemaAny,
Array: SchemaArray,
Boolean: SchemaBoolean,
Date: SchemaDate,
@ -79,6 +81,10 @@ export default class Schema<T extends Record<string, SchemaItem> = Record<string
return this.registeredModules.find((it) => it.name === name)
}
public static any() {
return new SchemaAny()
}
public static array<Type extends SchemaItem>(
...inputs: ConstructorParameters<typeof SchemaArray<Type>>
): SchemaArray<Type> {
@ -232,10 +238,9 @@ export * from './helpers'
export type * from './types.d.ts'
export {
SchemaArray,
SchemaAny, SchemaArray,
SchemaBoolean, SchemaDate, SchemaEnum, SchemaItem, SchemaLiteral,
SchemaNullable,
SchemaNumber,
SchemaObject, SchemaRecord, SchemaString,
SchemaNumber, SchemaObject, SchemaRecord, SchemaString,
SchemaUnion
}

7
src/items/any.ts Normal file
View File

@ -0,0 +1,7 @@
import SchemaItem from '../SchemaItem'
export default class SchemaAny extends SchemaItem {
public override isOfType(input: unknown): input is any {
return true
}
}