SchemaClass work
This commit is contained in:
@@ -3,89 +3,17 @@ import { z } from "zod"
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a schema class with generic parameters for defining validation schemas.
|
* Configuration for creating a schemable object with validation schemas.
|
||||||
*
|
* @template Values - The type representing the expected values.
|
||||||
* @template Values - The type of values expected by the schema.
|
* @template Input - The type representing the input values.
|
||||||
* @template Input - The type of input data expected by the schema.
|
* @template SchemaT - The type representing the base validation schema.
|
||||||
* @template SchemaT - The type of the raw shape of the schema.
|
* @template SchemaUnknownKeys - The type representing the unknown keys behavior in the base validation schema.
|
||||||
* @template SchemaUnknownKeys - The type of unknown keys parameter for the schema.
|
* @template SchemaCatchall - The type representing the catchall behavior in the base validation schema.
|
||||||
* @template SchemaCatchall - The type of catchall parameter for the schema.
|
* @template SchemaWithDefaultValuesT - The type representing the validation schema with default values.
|
||||||
* @template SchemaWithDefaultValuesT - The type of the raw shape for default values schema.
|
* @template SchemaWithDefaultValuesUnknownKeys - The type representing the unknown keys behavior in the validation schema with default values.
|
||||||
* @template SchemaWithDefaultValuesUnknownKeys - The type of unknown keys parameter for default values schema.
|
* @template SchemaWithDefaultValuesCatchall - The type representing the catchall behavior in the validation schema with default values.
|
||||||
* @template SchemaWithDefaultValuesCatchall - The type of catchall parameter for default values schema.
|
|
||||||
*/
|
*/
|
||||||
export type SchemaClass<
|
export type SchemableConfig<
|
||||||
Values extends {} = {},
|
|
||||||
Input extends {} = {},
|
|
||||||
|
|
||||||
SchemaT extends z.ZodRawShape = z.ZodRawShape,
|
|
||||||
SchemaUnknownKeys extends z.UnknownKeysParam = z.UnknownKeysParam,
|
|
||||||
SchemaCatchall extends z.ZodTypeAny = z.ZodTypeAny,
|
|
||||||
|
|
||||||
SchemaWithDefaultValuesT extends z.ZodRawShape = z.ZodRawShape,
|
|
||||||
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam = z.UnknownKeysParam,
|
|
||||||
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny = z.ZodTypeAny,
|
|
||||||
> = (
|
|
||||||
Class<
|
|
||||||
SchemaObject<
|
|
||||||
Values,
|
|
||||||
Input,
|
|
||||||
|
|
||||||
SchemaT,
|
|
||||||
SchemaUnknownKeys,
|
|
||||||
SchemaCatchall,
|
|
||||||
|
|
||||||
SchemaWithDefaultValuesT,
|
|
||||||
SchemaWithDefaultValuesUnknownKeys,
|
|
||||||
SchemaWithDefaultValuesCatchall
|
|
||||||
>,
|
|
||||||
|
|
||||||
SchemaClassConstructorParams<Values>
|
|
||||||
> & {
|
|
||||||
readonly schema: z.ZodObject<
|
|
||||||
SchemaT,
|
|
||||||
SchemaUnknownKeys,
|
|
||||||
SchemaCatchall,
|
|
||||||
Values,
|
|
||||||
Values
|
|
||||||
>
|
|
||||||
|
|
||||||
readonly schemaWithDefaultValues: z.ZodObject<
|
|
||||||
SchemaWithDefaultValuesT,
|
|
||||||
SchemaWithDefaultValuesUnknownKeys,
|
|
||||||
SchemaWithDefaultValuesCatchall,
|
|
||||||
Values,
|
|
||||||
Input
|
|
||||||
>
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the constructor parameters for a schema class.
|
|
||||||
*
|
|
||||||
* @template Values - The type of values expected by the schema.
|
|
||||||
*/
|
|
||||||
export type SchemaClassConstructorParams<
|
|
||||||
Values extends {} = {}
|
|
||||||
> = (
|
|
||||||
Parameters<
|
|
||||||
(data: Values) => void
|
|
||||||
>
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a schema object with generic parameters for defining validation schemas.
|
|
||||||
*
|
|
||||||
* @template Values - The type of values expected by the schema.
|
|
||||||
* @template Input - The type of input data expected by the schema.
|
|
||||||
* @template SchemaT - The type of the raw shape of the schema.
|
|
||||||
* @template SchemaUnknownKeys - The type of unknown keys parameter for the schema.
|
|
||||||
* @template SchemaCatchall - The type of catchall parameter for the schema.
|
|
||||||
* @template SchemaWithDefaultValuesT - The type of the raw shape for default values schema.
|
|
||||||
* @template SchemaWithDefaultValuesUnknownKeys - The type of unknown keys parameter for default values schema.
|
|
||||||
* @template SchemaWithDefaultValuesCatchall - The type of catchall parameter for default values schema.
|
|
||||||
*/
|
|
||||||
export type SchemaObject<
|
|
||||||
Values extends {} = {},
|
Values extends {} = {},
|
||||||
Input extends {} = {},
|
Input extends {} = {},
|
||||||
|
|
||||||
@@ -97,6 +25,9 @@ export type SchemaObject<
|
|||||||
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam = z.UnknownKeysParam,
|
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam = z.UnknownKeysParam,
|
||||||
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny = z.ZodTypeAny,
|
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny = z.ZodTypeAny,
|
||||||
> = {
|
> = {
|
||||||
|
readonly values: Values
|
||||||
|
readonly input: Input
|
||||||
|
|
||||||
readonly schema: z.ZodObject<
|
readonly schema: z.ZodObject<
|
||||||
SchemaT,
|
SchemaT,
|
||||||
SchemaUnknownKeys,
|
SchemaUnknownKeys,
|
||||||
@@ -112,4 +43,48 @@ export type SchemaObject<
|
|||||||
Values,
|
Values,
|
||||||
Input
|
Input
|
||||||
>
|
>
|
||||||
} & Values
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a class with validation schemas.
|
||||||
|
* @template $Config - The configuration type for the schemable object.
|
||||||
|
*/
|
||||||
|
export type SchemaClass<
|
||||||
|
$Config extends SchemableConfig
|
||||||
|
> = (
|
||||||
|
Class<
|
||||||
|
SchemaObject<$Config>,
|
||||||
|
SchemaClassConstructorParams<$Config>
|
||||||
|
> & {
|
||||||
|
readonly $schemableConfig: $Config
|
||||||
|
readonly schema: $Config["schema"]
|
||||||
|
readonly schemaWithDefaultValues: $Config["schemaWithDefaultValues"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the constructor parameters for the schemable object class.
|
||||||
|
* @template $Config - The configuration type for the schemable object.
|
||||||
|
*/
|
||||||
|
export type SchemaClassConstructorParams<
|
||||||
|
$Config extends SchemableConfig
|
||||||
|
> = (
|
||||||
|
Parameters<
|
||||||
|
(data: $Config["values"]) => void
|
||||||
|
>
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an object with validation schemas.
|
||||||
|
* @template $Config - The configuration type for the schemable object.
|
||||||
|
*/
|
||||||
|
export type SchemaObject<
|
||||||
|
$Config extends SchemableConfig
|
||||||
|
> = (
|
||||||
|
{
|
||||||
|
readonly $schemableConfig: $Config
|
||||||
|
readonly schema: $Config["schema"]
|
||||||
|
readonly schemaWithDefaultValues: $Config["schemaWithDefaultValues"]
|
||||||
|
} & $Config["values"]
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user