@profullstack/dbml 0.0.0-stage → 0.1.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 (4) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +35 -2
  3. package/bin/dbml.js +226 -0
  4. package/package.json +39 -4
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Profullstack, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # @profullstack/dbml
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The CLI and MCP stdio bridge for [dbml.db](https://dbml.db.pit.world): validate,
4
+ review and convert [DBML](https://dbml.dbdiagram.io/docs) database schemas from a
5
+ terminal or an AI agent. No dependencies.
6
+
7
+ ```sh
8
+ npm i -g @profullstack/dbml
9
+
10
+ dbml validate schema.dbml # errors as file:line:column
11
+ dbml review schema.dbml # lint + score; exit 1 on errors
12
+ dbml watch schema.dbml # re-review on every save
13
+ dbml to-sql schema.dbml --dialect mysql > schema.sql
14
+ dbml from-sql dump.sql --dialect postgres > schema.dbml
15
+ dbml summary schema.dbml
16
+ cat schema.dbml | dbml format -
17
+ dbml rules
18
+ dbml syntax
19
+ ```
20
+
21
+ `--json` prints the raw answer. `DBML_API` points at another server.
22
+
23
+ ## MCP
24
+
25
+ The hosted server speaks streamable HTTP at `https://dbml.db.pit.world/mcp`. For
26
+ clients that only do stdio:
27
+
28
+ ```json
29
+ { "mcpServers": { "dbml": { "command": "npx", "args": ["-y", "@profullstack/dbml", "mcp"] } } }
30
+ ```
31
+
32
+ Tools: validate_dbml, parse_dbml, summarize_dbml, review_dbml, format_dbml,
33
+ dbml_to_sql, sql_to_dbml, list_review_rules, dbml_syntax.
34
+
35
+ Source: https://github.com/profullstack/dbml.db · MIT · Parsing by
36
+ [@dbml/core](https://github.com/holistics/dbml) (Apache-2.0) on the server.
package/bin/dbml.js ADDED
@@ -0,0 +1,226 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dbml: the dbml.db CLI. Validate, review and convert DBML schemas from the
4
+ * terminal, or bridge the dbml.db MCP server to stdio for desktop assistants.
5
+ * Talks to https://dbml.db.pit.world (or $DBML_API). No dependencies.
6
+ */
7
+ import { readFileSync, watchFile } from 'node:fs';
8
+ import { createInterface } from 'node:readline';
9
+
10
+ const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
11
+ const API = (process.env.DBML_API || 'https://dbml.db.pit.world').replace(/\/$/, '');
12
+ const UA = `dbml-cli/${VERSION}`;
13
+
14
+ const HELP = `dbml ${VERSION}: DBML schemas for people and agents (${API})
15
+
16
+ usage:
17
+ dbml validate <file|-> syntax + semantic errors with line:column
18
+ dbml parse <file|-> JSON model (tables, columns, refs, enums)
19
+ dbml summary <file|-> counts and a per-table outline
20
+ dbml review <file|-> [--rules a,b] deterministic schema review, score 0-100
21
+ dbml format <file|-> canonical DBML
22
+ dbml to-sql <file|-> [--dialect postgres|mysql|mssql|oracle]
23
+ dbml from-sql <file|-> [--dialect postgres|mysql|mssql|oracle|snowflake|schemarb|json]
24
+ dbml watch <file> re-review on every save (terminal view)
25
+ dbml rules list the review rules
26
+ dbml syntax DBML cheat sheet
27
+ dbml mcp MCP over stdio (proxies ${API}/mcp)
28
+
29
+ flags:
30
+ --json print the raw JSON answer
31
+ --dialect SQL dialect (default postgres)
32
+
33
+ env:
34
+ DBML_API server (default https://dbml.db.pit.world)
35
+
36
+ exit codes: 0 ok, 1 invalid schema or review errors, 2 usage or network error`;
37
+
38
+ function args(argv) {
39
+ const out = { _: [], flags: {} };
40
+ for (let i = 0; i < argv.length; i++) {
41
+ const a = argv[i];
42
+ if (a === '-') out._.push(a);
43
+ else if (a.startsWith('--')) {
44
+ const [k, v] = a.slice(2).split('=');
45
+ if (v !== undefined) out.flags[k] = v;
46
+ else if (argv[i + 1] && !argv[i + 1].startsWith('--') && !['json', 'help', 'version'].includes(k)) out.flags[k] = argv[++i];
47
+ else out.flags[k] = true;
48
+ } else out._.push(a);
49
+ }
50
+ return out;
51
+ }
52
+
53
+ async function readSource(file) {
54
+ if (!file) throw usage('missing <file> (use - for stdin)');
55
+ if (file === '-') {
56
+ const chunks = [];
57
+ for await (const c of process.stdin) chunks.push(c);
58
+ return Buffer.concat(chunks).toString('utf8');
59
+ }
60
+ return readFileSync(file, 'utf8');
61
+ }
62
+
63
+ function usage(msg) {
64
+ const e = new Error(msg);
65
+ e.exit = 2;
66
+ return e;
67
+ }
68
+
69
+ async function call(method, path, body) {
70
+ let res;
71
+ try {
72
+ res = await fetch(API + path, {
73
+ method,
74
+ headers: { 'content-type': 'application/json', 'user-agent': UA, accept: 'application/json' },
75
+ body: body ? JSON.stringify(body) : undefined,
76
+ });
77
+ } catch (e) {
78
+ throw usage(`could not reach ${API}: ${e.message}`);
79
+ }
80
+ const type = res.headers.get('content-type') || '';
81
+ const data = type.includes('json') ? await res.json() : await res.text();
82
+ if (res.status === 429 || res.status === 402) throw usage(`rate limited (${res.status}); try again in a minute`);
83
+ if (res.status >= 400 && res.status !== 422) throw usage(data?.error || `HTTP ${res.status}`);
84
+ return data;
85
+ }
86
+
87
+ const loc = (e, file) => `${file && file !== '-' ? file : 'stdin'}:${e.line ?? '?'}:${e.column ?? '?'}`;
88
+ const color = process.stdout.isTTY && !process.env.NO_COLOR;
89
+ const paint = (code, s) => (color ? `\x1b[${code}m${s}\x1b[0m` : s);
90
+ const SEV = { error: (s) => paint('31', s), warning: (s) => paint('33', s), info: (s) => paint('36', s) };
91
+
92
+ function printErrors(errors, file) {
93
+ for (const e of errors) console.error(`${loc(e, file)} ${SEV.error('error')} ${e.message}`);
94
+ }
95
+
96
+ function printReview(r, file) {
97
+ if (!r.valid) {
98
+ printErrors(r.errors, file);
99
+ return 1;
100
+ }
101
+ for (const f of r.findings) {
102
+ const where = f.line ? `${file && file !== '-' ? file : 'stdin'}:${f.line}:${f.column_number ?? 1}` : '(schema)';
103
+ console.log(`${where} ${SEV[f.severity](f.severity.padEnd(7))} ${f.message} ${paint('2', `[${f.rule}]`)}`);
104
+ }
105
+ console.log(`\nscore ${r.score}/100: ${r.counts.error} errors, ${r.counts.warning} warnings, ${r.counts.info} info`);
106
+ return r.counts.error ? 1 : 0;
107
+ }
108
+
109
+ async function mcpBridge() {
110
+ const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
111
+ for await (const line of rl) {
112
+ if (!line.trim()) continue;
113
+ let msg;
114
+ try {
115
+ msg = JSON.parse(line);
116
+ } catch {
117
+ continue;
118
+ }
119
+ try {
120
+ const res = await fetch(`${API}/mcp`, {
121
+ method: 'POST',
122
+ headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream', 'user-agent': UA },
123
+ body: JSON.stringify(msg),
124
+ });
125
+ if (res.status === 202 || res.status === 204) continue;
126
+ const text = await res.text();
127
+ if (text.trim()) process.stdout.write(text.trim().replace(/\n/g, ' ') + '\n');
128
+ } catch (e) {
129
+ if (msg.id !== undefined) {
130
+ process.stdout.write(JSON.stringify({ jsonrpc: '2.0', id: msg.id, error: { code: -32000, message: `dbml.db unreachable: ${e.message}` } }) + '\n');
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ async function main() {
137
+ const { _, flags } = args(process.argv.slice(2));
138
+ const [cmd, file] = _;
139
+ if (flags.version) return console.log(VERSION), 0;
140
+ if (!cmd || flags.help || cmd === 'help') return console.log(HELP), 0;
141
+ const json = flags.json === true;
142
+ const dialect = typeof flags.dialect === 'string' ? flags.dialect : 'postgres';
143
+
144
+ switch (cmd) {
145
+ case 'validate': {
146
+ const r = await call('POST', '/api/v1/validate', { dbml: await readSource(file) });
147
+ if (json) console.log(JSON.stringify(r, null, 2));
148
+ else if (r.valid) console.log('valid');
149
+ else printErrors(r.errors, file);
150
+ return r.valid ? 0 : 1;
151
+ }
152
+ case 'parse':
153
+ case 'summary': {
154
+ const r = await call('POST', `/api/v1/${cmd}`, { dbml: await readSource(file) });
155
+ if (!r.valid) return printErrors(r.errors, file), 1;
156
+ if (cmd === 'summary' && !json) console.log(r.summary.text);
157
+ else console.log(JSON.stringify(cmd === 'parse' && !json ? r.model : r, null, 2));
158
+ return 0;
159
+ }
160
+ case 'review': {
161
+ const rules = typeof flags.rules === 'string' ? flags.rules.split(',') : undefined;
162
+ const r = await call('POST', '/api/v1/review', { dbml: await readSource(file), rules });
163
+ if (json) return console.log(JSON.stringify(r, null, 2)), r.valid && !r.counts?.error ? 0 : 1;
164
+ return printReview(r, file);
165
+ }
166
+ case 'watch': {
167
+ if (!file || file === '-') throw usage('watch needs a file');
168
+ const once = async () => {
169
+ let r;
170
+ try {
171
+ r = await call('POST', '/api/v1/review', { dbml: readFileSync(file, 'utf8') });
172
+ } catch (e) {
173
+ console.error(e.message);
174
+ return;
175
+ }
176
+ if (process.stdout.isTTY) process.stdout.write('\x1b[2J\x1b[H');
177
+ console.log(paint('1', `dbml review ${file}`) + paint('2', ` ${new Date().toLocaleTimeString()} (ctrl-c to quit)\n`));
178
+ printReview(r, file);
179
+ };
180
+ await once();
181
+ watchFile(file, { interval: 500 }, once);
182
+ return new Promise(() => {});
183
+ }
184
+ case 'format': {
185
+ const r = await call('POST', '/api/v1/format', { dbml: await readSource(file) });
186
+ if (!r.ok) return printErrors(r.errors, file), 1;
187
+ process.stdout.write(json ? JSON.stringify(r, null, 2) + '\n' : r.dbml);
188
+ return 0;
189
+ }
190
+ case 'to-sql': {
191
+ const r = await call('POST', '/api/v1/dbml-to-sql', { dbml: await readSource(file), dialect });
192
+ if (!r.ok) return printErrors(r.errors, file), 1;
193
+ process.stdout.write(json ? JSON.stringify(r, null, 2) + '\n' : r.sql);
194
+ return 0;
195
+ }
196
+ case 'from-sql': {
197
+ const r = await call('POST', '/api/v1/sql-to-dbml', { sql: await readSource(file), dialect });
198
+ if (!r.ok) return printErrors(r.errors, file), 1;
199
+ process.stdout.write(json ? JSON.stringify(r, null, 2) + '\n' : r.dbml);
200
+ return 0;
201
+ }
202
+ case 'rules': {
203
+ const r = await call('GET', '/api/v1/rules');
204
+ if (json) console.log(JSON.stringify(r, null, 2));
205
+ else for (const x of r) console.log(`${x.id.padEnd(28)} ${SEV[x.severity](x.severity.padEnd(7))} ${x.description}`);
206
+ return 0;
207
+ }
208
+ case 'syntax': {
209
+ process.stdout.write(await call('GET', '/api/v1/syntax'));
210
+ return 0;
211
+ }
212
+ case 'mcp':
213
+ await mcpBridge();
214
+ return 0;
215
+ default:
216
+ throw usage(`unknown command "${cmd}". Run dbml --help`);
217
+ }
218
+ }
219
+
220
+ main().then(
221
+ (code) => process.exit(code ?? 0),
222
+ (e) => {
223
+ console.error(`dbml: ${e.message}`);
224
+ process.exit(e.exit ?? 2);
225
+ },
226
+ );
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@profullstack/dbml",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "CLI and MCP stdio bridge for dbml.db: validate, review and convert DBML database schemas (DBML to SQL and back) from the terminal or an AI agent.",
5
+ "type": "module",
6
+ "bin": {
7
+ "dbml": "bin/dbml.js",
8
+ "dbml-db": "bin/dbml.js"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "engines": {
16
+ "node": ">=20"
17
+ },
18
+ "keywords": [
19
+ "dbml",
20
+ "database",
21
+ "schema",
22
+ "sql",
23
+ "mcp",
24
+ "ai-agents",
25
+ "lint",
26
+ "postgres",
27
+ "mysql"
28
+ ],
29
+ "homepage": "https://dbml.db.pit.world",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/profullstack/dbml.db.git",
33
+ "directory": "cli"
34
+ },
35
+ "bugs": "https://github.com/profullstack/dbml.db/issues",
36
+ "license": "MIT",
37
+ "author": "Profullstack, Inc. <hello@profullstack.com> (https://profullstack.com)",
38
+ "publishConfig": {
39
+ "access": "public"
40
+ }
41
+ }