Jsonifiable schema refactoring
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -2,11 +2,16 @@ import { Decimal } from "decimal.js"
|
||||
import { z } from "zod"
|
||||
|
||||
|
||||
export const jsonifyDecimalSchema = <S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>>(schema: S) =>
|
||||
schema.transform(v => v.toJSON())
|
||||
export function jsonifyDecimalSchema<
|
||||
S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>
|
||||
>(schema: S) {
|
||||
return schema.transform(v => v.toJSON())
|
||||
}
|
||||
|
||||
export const dejsonifyDecimalSchema = <S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>>(schema: S) =>
|
||||
z
|
||||
export function dejsonifyDecimalSchema<
|
||||
S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>
|
||||
>(schema: S) {
|
||||
return z
|
||||
.string()
|
||||
.transform(v => {
|
||||
try {
|
||||
@@ -17,3 +22,4 @@ export const dejsonifyDecimalSchema = <S extends z.ZodType<Decimal, z.ZodTypeDef
|
||||
}
|
||||
})
|
||||
.pipe(schema)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user