hekireki 0.21.0 → 0.22.1
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 +161 -278
- package/dist/bin/activerecord.js +1 -1
- package/dist/bin/ajv.js +1 -1
- package/dist/bin/arktype.js +1 -1
- package/dist/bin/atlas.js +1 -1
- package/dist/bin/django.js +1 -1
- package/dist/bin/drizzle.js +1 -1
- package/dist/bin/ecto.js +1 -1
- package/dist/bin/efcore.d.ts +1 -0
- package/dist/bin/efcore.js +6 -0
- package/dist/bin/effect.js +1 -1
- package/dist/bin/eloquent.js +1 -1
- package/dist/bin/er.js +1 -1
- package/dist/bin/gorm.js +1 -1
- package/dist/bin/hekireki.js +1 -1
- package/dist/bin/kysely.js +1 -1
- package/dist/bin/pydantic.js +1 -1
- package/dist/bin/sea-orm.js +1 -1
- package/dist/bin/sqlalchemy.js +1 -1
- package/dist/bin/typebox.js +1 -1
- package/dist/bin/valibot.js +1 -1
- package/dist/bin/zod.js +1 -1
- package/dist/{bin-Ca0TR-Zh.js → bin-DxYpJikH.js} +1409 -10
- package/dist/studio/assets/{chip-CLdO-gL5.js → chip-B9UolvIl.js} +1 -1
- package/dist/studio/assets/{copy-CcAufM8p.js → copy-DiFFafx_.js} +1 -1
- package/dist/studio/assets/{debounce-T36H3Pq5.js → debounce-WjLaYdFF.js} +1 -1
- package/dist/studio/assets/{docs-DW8-viIy.js → docs-D2Vpbqbg.js} +1 -1
- package/dist/studio/assets/{enums._name-C2s5pbQ3.js → enums._name-t90NJ6-H.js} +1 -1
- package/dist/studio/assets/hooks-UJuF1mqe.js +1 -0
- package/dist/studio/assets/{index-BP1uJf2T.js → index-C29_CUjj.js} +3 -3
- package/dist/studio/assets/{labels-BXtM_faz.js → labels-D0IhxSmD.js} +1 -1
- package/dist/studio/assets/{lazyRouteComponent-C6zg30cR.js → lazyRouteComponent-G8mNaW9J.js} +1 -1
- package/dist/studio/assets/{lu-BKd2Ee9U.js → lu-DvK-u3Mx.js} +1 -1
- package/dist/studio/assets/{models._name-BgQ9M7k3.js → models._name-DUEsQrdC.js} +1 -1
- package/dist/studio/assets/{not-found-OmQoujxN.js → not-found-Dr2QuAjv.js} +1 -1
- package/dist/studio/assets/{prisma-BbI26USq.js → prisma-Co828tLd.js} +1 -1
- package/dist/studio/assets/routes-BIbzUF01.js +1 -0
- package/dist/studio/assets/{schema-gate-Dq_XVfAD.js → schema-gate-Bad9LKCZ.js} +1 -1
- package/dist/studio/assets/{schema-view-BuWOw5GX.js → schema-view-nCetSUyn.js} +1 -1
- package/dist/studio/assets/{sql--CSU_IR2.js → sql-Db9voX3l.js} +1 -1
- package/dist/studio/assets/{table-Dfy6EciQ.js → table-BfaXyuqp.js} +1 -1
- package/dist/studio/assets/{tabs-Ce14hvOa.js → tabs-BXvBDUhR.js} +1 -1
- package/dist/studio/assets/{useFormValidation-gdk4CRGT.js → useFormValidation-D6Nfw1Ec.js} +1 -1
- package/dist/studio/assets/{useMatch-CdyJXF1Q.js → useMatch-BZSBUGcY.js} +1 -1
- package/dist/studio/assets/{useMultipleSelectionState-a9-PqoPk.js → useMultipleSelectionState-Bz2aFLv7.js} +1 -1
- package/dist/studio/assets/{useOverlayTriggerState-DCPjC07T.js → useOverlayTriggerState-C-S92dgf.js} +1 -1
- package/dist/studio/index.html +8 -8
- package/package.json +7 -3
- package/dist/studio/assets/hooks-Ctp_pGlY.js +0 -1
- package/dist/studio/assets/routes-Bp4Bkwc2.js +0 -1
package/README.md
CHANGED
|
@@ -3,16 +3,8 @@
|
|
|
3
3
|
# Hekireki
|
|
4
4
|
|
|
5
5
|
**[Hekireki](https://www.npmjs.com/package/hekireki)** generates validation schemas, ORM models and
|
|
6
|
-
ER diagrams from a [Prisma](https://www.prisma.io/) schema
|
|
7
|
-
|
|
8
|
-
[Hekireki Studio](#studio).
|
|
9
|
-
|
|
10
|
-
## Features
|
|
11
|
-
|
|
12
|
-
- **Validation schemas** — [Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), [Effect Schema](https://effect.website/docs/schema/introduction/), [TypeBox](https://github.com/sinclairzx81/typebox), [AJV](https://ajv.js.org/) (JSON Schema) and [Pydantic](https://docs.pydantic.dev/) v2, written from the `///` [annotations](#annotations) on each field
|
|
13
|
-
- **ORM models and DDL** — [Drizzle](https://orm.drizzle.team/), [Kysely](https://kysely.dev/), [SQLAlchemy](https://www.sqlalchemy.org/), [Django](https://www.djangoproject.com/), [GORM](https://gorm.io/), [Sea-ORM](https://www.sea-ql.org/SeaORM/), [Ecto](https://hexdocs.pm/ecto/Ecto.Schema.html), [Active Record](https://guides.rubyonrails.org/active_record_basics.html), [Eloquent](https://laravel.com/docs/eloquent) and [Atlas](https://atlasgo.io/) HCL — with relations, enums, composite keys, indexes and `@@map` / `@map` throughout
|
|
14
|
-
- **ER diagrams** — [Mermaid](https://mermaid.js.org/), [DBML](https://dbml.dbdiagram.io/), PNG and SVG from one generator block, with crow's-foot cardinality and `PK` / `FK` / `UK` markers
|
|
15
|
-
- **[Hekireki Studio](#studio)** — the ER diagram, a reference docs page, every model's data, a Prisma editor and a SQL console, live from `schema.prisma`
|
|
6
|
+
ER diagrams from a [Prisma](https://www.prisma.io/) schema, and opens the schema and its data in the
|
|
7
|
+
browser with Hekireki Studio.
|
|
16
8
|
|
|
17
9
|
## Installation
|
|
18
10
|
|
|
@@ -22,22 +14,22 @@ npm install -D hekireki
|
|
|
22
14
|
|
|
23
15
|
## Usage
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
directory to get the default file name of that generator, or at a path with an extension to name
|
|
27
|
-
the file yourself. `hekireki-er` is the exception: it has no default file name, so it only takes
|
|
28
|
-
paths to files, extension included (see [ER diagrams](#er-diagrams)).
|
|
17
|
+
Add a generator to `schema.prisma` and run `npx prisma generate`. `output` is required.
|
|
29
18
|
|
|
30
19
|
```prisma
|
|
31
20
|
datasource db {
|
|
32
|
-
provider = "
|
|
21
|
+
provider = "postgresql"
|
|
33
22
|
}
|
|
34
23
|
|
|
35
24
|
generator Hekireki-Zod {
|
|
36
25
|
provider = "hekireki-zod"
|
|
37
26
|
output = "./zod"
|
|
38
27
|
type = true
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
generator Hekireki-Drizzle {
|
|
31
|
+
provider = "hekireki-drizzle"
|
|
32
|
+
output = "./drizzle"
|
|
41
33
|
}
|
|
42
34
|
|
|
43
35
|
model User {
|
|
@@ -57,135 +49,57 @@ model Post {
|
|
|
57
49
|
/// Article title
|
|
58
50
|
/// @z.string().min(1).max(100)
|
|
59
51
|
title String
|
|
60
|
-
/// Foreign key referencing User.id
|
|
61
|
-
/// @z.uuid()
|
|
62
52
|
userId String
|
|
63
53
|
user User @relation(fields: [userId], references: [id])
|
|
64
54
|
}
|
|
65
55
|
```
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import * as z from 'zod'
|
|
71
|
-
|
|
72
|
-
export const UserSchema = z.object({
|
|
73
|
-
/**
|
|
74
|
-
* Primary key
|
|
75
|
-
*/
|
|
76
|
-
id: z.uuid(),
|
|
77
|
-
/**
|
|
78
|
-
* Display name
|
|
79
|
-
*/
|
|
80
|
-
name: z.string().min(1).max(50),
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
export type User = z.infer<typeof UserSchema>
|
|
84
|
-
|
|
85
|
-
export const PostSchema = z.object({
|
|
86
|
-
/**
|
|
87
|
-
* Primary key
|
|
88
|
-
*/
|
|
89
|
-
id: z.uuid(),
|
|
90
|
-
/**
|
|
91
|
-
* Article title
|
|
92
|
-
*/
|
|
93
|
-
title: z.string().min(1).max(100),
|
|
94
|
-
/**
|
|
95
|
-
* Foreign key referencing User.id
|
|
96
|
-
*/
|
|
97
|
-
userId: z.uuid(),
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
export type Post = z.infer<typeof PostSchema>
|
|
101
|
-
|
|
102
|
-
export const UserRelationsSchema = z.object({
|
|
103
|
-
...UserSchema.shape,
|
|
104
|
-
posts: z.array(PostSchema),
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
export type UserRelations = z.infer<typeof UserRelationsSchema>
|
|
108
|
-
|
|
109
|
-
export const PostRelationsSchema = z.object({
|
|
110
|
-
...PostSchema.shape,
|
|
111
|
-
user: UserSchema,
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
export type PostRelations = z.infer<typeof PostRelationsSchema>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Every other generator reads the same schema. What each one writes is easiest to read as real
|
|
118
|
-
output: [`example/schema.prisma`](https://github.com/nakita628/hekireki/blob/main/example/schema.prisma)
|
|
119
|
-
exercises all of them at once — enums, `@@map`, composite keys, self-relations, implicit
|
|
120
|
-
many-to-many, native `@db.*` types — and the output of every generator for it is committed under
|
|
121
|
-
[`example/generated/`](https://github.com/nakita628/hekireki/tree/main/example/generated).
|
|
57
|
+
## Generators
|
|
122
58
|
|
|
123
|
-
|
|
59
|
+
### Validation schemas
|
|
124
60
|
|
|
125
|
-
|
|
126
|
-
|
|
61
|
+
- `hekireki-zod` — [Zod](https://zod.dev/)
|
|
62
|
+
- `hekireki-valibot` — [Valibot](https://valibot.dev/)
|
|
63
|
+
- `hekireki-arktype` — [ArkType](https://arktype.io/)
|
|
64
|
+
- `hekireki-effect` — [Effect Schema](https://effect.website/docs/schema/introduction/)
|
|
65
|
+
- `hekireki-typebox` — [TypeBox](https://github.com/sinclairzx81/typebox)
|
|
66
|
+
- `hekireki-ajv` — [AJV](https://ajv.js.org/)
|
|
67
|
+
- `hekireki-pydantic` — [Pydantic](https://docs.pydantic.dev/)
|
|
127
68
|
|
|
128
|
-
|
|
129
|
-
| ------ | ----------------- | ----------------------------------------- |
|
|
130
|
-
| `@z.` | Zod | `/// @z.string().min(1).max(50)` |
|
|
131
|
-
| `@v.` | Valibot | `/// @v.pipe(v.string(), v.minLength(1))` |
|
|
132
|
-
| `@a.` | ArkType | `/// @a."1 <= string <= 50"` |
|
|
133
|
-
| `@e.` | Effect Schema | `/// @e.Schema.UUID` |
|
|
134
|
-
| `@t.` | TypeBox | `/// @t.Type.String({ format: 'uuid' })` |
|
|
135
|
-
| `@j.` | AJV / JSON Schema | `/// @j.{ type: 'string' as const }` |
|
|
136
|
-
| `@p.` | Pydantic | `/// @p.EmailStr` |
|
|
69
|
+
### ORM models
|
|
137
70
|
|
|
138
|
-
|
|
139
|
-
|
|
71
|
+
- `hekireki-drizzle` — [Drizzle](https://orm.drizzle.team/)
|
|
72
|
+
- `hekireki-kysely` — [Kysely](https://kysely.dev/)
|
|
73
|
+
- `hekireki-sqlalchemy` — [SQLAlchemy](https://www.sqlalchemy.org/)
|
|
74
|
+
- `hekireki-django` — [Django](https://www.djangoproject.com/)
|
|
75
|
+
- `hekireki-gorm` — [GORM](https://gorm.io/)
|
|
76
|
+
- `hekireki-sea-orm` — [SeaORM](https://www.sea-ql.org/SeaORM/)
|
|
77
|
+
- `hekireki-ecto` — [Ecto](https://hexdocs.pm/ecto/Ecto.Schema.html)
|
|
78
|
+
- `hekireki-activerecord` — [Active Record](https://guides.rubyonrails.org/active_record_basics.html)
|
|
79
|
+
- `hekireki-eloquent` — [Eloquent](https://laravel.com/docs/eloquent)
|
|
80
|
+
- `hekireki-efcore` — [EF Core](https://learn.microsoft.com/ef/core/)
|
|
81
|
+
- `hekireki-atlas` — [Atlas](https://atlasgo.io/) HCL
|
|
140
82
|
|
|
141
|
-
|
|
142
|
-
that has no physical foreign key — it is drawn in the Mermaid, DBML and image output (dashed in the
|
|
143
|
-
drawing) even though the column carries no `@relation(...)`:
|
|
83
|
+
### ER diagrams
|
|
144
84
|
|
|
145
|
-
|
|
146
|
-
/// @relation User.id Post.userId one-to-many
|
|
147
|
-
model Post {
|
|
148
|
-
id String @id @default(uuid())
|
|
149
|
-
userId String
|
|
150
|
-
}
|
|
151
|
-
```
|
|
85
|
+
- `hekireki-er` — Mermaid, DBML, PNG and SVG
|
|
152
86
|
|
|
153
|
-
##
|
|
87
|
+
## Configuration
|
|
154
88
|
|
|
155
|
-
|
|
156
|
-
| ----------------------- | -------------------------- | ------------------------------------------- | ------------------------------------ |
|
|
157
|
-
| `hekireki-zod` | TypeScript | `index.ts` | `type`, `comment`, `relation`, `zod` |
|
|
158
|
-
| `hekireki-valibot` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
|
|
159
|
-
| `hekireki-arktype` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
|
|
160
|
-
| `hekireki-effect` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
|
|
161
|
-
| `hekireki-typebox` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
|
|
162
|
-
| `hekireki-ajv` | TypeScript | `index.ts` | `type`, `comment`, `relation` |
|
|
163
|
-
| `hekireki-drizzle` | TypeScript | `schema.ts` | — |
|
|
164
|
-
| `hekireki-kysely` | TypeScript | `types.ts` | — |
|
|
165
|
-
| `hekireki-pydantic` | Python | `models.py` | `comment`, `relation` |
|
|
166
|
-
| `hekireki-sqlalchemy` | Python | `models.py` | — |
|
|
167
|
-
| `hekireki-django` | Python (Django ≥ 5.2) | `models.py` | — |
|
|
168
|
-
| `hekireki-gorm` | Go | `models.go` | `package` |
|
|
169
|
-
| `hekireki-sea-orm` | Rust | one `.rs` per model, `mod.rs`, `prelude.rs` | `renameAll` |
|
|
170
|
-
| `hekireki-ecto` | Elixir | one `.ex` per model | `app` |
|
|
171
|
-
| `hekireki-activerecord` | Ruby (Rails ≥ 7.1) | one `.rb` per model | — |
|
|
172
|
-
| `hekireki-eloquent` | PHP (Laravel, PHP ≥ 8.1) | one `.php` per model and enum | `namespace` |
|
|
173
|
-
| `hekireki-atlas` | Atlas HCL | `schema.hcl` | `schemaName`, `comment` |
|
|
174
|
-
| `hekireki-er` | Mermaid / DBML / PNG / SVG | — ([extension required](#er-diagrams)) | `outputs`, `theme` |
|
|
89
|
+
Every generator with every option. All options are optional.
|
|
175
90
|
|
|
176
|
-
|
|
91
|
+
### Validation schemas
|
|
177
92
|
|
|
178
93
|
```prisma
|
|
179
94
|
generator Hekireki-Zod {
|
|
180
95
|
provider = "hekireki-zod"
|
|
181
|
-
output = "./zod"
|
|
182
|
-
type = true
|
|
183
|
-
comment = true
|
|
184
|
-
relation = true
|
|
185
|
-
zod = "v4"
|
|
96
|
+
output = "./zod"
|
|
97
|
+
type = true // Export TypeScript types
|
|
98
|
+
comment = true // Keep /// comments
|
|
99
|
+
relation = true // Add <Model>Relations schemas
|
|
100
|
+
zod = "v4" // "v4" (default), "mini" or "@hono/zod-openapi"
|
|
186
101
|
}
|
|
187
102
|
|
|
188
|
-
// Valibot, ArkType, Effect Schema, TypeBox and AJV take the same type / comment / relation options.
|
|
189
103
|
generator Hekireki-Valibot {
|
|
190
104
|
provider = "hekireki-valibot"
|
|
191
105
|
output = "./valibot"
|
|
@@ -194,209 +108,178 @@ generator Hekireki-Valibot {
|
|
|
194
108
|
relation = true
|
|
195
109
|
}
|
|
196
110
|
|
|
111
|
+
generator Hekireki-ArkType {
|
|
112
|
+
provider = "hekireki-arktype"
|
|
113
|
+
output = "./arktype"
|
|
114
|
+
type = true
|
|
115
|
+
comment = true
|
|
116
|
+
relation = true
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
generator Hekireki-Effect {
|
|
120
|
+
provider = "hekireki-effect"
|
|
121
|
+
output = "./effect"
|
|
122
|
+
type = true
|
|
123
|
+
comment = true
|
|
124
|
+
relation = true
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
generator Hekireki-TypeBox {
|
|
128
|
+
provider = "hekireki-typebox"
|
|
129
|
+
output = "./typebox"
|
|
130
|
+
type = true
|
|
131
|
+
comment = true
|
|
132
|
+
relation = true
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
generator Hekireki-AJV {
|
|
136
|
+
provider = "hekireki-ajv"
|
|
137
|
+
output = "./ajv"
|
|
138
|
+
type = true
|
|
139
|
+
comment = true
|
|
140
|
+
relation = true
|
|
141
|
+
}
|
|
142
|
+
|
|
197
143
|
generator Hekireki-Pydantic {
|
|
198
144
|
provider = "hekireki-pydantic"
|
|
199
|
-
output = "./pydantic"
|
|
200
|
-
comment = true
|
|
201
|
-
relation = true
|
|
145
|
+
output = "./pydantic"
|
|
146
|
+
comment = true
|
|
147
|
+
relation = true
|
|
202
148
|
}
|
|
149
|
+
```
|
|
203
150
|
|
|
204
|
-
|
|
151
|
+
### ORM models
|
|
152
|
+
|
|
153
|
+
```prisma
|
|
205
154
|
generator Hekireki-Drizzle {
|
|
206
155
|
provider = "hekireki-drizzle"
|
|
207
|
-
output = "./drizzle"
|
|
156
|
+
output = "./drizzle"
|
|
208
157
|
}
|
|
209
158
|
|
|
210
|
-
generator Hekireki-
|
|
211
|
-
provider
|
|
212
|
-
output
|
|
213
|
-
|
|
214
|
-
|
|
159
|
+
generator Hekireki-Kysely {
|
|
160
|
+
provider = "hekireki-kysely"
|
|
161
|
+
output = "./kysely"
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
generator Hekireki-SQLAlchemy {
|
|
165
|
+
provider = "hekireki-sqlalchemy"
|
|
166
|
+
output = "./sqlalchemy"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
generator Hekireki-Django {
|
|
170
|
+
provider = "hekireki-django"
|
|
171
|
+
output = "./django"
|
|
215
172
|
}
|
|
216
173
|
|
|
217
174
|
generator Hekireki-GORM {
|
|
218
175
|
provider = "hekireki-gorm"
|
|
219
|
-
output = "./gorm"
|
|
220
|
-
package = "model"
|
|
176
|
+
output = "./gorm"
|
|
177
|
+
package = "model" // Go package name (default: "model")
|
|
221
178
|
}
|
|
222
179
|
|
|
223
180
|
generator Hekireki-SeaORM {
|
|
224
181
|
provider = "hekireki-sea-orm"
|
|
225
|
-
output = "./
|
|
226
|
-
renameAll = "camelCase" // #[serde(rename_all = "...")]
|
|
182
|
+
output = "./sea-orm"
|
|
183
|
+
renameAll = "camelCase" // #[serde(rename_all = "...")]
|
|
227
184
|
}
|
|
228
185
|
|
|
229
186
|
generator Hekireki-Ecto {
|
|
230
187
|
provider = "hekireki-ecto"
|
|
231
188
|
output = "./ecto"
|
|
232
|
-
app = "MyApp"
|
|
189
|
+
app = "MyApp" // Module prefix (default: "MyApp")
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
generator Hekireki-ActiveRecord {
|
|
193
|
+
provider = "hekireki-activerecord"
|
|
194
|
+
output = "./activerecord"
|
|
233
195
|
}
|
|
234
196
|
|
|
235
197
|
generator Hekireki-Eloquent {
|
|
236
198
|
provider = "hekireki-eloquent"
|
|
237
199
|
output = "./eloquent"
|
|
238
|
-
namespace = "App.Models"
|
|
200
|
+
namespace = "App.Models" // "." becomes "\" (default: "App\Models")
|
|
239
201
|
}
|
|
240
202
|
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
theme = "light" // .png / .svg only. "light" (default) or "dark"
|
|
203
|
+
// PostgreSQL only
|
|
204
|
+
generator Hekireki-EFCore {
|
|
205
|
+
provider = "hekireki-efcore"
|
|
206
|
+
output = "./efcore"
|
|
207
|
+
namespace = "MyApp.Models" // C# namespace (default: "Models")
|
|
208
|
+
context = "AppDbContext" // DbContext class name (default: "AppDbContext")
|
|
248
209
|
}
|
|
249
|
-
```
|
|
250
210
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
211
|
+
generator Hekireki-Atlas {
|
|
212
|
+
provider = "hekireki-atlas"
|
|
213
|
+
output = "./atlas"
|
|
214
|
+
schemaName = "public" // Default: "public" ("main" on SQLite)
|
|
215
|
+
comment = true // Keep /// comments
|
|
216
|
+
}
|
|
217
|
+
```
|
|
256
218
|
|
|
257
|
-
|
|
258
|
-
| --------- | ---------------------- |
|
|
259
|
-
| `.md` | A Mermaid `erDiagram` |
|
|
260
|
-
| `.dbml` | DBML |
|
|
261
|
-
| `.png` | The diagram, as a PNG |
|
|
262
|
-
| `.svg` | The diagram, as an SVG |
|
|
219
|
+
### ER diagrams
|
|
263
220
|
|
|
264
|
-
|
|
265
|
-
you need, `output` alone is enough:
|
|
221
|
+
The extension of each path picks the format: `.md` (Mermaid), `.dbml`, `.png` or `.svg`.
|
|
266
222
|
|
|
267
223
|
```prisma
|
|
268
224
|
generator Hekireki-ER {
|
|
269
225
|
provider = "hekireki-er"
|
|
270
|
-
|
|
226
|
+
outputs = ["docs/er.md", "docs/er.dbml", "docs/er.png", "docs/er.svg"] // One file: output = "docs/er.md"
|
|
227
|
+
theme = "dark" // .png / .svg: "light" (default) or "dark"
|
|
271
228
|
}
|
|
272
229
|
```
|
|
273
230
|
|
|
274
|
-
|
|
231
|
+
## Annotations
|
|
232
|
+
|
|
233
|
+
A `///` line starting with `@z.`, `@v.`, `@a.`, `@e.`, `@t.`, `@j.` or `@p.` is used as-is by Zod,
|
|
234
|
+
Valibot, ArkType, Effect Schema, TypeBox, AJV or Pydantic. Any other `///` line is documentation.
|
|
275
235
|
|
|
276
236
|
```prisma
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
237
|
+
model User {
|
|
238
|
+
/// Display name
|
|
239
|
+
/// @z.string().min(1).max(50)
|
|
240
|
+
/// @v.pipe(v.string(), v.minLength(1), v.maxLength(50))
|
|
241
|
+
/// @a."1 <= string <= 50"
|
|
242
|
+
/// @e.Schema.String.pipe(Schema.minLength(1), Schema.maxLength(50))
|
|
243
|
+
/// @t.Type.String({ minLength: 1, maxLength: 50 })
|
|
244
|
+
/// @j.{ type: 'string' as const, minLength: 1, maxLength: 50 }
|
|
245
|
+
/// @p.Annotated[str, StringConstraints(min_length=1, max_length=50)]
|
|
246
|
+
name String
|
|
247
|
+
/// @z.email()
|
|
248
|
+
/// @v.pipe(v.string(), v.email())
|
|
249
|
+
/// @a."string.email"
|
|
250
|
+
/// @e.Schema.String.pipe(Schema.pattern(/^[^@]+@[^@]+\.[^@]+$/))
|
|
251
|
+
/// @t.Type.String({ format: 'email' })
|
|
252
|
+
/// @j.{ type: 'string' as const, format: 'email' as const }
|
|
253
|
+
/// @p.EmailStr
|
|
254
|
+
email String @unique
|
|
280
255
|
}
|
|
281
256
|
```
|
|
282
257
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
guess — `output = "docs"` fails.
|
|
287
|
-
|
|
288
|
-
Every option belongs to a format (`theme` to `.png` and `.svg`), and setting one that no chosen
|
|
289
|
-
format reads is an error — so an option never looks like it did something it did not.
|
|
290
|
-
|
|
291
|
-
`.md` writes a Mermaid diagram:
|
|
292
|
-
|
|
293
|
-
```mermaid
|
|
294
|
-
erDiagram
|
|
295
|
-
User ||--o{ Post : "(id) - (userId)"
|
|
296
|
-
User {
|
|
297
|
-
string id PK "Primary key"
|
|
298
|
-
string name "Display name"
|
|
299
|
-
}
|
|
300
|
-
Post {
|
|
301
|
-
string id PK "Primary key"
|
|
302
|
-
string title "Article title"
|
|
303
|
-
string userId FK "Foreign key referencing User.id"
|
|
304
|
-
}
|
|
305
|
-
```
|
|
258
|
+
On a model, `@p.ConfigDict(...)` becomes Pydantic's `model_config`, and
|
|
259
|
+
`@relation <Model>.<field> <Model>.<field> <type>` adds a relation without a foreign key to the ER
|
|
260
|
+
diagram (drawn dashed).
|
|
306
261
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
Studio's Schema page exports both with the models where you dragged them.
|
|
262
|
+
```prisma
|
|
263
|
+
/// @p.ConfigDict(extra='forbid')
|
|
264
|
+
/// @relation User.id Post.userId one-to-many
|
|
265
|
+
model Post {
|
|
266
|
+
id String @id @default(uuid())
|
|
267
|
+
userId String
|
|
268
|
+
}
|
|
269
|
+
```
|
|
316
270
|
|
|
317
271
|
## Studio
|
|
318
272
|
|
|
319
|
-
`hekireki studio` opens the schema in the browser, served locally by [Hono](https://hono.dev/).
|
|
320
|
-
Nothing is generated first — Studio reads `schema.prisma` itself and reloads on every edit to it:
|
|
321
|
-
|
|
322
273
|
```bash
|
|
323
|
-
#
|
|
324
|
-
hekireki studio
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
hekireki studio --schema prisma/schema
|
|
328
|
-
|
|
329
|
-
# Browse a database of your choosing
|
|
330
|
-
hekireki studio --url file:./dev.db
|
|
331
|
-
|
|
332
|
-
# Listen on another port
|
|
333
|
-
hekireki studio -p 3000
|
|
274
|
+
hekireki studio # ./prisma/schema.prisma or ./schema.prisma
|
|
275
|
+
hekireki studio --schema prisma/schema # A multi-file schema
|
|
276
|
+
hekireki studio --url file:./dev.db # A database of your choice
|
|
277
|
+
hekireki studio -p 3000 # Another port (default: 5555)
|
|
334
278
|
```
|
|
335
279
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
| `/docs` — Docs | The reference page: every model and enum with its fields, attributes and comments |
|
|
340
|
-
| `/models/<name>` | A model's rows, editable, next to its fields |
|
|
341
|
-
| `/enums/<name>` | An enum with its members and the fields that hold it |
|
|
342
|
-
| `/prisma` | The schema in a Prisma editor, with the language server's diagnostics |
|
|
343
|
-
| `/sql` | A SQL console: completion from the schema, a data-flow picture, the query plan |
|
|
344
|
-
|
|
345
|
-
**⌘K** / **Ctrl+K** opens a search over the whole schema — every page, model, enum and field, by
|
|
346
|
-
the letters of its name in order, so `usemail` finds `User.email`. Following a field opens its
|
|
347
|
-
model on that row.
|
|
348
|
-
|
|
349
|
-
On a model's page, **/** puts the cursor in the search box and every column is searched as you
|
|
350
|
-
type, with what matched marked in the rows that come back. Clicking a cell picks it and nothing
|
|
351
|
-
more; the two buttons that appear on it copy just that value or open it for editing, and **⌘C** /
|
|
352
|
-
**Ctrl+C** copies the picked cell. Tick rows to act on them together: **Copy** takes them as
|
|
353
|
-
tab-separated text — what a spreadsheet pastes — and **Delete** asks first, naming the rows it is
|
|
354
|
-
about to remove. **Export** downloads or copies the page as CSV or JSON. A SQL result is sorted and narrowed in the browser,
|
|
355
|
-
without asking the database a second question.
|
|
356
|
-
|
|
357
|
-
The SQL page completes table and column names from the schema — `@@map` / `@map` names, as the
|
|
358
|
-
database knows them — and reads the statement as you type: **Flow** draws where its rows come from
|
|
359
|
-
(every table, join, filter, grouping and the projection), **Columns** traces each result column back
|
|
360
|
-
to the base tables and lists every table touched with its alias and the columns read, and **Type**
|
|
361
|
-
shows the row and parameter types as TypeScript, and **Plan** asks the database for its execution
|
|
362
|
-
plan (`EXPLAIN`) as a tree. The models the statement touches light up on the
|
|
363
|
-
schema beside it, with the columns it reads marked; a `?` or `$1` placeholder gets a field typed
|
|
364
|
-
from the column it is compared with, and a name the schema does not know is underlined.
|
|
365
|
-
|
|
366
|
-
**Columns** in the toolbar says which columns the grid draws, remembered per model; what is on
|
|
367
|
-
screen is what **Copy** and **Export** take, so a copy of two columns out of forty is two ticks
|
|
368
|
-
away. A row is still written whole, so the Add row form brings every column back for as long as it
|
|
369
|
-
is open.
|
|
370
|
-
|
|
371
|
-
`--schema` takes either a `schema.prisma` file or a directory — every `.prisma` file directly in the
|
|
372
|
-
directory (subdirectories are not descended into) is read as one schema, which is how Prisma's
|
|
373
|
-
[multi-file schema](https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema)
|
|
374
|
-
(`prisma/schema/`) is opened. Without the flag, `./prisma/schema.prisma` then `./schema.prisma` are
|
|
375
|
-
looked for — the same two paths the Prisma CLI defaults to. Either way the whole directory is
|
|
376
|
-
watched, so a `.prisma` file added to it appears in Studio without a restart.
|
|
377
|
-
|
|
378
|
-
The database is the one `--url` names, or `DATABASE_URL` from the environment or `.env`, then
|
|
379
|
-
`datasource.url` in `prisma.config.ts`; `postgres://`, `mysql://` and `file:` are understood. A
|
|
380
|
-
relative `file:` path is resolved from the schema directory, as Prisma resolves it — with the
|
|
381
|
-
default `prisma/schema.prisma`, `file:./dev.db` is `prisma/dev.db`. Without a database, Studio
|
|
382
|
-
serves the schema alone — the diagram, the docs and the editor still work.
|
|
383
|
-
|
|
384
|
-
The HTTP API behind it is documented in [docs/studio-api.md](https://github.com/nakita628/hekireki/blob/main/packages/hekireki/docs/studio-api.md).
|
|
385
|
-
|
|
386
|
-
## Notes
|
|
387
|
-
|
|
388
|
-
- **Atlas** — declarative `atlas schema apply` drops whatever is missing from the HCL, and Prisma's
|
|
389
|
-
`_prisma_migrations` table, `@ignore`d columns and `Unsupported(...)` types can never appear in it.
|
|
390
|
-
Dry-run first and exclude the migrations table: `--exclude '_prisma_migrations'`.
|
|
391
|
-
- **Kysely** — only **database-side** defaults become `Generated<T>`. `uuid()`, `cuid()`, `ulid()`
|
|
392
|
-
and `nanoid()` are evaluated by the Prisma Client, so a raw Kysely insert must still supply them.
|
|
393
|
-
- **Django** — enums become `TextChoices` + `TextField(choices=…)` (Django has no native PostgreSQL
|
|
394
|
-
enum type), a foreign key to a composite `@@id` / `@@unique` is emitted as the scalar columns
|
|
395
|
-
without a relation, `onUpdate` is dropped, and a plain `DateTime` maps to `DateTimeField` while
|
|
396
|
-
Prisma stores `timestamp` — annotate it `@db.Timestamptz` to keep `USE_TZ = True` reads aware.
|
|
397
|
-
- **Eloquent** — a composite primary key is emitted as `protected $primaryKey = null;`, because
|
|
398
|
-
Eloquent has no native support for one. Active Record writes the real
|
|
399
|
-
`self.primary_key = [...]` (Rails ≥ 7.1).
|
|
280
|
+
Studio shows the ER diagram, the docs, each model's rows, a Prisma editor and a SQL console, and
|
|
281
|
+
reloads when the schema changes. The database comes from `--url`, `DATABASE_URL` or
|
|
282
|
+
`prisma.config.ts`.
|
|
400
283
|
|
|
401
284
|
## License
|
|
402
285
|
|
package/dist/bin/activerecord.js
CHANGED
package/dist/bin/ajv.js
CHANGED
package/dist/bin/arktype.js
CHANGED
package/dist/bin/atlas.js
CHANGED
package/dist/bin/django.js
CHANGED
package/dist/bin/drizzle.js
CHANGED
package/dist/bin/ecto.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/bin/effect.js
CHANGED
package/dist/bin/eloquent.js
CHANGED
package/dist/bin/er.js
CHANGED
package/dist/bin/gorm.js
CHANGED