{"_id":"@alex-lehloenya/zod-prisma","name":"@alex-lehloenya/zod-prisma","dist-tags":{"latest":"0.5.4"},"versions":{"0.5.4":{"name":"@alex-lehloenya/zod-prisma","version":"0.5.4","description":"A Prisma generator that creates Zod schemas for all of your models","license":"MIT","author":{"name":"Carter Grimmeisen"},"homepage":"https://github.com/CarterGrimmeisen/zod-prisma#readme","repository":{"type":"git","url":"git+https://github.com/CarterGrimmeisen/zod-prisma.git"},"bugs":{"url":"https://github.com/CarterGrimmeisen/zod-prisma/issues"},"main":"dist/index.js","module":"dist/zod-prisma.esm.js","typings":"dist/index.d.ts","bin":{"zod-prisma":"bin/cli.js"},"keywords":["zod","prisma","generator"],"prettier":{"printWidth":100,"semi":false,"singleQuote":true,"tabWidth":4,"trailingComma":"es5","useTabs":true},"eslintConfig":{"rules":{"react-hooks/rules-of-hooks":"off"}},"jest":{"testEnvironment":"node"},"dependencies":{"@prisma/generator-helper":"~3.8.1","parenthesis":"^3.1.8","ts-morph":"^13.0.2"},"devDependencies":{"@prisma/client":"~3.8.1","@prisma/sdk":"~3.7.0","@tsconfig/recommended":"^1.0.1","@types/fs-extra":"^9.0.13","@types/jest":"^29.5.11","dts-cli":"^1.1.5","execa":"^5.1.0","fast-glob":"^3.2.5","fs-extra":"^10.0.0","husky":"^7.0.4","jest-mock-extended":"^2.0.4","prisma":"^3.4.2","tslib":"^2.3.1","typescript":"^4.5.4","zod":"^3.11.6"},"peerDependencies":{"decimal.js":"^10.0.0","prisma":"^3.0.0","zod":"^3.0.0"},"peerDependenciesMeta":{"decimal.js":{"optional":true}},"engines":{"node":">=14"},"scripts":{"build":"dts build --target node --format cjs --rollupTypes","lint":"tsc --noEmit && dts lint src --ignore-pattern src/test/functional","prepublish":"dts build --target node --format cjs --rollupTypes","start":"dts watch","test":"dts test --maxWorkers=4 --verbose"},"_id":"@alex-lehloenya/zod-prisma@0.5.4","_integrity":"sha512-Yc//t0WnK11w8ulnzoq/qknBI9gw6tCyXDvRP8Os3/5U2XFeusOJHv1T7HUYnsAAWWEBYXZX3e2eXDoPnxXi5A==","_resolved":"C:\\Users\\ALEXLE~1\\AppData\\Local\\Temp\\3a924b3f5ae93bf5c466c2178973ffae\\alex-lehloenya-zod-prisma-0.5.4.tgz","_from":"file:alex-lehloenya-zod-prisma-0.5.4.tgz","_nodeVersion":"21.1.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-Yc//t0WnK11w8ulnzoq/qknBI9gw6tCyXDvRP8Os3/5U2XFeusOJHv1T7HUYnsAAWWEBYXZX3e2eXDoPnxXi5A==","shasum":"3c29b3f71d1f302309aad60369cda78373a0ab89","tarball":"https://registry.npmjs.org/@alex-lehloenya/zod-prisma/-/zod-prisma-0.5.4.tgz","fileCount":10,"unpackedSize":89907,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH/uoLETXl/MfTbxynBtF4I3YRww/dR/emHK6jH7Rn2PAiEAl5F8LRLwqr4zW1fMR4Kwky0FzSQYZTBoq2wg0fKFF6Y="}]},"_npmUser":{"name":"alex-lehloenya","email":"letlotlolehloenya@gmail.com"},"directories":{},"maintainers":[{"name":"alex-lehloenya","email":"letlotlolehloenya@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/zod-prisma_0.5.4_1706010572208_0.2338831947349167"},"_hasShrinkwrap":false}},"time":{"created":"2024-01-23T11:49:32.084Z","0.5.4":"2024-01-23T11:49:32.348Z","modified":"2024-01-23T11:49:32.616Z"},"maintainers":[{"name":"alex-lehloenya","email":"letlotlolehloenya@gmail.com"}],"description":"A Prisma generator that creates Zod schemas for all of your models","homepage":"https://github.com/CarterGrimmeisen/zod-prisma#readme","keywords":["zod","prisma","generator"],"repository":{"type":"git","url":"git+https://github.com/CarterGrimmeisen/zod-prisma.git"},"author":{"name":"Carter Grimmeisen"},"bugs":{"url":"https://github.com/CarterGrimmeisen/zod-prisma/issues"},"license":"MIT","readme":"<!--\r\n*** Thanks for checking out the Best-README-Template. If you have a suggestion\r\n*** that would make this better, please fork the repo and create a pull request\r\n*** or simply open an issue with the tag \"enhancement\".\r\n*** Thanks again! Now go create something AMAZING! :D\r\n***\r\n***\r\n***\r\n*** To avoid retyping too much info. Do a search and replace for the following:\r\n*** CarterGrimmeisen, zod-prisma, twitter_handle, Carter.Grimmeisen@uah.edu, Zod Prisma, A custom prisma generator that creates Zod schemas from your Prisma model.\r\n-->\r\n\r\n<!-- PROJECT SHIELDS -->\r\n<!--\r\n*** I'm using markdown \"reference style\" links for readability.\r\n*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).\r\n*** See the bottom of this document for the declaration of the reference variables\r\n*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.\r\n*** https://www.markdownguide.org/basic-syntax/#reference-style-links\r\n-->\r\n\r\n[![NPM][npm-shield]][npm-url]\r\n[![Contributors][contributors-shield]][contributors-url]\r\n[![Forks][forks-shield]][forks-url]\r\n[![Stargazers][stars-shield]][stars-url]\r\n[![Issues][issues-shield]][issues-url]\r\n[![MIT License][license-shield]][license-url]\r\n\r\n<!-- PROJECT LOGO -->\r\n<br />\r\n<p align=\"center\">\r\n  <a href=\"https://github.com/CarterGrimmeisen/zod-prisma\">\r\n    <img src=\"https://raw.githubusercontent.com/CarterGrimmeisen/zod-prisma/main/images/zod-prisma.svg\" alt=\"Logo\" width=\"120\" height=\"120\">\r\n  </a>\r\n  <h3 align=\"center\">Zod Prisma</h3>\r\n  <p align=\"center\">\r\n    A custom prisma generator that creates Zod schemas from your Prisma model.\r\n    <br />\r\n    <a href=\"https://github.com/CarterGrimmeisen/zod-prisma\"><strong>Explore the docs »</strong></a>\r\n    <br />\r\n    <br />\r\n    <a href=\"https://github.com/CarterGrimmeisen/zod-prisma/blob/main/src/test/functional\">View Demo</a>\r\n    ·\r\n    <a href=\"https://github.com/CarterGrimmeisen/zod-prisma/issues\">Report Bug</a>\r\n    ·\r\n    <a href=\"https://github.com/CarterGrimmeisen/zod-prisma/issues\">Request Feature</a>\r\n  </p>\r\n</p>\r\n\r\n<!-- TABLE OF CONTENTS -->\r\n<details open=\"open\">\r\n  <summary><h2 style=\"display: inline-block\">Table of Contents</h2></summary>\r\n  <ol>\r\n    <li>\r\n      <a href=\"#about-the-project\">About The Project</a>\r\n      <ul>\r\n        <li><a href=\"#built-with\">Built With</a></li>\r\n      </ul>\r\n    </li>\r\n    <li>\r\n      <a href=\"#getting-started\">Getting Started</a>\r\n      <ul>\r\n        <li><a href=\"#prerequisites\">Prerequisites</a></li>\r\n        <li><a href=\"#installation\">Installation</a></li>\r\n      </ul>\r\n    </li>\r\n    <li><a href=\"#usage\">Usage</a>\r\n      <ul>\r\n      <li><a href=\"#jsdoc-generation\">JSDoc Generation</a></li>\r\n      <li><a href=\"#extending-zod-fields\">Extending Zod Fields</a></li>\r\n      <li>\r\n        <a href=\"#importing-helpers\">Importing Helpers</a>\r\n        <ul>\r\n        <li><a href=\"#custom-zod-schema\">Custom Zod Schemas</a></li>\r\n        </ul>\r\n      </li>\r\n      <li><a href=\"#json-fields\">JSON Fields</a></li>\r\n      </ul>\r\n    </li>\r\n    <li><a href=\"#examples\">Examples</a></li>\r\n    <li><a href=\"#roadmap\">Roadmap</a></li>\r\n    <li><a href=\"#contributing\">Contributing</a></li>\r\n    <li><a href=\"#license\">License</a></li>\r\n    <li><a href=\"#contact\">Contact</a></li>\r\n  </ol>\r\n</details>\r\n\r\n<!-- ABOUT THE PROJECT -->\r\n\r\n## About The Project\r\n\r\nI got tired of having to manually create Zod schemas for my Prisma models and of updating them everytime I made schema changes.\r\nThis provides a way of automatically generating them with your prisma\r\n\r\n<!-- [![Product Name Screen Shot][product-screenshot]](https://example.com) -->\r\n\r\n### Built With\r\n\r\n-   [dts-cli](https://github.com/weiran-zsd/dts-cli)\r\n-   [Zod](https://github.com/colinhacks/zod)\r\n-   [Based on this gist](https://gist.github.com/deckchairlabs/8a11c33311c01273deec7e739417dbc9)\r\n\r\n<!-- GETTING STARTED -->\r\n\r\n## Getting Started\r\n\r\nTo get a local copy up and running follow these simple steps.\r\n\r\n### Prerequisites\r\n\r\nThis project utilizes yarn and if you plan on contributing, you should too.\r\n\r\n```sh\r\nnpm install -g yarn\r\n```\r\n\r\n### Installation\r\n\r\n0.  **Ensure your tsconfig.json enables the compiler's strict mode.**\r\n    **Zod requires it and so do we, you will experience TS errors without strict mode enabled**\r\n\r\n1.  Add zod-prisma as a dev dependency\r\n\r\n    ```sh\r\n    yarn add -D zod-prisma\r\n    ```\r\n\r\n2.  Add the zod-prisma generator to your schema.prisma\r\n\r\n    ```prisma\r\n    generator zod {\r\n      provider                 = \"zod-prisma\"\r\n      output                   = \"./zod\" // (default) the directory where generated zod schemas will be saved\r\n\r\n      relationModel            = true // (default) Create and export both plain and related models.\r\n      // relationModel         = \"default\" // Do not export model without relations.\r\n      // relationModel         = false // Do not generate related model\r\n\r\n      modelCase                = \"PascalCase\" // (default) Output models using pascal case (ex. UserModel, PostModel)\r\n      // modelCase             = \"camelCase\" // Output models using camel case (ex. userModel, postModel)\r\n\r\n      modelSuffix              = \"Model\" // (default) Suffix to apply to your prisma models when naming Zod schemas\r\n\r\n      // useDecimalJs          = false // (default) represent the prisma Decimal type using as a JS number\r\n      useDecimalJs             = true // represent the prisma Decimal type using Decimal.js (as Prisma does)\r\n\r\n      imports                  = null // (default) will import the referenced file in generated schemas to be used via imports.someExportedVariable\r\n\r\n      // https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields#filtering-by-null-values\r\n      prismaJsonNullability    = true // (default) uses prisma's scheme for JSON field nullability\r\n      // prismaJsonNullability = false // allows null assignment to optional JSON fields\r\n    }\r\n    ```\r\n\r\n3.  Run `npx prisma generate` or `yarn prisma generate` to generate your zod schemas\r\n4.  Import the generated schemas form your selected output location\r\n\r\n<!-- USAGE EXAMPLES -->\r\n\r\n## Usage\r\n\r\n### JSDoc Generation\r\n\r\n[Rich-comments](https://www.prisma.io/docs/concepts/components/prisma-schema#comments)\r\nin the Prisma schema will be transformed into JSDoc for the associated fields:\r\n\r\n> _Note: make sure to use a triple-slash. Double-slash comments won't be processed._\r\n\r\n```prisma\r\nmodel Post {\r\n  /// The unique identifier for the post\r\n  /// @default {Generated by database}\r\n  id String @id @default(uuid())\r\n\r\n  /// A brief title that describes the contents of the post\r\n  title String\r\n\r\n  /// The actual contents of the post.\r\n  contents String\r\n}\r\n```\r\n\r\nGenerated code:\r\n\r\n```ts\r\nexport const PostModel = z.object({\r\n\t/**\r\n\t * The unique identifier for the post\r\n\t * @default {Generated by database}\r\n\t */\r\n\tid: z.string().uuid(),\r\n\t/**\r\n\t * A brief title that describes the contents of the post\r\n\t */\r\n\ttitle: z.string(),\r\n\t/**\r\n\t * The actual contents of the post.\r\n\t */\r\n\tcontents: z.string(),\r\n})\r\n```\r\n\r\n### Extending Zod Fields\r\n\r\nYou can also use the `@zod` keyword in rich-comments in the Prisma schema\r\nto extend your Zod schema fields:\r\n\r\n```prisma\r\nmodel Post {\r\n  id String @id @default(uuid()) /// @zod.uuid()\r\n\r\n  /// @zod.max(255, { message: \"The title must be shorter than 256 characters\" })\r\n  title String\r\n\r\n  contents String /// @zod.max(10240)\r\n}\r\n```\r\n\r\nGenerated code:\r\n\r\n```ts\r\nexport const PostModel = z.object({\r\n\tid: z.string().uuid(),\r\n\ttitle: z.string().max(255, { message: 'The title must be shorter than 256 characters' }),\r\n\tcontents: z.string().max(10240),\r\n})\r\n```\r\n\r\n### Importing Helpers\r\n\r\nSometimes its useful to define a custom Zod preprocessor or transformer for your data.\r\nzod-prisma enables you to reuse these by importing them via a config options. For example:\r\n\r\n```prisma\r\ngenerator zod {\r\n  provider      = \"zod-prisma\"\r\n  output        = \"./zod\"\r\n  imports \t\t  = \"../src/zod-schemas\"\r\n}\r\n\r\nmodel User {\r\n  username\tString /// @zod.refine(imports.isValidUsername)\r\n}\r\n```\r\n\r\nThe referenced file can then be used by simply referring to exported members via `imports.whateverExport`.\r\nThe generated zod schema files will now include a namespaced import like the following.\r\n\r\n```typescript\r\nimport * as imports from '../../src/zod-schemas'\r\n```\r\n\r\n#### Custom Zod Schema\r\n\r\nIn conjunction with this import option, you may want to utilize an entirely custom zod schema for a field.\r\nThis can be accomplished by using the special comment directive `@zod.custom()`.\r\nBy specifying the custom schema within the parentheses you can replace the autogenerated type that would normally be assigned to the field.\r\n\r\n> For instance if you wanted to use `z.preprocess`\r\n\r\n### JSON Fields\r\n\r\nJSON fields in Prisma disallow null values. This is to disambiguate between setting a field's value to NULL in the database and having\r\na value of null stored in the JSON. In accordance with this zod-prisma will default to disallowing null values, even if your JSON field is optional.\r\n\r\nIf you would like to revert this behavior and allow null assignment to JSON fields,\r\nyou can set `prismaJsonNullability` to `false` in the generator options.\r\n\r\n## Examples\r\n\r\n<!-- Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources. -->\r\n\r\n_For examples, please refer to the [Examples Directory](https://github.com/CarterGrimmeisen/zod-prisma/blob/main/examples) or the [Functional Tests](https://github.com/CarterGrimmeisen/zod-prisma/blob/main/src/test/functional)_\r\n\r\n<!-- ROADMAP -->\r\n\r\n## Roadmap\r\n\r\nSee the [open issues](https://github.com/CarterGrimmeisen/zod-prisma/issues) for a list of proposed features (and known issues).\r\n\r\n<!-- CONTRIBUTING -->\r\n\r\n## Contributing\r\n\r\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.\r\n\r\n1. Fork the Project\r\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\r\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\r\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\r\n5. Open a Pull Request\r\n\r\n<!-- LICENSE -->\r\n\r\n## License\r\n\r\nDistributed under the MIT License. See `LICENSE` for more information.\r\n\r\n<!-- CONTACT -->\r\n\r\n## Contact\r\n\r\nCarter Grimmeisen - Carter.Grimmeisen@uah.edu\r\n\r\nProject Link: [https://github.com/CarterGrimmeisen/zod-prisma](https://github.com/CarterGrimmeisen/zod-prisma)\r\n\r\n<!-- MARKDOWN LINKS & IMAGES -->\r\n<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->\r\n\r\n[npm-shield]: https://img.shields.io/npm/v/zod-prisma?style=for-the-badge\r\n[npm-url]: https://www.npmjs.com/package/zod-prisma\r\n[contributors-shield]: https://img.shields.io/github/contributors/CarterGrimmeisen/zod-prisma.svg?style=for-the-badge\r\n[contributors-url]: https://github.com/CarterGrimmeisen/zod-prisma/graphs/contributors\r\n[forks-shield]: https://img.shields.io/github/forks/CarterGrimmeisen/zod-prisma.svg?style=for-the-badge\r\n[forks-url]: https://github.com/CarterGrimmeisen/zod-prisma/network/members\r\n[stars-shield]: https://img.shields.io/github/stars/CarterGrimmeisen/zod-prisma.svg?style=for-the-badge\r\n[stars-url]: https://github.com/CarterGrimmeisen/zod-prisma/stargazers\r\n[issues-shield]: https://img.shields.io/github/issues/CarterGrimmeisen/zod-prisma.svg?style=for-the-badge\r\n[issues-url]: https://github.com/CarterGrimmeisen/zod-prisma/issues\r\n[license-shield]: https://img.shields.io/github/license/CarterGrimmeisen/zod-prisma.svg?style=for-the-badge\r\n[license-url]: https://github.com/CarterGrimmeisen/zod-prisma/blob/main/LICENSE\r\n","readmeFilename":"README.md"}