From 7d278f7422b71cb610a70ecc4c9949bfdf2e92a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 21 Mar 2024 18:34:33 +0100 Subject: [PATCH] Schema work --- src/schema/effect/option.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/schema/effect/option.ts b/src/schema/effect/option.ts index b86e4d8..ba6aed1 100644 --- a/src/schema/effect/option.ts +++ b/src/schema/effect/option.ts @@ -3,25 +3,23 @@ import { identity } from "lodash-es" import { z } from "zod" -export const option = { - option: (schema: S) => - z.union([option.some(schema), option.none(schema)]), +export const option = (schema: S) => + z.union([option.some(schema), option.none(schema)]) - some: (schema: S) => z - .custom>>(v => Option.isOption(v) && Option.isSome(v), "Not an Option") - .pipe(z.object({ value: schema }).passthrough()) - .transform>>(identity), +option.some = (schema: S) => z + .custom>>(v => Option.isOption(v) && Option.isSome(v), "Not an Option") + .pipe(z.object({ value: schema }).passthrough()) + .transform>>(identity) - none: (_schema?: S) => - z.custom - : unknown - >>(v => Option.isOption(v) && Option.isNone(v), "Not an Option"), -} as const +option.none = (_schema?: S) => + z.custom + : unknown + >>(v => Option.isOption(v) && Option.isNone(v), "Not an Option") -export type ZodEffectOption = ReturnType> +export type ZodEffectOption = ReturnType> export const effectOptionSomeSchema = (schema: ZodEffectOption): ZodEffectOptionSome => schema.options[0]