Skip to content

Commit

Permalink
feat(tools-storm-plugins-zod): Added the Zod validation Storm plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Aug 26, 2023
1 parent 7c45e02 commit f050deb
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CI=false
CI=true
TYPESENSE_API_KEY=xyz
NODE_OPTIONS="--trace-warnings --heapsnapshot-near-heap-limit=3 --heapsnapshot-signal=SIGTERM"
NODE_OPTIONS="--trace-warnings --require helios-opentelemetry-sdk --heapsnapshot-near-heap-limit=3 --heapsnapshot-signal=SIGTERM"

ROOT_HOST=192.168.1.18
HOST_SERVER=host.docker.internal
Expand Down
28 changes: 28 additions & 0 deletions tools/storm/plugins/zod/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": ["../../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"parserOptions": {
"project": ["tools/storm/plugins/zod/tsconfig.*?.json"]
},
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
144 changes: 144 additions & 0 deletions tools/storm/plugins/zod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<!-- START header -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->


<div align="center"><img src="https://pub-e71cff0f90204755bc910518d63cacf8.r2.dev/open-system.logo-green.svg" width="100%" title="Open System" altText="Open System" /></div>

<div align="center">
<a href="https://www.patsullivan.org" target="_blank">Website</a> | <a href="https://www.patsullivan.org/contact" target="_blank">Contact</a> | <a href="https:/sullivanpj/open-system" target="_blank">Repository</a> | <a href="https://sullivanpj.github.io/open-system/" target="_blank">Documentation</a> | <a href="https:/sullivanpj/open-system/issues/new?assignees=&labels=bug&template=bug-report.yml&title=Bug Report%3A+">Report a Bug</a> | <a href="https:/sullivanpj/open-system/issues/new?assignees=&labels=enhancement&template=feature-request.yml&title=Feature Request%3A+">Request a Feature</a> | <a href="https:/sullivanpj/open-system/issues/new?assignees=&labels=documentation&template=documentation.yml&title=Documentation Request%3A+">Request Documentation</a> | <a href="https:/sullivanpj/open-system/discussions">Ask a Question</a>
</div>

<br />
The <b>Open System</b> is a monorepo containing modern, scalable web application code, additional utility applications/tools, various libraries, and a fully featured, serverless back-end framework. The Open System is built using <a href="https://nx.dev/" target="_blank">Nx</a>, a set of extensible dev tools for monorepos, which helps you develop like Google, Facebook, and Microsoft. Building on top of Nx, the Open System provides a set of tools and patterns that help you scale your monorepo to many teams while keeping the codebase maintainable.

<h4 align="center">💻 Visit <a href="https://www.patsullivan.org" target="_blank">patsullivan.org</a> to stay up to date with this developer<br /><br /></h4>

[![Version](https://img.shields.io/badge/version-0.0.1-10B981.svg?style=for-the-badge&color=10B981)](https://prettier.io/)&nbsp;
[![Nx](https://img.shields.io/badge/Nx-14.4.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=10B981)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-13.0.5-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=10B981)](https://nextjs.org/)&nbsp;[![codecov.io](https://img.shields.io/codecov/c/github/commitizen/cz-cli.svg?style=for-the-badge&color=10B981)](https://codecov.io/github/commitizen/cz-cli?branch=master)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=10B981)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=10B981)&nbsp;[![documented with docusaurus](https://img.shields.io/badge/documented_with-docusaurus-success.svg?style=for-the-badge&logo=readthedocs&color=10B981)](https://docusaurus.io/)


<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- END header -->

# ⚡ Storm - Zod Validation Plugin

This library was generated with [Nx](https://nx.dev).

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

## Table of Contents

- [⚡ Storm - Zod Validation Plugin](#-storm---zod-validation-plugin)
- [Table of Contents](#table-of-contents)
- [Running unit tests](#running-unit-tests)
- [Roadmap](#roadmap)
- [Support](#support)
- [License](#license)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Contributors](#contributors)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Running unit tests

Run `nx test tools-storm-plugins-zod` to execute the unit tests via [Jest](https://jestjs.io).

<!-- START footer -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->


## Roadmap

See the [open issues](https:/sullivanpj/open-system/issues) for a list of proposed features (and known issues).

- [Top Feature Requests](https:/sullivanpj/open-system/issues?q=label%3Aenhancement+is%3Aopen+sort%3Areactions-%2B1-desc) (Add your votes using the 👍 reaction)
- [Top Bugs](https:/sullivanpj/open-system/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Areactions-%2B1-desc) (Add your votes using the 👍 reaction)
- [Newest Bugs](https:/sullivanpj/open-system/issues?q=is%3Aopen+is%3Aissue+label%3Abug)

## Support

Reach out to the maintainer at one of the following places:

- [Contact](https://www.patsullivan.org/contact)
- [GitHub discussions](https:/sullivanpj/open-system/discussions)
- <[email protected]>

## License

This project is licensed under the **BSD-2-Clause license**. Feel free to edit and distribute this template as you like.

See [LICENSE](LICENSE) for more information.

## Changelog

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Every release, along with the migration instructions, is documented in the [CHANGELOG](CHANGELOG.md) file

## Contributing

First off, thanks for taking the time to contribute! Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are **greatly appreciated**.

Please try to create bug reports that are:

- _Reproducible._ Include steps to reproduce the problem.
- _Specific._ Include as much detail as possible: which version, what environment, etc.
- _Unique._ Do not duplicate existing opened issues.
- _Scoped to a Single Bug._ One bug per report.

Please adhere to this project's [code of conduct](.github/CODE_OF_CONDUCT.md).

You can use [markdownlint-cli](https:/sullivanpj/open-system/markdownlint-cli) to check for common markdown style inconsistency.

## Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->

<table>
<tbody>
<tr>
<td align="center"><a href="http://www.sullypat.com/"><img src="https://avatars.githubusercontent.com/u/99053093?v=4?s=100" width="100px;" alt="Patrick Sullivan"/><br /><sub><b>Patrick Sullivan</b></sub></a><br /><a href="#design-sullivanpj" title="Design">🎨</a> <a href="https:/sullivanpj/open-system/commits?author=sullivanpj" title="Code">💻</a> <a href="#tool-sullivanpj" title="Tools">🔧</a> <a href="https:/sullivanpj/open-system/commits?author=sullivanpj" title="Documentation">📖</a> <a href="https:/sullivanpj/open-system/commits?author=sullivanpj" title="Tests">⚠️</a></td>
<td align="center"><a href="https://tylerbenning.com/"><img src="https://avatars.githubusercontent.com/u/7265547?v=4?s=100" width="100px;" alt="Tyler Benning"/><br /><sub><b>Tyler Benning</b></sub></a><br /><a href="#design-tbenning" title="Design">🎨</a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td align="center" size="13px" colspan="7">
<a href="https://all-contributors.js.org/docs/en/bot/usage">
<img src="https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg" />
Add your contributions</a>
</td>
</tr>
</tfoot>
</table>

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https:/all-contributors/all-contributors) specification. Contributions of any kind welcome!

<br />
<br />
<div align="center">
<img src="https://pub-e71cff0f90204755bc910518d63cacf8.r2.dev/logo-opengraph.png" width="100%"/>
</div>
<div align="center">
<a href="https://www.patsullivan.org" target="_blank">Website</a> | <a href="https://www.patsullivan.org/contact" target="_blank">Contact</a> | <a href="https://linkedin.com/in/patrick-sullivan-865526b0" target="_blank">LinkedIn</a> | <a href="https://medium.com/@pat.joseph.sullivan" target="_blank">Medium</a> | <a href="https:/sullivanpj" target="_blank">GitHub</a> | <a href="https://keybase.io/sullivanp" target="_blank">OpenPGP Key</a>
</div>

<div align="center">
<p><b>Fingerprint:</b> 1BD2 7192 7770 2549 F4C9 F238 E6AD C420 DA5C 4C2D</p>
</div>

<h4 align="center">💻 Visit <a href="https://www.patsullivan.org" target="_blank">patsullivan.org</a> to stay up to date with this developer<br /><br /></h4>


<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- END footer -->
10 changes: 10 additions & 0 deletions tools/storm/plugins/zod/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@open-system/tools-storm-plugins-zod",
"version": "0.0.1",
"dependencies": {
"@prisma/generator-helper": "^5.2.0",
"path": "^0.12.7",
"semver": "^7.5.4",
"ts-morph": "^19.0.0"
}
}
93 changes: 93 additions & 0 deletions tools/storm/plugins/zod/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"name": "tools-storm-plugins-zod",
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "tools/storm/plugins/zod/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/tools/storm/plugins/zod",
"main": "tools/storm/plugins/zod/src/index.ts",
"project": "tools/storm/plugins/zod/package.json",
"tsConfig": "tools/storm/plugins/zod/tsconfig.json",
"platform": "node",
"deleteOutputPath": true,
"bundle": true,
"sourcemap": true,
"minify": false,
"skipTypeCheck": true,
"format": ["esm", "cjs"],
"assets": [
{
"input": "tools/storm/plugins/zod",
"glob": "README.md",
"output": "."
},
{
"input": ".",
"glob": "LICENSE",
"output": "."
}
]
}
},
"pack": {
"executor": "nx:run-commands",
"options": {
"commands": ["pnpm pack dist --pack-destination \"../.build\""],
"cwd": "dist/tools/storm/plugins/zod"
}
},
"publish-dev": {
"executor": "nx:run-commands",
"options": {
"commands": [
"pnpm nx run tools-storm-runtime:build && pnpm publish --tag dev"
],
"cwd": "dist/tools/storm/plugins/zod"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"options": {
"lintFilePatterns": [
"tools/storm/plugins/zod/**/*.ts",
"tools/storm/plugins/zod/generators.json",
"tools/storm/plugins/zod/package.json"
]
},
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "tools/storm/plugins/zod/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"semantic-release": {
"executor": "@theunderscorer/nx-semantic-release:semantic-release",
"options": {
"github": true,
"npm": false,
"changelog": true,
"tagFormat": "tools-storm-plugins-zod-v${VERSION}"
}
}
},
"tags": [],
"implicitDependencies": [
"core-shared-utilities",
"tools-storm-language",
"tools-storm-schema"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
isDataSource,
isEnum
} from "@open-system/tools-storm-language/ast";
import { ConnectorType, DMMF } from "@prisma/generator-helper";
import { promises as fs } from "fs";
import { join } from "path";
import { Project } from "ts-morph";
import { getDefaultOutputFolder } from "@open-system/tools-storm-schema/plugins/plugin-utils";
import { PrismaModel } from "@open-system/tools-storm-schema/plugins/prisma/prisma-builder";
import PrismaSchemaGenerator from "@open-system/tools-storm-schema/plugins/prisma/schema-generator";
import {
AUXILIARY_FIELDS,
PluginOptions,
Expand All @@ -25,14 +24,15 @@ import {
isForeignKeyField,
resolvePath,
saveProject
} from "../../sdk";
} from "@open-system/tools-storm-schema/sdk";
import {
addMissingInputObjectTypes,
resolveAggregateOperationSupport
} from "../../sdk/dmmf-helpers";
import { getDefaultOutputFolder } from "../plugin-utils";
import { PrismaModel } from "../prisma/prisma-builder";
import PrismaSchemaGenerator from "../prisma/schema-generator";
} from "@open-system/tools-storm-schema/sdk/dmmf-helpers";
import { ConnectorType, DMMF } from "@prisma/generator-helper";
import { promises as fs } from "fs";
import { join } from "path";
import { Project } from "ts-morph";
import Transformer from "./transformer";
import removeDir from "./utils/removeDir";
import { makeFieldSchema, makeValidationRefinements } from "./utils/schema-gen";
Expand Down Expand Up @@ -144,7 +144,7 @@ async function generateCommonSchemas(project: Project, output: string) {
join(output, "common", "index.ts"),
`/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
${getFileHeader("Zod Schema")}
${getFileHeader("Zod Validation")}
import { z } from 'zod';
export const DecimalSchema = z.union([z.number(), z.string(), z.object({d: z.number().array(), e: z.number(), s: z.number()})]);
Expand Down Expand Up @@ -263,7 +263,7 @@ async function generateModelSchema(
);

writer.writeLine("/* eslint-disable */");
writer.writeLine(getFileHeader("Zod Schema"));
writer.writeLine(getFileHeader("Zod Validation"));
writer.writeLine(`import { z } from 'zod';`);

// import user-defined enums from Prisma as they might be referenced in the expressions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Model } from "@open-system/tools-storm-language/ast";
import { PluginOptions } from "@open-system/tools-storm-schema/sdk";
import type { DMMF } from "@prisma/generator-helper";
import { PluginOptions } from "../../sdk";
import { generate } from "./generator";

export const name = "Zod";
Expand Down
Loading

0 comments on commit f050deb

Please sign in to comment.