0.1.2 #3
@@ -7,94 +7,5 @@ import { parseZodTypeEffect } from "../util"
|
||||
|
||||
export const JsonifiableZodSchemaObject = trait
|
||||
.implement(Super => class JsonifiableZodSchemaObject extends Super {
|
||||
jsonify<
|
||||
JsonifySchemaT extends z.ZodRawShape,
|
||||
JsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
JsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
DejsonifySchemaT extends z.ZodRawShape,
|
||||
DejsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
DejsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
JsonifiedValues extends JsonifiableObject,
|
||||
Values extends object,
|
||||
>(
|
||||
this: Values & JsonifiableZodSchemas<
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
JsonifiedValues,
|
||||
Values
|
||||
>,
|
||||
|
||||
params?: Partial<z.ParseParams>,
|
||||
) {
|
||||
return this.jsonifySchema.parse(this, params)
|
||||
}
|
||||
|
||||
async jsonifyPromise<
|
||||
JsonifySchemaT extends z.ZodRawShape,
|
||||
JsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
JsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
DejsonifySchemaT extends z.ZodRawShape,
|
||||
DejsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
DejsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
JsonifiedValues extends JsonifiableObject,
|
||||
Values extends object,
|
||||
>(
|
||||
this: Values & JsonifiableZodSchemas<
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
JsonifiedValues,
|
||||
Values
|
||||
>,
|
||||
|
||||
params?: Partial<z.ParseParams>,
|
||||
) {
|
||||
return this.jsonifySchema.parseAsync(this, params)
|
||||
}
|
||||
|
||||
jsonifyEffect<
|
||||
JsonifySchemaT extends z.ZodRawShape,
|
||||
JsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
JsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
DejsonifySchemaT extends z.ZodRawShape,
|
||||
DejsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
DejsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
JsonifiedValues extends JsonifiableObject,
|
||||
Values extends object,
|
||||
>(
|
||||
this: Values & JsonifiableZodSchemas<
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
JsonifiedValues,
|
||||
Values
|
||||
>,
|
||||
|
||||
params?: Partial<z.ParseParams>,
|
||||
) {
|
||||
return parseZodTypeEffect(this.jsonifySchema, this, params)
|
||||
}
|
||||
})
|
||||
.build()
|
||||
|
||||
@@ -85,3 +85,32 @@ export const ZodSchemaObject = <
|
||||
}
|
||||
})
|
||||
.build()
|
||||
|
||||
|
||||
export type ZodSchemaObjectTrait<
|
||||
SchemaT extends z.ZodRawShape,
|
||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
SchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
SchemaWithDefaultValuesT extends z.ZodRawShape,
|
||||
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam,
|
||||
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny,
|
||||
|
||||
Values extends object,
|
||||
PartialValues extends Partial<Values>,
|
||||
> = (
|
||||
ReturnType<
|
||||
typeof ZodSchemaObject<
|
||||
SchemaT,
|
||||
SchemaUnknownKeys,
|
||||
SchemaCatchall,
|
||||
|
||||
SchemaWithDefaultValuesT,
|
||||
SchemaWithDefaultValuesUnknownKeys,
|
||||
SchemaWithDefaultValuesCatchall,
|
||||
|
||||
Values,
|
||||
PartialValues
|
||||
>
|
||||
>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user