hekireki 0.38.0 → 0.40.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 +129 -149
- package/dist/bin/activerecord.js +2 -3
- package/dist/bin/ajv.js +2 -3
- package/dist/bin/arktype.js +2 -3
- package/dist/bin/atlas.js +2 -3
- package/dist/bin/django.js +2 -3
- package/dist/bin/drizzle.js +2 -3
- package/dist/bin/ecto.js +2 -3
- package/dist/bin/efcore.js +2 -3
- package/dist/bin/effect.js +2 -3
- package/dist/bin/eloquent.js +2 -3
- package/dist/bin/er.js +2 -3
- package/dist/bin/exposed.js +2 -3
- package/dist/bin/gorm.js +2 -3
- package/dist/bin/hekireki.js +12 -18
- package/dist/bin/kysely.js +2 -3
- package/dist/bin/openapi.d.ts +1 -0
- package/dist/bin/openapi.js +5 -0
- package/dist/bin/pydantic.js +2 -3
- package/dist/bin/sea-orm.js +2 -3
- package/dist/bin/seed.js +2 -3
- package/dist/bin/sqlalchemy.js +2 -3
- package/dist/bin/typebox.js +2 -3
- package/dist/bin/valibot.js +2 -3
- package/dist/bin/zod.js +2 -3
- package/dist/{bin-BqUSO3tD.js → bin-CVNnCHYf.js} +563 -181
- package/dist/{discover-taxa67WN.js → discover-BJMo8i2-.js} +2 -3
- package/dist/{emit-D6EafjQn.js → emit-C4CeSye3.js} +3 -4
- package/dist/{file-BTbZL3ea.js → file-BAVQ-zst.js} +1 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -2
- package/dist/{migrate-Cd3qP1eq.js → migrate-BhCE-YSd.js} +7 -10
- package/dist/{plan-CdJPwUlk.js → plan-D9axVHFD.js} +93 -122
- package/dist/{prisma-model-bvolNNow.js → prisma-model-DFq7AQgV.js} +3 -6
- package/dist/{run-BsljUkdw.js → run-Be-2eG1y.js} +22 -37
- package/dist/{schema-DaaMSqfw.js → schema-CfxnFLAw.js} +3 -5
- package/dist/{sql-BGnCCgBa.js → sql-FGRCF9o4.js} +12 -22
- package/dist/{start-DbgHOCcl.js → start-9gS-ABI-.js} +137 -98
- package/dist/studio/assets/chip-5pFaNmwL.js +1 -0
- package/dist/studio/assets/client-Cn44j_II.js +2 -0
- package/dist/studio/assets/code-block-B1wLRka8.js +24 -0
- package/dist/studio/assets/confirm-dialog-C84-yLfM.js +1 -0
- package/dist/studio/assets/copy-DvJVuM56.js +1 -0
- package/dist/studio/assets/{copy-button-GpjT0EAk.js → copy-button-D4zjbBc-.js} +1 -1
- package/dist/studio/assets/dist-DEp-MbCs.js +13 -0
- package/dist/studio/assets/{docs-S_l70Obd.js → docs-Cg9xqNoX.js} +1 -1
- package/dist/studio/assets/editor.worker-CRz__AKW.js +33 -0
- package/dist/studio/assets/{enums._name-CgfuhC_J.js → enums._name-BhNYpcT7.js} +1 -1
- package/dist/studio/assets/field-icon-j33Axyq4.js +55 -0
- package/dist/studio/assets/hooks-vFvEnsyJ.js +2 -0
- package/dist/studio/assets/index-Cjy--gYX.js +11 -0
- package/dist/studio/assets/labels-Db1CHOpt.js +2 -0
- package/dist/studio/assets/lazyRouteComponent-TkAX4iEA.js +1 -0
- package/dist/studio/assets/lu-CUfSReIi.js +7 -0
- package/dist/studio/assets/marked-text-BNzjDVlk.js +3 -0
- package/dist/studio/assets/models._name-BgiyfSuj.js +1 -0
- package/dist/studio/assets/monaco-BoT_UVCW.js +943 -0
- package/dist/studio/assets/{monaco-BudPI5dD.js → monaco-DFkSQFp9.js} +2 -2
- package/dist/studio/assets/{not-found-BwoXwGj1.js → not-found-CTsERB3d.js} +1 -1
- package/dist/studio/assets/prisma-DZMNzXN7.js +2 -0
- package/dist/studio/assets/result-table-zFoiQlAu.js +1 -0
- package/dist/studio/assets/routes-Dpy0uL8H.js +1 -0
- package/dist/studio/assets/{schema-gate-2EVbnuHb.js → schema-gate-CXYSsT5T.js} +1 -1
- package/dist/studio/assets/schema-view-wADoyIFc.js +9 -0
- package/dist/studio/assets/search-field-Dshrbbug.js +5 -0
- package/dist/studio/assets/sql-0uoTjX3O.js +6 -0
- package/dist/studio/assets/table-5cZklaSq.js +1 -0
- package/dist/studio/assets/tabs-B7UQa0vf.js +1 -0
- package/dist/studio/assets/useFormValidation-D0dsTzOi.js +1 -0
- package/dist/studio/assets/useMatch-wXiBv0wx.js +1 -0
- package/dist/studio/assets/useMultipleSelectionState-CyThblbT.js +1 -0
- package/dist/studio/index.html +10 -9
- package/package.json +46 -43
- package/dist/studio/assets/chip-CwHVlS01.js +0 -1
- package/dist/studio/assets/client-B2hYQz8F.js +0 -2
- package/dist/studio/assets/code-block-dHRHGdZi.js +0 -24
- package/dist/studio/assets/confirm-dialog-CIK7kJpM.js +0 -1
- package/dist/studio/assets/copy-v7yXoQkP.js +0 -1
- package/dist/studio/assets/dist-DZceSPCo.js +0 -13
- package/dist/studio/assets/editor.worker-DWPaKKV_.js +0 -33
- package/dist/studio/assets/field-icon-D8bfUPpy.js +0 -55
- package/dist/studio/assets/hooks-DeuaUhcR.js +0 -1
- package/dist/studio/assets/index-Bker_LvN.js +0 -16
- package/dist/studio/assets/labels-DFD0w0UA.js +0 -2
- package/dist/studio/assets/lazyRouteComponent-CwnLm_G3.js +0 -1
- package/dist/studio/assets/lu-BoQjjUIa.js +0 -7
- package/dist/studio/assets/marked-text-B26BKtKj.js +0 -3
- package/dist/studio/assets/models._name-Cppkpc7A.js +0 -1
- package/dist/studio/assets/monaco-D2mUqTP2.js +0 -943
- package/dist/studio/assets/prisma-nwr9d7Hc.js +0 -2
- package/dist/studio/assets/result-table-QBRNlxVR.js +0 -1
- package/dist/studio/assets/routes-CBUHL6nR.js +0 -1
- package/dist/studio/assets/schema-view-BuDWr18M.js +0 -9
- package/dist/studio/assets/sql-DoUNVJN4.js +0 -6
- package/dist/studio/assets/table-BmClRQIB.js +0 -1
- package/dist/studio/assets/tabs-Ch4HlDpy.js +0 -1
- package/dist/studio/assets/useFormValidation-C1BcVIai.js +0 -1
- package/dist/studio/assets/useMatch-Blw1lv8C.js +0 -1
- package/dist/studio/assets/useMultipleSelectionState-VYP1HJvO.js +0 -1
package/README.md
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
# Hekireki
|
|
4
4
|
|
|
5
|
-
**[Hekireki](https://www.npmjs.com/package/hekireki)**
|
|
6
|
-
|
|
5
|
+
**[Hekireki](https://www.npmjs.com/package/hekireki)** reads a [Prisma](https://www.prisma.io/)
|
|
6
|
+
schema and writes what the rest of the project needs from it: validation schemas, ORM models, an
|
|
7
|
+
OpenAPI document, an ER diagram and seed data. It also comes with a Studio for the schema and its
|
|
8
|
+
database.
|
|
7
9
|
|
|
8
10
|
## Installation
|
|
9
11
|
|
|
@@ -11,12 +13,9 @@ ER diagrams from a [Prisma](https://www.prisma.io/) schema, and seeds a database
|
|
|
11
13
|
npm install -D hekireki
|
|
12
14
|
```
|
|
13
15
|
|
|
14
|
-
##
|
|
16
|
+
## Quick start
|
|
15
17
|
|
|
16
|
-
Add a generator to `schema.prisma` and run `npx prisma generate`. `output` is required.
|
|
17
|
-
generator reads the tables and columns Prisma creates: a model or field without `@map` keeps the
|
|
18
|
-
name it has in the schema (`"Todo"`, `"authorId"`), and each ORM is told so where its own
|
|
19
|
-
convention would say otherwise.
|
|
18
|
+
Add a generator block to `schema.prisma` and run `npx prisma generate`. `output` is required.
|
|
20
19
|
|
|
21
20
|
```prisma
|
|
22
21
|
generator Hekireki-Zod {
|
|
@@ -26,65 +25,9 @@ generator Hekireki-Zod {
|
|
|
26
25
|
}
|
|
27
26
|
```
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
| `hekireki-valibot`, `hekireki-arktype`, `hekireki-effect`, `hekireki-typebox`, `hekireki-ajv` | Valibot, ArkType, Effect Schema, TypeBox, AJV | `type`, `relation` |
|
|
33
|
-
| `hekireki-pydantic` | Pydantic | `relation` |
|
|
34
|
-
| `hekireki-drizzle`, `hekireki-kysely`, `hekireki-sqlalchemy`, `hekireki-django` | Drizzle, Kysely, SQLAlchemy, Django | |
|
|
35
|
-
| `hekireki-activerecord` | Active Record | `locales` |
|
|
36
|
-
| `hekireki-gorm` | GORM | `package` |
|
|
37
|
-
| `hekireki-sea-orm` | SeaORM | `renameAll` |
|
|
38
|
-
| `hekireki-ecto` | Ecto | `app` |
|
|
39
|
-
| `hekireki-eloquent` | Eloquent | `namespace` |
|
|
40
|
-
| `hekireki-efcore` (PostgreSQL, MySQL, SQLite) | EF Core | `namespace`, `context` |
|
|
41
|
-
| `hekireki-exposed` (PostgreSQL) | Exposed | `package`, `dao` |
|
|
42
|
-
| `hekireki-atlas` | Atlas HCL | `schemaName` |
|
|
43
|
-
| `hekireki-er` | ER diagram | `outputs` (`.md`, `.dbml`, `.png`, `.svg`), `theme` |
|
|
44
|
-
| `hekireki-seed` | The schema module `hekireki.config.ts` is typed against | |
|
|
45
|
-
|
|
46
|
-
On MySQL, `hekireki-drizzle` reads and writes a `@db.Timestamp` column as UTC, and MySQL converts a
|
|
47
|
-
`TIMESTAMP` through the connection's `time_zone`: set it to `'+00:00'` on drizzle's connection, as
|
|
48
|
-
Prisma's adapter does on its own, or the two see times that differ by the offset. On CockroachDB it
|
|
49
|
-
writes the PostgreSQL schema, for node-postgres, and an `Int` key with `@default(sequence())` is an
|
|
50
|
-
identity column, as Prisma makes it; keep the session's `TimeZone` at UTC there, as on PostgreSQL,
|
|
51
|
-
for a `dbgenerated("CURRENT_TIMESTAMP")` default to be UTC.
|
|
52
|
-
|
|
53
|
-
`hekireki-atlas` writes the tables as Prisma Migrate makes them, so that `atlas schema diff`
|
|
54
|
-
against a database Prisma made has nothing to change. Its `schemaName` is `public` unless given
|
|
55
|
-
(`main` on SQLite): on MySQL, where the schema is the database, give the database's name.
|
|
56
|
-
|
|
57
|
-
`hekireki-efcore` stores a `DateTime` as Prisma Client does, whatever its `DateTimeKind`: the UTC
|
|
58
|
-
instant (a `Local` value converted), read back as `Utc`, in Prisma's text form on SQLite, and
|
|
59
|
-
`now()` filled in by EF Core rather than by the database's clock. It takes Npgsql's legacy
|
|
60
|
-
timestamp behaviour to be off. On MySQL, compare a `@db.Time` column with a parameter rather than
|
|
61
|
-
a constant: MySql.EntityFrameworkCore writes a constant `TimeSpan` as `TIME '03:04:05'`, without
|
|
62
|
-
its fraction.
|
|
63
|
-
|
|
64
|
-
`hekireki-django` keeps a `DateTime` as Prisma Client keeps it. A column without a zone is declared
|
|
65
|
-
with the `UtcDateTimeField` written into `models.py`, which stores the UTC instant (on SQLite
|
|
66
|
-
Prisma's text, `2030-01-02T03:04:05.678+00:00`) and reads it back as UTC, aware under
|
|
67
|
-
`USE_TZ = True` and in `TIME_ZONE` under `False`; a `@db.Timestamptz` is Django's own field.
|
|
68
|
-
`now()` is filled in by the model, in UTC (the UTC date or time on `@db.Date` and `@db.Time`), a
|
|
69
|
-
literal default on a date or time column is its UTC date or time, an `@updatedAt` on one stamps the
|
|
70
|
-
UTC date or time (`UtcDateField`, `UtcTimeField`) where Django's `auto_now` would take the local
|
|
71
|
-
one, and a model with `@updatedAt` is managed by `AutoNowQuerySet`, so `QuerySet.update()` bumps it
|
|
72
|
-
as `updateMany` does. Keep
|
|
73
|
-
`USE_TZ = True`, Django's default: with `False`, Django sets a PostgreSQL session to `TIME_ZONE`,
|
|
74
|
-
and a `dbgenerated()` default such as `CURRENT_TIMESTAMP` is evaluated in that zone.
|
|
75
|
-
|
|
76
|
-
`hekireki-exposed` keeps a `DateTime` as Prisma Client keeps it, with no conversion through the
|
|
77
|
-
JVM's zone: an `Instant` bound and read as the UTC instant, to the millisecond (a finer value is
|
|
78
|
-
truncated, as a JavaScript Date holds it, in every native type), the UTC date of a `@db.Date`, the
|
|
79
|
-
UTC time of a `@db.Time`, and a `@db.Timetz` at offset zero. `now()`, literal defaults and every
|
|
80
|
-
`@updatedAt` are filled in by the client on a DAO or DSL insert, and the DAO bumps `@updatedAt` on
|
|
81
|
-
update; a DSL `Table.update` has no such hook, so set it there yourself
|
|
82
|
-
(`it[updatedAt] = Instant.now()`). pgjdbc sets the session to the JVM's zone, so open the
|
|
83
|
-
connection in UTC, as Prisma's is, for a `dbgenerated("CURRENT_TIMESTAMP")` default or `now()` in
|
|
84
|
-
SQL: `Database.connect(url, setupConnection = { it.createStatement().use { s -> s.execute("SET TIME ZONE 'UTC'") } })`.
|
|
85
|
-
|
|
86
|
-
A `///` line starting with `@z.`, `@v.`, `@a.`, `@e.`, `@t.`, `@j.`, `@p.`, `@ar.` or `@ecto.` is
|
|
87
|
-
used as-is by Zod, Valibot, ArkType, Effect Schema, TypeBox, AJV, Pydantic, Active Record or Ecto:
|
|
28
|
+
A `///` comment on a field can carry a line for a validation generator, which uses it as it is.
|
|
29
|
+
The prefix says which: `@z.` Zod, `@v.` Valibot, `@a.` ArkType, `@e.` Effect Schema, `@t.`
|
|
30
|
+
TypeBox, `@j.` AJV, `@p.` Pydantic, `@ar.` Active Record, `@ecto.` Ecto.
|
|
88
31
|
|
|
89
32
|
```prisma
|
|
90
33
|
model User {
|
|
@@ -94,7 +37,64 @@ model User {
|
|
|
94
37
|
}
|
|
95
38
|
```
|
|
96
39
|
|
|
97
|
-
|
|
40
|
+
## Generators
|
|
41
|
+
|
|
42
|
+
The `provider` of the generator block picks the output. Every option is optional.
|
|
43
|
+
|
|
44
|
+
### Validation schemas
|
|
45
|
+
|
|
46
|
+
| Provider | Writes | Options |
|
|
47
|
+
| ------------------- | ------------- | ------------------------------------------------------------------- |
|
|
48
|
+
| `hekireki-zod` | Zod | `type`, `relation`, `zod` (`"v4"`, `"mini"`, `"@hono/zod-openapi"`) |
|
|
49
|
+
| `hekireki-valibot` | Valibot | `type`, `relation` |
|
|
50
|
+
| `hekireki-arktype` | ArkType | `type`, `relation` |
|
|
51
|
+
| `hekireki-effect` | Effect Schema | `type`, `relation` |
|
|
52
|
+
| `hekireki-typebox` | TypeBox | `type`, `relation` |
|
|
53
|
+
| `hekireki-ajv` | AJV | `type`, `relation` |
|
|
54
|
+
| `hekireki-pydantic` | Pydantic | `relation` |
|
|
55
|
+
|
|
56
|
+
`type` also exports the TypeScript type of each schema; `relation` adds a schema per relation.
|
|
57
|
+
|
|
58
|
+
### ORM models
|
|
59
|
+
|
|
60
|
+
| Provider | Writes | Options |
|
|
61
|
+
| ----------------------- | ----------------------------- | -------------------------------------------------- |
|
|
62
|
+
| `hekireki-drizzle` | Drizzle tables | |
|
|
63
|
+
| `hekireki-kysely` | Kysely `DB` interface | |
|
|
64
|
+
| `hekireki-sqlalchemy` | SQLAlchemy models | |
|
|
65
|
+
| `hekireki-django` | Django models | |
|
|
66
|
+
| `hekireki-activerecord` | Rails models | `locales`: directory of the translated messages |
|
|
67
|
+
| `hekireki-gorm` | GORM structs | `package` (`model`) |
|
|
68
|
+
| `hekireki-sea-orm` | SeaORM entities | `renameAll`: serde's `rename_all` |
|
|
69
|
+
| `hekireki-ecto` | Ecto schemas | `app` (`MyApp`) |
|
|
70
|
+
| `hekireki-eloquent` | Eloquent models | `namespace` (`App\Models`) |
|
|
71
|
+
| `hekireki-efcore` | EF Core entities, `DbContext` | `namespace` (`Models`), `context` (`AppDbContext`) |
|
|
72
|
+
| `hekireki-exposed` | Exposed tables | `package` (`models`), `dao` (`true`) |
|
|
73
|
+
|
|
74
|
+
Every ORM generator stores a `DateTime` as Prisma Client stores it, so the ORM and Prisma read
|
|
75
|
+
each other's rows alike.
|
|
76
|
+
|
|
77
|
+
### Database and documents
|
|
78
|
+
|
|
79
|
+
| Provider | Writes | Options |
|
|
80
|
+
| ------------------ | --------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
81
|
+
| `hekireki-atlas` | Atlas HCL | `schemaName` (`public`, `main` on SQLite) |
|
|
82
|
+
| `hekireki-openapi` | OpenAPI 3.1 (`.yaml`, `.json`) | `title`, `version`, `paths`: the CRUD of each model |
|
|
83
|
+
| `hekireki-er` | ER diagram | `outputs`: files, one per extension (`.md`, `.dbml`, `.png`, `.svg`); `theme` (`light`, `dark`) |
|
|
84
|
+
| `hekireki-seed` | Schema module for `hekireki seed` | |
|
|
85
|
+
|
|
86
|
+
`hekireki-atlas` writes the tables as Prisma Migrate makes them, so `atlas schema diff` against a
|
|
87
|
+
database Prisma made has nothing to change. `hekireki-openapi` writes them as the
|
|
88
|
+
`components.schemas` Atlas's template writes, `///` comments as descriptions; with `paths`, each
|
|
89
|
+
model gets `GET` and `POST /users` and `GET`, `PATCH` and `DELETE /users/{id}`.
|
|
90
|
+
|
|
91
|
+
Every generator keeps Prisma's names: a model or field without `@map` keeps the name it has in the
|
|
92
|
+
schema, and each ORM is told so where its own convention would say otherwise. What each generator
|
|
93
|
+
does beyond that, and what it leaves to the caller, is in
|
|
94
|
+
[docs/generators.md](https://github.com/nakita628/hekireki/blob/main/packages/hekireki/docs/generators.md).
|
|
95
|
+
Active Record and Ecto take `///` lines of their own, so they are here.
|
|
96
|
+
|
|
97
|
+
### Active Record
|
|
98
98
|
|
|
99
99
|
`hekireki-activerecord` writes `app/models` from the schema: `application_record.rb` and one model
|
|
100
100
|
per Prisma model, as a Rails developer would write them (and `prisma_date_time.rb` where a column
|
|
@@ -107,7 +107,9 @@ A `/// @ar.` line on a field is a validator (`presence`, `length(maximum: 255)`)
|
|
|
107
107
|
field's `validates`; on a model it is a Ruby line written into the class as it is
|
|
108
108
|
(`has_secure_password`, `has_many :tags, through: :post_tags`, `scope ...`). A message or name
|
|
109
109
|
given per locale, `message: { ja: "...", en: "..." }` or `@ar.name(ja: "...")`, goes to
|
|
110
|
-
`config/locales/models/<model>/<locale>.yml` under the key Rails reads.
|
|
110
|
+
`config/locales/models/<model>/<locale>.yml` under the key Rails reads. From `app/models` that
|
|
111
|
+
directory is the application's own; from anywhere else, `locales` has to name it, relative to
|
|
112
|
+
`output`.
|
|
111
113
|
|
|
112
114
|
```prisma
|
|
113
115
|
generator Hekireki-ActiveRecord {
|
|
@@ -160,55 +162,65 @@ ja:
|
|
|
160
162
|
The tables stay Prisma's to create, so set `config.active_record.migration_error = false` and
|
|
161
163
|
create the test database with `prisma migrate deploy`.
|
|
162
164
|
|
|
163
|
-
A `DateTime` is stored as Prisma Client stores it
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
165
|
+
A `DateTime` is stored as Prisma Client stores it:
|
|
166
|
+
|
|
167
|
+
- Every `@updatedAt` column is bumped, not only the one aliased to `updated_at`.
|
|
168
|
+
- A column holding fewer than three digits of a second (`@db.Timestamp(0)`, MySQL's bare
|
|
169
|
+
`@db.DateTime`) is sent Prisma's milliseconds for the database to round (`precision: 3`), where
|
|
170
|
+
Active Record would cut them off first.
|
|
171
|
+
- A `@db.Timetz` column is read as a time, not a String. Active Record still warns
|
|
172
|
+
`unknown OID 1266` once as it reads the table's columns, before the declared type takes over.
|
|
173
|
+
- On SQLite every `DateTime` column is declared with `PrismaDateTime`, which writes Prisma's text
|
|
174
|
+
(`2030-01-02T03:04:05.678+00:00`) so that comparisons, unique indexes and ordering see both
|
|
175
|
+
clients' rows alike. On SQL Server a `@db.DateTime` or `@db.SmallDateTime` column is too: it
|
|
176
|
+
sends milliseconds for the server to round to 1/300 s or to the minute as Prisma's are, where
|
|
177
|
+
the adapter would round or cut them first. The type is generated into `prisma_date_time.rb`
|
|
178
|
+
beside the models, so Zeitwerk loads it from wherever it loads them, whatever `output` is.
|
|
179
|
+
- On SQLite and SQL Server, whose `CURRENT_TIMESTAMP` is text of another shape or the server's
|
|
180
|
+
local time, `now()` is filled in by the model.
|
|
181
|
+
|
|
182
|
+
Keep `config.active_record.default_timezone` at `:utc`, Rails' default: with `:local`, a
|
|
183
|
+
`timestamp` column is written in the process's zone and Prisma reads it as UTC.
|
|
184
|
+
|
|
185
|
+
`examples/active-record` in the repository runs a fuller schema against Active Record on SQLite,
|
|
186
|
+
and is the place to read what each thing becomes.
|
|
182
187
|
|
|
183
188
|
### Ecto
|
|
184
189
|
|
|
185
190
|
`hekireki-ecto` writes one `Ecto.Schema` module per model. A model with a `/// @ecto` line on it
|
|
186
|
-
or on one of its fields also gets a `changeset/2`:
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
191
|
+
or on one of its fields also gets a `changeset/2`:
|
|
192
|
+
|
|
193
|
+
- `cast` of every field it can write;
|
|
194
|
+
- `validate_required` of the required fields Prisma gives no default;
|
|
195
|
+
- a `unique_constraint` for each `@unique` and `@@unique`;
|
|
196
|
+
- a `foreign_key_constraint` for each foreign key;
|
|
197
|
+
- a `no_assoc_constraint` for each `has_one` or `has_many` whose rows the database will not let
|
|
198
|
+
go of (`Restrict` or `NoAction` on delete, which Prisma makes of a required relation that names
|
|
199
|
+
neither), so a refused delete is an error on the association.
|
|
200
|
+
|
|
201
|
+
Each constraint is named as the database reports it: Prisma's `<table>_<columns>_key` and
|
|
202
|
+
`_fkey`, cut to the database's limit in bytes as Prisma cuts them, or the `map:` given. On SQLite
|
|
203
|
+
a unique key takes the name Ecto derives itself, and a foreign key gets no constraint, since
|
|
204
|
+
SQLite names none when it refuses a row; with `relationMode = "prisma"` there is no foreign key in
|
|
205
|
+
the database to report.
|
|
206
|
+
|
|
207
|
+
A `/// @ecto.` line on a field is an `Ecto.Changeset` function that takes the field first, written
|
|
208
|
+
without the field: `validate_length(max: 50)`, or `validate_required(message: "...")` for a
|
|
209
|
+
message of the field's own. `unique_constraint(message: "...")` on a `@unique` field and
|
|
200
210
|
`foreign_key_constraint(message: "...")` on a foreign key give the constraint its message. On a
|
|
201
211
|
relation field, `assoc_constraint` (the side with the key) puts a missing row's error on the
|
|
202
212
|
association, and `no_assoc_constraint(message: "...")` on a `has_one` or `has_many` gives a refused
|
|
203
|
-
delete its message (or asks for one where the database cascades).
|
|
204
|
-
|
|
205
|
-
a
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
213
|
+
delete its message (or asks for one where the database cascades).
|
|
214
|
+
|
|
215
|
+
On a model, a line is a step of the pipeline written as it is (`validate_confirmation(:password)`);
|
|
216
|
+
`unique_constraint([:a, :b], message: "...")` on the fields of a `@@unique` gives that constraint
|
|
217
|
+
its message; `cast(empty_values: [])` hands its options to the changeset's `cast`; and a bare
|
|
218
|
+
`/// @ecto` asks for the changeset with nothing added. With empty values of the model's own, `""`
|
|
219
|
+
is a value, as it is to the column, so the required fields are checked by a `validate_not_null`
|
|
220
|
+
written into the module, which counts only `nil` as missing (`validate_required` would count `""`
|
|
221
|
+
too); a field's own `validate_required` line keeps Ecto's meaning. Ecto has no association for a
|
|
222
|
+
foreign key of several columns, so the constraints of one are `foreign_key_constraint`s with the
|
|
223
|
+
error on the relation's name.
|
|
212
224
|
|
|
213
225
|
```prisma
|
|
214
226
|
model User {
|
|
@@ -242,51 +254,16 @@ the module's documentation names the session time zone a `@db.Timestamptz`, `@db
|
|
|
242
254
|
|
|
243
255
|
`examples/ecto` in the repository runs a schema against Ecto on SQLite.
|
|
244
256
|
|
|
245
|
-
### Kysely
|
|
246
|
-
|
|
247
|
-
`hekireki-kysely` writes one `DB` interface, each column typed as the driver of the datasource
|
|
248
|
-
reads and binds it: better-sqlite3 on SQLite, pg on PostgreSQL, mysql2 on MySQL. Kysely converts
|
|
249
|
-
nothing and runs no hook, so what the types cannot say is the caller's:
|
|
250
|
-
|
|
251
|
-
- On SQLite a `DateTime` is text, compared as text: write it as Prisma does,
|
|
252
|
-
`date.toISOString().replace('Z', '+00:00')`, or `=`, `@unique` and `@@id` do not meet Prisma's
|
|
253
|
-
rows. A `DateTime` with `now()` or a literal default is asked for on insert there, as Prisma
|
|
254
|
-
Client writes it itself: SQLite's own default is other text (`CURRENT_TIMESTAMP` sorts before
|
|
255
|
-
Prisma's rows, and Prisma reads the literal as an Invalid Date).
|
|
256
|
-
- pg and mysql2 read a column without a zone in the process's zone, Prisma in UTC: set pg's type
|
|
257
|
-
parsers 1114, 1082, 1115 and 1182 to UTC with `pg.defaults.parseInputDatesAsUTC = true`, and
|
|
258
|
-
give mysql2 `timezone: 'Z'`. MySQL refuses ISO text with a `Z`; write a `Date`
|
|
259
|
-
or MySQL's `2030-01-02 03:04:05.678901`.
|
|
260
|
-
- `@db.Time` and `@db.Timetz` are `string`, the time of day the drivers read.
|
|
261
|
-
- `@updatedAt` is asked for on insert, optional or not, and must be set on every update.
|
|
262
|
-
|
|
263
|
-
`examples/kysely` in the repository runs a schema against Kysely on SQLite.
|
|
264
|
-
|
|
265
|
-
### SeaORM
|
|
266
|
-
|
|
267
|
-
`hekireki-sea-orm` writes one entity per model into a directory, with a `mod.rs` and a
|
|
268
|
-
`prelude.rs`. A `DateTime` is kept as Prisma Client keeps it:
|
|
269
|
-
|
|
270
|
-
- `now()`, `@updatedAt` and a literal default are filled by `ActiveModelBehavior::before_save`, in
|
|
271
|
-
UTC with milliseconds, so the crate needs `chrono` and `async-trait` beside `sea-orm`.
|
|
272
|
-
- On SQLite every `DateTime` is a `PrismaDateTime` (written into `prisma_date_time.rs`), which
|
|
273
|
-
binds Prisma's text, `2030-01-02T03:04:05.000+00:00`: filter with
|
|
274
|
-
`Column::At.eq(PrismaDateTime(instant))`, not a bare `DateTimeUtc`, which sqlx writes without
|
|
275
|
-
the `.000` of a whole second.
|
|
276
|
-
- On PostgreSQL and MySQL a `DateTime` is a `NaiveDateTime` in UTC, `@db.Timestamptz` a
|
|
277
|
-
`DateTimeWithTimeZone`, a MySQL `@db.Timestamp` a `DateTimeUtc`. `@db.Timetz` is refused: sqlx
|
|
278
|
-
has no type to read it into.
|
|
279
|
-
|
|
280
|
-
`examples/sea-orm` in the repository runs a schema against SeaORM on SQLite, PostgreSQL and MySQL.
|
|
281
|
-
|
|
282
257
|
## Studio
|
|
283
258
|
|
|
284
259
|
```bash
|
|
285
|
-
npx hekireki studio
|
|
260
|
+
npx hekireki studio
|
|
286
261
|
npx hekireki studio --url file:./dev.db
|
|
287
262
|
```
|
|
288
263
|
|
|
289
|
-
Your schema and database in the browser, on SQLite, PostgreSQL and MySQL.
|
|
264
|
+
Your schema and database in the browser, on SQLite, PostgreSQL and MySQL. Without flags, Studio
|
|
265
|
+
reads the `schema` of `prisma.config.ts`, else `./prisma/schema.prisma` or `./schema.prisma`, and
|
|
266
|
+
listens on port 5555.
|
|
290
267
|
|
|
291
268
|
**Browse the rows** of each model: search, add, edit and export them.
|
|
292
269
|
|
|
@@ -316,6 +293,9 @@ npx hekireki seed # Through the project's Prisma Client
|
|
|
316
293
|
npx hekireki seed --sql seed.sql # Or as a SQL script
|
|
317
294
|
```
|
|
318
295
|
|
|
296
|
+
The `hekireki-seed` generator writes a schema module; `hekireki.config.ts` imports it and is typed
|
|
297
|
+
against it, so each model's fields are known as the config is written.
|
|
298
|
+
|
|
319
299
|
```ts
|
|
320
300
|
// hekireki.config.ts
|
|
321
301
|
import { defineConfig } from 'hekireki'
|
package/dist/bin/activerecord.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as registerGenerator } from "../bin-
|
|
3
|
-
|
|
2
|
+
import { t as registerGenerator } from "../bin-CVNnCHYf.js";
|
|
3
|
+
// src/bin/activerecord.ts
|
|
4
4
|
registerGenerator("activerecord");
|
|
5
|
-
//#endregion
|
|
6
5
|
export {};
|
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
package/dist/bin/efcore.js
CHANGED
package/dist/bin/effect.js
CHANGED
package/dist/bin/eloquent.js
CHANGED
package/dist/bin/er.js
CHANGED
package/dist/bin/exposed.js
CHANGED
package/dist/bin/gorm.js
CHANGED
package/dist/bin/hekireki.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { s as readFile, t as exists } from "../file-
|
|
2
|
+
import { s as readFile, t as exists } from "../file-BAVQ-zst.js";
|
|
3
3
|
import { runMain } from "@effect/platform-node/NodeRuntime";
|
|
4
4
|
import { layer } from "@effect/platform-node/NodeServices";
|
|
5
5
|
import { Console, Data, Effect, Schema } from "effect";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { CliError, Command, Flag } from "effect/cli";
|
|
8
|
-
|
|
9
|
-
var version = "0.
|
|
10
|
-
|
|
11
|
-
//#region src/schema/path.ts
|
|
8
|
+
// package.json
|
|
9
|
+
var version = "0.40.0";
|
|
10
|
+
// src/schema/path.ts
|
|
12
11
|
/** Where Prisma looks for a schema when neither the command nor prisma.config.ts names one. */
|
|
13
12
|
const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
|
|
14
13
|
const CONFIG_EXTENSIONS = [
|
|
@@ -64,8 +63,7 @@ function prismaSchemaPath(dir) {
|
|
|
64
63
|
return null;
|
|
65
64
|
});
|
|
66
65
|
}
|
|
67
|
-
|
|
68
|
-
//#region src/studio/server/constants/index.ts
|
|
66
|
+
// src/studio/server/constants/index.ts
|
|
69
67
|
/** Studio only listens on loopback: the API serves the raw schema and runs SQL without authentication. */
|
|
70
68
|
const STUDIO_HOSTNAME = "127.0.0.1";
|
|
71
69
|
const DEFAULT_PORT = 5555;
|
|
@@ -76,8 +74,7 @@ const SSE_PING_MS = 15e3;
|
|
|
76
74
|
const PRISMA_FILE_URI = "file:///schema.prisma";
|
|
77
75
|
/** How often the migrations directory is read for a change. */
|
|
78
76
|
const MIGRATIONS_POLL_MS = 1e3;
|
|
79
|
-
|
|
80
|
-
//#region src/studio/server/errors/index.ts
|
|
77
|
+
// src/studio/server/errors/index.ts
|
|
81
78
|
var UnknownModelError = class extends Data.TaggedError("UnknownModelError") {};
|
|
82
79
|
var UnknownFileError = class extends Data.TaggedError("UnknownFileError") {};
|
|
83
80
|
var FileWriteError = class extends Data.TaggedError("FileWriteError") {};
|
|
@@ -91,8 +88,7 @@ var ContractViolationError = class extends Data.TaggedError("ContractViolationEr
|
|
|
91
88
|
var SchemaLoadError = class extends Data.TaggedError("SchemaLoadError") {};
|
|
92
89
|
var SchemaParseError = class extends Data.TaggedError("SchemaParseError") {};
|
|
93
90
|
var ServerListenError = class extends Data.TaggedError("ServerListenError") {};
|
|
94
|
-
|
|
95
|
-
//#region src/cli/index.ts
|
|
91
|
+
// src/cli/index.ts
|
|
96
92
|
const COMMAND_NAME = "hekireki";
|
|
97
93
|
const STATIC_DIR = path.resolve(import.meta.dirname, "../studio");
|
|
98
94
|
const DatabaseUrl = Schema.String.pipe(Schema.check(Schema.isPattern(/^(?:postgres|postgresql|mysql|file):/u, { message: "a postgres://, postgresql://, mysql:// or file: connection string" })));
|
|
@@ -140,7 +136,7 @@ const studioFlags = {
|
|
|
140
136
|
function runStudio(args) {
|
|
141
137
|
return Effect.gen(function* () {
|
|
142
138
|
const schemaPath = yield* resolveSchemaPath(args.schema, [COMMAND_NAME, "studio"]);
|
|
143
|
-
const { startStudioServer } = yield* Effect.promise(() => import("../start-
|
|
139
|
+
const { startStudioServer } = yield* Effect.promise(() => import("../start-9gS-ABI-.js"));
|
|
144
140
|
const started = yield* startStudioServer({
|
|
145
141
|
schemaPath,
|
|
146
142
|
port: args.port,
|
|
@@ -188,7 +184,7 @@ const seedFlags = {
|
|
|
188
184
|
};
|
|
189
185
|
function runSeedCommand(args) {
|
|
190
186
|
return Effect.gen(function* () {
|
|
191
|
-
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-
|
|
187
|
+
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-Be-2eG1y.js"));
|
|
192
188
|
const report = yield* runSeed(args, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
193
189
|
yield* Console.log(seedBanner(report));
|
|
194
190
|
});
|
|
@@ -231,7 +227,7 @@ function runMigrateCheckCommand(args) {
|
|
|
231
227
|
"migrate",
|
|
232
228
|
"check"
|
|
233
229
|
]);
|
|
234
|
-
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-
|
|
230
|
+
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-BhCE-YSd.js"));
|
|
235
231
|
const report = yield* runMigrateCheck({
|
|
236
232
|
...args,
|
|
237
233
|
schemaPath,
|
|
@@ -278,7 +274,7 @@ function runMigratePlanCommand(args) {
|
|
|
278
274
|
"migrate",
|
|
279
275
|
"plan"
|
|
280
276
|
]);
|
|
281
|
-
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-
|
|
277
|
+
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-BhCE-YSd.js"));
|
|
282
278
|
const report = yield* runMigrateCheck({
|
|
283
279
|
...args,
|
|
284
280
|
schemaPath,
|
|
@@ -335,8 +331,6 @@ function cli() {
|
|
|
335
331
|
function hekireki() {
|
|
336
332
|
return Command.run(cli(), { version });
|
|
337
333
|
}
|
|
338
|
-
|
|
339
|
-
//#region src/bin/hekireki.ts
|
|
334
|
+
// src/bin/hekireki.ts
|
|
340
335
|
runMain(hekireki().pipe(Effect.provide(layer)));
|
|
341
|
-
//#endregion
|
|
342
336
|
export { SSE_PING_MS as _, DatabaseUnavailableError as a, prismaSchemaPath as b, InvalidInputError as c, ServerListenError as d, UnknownFileError as f, PRISMA_FILE_URI as g, MIGRATIONS_POLL_MS as h, DatabaseError as i, SchemaLoadError as l, FORBIDDEN_HOST_MESSAGE as m, ClientUnavailableError as n, FileWriteError as o, UnknownModelError as p, ContractViolationError as r, FormatError as s, ClientQueryError as t, SchemaParseError as u, STUDIO_HOSTNAME as v, readPrismaConfig as x, DEFAULT_SCHEMA_PATHS as y };
|
package/dist/bin/kysely.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/bin/pydantic.js
CHANGED
package/dist/bin/sea-orm.js
CHANGED