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