Option jsonification work
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { Decimal } from "decimal.js"
|
||||
import { identity } from "lodash-es"
|
||||
import { Opaque } from "type-fest"
|
||||
import { z } from "zod"
|
||||
|
||||
|
||||
export type JsonifiedDecimal = Opaque<string, "@thilawyn/zod-schema-class/JsonifiedDecimal">
|
||||
export type JsonifiedDecimalBrand = "@thilawyn/zod-schema-class/JsonifiedDecimal"
|
||||
|
||||
|
||||
export function jsonifyDecimalSchema<S extends z.ZodType<Decimal>>(schema: S) {
|
||||
return schema.transform(v => v.toJSON() as JsonifiedDecimal)
|
||||
return schema
|
||||
.transform(v => v.toJSON())
|
||||
.brand<JsonifiedDecimalBrand>()
|
||||
}
|
||||
|
||||
export function dejsonifyDecimalSchema<S extends z.ZodType<Decimal>>(schema: S) {
|
||||
return z
|
||||
.custom<JsonifiedDecimal>(identity)
|
||||
.custom<string & z.BRAND<JsonifiedDecimalBrand>>()
|
||||
.pipe(
|
||||
z
|
||||
.string()
|
||||
|
||||
Reference in New Issue
Block a user