|
|
|
|
@@ -1,4 +1,4 @@
|
|
|
|
|
import { TraitStaticMembers, expression } from "@thilawyn/traitify-ts"
|
|
|
|
|
import { TraitStaticMembers, trait } from "@thilawyn/traitify-ts"
|
|
|
|
|
import { HasRequiredKeys } from "type-fest"
|
|
|
|
|
import { z } from "zod"
|
|
|
|
|
import { ZodSchemaClass } from "../shapes/ZodSchemaClass"
|
|
|
|
|
@@ -6,6 +6,8 @@ import { parseZodTypeEffect } from "../util"
|
|
|
|
|
import { ZodSchemaObjectInstantiationSchemas } from "./ZodSchemaObjectInstantiationSchemas"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ZodSchemaObjectInstantiationSchemasStaticMembers = TraitStaticMembers<typeof ZodSchemaObjectInstantiationSchemas>
|
|
|
|
|
|
|
|
|
|
type NewZodSchemaInstanceInput<
|
|
|
|
|
Values extends object,
|
|
|
|
|
DefaultValues extends Partial<Values>,
|
|
|
|
|
@@ -26,66 +28,63 @@ type NewZodSchemaInstanceArgs<Input extends object> = (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const InstantiableZodSchemaObject = expression
|
|
|
|
|
.expresses(ZodSchemaObjectInstantiationSchemas)
|
|
|
|
|
export const InstantiableZodSchemaObject = trait
|
|
|
|
|
.implement(Super => class InstantiableZodSchemaObject extends Super {
|
|
|
|
|
static create<
|
|
|
|
|
Instance extends Values,
|
|
|
|
|
|
|
|
|
|
SchemaWithDefaultValuesT extends z.ZodRawShape,
|
|
|
|
|
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam,
|
|
|
|
|
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny,
|
|
|
|
|
|
|
|
|
|
Values extends object,
|
|
|
|
|
PartialValues extends Partial<Values>,
|
|
|
|
|
>(
|
|
|
|
|
this: (
|
|
|
|
|
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
|
|
|
|
|
ZodSchemaObjectInstantiationSchemasStaticMembers
|
|
|
|
|
),
|
|
|
|
|
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
|
|
|
|
) {
|
|
|
|
|
return this.instantiationSchemaWithDefaultValues().parse(values, params)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async createPromise<
|
|
|
|
|
Instance extends Values,
|
|
|
|
|
|
|
|
|
|
SchemaWithDefaultValuesT extends z.ZodRawShape,
|
|
|
|
|
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam,
|
|
|
|
|
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny,
|
|
|
|
|
|
|
|
|
|
Values extends object,
|
|
|
|
|
PartialValues extends Partial<Values>,
|
|
|
|
|
>(
|
|
|
|
|
this: (
|
|
|
|
|
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
|
|
|
|
|
ZodSchemaObjectInstantiationSchemasStaticMembers
|
|
|
|
|
),
|
|
|
|
|
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
|
|
|
|
) {
|
|
|
|
|
return this.instantiationSchemaWithDefaultValues().parseAsync(values, params)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static createEffect<
|
|
|
|
|
Instance extends Values,
|
|
|
|
|
|
|
|
|
|
SchemaWithDefaultValuesT extends z.ZodRawShape,
|
|
|
|
|
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam,
|
|
|
|
|
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny,
|
|
|
|
|
|
|
|
|
|
Values extends object,
|
|
|
|
|
PartialValues extends Partial<Values>,
|
|
|
|
|
>(
|
|
|
|
|
this: (
|
|
|
|
|
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
|
|
|
|
|
ZodSchemaObjectInstantiationSchemasStaticMembers
|
|
|
|
|
),
|
|
|
|
|
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
|
|
|
|
) {
|
|
|
|
|
return parseZodTypeEffect(this.instantiationSchemaWithDefaultValues(), values, params)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.build()
|
|
|
|
|
.subtrait()
|
|
|
|
|
.implement(Super => class InstantiableZodSchemaObject extends Super {
|
|
|
|
|
static create<
|
|
|
|
|
Instance extends Values,
|
|
|
|
|
|
|
|
|
|
SchemaWithDefaultValuesT extends z.ZodRawShape,
|
|
|
|
|
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam,
|
|
|
|
|
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny,
|
|
|
|
|
|
|
|
|
|
Values extends object,
|
|
|
|
|
PartialValues extends Partial<Values>,
|
|
|
|
|
>(
|
|
|
|
|
this: (
|
|
|
|
|
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
|
|
|
|
|
TraitStaticMembers<typeof ZodSchemaObjectInstantiationSchemas>
|
|
|
|
|
),
|
|
|
|
|
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
|
|
|
|
) {
|
|
|
|
|
return this.instantiationSchemaWithDefaultValues().parse(values, params)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async createPromise<
|
|
|
|
|
Instance extends Values,
|
|
|
|
|
|
|
|
|
|
SchemaWithDefaultValuesT extends z.ZodRawShape,
|
|
|
|
|
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam,
|
|
|
|
|
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny,
|
|
|
|
|
|
|
|
|
|
Values extends object,
|
|
|
|
|
PartialValues extends Partial<Values>,
|
|
|
|
|
>(
|
|
|
|
|
this: (
|
|
|
|
|
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
|
|
|
|
|
TraitStaticMembers<typeof ZodSchemaObjectInstantiationSchemas>
|
|
|
|
|
),
|
|
|
|
|
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
|
|
|
|
) {
|
|
|
|
|
return this.instantiationSchemaWithDefaultValues().parseAsync(values, params)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static createEffect<
|
|
|
|
|
Instance extends Values,
|
|
|
|
|
|
|
|
|
|
SchemaWithDefaultValuesT extends z.ZodRawShape,
|
|
|
|
|
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam,
|
|
|
|
|
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny,
|
|
|
|
|
|
|
|
|
|
Values extends object,
|
|
|
|
|
PartialValues extends Partial<Values>,
|
|
|
|
|
>(
|
|
|
|
|
this: (
|
|
|
|
|
ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues> &
|
|
|
|
|
TraitStaticMembers<typeof ZodSchemaObjectInstantiationSchemas>
|
|
|
|
|
),
|
|
|
|
|
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
|
|
|
|
) {
|
|
|
|
|
return parseZodTypeEffect(this.instantiationSchemaWithDefaultValues(), values, params)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.build()
|
|
|
|
|
|