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

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))