SchemaClass -> SchemableClass

This commit is contained in:
Julien Valverdé
2023-12-31 00:48:02 +01:00
parent 737cb781e6
commit 9552a7f709
2 changed files with 22 additions and 5 deletions

View File

@@ -50,12 +50,12 @@ export type SchemableConfig<
* Represents a class with validation schemas.
* @template $Config - The configuration type for the schemable object.
*/
export type SchemaClass<
export type SchemableClass<
$Config extends SchemableConfig
> = (
Class<
SchemaObject<$Config>,
SchemaClassConstructorParams<$Config>
SchemableObject<$Config>,
SchemableClassConstructorParams<$Config>
> & {
readonly $schemableConfig: $Config
readonly schema: $Config["schema"]
@@ -67,7 +67,7 @@ export type SchemaClass<
* Represents the constructor parameters for the schemable object class.
* @template $Config - The configuration type for the schemable object.
*/
export type SchemaClassConstructorParams<
export type SchemableClassConstructorParams<
$Config extends SchemableConfig
> = (
Parameters<
@@ -79,7 +79,7 @@ export type SchemaClassConstructorParams<
* Represents an object with validation schemas.
* @template $Config - The configuration type for the schemable object.
*/
export type SchemaObject<
export type SchemableObject<
$Config extends SchemableConfig
> = (
{

17
src/newSchemable.ts Normal file
View File

@@ -0,0 +1,17 @@
type ParamsArgs = [] | [Partial<z.ParseParams>]
type NewEntityArgs<Input extends object> =
HasRequiredKeys<Input> extends true
? [Input, ...ParamsArgs]
: [] | [Input, ...ParamsArgs]
export const newEntity = <
$Config extends EntityConfig,
Static extends EntityClassStatic<$Config>,
T extends Entity<$Config>,
>(
class_: EntityClass<$Config, Static, T>,
...[values, params]: NewEntityArgs<$Config["input"]>
) =>
new class_(class_.schemaWithDefaultValues.parse(values || {}, params))