0.1.3 #4
5
src/schema/decimal.ts
Normal file
5
src/schema/decimal.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import Decimal from "decimal.js"
|
||||
import { z } from "zod"
|
||||
|
||||
|
||||
export const decimal = z.custom<Decimal>(v => Decimal.isDecimal(v))
|
||||
@@ -6,11 +6,11 @@ import { z } from "zod"
|
||||
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)
|
||||
}
|
||||
|
||||
export function dejsonifyBigIntSchema<S extends z.ZodBigInt>(schema: S) {
|
||||
export function dejsonifyBigIntSchema<S extends z.ZodType<bigint>>(schema: S) {
|
||||
return z
|
||||
.custom<JsonifiedBigInt>(identity)
|
||||
.pipe(
|
||||
|
||||
@@ -6,11 +6,11 @@ import { z } from "zod"
|
||||
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)
|
||||
}
|
||||
|
||||
export function dejsonifyDateSchema<S extends z.ZodDate>(schema: S) {
|
||||
export function dejsonifyDateSchema<S extends z.ZodType<Date>>(schema: S) {
|
||||
return z
|
||||
.custom<JsonifiedDate>(identity)
|
||||
.pipe(
|
||||
|
||||
@@ -7,15 +7,11 @@ import { z } from "zod"
|
||||
export type JsonifiedDecimal = Opaque<string, "@thilawyn/zod-schema-class/JsonifiedDecimal">
|
||||
|
||||
|
||||
export function jsonifyDecimalSchema<
|
||||
S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>
|
||||
>(schema: S) {
|
||||
export function jsonifyDecimalSchema<S extends z.ZodType<Decimal>>(schema: S) {
|
||||
return schema.transform(v => v.toJSON() as JsonifiedDecimal)
|
||||
}
|
||||
|
||||
export function dejsonifyDecimalSchema<
|
||||
S extends z.ZodType<Decimal, z.ZodTypeDef, Decimal>
|
||||
>(schema: S) {
|
||||
export function dejsonifyDecimalSchema<S extends z.ZodType<Decimal>>(schema: S) {
|
||||
return z
|
||||
.custom<JsonifiedDecimal>(identity)
|
||||
.pipe(
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./decimal"
|
||||
export * from "./effect"
|
||||
export * from "./jsonified"
|
||||
|
||||
Reference in New Issue
Block a user