0.1.1 #2
@@ -1,25 +1,139 @@
|
|||||||
|
import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
||||||
import { z } from "zod"
|
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 function jsonifySchemableSchema<
|
||||||
export const jsonifySchemableSchema = <
|
C extends JsonifiableSchemableClass<
|
||||||
C extends JsonifiableSchemableClass<$Config>,
|
SchemaT,
|
||||||
$Config extends JsonifiableSchemableConfig,
|
SchemaUnknownKeys,
|
||||||
S extends z.ZodType<InstanceType<C>, z.ZodTypeDef, InstanceType<C>>,
|
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>,
|
class_: C | JsonifiableSchemableClass<
|
||||||
schema: S,
|
SchemaT,
|
||||||
) =>
|
SchemaUnknownKeys,
|
||||||
schema.pipe(class_.jsonifySchema)
|
SchemaCatchall,
|
||||||
|
|
||||||
// TODO: try to find a way to get rid of the 'class_' arg
|
Values,
|
||||||
export const dejsonifySchemableSchema = <
|
DefaultValues,
|
||||||
C extends JsonifiableSchemableClass<$Config>,
|
|
||||||
$Config extends JsonifiableSchemableConfig,
|
JsonifySchemaT,
|
||||||
S extends z.ZodType<InstanceType<C>, z.ZodTypeDef, InstanceType<C>>,
|
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>,
|
class_: C | JsonifiableSchemableClass<
|
||||||
schema: S,
|
SchemaT,
|
||||||
) =>
|
SchemaUnknownKeys,
|
||||||
class_.dejsonifySchema.transform(v => new class_(v)).pipe(schema)
|
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