jsonifySchemableSchema refactoring
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,25 +1,139 @@
|
||||
import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
||||
import { z } from "zod"
|
||||
import { JsonifiableSchemableClass, JsonifiableSchemableConfig } from ".."
|
||||
import { JsonifiableSchemableClass } from ".."
|
||||
|
||||
|
||||
// TODO: try to find a way to get rid of the 'class_' arg
|
||||
export const jsonifySchemableSchema = <
|
||||
C extends JsonifiableSchemableClass<$Config>,
|
||||
$Config extends JsonifiableSchemableConfig,
|
||||
S extends z.ZodType<InstanceType<C>, z.ZodTypeDef, InstanceType<C>>,
|
||||
export function jsonifySchemableSchema<
|
||||
C extends JsonifiableSchemableClass<
|
||||
SchemaT,
|
||||
SchemaUnknownKeys,
|
||||
SchemaCatchall,
|
||||
|
||||
Values,
|
||||
DefaultValues,
|
||||
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
JsonifiedValues,
|
||||
|
||||
"Class"
|
||||
>,
|
||||
|
||||
SchemaT extends z.ZodRawShape,
|
||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
SchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
Values extends {},
|
||||
DefaultValues extends Partial<Values>,
|
||||
|
||||
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,
|
||||
|
||||
S extends z.ZodType<InstanceType<C>, z.ZodTypeDef, InstanceType<C>>,
|
||||
>(
|
||||
class_: C | JsonifiableSchemableClass<$Config>,
|
||||
schema: S,
|
||||
) =>
|
||||
schema.pipe(class_.jsonifySchema)
|
||||
class_: C | JsonifiableSchemableClass<
|
||||
SchemaT,
|
||||
SchemaUnknownKeys,
|
||||
SchemaCatchall,
|
||||
|
||||
// TODO: try to find a way to get rid of the 'class_' arg
|
||||
export const dejsonifySchemableSchema = <
|
||||
C extends JsonifiableSchemableClass<$Config>,
|
||||
$Config extends JsonifiableSchemableConfig,
|
||||
S extends z.ZodType<InstanceType<C>, z.ZodTypeDef, InstanceType<C>>,
|
||||
Values,
|
||||
DefaultValues,
|
||||
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
JsonifiedValues,
|
||||
|
||||
"Class"
|
||||
>,
|
||||
|
||||
schema: S,
|
||||
) {
|
||||
return schema.pipe(class_.jsonifySchema)
|
||||
}
|
||||
|
||||
|
||||
export function dejsonifySchemableSchema<
|
||||
C extends JsonifiableSchemableClass<
|
||||
SchemaT,
|
||||
SchemaUnknownKeys,
|
||||
SchemaCatchall,
|
||||
|
||||
Values,
|
||||
DefaultValues,
|
||||
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
JsonifiedValues,
|
||||
|
||||
"Class"
|
||||
>,
|
||||
|
||||
SchemaT extends z.ZodRawShape,
|
||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
SchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
Values extends {},
|
||||
DefaultValues extends Partial<Values>,
|
||||
|
||||
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,
|
||||
|
||||
S extends z.ZodType<InstanceType<C>, z.ZodTypeDef, InstanceType<C>>,
|
||||
>(
|
||||
class_: C | JsonifiableSchemableClass<$Config>,
|
||||
schema: S,
|
||||
) =>
|
||||
class_.dejsonifySchema.transform(v => new class_(v)).pipe(schema)
|
||||
class_: C | JsonifiableSchemableClass<
|
||||
SchemaT,
|
||||
SchemaUnknownKeys,
|
||||
SchemaCatchall,
|
||||
|
||||
Values,
|
||||
DefaultValues,
|
||||
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
JsonifiedValues,
|
||||
|
||||
"Class"
|
||||
>,
|
||||
|
||||
schema: S,
|
||||
) {
|
||||
return class_.dejsonifySchema.transform(v => new class_(v)).pipe(schema)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user