diff --git a/src/SchemaClass.ts b/src/SchemableClass.ts similarity index 94% rename from src/SchemaClass.ts rename to src/SchemableClass.ts index 962f622..f85216c 100644 --- a/src/SchemaClass.ts +++ b/src/SchemableClass.ts @@ -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 > = ( { diff --git a/src/newSchemable.ts b/src/newSchemable.ts new file mode 100644 index 0000000..26482a6 --- /dev/null +++ b/src/newSchemable.ts @@ -0,0 +1,17 @@ +type ParamsArgs = [] | [Partial] + +type NewEntityArgs = + HasRequiredKeys 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))