@zod-plugin/effect
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Zod logo

Zod

https://zod.dev
TypeScript-first schema validation with static type inference




Effect plugin for Zod

This is a plugin to add support for Effect to Zod. Effect provides a foundation for writing TypeScript in a functional, composable way. Refer to the Effect docs for details.

Usage

Requirements (peer dependencies):

  • zod@^3.0.0
  • effect@^3.0.0

To install the plugin:

npm add effect zod @zod-plugin/effect

To use the plugin, add the following line in the entry point of your application:

import "@zod-plugin/effect";

This adds two new methods to the ZodType base class. These methods are now available on all schemas throughout your application.

.effect.parse(data): Effect<T, ZodError, never>

This method accepts some input data and parses it asynchronously.

import * as z from "zod";
import { Effect } from "effect";

import "@zod-plugin/effect";

const schema = z.object({
  name: z.string(),
});

const effect = schema.effect.parse({ name: "Michael Arnaldi" });
//=>  Effect<{ name: string }, ZodError, never>;

await Effect.runPromise(effect);
// => { name: "Michael Arnaldi" }

.effect.parseSync(data): Effect<T, ZodError, never>

This method accepts some input data and parses it synchronously. If any asynchronous refinements or transforms are encountered, Effect will throw an error.

import * as z from "zod";
import { Effect } from "effect";

import "@zod-plugin/effect";

const schema = z.object({
  name: z.string(),
});

const effect = schema.effect.parseSync({ name: "Michael Arnaldi" });
//=>  Effect<{ name: string }, ZodError, never>;

await Effect.runSync(effect);
// => { name: "Michael Arnaldi" }

Package Sidebar

Install

npm i @zod-plugin/effect

Weekly Downloads

9

Version

0.1.0

License

MIT

Unpacked Size

104 kB

Total Files

6

Last publish

Collaborators

  • colinmcd94