18 lines
551 B
TypeScript
18 lines
551 B
TypeScript
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))
|