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:
@@ -1,11 +1,12 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
|
||||||
export const jsonifyBigIntSchema = <S extends z.ZodBigInt>(schema: S) =>
|
export function jsonifyBigIntSchema<S extends z.ZodBigInt>(schema: S) {
|
||||||
schema.transform(v => v.toString())
|
return schema.transform(v => v.toString())
|
||||||
|
}
|
||||||
|
|
||||||
export const dejsonifyBigIntSchema = <S extends z.ZodBigInt>(schema: S) =>
|
export function dejsonifyBigIntSchema<S extends z.ZodBigInt>(schema: S) {
|
||||||
z
|
return z
|
||||||
.string()
|
.string()
|
||||||
.transform(v => {
|
.transform(v => {
|
||||||
try {
|
try {
|
||||||
@@ -16,3 +17,4 @@ export const dejsonifyBigIntSchema = <S extends z.ZodBigInt>(schema: S) =>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.pipe(schema)
|
.pipe(schema)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
|
||||||
export const jsonifyDateSchema = <S extends z.ZodDate>(schema: S) =>
|
export function jsonifyDateSchema<S extends z.ZodDate>(schema: S) {
|
||||||
schema.transform(v => v.toString())
|
return schema.transform(v => v.toString())
|
||||||
|
}
|
||||||
|
|
||||||
export const dejsonifyDateSchema = <S extends z.ZodDate>(schema: S) =>
|
export function dejsonifyDateSchema<S extends z.ZodDate>(schema: S) {
|
||||||
z
|
return z
|
||||||
.string()
|
.string()
|
||||||
.transform(v => {
|
.transform(v => {
|
||||||
try {
|
try {
|
||||||
@@ -16,3 +17,4 @@ export const dejsonifyDateSchema = <S extends z.ZodDate>(schema: S) =>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.pipe(schema)
|
.pipe(schema)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ import { Decimal } from "decimal.js"
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
|
||||||
export const jsonifyDecimalSchema = <S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>>(schema: S) =>
|
export function jsonifyDecimalSchema<
|
||||||
schema.transform(v => v.toJSON())
|
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) =>
|
export function dejsonifyDecimalSchema<
|
||||||
z
|
S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>
|
||||||
|
>(schema: S) {
|
||||||
|
return z
|
||||||
.string()
|
.string()
|
||||||
.transform(v => {
|
.transform(v => {
|
||||||
try {
|
try {
|
||||||
@@ -17,3 +22,4 @@ export const dejsonifyDecimalSchema = <S extends z.ZodType<Decimal, z.ZodTypeDef
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.pipe(schema)
|
.pipe(schema)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user