hekireki 0.21.0 → 0.22.0
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 +60 -344
- 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 +6 -2
- 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,381 +14,105 @@ 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
|
-
datasource db {
|
|
32
|
-
provider = "sqlite"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
20
|
generator Hekireki-Zod {
|
|
36
21
|
provider = "hekireki-zod"
|
|
37
22
|
output = "./zod"
|
|
38
|
-
type = true
|
|
39
|
-
comment = true
|
|
40
|
-
relation = true
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
model User {
|
|
44
|
-
/// Primary key
|
|
45
|
-
/// @z.uuid()
|
|
46
|
-
id String @id @default(uuid())
|
|
47
|
-
/// Display name
|
|
48
|
-
/// @z.string().min(1).max(50)
|
|
49
|
-
name String
|
|
50
|
-
posts Post[]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
model Post {
|
|
54
|
-
/// Primary key
|
|
55
|
-
/// @z.uuid()
|
|
56
|
-
id String @id @default(uuid())
|
|
57
|
-
/// Article title
|
|
58
|
-
/// @z.string().min(1).max(100)
|
|
59
|
-
title String
|
|
60
|
-
/// Foreign key referencing User.id
|
|
61
|
-
/// @z.uuid()
|
|
62
|
-
userId String
|
|
63
|
-
user User @relation(fields: [userId], references: [id])
|
|
64
23
|
}
|
|
65
24
|
```
|
|
66
25
|
|
|
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).
|
|
122
|
-
|
|
123
|
-
## Annotations
|
|
124
|
-
|
|
125
|
-
A `///` comment on a field is its documentation. A `///` line that begins with one of the prefixes
|
|
126
|
-
below is the validation the matching generator emits for that field, used verbatim:
|
|
26
|
+
## Generators
|
|
127
27
|
|
|
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` |
|
|
28
|
+
### Validation schemas
|
|
137
29
|
|
|
138
|
-
|
|
139
|
-
|
|
30
|
+
- `hekireki-zod` — [Zod](https://zod.dev/)
|
|
31
|
+
- `hekireki-valibot` — [Valibot](https://valibot.dev/)
|
|
32
|
+
- `hekireki-arktype` — [ArkType](https://arktype.io/)
|
|
33
|
+
- `hekireki-effect` — [Effect Schema](https://effect.website/docs/schema/introduction/)
|
|
34
|
+
- `hekireki-typebox` — [TypeBox](https://github.com/sinclairzx81/typebox)
|
|
35
|
+
- `hekireki-ajv` — [AJV](https://ajv.js.org/)
|
|
36
|
+
- `hekireki-pydantic` — [Pydantic](https://docs.pydantic.dev/)
|
|
140
37
|
|
|
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(...)`:
|
|
38
|
+
### ORM models
|
|
144
39
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
40
|
+
- `hekireki-drizzle` — [Drizzle](https://orm.drizzle.team/)
|
|
41
|
+
- `hekireki-kysely` — [Kysely](https://kysely.dev/)
|
|
42
|
+
- `hekireki-sqlalchemy` — [SQLAlchemy](https://www.sqlalchemy.org/)
|
|
43
|
+
- `hekireki-django` — [Django](https://www.djangoproject.com/)
|
|
44
|
+
- `hekireki-gorm` — [GORM](https://gorm.io/)
|
|
45
|
+
- `hekireki-sea-orm` — [SeaORM](https://www.sea-ql.org/SeaORM/)
|
|
46
|
+
- `hekireki-ecto` — [Ecto](https://hexdocs.pm/ecto/Ecto.Schema.html)
|
|
47
|
+
- `hekireki-activerecord` — [Active Record](https://guides.rubyonrails.org/active_record_basics.html)
|
|
48
|
+
- `hekireki-eloquent` — [Eloquent](https://laravel.com/docs/eloquent)
|
|
49
|
+
- `hekireki-efcore` — [EF Core](https://learn.microsoft.com/ef/core/)
|
|
50
|
+
- `hekireki-atlas` — [Atlas](https://atlasgo.io/) HCL
|
|
152
51
|
|
|
153
|
-
|
|
52
|
+
### ER diagrams
|
|
154
53
|
|
|
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` |
|
|
54
|
+
- `hekireki-er` — Mermaid, DBML, PNG and SVG
|
|
175
55
|
|
|
176
|
-
##
|
|
56
|
+
## Options
|
|
177
57
|
|
|
178
58
|
```prisma
|
|
179
59
|
generator Hekireki-Zod {
|
|
180
60
|
provider = "hekireki-zod"
|
|
181
|
-
output = "./zod"
|
|
182
|
-
type = true
|
|
183
|
-
comment = true
|
|
184
|
-
relation = true
|
|
185
|
-
zod = "v4"
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Valibot, ArkType, Effect Schema, TypeBox and AJV take the same type / comment / relation options.
|
|
189
|
-
generator Hekireki-Valibot {
|
|
190
|
-
provider = "hekireki-valibot"
|
|
191
|
-
output = "./valibot"
|
|
192
|
-
type = true
|
|
193
|
-
comment = true
|
|
194
|
-
relation = true
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
generator Hekireki-Pydantic {
|
|
198
|
-
provider = "hekireki-pydantic"
|
|
199
|
-
output = "./pydantic" // A directory here yields ./pydantic/models.py
|
|
200
|
-
comment = true // /// comments as docstrings (default: false)
|
|
201
|
-
relation = true // <Model>Relations subclasses (default: false)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Drizzle, Kysely, SQLAlchemy, Django and Active Record take output alone.
|
|
205
|
-
generator Hekireki-Drizzle {
|
|
206
|
-
provider = "hekireki-drizzle"
|
|
207
|
-
output = "./drizzle" // A directory here yields ./drizzle/schema.ts
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
generator Hekireki-Atlas {
|
|
211
|
-
provider = "hekireki-atlas"
|
|
212
|
-
output = "./atlas" // A directory here yields ./atlas/schema.hcl
|
|
213
|
-
schemaName = "public" // Schema label (default: postgresql/mysql "public", sqlite "main")
|
|
214
|
-
comment = true // /// comments as comment attributes (default: false)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
generator Hekireki-GORM {
|
|
218
|
-
provider = "hekireki-gorm"
|
|
219
|
-
output = "./gorm" // A directory here yields ./gorm/models.go
|
|
220
|
-
package = "model" // Go package name (default: model)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
generator Hekireki-SeaORM {
|
|
224
|
-
provider = "hekireki-sea-orm"
|
|
225
|
-
output = "./sea_orm"
|
|
226
|
-
renameAll = "camelCase" // #[serde(rename_all = "...")] (optional)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
generator Hekireki-Ecto {
|
|
230
|
-
provider = "hekireki-ecto"
|
|
231
|
-
output = "./ecto"
|
|
232
|
-
app = "MyApp" // Module prefix (default: MyApp)
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
generator Hekireki-Eloquent {
|
|
236
|
-
provider = "hekireki-eloquent"
|
|
237
|
-
output = "./eloquent"
|
|
238
|
-
namespace = "App.Models" // PHP namespace, "." becomes "\" (default: App\Models)
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// ER takes output or outputs (not both). Every path is a file ending in .md, .dbml, .png or .svg,
|
|
242
|
-
// never a directory, and its extension picks the format (see ER diagrams).
|
|
243
|
-
generator Hekireki-ER {
|
|
244
|
-
provider = "hekireki-er"
|
|
245
|
-
// output = "docs/er.md" // One file: output alone is enough
|
|
246
|
-
outputs = ["docs/er.md", "docs/schema.dbml", "docs/er.svg"] // Several files: list them here
|
|
247
|
-
theme = "light" // .png / .svg only. "light" (default) or "dark"
|
|
61
|
+
output = "./zod"
|
|
62
|
+
type = true // Export TypeScript types
|
|
63
|
+
comment = true // Keep /// comments
|
|
64
|
+
relation = true // Add <Model>Relations schemas
|
|
65
|
+
zod = "v4" // "v4" (default), "mini" or "@hono/zod-openapi"
|
|
248
66
|
}
|
|
249
67
|
```
|
|
250
68
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
69
|
+
- `type`, `comment`, `relation` — every validation schema generator (Pydantic: `comment`, `relation`)
|
|
70
|
+
- `package` — GORM package name (default: `model`)
|
|
71
|
+
- `renameAll` — SeaORM `#[serde(rename_all = "...")]`
|
|
72
|
+
- `app` — Ecto module prefix (default: `MyApp`)
|
|
73
|
+
- `namespace` — Eloquent (default: `App\Models`) and EF Core (default: `Models`)
|
|
74
|
+
- `context` — EF Core `DbContext` class name (default: `AppDbContext`)
|
|
75
|
+
- `schemaName`, `comment` — Atlas
|
|
76
|
+
- `outputs`, `theme` — ER
|
|
256
77
|
|
|
257
|
-
|
|
258
|
-
| --------- | ---------------------- |
|
|
259
|
-
| `.md` | A Mermaid `erDiagram` |
|
|
260
|
-
| `.dbml` | DBML |
|
|
261
|
-
| `.png` | The diagram, as a PNG |
|
|
262
|
-
| `.svg` | The diagram, as an SVG |
|
|
78
|
+
## Annotations
|
|
263
79
|
|
|
264
|
-
|
|
265
|
-
|
|
80
|
+
A `///` line starting with `@z.`, `@v.`, `@a.`, `@e.`, `@t.`, `@j.` or `@p.` is used as-is by Zod,
|
|
81
|
+
Valibot, ArkType, Effect Schema, TypeBox, AJV or Pydantic. Any other `///` line is documentation.
|
|
266
82
|
|
|
267
83
|
```prisma
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
84
|
+
model User {
|
|
85
|
+
/// Display name
|
|
86
|
+
/// @z.string().min(1).max(50)
|
|
87
|
+
/// @v.pipe(v.string(), v.minLength(1), v.maxLength(50))
|
|
88
|
+
name String
|
|
271
89
|
}
|
|
272
90
|
```
|
|
273
91
|
|
|
274
|
-
|
|
92
|
+
## ER diagrams
|
|
93
|
+
|
|
94
|
+
The extension of each path picks the format: `.md` (Mermaid), `.dbml`, `.png` or `.svg`.
|
|
275
95
|
|
|
276
96
|
```prisma
|
|
277
97
|
generator Hekireki-ER {
|
|
278
98
|
provider = "hekireki-er"
|
|
279
|
-
outputs = ["docs/er.md", "docs/er.svg"]
|
|
99
|
+
outputs = ["docs/er.md", "docs/er.svg"] // One file: output = "docs/er.md"
|
|
100
|
+
theme = "dark" // .png / .svg: "light" (default) or "dark"
|
|
280
101
|
}
|
|
281
102
|
```
|
|
282
103
|
|
|
283
|
-
Every path is a whole file, directory and extension included, resolved the way Prisma resolves any
|
|
284
|
-
`output`: against the directory of the schema file that declares the generator. Neither ever names
|
|
285
|
-
a directory, so a path with no extension, or with one outside the four, is an error rather than a
|
|
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
|
-
```
|
|
306
|
-
|
|
307
|
-
`.dbml` writes the same model for [dbdiagram.io](https://dbml.dbdiagram.io/) as the database
|
|
308
|
-
names it: tables, columns, enums and enum values under their `@@map` / `@map` names wherever the
|
|
309
|
-
schema declares one. `.png` and `.svg`
|
|
310
|
-
draw the diagram Hekireki Studio shows, laid out automatically: a card per model and enum, its
|
|
311
|
-
fields with `🔑` / `🔗` / `UK` marks, the attributes and `///` prose under each, the `@@id` /
|
|
312
|
-
`@@unique` / `@@index` block attributes, and an edge per relation in crow's-foot notation captioned
|
|
313
|
-
with its cardinality and referential action. No external renderer is involved, and the PNG is
|
|
314
|
-
rasterised at 2x. Use `.svg` for files in the repository and `.png` where images are embedded.
|
|
315
|
-
Studio's Schema page exports both with the models where you dragged them.
|
|
316
|
-
|
|
317
104
|
## Studio
|
|
318
105
|
|
|
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
106
|
```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
|
|
107
|
+
hekireki studio # ./prisma/schema.prisma or ./schema.prisma
|
|
108
|
+
hekireki studio --schema prisma/schema # A multi-file schema
|
|
109
|
+
hekireki studio --url file:./dev.db # A database of your choice
|
|
110
|
+
hekireki studio -p 3000 # Another port (default: 5555)
|
|
334
111
|
```
|
|
335
112
|
|
|
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).
|
|
113
|
+
Studio shows the ER diagram, the docs, each model's rows, a Prisma editor and a SQL console, and
|
|
114
|
+
reloads when the schema changes. The database comes from `--url`, `DATABASE_URL` or
|
|
115
|
+
`prisma.config.ts`.
|
|
400
116
|
|
|
401
117
|
## License
|
|
402
118
|
|
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
package/dist/bin/hekireki.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Config, Console, Data, Effect, Option, Schema, Stdio } from "effect";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { CliError, Command, Flag } from "effect/unstable/cli";
|
|
7
7
|
//#region package.json
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.22.0";
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/studio/server/constants/index.ts
|
|
11
11
|
/** Studio only listens on loopback: the API serves the raw schema and runs SQL without authentication. */
|
package/dist/bin/kysely.js
CHANGED
package/dist/bin/pydantic.js
CHANGED
package/dist/bin/sea-orm.js
CHANGED
package/dist/bin/sqlalchemy.js
CHANGED
package/dist/bin/typebox.js
CHANGED
package/dist/bin/valibot.js
CHANGED
package/dist/bin/zod.js
CHANGED