npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pesto-io/zod-reify

v0.0.1-alpha-commit-baa4aa315000547e899f021f69a807ff4406756e

Published

Pesto module to intantiate zod schema from Typescript source code as string.

Readme

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);});