hekireki 0.22.0 → 0.23.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.
Files changed (92) hide show
  1. package/README.md +48 -78
  2. package/dist/bin/activerecord.js +1 -1
  3. package/dist/bin/ajv.js +1 -1
  4. package/dist/bin/arktype.js +1 -1
  5. package/dist/bin/atlas.js +1 -1
  6. package/dist/bin/django.js +1 -1
  7. package/dist/bin/drizzle.js +1 -1
  8. package/dist/bin/ecto.js +1 -1
  9. package/dist/bin/efcore.js +1 -1
  10. package/dist/bin/effect.js +1 -1
  11. package/dist/bin/eloquent.js +1 -1
  12. package/dist/bin/er.js +1 -1
  13. package/dist/bin/exposed.d.ts +1 -0
  14. package/dist/bin/exposed.js +6 -0
  15. package/dist/bin/gorm.js +1 -1
  16. package/dist/bin/hekireki.js +180 -68
  17. package/dist/bin/kysely.js +1 -1
  18. package/dist/bin/pydantic.js +1 -1
  19. package/dist/bin/sea-orm.js +1 -1
  20. package/dist/bin/seed.d.ts +1 -0
  21. package/dist/bin/seed.js +6 -0
  22. package/dist/bin/sqlalchemy.js +1 -1
  23. package/dist/bin/typebox.js +1 -1
  24. package/dist/bin/valibot.js +1 -1
  25. package/dist/bin/zod.js +1 -1
  26. package/dist/{bin-DxYpJikH.js → bin-_yRLzidS.js} +3049 -616
  27. package/dist/discover-Dd4T0K--.js +179 -0
  28. package/dist/emit-Cg7AiLfc.js +29 -0
  29. package/dist/{file-yN0By3gn.js → file-BPNqvwXD.js} +24 -2
  30. package/dist/index.d.ts +267 -0
  31. package/dist/index.js +18 -0
  32. package/dist/migrate-D_qSZohK.js +184 -0
  33. package/dist/plan-CYDx4rVr.js +6752 -0
  34. package/dist/run-DBKTGE9q.js +1571 -0
  35. package/dist/{schema-Ci19PgR9.js → schema-n8EV8GwT.js} +12 -129
  36. package/dist/sql-Bfp97prN.js +604 -0
  37. package/dist/{start-EKGd2Tvk.js → start-CHsK9ngN.js} +6215 -2298
  38. package/dist/studio/assets/chip-DktDoVzE.js +1 -0
  39. package/dist/studio/assets/client-Dr3jviL4.js +2 -0
  40. package/dist/studio/assets/code-block-BjrKQVTG.js +24 -0
  41. package/dist/studio/assets/confirm-dialog-DyTVsQSX.js +1 -0
  42. package/dist/studio/assets/{copy-DiFFafx_.js → copy-BiNLD_lP.js} +1 -1
  43. package/dist/studio/assets/copy-button-BVg2tjZ8.js +1 -0
  44. package/dist/studio/assets/{dist-Ax_1vG1u.js → dist-B67qd3Zz.js} +8 -7
  45. package/dist/studio/assets/docs-CkqYk8Me.js +1 -0
  46. package/dist/studio/assets/enums._name-Bgr8KpI7.js +1 -0
  47. package/dist/studio/assets/hooks-D5FHpZ7j.js +50 -0
  48. package/dist/studio/assets/index-DOc026EB.css +2 -0
  49. package/dist/studio/assets/index-S7nroM-z.js +16 -0
  50. package/dist/studio/assets/labels-BNvY0cN5.js +1 -0
  51. package/dist/studio/assets/lazyRouteComponent-CAes9Xsr.js +1 -0
  52. package/dist/studio/assets/lu-d7uRxrOD.js +7 -0
  53. package/dist/studio/assets/marked-text-BdD2j0fn.js +3 -0
  54. package/dist/studio/assets/models._name-D4_ZANEh.js +1 -0
  55. package/dist/studio/assets/monaco-DcZOWb7S.js +11 -0
  56. package/dist/studio/assets/{prisma-C2rAM-pV.css → monaco-I0M_1p4d.css} +1 -1
  57. package/dist/studio/assets/monaco-gMjyryJ5.js +880 -0
  58. package/dist/studio/assets/{not-found-Dr2QuAjv.js → not-found-CeYHDNqo.js} +1 -1
  59. package/dist/studio/assets/prisma-BO0BCCER.js +2 -0
  60. package/dist/studio/assets/result-table-88RDb-mF.js +1 -0
  61. package/dist/studio/assets/routes-CcWfWQAl.js +1 -0
  62. package/dist/studio/assets/{schema-gate-Bad9LKCZ.js → schema-gate-CsCy68T_.js} +1 -1
  63. package/dist/studio/assets/schema-view-nvsbR-7o.js +8 -0
  64. package/dist/studio/assets/sql-Dz7KO9RT.js +6 -0
  65. package/dist/studio/assets/table-Dh7RyVup.js +1 -0
  66. package/dist/studio/assets/tabs-Den1DTwv.js +1 -0
  67. package/dist/studio/assets/{useFormValidation-D6Nfw1Ec.js → useFormValidation-DYw-_Bbl.js} +1 -1
  68. package/dist/studio/assets/useMatch-Bfhrp9go.js +1 -0
  69. package/dist/studio/assets/useMultipleSelectionState-7x90tUim.js +1 -0
  70. package/dist/studio/assets/{useOverlayTriggerState-C-S92dgf.js → useOverlayTriggerState-vyNglC3z.js} +1 -1
  71. package/dist/studio/index.html +11 -9
  72. package/dist/utils-CH4KSdD_.js +141 -0
  73. package/package.json +22 -3
  74. package/dist/studio/assets/chip-B9UolvIl.js +0 -1
  75. package/dist/studio/assets/debounce-WjLaYdFF.js +0 -3
  76. package/dist/studio/assets/docs-D2Vpbqbg.js +0 -24
  77. package/dist/studio/assets/enums._name-t90NJ6-H.js +0 -1
  78. package/dist/studio/assets/hooks-UJuF1mqe.js +0 -1
  79. package/dist/studio/assets/index-C29_CUjj.js +0 -16
  80. package/dist/studio/assets/index-CYncH7vk.css +0 -2
  81. package/dist/studio/assets/labels-D0IhxSmD.js +0 -1
  82. package/dist/studio/assets/lazyRouteComponent-G8mNaW9J.js +0 -1
  83. package/dist/studio/assets/lu-DvK-u3Mx.js +0 -7
  84. package/dist/studio/assets/models._name-DUEsQrdC.js +0 -1
  85. package/dist/studio/assets/prisma-Co828tLd.js +0 -891
  86. package/dist/studio/assets/routes-BIbzUF01.js +0 -1
  87. package/dist/studio/assets/schema-view-nCetSUyn.js +0 -8
  88. package/dist/studio/assets/sql-Db9voX3l.js +0 -7
  89. package/dist/studio/assets/table-BfaXyuqp.js +0 -1
  90. package/dist/studio/assets/tabs-BXvBDUhR.js +0 -1
  91. package/dist/studio/assets/useMatch-BZSBUGcY.js +0 -1
  92. package/dist/studio/assets/useMultipleSelectionState-Bz2aFLv7.js +0 -1
package/README.md CHANGED
@@ -3,8 +3,7 @@
3
3
  # Hekireki
4
4
 
5
5
  **[Hekireki](https://www.npmjs.com/package/hekireki)** generates validation schemas, ORM models and
6
- ER diagrams from a [Prisma](https://www.prisma.io/) schema, and opens the schema and its data in the
7
- browser with Hekireki Studio.
6
+ ER diagrams from a [Prisma](https://www.prisma.io/) schema, and seeds a database.
8
7
 
9
8
  ## Installation
10
9
 
@@ -12,108 +11,79 @@ browser with Hekireki Studio.
12
11
  npm install -D hekireki
13
12
  ```
14
13
 
15
- ## Usage
16
-
17
- Add a generator to `schema.prisma` and run `npx prisma generate`. `output` is required.
18
-
19
- ```prisma
20
- generator Hekireki-Zod {
21
- provider = "hekireki-zod"
22
- output = "./zod"
23
- }
24
- ```
25
-
26
14
  ## Generators
27
15
 
28
- ### Validation schemas
29
-
30
- - `hekireki-zod` — [Zod](https://zod.dev/)
31
- - `hekireki-valibot` — [Valibot](https://valibot.dev/)
32
- - `hekireki-arktype` — [ArkType](https://arktype.io/)
33
- - `hekireki-effect` — [Effect Schema](https://effect.website/docs/schema/introduction/)
34
- - `hekireki-typebox` — [TypeBox](https://github.com/sinclairzx81/typebox)
35
- - `hekireki-ajv` — [AJV](https://ajv.js.org/)
36
- - `hekireki-pydantic` — [Pydantic](https://docs.pydantic.dev/)
37
-
38
- ### ORM models
39
-
40
- - `hekireki-drizzle` — [Drizzle](https://orm.drizzle.team/)
41
- - `hekireki-kysely` — [Kysely](https://kysely.dev/)
42
- - `hekireki-sqlalchemy` — [SQLAlchemy](https://www.sqlalchemy.org/)
43
- - `hekireki-django` — [Django](https://www.djangoproject.com/)
44
- - `hekireki-gorm` — [GORM](https://gorm.io/)
45
- - `hekireki-sea-orm` — [SeaORM](https://www.sea-ql.org/SeaORM/)
46
- - `hekireki-ecto` — [Ecto](https://hexdocs.pm/ecto/Ecto.Schema.html)
47
- - `hekireki-activerecord` — [Active Record](https://guides.rubyonrails.org/active_record_basics.html)
48
- - `hekireki-eloquent` — [Eloquent](https://laravel.com/docs/eloquent)
49
- - `hekireki-efcore` — [EF Core](https://learn.microsoft.com/ef/core/)
50
- - `hekireki-atlas` — [Atlas](https://atlasgo.io/) HCL
51
-
52
- ### ER diagrams
53
-
54
- - `hekireki-er` — Mermaid, DBML, PNG and SVG
55
-
56
- ## Options
16
+ Add a generator to `schema.prisma` and run `npx prisma generate`. `output` is required.
57
17
 
58
18
  ```prisma
59
19
  generator Hekireki-Zod {
60
20
  provider = "hekireki-zod"
61
21
  output = "./zod"
62
22
  type = true // Export TypeScript types
63
- comment = true // Keep /// comments
64
- relation = true // Add <Model>Relations schemas
65
- zod = "v4" // "v4" (default), "mini" or "@hono/zod-openapi"
66
23
  }
67
24
  ```
68
25
 
69
- - `type`, `comment`, `relation` — every validation schema generator (Pydantic: `comment`, `relation`)
70
- - `package` — GORM package name (default: `model`)
71
- - `renameAll` — SeaORM `#[serde(rename_all = "...")]`
72
- - `app` — Ecto module prefix (default: `MyApp`)
73
- - `namespace` — Eloquent (default: `App\Models`) and EF Core (default: `Models`)
74
- - `context` — EF Core `DbContext` class name (default: `AppDbContext`)
75
- - `schemaName`, `comment` — Atlas
76
- - `outputs`, `theme` — ER
77
-
78
- ## Annotations
26
+ | Provider | Generates | Options |
27
+ | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------ |
28
+ | `hekireki-zod` | [Zod](https://zod.dev/) | `type`, `comment`, `relation`, `zod` (`"v4"`, `"mini"`, `"@hono/zod-openapi"`) |
29
+ | `hekireki-valibot`, `hekireki-arktype`, `hekireki-effect`, `hekireki-typebox`, `hekireki-ajv` | Valibot, ArkType, Effect Schema, TypeBox, AJV | `type`, `comment`, `relation` |
30
+ | `hekireki-pydantic` | Pydantic | `comment`, `relation` |
31
+ | `hekireki-drizzle`, `hekireki-kysely`, `hekireki-sqlalchemy`, `hekireki-django`, `hekireki-activerecord` | Drizzle, Kysely, SQLAlchemy, Django, Active Record | |
32
+ | `hekireki-gorm` | GORM | `package` |
33
+ | `hekireki-sea-orm` | SeaORM | `renameAll` |
34
+ | `hekireki-ecto` | Ecto | `app` |
35
+ | `hekireki-eloquent` | Eloquent | `namespace` |
36
+ | `hekireki-efcore` (PostgreSQL) | EF Core | `namespace`, `context` |
37
+ | `hekireki-exposed` (PostgreSQL) | Exposed | `package`, `dao` |
38
+ | `hekireki-atlas` | Atlas HCL | `schemaName`, `comment` |
39
+ | `hekireki-er` | ER diagram | `outputs` (`.md`, `.dbml`, `.png`, `.svg`), `theme` |
40
+ | `hekireki-seed` | The schema module `hekireki.config.ts` is typed against | |
79
41
 
80
42
  A `///` line starting with `@z.`, `@v.`, `@a.`, `@e.`, `@t.`, `@j.` or `@p.` is used as-is by Zod,
81
- Valibot, ArkType, Effect Schema, TypeBox, AJV or Pydantic. Any other `///` line is documentation.
43
+ Valibot, ArkType, Effect Schema, TypeBox, AJV or Pydantic:
82
44
 
83
45
  ```prisma
84
46
  model User {
85
- /// Display name
86
- /// @z.string().min(1).max(50)
87
- /// @v.pipe(v.string(), v.minLength(1), v.maxLength(50))
88
- name String
47
+ /// @z.email()
48
+ /// @v.pipe(v.string(), v.email())
49
+ email String @unique
89
50
  }
90
51
  ```
91
52
 
92
- ## ER diagrams
93
-
94
- The extension of each path picks the format: `.md` (Mermaid), `.dbml`, `.png` or `.svg`.
53
+ ## Studio
95
54
 
96
- ```prisma
97
- generator Hekireki-ER {
98
- provider = "hekireki-er"
99
- outputs = ["docs/er.md", "docs/er.svg"] // One file: output = "docs/er.md"
100
- theme = "dark" // .png / .svg: "light" (default) or "dark"
101
- }
55
+ ```bash
56
+ npx hekireki studio # ./prisma/schema.prisma or ./schema.prisma, port 5555
57
+ npx hekireki studio --url file:./dev.db
102
58
  ```
103
59
 
104
- ## Studio
60
+ The ER diagram, the rows of each model, a schema editor, a SQL console and a Prisma Client
61
+ playground, in the browser. SQLite, PostgreSQL and MySQL.
62
+
63
+ ## Seed
105
64
 
106
65
  ```bash
107
- hekireki studio # ./prisma/schema.prisma or ./schema.prisma
108
- hekireki studio --schema prisma/schema # A multi-file schema
109
- hekireki studio --url file:./dev.db # A database of your choice
110
- hekireki studio -p 3000 # Another port (default: 5555)
66
+ npx hekireki seed # Through the project's Prisma Client
67
+ npx hekireki seed --sql seed.sql # Or as a SQL script
68
+ ```
69
+
70
+ ```ts
71
+ // hekireki.config.ts
72
+ import { defineConfig } from 'hekireki'
73
+
74
+ import { schema } from './prisma/seed/schema' // written by the hekireki-seed generator
75
+
76
+ export default defineConfig(schema, {
77
+ seed: 42,
78
+ models: {
79
+ User: { count: 100, fields: { age: { min: 18, max: 65 } } },
80
+ Tag: { data: [{ label: 'prisma' }, { label: 'effect' }] },
81
+ },
82
+ })
111
83
  ```
112
84
 
113
- Studio shows the ER diagram, the docs, each model's rows, a Prisma editor and a SQL console, and
114
- reloads when the schema changes. The database comes from `--url`, `DATABASE_URL` or
115
- `prisma.config.ts`.
85
+ Every foreign key, unique constraint and enum is respected.
116
86
 
117
87
  ## License
118
88
 
119
- Distributed under the MIT License. See [LICENSE](https://github.com/nakita628/hekireki?tab=MIT-1-ov-file) for more information.
89
+ MIT. See [LICENSE](https://github.com/nakita628/hekireki?tab=MIT-1-ov-file).
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/activerecord.ts
4
4
  registerGenerator("activerecord");
5
5
  //#endregion
package/dist/bin/ajv.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/ajv.ts
4
4
  registerGenerator("ajv");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/arktype.ts
4
4
  registerGenerator("arktype");
5
5
  //#endregion
package/dist/bin/atlas.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/atlas.ts
4
4
  registerGenerator("atlas");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/django.ts
4
4
  registerGenerator("django");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/drizzle.ts
4
4
  registerGenerator("drizzle");
5
5
  //#endregion
package/dist/bin/ecto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/ecto.ts
4
4
  registerGenerator("ecto");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/efcore.ts
4
4
  registerGenerator("efcore");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/effect.ts
4
4
  registerGenerator("effect");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/eloquent.ts
4
4
  registerGenerator("eloquent");
5
5
  //#endregion
package/dist/bin/er.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/er.ts
4
4
  registerGenerator("er");
5
5
  //#endregion
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
+ //#region src/bin/exposed.ts
4
+ registerGenerator("exposed");
5
+ //#endregion
6
+ export {};
package/dist/bin/gorm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/gorm.ts
4
4
  registerGenerator("gorm");
5
5
  //#endregion
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { t as exists } from "../file-yN0By3gn.js";
2
+ import { t as exists } from "../file-BPNqvwXD.js";
3
3
  import { NodeRuntime, NodeServices } from "@effect/platform-node";
4
4
  import { Config, Console, Data, Effect, Option, Schema, Stdio } from "effect";
5
5
  import path from "node:path";
6
6
  import { CliError, Command, Flag } from "effect/unstable/cli";
7
7
  //#region package.json
8
- var version = "0.22.0";
8
+ var version = "0.23.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. */
@@ -16,6 +16,8 @@ const FORBIDDEN_HOST_MESSAGE = "Forbidden: Hekireki Studio only answers requests
16
16
  const SSE_PING_MS = 15e3;
17
17
  /** The URI the Prisma language server sees for the single in-memory schema document. */
18
18
  const PRISMA_FILE_URI = "file:///schema.prisma";
19
+ /** How often the migrations directory is read for a change. */
20
+ const MIGRATIONS_POLL_MS = 1e3;
19
21
  //#endregion
20
22
  //#region src/studio/server/errors/index.ts
21
23
  var UnknownModelError = class extends Data.TaggedError("UnknownModelError") {};
@@ -23,6 +25,8 @@ var UnknownFileError = class extends Data.TaggedError("UnknownFileError") {};
23
25
  var FileWriteError = class extends Data.TaggedError("FileWriteError") {};
24
26
  var DatabaseUnavailableError = class extends Data.TaggedError("DatabaseUnavailableError") {};
25
27
  var DatabaseError = class extends Data.TaggedError("DatabaseError") {};
28
+ var ClientUnavailableError = class extends Data.TaggedError("ClientUnavailableError") {};
29
+ var ClientQueryError = class extends Data.TaggedError("ClientQueryError") {};
26
30
  var InvalidInputError = class extends Data.TaggedError("InvalidInputError") {};
27
31
  var FormatError = class extends Data.TaggedError("FormatError") {};
28
32
  var ContractViolationError = class extends Data.TaggedError("ContractViolationError") {};
@@ -30,31 +34,14 @@ var SchemaLoadError = class extends Data.TaggedError("SchemaLoadError") {};
30
34
  var SchemaParseError = class extends Data.TaggedError("SchemaParseError") {};
31
35
  var ServerListenError = class extends Data.TaggedError("ServerListenError") {};
32
36
  //#endregion
33
- //#region src/cli/index.ts
34
- const COMMAND_NAME = "hekireki";
37
+ //#region src/cli/constants.ts
35
38
  /** Where `--schema` looks when it is omitted, in order. */
36
39
  const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
37
- const DATABASE_URL_SCHEMES = [
38
- "postgres",
39
- "postgresql",
40
- "mysql",
41
- "file"
42
- ];
40
+ //#endregion
41
+ //#region src/cli/index.ts
42
+ const COMMAND_NAME = "hekireki";
43
43
  const STATIC_DIR = path.resolve(import.meta.dirname, "../studio");
44
- const databaseUrlSchema = Schema.String.pipe(Schema.refine((value) => DATABASE_URL_SCHEMES.some((scheme) => value.startsWith(`${scheme}:`)), { message: "a postgres://, postgresql://, mysql:// or file: connection string" }));
45
- function userError(message) {
46
- return new CliError.UserError({
47
- cause: new Error(message),
48
- userMessage: message
49
- });
50
- }
51
- /** The usage block, with the sentence that asked for it — what the runner renders for a bad line. */
52
- function showHelp(commandPath, message) {
53
- return new CliError.ShowHelp({
54
- commandPath: [...commandPath],
55
- errors: [userError(message)]
56
- });
57
- }
44
+ const DatabaseUrl = Schema.String.pipe(Schema.check(Schema.isPattern(/^(?:postgres|postgresql|mysql|file):/u, { message: "a postgres://, postgresql://, mysql:// or file: connection string" })));
58
45
  /**
59
46
  * The explicit schema when it exists, else the first default path that does.
60
47
  *
@@ -66,16 +53,15 @@ function resolveSchemaPath(explicit, commandPath) {
66
53
  return Effect.gen(function* () {
67
54
  if (explicit !== null) {
68
55
  if (yield* exists(explicit)) return explicit;
69
- return yield* userError(`Schema not found: ${explicit}\n Check the path passed to --schema.`);
56
+ return yield* new CliError.UserError({ cause: `Schema not found: ${explicit}\n Check the path passed to --schema.` });
70
57
  }
71
58
  for (const candidate of DEFAULT_SCHEMA_PATHS) if (yield* exists(candidate)) return candidate;
72
- return yield* showHelp(commandPath, `No Prisma schema found (looked for ${DEFAULT_SCHEMA_PATHS.join(", ")}).\n Pass --schema <path> to point at your schema.prisma or a directory of .prisma files.`);
59
+ return yield* new CliError.ShowHelp({
60
+ commandPath: [...commandPath],
61
+ errors: [new CliError.UserError({ cause: `No Prisma schema found (looked for ${DEFAULT_SCHEMA_PATHS.join(", ")}).\n Pass --schema <path> to point at your schema.prisma or a directory of .prisma files.` })]
62
+ });
73
63
  });
74
64
  }
75
- /** Every way the server can refuse to start, as the one sentence the runner prints. */
76
- function startError(error) {
77
- return error instanceof ServerListenError && error.code === "EADDRINUSE" ? userError(`Port ${error.port} is already in use. Pass -p <port> to use another port.`) : userError(error.message);
78
- }
79
65
  function studioBanner(options) {
80
66
  return [
81
67
  `⚡️ Hekireki Studio started at http://localhost:${options.port}`,
@@ -84,32 +70,21 @@ function studioBanner(options) {
84
70
  ...options.error === null ? [] : [` Schema has errors, fix them and Studio will reload:\n${options.error}`]
85
71
  ].join("\n");
86
72
  }
87
- /**
88
- * The command line itself: what Studio accepts, what each piece means, and the schema every
89
- * value is decoded through before the handler below ever sees it.
90
- */
91
73
  const studioFlags = {
92
74
  port: Flag.integer("port").pipe(Flag.withAlias("p"), Flag.withSchema(Config.Port), Flag.withDescription(`Port to listen on (default: ${DEFAULT_PORT})`), Flag.withMetavar("port"), Flag.withDefault(DEFAULT_PORT)),
93
75
  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.optional),
94
- url: Flag.string("url").pipe(Flag.withAlias("u"), Flag.withSchema(databaseUrlSchema), Flag.withDescription("Database connection URL for browsing and editing data (default: DATABASE_URL from the environment or .env, then datasource.url in prisma.config.ts)"), Flag.withMetavar("connection-string"), Flag.optional)
76
+ 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.optional)
95
77
  };
96
- /**
97
- * Studio itself, listening until it is interrupted.
98
- *
99
- * It pulls in Hono, the Prisma schema engine and the database drivers. `--help`, `--version`,
100
- * `--completions` and every rejected command line must not pay for that, so it is imported here
101
- * rather than at module scope.
102
- */
103
78
  function runStudio(args) {
104
79
  return Effect.gen(function* () {
105
80
  const schemaPath = yield* resolveSchemaPath(Option.getOrNull(args.schema), [COMMAND_NAME, "studio"]);
106
- const { startStudioServer } = yield* Effect.promise(() => import("../start-EKGd2Tvk.js"));
81
+ const { startStudioServer } = yield* Effect.promise(() => import("../start-CHsK9ngN.js"));
107
82
  const started = yield* startStudioServer({
108
83
  schemaPath,
109
84
  port: args.port,
110
85
  staticDir: STATIC_DIR,
111
86
  databaseUrl: Option.getOrNull(args.url)
112
- }).pipe(Effect.mapError(startError));
87
+ }).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 })));
113
88
  yield* Console.log(studioBanner({
114
89
  port: args.port,
115
90
  schemaPath,
@@ -137,31 +112,168 @@ const studio = Command.make("studio", studioFlags, runStudio).pipe(Command.withD
137
112
  description: "Listen on another port"
138
113
  }
139
114
  ]));
140
- /** The `hekireki` command tree; run it with {@link hekirekiCli}. */
141
- const cli = Command.make(COMMAND_NAME).pipe(Command.withDescription("⚡️ Prisma schema tools"), Command.withSubcommands([studio]));
142
- /**
143
- * `help` spelled as Effect's own `--help` action, wherever it sits in the command path: `hekireki
144
- * help`, `hekireki help studio` and `hekireki studio help` all render the document the CLI already
145
- * builds, so there is no second copy of the help text to keep in step with the commands.
146
- *
147
- * Only the words before the first flag are a command path, so a value that happens to read `help`
148
- * (`--schema help`) is left alone.
149
- */
150
- function helpAsFlag(args) {
151
- const flag = args.findIndex((arg) => arg.startsWith("-"));
152
- const at = (flag === -1 ? args : args.slice(0, flag)).indexOf("help");
153
- return at === -1 ? args : [
154
- ...args.slice(0, at),
155
- ...args.slice(at + 1),
156
- "--help"
157
- ];
115
+ const seedFlags = {
116
+ 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.optional),
117
+ 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.optional),
118
+ 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.optional),
119
+ sql: Flag.string("sql").pipe(Flag.withDescription("Write the rows to this SQL file instead of inserting them"), Flag.withMetavar("seed.sql"), Flag.optional),
120
+ seed: Flag.integer("seed").pipe(Flag.withDescription("The faker seed; the same seed always gives the same rows (left out: every run differs)"), Flag.withMetavar("n"), Flag.optional),
121
+ count: Flag.integer("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.optional),
122
+ 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.optional),
123
+ reset: Flag.boolean("reset").pipe(Flag.withDescription("Delete every row of the seeded tables before inserting"), Flag.withDefault(false))
124
+ };
125
+ function runSeedCommand(args) {
126
+ return Effect.gen(function* () {
127
+ const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-DBKTGE9q.js"));
128
+ const report = yield* runSeed({
129
+ config: Option.getOrNull(args.config),
130
+ schema: Option.getOrNull(args.schema),
131
+ url: Option.getOrNull(args.url),
132
+ output: Option.getOrNull(args.sql),
133
+ seed: Option.getOrNull(args.seed),
134
+ count: Option.getOrNull(args.count),
135
+ locale: Option.getOrNull(args.locale),
136
+ reset: args.reset
137
+ }, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
138
+ yield* Console.log(seedBanner(report));
139
+ });
158
140
  }
159
- /**
160
- * Runs `hekireki` against an argument list: parsing, validation, `--help`, `--version` and shell
161
- * completions are owned by `effect/unstable/cli`, the commands above are the rest.
162
- */
141
+ const seed = Command.make("seed", seedFlags, runSeedCommand).pipe(Command.withDescription("Fill the database with faker rows that follow the schema: relations, enums, unique keys and date ranges"), Command.withExamples([
142
+ {
143
+ command: `${COMMAND_NAME} seed`,
144
+ description: "Read hekireki.config.ts and insert into the database named by DATABASE_URL"
145
+ },
146
+ {
147
+ command: `${COMMAND_NAME} seed --sql prisma/seed.sql`,
148
+ description: "Write the same rows as a SQL script instead of inserting them"
149
+ },
150
+ {
151
+ command: `${COMMAND_NAME} seed --reset --seed 7 --count 100`,
152
+ description: "Empty the seeded tables first, then insert 100 rows per model from seed 7"
153
+ },
154
+ {
155
+ command: `${COMMAND_NAME} seed --locale ja`,
156
+ description: "Japanese names, addresses and text"
157
+ }
158
+ ]));
159
+ const migrateCheckFlags = {
160
+ 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.optional),
161
+ 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.optional),
162
+ 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.optional),
163
+ timeout: Flag.integer("timeout").pipe(Flag.withDescription("How long one query may run, in milliseconds, on PostgreSQL and MySQL (default: no limit)"), Flag.withMetavar("ms"), Flag.optional),
164
+ json: Flag.boolean("json").pipe(Flag.withDescription("Print the report as JSON, every check with its count and SQL"), Flag.withDefault(false))
165
+ };
166
+ /** The command line of `migrate check` as the runner reads it. */
167
+ function migrateInput(args, schemaPath) {
168
+ return {
169
+ schemaPath,
170
+ url: Option.getOrNull(args.url),
171
+ decisions: Option.getOrNull(args.decisions),
172
+ timeout: Option.getOrNull(args.timeout),
173
+ cwd: process.cwd(),
174
+ env: process.env
175
+ };
176
+ }
177
+ /** Why the data is not ready, as the command fails with it. */
178
+ function notReady(summary) {
179
+ 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.`;
180
+ }
181
+ function runMigrateCheckCommand(args) {
182
+ return Effect.gen(function* () {
183
+ const schemaPath = yield* resolveSchemaPath(Option.getOrNull(args.schema), [
184
+ COMMAND_NAME,
185
+ "migrate",
186
+ "check"
187
+ ]);
188
+ const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-D_qSZohK.js"));
189
+ const report = yield* runMigrateCheck(migrateInput(args, schemaPath)).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
190
+ yield* Console.log(args.json ? checkJson(report) : checkBanner(report));
191
+ const summary = summarize(report);
192
+ if (!summary.ok) yield* new CliError.UserError({ cause: notReady(summary) });
193
+ });
194
+ }
195
+ const migrateCheck = Command.make("check", migrateCheckFlags, runMigrateCheckCommand).pipe(Command.withDescription("Check the rows of the database against the schema about to be migrated: NULLs in a column turning required, duplicates under a new unique key, orphans of a foreign key, values an enum drops, and the data a dropped table or column takes with it. Read only; fails when something blocks."), Command.withExamples([
196
+ {
197
+ command: `${COMMAND_NAME} migrate check`,
198
+ description: "Check the edited schema against the database named by DATABASE_URL"
199
+ },
200
+ {
201
+ command: `${COMMAND_NAME} migrate check --url postgresql://readonly@prod/app`,
202
+ description: "Check the production data before `prisma migrate deploy` runs on it"
203
+ },
204
+ {
205
+ command: `${COMMAND_NAME} migrate check --json`,
206
+ description: "A report for CI: every check, its count and the SQL that counted it"
207
+ },
208
+ {
209
+ command: `${COMMAND_NAME} migrate check --timeout 30000`,
210
+ description: "Stop any query that runs longer than 30 seconds"
211
+ }
212
+ ]));
213
+ const migratePlanFlags = {
214
+ schema: migrateCheckFlags.schema,
215
+ url: migrateCheckFlags.url,
216
+ decisions: migrateCheckFlags.decisions,
217
+ timeout: migrateCheckFlags.timeout,
218
+ 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.optional),
219
+ batch: Flag.integer("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.optional),
220
+ 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.optional)
221
+ };
222
+ function runMigratePlanCommand(args) {
223
+ return Effect.gen(function* () {
224
+ const schemaPath = yield* resolveSchemaPath(Option.getOrNull(args.schema), [
225
+ COMMAND_NAME,
226
+ "migrate",
227
+ "plan"
228
+ ]);
229
+ const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-D_qSZohK.js"));
230
+ const report = yield* runMigrateCheck(migrateInput(args, schemaPath)).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
231
+ const migrationPath = Option.getOrNull(args.migration);
232
+ const migration = migrationPath === null ? null : yield* readMigration(path.resolve(migrationPath)).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
233
+ const batch = Option.getOrNull(args.batch);
234
+ if (batch !== null && batch < 1) yield* new CliError.UserError({ cause: "--batch takes a number of rows, 1 or more." });
235
+ const { sql, errors, notes } = planSql(report, migration, batch);
236
+ if (errors.length > 0) yield* new CliError.UserError({ cause: errors.join("\n") });
237
+ const output = Option.getOrNull(args.output);
238
+ const noted = notes.map((note) => ` ${note}`).join("\n");
239
+ if (output === null) {
240
+ yield* Console.log(sql.trimEnd());
241
+ yield* Console.error(noted);
242
+ } else {
243
+ const file = path.resolve(output);
244
+ yield* writePlan(sql, file).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
245
+ yield* Console.log(`${checkBanner(report)}\n\n Plan: ${file}\n${noted}`);
246
+ }
247
+ const summary = summarize(report);
248
+ if (!summary.ok) yield* new CliError.UserError({ cause: notReady(summary) });
249
+ });
250
+ }
251
+ const migratePlan = Command.make("plan", migratePlanFlags, runMigratePlanCommand).pipe(Command.withDescription("Write the fixes decided on the Migrate page of hekireki studio as SQL to run before the migration: the UPDATEs and DELETEs `migrate check` counted them by. With --migration, the whole migration Prisma wrote, the fixes first and the renames, conversions, fills and new enum members written into it. Reads the database, writes nothing to it; fails when something still blocks."), Command.withExamples([
252
+ {
253
+ command: `${COMMAND_NAME} migrate plan > fixes.sql`,
254
+ description: "The SQL on stdout, to paste at the top of the migration Prisma writes"
255
+ },
256
+ {
257
+ command: `${COMMAND_NAME} migrate plan -o prisma/fixes.sql`,
258
+ description: "Write it to a file and print the report of the check"
259
+ },
260
+ {
261
+ command: `${COMMAND_NAME} migrate plan -m prisma/migrations/20260915_rename/migration.sql -o prisma/migrations/20260915_rename/migration.sql`,
262
+ description: "Rewrite the migration Prisma wrote: the fixes first, renames, conversions and fills in its statements"
263
+ },
264
+ {
265
+ command: `${COMMAND_NAME} migrate plan --batch 10000 -o prisma/fixes.sql`,
266
+ description: "On a large table in use: a fix over more than 10000 rows runs 10000 at a time"
267
+ }
268
+ ]));
269
+ const migrate = Command.make("migrate").pipe(Command.withDescription("Data checks and fixes for a schema migration"), Command.withSubcommands([migrateCheck, migratePlan]));
270
+ const cli = Command.make(COMMAND_NAME).pipe(Command.withDescription("⚡️ Prisma schema tools"), Command.withSubcommands([
271
+ studio,
272
+ seed,
273
+ migrate
274
+ ]));
163
275
  function hekirekiCli(argv, config) {
164
- return Command.runWith(cli, config)(helpAsFlag(argv));
276
+ return Command.runWith(cli, config)(argv);
165
277
  }
166
278
  /** The entry point the bin runs, reading its arguments the way `Command.run` does. */
167
279
  function hekireki(config) {
@@ -173,4 +285,4 @@ function hekireki(config) {
173
285
  //#region src/bin/hekireki.ts
174
286
  NodeRuntime.runMain(hekireki({ version }).pipe(Effect.provide(NodeServices.layer)));
175
287
  //#endregion
176
- export { FormatError as a, SchemaParseError as c, UnknownModelError as d, FORBIDDEN_HOST_MESSAGE as f, STUDIO_HOSTNAME as h, FileWriteError as i, ServerListenError as l, SSE_PING_MS as m, DatabaseError as n, InvalidInputError as o, PRISMA_FILE_URI as p, DatabaseUnavailableError as r, SchemaLoadError as s, ContractViolationError as t, UnknownFileError as u };
288
+ export { PRISMA_FILE_URI as _, DatabaseError as a, FormatError as c, SchemaParseError as d, ServerListenError as f, MIGRATIONS_POLL_MS as g, FORBIDDEN_HOST_MESSAGE as h, ContractViolationError as i, InvalidInputError as l, UnknownModelError as m, ClientQueryError as n, DatabaseUnavailableError as o, UnknownFileError as p, ClientUnavailableError as r, FileWriteError as s, DEFAULT_SCHEMA_PATHS as t, SchemaLoadError as u, SSE_PING_MS as v, STUDIO_HOSTNAME as y };
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/kysely.ts
4
4
  registerGenerator("kysely");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/pydantic.ts
4
4
  registerGenerator("pydantic");
5
5
  //#endregion
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-DxYpJikH.js";
2
+ import { t as registerGenerator } from "../bin-_yRLzidS.js";
3
3
  //#region src/bin/sea-orm.ts
4
4
  registerGenerator("sea-orm");
5
5
  //#endregion