hekireki 0.32.0 → 0.33.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 +168 -11
- 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.js +1 -1
- package/dist/bin/effect.js +1 -1
- package/dist/bin/eloquent.js +1 -1
- package/dist/bin/er.js +1 -1
- package/dist/bin/exposed.js +1 -1
- package/dist/bin/gorm.js +1 -1
- package/dist/bin/hekireki.js +51 -75
- 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/seed.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-CmwdzyIR.js → bin-BedDciI4.js} +4115 -1204
- package/dist/{discover-DVB1eehy.js → discover-C_OWaNiu.js} +1 -1
- package/dist/{emit-CdFQK71O.js → emit-BeblTVH8.js} +2 -2
- package/dist/{file-BPNqvwXD.js → file-Df9ykHXv.js} +1 -5
- package/dist/{migrate-B10ui4rh.js → migrate-CvfrvM4u.js} +4 -4
- package/dist/{plan-BDkcp2gn.js → plan-dRHRS5pw.js} +11 -8
- package/dist/{run-DhCGgShc.js → run-BKGjRYpT.js} +7 -8
- package/dist/{schema-B-2ni3YF.js → schema-RYU_i7qd.js} +2 -2
- package/dist/{sql-Bb3cwfJt.js → sql-MFsOi3_t.js} +3 -3
- package/dist/{start-BhcpaMcT.js → start-Crxh2c9d.js} +14 -17
- package/dist/studio/assets/{client-Cml1DF4R.js → client-DjOVdm86.js} +1 -1
- package/dist/studio/assets/{code-block-ON7BoQW2.js → code-block-Bo0pcw3d.js} +1 -1
- package/dist/studio/assets/{confirm-dialog-IdKC4Tr2.js → confirm-dialog-BQVcIkfP.js} +1 -1
- package/dist/studio/assets/{copy-D3Vc_bt4.js → copy-DVfEjDPw.js} +1 -1
- package/dist/studio/assets/{copy-button-CbaXuxba.js → copy-button-Di-sHQ2O.js} +1 -1
- package/dist/studio/assets/{dist-DmM7_t8o.js → dist-CebhqUaX.js} +5 -5
- package/dist/studio/assets/{docs-ExwrGDZu.js → docs-BpQXqPH3.js} +1 -1
- package/dist/studio/assets/{enums._name-C9BGV9--.js → enums._name-BufcpUnz.js} +1 -1
- package/dist/studio/assets/{index-ClVBmPHO.js → index-CXzs-Au7.js} +4 -4
- package/dist/studio/assets/{labels-C7nHuKvb.js → labels-DuphOVul.js} +1 -1
- package/dist/studio/assets/{lazyRouteComponent-CDmLrXMS.js → lazyRouteComponent-tS2t_LrD.js} +1 -1
- package/dist/studio/assets/{lu-BrVGIhAn.js → lu-cVORv6D3.js} +1 -1
- package/dist/studio/assets/{marked-text-BRnsKz9k.js → marked-text-DtpHRSKt.js} +1 -1
- package/dist/studio/assets/{models._name-ByPeXRmm.js → models._name-BNMTjU6P.js} +1 -1
- package/dist/studio/assets/{prisma-BnoDMkaK.js → prisma-CBc_VcSl.js} +1 -1
- package/dist/studio/assets/{result-table-CpErC1Pk.js → result-table-CrTPC-aR.js} +1 -1
- package/dist/studio/assets/{routes-CKzRT8uT.js → routes-B3m6jQHR.js} +1 -1
- package/dist/studio/assets/{schema-gate-B50_6S0h.js → schema-gate-BC3i18Tp.js} +1 -1
- package/dist/studio/assets/{schema-view-fqeCWRR2.js → schema-view-C427B7Jc.js} +1 -1
- package/dist/studio/assets/{sql-CRhtXB4v.js → sql-B3t2pCf4.js} +1 -1
- package/dist/studio/assets/{table-Rze42PM3.js → table-bAwthXaP.js} +1 -1
- package/dist/studio/assets/{tabs-ClImdGQ1.js → tabs-Bj63lLvK.js} +1 -1
- package/dist/studio/assets/{useFormValidation-Bgjs6o3Q.js → useFormValidation-B7STfHY3.js} +1 -1
- package/dist/studio/assets/{useMultipleSelectionState-DUiRXMUh.js → useMultipleSelectionState-vASeYbQk.js} +1 -1
- package/dist/studio/assets/{useOverlayTriggerState-2DwfYtnL.js → useOverlayTriggerState-BO95y8NP.js} +1 -1
- package/dist/studio/index.html +6 -6
- package/dist/{utils-Cgi66Lfo.js → utils-ckthTWS0.js} +38 -2
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -30,21 +30,61 @@ generator Hekireki-Zod {
|
|
|
30
30
|
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
31
31
|
| `hekireki-zod` | [Zod](https://zod.dev/) | `type`, `comment`, `relation`, `zod` (`"v4"`, `"mini"`, `"@hono/zod-openapi"`) |
|
|
32
32
|
| `hekireki-valibot`, `hekireki-arktype`, `hekireki-effect`, `hekireki-typebox`, `hekireki-ajv` | Valibot, ArkType, Effect Schema, TypeBox, AJV | `type`, `comment`, `relation` |
|
|
33
|
-
| `hekireki-pydantic` | Pydantic | `
|
|
33
|
+
| `hekireki-pydantic` | Pydantic | `relation` |
|
|
34
34
|
| `hekireki-drizzle`, `hekireki-kysely`, `hekireki-sqlalchemy`, `hekireki-django` | Drizzle, Kysely, SQLAlchemy, Django | |
|
|
35
35
|
| `hekireki-activerecord` | Active Record | `locales` |
|
|
36
36
|
| `hekireki-gorm` | GORM | `package` |
|
|
37
37
|
| `hekireki-sea-orm` | SeaORM | `renameAll` |
|
|
38
38
|
| `hekireki-ecto` | Ecto | `app` |
|
|
39
39
|
| `hekireki-eloquent` | Eloquent | `namespace` |
|
|
40
|
-
| `hekireki-efcore` (PostgreSQL)
|
|
40
|
+
| `hekireki-efcore` (PostgreSQL, MySQL, SQLite) | EF Core | `namespace`, `context` |
|
|
41
41
|
| `hekireki-exposed` (PostgreSQL) | Exposed | `package`, `dao` |
|
|
42
|
-
| `hekireki-atlas` | Atlas HCL | `schemaName
|
|
42
|
+
| `hekireki-atlas` | Atlas HCL | `schemaName` |
|
|
43
43
|
| `hekireki-er` | ER diagram | `outputs` (`.md`, `.dbml`, `.png`, `.svg`), `theme` |
|
|
44
44
|
| `hekireki-seed` | The schema module `hekireki.config.ts` is typed against | |
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
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:
|
|
48
88
|
|
|
49
89
|
```prisma
|
|
50
90
|
model User {
|
|
@@ -57,11 +97,11 @@ model User {
|
|
|
57
97
|
### Rails
|
|
58
98
|
|
|
59
99
|
`hekireki-activerecord` writes `app/models` from the schema: `application_record.rb` and one model
|
|
60
|
-
per Prisma model, as a Rails developer would write them
|
|
61
|
-
(`table_name`, `class_name`, `foreign_key`,
|
|
62
|
-
is left unsaid; what the schema promises is
|
|
63
|
-
|
|
64
|
-
`uniqueness`, `length`).
|
|
100
|
+
per Prisma model, as a Rails developer would write them (and `prisma_date_time.rb` where a column
|
|
101
|
+
needs it). What Rails works out on its own (`table_name`, `class_name`, `foreign_key`,
|
|
102
|
+
`inverse_of` where the names follow its conventions) is left unsaid; what the schema promises is
|
|
103
|
+
written: `attribute` defaults, `enum`, timestamps, associations with `dependent:` from `onDelete`,
|
|
104
|
+
and validations from the columns (`presence`, `uniqueness`, `length`).
|
|
65
105
|
|
|
66
106
|
A `/// @ar.` line on a field is a validator (`presence`, `length(maximum: 255)`) added to that
|
|
67
107
|
field's `validates`; on a model it is a Ruby line written into the class as it is
|
|
@@ -118,10 +158,127 @@ ja:
|
|
|
118
158
|
```
|
|
119
159
|
|
|
120
160
|
The tables stay Prisma's to create, so set `config.active_record.migration_error = false` and
|
|
121
|
-
create the test database with `prisma migrate deploy`.
|
|
161
|
+
create the test database with `prisma migrate deploy`.
|
|
162
|
+
|
|
163
|
+
A `DateTime` is stored as Prisma Client stores it. Every `@updatedAt` column is bumped, not only
|
|
164
|
+
the one aliased to `updated_at`. A column holding fewer than three digits of a second
|
|
165
|
+
(`@db.Timestamp(0)`, MySQL's bare `@db.DateTime`) is sent Prisma's milliseconds for the database
|
|
166
|
+
to round (`precision: 3`), where Active Record would cut them off first; a `@db.Timetz` column is
|
|
167
|
+
read as a time, not a String (Active Record still warns `unknown OID 1266` once as it reads the
|
|
168
|
+
table's columns, before the declared type takes over). On SQLite every `DateTime` column is
|
|
169
|
+
declared with `PrismaDateTime`, which writes Prisma's text (`2030-01-02T03:04:05.678+00:00`) so
|
|
170
|
+
that comparisons, unique indexes and ordering see both clients' rows alike; on SQL Server a
|
|
171
|
+
`@db.DateTime` or `@db.SmallDateTime` column is, which sends milliseconds for the server to round
|
|
172
|
+
to 1/300 s or to the minute as Prisma's are, where the adapter would round or cut them first. It is
|
|
173
|
+
generated into `prisma_date_time.rb` beside the models, so Zeitwerk loads it from wherever it
|
|
174
|
+
loads them, whatever `output` is. On SQLite and SQL Server, whose `CURRENT_TIMESTAMP` is text of
|
|
175
|
+
another shape or the server's local time, `now()` is filled in by the model. Keep
|
|
176
|
+
`config.active_record.default_timezone` at `:utc`, Rails' default: with `:local`, a `timestamp`
|
|
177
|
+
column is written in the process's zone and Prisma reads it as UTC.
|
|
178
|
+
|
|
179
|
+
`examples/active-record` in the repository
|
|
122
180
|
runs a fuller schema against Active Record on SQLite, and is the place to read what each thing
|
|
123
181
|
becomes.
|
|
124
182
|
|
|
183
|
+
### Ecto
|
|
184
|
+
|
|
185
|
+
`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`: `cast` of every field it can write,
|
|
187
|
+
`validate_required` of the required fields Prisma gives no default, a `unique_constraint` for each
|
|
188
|
+
`@unique` and `@@unique`, a `foreign_key_constraint` for each foreign key, and a
|
|
189
|
+
`no_assoc_constraint` for each `has_one` or `has_many` whose rows the database will not let go of
|
|
190
|
+
(`Restrict` or `NoAction` on delete, which Prisma makes of a required relation that names neither),
|
|
191
|
+
so a refused delete is an error on the association. Each constraint is
|
|
192
|
+
named as the database reports it: Prisma's `<table>_<columns>_key` and `_fkey`, cut to the
|
|
193
|
+
database's limit in bytes as Prisma cuts them, or the `map:` given. On SQLite a unique key takes
|
|
194
|
+
the name Ecto derives itself, and a foreign key gets no constraint, since SQLite names none when it
|
|
195
|
+
refuses a row; with `relationMode = "prisma"` there is no foreign key in the database to report.
|
|
196
|
+
|
|
197
|
+
A `/// @ecto.` line on a field is an `Ecto.Changeset` function that takes the field first, without
|
|
198
|
+
the field: `validate_length(max: 50)`, or `validate_required(message: "...")` for a message of the
|
|
199
|
+
field's own. `unique_constraint(message: "...")` on a `@unique` field and
|
|
200
|
+
`foreign_key_constraint(message: "...")` on a foreign key give the constraint its message. On a
|
|
201
|
+
relation field, `assoc_constraint` (the side with the key) puts a missing row's error on the
|
|
202
|
+
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). On a model a line is a step of the pipeline written as it is
|
|
204
|
+
(`validate_confirmation(:password)`), `unique_constraint([:a, :b], message: "...")` on the fields of
|
|
205
|
+
a `@@unique` gives that constraint its message, `cast(empty_values: [])` hands its options to the
|
|
206
|
+
changeset's `cast`, and a bare `/// @ecto` asks for the changeset with nothing added. With empty
|
|
207
|
+
values of the model's own, `""` is a value, as it is to the column, so the required fields are
|
|
208
|
+
checked by a `validate_not_null` written into the module, which counts only `nil` as missing
|
|
209
|
+
(`validate_required` would count `""` too); a field's own `validate_required` line keeps Ecto's
|
|
210
|
+
meaning. Ecto has no association for a foreign key of several columns, so the constraints of one
|
|
211
|
+
are `foreign_key_constraint`s with the error on the relation's name.
|
|
212
|
+
|
|
213
|
+
```prisma
|
|
214
|
+
model User {
|
|
215
|
+
id Int @id @default(autoincrement())
|
|
216
|
+
/// @ecto.validate_required(message: "名前を入力してください")
|
|
217
|
+
/// @ecto.validate_length(max: 50, message: "%{count}文字以内で入力してください")
|
|
218
|
+
name String
|
|
219
|
+
age Int?
|
|
220
|
+
email String? @unique
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```elixir
|
|
225
|
+
def changeset(user, attrs) do
|
|
226
|
+
user
|
|
227
|
+
|> cast(attrs, [:name, :age, :email])
|
|
228
|
+
|> validate_required([:name], message: "名前を入力してください")
|
|
229
|
+
|> validate_length(:name, max: 50, message: "%{count}文字以内で入力してください")
|
|
230
|
+
|> unique_constraint(:email, name: "User_email_key")
|
|
231
|
+
end
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
A `DateTime` is kept as Prisma Client keeps it, through modules written alongside the schemas:
|
|
235
|
+
`PrismaDateTime` holds the instant in UTC in milliseconds (on SQLite the text Prisma writes,
|
|
236
|
+
`2030-01-01T09:00:00.000+00:00`, so an equality or a range finds Prisma's rows), `PrismaDate` a
|
|
237
|
+
`@db.Date` and `PrismaTime` a `@db.Time` or `@db.Timetz`. `now()` and `@updatedAt` are
|
|
238
|
+
`timestamps()` calls of those types. An optional `@updatedAt` is stored as null on insert only when
|
|
239
|
+
given by `Ecto.Changeset.force_change/3`, as a struct's `nil` is no change. On PostgreSQL and MySQL
|
|
240
|
+
the module's documentation names the session time zone a `@db.Timestamptz`, `@db.Timetz` or
|
|
241
|
+
`TIMESTAMP` column needs.
|
|
242
|
+
|
|
243
|
+
`examples/ecto` in the repository runs a schema against Ecto on SQLite.
|
|
244
|
+
|
|
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
|
+
|
|
125
282
|
## Studio
|
|
126
283
|
|
|
127
284
|
```bash
|
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
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,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as exists } from "../file-
|
|
2
|
+
import { t as exists } from "../file-Df9ykHXv.js";
|
|
3
3
|
import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
4
|
-
import { Console, Data, Effect,
|
|
5
|
-
import path from "node:path";
|
|
4
|
+
import { Console, Data, Effect, Schema } from "effect";
|
|
6
5
|
import { CliError, Command, Flag } from "effect/unstable/cli";
|
|
6
|
+
import path from "node:path";
|
|
7
7
|
//#region package.json
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.33.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. */
|
|
@@ -34,12 +34,10 @@ var SchemaLoadError = class extends Data.TaggedError("SchemaLoadError") {};
|
|
|
34
34
|
var SchemaParseError = class extends Data.TaggedError("SchemaParseError") {};
|
|
35
35
|
var ServerListenError = class extends Data.TaggedError("ServerListenError") {};
|
|
36
36
|
//#endregion
|
|
37
|
-
//#region src/cli/constants.ts
|
|
38
|
-
/** Where `--schema` looks when it is omitted, in order. */
|
|
39
|
-
const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
|
|
40
|
-
//#endregion
|
|
41
37
|
//#region src/cli/index.ts
|
|
42
38
|
const COMMAND_NAME = "hekireki";
|
|
39
|
+
/** Where `--schema` looks when it is omitted, in order. */
|
|
40
|
+
const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
|
|
43
41
|
const STATIC_DIR = path.resolve(import.meta.dirname, "../studio");
|
|
44
42
|
const DatabaseUrl = Schema.String.pipe(Schema.check(Schema.isPattern(/^(?:postgres|postgresql|mysql|file):/u, { message: "a postgres://, postgresql://, mysql:// or file: connection string" })));
|
|
45
43
|
/**
|
|
@@ -76,18 +74,18 @@ const Port = Schema.Int.check(Schema.isBetween({
|
|
|
76
74
|
}));
|
|
77
75
|
const studioFlags = {
|
|
78
76
|
port: Flag.Int("port").pipe(Flag.withAlias("p"), Flag.withSchema(Port), Flag.withDescription(`Port to listen on (default: ${DEFAULT_PORT})`), Flag.withMetavar("port"), Flag.withDefault(DEFAULT_PORT)),
|
|
79
|
-
schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to schema.prisma or a directory of .prisma files (default: ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.
|
|
80
|
-
url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL for browsing and editing data (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.
|
|
77
|
+
schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to schema.prisma or a directory of .prisma files (default: ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.withDefault(null)),
|
|
78
|
+
url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL for browsing and editing data (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.withDefault(null))
|
|
81
79
|
};
|
|
82
80
|
function runStudio(args) {
|
|
83
81
|
return Effect.gen(function* () {
|
|
84
|
-
const schemaPath = yield* resolveSchemaPath(
|
|
85
|
-
const { startStudioServer } = yield* Effect.promise(() => import("../start-
|
|
82
|
+
const schemaPath = yield* resolveSchemaPath(args.schema, [COMMAND_NAME, "studio"]);
|
|
83
|
+
const { startStudioServer } = yield* Effect.promise(() => import("../start-Crxh2c9d.js"));
|
|
86
84
|
const started = yield* startStudioServer({
|
|
87
85
|
schemaPath,
|
|
88
86
|
port: args.port,
|
|
89
87
|
staticDir: STATIC_DIR,
|
|
90
|
-
databaseUrl:
|
|
88
|
+
databaseUrl: args.url
|
|
91
89
|
}).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error instanceof ServerListenError && error.code === "EADDRINUSE" ? `Port ${error.port} is already in use. Pass -p <port> to use another port.` : error.message })));
|
|
92
90
|
yield* Console.log(studioBanner({
|
|
93
91
|
port: args.port,
|
|
@@ -117,28 +115,19 @@ const studio = Command.make("studio", studioFlags, runStudio).pipe(Command.withD
|
|
|
117
115
|
}
|
|
118
116
|
]));
|
|
119
117
|
const seedFlags = {
|
|
120
|
-
config: Flag.String("config").pipe(Flag.withAlias("c"), Flag.withDescription("Path to the config, a TypeScript file (default: hekireki.config.ts in the working directory)"), Flag.withMetavar("hekireki.config.ts"), Flag.
|
|
121
|
-
schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to schema.prisma or a directory of .prisma files (default: \`schema\` in the config, then ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.
|
|
122
|
-
url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL to insert into (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.
|
|
123
|
-
|
|
124
|
-
seed: Flag.Int("seed").pipe(Flag.withDescription("The faker seed; the same seed always gives the same rows (left out: every run differs)"), Flag.withMetavar("n"), Flag.
|
|
125
|
-
count: Flag.Int("count").pipe(Flag.withAlias("n"), Flag.withDescription("Rows for every faker model, over the per-model counts of the config; models given as data keep their rows (left out: the config decides, and only the configured models are seeded)"), Flag.withMetavar("rows"), Flag.
|
|
126
|
-
locale: Flag.String("locale").pipe(Flag.withAlias("l"), Flag.withDescription("Faker locale, or a comma-separated list tried in order (left out: faker's English)"), Flag.withMetavar("ja,en"), Flag.
|
|
118
|
+
config: Flag.String("config").pipe(Flag.withAlias("c"), Flag.withDescription("Path to the config, a TypeScript file (default: hekireki.config.ts in the working directory)"), Flag.withMetavar("hekireki.config.ts"), Flag.withDefault(null)),
|
|
119
|
+
schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to schema.prisma or a directory of .prisma files (default: \`schema\` in the config, then ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.withDefault(null)),
|
|
120
|
+
url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL to insert into (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.withDefault(null)),
|
|
121
|
+
output: Flag.String("sql").pipe(Flag.withDescription("Write the rows to this SQL file instead of inserting them"), Flag.withMetavar("seed.sql"), Flag.withDefault(null)),
|
|
122
|
+
seed: Flag.Int("seed").pipe(Flag.withDescription("The faker seed; the same seed always gives the same rows (left out: every run differs)"), Flag.withMetavar("n"), Flag.withDefault(null)),
|
|
123
|
+
count: Flag.Int("count").pipe(Flag.withAlias("n"), Flag.withDescription("Rows for every faker model, over the per-model counts of the config; models given as data keep their rows (left out: the config decides, and only the configured models are seeded)"), Flag.withMetavar("rows"), Flag.withDefault(null)),
|
|
124
|
+
locale: Flag.String("locale").pipe(Flag.withAlias("l"), Flag.withDescription("Faker locale, or a comma-separated list tried in order (left out: faker's English)"), Flag.withMetavar("ja,en"), Flag.withDefault(null)),
|
|
127
125
|
reset: Flag.Boolean("reset").pipe(Flag.withDescription("Delete every row of the seeded tables before inserting"), Flag.withDefault(false))
|
|
128
126
|
};
|
|
129
127
|
function runSeedCommand(args) {
|
|
130
128
|
return Effect.gen(function* () {
|
|
131
|
-
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-
|
|
132
|
-
const report = yield* runSeed({
|
|
133
|
-
config: Option.getOrNull(args.config),
|
|
134
|
-
schema: Option.getOrNull(args.schema),
|
|
135
|
-
url: Option.getOrNull(args.url),
|
|
136
|
-
output: Option.getOrNull(args.sql),
|
|
137
|
-
seed: Option.getOrNull(args.seed),
|
|
138
|
-
count: Option.getOrNull(args.count),
|
|
139
|
-
locale: Option.getOrNull(args.locale),
|
|
140
|
-
reset: args.reset
|
|
141
|
-
}, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
129
|
+
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-BKGjRYpT.js"));
|
|
130
|
+
const report = yield* runSeed(args, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
142
131
|
yield* Console.log(seedBanner(report));
|
|
143
132
|
});
|
|
144
133
|
}
|
|
@@ -161,36 +150,30 @@ const seed = Command.make("seed", seedFlags, runSeedCommand).pipe(Command.withDe
|
|
|
161
150
|
}
|
|
162
151
|
]));
|
|
163
152
|
const migrateCheckFlags = {
|
|
164
|
-
schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to the schema about to be migrated: schema.prisma or a directory of .prisma files (default: ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.
|
|
165
|
-
url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL to check, read only (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.
|
|
166
|
-
decisions: Flag.String("decisions").pipe(Flag.withAlias("d"), Flag.withDescription("Path to the decisions made on the Migrate page of `hekireki studio`: what becomes of the rows that stand in the way (default: .hekireki/migrate.json beside the schema)"), Flag.withMetavar("migrate.json"), Flag.
|
|
167
|
-
timeout: Flag.Int("timeout").pipe(Flag.withDescription("How long one query may run, in milliseconds, on PostgreSQL and MySQL (default: no limit)"), Flag.withMetavar("ms"), Flag.
|
|
153
|
+
schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to the schema about to be migrated: schema.prisma or a directory of .prisma files (default: ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.withDefault(null)),
|
|
154
|
+
url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL to check, read only (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.withDefault(null)),
|
|
155
|
+
decisions: Flag.String("decisions").pipe(Flag.withAlias("d"), Flag.withDescription("Path to the decisions made on the Migrate page of `hekireki studio`: what becomes of the rows that stand in the way (default: .hekireki/migrate.json beside the schema)"), Flag.withMetavar("migrate.json"), Flag.withDefault(null)),
|
|
156
|
+
timeout: Flag.Int("timeout").pipe(Flag.withDescription("How long one query may run, in milliseconds, on PostgreSQL and MySQL (default: no limit)"), Flag.withMetavar("ms"), Flag.withDefault(null)),
|
|
168
157
|
json: Flag.Boolean("json").pipe(Flag.withDescription("Print the report as JSON, every check with its count and SQL"), Flag.withDefault(false))
|
|
169
158
|
};
|
|
170
|
-
/** The command line of `migrate check` as the runner reads it. */
|
|
171
|
-
function migrateInput(args, schemaPath) {
|
|
172
|
-
return {
|
|
173
|
-
schemaPath,
|
|
174
|
-
url: Option.getOrNull(args.url),
|
|
175
|
-
decisions: Option.getOrNull(args.decisions),
|
|
176
|
-
timeout: Option.getOrNull(args.timeout),
|
|
177
|
-
cwd: process.cwd(),
|
|
178
|
-
env: process.env
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
159
|
/** Why the data is not ready, as the command fails with it. */
|
|
182
160
|
function notReady(summary) {
|
|
183
161
|
return summary.blocking > 0 ? `${summary.blocking} blocking problem${summary.blocking === 1 ? "" : "s"} in the data: fix the rows, or decide what becomes of them on the Migrate page of hekireki studio, before migrating.` : `${summary.failed} check${summary.failed === 1 ? "" : "s"} could not run.`;
|
|
184
162
|
}
|
|
185
163
|
function runMigrateCheckCommand(args) {
|
|
186
164
|
return Effect.gen(function* () {
|
|
187
|
-
const schemaPath = yield* resolveSchemaPath(
|
|
165
|
+
const schemaPath = yield* resolveSchemaPath(args.schema, [
|
|
188
166
|
COMMAND_NAME,
|
|
189
167
|
"migrate",
|
|
190
168
|
"check"
|
|
191
169
|
]);
|
|
192
|
-
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-
|
|
193
|
-
const report = yield* runMigrateCheck(
|
|
170
|
+
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-CvfrvM4u.js"));
|
|
171
|
+
const report = yield* runMigrateCheck({
|
|
172
|
+
...args,
|
|
173
|
+
schemaPath,
|
|
174
|
+
cwd: process.cwd(),
|
|
175
|
+
env: process.env
|
|
176
|
+
}).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
194
177
|
yield* Console.log(args.json ? checkJson(report) : checkBanner(report));
|
|
195
178
|
const summary = summarize(report);
|
|
196
179
|
if (!summary.ok) yield* new CliError.UserError({ cause: notReady(summary) });
|
|
@@ -219,32 +202,34 @@ const migratePlanFlags = {
|
|
|
219
202
|
url: migrateCheckFlags.url,
|
|
220
203
|
decisions: migrateCheckFlags.decisions,
|
|
221
204
|
timeout: migrateCheckFlags.timeout,
|
|
222
|
-
migration: Flag.String("migration").pipe(Flag.withAlias("m"), Flag.withDescription("The migration.sql Prisma wrote for the schema (`prisma migrate dev --create-only`): the plan is then the whole migration, the fixes first and what the migration itself has to do written into Prisma's statements"), Flag.withMetavar("migration.sql"), Flag.
|
|
223
|
-
batch: Flag.Int("batch").pipe(Flag.withDescription("Run a fix over more rows than this that many at a time, one statement after another, so none holds its locks for the whole table (default: every fix in one statement; no effect inside the one DO block of PostgreSQL)"), Flag.withMetavar("rows"), Flag.
|
|
224
|
-
output: Flag.String("output").pipe(Flag.withAlias("o"), Flag.withDescription("Write the SQL to this file and print the report (default: the SQL to stdout)"), Flag.withMetavar("fixes.sql"), Flag.
|
|
205
|
+
migration: Flag.String("migration").pipe(Flag.withAlias("m"), Flag.withDescription("The migration.sql Prisma wrote for the schema (`prisma migrate dev --create-only`): the plan is then the whole migration, the fixes first and what the migration itself has to do written into Prisma's statements"), Flag.withMetavar("migration.sql"), Flag.withDefault(null)),
|
|
206
|
+
batch: Flag.Int("batch").pipe(Flag.withDescription("Run a fix over more rows than this that many at a time, one statement after another, so none holds its locks for the whole table (default: every fix in one statement; no effect inside the one DO block of PostgreSQL)"), Flag.withMetavar("rows"), Flag.withDefault(null)),
|
|
207
|
+
output: Flag.String("output").pipe(Flag.withAlias("o"), Flag.withDescription("Write the SQL to this file and print the report (default: the SQL to stdout)"), Flag.withMetavar("fixes.sql"), Flag.withDefault(null))
|
|
225
208
|
};
|
|
226
209
|
function runMigratePlanCommand(args) {
|
|
227
210
|
return Effect.gen(function* () {
|
|
228
|
-
const schemaPath = yield* resolveSchemaPath(
|
|
211
|
+
const schemaPath = yield* resolveSchemaPath(args.schema, [
|
|
229
212
|
COMMAND_NAME,
|
|
230
213
|
"migrate",
|
|
231
214
|
"plan"
|
|
232
215
|
]);
|
|
233
|
-
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-
|
|
234
|
-
const report = yield* runMigrateCheck(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
216
|
+
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-CvfrvM4u.js"));
|
|
217
|
+
const report = yield* runMigrateCheck({
|
|
218
|
+
...args,
|
|
219
|
+
schemaPath,
|
|
220
|
+
cwd: process.cwd(),
|
|
221
|
+
env: process.env
|
|
222
|
+
}).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
223
|
+
const migration = args.migration === null ? null : yield* readMigration(path.resolve(args.migration)).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
224
|
+
if (args.batch !== null && args.batch < 1) yield* new CliError.UserError({ cause: "--batch takes a number of rows, 1 or more." });
|
|
225
|
+
const { sql, errors, notes } = planSql(report, migration, args.batch);
|
|
240
226
|
if (errors.length > 0) yield* new CliError.UserError({ cause: errors.join("\n") });
|
|
241
|
-
const output = Option.getOrNull(args.output);
|
|
242
227
|
const noted = notes.map((note) => ` ${note}`).join("\n");
|
|
243
|
-
if (output === null) {
|
|
228
|
+
if (args.output === null) {
|
|
244
229
|
yield* Console.log(sql.trimEnd());
|
|
245
230
|
yield* Console.error(noted);
|
|
246
231
|
} else {
|
|
247
|
-
const file = path.resolve(output);
|
|
232
|
+
const file = path.resolve(args.output);
|
|
248
233
|
yield* writePlan(sql, file).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
249
234
|
yield* Console.log(`${checkBanner(report)}\n\n Plan: ${file}\n${noted}`);
|
|
250
235
|
}
|
|
@@ -271,22 +256,13 @@ const migratePlan = Command.make("plan", migratePlanFlags, runMigratePlanCommand
|
|
|
271
256
|
}
|
|
272
257
|
]));
|
|
273
258
|
const migrate = Command.make("migrate").pipe(Command.withDescription("Data checks and fixes for a schema migration"), Command.withSubcommands([migrateCheck, migratePlan]));
|
|
274
|
-
const
|
|
259
|
+
const hekireki = Command.make(COMMAND_NAME).pipe(Command.withDescription("⚡️ Prisma schema tools"), Command.withSubcommands([
|
|
275
260
|
studio,
|
|
276
261
|
seed,
|
|
277
262
|
migrate
|
|
278
263
|
]));
|
|
279
|
-
function hekirekiCli(argv, config) {
|
|
280
|
-
return Command.runWith(cli, config)(argv);
|
|
281
|
-
}
|
|
282
|
-
/** The entry point the bin runs, reading its arguments the way `Command.run` does. */
|
|
283
|
-
function hekireki(config) {
|
|
284
|
-
return Effect.gen(function* () {
|
|
285
|
-
return yield* hekirekiCli(yield* (yield* Stdio.Stdio).args, config);
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
264
|
//#endregion
|
|
289
265
|
//#region src/bin/hekireki.ts
|
|
290
|
-
NodeRuntime.runMain(hekireki
|
|
266
|
+
NodeRuntime.runMain(Command.run(hekireki, { version }).pipe(Effect.provide(NodeServices.layer)));
|
|
291
267
|
//#endregion
|
|
292
|
-
export {
|
|
268
|
+
export { SSE_PING_MS as _, DatabaseUnavailableError as a, 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 };
|
package/dist/bin/kysely.js
CHANGED
package/dist/bin/pydantic.js
CHANGED
package/dist/bin/sea-orm.js
CHANGED
package/dist/bin/seed.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