0.1.0 #1
@@ -1,3 +1,4 @@
|
|||||||
export * from "./bigint"
|
export * from "./bigint"
|
||||||
export * from "./date"
|
export * from "./date"
|
||||||
export * from "./decimal"
|
export * from "./decimal"
|
||||||
|
export * from "./schemable"
|
||||||
|
|||||||
25
src/jsonifiable/schema/schemable.ts
Normal file
25
src/jsonifiable/schema/schemable.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
import { JsonifiableSchemableClass, JsonifiableSchemableConfig } 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>>,
|
||||||
|
>(
|
||||||
|
class_: C | JsonifiableSchemableClass<$Config>,
|
||||||
|
schema: S,
|
||||||
|
) =>
|
||||||
|
schema.pipe(class_.jsonifySchema)
|
||||||
|
|
||||||
|
// 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>>,
|
||||||
|
>(
|
||||||
|
class_: C | JsonifiableSchemableClass<$Config>,
|
||||||
|
schema: S,
|
||||||
|
) =>
|
||||||
|
class_.dejsonifySchema.transform(v => new class_(v)).pipe(schema)
|
||||||
Reference in New Issue
Block a user