@pesto-io/zod-reify
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-alpha-commit-baa4aa315000547e899f021f69a807ff4406756e • Public • Published

Pesto

npm bundle size

CircleCI (branch)

Zod Reify

The zod-reify npm package contains zod related utilities that the pesto app uses.

One of the most important, is the ZodSchemaReifier, which is able to read some source code provided as a simple string, and to instantiate a zod schema.

  • left TODO before a first release:

I have now the generalized algorithm:

  • [ ] we need to add more test cases to fully cover all zod functions support.
  • [ ] We also need to update docs and README. We also need to change the git repository.
  • [x] We also need to complete method renaming.
  • [ ] We also need to replace any console.log with winston logging silenced by default.
  • [ ] setup the cloudflare pages to publish the documentation astro website

Finally adding some speed automated tests with https://github.com/tinylibs/tinybench

Jest Tests reporting:

How to Use

  • first, install the package:
npm i @pesto-io/zod-reify
# pnpm add @pesto-io/zod-reify
  • Then, in your code, you can:
import { ZodSchemaReifier } from "@pesto-io/zod-reify"

Contribute

Git clone the source, and:

  • Install dependencies:
pnpm i

Running the Tests

Jest is the framework used to run automatic, non regression, unit testing.

  • To run all jest tests, run:
pnpm test

Inside the ./tests/reify/ZodSchemaReifier.test.ts Test Suite file, the tests are designed like this:

  • You will find a number of TestCase Objects

  • The Jest Tests run an each loop over arrays of TestCase Objects

  • All The TestCase Objects implement either of:

    • ZodValidateTestCase<T>: the Test cases implementing that interface are all meant to test running the zod safeParse method, using a zod schema reified using the reify method, defined in the ZodSchemaReifier class, which source code is in ./src/reify/ZodSchemaReifier.ts.
    • FrontMatterValidateTestCase<T>: the Test cases implementing that interface are all meant to test running the zod safeParse method, using a zod schema reified using the reify method, defined in the ZodSchemaReifier class, which source code is in ./src/reify/ZodSchemaReifier.ts, over frontmatter data parsed by the zod-matter parse method, over a test markdown.
    • both of the ZodValidateTestCase<T> and FrontMatterValidateTestCase<T> interfaces have a name property
  • To run a single test case (important to debug your code), you can simply use the value of the name (coming from either of ZodValidateTestCase<T> or FrontMatterValidateTestCase<T> interfaces), like this:

# --
# below will run only the 
# 'const testCase1bis: ZodValidateTestCase', cf. The './tests/reify/ZodSchemaReifier.test.ts' Test Suite file.

pnpm test -- -t 'Test #1bis: zodSchema1 should fail with null'

# --
# below will run only the 
# 'const testCase2: ZodValidateTestCase', cf. The './tests/reify/ZodSchemaReifier.test.ts' Test Suite file.
pnpm test -- -t 'Test #2: zodSchema2'


# --
# below will run only the 
# 'const markDownTestCase4: FrontMatterValidateTestCase', cf. The './tests/reify/ZodSchemaReifier.test.ts' Test Suite file.
pnpm test -- -t 'Test #4: markdown frontmatter extraction zodSchema4'

Worth noting, other test run options:

# [pnpm test -- -i <your-test-file> -c <jest-config> -t "<test-block-name>"]
# --- 
# [pnpm test -- -c ./jest.config.ts]
# [pnpm test -- -c ./jest.config.ts -t 'Test #1bis: zodSchema1 should fail with null']

Generate the docs

pnpm run gen:api-docs

The Astro docs (WIP)

pnpm run build:docs:astro
# pnpm run dev:docs:astro

ANNEX: The next Evolution

Evaluate typescript from string

import * as ts from "typescript";

let code: string = `({
    Run: (data: string): string => {
        console.log(data); return Promise.resolve("SUCCESS"); }
    })`;

let result = ts.transpile(code);
let runnable :any = eval(result);
runnable.Run("RUN!").then((result:string)=>{console.log(result);});

Package Sidebar

Install

npm i @pesto-io/zod-reify

Weekly Downloads

5

Version

0.0.1-alpha-commit-baa4aa315000547e899f021f69a807ff4406756e

License

ISC

Unpacked Size

101 kB

Total Files

10

Last publish

Collaborators

  • pesto-bot