0.1.0 #1

Merged
Thilawyn merged 24 commits from next into master 2024-01-05 00:39:33 +01:00
Showing only changes of commit 737cb781e6 - Show all commits

View File

@@ -3,18 +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 {} = {}, Values extends {} = {},
Input extends {} = {}, Input extends {} = {},
@@ -25,23 +24,10 @@ export type SchemaClass<
SchemaWithDefaultValuesT extends z.ZodRawShape = z.ZodRawShape, SchemaWithDefaultValuesT extends z.ZodRawShape = z.ZodRawShape,
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam = z.UnknownKeysParam, SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam = z.UnknownKeysParam,
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny = z.ZodTypeAny, SchemaWithDefaultValuesCatchall extends z.ZodTypeAny = z.ZodTypeAny,
> = ( > = {
Class< readonly values: Values
SchemaObject< readonly input: Input
Values,
Input,
SchemaT,
SchemaUnknownKeys,
SchemaCatchall,
SchemaWithDefaultValuesT,
SchemaWithDefaultValuesUnknownKeys,
SchemaWithDefaultValuesCatchall
>,
SchemaClassConstructorParams<Values>
> & {
readonly schema: z.ZodObject< readonly schema: z.ZodObject<
SchemaT, SchemaT,
SchemaUnknownKeys, SchemaUnknownKeys,
@@ -58,58 +44,47 @@ export type SchemaClass<
Input Input
> >
} }
/**
* 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 a schema class. * Represents the constructor parameters for the schemable object class.
* * @template $Config - The configuration type for the schemable object.
* @template Values - The type of values expected by the schema.
*/ */
export type SchemaClassConstructorParams< export type SchemaClassConstructorParams<
Values extends {} = {} $Config extends SchemableConfig
> = ( > = (
Parameters< Parameters<
(data: Values) => void (data: $Config["values"]) => void
> >
) )
/** /**
* Represents a schema object with generic parameters for defining validation schemas. * Represents an object with validation schemas.
* * @template $Config - The configuration type for the schemable object.
* @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< export type SchemaObject<
Values extends {} = {}, $Config extends SchemableConfig
Input extends {} = {}, > = (
{
SchemaT extends z.ZodRawShape = z.ZodRawShape, readonly $schemableConfig: $Config
SchemaUnknownKeys extends z.UnknownKeysParam = z.UnknownKeysParam, readonly schema: $Config["schema"]
SchemaCatchall extends z.ZodTypeAny = z.ZodTypeAny, readonly schemaWithDefaultValues: $Config["schemaWithDefaultValues"]
} & $Config["values"]
SchemaWithDefaultValuesT extends z.ZodRawShape = z.ZodRawShape, )
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam = z.UnknownKeysParam,
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny = z.ZodTypeAny,
> = {
readonly schema: z.ZodObject<
SchemaT,
SchemaUnknownKeys,
SchemaCatchall,
Values,
Values
>
readonly schemaWithDefaultValues: z.ZodObject<
SchemaWithDefaultValuesT,
SchemaWithDefaultValuesUnknownKeys,
SchemaWithDefaultValuesCatchall,
Values,
Input
>
} & Values