@ghentcdh/crouton-prisma 0.0.1-alpha.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -0
- package/dist/generator.js +34591 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @ghentcdh/crouton-prisma
|
|
2
|
+
|
|
3
|
+
Prisma generator that produces Zod validation schemas from your Prisma models. Used as part of
|
|
4
|
+
the [Crouton](https://github.com/ghentcdh/crouton) framework.
|
|
5
|
+
|
|
6
|
+
## What it does
|
|
7
|
+
|
|
8
|
+
Runs as a Prisma generator and:
|
|
9
|
+
|
|
10
|
+
1. Normalizes relation field names in your schema (`normalize-schema.json` rules)
|
|
11
|
+
2. Invokes [`zod-prisma-types`](https://github.com/chrishoermann/zod-prisma-types) on a temporary schema to generate Zod
|
|
12
|
+
types
|
|
13
|
+
3. Fixes missing Zod imports in the generated output
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
pnpm add -D @ghentcdh/crouton-prisma prisma zod-prisma-types
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Prisma schema
|
|
24
|
+
|
|
25
|
+
Add the `crouton` generator block to `prisma/default/schema.prisma`:
|
|
26
|
+
|
|
27
|
+
```prisma
|
|
28
|
+
generator client {
|
|
29
|
+
provider = "prisma-client-js"
|
|
30
|
+
output = "../../generated/default/client/src"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
generator crouton {
|
|
34
|
+
provider = "crouton-prisma"
|
|
35
|
+
zodOutput = "../../generated/default/types/src"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Option | Required | Description |
|
|
41
|
+
|-------------|----------|--------------------------------------------------|
|
|
42
|
+
| `provider` | yes | Must be `"crouton-prisma"` |
|
|
43
|
+
| `zodOutput` | yes | Path (relative to the schema file) for Zod types |
|
|
44
|
+
|
|
45
|
+
### Prisma config
|
|
46
|
+
|
|
47
|
+
Create `prisma/default/prisma.config.ts`:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import 'dotenv/config';
|
|
51
|
+
import { defineConfig, env } from 'prisma/config';
|
|
52
|
+
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
schema: 'prisma/default/schema.prisma',
|
|
55
|
+
migrations: {
|
|
56
|
+
path: 'prisma/default/migrations',
|
|
57
|
+
},
|
|
58
|
+
datasource: {
|
|
59
|
+
url: env('DATABASE_URL'),
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Generate
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
prisma generate --schema prisma/default/schema.prisma
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Or via the Crouton CLI when using the full Crouton setup.
|
|
71
|
+
|
|
72
|
+
## Peer dependencies
|
|
73
|
+
|
|
74
|
+
| Package | Version |
|
|
75
|
+
|--------------------|-----------|
|
|
76
|
+
| `prisma` | `>=6.0.0` |
|
|
77
|
+
| `zod-prisma-types` | `>=3.0.0` |
|