hekireki 0.50.0 → 0.52.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 +115 -0
- 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-CPGRsAFR.js → bin-BcqPhgiX.js} +1149 -65
- package/dist/{discover-BOxkoGMk.js → discover-BKlX-LLS.js} +44 -34
- package/dist/{emit-CEF3yPYX.js → emit-BSQAIFiF.js} +2 -2
- package/dist/file-DOGnu_Q2.js +190 -0
- package/dist/{migrate-DMq3xNH-.js → migrate-BS6d_8aA.js} +4 -4
- package/dist/{native-engine-CY0OVgi3.js → native-engine-DcZUEqO8.js} +3 -3
- package/dist/{plan-5FxkaGBO.js → plan-BMypogKp.js} +323 -152
- package/dist/{run-Bs1aLLKy.js → run-BYq7BEVd.js} +6 -6
- package/dist/{schema-B_l4tAqI.js → schema-B7beUJic.js} +93 -49
- package/dist/{sql-DFjtK_8B.js → sql-BwL2BncN.js} +24 -24
- package/dist/{start-B9nw7W-E.js → start-s1j4PqUM.js} +12 -10
- package/package.json +16 -7
- package/dist/file-BAVQ-zst.js +0 -71
package/README.md
CHANGED
|
@@ -111,6 +111,108 @@ Every generator keeps Prisma's names: a model or field without `@map` keeps the
|
|
|
111
111
|
schema, and each ORM is told so where its own convention would say otherwise. Active Record and Ecto
|
|
112
112
|
take `///` lines of their own, described below.
|
|
113
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`, `jwks`, `cloudflare-access`), `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
|
+
`GET /users` answers a page: `limit` rows (20 by default, at most 100) after `offset`, in the
|
|
142
|
+
order of the key, and the number of rows in all in the `X-Total-Count` header. No request reads a
|
|
143
|
+
whole table.
|
|
144
|
+
|
|
145
|
+
A `POST` or a `PATCH` takes only the fields a client may write. A field the server fills is left
|
|
146
|
+
out: `@updatedAt`, and a `@default` the database or Prisma makes (`autoincrement()`, `now()`,
|
|
147
|
+
`uuid()`, `cuid()`, `ulid()`, `nanoid()`, `dbgenerated()`); a plain `@default("user")` is not. A
|
|
148
|
+
`///` line keeps any other field from the API: `@api.readonly` answers it and never takes it,
|
|
149
|
+
`@api.hidden` neither answers nor takes it, and every query omits it. Zod drops a field its schema
|
|
150
|
+
does not have, so a request that sends one changes nothing.
|
|
151
|
+
|
|
152
|
+
```prisma
|
|
153
|
+
model User {
|
|
154
|
+
id Int @id @default(autoincrement()) // answered, never taken
|
|
155
|
+
email String @unique
|
|
156
|
+
/// @api.readonly
|
|
157
|
+
role String @default("user") // answered, never taken
|
|
158
|
+
/// @api.hidden
|
|
159
|
+
passwordHash String // neither answered nor taken
|
|
160
|
+
createdAt DateTime @default(now()) // answered, never taken
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
A required field the API never takes and that has no `@default` (`passwordHash` above) leaves
|
|
165
|
+
`POST /users` unable to make a row: such a model is created by a handler of your own.
|
|
166
|
+
|
|
167
|
+
With `auth`, every operation asks for a token (`bearerAuth` in the document, `cloudflareAccess`
|
|
168
|
+
for `cloudflare-access`, and a 401 and a 403 among its answers), and the app entry runs `auth` on every model's paths, `app.use('/users/*', auth)`.
|
|
169
|
+
`auth.ts`, written when it is not there and left as it is after, checks the token; a handler reads
|
|
170
|
+
its payload with `c.get('jwtPayload')`. A guard of a model's paths that is not in the app entry is
|
|
171
|
+
added again when the generator runs.
|
|
172
|
+
|
|
173
|
+
| `auth` | The token | Environment |
|
|
174
|
+
| ------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------ |
|
|
175
|
+
| `jwks` | Signed by an issuer with a key it publishes (RS256, PS256, ES256, EdDSA) | `JWKS_URI`, `JWT_ISSUER`, `JWT_AUDIENCE` |
|
|
176
|
+
| `jwt` | Signed with HS256 by a secret the app shares with the issuer | `JWT_SECRET`, `JWT_ISSUER`, `JWT_AUDIENCE` |
|
|
177
|
+
| `cloudflare-access` | Put in `Cf-Access-Jwt-Assertion` by Cloudflare Access, signed with RS256 by a key the team publishes | `CF_ACCESS_TEAM_DOMAIN`, `CF_ACCESS_AUD` |
|
|
178
|
+
|
|
179
|
+
Whatever the kind, a token passes only with the `iss` and `aud` named, and with an `exp`: Hono checks `exp`
|
|
180
|
+
only when a token has it, so `auth.ts` refuses one without it, which would never expire. A missing
|
|
181
|
+
variable fails every request with 500 rather than let one through.
|
|
182
|
+
|
|
183
|
+
With `jwt` and `jwks`, the API writes every model, so a valid token also has to hold the `admin`
|
|
184
|
+
role, in its `role` claim (a string or an array of strings), or it is answered 403. `REQUIRED_ROLES` and `ROLE_CLAIM` in
|
|
185
|
+
`auth.ts` say which roles and which claim (an identity provider may put roles under a claim of its
|
|
186
|
+
own, such as `https://example.com/roles`); an empty `REQUIRED_ROLES` lets any valid token through.
|
|
187
|
+
|
|
188
|
+
`jwks` is safer than `jwt`: the app holds no key that signs a token, and the issuer (an identity
|
|
189
|
+
provider such as Auth0, Clerk or Okta) rotates and revokes them. `JWKS_URI` is https
|
|
190
|
+
(http only on `localhost`); the keys are cached for ten minutes and fetched again for a `kid` the
|
|
191
|
+
cache lacks, at most once a minute.
|
|
192
|
+
|
|
193
|
+
`cloudflare-access` is for an app behind
|
|
194
|
+
[Cloudflare Access](https://developers.cloudflare.com/cloudflare-one/policies/access/), on Workers
|
|
195
|
+
or behind a Cloudflare Tunnel. `CF_ACCESS_TEAM_DOMAIN` is the team domain
|
|
196
|
+
(`https://<team>.cloudflareaccess.com`), the token's `iss`, and `CF_ACCESS_AUD` the application's
|
|
197
|
+
Application Audience (AUD) tag. The keys come from `<team domain>/cdn-cgi/access/certs`, cached as
|
|
198
|
+
with `jwks`. Access's token carries no role, since its policy decides who passes, so
|
|
199
|
+
`REQUIRED_ROLES` starts empty there. The signature is checked all the same, so a request that
|
|
200
|
+
reaches the app around Access (its `workers.dev` URL, the origin's own address) is refused. The
|
|
201
|
+
document names the header (`cloudflareAccess`) rather than a bearer token.
|
|
202
|
+
|
|
203
|
+
With `jwt`, `JWT_SECRET` is at least 32 bytes (`openssl rand -base64 48`), shared with nothing but
|
|
204
|
+
the issuer, and a token lives at most an hour from its `iat` (`MAX_TOKEN_LIFETIME_SECONDS` in
|
|
205
|
+
`auth.ts`). A token cannot be taken back before its `exp`; only a new secret ends every token.
|
|
206
|
+
|
|
207
|
+
An `auth.ts` written by a release before 0.52.0 lets through a token without `exp`, and does not
|
|
208
|
+
check `iss`, `aud` or a role. Delete it and run the generator to have the current one, then set the
|
|
209
|
+
variables above.
|
|
210
|
+
|
|
211
|
+
A handler that has a body is kept when the generator runs again, as Hono Takibi keeps it, so a
|
|
212
|
+
handler changed by hand stays as it is; only an empty one is filled. A `BigInt` is answered as a
|
|
213
|
+
number and `Bytes` as base64, which the handler encodes and decodes with `Buffer`. `hono-takibi`
|
|
214
|
+
is a peer dependency: `npm install -D hono-takibi`.
|
|
215
|
+
|
|
114
216
|
### Active Record
|
|
115
217
|
|
|
116
218
|
`hekireki-activerecord` writes `app/models` from the schema: `application_record.rb` and one model
|
|
@@ -290,6 +392,19 @@ Your schema and database in the browser, on SQLite, PostgreSQL and MySQL. Withou
|
|
|
290
392
|
reads the `schema` of `prisma.config.ts`, else `./prisma/schema.prisma` or `./schema.prisma`, and
|
|
291
393
|
listens on port 5555.
|
|
292
394
|
|
|
395
|
+
The database driver is your project's own: `pg` for PostgreSQL (Neon, Supabase, PlanetScale
|
|
396
|
+
Postgres), `mysql2` for MySQL (PlanetScale), the built-in `node:sqlite` for a SQLite file, and
|
|
397
|
+
`@libsql/client` for a libSQL server (Turso, or `sqld`). A token in the URL is shown as `***`.
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
npx hekireki studio --url "postgresql://user:pass@ep-x.neon.tech/app?sslmode=require"
|
|
401
|
+
npx hekireki studio --url 'mysql://user:pass@aws.connect.psdb.cloud/app?ssl={"rejectUnauthorized":true}'
|
|
402
|
+
npx hekireki studio --url "libsql://app-org.turso.io?authToken=$TURSO_AUTH_TOKEN"
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
On a libSQL server, the Migrate page takes no backup and runs no rehearsal: both copy the database
|
|
406
|
+
file, which is not here. The service's own point-in-time restore takes the backup's place.
|
|
407
|
+
|
|
293
408
|
**Browse the rows** of each model: search, add, edit and export them.
|
|
294
409
|
|
|
295
410
|

|
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.52.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-s1j4PqUM.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-BYq7BEVd.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-BS6d_8aA.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-BS6d_8aA.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