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