zodser
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

zodser

A serialisation and deserialisation libarary for Zod.

This is useful when there is a need to keep a list of historic versions of zod schema.

Install

npm install zodser
yarn add zodser

Usages

To serialise a zod schema to a string for saving

import { serialise } from "zodser";

const schemaString = serialise(zodSchema);

To deserialise a previously serialised zod schema string

import { deserialise } from "zodser";

const zodSchema = deserialise(schemaString);

limitations

Currently, all built-in Zod types except ZodEffect are supported with below known limitations

ZodCatch

Only constant catch value is supported

// constant value is supported
z.string().catch("fallback");

// catch function that returns a constant value is supported
z.string().catch(() => "fallback");

// this is also okay
const s = "fallback";
z.string().catch(() => s);

// this is not supported, because a different Date will be returned for each call; in this example, timestamp of when serialisation runs will be captured and is used as the catch value after deserialisation
z.date().catch(() => new Date());

Package Sidebar

Install

npm i zodser

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

55.7 kB

Total Files

18

Last publish

Collaborators

  • shaketbaby