import { Opaque } from "type-fest" import { z } from "zod" import { identity } from "../../util" export type JsonifiedBigInt = Opaque export function jsonifyBigIntSchema(schema: S) { return schema.transform(v => v.toString() as JsonifiedBigInt) } export function dejsonifyBigIntSchema(schema: S) { return z .custom(identity) .pipe(z .string() .transform(v => { try { return BigInt(v) } catch (e) { return v } }) .pipe(schema) ) }