Jsonifiable

This commit is contained in:
Julien Valverdé
2024-01-01 23:14:08 +01:00
parent 92271583ce
commit 00040fb7df
9 changed files with 87 additions and 8 deletions

View File

@@ -0,0 +1,18 @@
import { z } from "zod"
export const jsonifyBigIntSchema = <S extends z.ZodBigInt>(schema: S) =>
schema.transform(v => v.toString())
export const dejsonifyBigIntSchema = <S extends z.ZodBigInt>(schema: S) =>
z
.string()
.transform(v => {
try {
return BigInt(v)
}
catch (e) {
return v
}
})
.pipe(schema)