hekireki 0.30.0 → 0.31.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 +171 -19
- 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 +5 -5
- 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-_yRLzidS.js → bin-CiVKUVYM.js} +1443 -270
- package/dist/{discover-Dd4T0K--.js → discover-DVB1eehy.js} +1 -1
- package/dist/{emit-Cg7AiLfc.js → emit-CdFQK71O.js} +1 -1
- package/dist/{migrate-D_qSZohK.js → migrate-B10ui4rh.js} +3 -3
- package/dist/{plan-CYDx4rVr.js → plan-BDkcp2gn.js} +3 -3
- package/dist/{run-DBKTGE9q.js → run-BMAnuiJ1.js} +4 -4
- package/dist/{schema-n8EV8GwT.js → schema-B-2ni3YF.js} +1 -1
- package/dist/{sql-Bfp97prN.js → sql-Bb3cwfJt.js} +1 -1
- package/dist/{start-CHsK9ngN.js → start-BhcpaMcT.js} +5 -5
- package/dist/{utils-CH4KSdD_.js → utils-Cgi66Lfo.js} +9 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,10 @@ npm install -D hekireki
|
|
|
13
13
|
|
|
14
14
|
## Generators
|
|
15
15
|
|
|
16
|
-
Add a generator to `schema.prisma` and run `npx prisma generate`. `output` is required.
|
|
16
|
+
Add a generator to `schema.prisma` and run `npx prisma generate`. `output` is required. Every
|
|
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.
|
|
17
20
|
|
|
18
21
|
```prisma
|
|
19
22
|
generator Hekireki-Zod {
|
|
@@ -23,24 +26,25 @@ generator Hekireki-Zod {
|
|
|
23
26
|
}
|
|
24
27
|
```
|
|
25
28
|
|
|
26
|
-
| Provider
|
|
27
|
-
|
|
|
28
|
-
| `hekireki-zod`
|
|
29
|
-
| `hekireki-valibot`, `hekireki-arktype`, `hekireki-effect`, `hekireki-typebox`, `hekireki-ajv`
|
|
30
|
-
| `hekireki-pydantic`
|
|
31
|
-
| `hekireki-drizzle`, `hekireki-kysely`, `hekireki-sqlalchemy`, `hekireki-django
|
|
32
|
-
| `hekireki-
|
|
33
|
-
| `hekireki-
|
|
34
|
-
| `hekireki-
|
|
35
|
-
| `hekireki-
|
|
36
|
-
| `hekireki-
|
|
37
|
-
| `hekireki-
|
|
38
|
-
| `hekireki-
|
|
39
|
-
| `hekireki-
|
|
40
|
-
| `hekireki-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
| Provider | Generates | Options |
|
|
30
|
+
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
31
|
+
| `hekireki-zod` | [Zod](https://zod.dev/) | `type`, `comment`, `relation`, `zod` (`"v4"`, `"mini"`, `"@hono/zod-openapi"`) |
|
|
32
|
+
| `hekireki-valibot`, `hekireki-arktype`, `hekireki-effect`, `hekireki-typebox`, `hekireki-ajv` | Valibot, ArkType, Effect Schema, TypeBox, AJV | `type`, `comment`, `relation` |
|
|
33
|
+
| `hekireki-pydantic` | Pydantic | `comment`, `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) | EF Core | `namespace`, `context` |
|
|
41
|
+
| `hekireki-exposed` (PostgreSQL) | Exposed | `package`, `dao` |
|
|
42
|
+
| `hekireki-atlas` | Atlas HCL | `schemaName`, `comment` |
|
|
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
|
+
A `///` line starting with `@z.`, `@v.`, `@a.`, `@e.`, `@t.`, `@j.`, `@p.` or `@ar.` is used
|
|
47
|
+
as-is by Zod, Valibot, ArkType, Effect Schema, TypeBox, AJV, Pydantic or Active Record:
|
|
44
48
|
|
|
45
49
|
```prisma
|
|
46
50
|
model User {
|
|
@@ -50,6 +54,154 @@ model User {
|
|
|
50
54
|
}
|
|
51
55
|
```
|
|
52
56
|
|
|
57
|
+
### Rails
|
|
58
|
+
|
|
59
|
+
`hekireki-activerecord` writes `app/models` whole, for Rails 7.1 or later: `application_record.rb`
|
|
60
|
+
as `rails new` writes it (when `output` is a directory named `models`) and one `.rb` file per
|
|
61
|
+
model, so the directory can go in `.gitignore` and be regenerated with `prisma generate`. Each
|
|
62
|
+
model is written as a Rails developer would write it, and what Rails derives on its own is left
|
|
63
|
+
unsaid: `table_name` appears only when the table is not the plural of the class (without `@@map`
|
|
64
|
+
it is the model's own name, `"Todo"`, as Prisma creates it), `class_name`, `foreign_key` and
|
|
65
|
+
`inverse_of` only where the names depart from Rails' conventions (`has_many :todos` over `user_id`
|
|
66
|
+
needs none of them; its `belongs_to :user` keeps `inverse_of: :todos`, the plural inverse Rails
|
|
67
|
+
infers only with `automatically_invert_plural_associations`), and no comment at all: the `///`
|
|
68
|
+
documentation stays in the schema. The files pass `rubocop-rails-omakase` and RuboCop's own
|
|
69
|
+
defaults with `rubocop-rails` as written.
|
|
70
|
+
|
|
71
|
+
What the model does carry: an `attribute` default for each literal `@default`, for `uuid()`,
|
|
72
|
+
`ulid()`, `cuid()`, `cuid(2)` and `nanoid()` (the `ulid`, `cuid`, `cuid2` and `nanoid` gems) and an
|
|
73
|
+
empty array for a list without one, as the Prisma client reads it; `implicit_order_column` on the
|
|
74
|
+
created timestamp when the primary key is random (`uuid()`, `cuid()`, `nanoid()`); `alias_attribute`
|
|
75
|
+
for a `createdAt` or `@updatedAt` column so Rails fills and bumps it as the Prisma client would;
|
|
76
|
+
`enum` with snake_case keys (`PENDING_REVIEW` gives `record.pending_review?` and the
|
|
77
|
+
`pending_review` scope, the stored value stays the database's), its `default:`, `prefix: true` when a
|
|
78
|
+
key is a method Ruby or Active Record already has, and `validate: true` so a value outside the enum
|
|
79
|
+
is a validation error rather than an `ArgumentError`; `dependent:` on every `has_many` and `has_one`
|
|
80
|
+
as the foreign key's `onDelete` acts (`Cascade` destroys, `SetNull` nullifies, `Restrict` and
|
|
81
|
+
`NoAction` refuse with an error); and validations from the columns: a required column without a
|
|
82
|
+
default is `presence` (`inclusion` in `[ true, false ]` for a `Boolean`, `exclusion` of `nil` for
|
|
83
|
+
`Json` and `Bytes`), `@unique` and `@@unique` are `uniqueness`, `@db.VarChar(n)` is `length`.
|
|
84
|
+
|
|
85
|
+
Validation stays in the model, as Active Record has it. A `/// @ar.` call on a field is one
|
|
86
|
+
validator on one `///` line, written as Rails spells it (`presence`, `length(maximum: 255)`), and
|
|
87
|
+
becomes an option of that field's `validates`, replacing the one the schema implied when it names
|
|
88
|
+
the same validator; a `/// @ar.` line on the model is written into the class as it is. A message
|
|
89
|
+
given per locale, `message: { ja: "...", en: "..." }` or `too_long: { ja: "...", en: "..." }`, is
|
|
90
|
+
not written into the model: it goes to `config/locales/models/todo/<locale>.yml` under the key the
|
|
91
|
+
[Rails i18n guide](https://guides.rubyonrails.org/i18n.html#error-message-scopes) lists for that
|
|
92
|
+
validator (`activerecord.errors.models.todo.attributes.title.blank`). `too_long` is a key already;
|
|
93
|
+
`message` stands for every key the validator can raise: `blank` for `presence`, all three of
|
|
94
|
+
`length`, and for `numericality` and `comparison` the keys of the options given
|
|
95
|
+
(`greater_than: 0` raises `greater_than`), so the one translation covers whichever fails. A locale's
|
|
96
|
+
value may be plural forms, `{ one: "...", other: "%{count} ..." }`, which I18n picks by `count`, and
|
|
97
|
+
`%{count}`, `%{value}`, `%{model}` and `%{attribute}` interpolate as Rails' own messages do.
|
|
98
|
+
`@ar.name(ja: "...", en: "...")` on a field or a model translates its name the same way
|
|
99
|
+
(`activerecord.attributes.todo.title`, `activerecord.models.todo`), plural forms included.
|
|
100
|
+
The files are laid out as the guide's
|
|
101
|
+
[organization of locale files](https://guides.rubyonrails.org/i18n.html#organization-of-locale-files)
|
|
102
|
+
has them, `models/<model>/<locale>.yml`, one directory per model and one file per locale it names,
|
|
103
|
+
so model and attribute names stay apart from the text of the views and from the defaults; Rails
|
|
104
|
+
loads `config/locales` through its subdirectories. `locales` names that directory; from
|
|
105
|
+
`app/models` it is `config/locales`. The comment has one shape: the description first, then the
|
|
106
|
+
`@ar.` calls, one to a `///` line. On a field each is `name` or `name(arguments)` with its
|
|
107
|
+
parentheses closed on that line; on the model each is a Ruby line as the class body would have it
|
|
108
|
+
(`validates :a, :b, presence: true`, `normalizes :title, with: ->(title) { title.strip }`), not
|
|
109
|
+
ending in a comma. A description line after a call, a call that runs on to the next `///` or a
|
|
110
|
+
call of another shape stops `prisma generate` with the model and field it is on. Rails joins attribute and message with a space (`errors.format`), which Japanese does not want: the
|
|
111
|
+
`rails-i18n` gem's `ja.yml` sets it to `%{attribute}%{message}`, and the generated files sit beside
|
|
112
|
+
it. Point `output` at `app/models`, and `todo.rb` is the model, nothing left to edit by hand:
|
|
113
|
+
|
|
114
|
+
```prisma
|
|
115
|
+
generator Hekireki-ActiveRecord {
|
|
116
|
+
provider = "hekireki-activerecord"
|
|
117
|
+
output = "../app/models"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/// @ar.name(ja: "やること", en: "Todo")
|
|
121
|
+
model Todo {
|
|
122
|
+
id Int @id @default(autoincrement())
|
|
123
|
+
/// @ar.name(ja: "タイトル", en: "Title")
|
|
124
|
+
/// @ar.presence(message: { ja: "を入力してください", en: "is required" })
|
|
125
|
+
/// @ar.length(maximum: 255, too_long: { ja: "%{count}文字以内で入力してください", en: "must be %{count} characters or less" })
|
|
126
|
+
title String @db.VarChar(255)
|
|
127
|
+
completed Boolean @default(false)
|
|
128
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
129
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
130
|
+
|
|
131
|
+
@@map("todos")
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
# app/models/application_record.rb
|
|
137
|
+
class ApplicationRecord < ActiveRecord::Base
|
|
138
|
+
primary_abstract_class
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# app/models/todo.rb
|
|
142
|
+
class Todo < ApplicationRecord
|
|
143
|
+
attribute :completed, default: false
|
|
144
|
+
|
|
145
|
+
validates :title, presence: true, length: { maximum: 255 }
|
|
146
|
+
end
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
# config/locales/models/todo/ja.yml
|
|
151
|
+
ja:
|
|
152
|
+
activerecord:
|
|
153
|
+
models:
|
|
154
|
+
todo: 'やること'
|
|
155
|
+
attributes:
|
|
156
|
+
todo:
|
|
157
|
+
title: 'タイトル'
|
|
158
|
+
errors:
|
|
159
|
+
models:
|
|
160
|
+
todo:
|
|
161
|
+
attributes:
|
|
162
|
+
title:
|
|
163
|
+
blank: 'を入力してください'
|
|
164
|
+
too_long: '%{count}文字以内で入力してください'
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```gitignore
|
|
168
|
+
/app/models/
|
|
169
|
+
/config/locales/models/
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Which file answers is the request's locale. The guide's
|
|
173
|
+
[managing the locale across requests](https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests)
|
|
174
|
+
sets it once per request with `I18n.with_locale`, which puts it back when the action ends rather
|
|
175
|
+
than leaving it on the thread for the next request, and names the locales the application serves:
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
# config/application.rb
|
|
179
|
+
config.i18n.available_locales = %i[ja en]
|
|
180
|
+
config.i18n.default_locale = :ja
|
|
181
|
+
|
|
182
|
+
# app/controllers/application_controller.rb
|
|
183
|
+
class ApplicationController < ActionController::Base
|
|
184
|
+
around_action :switch_locale
|
|
185
|
+
|
|
186
|
+
private
|
|
187
|
+
def switch_locale(&action)
|
|
188
|
+
locale = params[:locale] || I18n.default_locale
|
|
189
|
+
I18n.with_locale(locale, &action)
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The tables stay Prisma's to create, so Rails must not run its own migrations against them:
|
|
195
|
+
|
|
196
|
+
```ruby
|
|
197
|
+
# config/application.rb
|
|
198
|
+
config.active_record.migration_error = false
|
|
199
|
+
config.active_record.maintain_test_schema = false
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Create the test database with `prisma migrate deploy` (from `test_helper.rb`, or before the test
|
|
203
|
+
run) rather than `db:test:prepare`.
|
|
204
|
+
|
|
53
205
|
## Studio
|
|
54
206
|
|
|
55
207
|
```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
|
@@ -5,7 +5,7 @@ import { 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.31.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. */
|
|
@@ -82,7 +82,7 @@ const studioFlags = {
|
|
|
82
82
|
function runStudio(args) {
|
|
83
83
|
return Effect.gen(function* () {
|
|
84
84
|
const schemaPath = yield* resolveSchemaPath(Option.getOrNull(args.schema), [COMMAND_NAME, "studio"]);
|
|
85
|
-
const { startStudioServer } = yield* Effect.promise(() => import("../start-
|
|
85
|
+
const { startStudioServer } = yield* Effect.promise(() => import("../start-BhcpaMcT.js"));
|
|
86
86
|
const started = yield* startStudioServer({
|
|
87
87
|
schemaPath,
|
|
88
88
|
port: args.port,
|
|
@@ -128,7 +128,7 @@ const seedFlags = {
|
|
|
128
128
|
};
|
|
129
129
|
function runSeedCommand(args) {
|
|
130
130
|
return Effect.gen(function* () {
|
|
131
|
-
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-
|
|
131
|
+
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-BMAnuiJ1.js"));
|
|
132
132
|
const report = yield* runSeed({
|
|
133
133
|
config: Option.getOrNull(args.config),
|
|
134
134
|
schema: Option.getOrNull(args.schema),
|
|
@@ -189,7 +189,7 @@ function runMigrateCheckCommand(args) {
|
|
|
189
189
|
"migrate",
|
|
190
190
|
"check"
|
|
191
191
|
]);
|
|
192
|
-
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-
|
|
192
|
+
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-B10ui4rh.js"));
|
|
193
193
|
const report = yield* runMigrateCheck(migrateInput(args, schemaPath)).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
194
194
|
yield* Console.log(args.json ? checkJson(report) : checkBanner(report));
|
|
195
195
|
const summary = summarize(report);
|
|
@@ -230,7 +230,7 @@ function runMigratePlanCommand(args) {
|
|
|
230
230
|
"migrate",
|
|
231
231
|
"plan"
|
|
232
232
|
]);
|
|
233
|
-
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-
|
|
233
|
+
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-B10ui4rh.js"));
|
|
234
234
|
const report = yield* runMigrateCheck(migrateInput(args, schemaPath)).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
235
235
|
const migrationPath = Option.getOrNull(args.migration);
|
|
236
236
|
const migration = migrationPath === null ? null : yield* readMigration(path.resolve(migrationPath)).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
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