Schema work
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julien Valverdé
2024-03-19 18:25:56 +01:00
parent 5e7588510d
commit 9ddda594ef
5 changed files with 12 additions and 10 deletions

5
src/schema/decimal.ts Normal file
View File

@@ -0,0 +1,5 @@
import Decimal from "decimal.js"
import { z } from "zod"
export const decimal = z.custom<Decimal>(v => Decimal.isDecimal(v))

View File

@@ -6,11 +6,11 @@ import { z } from "zod"
export type JsonifiedBigInt = Opaque<string, "@thilawyn/zod-schema-class/JsonifiedBigInt"> export type JsonifiedBigInt = Opaque<string, "@thilawyn/zod-schema-class/JsonifiedBigInt">
export function jsonifyBigIntSchema<S extends z.ZodBigInt>(schema: S) { export function jsonifyBigIntSchema<S extends z.ZodType<bigint>>(schema: S) {
return schema.transform(v => v.toString() as JsonifiedBigInt) return schema.transform(v => v.toString() as JsonifiedBigInt)
} }
export function dejsonifyBigIntSchema<S extends z.ZodBigInt>(schema: S) { export function dejsonifyBigIntSchema<S extends z.ZodType<bigint>>(schema: S) {
return z return z
.custom<JsonifiedBigInt>(identity) .custom<JsonifiedBigInt>(identity)
.pipe( .pipe(

View File

@@ -6,11 +6,11 @@ import { z } from "zod"
export type JsonifiedDate = Opaque<string, "@thilawyn/zod-schema-class/JsonifiedDate"> export type JsonifiedDate = Opaque<string, "@thilawyn/zod-schema-class/JsonifiedDate">
export function jsonifyDateSchema<S extends z.ZodDate>(schema: S) { export function jsonifyDateSchema<S extends z.ZodType<Date>>(schema: S) {
return schema.transform(v => v.toString() as JsonifiedDate) return schema.transform(v => v.toString() as JsonifiedDate)
} }
export function dejsonifyDateSchema<S extends z.ZodDate>(schema: S) { export function dejsonifyDateSchema<S extends z.ZodType<Date>>(schema: S) {
return z return z
.custom<JsonifiedDate>(identity) .custom<JsonifiedDate>(identity)
.pipe( .pipe(

View File

@@ -7,15 +7,11 @@ import { z } from "zod"
export type JsonifiedDecimal = Opaque<string, "@thilawyn/zod-schema-class/JsonifiedDecimal"> export type JsonifiedDecimal = Opaque<string, "@thilawyn/zod-schema-class/JsonifiedDecimal">
export function jsonifyDecimalSchema< export function jsonifyDecimalSchema<S extends z.ZodType<Decimal>>(schema: S) {
S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>
>(schema: S) {
return schema.transform(v => v.toJSON() as JsonifiedDecimal) return schema.transform(v => v.toJSON() as JsonifiedDecimal)
} }
export function dejsonifyDecimalSchema< export function dejsonifyDecimalSchema<S extends z.ZodType<Decimal>>(schema: S) {
S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>
>(schema: S) {
return z return z
.custom<JsonifiedDecimal>(identity) .custom<JsonifiedDecimal>(identity)
.pipe( .pipe(

View File

@@ -1,2 +1,3 @@
export * from "./decimal"
export * from "./effect" export * from "./effect"
export * from "./jsonified" export * from "./jsonified"