This commit is contained in:
6
src/schema/effect/index.ts
Normal file
6
src/schema/effect/index.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { option } from "./option"
|
||||||
|
|
||||||
|
|
||||||
|
export const effect = {
|
||||||
|
option,
|
||||||
|
} as const
|
||||||
21
src/schema/effect/option.ts
Normal file
21
src/schema/effect/option.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { Option } from "effect"
|
||||||
|
import { identity } from "lodash-es"
|
||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
|
||||||
|
export const option = {
|
||||||
|
some: <S extends z.ZodSchema>(schema: S) => z
|
||||||
|
.custom(v => Option.isOption(v) && Option.isSome(v), "Not an Option")
|
||||||
|
.pipe(z.object({ value: schema }).passthrough())
|
||||||
|
.transform<Option.Some<z.output<S>>>(identity),
|
||||||
|
|
||||||
|
none: <S extends z.ZodSchema | unknown = unknown>(_schema?: S) =>
|
||||||
|
z.custom<Option.None<
|
||||||
|
S extends z.ZodSchema
|
||||||
|
? z.output<S>
|
||||||
|
: unknown
|
||||||
|
>>(v => Option.isOption(v) && Option.isNone(v), "Not an Option"),
|
||||||
|
|
||||||
|
option: <S extends z.ZodSchema>(schema: S) =>
|
||||||
|
z.union([option.some(schema), option.none(schema)]),
|
||||||
|
} as const
|
||||||
@@ -1 +1,2 @@
|
|||||||
|
export * from "./effect"
|
||||||
export * from "./jsonifiable"
|
export * from "./jsonifiable"
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ import { z } from "zod"
|
|||||||
import { zodSchemaClass } from "./builders/ZodSchemaClassBuilder"
|
import { zodSchemaClass } from "./builders/ZodSchemaClassBuilder"
|
||||||
import { dejsonify, jsonify } from "./schema/jsonifiable"
|
import { dejsonify, jsonify } from "./schema/jsonifiable"
|
||||||
import { MobXObservableZodSchemaObject } from "./traits/MobXObservableZodSchemaObject"
|
import { MobXObservableZodSchemaObject } from "./traits/MobXObservableZodSchemaObject"
|
||||||
|
import { effect } from "./schema/effect"
|
||||||
|
|
||||||
|
|
||||||
|
const stringOption = effect.option.option(z.string())
|
||||||
|
type T = z.output<typeof stringOption>
|
||||||
|
|
||||||
|
|
||||||
const exp = zodSchemaClass
|
const exp = zodSchemaClass
|
||||||
|
|||||||
Reference in New Issue
Block a user