hekireki 0.10.2 → 0.20.1
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 +179 -1189
- 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/effect.js +1 -1
- package/dist/bin/eloquent.js +1 -1
- package/dist/bin/er.js +6 -0
- package/dist/bin/gorm.js +1 -1
- package/dist/bin/hekireki.js +176 -0
- 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/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-9aHkP_Bs.js → bin-CPb5ZV8W.js} +1436 -1751
- package/dist/file-yN0By3gn.js +48 -0
- package/dist/schema-DwMNeEei.js +823 -0
- package/dist/start-Blp4k61D.js +5764 -0
- package/dist/studio/assets/cells-lAj-v64A.js +2 -0
- package/dist/studio/assets/codicon-Brq4_Ui5.ttf +0 -0
- package/dist/studio/assets/docs-CpeTt3O2.js +34 -0
- package/dist/studio/assets/editor.worker-D9zwrD0f.js +30 -0
- package/dist/studio/assets/enums._name-My5PypWw.js +1 -0
- package/dist/studio/assets/hooks-CiUANSpJ.js +1 -0
- package/dist/studio/assets/index-C4wWEcwe.js +188 -0
- package/dist/studio/assets/index-ZSt1ppSG.css +2 -0
- package/dist/studio/assets/labels-DBXIkmbm.js +1 -0
- package/dist/studio/assets/lazyRouteComponent-DmCXXiGp.js +1 -0
- package/dist/studio/assets/models._name-oUX64rwK.js +1 -0
- package/dist/studio/assets/not-found-DxAsuyR5.js +1 -0
- package/dist/studio/assets/prisma-Bk53qnxm.js +891 -0
- package/dist/studio/assets/prisma-C2rAM-pV.css +1 -0
- package/dist/studio/assets/routes-ZmrohHNP.js +1 -0
- package/dist/studio/assets/schema-gate-DJ_-6NYR.js +1 -0
- package/dist/studio/assets/schema-view-BaoCWAL8.js +8 -0
- package/dist/studio/assets/sql-DpzkSc6F.js +1 -0
- package/dist/studio/assets/useMatch-D73HO_WB.js +1 -0
- package/dist/studio/index.html +16 -0
- package/package.json +55 -27
- package/dist/bin/dbml.js +0 -6
- package/dist/bin/docs.js +0 -6
- package/dist/bin/mermaid-er.d.ts +0 -1
- package/dist/bin/mermaid-er.js +0 -6
- package/dist/cli/index.d.ts +0 -138
- package/dist/cli/index.js +0 -134
- /package/dist/bin/{dbml.d.ts → er.d.ts} +0 -0
- /package/dist/bin/{docs.d.ts → hekireki.d.ts} +0 -0
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/effect.js
CHANGED
package/dist/bin/eloquent.js
CHANGED
package/dist/bin/er.js
ADDED
package/dist/bin/gorm.js
CHANGED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as exists } from "../file-yN0By3gn.js";
|
|
3
|
+
import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
4
|
+
import { Config, Console, Data, Effect, Option, Schema, Stdio } from "effect";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { CliError, Command, Flag } from "effect/unstable/cli";
|
|
7
|
+
//#region package.json
|
|
8
|
+
var version = "0.20.1";
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/studio/server/constants/index.ts
|
|
11
|
+
/** Studio only listens on loopback: the API serves the raw schema and runs SQL without authentication. */
|
|
12
|
+
const STUDIO_HOSTNAME = "127.0.0.1";
|
|
13
|
+
const DEFAULT_PORT = 5555;
|
|
14
|
+
const FORBIDDEN_HOST_MESSAGE = "Forbidden: Hekireki Studio only answers requests addressed to localhost.";
|
|
15
|
+
/** Keep-alive interval of the schema event stream. */
|
|
16
|
+
const SSE_PING_MS = 15e3;
|
|
17
|
+
/** The URI the Prisma language server sees for the single in-memory schema document. */
|
|
18
|
+
const PRISMA_FILE_URI = "file:///schema.prisma";
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/studio/server/errors/index.ts
|
|
21
|
+
var UnknownModelError = class extends Data.TaggedError("UnknownModelError") {};
|
|
22
|
+
var UnknownFileError = class extends Data.TaggedError("UnknownFileError") {};
|
|
23
|
+
var FileWriteError = class extends Data.TaggedError("FileWriteError") {};
|
|
24
|
+
var DatabaseUnavailableError = class extends Data.TaggedError("DatabaseUnavailableError") {};
|
|
25
|
+
var DatabaseError = class extends Data.TaggedError("DatabaseError") {};
|
|
26
|
+
var InvalidInputError = class extends Data.TaggedError("InvalidInputError") {};
|
|
27
|
+
var FormatError = class extends Data.TaggedError("FormatError") {};
|
|
28
|
+
var ContractViolationError = class extends Data.TaggedError("ContractViolationError") {};
|
|
29
|
+
var SchemaLoadError = class extends Data.TaggedError("SchemaLoadError") {};
|
|
30
|
+
var SchemaParseError = class extends Data.TaggedError("SchemaParseError") {};
|
|
31
|
+
var ServerListenError = class extends Data.TaggedError("ServerListenError") {};
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/cli/index.ts
|
|
34
|
+
const COMMAND_NAME = "hekireki";
|
|
35
|
+
/** Where `--schema` looks when it is omitted, in order. */
|
|
36
|
+
const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
|
|
37
|
+
const DATABASE_URL_SCHEMES = [
|
|
38
|
+
"postgres",
|
|
39
|
+
"postgresql",
|
|
40
|
+
"mysql",
|
|
41
|
+
"file"
|
|
42
|
+
];
|
|
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
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The explicit schema when it exists, else the first default path that does.
|
|
60
|
+
*
|
|
61
|
+
* A path that was typed out and is not there names itself, and the usage block would only bury
|
|
62
|
+
* it. Nothing typed and nothing found is the other case — the command was run somewhere without
|
|
63
|
+
* a schema — and there the usage block is the answer.
|
|
64
|
+
*/
|
|
65
|
+
function resolveSchemaPath(explicit, commandPath) {
|
|
66
|
+
return Effect.gen(function* () {
|
|
67
|
+
if (explicit !== null) {
|
|
68
|
+
if (yield* exists(explicit)) return explicit;
|
|
69
|
+
return yield* userError(`Schema not found: ${explicit}\n Check the path passed to --schema.`);
|
|
70
|
+
}
|
|
71
|
+
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.`);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
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
|
+
function studioBanner(options) {
|
|
80
|
+
return [
|
|
81
|
+
`⚡️ Hekireki Studio started at http://localhost:${options.port}`,
|
|
82
|
+
` Schema: ${path.resolve(options.schemaPath)} (watching for changes)`,
|
|
83
|
+
options.database.connected ? ` Database: ${options.database.dialect ?? ""} ${options.database.url ?? ""}`.trimEnd() : ` Database: not connected (schema only)\n ${options.database.error ?? ""}`.trimEnd(),
|
|
84
|
+
...options.error === null ? [] : [` Schema has errors, fix them and Studio will reload:\n${options.error}`]
|
|
85
|
+
].join("\n");
|
|
86
|
+
}
|
|
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
|
+
const studioFlags = {
|
|
92
|
+
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
|
+
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)
|
|
95
|
+
};
|
|
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
|
+
function runStudio(args) {
|
|
104
|
+
return Effect.gen(function* () {
|
|
105
|
+
const schemaPath = yield* resolveSchemaPath(Option.getOrNull(args.schema), [COMMAND_NAME, "studio"]);
|
|
106
|
+
const { startStudioServer } = yield* Effect.promise(() => import("../start-Blp4k61D.js"));
|
|
107
|
+
const started = yield* startStudioServer({
|
|
108
|
+
schemaPath,
|
|
109
|
+
port: args.port,
|
|
110
|
+
staticDir: STATIC_DIR,
|
|
111
|
+
databaseUrl: Option.getOrNull(args.url)
|
|
112
|
+
}).pipe(Effect.mapError(startError));
|
|
113
|
+
yield* Console.log(studioBanner({
|
|
114
|
+
port: args.port,
|
|
115
|
+
schemaPath,
|
|
116
|
+
error: started.snapshot.error,
|
|
117
|
+
database: started.database
|
|
118
|
+
}));
|
|
119
|
+
yield* Effect.never;
|
|
120
|
+
}).pipe(Effect.scoped);
|
|
121
|
+
}
|
|
122
|
+
const studio = Command.make("studio", studioFlags, runStudio).pipe(Command.withDescription("Open Hekireki Studio: ER diagram, docs, model data and SQL for a Prisma schema"), Command.withExamples([
|
|
123
|
+
{
|
|
124
|
+
command: `${COMMAND_NAME} studio`,
|
|
125
|
+
description: `Open ./${DEFAULT_SCHEMA_PATHS[0]}, with the database URL from .env`
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
command: `${COMMAND_NAME} studio --schema prisma/schema`,
|
|
129
|
+
description: "Read a multi-file schema: every .prisma file of the directory, together"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
command: `${COMMAND_NAME} studio --url file:./dev.db`,
|
|
133
|
+
description: "Browse a SQLite file, resolved from the schema directory as Prisma resolves it"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
command: `${COMMAND_NAME} studio -p 3000`,
|
|
137
|
+
description: "Listen on another port"
|
|
138
|
+
}
|
|
139
|
+
]));
|
|
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
|
+
];
|
|
158
|
+
}
|
|
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
|
+
*/
|
|
163
|
+
function hekirekiCli(argv, config) {
|
|
164
|
+
return Command.runWith(cli, config)(helpAsFlag(argv));
|
|
165
|
+
}
|
|
166
|
+
/** The entry point the bin runs, reading its arguments the way `Command.run` does. */
|
|
167
|
+
function hekireki(config) {
|
|
168
|
+
return Effect.gen(function* () {
|
|
169
|
+
return yield* hekirekiCli(yield* (yield* Stdio.Stdio).args, config);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/bin/hekireki.ts
|
|
174
|
+
NodeRuntime.runMain(hekireki({ version }).pipe(Effect.provide(NodeServices.layer)));
|
|
175
|
+
//#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 };
|
package/dist/bin/kysely.js
CHANGED
package/dist/bin/pydantic.js
CHANGED
package/dist/bin/sea-orm.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