Skip to content

Commit e39fcae

Browse files
committed
init
0 parents  commit e39fcae

25 files changed

+3094
-0
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.github/CONTRIBUTING.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Contributing to Omar Dulaimi projects
2+
3+
A big welcome and thank you for considering contributing to my open source projects! It’s people like you that make it a reality for users in our community.
4+
5+
Reading and following these guidelines will help us make the contribution process easy and effective for everyone involved. It also communicates that you agree to respect the time of the developers managing and developing these open source projects. In return, we will reciprocate that respect by addressing your issue, assessing changes, and helping you finalize your pull requests.
6+
7+
## Quicklinks
8+
9+
* [Getting Started](#getting-started)
10+
* [Issues](#issues)
11+
* [Pull Requests](#pull-requests)
12+
* [Getting Help](#getting-help)
13+
14+
15+
## Getting Started
16+
17+
Contributions are made to this repo via Issues and Pull Requests (PRs). A few general guidelines that cover both:
18+
19+
- Search for existing Issues and PRs before creating your own.
20+
- We work hard to make sure issues are handled in a timely manner but, depending on the impact, it could take a while to investigate the root cause. A friendly ping in the comment thread to the submitter or a contributor can help draw attention if your issue is blocking.
21+
22+
### Issues
23+
24+
Issues should be used to report problems with the library, request a new feature, or to discuss potential changes before a PR is created. When you create a new Issue, a template will be loaded that will guide you through collecting and providing the information we need to investigate.
25+
26+
If you find an Issue that addresses the problem you're having, please add your own reproduction information to the existing issue rather than creating a new one. Adding a [reaction](https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) can also help be indicating to our maintainers that a particular problem is affecting more than just the reporter.
27+
28+
### Pull Requests
29+
30+
PRs to my libraries are always welcome and can be a quick way to get your fix or improvement slated for the next release. In general, PRs should:
31+
32+
- Only fix/add the functionality in question **OR** address wide-spread whitespace/style issues, not both.
33+
- Add unit or integration tests for fixed or changed functionality (if a test suite already exists).
34+
- Address a single concern in the least number of changed lines as possible.
35+
- Be accompanied by a complete Pull Request template (loaded automatically when a PR is created).
36+
37+
For changes that address core functionality or would require breaking changes (e.g. a major release), it's best to open an Issue to discuss your proposal first.
38+
39+
In general, we follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr)
40+
41+
1. Fork the repository to your own Github account
42+
2. Clone the project to your machine
43+
3. Create a branch locally with a succinct but descriptive name
44+
4. Commit changes to the branch
45+
5. Following any formatting and testing guidelines specific to this repo
46+
6. Push changes to your fork
47+
7. Open a PR in our repository and follow the PR template so that we can efficiently review the changes.

.github/ISSUE_TEMPLATE/bug_report.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Bug report
2+
description: Create a bug report to help us improve Prisma Zod Generator
3+
labels: 'kind/bug'
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
Thanks for helping us improve Prisma Zod Generator!
9+
- type: textarea
10+
attributes:
11+
label: Bug description
12+
description: A clear and concise description of what the bug is.
13+
validations:
14+
required: true
15+
- type: textarea
16+
attributes:
17+
label: How to reproduce
18+
description: Steps to reproduce the behavior
19+
value: |
20+
<!--
21+
1. Go to '...'
22+
2. Change '....'
23+
3. Run '....'
24+
4. See error
25+
-->
26+
validations:
27+
required: true
28+
- type: textarea
29+
attributes:
30+
label: Expected behavior
31+
description: A clear and concise description of what you expected to happen.
32+
- type: textarea
33+
attributes:
34+
label: Prisma information
35+
description: Your Prisma schema, Prisma Client queries, ...
36+
value: |
37+
<!-- Do not include your database credentials when sharing your Prisma schema! -->
38+
validations:
39+
required: true
40+
- type: textarea
41+
attributes:
42+
label: Environment & setup
43+
description: In which environment does the problem occur
44+
value: |
45+
- OS: <!--[e.g. Mac OS, Windows, Debian, CentOS, ...]-->
46+
- Database: <!--[PostgreSQL, MySQL, MariaDB or SQLite]-->
47+
- Node.js version: <!--[Run `node -v` to see your Node.js version]-->
48+
validations:
49+
required: true
50+
- type: textarea
51+
attributes:
52+
label: Prisma Version
53+
description: Run `prisma -v` to see your Prisma version and paste it between the ´´´
54+
value: |
55+
```
56+
57+
```
58+
validations:
59+
required: true

.github/ISSUE_TEMPLATE/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: true
2+
contact_links:
3+
- name: Ask a question
4+
url: https://github.com/omar-dulaimi/prisma-zod-generator/discussions/new
5+
about: Ask questions and discuss with others
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
---
8+
9+
## Problem
10+
11+
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
12+
13+
## Suggested solution
14+
15+
<!-- A clear and concise description of what you want to happen. -->
16+
17+
## Alternatives
18+
19+
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
20+
21+
## Additional context
22+
23+
<!-- Add any other context or screenshots about the feature request here. -->

.github/PULL_REQUEST_TEMPLATE.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Please see the [contributing guidelines](https://github.com/omar-dulaimi/prisma-zod-generator/blob/master/CONTRIBUTING.md) for how to create and submit a high-quality PR for this repo.
2+
3+
### Description
4+
5+
> Describe the purpose of this PR along with any background information and the impacts of the proposed change. For the benefit of the community, please do not assume prior context.
6+
>
7+
> Provide details that support your chosen implementation, including: breaking changes, alternatives considered, changes to the API, etc.
8+
>
9+
> If the UI is being changed, please provide screenshots.
10+
11+
12+
### References
13+
14+
> Include any links supporting this change such as a:
15+
>
16+
> - GitHub Issue/PR number addressed or fixed
17+
> - StackOverflow post
18+
> - Related pull requests/issues from other repos
19+
>
20+
> If there are no references, simply delete this section.

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
lib
3+
package
4+
npm-debug.log*
5+
prisma/generated

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib/**/*
2+
package/**/*

.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 2,
4+
"printWidth": 80,
5+
"bracketSpacing": true,
6+
"semi": true,
7+
"singleQuote": true,
8+
"useTabs": false
9+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 omar-dulaimi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Prisma Zod Generator
2+
3+
[![npm version](https://badge.fury.io/js/prisma-zod-generator.svg)](https://badge.fury.io/js/prisma-zod-generator)
4+
[![npm](https://img.shields.io/npm/dt/prisma-zod-generator.svg)](https://www.npmjs.com/package/prisma-zod-generator)
5+
[![HitCount](https://hits.dwyl.com/omar-dulaimi/prisma-zod-generator.svg?style=flat)](http://hits.dwyl.com/omar-dulaimi/prisma-zod-generator)
6+
[![npm](https://img.shields.io/npm/l/prisma-zod-generator.svg)](LICENSE)
7+
8+
Automatically generate [Zod](https://github.com/colinhacks/zod) schemas from your [Prisma](https://github.com/prisma/prisma) Schema, and use them to validate your API endpoints or any other use you have. Updates every time `npx prisma generate` runs.
9+
10+
## Table of Contents
11+
12+
- [Installation](#installing)
13+
- [Usage](#usage)
14+
- [Additional Options](#additional-options)
15+
16+
## Installation
17+
18+
Using npm:
19+
20+
```bash
21+
npm install prisma-zod-generator
22+
```
23+
24+
Using yarn:
25+
26+
```bash
27+
yarn add prisma-zod-generator
28+
```
29+
30+
# Usage
31+
32+
1- Star this repo 😉
33+
34+
2- Add the generator to your Prisma schema
35+
36+
```prisma
37+
generator zod {
38+
provider = "prisma-zod-generator"
39+
}
40+
```
41+
42+
3- Running `npx prisma generate` for the following schema.prisma
43+
44+
```prisma
45+
model User {
46+
id Int @id @default(autoincrement())
47+
email String @unique
48+
name String?
49+
posts Post[]
50+
}
51+
52+
model Post {
53+
id Int @id @default(autoincrement())
54+
createdAt DateTime @default(now())
55+
updatedAt DateTime @updatedAt
56+
title String
57+
content String?
58+
published Boolean @default(false)
59+
viewCount Int @default(0)
60+
author User? @relation(fields: [authorId], references: [id])
61+
authorId Int?
62+
}
63+
```
64+
65+
will generate the following files
66+
67+
![Zod Schemas](https://raw.githubusercontent.com/omar-dulaimi/prisma-zod-generator/master/zodSchemas.png)
68+
69+
4- Use generated schemas somewhere in your API logic, like middleware or decorator
70+
71+
```ts
72+
import { PostCreateOneSchema } from './prisma/generated/schemas/createOnePost.schema';
73+
74+
app.post('/blog', async (req, res, next) => {
75+
const { body } = req;
76+
await PostCreateOneSchema.parse(body);
77+
});
78+
```
79+
80+
## Additional Options
81+
82+
| Option |  Description | Type |  Default |
83+
| -------- | ---------------------------------------------- | -------- | ------------- |
84+
| `output` | Output directory for the generated zod schemas | `string` | `./generated` |
85+
86+
Use additional options in the `schema.prisma`
87+
88+
```prisma
89+
generator zod {
90+
provider = "prisma-zod-generator"
91+
output = "./generated-zod-schemas"
92+
}
93+
```

0 commit comments

Comments
 (0)