This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { dejsonifyBigIntSchema, jsonifyBigIntSchema } from "./bigint"
|
||||
import { dejsonifyDateSchema, jsonifyDateSchema } from "./date"
|
||||
import { dejsonifyDecimalSchema, jsonifyDecimalSchema } from "./decimal"
|
||||
import { jsonifyOption } from "./option"
|
||||
|
||||
|
||||
export const jsonify = {
|
||||
bigint: jsonifyBigIntSchema,
|
||||
date: jsonifyDateSchema,
|
||||
decimal: jsonifyDecimalSchema,
|
||||
option: jsonifyOption,
|
||||
} as const
|
||||
|
||||
export const dejsonify = {
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { Option } from "effect"
|
||||
import { identity } from "lodash-es"
|
||||
import { z } from "zod"
|
||||
import { effect } from "../effect"
|
||||
|
||||
|
||||
export const jsonifyOption = {
|
||||
option: <S extends z.ZodSchema>(schema: S) =>
|
||||
z.union([option.some(schema), option.none(schema)]),
|
||||
// option: <S extends z.ZodSchema>(schema: S) =>
|
||||
// z.union([option.some(schema), option.none(schema)]),
|
||||
|
||||
some: <S extends z.ZodSchema>(schema: S) => z
|
||||
.custom<Option.Some<z.output<S>>>(v => Option.isOption(v) && Option.isSome(v), "Not an Option")
|
||||
.pipe(z.object({ value: schema }).passthrough())
|
||||
.transform<Option.Some<z.output<S>>>(identity),
|
||||
some: <
|
||||
S extends ReturnType<typeof effect.option.some<T>>,
|
||||
T extends z.ZodSchema,
|
||||
>(
|
||||
schema: S | ReturnType<typeof effect.option.some<T>>
|
||||
) =>
|
||||
(schema as S).transform(v => Option.getOrThrow(v)),
|
||||
|
||||
none: <S extends z.ZodSchema | unknown = unknown>(_schema?: S) =>
|
||||
z.custom<Option.None<
|
||||
|
||||
Reference in New Issue
Block a user