hekireki 0.49.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -4
- 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/docs.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 +18 -12
- package/dist/bin/kysely.js +1 -1
- package/dist/bin/openapi.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-openapi-hono.d.ts +1 -0
- package/dist/bin/zod-openapi-hono.js +5 -0
- package/dist/bin/zod.js +1 -1
- package/dist/{bin-BwEbmAZJ.js → bin-DqjEDWJu.js} +928 -126
- package/dist/{discover-Cl2bvBbf.js → discover-C0ef4bHT.js} +44 -34
- package/dist/{emit-B34moVCH.js → emit-Cz3yGQN2.js} +2 -2
- package/dist/file-DOGnu_Q2.js +190 -0
- package/dist/{migrate-Br4Ihwix.js → migrate-CdaZW-P-.js} +4 -4
- package/dist/{native-engine-Chz7hHRS.js → native-engine-DcCamR8F.js} +3 -3
- package/dist/{plan-D02O7uP9.js → plan-P2yzjNsy.js} +323 -152
- package/dist/{run-C1XOA4x-.js → run-CiIfED-2.js} +6 -6
- package/dist/{schema-E_PyiUp_.js → schema-CRiLGfEP.js} +112 -49
- package/dist/{sql-U9Fo2g8L.js → sql-BDYu__ri.js} +24 -24
- package/dist/{start-Dez8JNe5.js → start-Cc_4AkrJ.js} +12 -10
- package/package.json +16 -3
- package/dist/file-BAVQ-zst.js +0 -71
package/README.md
CHANGED
|
@@ -37,6 +37,12 @@ model User {
|
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
The rest of a `///` comment, the prose without those lines, is written into the code each
|
|
41
|
+
generator emits, above the model, the field or the enum it documents, as a comment of that
|
|
42
|
+
language: JSDoc in TypeScript, docstrings in Python, `//` in Go, `///` in Rust, `<summary>` in C#,
|
|
43
|
+
KDoc in Kotlin, PHPDoc in PHP (a column's as its `@property` tag), `@moduledoc` and `#` in Elixir,
|
|
44
|
+
and `#` in Ruby (a column's as an entry `name:: prose` above the class) and in Atlas HCL.
|
|
45
|
+
|
|
40
46
|
## Generators
|
|
41
47
|
|
|
42
48
|
The `provider` of the generator block picks the output. Every option is optional.
|
|
@@ -102,10 +108,47 @@ are shown as code. Nothing connects to a database for either.
|
|
|
102
108
|
is such a directory.
|
|
103
109
|
|
|
104
110
|
Every generator keeps Prisma's names: a model or field without `@map` keeps the name it has in the
|
|
105
|
-
schema, and each ORM is told so where its own convention would say otherwise.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
schema, and each ORM is told so where its own convention would say otherwise. Active Record and Ecto
|
|
112
|
+
take `///` lines of their own, described below.
|
|
113
|
+
|
|
114
|
+
### API
|
|
115
|
+
|
|
116
|
+
| Provider | Writes | Options |
|
|
117
|
+
| --------------------------- | ------------------------------------------ | --------------------------------------------------------- |
|
|
118
|
+
| `hekireki-zod-openapi-hono` | Hono app of the CRUD (`@hono/zod-openapi`) | `prisma` (`./prisma`), `auth` (`jwt`), `title`, `version` |
|
|
119
|
+
|
|
120
|
+
`hekireki-zod-openapi-hono` writes, in the directory `output` names, `openapi.yaml`: the CRUD of
|
|
121
|
+
each model, `GET` and `POST /users` and `GET`, `PATCH` and `DELETE /users/{id}`, with the rows as
|
|
122
|
+
Prisma Client reads them, fields under their Prisma names. It then runs the template of
|
|
123
|
+
[Hono Takibi](https://github.com/nakita628/hono-takibi) on it, `routeHandler`, which writes the
|
|
124
|
+
routes and their Zod schemas in one file (`routes.ts`), a file of `RouteHandler`s per model
|
|
125
|
+
(`handlers/`) and the app that registers each route with its handler (`index.ts`), and fills each
|
|
126
|
+
handler with the call to Prisma Client: `prisma.user.findMany()`, `create`, and `findFirst`,
|
|
127
|
+
`updateMany` and `deleteMany` by the key, answering 404 for a key no row has. The handlers import
|
|
128
|
+
`prisma` from the module `prisma` names, as the app entry sees it; that module exports the client:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
// src/prisma.ts
|
|
132
|
+
import { PrismaPg } from '@prisma/adapter-pg'
|
|
133
|
+
|
|
134
|
+
import { PrismaClient } from './generated/prisma/client'
|
|
135
|
+
|
|
136
|
+
export const prisma = new PrismaClient({
|
|
137
|
+
adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }),
|
|
138
|
+
})
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
With `auth = "jwt"`, every operation asks for a bearer JWT (`bearerAuth` in the document, and a
|
|
142
|
+
401 among its answers), and the app entry runs `auth` on every model's paths,
|
|
143
|
+
`app.use('/users/*', auth)`. `auth.ts`, written when it is not there and left as it is after, lets
|
|
144
|
+
a request through with a JWT signed with HS256 by the secret `JWT_SECRET`, read from the runtime's
|
|
145
|
+
environment; a handler reads the token's payload with `c.get('jwtPayload')`. A guard of a model's
|
|
146
|
+
paths that is not in the app entry is added again when the generator runs.
|
|
147
|
+
|
|
148
|
+
A handler that has a body is kept when the generator runs again, as Hono Takibi keeps it, so a
|
|
149
|
+
handler changed by hand stays as it is; only an empty one is filled. A `BigInt` is answered as a
|
|
150
|
+
number and `Bytes` as base64, which the handler encodes and decodes with `Buffer`. `hono-takibi`
|
|
151
|
+
is a peer dependency: `npm install -D hono-takibi`.
|
|
109
152
|
|
|
110
153
|
### Active Record
|
|
111
154
|
|
|
@@ -286,6 +329,19 @@ Your schema and database in the browser, on SQLite, PostgreSQL and MySQL. Withou
|
|
|
286
329
|
reads the `schema` of `prisma.config.ts`, else `./prisma/schema.prisma` or `./schema.prisma`, and
|
|
287
330
|
listens on port 5555.
|
|
288
331
|
|
|
332
|
+
The database driver is your project's own: `pg` for PostgreSQL (Neon, Supabase, PlanetScale
|
|
333
|
+
Postgres), `mysql2` for MySQL (PlanetScale), the built-in `node:sqlite` for a SQLite file, and
|
|
334
|
+
`@libsql/client` for a libSQL server (Turso, or `sqld`). A token in the URL is shown as `***`.
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
npx hekireki studio --url "postgresql://user:pass@ep-x.neon.tech/app?sslmode=require"
|
|
338
|
+
npx hekireki studio --url 'mysql://user:pass@aws.connect.psdb.cloud/app?ssl={"rejectUnauthorized":true}'
|
|
339
|
+
npx hekireki studio --url "libsql://app-org.turso.io?authToken=$TURSO_AUTH_TOKEN"
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
On a libSQL server, the Migrate page takes no backup and runs no rehearsal: both copy the database
|
|
343
|
+
file, which is not here. The service's own point-in-time restore takes the backup's place.
|
|
344
|
+
|
|
289
345
|
**Browse the rows** of each model: search, add, edit and export them.
|
|
290
346
|
|
|
291
347
|

|
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/docs.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,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { s as readFile, t as exists } from "../file-
|
|
2
|
+
import { g as LIBSQL_SCHEMES, p as DIALECT_SCHEMES, s as readFile, t as exists } from "../file-DOGnu_Q2.js";
|
|
3
3
|
import { runMain } from "@effect/platform-node/NodeRuntime";
|
|
4
4
|
import { layer } from "@effect/platform-node/NodeServices";
|
|
5
5
|
import { Console, Data, Effect, Schema } from "effect";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { CliError, Command, Flag } from "effect/cli";
|
|
8
8
|
// package.json
|
|
9
|
-
var version = "0.
|
|
9
|
+
var version = "0.51.0";
|
|
10
10
|
// src/schema/path.ts
|
|
11
11
|
/** Where Prisma looks for a schema when neither the command nor prisma.config.ts names one. */
|
|
12
12
|
const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
|
|
@@ -74,6 +74,11 @@ const SSE_PING_MS = 15e3;
|
|
|
74
74
|
const PRISMA_FILE_URI = "file:///schema.prisma";
|
|
75
75
|
/** How often the migrations directory is read for a change. */
|
|
76
76
|
const MIGRATIONS_POLL_MS = 1e3;
|
|
77
|
+
// src/database/errors.ts
|
|
78
|
+
/** No database to talk to (no URL, no driver installed, or the connection refused); raised by the driver when it opens one. */
|
|
79
|
+
var DatabaseUnavailableError = class extends Data.TaggedError("DatabaseUnavailableError") {};
|
|
80
|
+
/** A statement the database driver rejected; raised by the driver and worded by whoever runs the statement. */
|
|
81
|
+
var DatabaseError = class extends Data.TaggedError("DatabaseError") {};
|
|
77
82
|
// src/studio/server/errors/index.ts
|
|
78
83
|
/** A model name the schema does not hold; raised by the database usecases before they touch a table. */
|
|
79
84
|
var UnknownModelError = class extends Data.TaggedError("UnknownModelError") {};
|
|
@@ -81,10 +86,6 @@ var UnknownModelError = class extends Data.TaggedError("UnknownModelError") {};
|
|
|
81
86
|
var UnknownFileError = class extends Data.TaggedError("UnknownFileError") {};
|
|
82
87
|
/** A schema file could not be written; raised by `writeSchemaFile`. */
|
|
83
88
|
var FileWriteError = class extends Data.TaggedError("FileWriteError") {};
|
|
84
|
-
/** No database to talk to (no URL, no driver installed, or the connection refused); raised by the database services when they open one. */
|
|
85
|
-
var DatabaseUnavailableError = class extends Data.TaggedError("DatabaseUnavailableError") {};
|
|
86
|
-
/** A statement the database driver rejected; raised by the database services and worded by the database usecases. */
|
|
87
|
-
var DatabaseError = class extends Data.TaggedError("DatabaseError") {};
|
|
88
89
|
/** The project's Prisma Client (or TypeScript, to check a query) could not be found or loaded; raised by the client and TypeScript services. */
|
|
89
90
|
var ClientUnavailableError = class extends Data.TaggedError("ClientUnavailableError") {};
|
|
90
91
|
/** A query the project's Prisma Client rejected or threw on; raised by the client service. */
|
|
@@ -102,7 +103,8 @@ var ServerListenError = class extends Data.TaggedError("ServerListenError") {};
|
|
|
102
103
|
// src/cli/index.ts
|
|
103
104
|
const COMMAND_NAME = "hekireki";
|
|
104
105
|
const STATIC_DIR = path.resolve(import.meta.dirname, "../studio");
|
|
105
|
-
const
|
|
106
|
+
const URL_SCHEMES = [...Object.values(DIALECT_SCHEMES).flat(), ...LIBSQL_SCHEMES];
|
|
107
|
+
const DatabaseUrl = Schema.String.pipe(Schema.check(Schema.isPattern(new RegExp(`^(?:${URL_SCHEMES.join("|")}):`, "u"), { message: "a postgres://, postgresql://, mysql://, file: or libsql:// connection string (http(s):// or ws(s):// for a libSQL server)" })));
|
|
106
108
|
/**
|
|
107
109
|
* The explicit schema when it exists, else the one Prisma itself reads: the `schema` of
|
|
108
110
|
* prisma.config.ts, then the first default path that exists.
|
|
@@ -147,7 +149,7 @@ const studioFlags = {
|
|
|
147
149
|
function runStudio(args) {
|
|
148
150
|
return Effect.gen(function* () {
|
|
149
151
|
const schemaPath = yield* resolveSchemaPath(args.schema, [COMMAND_NAME, "studio"]);
|
|
150
|
-
const { startStudioServer } = yield* Effect.promise(() => import("../start-
|
|
152
|
+
const { startStudioServer } = yield* Effect.promise(() => import("../start-Cc_4AkrJ.js"));
|
|
151
153
|
const started = yield* startStudioServer({
|
|
152
154
|
schemaPath,
|
|
153
155
|
port: args.port,
|
|
@@ -177,6 +179,10 @@ function studio() {
|
|
|
177
179
|
command: `${COMMAND_NAME} studio --url file:./dev.db`,
|
|
178
180
|
description: "Browse a SQLite file, resolved from the schema directory as Prisma resolves it"
|
|
179
181
|
},
|
|
182
|
+
{
|
|
183
|
+
command: `${COMMAND_NAME} studio --url "libsql://app-org.turso.io?authToken=$TURSO_AUTH_TOKEN"`,
|
|
184
|
+
description: "Browse a Turso database (or a libSQL server), through the project @libsql/client"
|
|
185
|
+
},
|
|
180
186
|
{
|
|
181
187
|
command: `${COMMAND_NAME} studio -p 3000`,
|
|
182
188
|
description: "Listen on another port"
|
|
@@ -195,7 +201,7 @@ const seedFlags = {
|
|
|
195
201
|
};
|
|
196
202
|
function runSeedCommand(args) {
|
|
197
203
|
return Effect.gen(function* () {
|
|
198
|
-
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-
|
|
204
|
+
const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-CiIfED-2.js"));
|
|
199
205
|
const report = yield* runSeed(args, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
|
|
200
206
|
yield* Console.log(seedBanner(report));
|
|
201
207
|
});
|
|
@@ -238,7 +244,7 @@ function runMigrateCheckCommand(args) {
|
|
|
238
244
|
"migrate",
|
|
239
245
|
"check"
|
|
240
246
|
]);
|
|
241
|
-
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-
|
|
247
|
+
const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-CdaZW-P-.js"));
|
|
242
248
|
const report = yield* runMigrateCheck({
|
|
243
249
|
...args,
|
|
244
250
|
schemaPath,
|
|
@@ -285,7 +291,7 @@ function runMigratePlanCommand(args) {
|
|
|
285
291
|
"migrate",
|
|
286
292
|
"plan"
|
|
287
293
|
]);
|
|
288
|
-
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-
|
|
294
|
+
const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-CdaZW-P-.js"));
|
|
289
295
|
const report = yield* runMigrateCheck({
|
|
290
296
|
...args,
|
|
291
297
|
schemaPath,
|
|
@@ -344,4 +350,4 @@ function hekireki() {
|
|
|
344
350
|
}
|
|
345
351
|
// src/bin/hekireki.ts
|
|
346
352
|
runMain(hekireki().pipe(Effect.provide(layer)));
|
|
347
|
-
export { STUDIO_HOSTNAME as _,
|
|
353
|
+
export { STUDIO_HOSTNAME as _, InvalidInputError as a, readPrismaConfig as b, ServerListenError as c, DatabaseError as d, DatabaseUnavailableError as f, SSE_PING_MS as g, PRISMA_FILE_URI as h, FormatError as i, UnknownFileError as l, MIGRATIONS_POLL_MS as m, ClientUnavailableError as n, SchemaLoadError as o, FORBIDDEN_HOST_MESSAGE as p, FileWriteError as r, SchemaParseError as s, ClientQueryError as t, UnknownModelError as u, DEFAULT_SCHEMA_PATHS as v, prismaSchemaPath as y };
|
package/dist/bin/kysely.js
CHANGED
package/dist/bin/openapi.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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/bin/zod.js
CHANGED