0.1.0 #1
@@ -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
17
src/newSchemable.ts
Normal 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))
|
||||
Reference in New Issue
Block a user