@tandemcreativedev/strabo 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.
- package/LICENSE +21 -0
- package/README.md +103 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +89 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.js +85 -0
- package/dist/diagram.d.ts +32 -0
- package/dist/diagram.js +92 -0
- package/dist/dump.d.ts +4 -0
- package/dist/dump.js +35 -0
- package/dist/generate.d.ts +13 -0
- package/dist/generate.js +38 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +9 -0
- package/dist/model.d.ts +62 -0
- package/dist/model.js +1 -0
- package/dist/parse.d.ts +4 -0
- package/dist/parse.js +198 -0
- package/dist/writers/dbml.d.ts +2 -0
- package/dist/writers/dbml.js +108 -0
- package/dist/writers/puml.d.ts +2 -0
- package/dist/writers/puml.js +75 -0
- package/dist/writers/sql.d.ts +2 -0
- package/dist/writers/sql.js +55 -0
- package/dist/writers/svg.d.ts +1 -0
- package/dist/writers/svg.js +17 -0
- package/package.json +54 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tandem Creative Dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,104 @@
|
|
|
1
|
-
#
|
|
1
|
+
# strabo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Named after the Greek geographer who wrote down the known world. Strabo writes down your database.
|
|
4
|
+
|
|
5
|
+
Generates a readable record of a Postgres schema from `pg_dump`: a tidy SQL reference plus DBML, PlantUML and SVG diagrams. Commit the output next to your migrations so people and AI agents can read the schema without a running database.
|
|
6
|
+
|
|
7
|
+
- `schema.sql`: every enum, table, view, function and trigger, grouped and sorted. Each table carries its constraints, indexes, comments, row level security and policies. It is for reading only, never for running.
|
|
8
|
+
- `.dbml`: diagrams for [dbdiagram.io](https://dbdiagram.io), split by domain or by schema. References to tables outside a diagram stay as comments.
|
|
9
|
+
- `.puml`: the same diagrams as PlantUML entity-relationship diagrams.
|
|
10
|
+
- `.svg`: the DBML diagrams rendered, with the optional `@softwaretechnik/dbml-renderer`.
|
|
11
|
+
|
|
12
|
+
Built for local Supabase stacks, and it works with any Postgres that `pg_dump` can reach.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
pnpm add -D @tandemcreativedev/strabo
|
|
18
|
+
# only if you want SVG output
|
|
19
|
+
pnpm add -D @softwaretechnik/dbml-renderer
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
You need the PostgreSQL client tools (`pg_dump`) at the same major version as the server or newer. Without them, point `pgDump` at the database container (see below).
|
|
23
|
+
|
|
24
|
+
## Use
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pnpm strabo init # writes a starter strabo.config.json
|
|
28
|
+
pnpm strabo # dumps the local database and writes docs/db/*
|
|
29
|
+
pnpm strabo --check # exits 1 if the committed files are out of date
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
A typical `package.json` script, run after applying migrations locally:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
"db:schema": "strabo"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Options
|
|
39
|
+
|
|
40
|
+
| Flag | Meaning |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `-c, --config <file>` | Config file. Defaults to `strabo.config.json` if present. |
|
|
43
|
+
| `-i, --input <file>` | Parse a saved schema-only dump instead of running `pg_dump`. |
|
|
44
|
+
| `--db-url <url>` | Database to dump. Defaults to local Supabase (`127.0.0.1:54322`). |
|
|
45
|
+
| `--out <dir>` | Output directory. |
|
|
46
|
+
| `--check` | Compare the output with the files on disk and write nothing. |
|
|
47
|
+
| `--allow-remote` | Allow a database that is not on this machine. Refused by default. |
|
|
48
|
+
|
|
49
|
+
## Config
|
|
50
|
+
|
|
51
|
+
`strabo.config.json`, with every field optional:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"databaseUrl": "postgresql://postgres:postgres@127.0.0.1:54322/postgres",
|
|
56
|
+
"schemas": ["public", "private", "audit"],
|
|
57
|
+
"outDir": "docs/db",
|
|
58
|
+
"sql": "schema.sql",
|
|
59
|
+
"pgDump": "pg_dump",
|
|
60
|
+
"diagrams": [
|
|
61
|
+
{ "name": "schema", "title": "Everything public", "schemas": ["public", "private"], "formats": ["dbml", "svg"] },
|
|
62
|
+
{ "name": "schema-audit", "title": "Audit log", "schemas": ["audit"] },
|
|
63
|
+
{
|
|
64
|
+
"name": "diagrams/01_tenancy",
|
|
65
|
+
"title": "Tenancy and access control",
|
|
66
|
+
"notes": ["Profiles extend auth.users one-to-one"],
|
|
67
|
+
"tables": ["tenants", "roles", "tenant_*", "profiles", "audit.log_tenant_*"],
|
|
68
|
+
"formats": ["dbml", "puml"]
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"hiddenRefs": {
|
|
72
|
+
"public.passages.document_id": "denormalised ref to documents.id"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- `schemas`: the schemas to dump. Names in the first one appear without a prefix (`users`, not `public.users`). Other schemas keep theirs (`audit.events`).
|
|
78
|
+
- `sql`: the SQL reference's file name, or `false` to skip it.
|
|
79
|
+
- `diagrams`: one entry per diagram. `name` is the output path without an extension, relative to `outDir`.
|
|
80
|
+
- `tables` lists the tables to draw, in drawing order. Bare names belong to the first schema, and `*` is a wildcard. When any diagram uses `tables`, the run warns about tables that no diagram lists, so new tables don't go undocumented.
|
|
81
|
+
- Without `tables`, a diagram draws every table in `schemas`, or in every dumped schema if `schemas` is also absent.
|
|
82
|
+
- `formats` takes any of `dbml` (the default), `puml` and `svg`.
|
|
83
|
+
- `hiddenRefs`: foreign keys to leave out of diagrams, each with a note to show on the column instead. Useful for denormalised columns that would tangle a diagram.
|
|
84
|
+
- `pgDump`: the command that runs `pg_dump`. Without local client tools, use the Supabase container: `"docker exec supabase_db_<project> pg_dump"`, with `databaseUrl` set to `postgresql://postgres:postgres@localhost:5432/postgres`, which is the address inside the container.
|
|
85
|
+
|
|
86
|
+
## Programmatic use
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { generate, resolveConfig } from "@tandemcreativedev/strabo";
|
|
90
|
+
|
|
91
|
+
const { files, warnings } = generate(dumpText, resolveConfig({ schemas: ["public"] }));
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`parseDump`, `buildDiagram`, `writeSql`, `writeDbml`, `writePuml` and `writeSvg` are exported too, for custom output.
|
|
95
|
+
|
|
96
|
+
## Development
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
pnpm test # parser and writer tests against test/fixtures/dump.sql
|
|
100
|
+
UPDATE_EXPECTED=1 pnpm test # accept output changes into test/fixtures/expected
|
|
101
|
+
pnpm fixture # rebuild the fixture dump from fixture.ddl.sql (needs local Supabase)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The parser reads pg_dump's plain-text output. It splits the dump on the `-- Name: …; Type: …` header that pg_dump writes before every object, then parses each statement on its own. It is tested against pg_dump 18 output.
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { CONFIG_FILE, DEFAULTS, loadConfig } from "./config.js";
|
|
6
|
+
import { dumpSchema } from "./dump.js";
|
|
7
|
+
import { generate } from "./generate.js";
|
|
8
|
+
const HELP = `Usage: strabo [init] [options]
|
|
9
|
+
|
|
10
|
+
Writes a readable SQL reference and diagrams of a Postgres schema from pg_dump.
|
|
11
|
+
|
|
12
|
+
Commands:
|
|
13
|
+
init Write a starter ${CONFIG_FILE}
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
-c, --config <file> Config file (default: ${CONFIG_FILE}, optional)
|
|
17
|
+
-i, --input <file> Read a schema-only dump from a file instead of running pg_dump
|
|
18
|
+
--db-url <url> Database to dump (default: local Supabase)
|
|
19
|
+
--out <dir> Output directory (default: ${DEFAULTS.outDir})
|
|
20
|
+
--check Exit 1 if any output file is out of date, writing nothing
|
|
21
|
+
--allow-remote Allow dumping a database that is not on this machine
|
|
22
|
+
-h, --help Show this help
|
|
23
|
+
`;
|
|
24
|
+
function init() {
|
|
25
|
+
if (fs.existsSync(CONFIG_FILE))
|
|
26
|
+
throw new Error(`${CONFIG_FILE} already exists`);
|
|
27
|
+
const starter = {
|
|
28
|
+
schemas: DEFAULTS.schemas,
|
|
29
|
+
outDir: DEFAULTS.outDir,
|
|
30
|
+
diagrams: [{ name: "schema", title: "Database schema", formats: ["dbml", "puml"] }],
|
|
31
|
+
};
|
|
32
|
+
fs.writeFileSync(CONFIG_FILE, `${JSON.stringify(starter, null, 2)}\n`);
|
|
33
|
+
console.log(`wrote ${CONFIG_FILE}`);
|
|
34
|
+
}
|
|
35
|
+
function run() {
|
|
36
|
+
const { values, positionals } = parseArgs({
|
|
37
|
+
allowPositionals: true,
|
|
38
|
+
options: {
|
|
39
|
+
config: { type: "string", short: "c" },
|
|
40
|
+
input: { type: "string", short: "i" },
|
|
41
|
+
"db-url": { type: "string" },
|
|
42
|
+
out: { type: "string" },
|
|
43
|
+
check: { type: "boolean" },
|
|
44
|
+
"allow-remote": { type: "boolean" },
|
|
45
|
+
help: { type: "boolean", short: "h" },
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
if (values.help) {
|
|
49
|
+
console.log(HELP);
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
if (positionals[0] === "init") {
|
|
53
|
+
init();
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
if (positionals.length)
|
|
57
|
+
throw new Error(`Unknown command ${positionals[0]}. Run strabo --help.`);
|
|
58
|
+
const config = loadConfig(values.config);
|
|
59
|
+
if (values["db-url"])
|
|
60
|
+
config.databaseUrl = values["db-url"];
|
|
61
|
+
if (values.out)
|
|
62
|
+
config.outDir = values.out;
|
|
63
|
+
const dump = values.input ? fs.readFileSync(values.input, "utf8") : dumpSchema(config, values["allow-remote"]);
|
|
64
|
+
const { schema, files, warnings } = generate(dump, config);
|
|
65
|
+
for (const warning of warnings)
|
|
66
|
+
console.warn(`warning: ${warning}`);
|
|
67
|
+
if (values.check) {
|
|
68
|
+
const stale = files.filter((file) => !fs.existsSync(file.path) || fs.readFileSync(file.path, "utf8") !== file.content);
|
|
69
|
+
for (const file of stale)
|
|
70
|
+
console.error(`out of date: ${file.path}`);
|
|
71
|
+
if (stale.length)
|
|
72
|
+
console.error("Run strabo to regenerate.");
|
|
73
|
+
return stale.length ? 1 : 0;
|
|
74
|
+
}
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
fs.mkdirSync(path.dirname(file.path), { recursive: true });
|
|
77
|
+
fs.writeFileSync(file.path, file.content);
|
|
78
|
+
console.log(`wrote ${file.path}`);
|
|
79
|
+
}
|
|
80
|
+
console.log(`${schema.tables.size} tables, ${schema.enums.length} enums, ${schema.views.length} views, ${schema.functions.length} functions, ${schema.triggers.length} triggers`);
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
process.exitCode = run();
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error(`strabo: ${error.message}`);
|
|
88
|
+
process.exitCode = 1;
|
|
89
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const DIAGRAM_FORMATS: readonly ["dbml", "puml", "svg"];
|
|
2
|
+
export type DiagramFormat = (typeof DIAGRAM_FORMATS)[number];
|
|
3
|
+
export interface DiagramConfig {
|
|
4
|
+
/** Output path without extension, relative to `outDir`, such as `diagrams/01_tenancy`. */
|
|
5
|
+
name: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
notes?: string[];
|
|
8
|
+
/** Tables to draw, as `schema.table` or bare names in the first schema. `*` matches any run of characters. */
|
|
9
|
+
tables?: string[];
|
|
10
|
+
/** Schemas to draw in full when `tables` is not given. Defaults to every dumped schema. */
|
|
11
|
+
schemas?: string[];
|
|
12
|
+
/** Defaults to `["dbml"]`. `svg` renders the DBML and needs `@softwaretechnik/dbml-renderer` installed. */
|
|
13
|
+
formats?: DiagramFormat[];
|
|
14
|
+
}
|
|
15
|
+
export interface Config {
|
|
16
|
+
/** Defaults to the local Supabase database. */
|
|
17
|
+
databaseUrl: string;
|
|
18
|
+
/** Schemas to dump. The first one is drawn without its schema prefix. */
|
|
19
|
+
schemas: string[];
|
|
20
|
+
outDir: string;
|
|
21
|
+
/** File name for the SQL reference, relative to `outDir`, or false to skip it. */
|
|
22
|
+
sql: string | false;
|
|
23
|
+
diagrams: DiagramConfig[];
|
|
24
|
+
/** Foreign keys to leave out of diagrams, as `schema.table.column`, each with the note to show instead. */
|
|
25
|
+
hiddenRefs: Record<string, string>;
|
|
26
|
+
/** The pg_dump command, such as `pg_dump` or `docker exec -i supabase_db_app pg_dump`. */
|
|
27
|
+
pgDump: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const CONFIG_FILE = "strabo.config.json";
|
|
30
|
+
export declare const DEFAULTS: Config;
|
|
31
|
+
/** Merges a parsed config file over the defaults, rejecting anything malformed. */
|
|
32
|
+
export declare function resolveConfig(raw: unknown): Config;
|
|
33
|
+
export declare function loadConfig(file?: string): Config;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export const DIAGRAM_FORMATS = ["dbml", "puml", "svg"];
|
|
4
|
+
export const CONFIG_FILE = "strabo.config.json";
|
|
5
|
+
export const DEFAULTS = {
|
|
6
|
+
databaseUrl: "postgresql://postgres:postgres@127.0.0.1:54322/postgres",
|
|
7
|
+
schemas: ["public"],
|
|
8
|
+
outDir: "docs/db",
|
|
9
|
+
sql: "schema.sql",
|
|
10
|
+
diagrams: [{ name: "schema" }],
|
|
11
|
+
hiddenRefs: {},
|
|
12
|
+
pgDump: "pg_dump",
|
|
13
|
+
};
|
|
14
|
+
function fail(message) {
|
|
15
|
+
throw new Error(`${CONFIG_FILE}: ${message}`);
|
|
16
|
+
}
|
|
17
|
+
function isStringArray(value) {
|
|
18
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
19
|
+
}
|
|
20
|
+
function validateDiagram(value, index) {
|
|
21
|
+
const at = `diagrams[${index}]`;
|
|
22
|
+
if (typeof value !== "object" || value === null)
|
|
23
|
+
fail(`${at} must be an object`);
|
|
24
|
+
const diagram = value;
|
|
25
|
+
if (typeof diagram.name !== "string" || !diagram.name)
|
|
26
|
+
fail(`${at}.name must be a non-empty string`);
|
|
27
|
+
if (diagram.title !== undefined && typeof diagram.title !== "string")
|
|
28
|
+
fail(`${at}.title must be a string`);
|
|
29
|
+
for (const key of ["notes", "tables", "schemas"])
|
|
30
|
+
if (diagram[key] !== undefined && !isStringArray(diagram[key]))
|
|
31
|
+
fail(`${at}.${key} must be an array of strings`);
|
|
32
|
+
if (diagram.formats !== undefined) {
|
|
33
|
+
if (!isStringArray(diagram.formats))
|
|
34
|
+
fail(`${at}.formats must be an array of strings`);
|
|
35
|
+
const unknown = diagram.formats.filter((format) => !DIAGRAM_FORMATS.includes(format));
|
|
36
|
+
if (unknown.length)
|
|
37
|
+
fail(`${at}.formats has unknown ${unknown.join(", ")}; use ${DIAGRAM_FORMATS.join(", ")}`);
|
|
38
|
+
}
|
|
39
|
+
return diagram;
|
|
40
|
+
}
|
|
41
|
+
/** Merges a parsed config file over the defaults, rejecting anything malformed. */
|
|
42
|
+
export function resolveConfig(raw) {
|
|
43
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw))
|
|
44
|
+
fail("must be a JSON object");
|
|
45
|
+
const input = raw;
|
|
46
|
+
const known = new Set([...Object.keys(DEFAULTS), "$schema"]);
|
|
47
|
+
const unknown = Object.keys(input).filter((key) => !known.has(key));
|
|
48
|
+
if (unknown.length)
|
|
49
|
+
fail(`unknown option ${unknown.join(", ")}`);
|
|
50
|
+
for (const key of ["databaseUrl", "outDir", "pgDump"])
|
|
51
|
+
if (input[key] !== undefined && typeof input[key] !== "string")
|
|
52
|
+
fail(`${key} must be a string`);
|
|
53
|
+
if (input.schemas !== undefined && (!isStringArray(input.schemas) || input.schemas.length === 0))
|
|
54
|
+
fail("schemas must be a non-empty array of strings");
|
|
55
|
+
if (input.sql !== undefined && input.sql !== false && typeof input.sql !== "string")
|
|
56
|
+
fail("sql must be a file name or false");
|
|
57
|
+
if (input.diagrams !== undefined && !Array.isArray(input.diagrams))
|
|
58
|
+
fail("diagrams must be an array");
|
|
59
|
+
if (input.hiddenRefs !== undefined &&
|
|
60
|
+
(typeof input.hiddenRefs !== "object" ||
|
|
61
|
+
input.hiddenRefs === null ||
|
|
62
|
+
!Object.values(input.hiddenRefs).every((note) => typeof note === "string")))
|
|
63
|
+
fail("hiddenRefs must map schema.table.column to a note");
|
|
64
|
+
return {
|
|
65
|
+
...DEFAULTS,
|
|
66
|
+
...input,
|
|
67
|
+
diagrams: Array.isArray(input.diagrams) ? input.diagrams.map(validateDiagram) : DEFAULTS.diagrams,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function loadConfig(file) {
|
|
71
|
+
const configPath = path.resolve(file ?? CONFIG_FILE);
|
|
72
|
+
if (!fs.existsSync(configPath)) {
|
|
73
|
+
if (file)
|
|
74
|
+
fail(`not found at ${configPath}`);
|
|
75
|
+
return DEFAULTS;
|
|
76
|
+
}
|
|
77
|
+
let raw;
|
|
78
|
+
try {
|
|
79
|
+
raw = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
fail(`is not valid JSON: ${error.message}`);
|
|
83
|
+
}
|
|
84
|
+
return resolveConfig(raw);
|
|
85
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DiagramConfig } from "./config.js";
|
|
2
|
+
import type { Column, Enum, Schema, Table } from "./model.js";
|
|
3
|
+
export type Cardinality = "one-to-one" | "many-to-one";
|
|
4
|
+
export interface Relation {
|
|
5
|
+
table: string;
|
|
6
|
+
columns: string[];
|
|
7
|
+
refTable: string;
|
|
8
|
+
refColumns: string[];
|
|
9
|
+
cardinality: Cardinality;
|
|
10
|
+
/** False when the column must hold a value. */
|
|
11
|
+
optional: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface Diagram {
|
|
14
|
+
name: string;
|
|
15
|
+
title: string;
|
|
16
|
+
notes: string[];
|
|
17
|
+
primarySchema: string;
|
|
18
|
+
tables: Table[];
|
|
19
|
+
enums: Enum[];
|
|
20
|
+
/** References between two tables in this diagram. */
|
|
21
|
+
relations: Relation[];
|
|
22
|
+
/** References to tables drawn elsewhere or not dumped at all. */
|
|
23
|
+
externalRelations: Relation[];
|
|
24
|
+
hiddenRefs: Map<string, string>;
|
|
25
|
+
}
|
|
26
|
+
export declare function selectTables(schema: Schema, config: Pick<DiagramConfig, "tables" | "schemas">, primarySchema: string, warn: (message: string) => void): Table[];
|
|
27
|
+
export declare function buildDiagram(schema: Schema, config: DiagramConfig, primarySchema: string, hiddenRefs: Record<string, string>, warn: (message: string) => void): Diagram;
|
|
28
|
+
/** Drops the primary schema's prefix, so `public.users` reads as `users`. */
|
|
29
|
+
export declare function displayName(qualified: string, primarySchema: string): string;
|
|
30
|
+
/** Orders columns primary key first and timestamps last, as people read a table. */
|
|
31
|
+
export declare function orderColumns(table: Table): Column[];
|
|
32
|
+
export declare function shortType(type: string, primarySchema: string): string;
|
package/dist/diagram.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
function pattern(entry, primarySchema) {
|
|
2
|
+
const qualified = entry.includes(".") ? entry : `${primarySchema}.${entry}`;
|
|
3
|
+
const escaped = qualified.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
4
|
+
return new RegExp(`^${escaped}$`);
|
|
5
|
+
}
|
|
6
|
+
export function selectTables(schema, config, primarySchema, warn) {
|
|
7
|
+
const all = [...schema.tables.values()];
|
|
8
|
+
if (!config.tables)
|
|
9
|
+
return config.schemas ? all.filter((table) => config.schemas?.includes(table.schema)) : all;
|
|
10
|
+
const selected = new Map();
|
|
11
|
+
for (const entry of config.tables) {
|
|
12
|
+
const matching = all.filter((table) => pattern(entry, primarySchema).test(table.name));
|
|
13
|
+
if (matching.length === 0)
|
|
14
|
+
warn(`no table matches ${entry}`);
|
|
15
|
+
for (const table of matching)
|
|
16
|
+
selected.set(table.name, table);
|
|
17
|
+
}
|
|
18
|
+
return [...selected.values()];
|
|
19
|
+
}
|
|
20
|
+
function sameColumns(a, b) {
|
|
21
|
+
return a.length === b.length && a.every((column) => b.includes(column));
|
|
22
|
+
}
|
|
23
|
+
function isUnique(table, columns) {
|
|
24
|
+
return (sameColumns(table.primaryKey, columns) ||
|
|
25
|
+
table.uniques.some((unique) => sameColumns(unique, columns)) ||
|
|
26
|
+
table.indexes.some((index) => index.unique && !index.partial && index.columns !== null && sameColumns(index.columns, columns)));
|
|
27
|
+
}
|
|
28
|
+
function toRelation(table, foreignKey) {
|
|
29
|
+
const columns = foreignKey.columns.map((name) => table.columns.find((column) => column.name === name));
|
|
30
|
+
return {
|
|
31
|
+
table: table.name,
|
|
32
|
+
columns: foreignKey.columns,
|
|
33
|
+
refTable: foreignKey.refTable,
|
|
34
|
+
refColumns: foreignKey.refColumns,
|
|
35
|
+
cardinality: isUnique(table, foreignKey.columns) ? "one-to-one" : "many-to-one",
|
|
36
|
+
optional: columns.some((column) => !column?.notNull),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function enumsUsedBy(tables, enums) {
|
|
40
|
+
const types = new Set(tables.flatMap((table) => table.columns.map((column) => column.type.replace(/\[\]$/, ""))));
|
|
41
|
+
return enums.filter((candidate) => types.has(candidate.name));
|
|
42
|
+
}
|
|
43
|
+
export function buildDiagram(schema, config, primarySchema, hiddenRefs, warn) {
|
|
44
|
+
const tables = selectTables(schema, config, primarySchema, warn);
|
|
45
|
+
const drawn = new Set(tables.map((table) => table.name));
|
|
46
|
+
const hidden = new Map(Object.entries(hiddenRefs));
|
|
47
|
+
const relations = [];
|
|
48
|
+
const externalRelations = [];
|
|
49
|
+
for (const table of tables)
|
|
50
|
+
for (const foreignKey of table.foreignKeys) {
|
|
51
|
+
if (foreignKey.columns.some((column) => hidden.has(`${table.name}.${column}`)))
|
|
52
|
+
continue;
|
|
53
|
+
const relation = toRelation(table, foreignKey);
|
|
54
|
+
(drawn.has(foreignKey.refTable) ? relations : externalRelations).push(relation);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
name: config.name,
|
|
58
|
+
title: config.title ?? config.name,
|
|
59
|
+
notes: config.notes ?? [],
|
|
60
|
+
primarySchema,
|
|
61
|
+
tables,
|
|
62
|
+
enums: enumsUsedBy(tables, schema.enums),
|
|
63
|
+
relations,
|
|
64
|
+
externalRelations,
|
|
65
|
+
hiddenRefs: hidden,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Drops the primary schema's prefix, so `public.users` reads as `users`. */
|
|
69
|
+
export function displayName(qualified, primarySchema) {
|
|
70
|
+
return qualified.startsWith(`${primarySchema}.`) ? qualified.slice(primarySchema.length + 1) : qualified;
|
|
71
|
+
}
|
|
72
|
+
/** Orders columns primary key first and timestamps last, as people read a table. */
|
|
73
|
+
export function orderColumns(table) {
|
|
74
|
+
const weight = (column) => {
|
|
75
|
+
if (table.primaryKey.includes(column.name))
|
|
76
|
+
return 0;
|
|
77
|
+
if (column.name === "created_at" || column.name === "createdAt")
|
|
78
|
+
return 2;
|
|
79
|
+
if (column.name === "updated_at" || column.name === "updatedAt")
|
|
80
|
+
return 3;
|
|
81
|
+
return 1;
|
|
82
|
+
};
|
|
83
|
+
return [...table.columns].sort((a, b) => weight(a) - weight(b));
|
|
84
|
+
}
|
|
85
|
+
export function shortType(type, primarySchema) {
|
|
86
|
+
return displayName(type, primarySchema)
|
|
87
|
+
.replace(/^timestamp(\(\d+\))? with time zone/, "timestamptz$1")
|
|
88
|
+
.replace(/^timestamp(\(\d+\))? without time zone/, "timestamp$1")
|
|
89
|
+
.replace(/^time(\(\d+\))? with time zone/, "timetz$1")
|
|
90
|
+
.replace(/^character varying/, "varchar")
|
|
91
|
+
.replace(/^character\b/, "char");
|
|
92
|
+
}
|
package/dist/dump.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Config } from "./config.js";
|
|
2
|
+
export declare function isLocal(databaseUrl: string): boolean;
|
|
3
|
+
/** Runs pg_dump for the configured schemas and returns the schema-only dump. */
|
|
4
|
+
export declare function dumpSchema(config: Pick<Config, "databaseUrl" | "schemas" | "pgDump">, allowRemote?: boolean): string;
|
package/dist/dump.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]", "host.docker.internal"]);
|
|
3
|
+
export function isLocal(databaseUrl) {
|
|
4
|
+
let hostname;
|
|
5
|
+
try {
|
|
6
|
+
hostname = new URL(databaseUrl).hostname;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
throw new Error("databaseUrl is not a valid postgresql:// URL");
|
|
10
|
+
}
|
|
11
|
+
return LOCAL_HOSTS.has(hostname) || hostname.endsWith(".localhost");
|
|
12
|
+
}
|
|
13
|
+
/** Runs pg_dump for the configured schemas and returns the schema-only dump. */
|
|
14
|
+
export function dumpSchema(config, allowRemote = false) {
|
|
15
|
+
if (!allowRemote && !isLocal(config.databaseUrl))
|
|
16
|
+
throw new Error("Refusing to dump a non-local database. Pass --allow-remote if you mean to.");
|
|
17
|
+
const [command, ...prefix] = config.pgDump.split(/\s+/).filter(Boolean);
|
|
18
|
+
const args = [
|
|
19
|
+
...prefix,
|
|
20
|
+
"--schema-only",
|
|
21
|
+
"--no-acl",
|
|
22
|
+
"--no-owner",
|
|
23
|
+
...config.schemas.map((schema) => `--schema=${schema}`),
|
|
24
|
+
config.databaseUrl,
|
|
25
|
+
];
|
|
26
|
+
try {
|
|
27
|
+
return execFileSync(command, args, { encoding: "utf8", maxBuffer: 256 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const failure = error;
|
|
31
|
+
if (failure.code === "ENOENT")
|
|
32
|
+
throw new Error(`${command} was not found. Install the PostgreSQL client tools, or set pgDump in the config.`);
|
|
33
|
+
throw new Error(`${command} failed: ${failure.stderr?.trim() || failure.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Config } from "./config.js";
|
|
2
|
+
import type { Schema } from "./model.js";
|
|
3
|
+
export interface OutputFile {
|
|
4
|
+
path: string;
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Result {
|
|
8
|
+
schema: Schema;
|
|
9
|
+
files: OutputFile[];
|
|
10
|
+
warnings: string[];
|
|
11
|
+
}
|
|
12
|
+
/** Turns a schema-only pg_dump into the SQL reference and diagram files the config asks for. Writes nothing. */
|
|
13
|
+
export declare function generate(dump: string, config: Config): Result;
|
package/dist/generate.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { buildDiagram, selectTables } from "./diagram.js";
|
|
3
|
+
import { parseDump } from "./parse.js";
|
|
4
|
+
import { writeDbml } from "./writers/dbml.js";
|
|
5
|
+
import { writePuml } from "./writers/puml.js";
|
|
6
|
+
import { writeSql } from "./writers/sql.js";
|
|
7
|
+
import { writeSvg } from "./writers/svg.js";
|
|
8
|
+
function uncovered(schema, config) {
|
|
9
|
+
const listed = config.diagrams.filter((diagram) => diagram.tables);
|
|
10
|
+
if (listed.length === 0)
|
|
11
|
+
return [];
|
|
12
|
+
const covered = new Set(listed.flatMap((diagram) => selectTables(schema, diagram, config.schemas[0], () => { }).map((table) => table.name)));
|
|
13
|
+
return [...schema.tables.keys()].filter((name) => !covered.has(name));
|
|
14
|
+
}
|
|
15
|
+
/** Turns a schema-only pg_dump into the SQL reference and diagram files the config asks for. Writes nothing. */
|
|
16
|
+
export function generate(dump, config) {
|
|
17
|
+
const schema = parseDump(dump);
|
|
18
|
+
const warnings = [];
|
|
19
|
+
const files = [];
|
|
20
|
+
const at = (file) => path.join(config.outDir, file);
|
|
21
|
+
if (config.sql)
|
|
22
|
+
files.push({ path: at(config.sql), content: writeSql(schema) });
|
|
23
|
+
for (const diagramConfig of config.diagrams) {
|
|
24
|
+
const diagram = buildDiagram(schema, diagramConfig, config.schemas[0], config.hiddenRefs, (message) => warnings.push(`${diagramConfig.name}: ${message}`));
|
|
25
|
+
const formats = diagramConfig.formats ?? ["dbml"];
|
|
26
|
+
const dbml = writeDbml(diagram);
|
|
27
|
+
if (formats.includes("dbml"))
|
|
28
|
+
files.push({ path: at(`${diagram.name}.dbml`), content: dbml });
|
|
29
|
+
if (formats.includes("puml"))
|
|
30
|
+
files.push({ path: at(`${diagram.name}.puml`), content: writePuml(diagram) });
|
|
31
|
+
if (formats.includes("svg"))
|
|
32
|
+
files.push({ path: at(`${diagram.name}.svg`), content: writeSvg(dbml) });
|
|
33
|
+
}
|
|
34
|
+
const missing = uncovered(schema, config);
|
|
35
|
+
if (missing.length)
|
|
36
|
+
warnings.push(`tables in no diagram: ${missing.join(", ")}`);
|
|
37
|
+
return { schema, files, warnings };
|
|
38
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { DEFAULTS, DIAGRAM_FORMATS, loadConfig, resolveConfig } from "./config.js";
|
|
2
|
+
export type { Config, DiagramConfig, DiagramFormat } from "./config.js";
|
|
3
|
+
export { buildDiagram } from "./diagram.js";
|
|
4
|
+
export type { Diagram, Relation } from "./diagram.js";
|
|
5
|
+
export { dumpSchema, isLocal } from "./dump.js";
|
|
6
|
+
export { generate } from "./generate.js";
|
|
7
|
+
export type { OutputFile, Result } from "./generate.js";
|
|
8
|
+
export type * from "./model.js";
|
|
9
|
+
export { parseDump } from "./parse.js";
|
|
10
|
+
export { writeDbml } from "./writers/dbml.js";
|
|
11
|
+
export { writePuml } from "./writers/puml.js";
|
|
12
|
+
export { writeSql } from "./writers/sql.js";
|
|
13
|
+
export { writeSvg } from "./writers/svg.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DEFAULTS, DIAGRAM_FORMATS, loadConfig, resolveConfig } from "./config.js";
|
|
2
|
+
export { buildDiagram } from "./diagram.js";
|
|
3
|
+
export { dumpSchema, isLocal } from "./dump.js";
|
|
4
|
+
export { generate } from "./generate.js";
|
|
5
|
+
export { parseDump } from "./parse.js";
|
|
6
|
+
export { writeDbml } from "./writers/dbml.js";
|
|
7
|
+
export { writePuml } from "./writers/puml.js";
|
|
8
|
+
export { writeSql } from "./writers/sql.js";
|
|
9
|
+
export { writeSvg } from "./writers/svg.js";
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export interface Column {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
notNull: boolean;
|
|
5
|
+
default: string | null;
|
|
6
|
+
identity: boolean;
|
|
7
|
+
generated: boolean;
|
|
8
|
+
comment: string | null;
|
|
9
|
+
/** The column line as pg_dump wrote it, with any default or identity set later appended. */
|
|
10
|
+
definition: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ForeignKey {
|
|
13
|
+
name: string;
|
|
14
|
+
columns: string[];
|
|
15
|
+
refTable: string;
|
|
16
|
+
refColumns: string[];
|
|
17
|
+
definition: string;
|
|
18
|
+
}
|
|
19
|
+
export interface Index {
|
|
20
|
+
name: string;
|
|
21
|
+
unique: boolean;
|
|
22
|
+
/** Plain column names, or null when the index is on an expression. */
|
|
23
|
+
columns: string[] | null;
|
|
24
|
+
expression: string;
|
|
25
|
+
partial: boolean;
|
|
26
|
+
definition: string;
|
|
27
|
+
}
|
|
28
|
+
export interface Table {
|
|
29
|
+
name: string;
|
|
30
|
+
schema: string;
|
|
31
|
+
columns: Column[];
|
|
32
|
+
/** Inline CHECK constraints from the CREATE TABLE body. */
|
|
33
|
+
checks: string[];
|
|
34
|
+
primaryKey: string[];
|
|
35
|
+
uniques: string[][];
|
|
36
|
+
foreignKeys: ForeignKey[];
|
|
37
|
+
/** ALTER TABLE ... ADD CONSTRAINT bodies, as pg_dump wrote them. */
|
|
38
|
+
constraints: string[];
|
|
39
|
+
indexes: Index[];
|
|
40
|
+
rls: boolean;
|
|
41
|
+
policies: string[];
|
|
42
|
+
comment: string | null;
|
|
43
|
+
}
|
|
44
|
+
export interface Enum {
|
|
45
|
+
name: string;
|
|
46
|
+
schema: string;
|
|
47
|
+
values: string[];
|
|
48
|
+
/** COMMENT ON TYPE statements, as pg_dump wrote them. */
|
|
49
|
+
comments: string[];
|
|
50
|
+
}
|
|
51
|
+
export interface Definition {
|
|
52
|
+
name: string;
|
|
53
|
+
/** The CREATE statement followed by any COMMENT ON statements for it. */
|
|
54
|
+
body: string;
|
|
55
|
+
}
|
|
56
|
+
export interface Schema {
|
|
57
|
+
enums: Enum[];
|
|
58
|
+
tables: Map<string, Table>;
|
|
59
|
+
views: Definition[];
|
|
60
|
+
functions: Definition[];
|
|
61
|
+
triggers: Definition[];
|
|
62
|
+
}
|
package/dist/model.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/parse.d.ts
ADDED
package/dist/parse.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
const NAME = String.raw `(?:"(?:[^"]|"")+"|\w+)`;
|
|
2
|
+
const QUALIFIED = `${NAME}(?:\\.${NAME})?`;
|
|
3
|
+
export function unquote(identifier) {
|
|
4
|
+
return identifier.replace(/"((?:[^"]|"")+)"/g, (_, inner) => inner.replace(/""/g, '"'));
|
|
5
|
+
}
|
|
6
|
+
function splitList(list) {
|
|
7
|
+
return list.split(",").map((part) => unquote(part.trim()));
|
|
8
|
+
}
|
|
9
|
+
function unescapeLiteral(literal) {
|
|
10
|
+
return literal.slice(1, -1).replace(/''/g, "'");
|
|
11
|
+
}
|
|
12
|
+
function schemaOf(qualified) {
|
|
13
|
+
return qualified.includes(".") ? qualified.split(".")[0] : "public";
|
|
14
|
+
}
|
|
15
|
+
function byName(a, b) {
|
|
16
|
+
return a.name.localeCompare(b.name);
|
|
17
|
+
}
|
|
18
|
+
/** Splits a dump on the `-- Name: ...; Type: ...` header pg_dump writes before every object. */
|
|
19
|
+
function splitStatements(dump) {
|
|
20
|
+
return dump
|
|
21
|
+
.replace(/^--\n-- PostgreSQL database dump complete\n--$/m, "")
|
|
22
|
+
.split(/^--\n-- (?:Data for )?Name: .*\n--\n/m)
|
|
23
|
+
.slice(1)
|
|
24
|
+
.map((chunk) => chunk.replace(/^(?:SET |SELECT pg_catalog\.|\\(?:un)?restrict ).*$/gm, "").trim())
|
|
25
|
+
.filter(Boolean);
|
|
26
|
+
}
|
|
27
|
+
function parseColumn(line) {
|
|
28
|
+
const match = line.match(new RegExp(`^(${NAME})\\s+(.*)$`));
|
|
29
|
+
if (!match)
|
|
30
|
+
throw new Error(`Unrecognised column definition: ${line}`);
|
|
31
|
+
let rest = match[2];
|
|
32
|
+
const notNull = /\bNOT NULL\b/.test(rest);
|
|
33
|
+
rest = rest.replace(/\s*\bNOT NULL\b/, "");
|
|
34
|
+
const generated = /\bGENERATED ALWAYS AS \(/.test(rest);
|
|
35
|
+
rest = rest.replace(/\s*\bGENERATED ALWAYS AS \(.*\) STORED$/, "");
|
|
36
|
+
rest = rest.replace(/\s*\bCOLLATE\s+\S+/, "");
|
|
37
|
+
let columnDefault = null;
|
|
38
|
+
const defaultAt = rest.search(/\bDEFAULT\b/);
|
|
39
|
+
if (defaultAt >= 0) {
|
|
40
|
+
columnDefault = rest.slice(defaultAt + "DEFAULT".length).trim();
|
|
41
|
+
rest = rest.slice(0, defaultAt);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
name: unquote(match[1]),
|
|
45
|
+
type: rest.trim(),
|
|
46
|
+
notNull,
|
|
47
|
+
default: columnDefault,
|
|
48
|
+
identity: false,
|
|
49
|
+
generated,
|
|
50
|
+
comment: null,
|
|
51
|
+
definition: line,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function parseTable(name, body) {
|
|
55
|
+
const lines = body
|
|
56
|
+
.split("\n")
|
|
57
|
+
.map((line) => line.trim().replace(/,$/, ""))
|
|
58
|
+
.filter(Boolean);
|
|
59
|
+
return {
|
|
60
|
+
name,
|
|
61
|
+
schema: schemaOf(name),
|
|
62
|
+
columns: lines.filter((line) => !line.startsWith("CONSTRAINT ")).map(parseColumn),
|
|
63
|
+
checks: lines.filter((line) => line.startsWith("CONSTRAINT ")),
|
|
64
|
+
primaryKey: [],
|
|
65
|
+
uniques: [],
|
|
66
|
+
foreignKeys: [],
|
|
67
|
+
constraints: [],
|
|
68
|
+
indexes: [],
|
|
69
|
+
rls: false,
|
|
70
|
+
policies: [],
|
|
71
|
+
comment: null,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function addConstraint(table, body) {
|
|
75
|
+
table.constraints.push(`CONSTRAINT ${body}`);
|
|
76
|
+
const primaryKey = body.match(/ PRIMARY KEY \((.+?)\)/);
|
|
77
|
+
if (primaryKey)
|
|
78
|
+
table.primaryKey = splitList(primaryKey[1]);
|
|
79
|
+
const unique = body.match(/ UNIQUE (?:NULLS NOT DISTINCT )?\((.+?)\)/);
|
|
80
|
+
if (unique)
|
|
81
|
+
table.uniques.push(splitList(unique[1]));
|
|
82
|
+
const foreignKey = body.match(new RegExp(`^(${NAME}) FOREIGN KEY \\((.+?)\\) REFERENCES (${QUALIFIED})\\((.+?)\\)`));
|
|
83
|
+
if (foreignKey)
|
|
84
|
+
table.foreignKeys.push({
|
|
85
|
+
name: unquote(foreignKey[1]),
|
|
86
|
+
columns: splitList(foreignKey[2]),
|
|
87
|
+
refTable: unquote(foreignKey[3]),
|
|
88
|
+
refColumns: splitList(foreignKey[4]),
|
|
89
|
+
definition: body,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function parseIndex(match) {
|
|
93
|
+
const [definition, unique, name, , expression, where] = match;
|
|
94
|
+
const plainColumns = new RegExp(`^${NAME}(?:, ${NAME})*$`).test(expression);
|
|
95
|
+
return {
|
|
96
|
+
name: unquote(name),
|
|
97
|
+
unique: Boolean(unique),
|
|
98
|
+
columns: plainColumns ? splitList(expression) : null,
|
|
99
|
+
expression,
|
|
100
|
+
partial: Boolean(where),
|
|
101
|
+
definition,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const PATTERNS = {
|
|
105
|
+
enum: new RegExp(`^CREATE TYPE (${QUALIFIED}) AS ENUM \\(\\n([\\s\\S]*?)\\n\\);$`),
|
|
106
|
+
table: new RegExp(`^CREATE (?:UNLOGGED )?TABLE (${QUALIFIED}) \\(\\n([\\s\\S]*?)\\n\\)[^;]*;$`),
|
|
107
|
+
setDefault: new RegExp(`^ALTER TABLE ONLY (${QUALIFIED}) ALTER COLUMN (${NAME}) SET DEFAULT (.+);$`),
|
|
108
|
+
identity: new RegExp(`^ALTER TABLE (${QUALIFIED}) ALTER COLUMN (${NAME}) ADD GENERATED (ALWAYS|BY DEFAULT) AS IDENTITY`),
|
|
109
|
+
constraint: new RegExp(`^ALTER TABLE ONLY (${QUALIFIED})\\n\\s+ADD CONSTRAINT (${NAME} [\\s\\S]+);$`),
|
|
110
|
+
index: new RegExp(`^CREATE (UNIQUE )?INDEX (${NAME}) ON (?:ONLY )?(${QUALIFIED}) USING \\w+ \\((.*?)\\)(?: INCLUDE \\(.*?\\))?( WHERE .*)?;$`),
|
|
111
|
+
rls: new RegExp(`^ALTER TABLE (${QUALIFIED}) ENABLE ROW LEVEL SECURITY;$`),
|
|
112
|
+
policy: new RegExp(`^CREATE POLICY ${NAME} ON (${QUALIFIED}) `),
|
|
113
|
+
tableComment: new RegExp(`^COMMENT ON TABLE (${QUALIFIED}) IS ('(?:[^']|'')*');$`),
|
|
114
|
+
columnComment: new RegExp(`^COMMENT ON COLUMN (${QUALIFIED})\\.(${NAME}) IS ('(?:[^']|'')*');$`),
|
|
115
|
+
view: new RegExp(`^CREATE (?:MATERIALIZED )?VIEW (${QUALIFIED}) `),
|
|
116
|
+
function: new RegExp(`^CREATE (?:FUNCTION|PROCEDURE) (${QUALIFIED})\\(`),
|
|
117
|
+
trigger: new RegExp(`^CREATE (?:CONSTRAINT )?TRIGGER (${NAME}) `),
|
|
118
|
+
objectComment: new RegExp(`^COMMENT ON (?:TYPE|VIEW|MATERIALIZED VIEW|FUNCTION|PROCEDURE) (${QUALIFIED})[ (][\\s\\S]*;$`),
|
|
119
|
+
};
|
|
120
|
+
/** Parses a `pg_dump --schema-only` dump into the tables, types and routines it defines. */
|
|
121
|
+
export function parseDump(dump) {
|
|
122
|
+
const statements = splitStatements(dump);
|
|
123
|
+
const matches = (pattern) => statements.flatMap((statement) => {
|
|
124
|
+
const match = statement.match(pattern);
|
|
125
|
+
return match ? [match] : [];
|
|
126
|
+
});
|
|
127
|
+
const comments = new Map();
|
|
128
|
+
for (const match of matches(PATTERNS.objectComment)) {
|
|
129
|
+
const name = unquote(match[1]);
|
|
130
|
+
comments.set(name, [...(comments.get(name) ?? []), match.input ?? ""]);
|
|
131
|
+
}
|
|
132
|
+
const definitions = (pattern) => matches(pattern)
|
|
133
|
+
.map((match) => {
|
|
134
|
+
const name = unquote(match[1]);
|
|
135
|
+
return { name, body: [match.input ?? "", ...(comments.get(name) ?? [])].join("\n") };
|
|
136
|
+
})
|
|
137
|
+
.sort(byName);
|
|
138
|
+
const enums = matches(PATTERNS.enum).map(([, name, body]) => ({
|
|
139
|
+
name: unquote(name),
|
|
140
|
+
comments: comments.get(unquote(name)) ?? [],
|
|
141
|
+
schema: schemaOf(unquote(name)),
|
|
142
|
+
values: body
|
|
143
|
+
.split("\n")
|
|
144
|
+
.map((line) => line.trim().replace(/,$/, ""))
|
|
145
|
+
.filter(Boolean)
|
|
146
|
+
.map(unescapeLiteral),
|
|
147
|
+
}));
|
|
148
|
+
const tables = new Map();
|
|
149
|
+
for (const [, name, body] of matches(PATTERNS.table))
|
|
150
|
+
tables.set(unquote(name), parseTable(unquote(name), body));
|
|
151
|
+
const table = (name) => tables.get(unquote(name));
|
|
152
|
+
const column = (tableName, name) => table(tableName)?.columns.find((c) => c.name === unquote(name));
|
|
153
|
+
for (const [, tableName, name, value] of matches(PATTERNS.setDefault)) {
|
|
154
|
+
const target = column(tableName, name);
|
|
155
|
+
if (!target)
|
|
156
|
+
continue;
|
|
157
|
+
target.default = value;
|
|
158
|
+
target.definition += ` DEFAULT ${value}`;
|
|
159
|
+
}
|
|
160
|
+
for (const [, tableName, name, kind] of matches(PATTERNS.identity)) {
|
|
161
|
+
const target = column(tableName, name);
|
|
162
|
+
if (!target)
|
|
163
|
+
continue;
|
|
164
|
+
target.identity = true;
|
|
165
|
+
target.definition += ` GENERATED ${kind} AS IDENTITY`;
|
|
166
|
+
}
|
|
167
|
+
for (const [, name, body] of matches(PATTERNS.constraint)) {
|
|
168
|
+
const target = table(name);
|
|
169
|
+
if (target)
|
|
170
|
+
addConstraint(target, body.replace(/\s+/g, " "));
|
|
171
|
+
}
|
|
172
|
+
for (const match of matches(PATTERNS.index))
|
|
173
|
+
table(match[3])?.indexes.push(parseIndex(match));
|
|
174
|
+
for (const [, name] of matches(PATTERNS.rls)) {
|
|
175
|
+
const target = table(name);
|
|
176
|
+
if (target)
|
|
177
|
+
target.rls = true;
|
|
178
|
+
}
|
|
179
|
+
for (const match of matches(PATTERNS.policy))
|
|
180
|
+
table(match[1])?.policies.push((match.input ?? "").replace(/\s+/g, " "));
|
|
181
|
+
for (const [, name, literal] of matches(PATTERNS.tableComment)) {
|
|
182
|
+
const target = table(name);
|
|
183
|
+
if (target)
|
|
184
|
+
target.comment = unescapeLiteral(literal);
|
|
185
|
+
}
|
|
186
|
+
for (const [, tableName, name, literal] of matches(PATTERNS.columnComment)) {
|
|
187
|
+
const target = column(tableName, name);
|
|
188
|
+
if (target)
|
|
189
|
+
target.comment = unescapeLiteral(literal);
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
enums: enums.sort(byName),
|
|
193
|
+
tables: new Map([...tables].sort(([a], [b]) => a.localeCompare(b))),
|
|
194
|
+
views: definitions(PATTERNS.view),
|
|
195
|
+
functions: definitions(PATTERNS.function),
|
|
196
|
+
triggers: definitions(PATTERNS.trigger),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { displayName, orderColumns, shortType } from "../diagram.js";
|
|
2
|
+
function identifier(name) {
|
|
3
|
+
return /^[A-Za-z_]\w*$/.test(name) ? name : `"${name.replace(/"/g, '\\"')}"`;
|
|
4
|
+
}
|
|
5
|
+
function tableName(qualified, diagram) {
|
|
6
|
+
return displayName(qualified, diagram.primarySchema).split(".").map(identifier).join(".");
|
|
7
|
+
}
|
|
8
|
+
function text(value) {
|
|
9
|
+
return value.includes("\n") ? `'''${value.replace(/'''/g, "\\'''")}'''` : `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
10
|
+
}
|
|
11
|
+
function type(column, diagram) {
|
|
12
|
+
const short = shortType(column.type, diagram.primarySchema);
|
|
13
|
+
const plain = /^[A-Za-z_][\w.]*(\(\d+(, ?\d+)?\))?(\[\])*$/.test(short) && !(short.includes(".") && short.includes("("));
|
|
14
|
+
return plain ? short : `"${short}"`;
|
|
15
|
+
}
|
|
16
|
+
function defaultValue(value) {
|
|
17
|
+
if (value.startsWith("nextval("))
|
|
18
|
+
return null;
|
|
19
|
+
if (/^(true|false|null)$/i.test(value))
|
|
20
|
+
return `default: ${value.toLowerCase()}`;
|
|
21
|
+
if (/^-?\d+(\.\d+)?$/.test(value))
|
|
22
|
+
return `default: ${value}`;
|
|
23
|
+
const string = value.match(/^'((?:[^']|'')*)'(?:::[\w. ]+(?:\[\])?)?$/);
|
|
24
|
+
if (string)
|
|
25
|
+
return `default: ${text(string[1].replace(/''/g, "'"))}`;
|
|
26
|
+
return `default: \`${value.replace(/`/g, "'")}\``;
|
|
27
|
+
}
|
|
28
|
+
function columnSettings(table, column, diagram) {
|
|
29
|
+
const settings = [];
|
|
30
|
+
const singlePk = table.primaryKey.length === 1 && table.primaryKey[0] === column.name;
|
|
31
|
+
if (singlePk)
|
|
32
|
+
settings.push("pk");
|
|
33
|
+
if (column.identity || column.default?.startsWith("nextval("))
|
|
34
|
+
settings.push("increment");
|
|
35
|
+
if (column.notNull && !singlePk)
|
|
36
|
+
settings.push("not null");
|
|
37
|
+
const unique = table.uniques.some((columns) => columns.length === 1 && columns[0] === column.name) ||
|
|
38
|
+
table.indexes.some((index) => index.unique && !index.partial && index.columns?.length === 1 && index.columns[0] === column.name);
|
|
39
|
+
if (unique && !singlePk)
|
|
40
|
+
settings.push("unique");
|
|
41
|
+
const fallback = column.default === null ? null : defaultValue(column.default);
|
|
42
|
+
if (fallback)
|
|
43
|
+
settings.push(fallback);
|
|
44
|
+
const notes = [
|
|
45
|
+
column.comment,
|
|
46
|
+
column.generated ? "generated column" : null,
|
|
47
|
+
diagram.hiddenRefs.get(`${table.name}.${column.name}`) ?? null,
|
|
48
|
+
].filter((note) => note !== null);
|
|
49
|
+
if (notes.length)
|
|
50
|
+
settings.push(`note: ${text(notes.join("; "))}`);
|
|
51
|
+
return settings;
|
|
52
|
+
}
|
|
53
|
+
function indexes(table) {
|
|
54
|
+
const columns = (names) => (names.length === 1 ? identifier(names[0]) : `(${names.map(identifier).join(", ")})`);
|
|
55
|
+
const lines = [
|
|
56
|
+
...(table.primaryKey.length > 1 ? [`${columns(table.primaryKey)} [pk]`] : []),
|
|
57
|
+
...table.uniques.filter((unique) => unique.length > 1).map((unique) => `${columns(unique)} [unique]`),
|
|
58
|
+
...table.indexes.map((index) => {
|
|
59
|
+
const target = index.columns ? columns(index.columns) : `\`${index.expression}\``;
|
|
60
|
+
const settings = [...(index.unique ? ["unique"] : []), `name: ${text(index.name)}`, ...(index.partial ? ["note: 'partial'"] : [])];
|
|
61
|
+
return `${target} [${settings.join(", ")}]`;
|
|
62
|
+
}),
|
|
63
|
+
];
|
|
64
|
+
return lines.length ? ["", " indexes {", ...lines.map((line) => ` ${line}`), " }"] : [];
|
|
65
|
+
}
|
|
66
|
+
function table(table, diagram) {
|
|
67
|
+
return [
|
|
68
|
+
`Table ${tableName(table.name, diagram)} {`,
|
|
69
|
+
...orderColumns(table).map((column) => {
|
|
70
|
+
const settings = columnSettings(table, column, diagram);
|
|
71
|
+
return ` ${identifier(column.name)} ${type(column, diagram)}${settings.length ? ` [${settings.join(", ")}]` : ""}`;
|
|
72
|
+
}),
|
|
73
|
+
...indexes(table),
|
|
74
|
+
...(table.comment === null ? [] : ["", ` Note: ${text(table.comment)}`]),
|
|
75
|
+
"}",
|
|
76
|
+
"",
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
function endpoint(qualified, columns, diagram) {
|
|
80
|
+
const names = columns.map(identifier);
|
|
81
|
+
return `${tableName(qualified, diagram)}.${names.length === 1 ? names[0] : `(${names.join(", ")})`}`;
|
|
82
|
+
}
|
|
83
|
+
function ref(relation, diagram) {
|
|
84
|
+
const operator = relation.cardinality === "one-to-one" ? "-" : ">";
|
|
85
|
+
return `Ref: ${endpoint(relation.table, relation.columns, diagram)} ${operator} ${endpoint(relation.refTable, relation.refColumns, diagram)}`;
|
|
86
|
+
}
|
|
87
|
+
export function writeDbml(diagram) {
|
|
88
|
+
const enums = diagram.enums.flatMap(({ name, values }) => [
|
|
89
|
+
`Enum ${tableName(name, diagram)} {`,
|
|
90
|
+
...values.map((value) => ` ${/^\w+$/.test(value) ? value : `"${value.replace(/"/g, '\\"')}"`}`),
|
|
91
|
+
"}",
|
|
92
|
+
"",
|
|
93
|
+
]);
|
|
94
|
+
return [
|
|
95
|
+
`// ${diagram.title}`,
|
|
96
|
+
"// Generated by strabo: regenerate it rather than editing it. Visualise at https://dbdiagram.io",
|
|
97
|
+
...diagram.notes.map((note) => `// ${note}`),
|
|
98
|
+
"",
|
|
99
|
+
...enums,
|
|
100
|
+
...diagram.tables.flatMap((entry) => table(entry, diagram)),
|
|
101
|
+
...diagram.relations.map((relation) => ref(relation, diagram)),
|
|
102
|
+
...(diagram.externalRelations.length ? ["", "// References to tables outside this diagram"] : []),
|
|
103
|
+
...diagram.externalRelations.map((relation) => `// ${ref(relation, diagram)}`),
|
|
104
|
+
]
|
|
105
|
+
.join("\n")
|
|
106
|
+
.trimEnd()
|
|
107
|
+
.concat("\n");
|
|
108
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { displayName, orderColumns, shortType } from "../diagram.js";
|
|
2
|
+
const STYLE = [
|
|
3
|
+
"skinparam entity {",
|
|
4
|
+
" BackgroundColor #FEFEFE",
|
|
5
|
+
" BorderColor #888888",
|
|
6
|
+
"}",
|
|
7
|
+
"skinparam arrow {",
|
|
8
|
+
" Color #555555",
|
|
9
|
+
"}",
|
|
10
|
+
"skinparam nodesep 60",
|
|
11
|
+
"skinparam ranksep 80",
|
|
12
|
+
"hide empty members",
|
|
13
|
+
"left to right direction",
|
|
14
|
+
];
|
|
15
|
+
function alias(qualified, diagram) {
|
|
16
|
+
return displayName(qualified, diagram.primarySchema).replace(/\W/g, "_");
|
|
17
|
+
}
|
|
18
|
+
function label(qualified, diagram) {
|
|
19
|
+
return displayName(qualified, diagram.primarySchema).replace(/"/g, "'");
|
|
20
|
+
}
|
|
21
|
+
function entity(table, diagram) {
|
|
22
|
+
const foreignKeyColumns = new Set(table.foreignKeys.flatMap((foreignKey) => foreignKey.columns));
|
|
23
|
+
const line = (name) => {
|
|
24
|
+
const column = table.columns.find((candidate) => candidate.name === name);
|
|
25
|
+
if (!column)
|
|
26
|
+
return [];
|
|
27
|
+
const stereotypes = [
|
|
28
|
+
...(table.primaryKey.includes(name) ? ["<<PK>>"] : []),
|
|
29
|
+
...(foreignKeyColumns.has(name) ? ["<<FK>>"] : []),
|
|
30
|
+
];
|
|
31
|
+
const required = column.notNull ? "* " : "";
|
|
32
|
+
return [` ${required}${name} : ${shortType(column.type, diagram.primarySchema)}${stereotypes.length ? ` ${stereotypes.join(" ")}` : ""}`];
|
|
33
|
+
};
|
|
34
|
+
const ordered = orderColumns(table).map((column) => column.name);
|
|
35
|
+
const keys = ordered.filter((name) => table.primaryKey.includes(name));
|
|
36
|
+
const rest = ordered.filter((name) => !table.primaryKey.includes(name));
|
|
37
|
+
return [
|
|
38
|
+
`entity "${label(table.name, diagram)}" as ${alias(table.name, diagram)} {`,
|
|
39
|
+
...keys.flatMap(line),
|
|
40
|
+
...(keys.length && rest.length ? [" --"] : []),
|
|
41
|
+
...rest.flatMap(line),
|
|
42
|
+
"}",
|
|
43
|
+
"",
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
function relation(relation, diagram) {
|
|
47
|
+
const childEnd = relation.cardinality === "one-to-one" ? (relation.optional ? "o|" : "||") : relation.optional ? "o{" : "|{";
|
|
48
|
+
return `${alias(relation.refTable, diagram)} ||--${childEnd} ${alias(relation.table, diagram)} : "${relation.columns.join(", ")}"`;
|
|
49
|
+
}
|
|
50
|
+
export function writePuml(diagram) {
|
|
51
|
+
const enums = diagram.enums.flatMap(({ name, values }) => [
|
|
52
|
+
`enum "${label(name, diagram)}" as ${alias(name, diagram)} {`,
|
|
53
|
+
...values.map((value) => ` ${value}`),
|
|
54
|
+
"}",
|
|
55
|
+
"",
|
|
56
|
+
]);
|
|
57
|
+
return [
|
|
58
|
+
`@startuml ${diagram.name.split("/").pop()}`,
|
|
59
|
+
"' Generated by strabo: regenerate it rather than editing it.",
|
|
60
|
+
"",
|
|
61
|
+
...STYLE,
|
|
62
|
+
"",
|
|
63
|
+
`title ${diagram.title}`,
|
|
64
|
+
"",
|
|
65
|
+
...(diagram.notes.length ? ["legend top left", ...diagram.notes, "endlegend", ""] : []),
|
|
66
|
+
...enums,
|
|
67
|
+
...diagram.tables.flatMap((table) => entity(table, diagram)),
|
|
68
|
+
...diagram.relations.map((entry) => relation(entry, diagram)),
|
|
69
|
+
...(diagram.externalRelations.length ? ["", "' References to tables outside this diagram"] : []),
|
|
70
|
+
...diagram.externalRelations.map((entry) => `' ${label(entry.table, diagram)}.${entry.columns.join(", ")} -> ${label(entry.refTable, diagram)}.${entry.refColumns.join(", ")}`),
|
|
71
|
+
"",
|
|
72
|
+
"@enduml",
|
|
73
|
+
"",
|
|
74
|
+
].join("\n");
|
|
75
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const HEADER = [
|
|
2
|
+
"-- Generated by strabo from pg_dump. Context only: never execute this file.",
|
|
3
|
+
"-- Statements are grouped for reading, so their order and constraints may not run as written.",
|
|
4
|
+
];
|
|
5
|
+
function literal(text) {
|
|
6
|
+
return `'${text.replace(/'/g, "''")}'`;
|
|
7
|
+
}
|
|
8
|
+
function block(lines) {
|
|
9
|
+
return lines.map((line, index) => ` ${line}${index < lines.length - 1 ? "," : ""}`);
|
|
10
|
+
}
|
|
11
|
+
function table(table) {
|
|
12
|
+
const out = [
|
|
13
|
+
`CREATE TABLE ${table.name} (`,
|
|
14
|
+
...block([...table.columns.map((column) => column.definition), ...table.checks, ...table.constraints]),
|
|
15
|
+
");",
|
|
16
|
+
];
|
|
17
|
+
if (table.comment !== null)
|
|
18
|
+
out.push(`COMMENT ON TABLE ${table.name} IS ${literal(table.comment)};`);
|
|
19
|
+
for (const column of table.columns)
|
|
20
|
+
if (column.comment !== null)
|
|
21
|
+
out.push(`COMMENT ON COLUMN ${table.name}.${column.name} IS ${literal(column.comment)};`);
|
|
22
|
+
out.push(...table.indexes.map((index) => index.definition));
|
|
23
|
+
if (table.rls)
|
|
24
|
+
out.push(`ALTER TABLE ${table.name} ENABLE ROW LEVEL SECURITY;`);
|
|
25
|
+
out.push(...table.policies);
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
function section(title, entries) {
|
|
29
|
+
if (entries.length === 0)
|
|
30
|
+
return [];
|
|
31
|
+
return [`-- ${title}`, "", ...entries.flatMap((entry) => [...entry, ""])];
|
|
32
|
+
}
|
|
33
|
+
function bodies(definitions) {
|
|
34
|
+
return definitions.map(({ body }) => [body]);
|
|
35
|
+
}
|
|
36
|
+
export function writeSql(schema) {
|
|
37
|
+
const enums = schema.enums.map(({ name, values, comments }) => [
|
|
38
|
+
`CREATE TYPE ${name} AS ENUM (`,
|
|
39
|
+
...block(values.map(literal)),
|
|
40
|
+
");",
|
|
41
|
+
...comments,
|
|
42
|
+
]);
|
|
43
|
+
return [
|
|
44
|
+
...HEADER,
|
|
45
|
+
"",
|
|
46
|
+
...section("Enums", enums),
|
|
47
|
+
...section("Tables", [...schema.tables.values()].map(table)),
|
|
48
|
+
...section("Views", bodies(schema.views)),
|
|
49
|
+
...section("Functions", bodies(schema.functions)),
|
|
50
|
+
...section("Triggers", bodies(schema.triggers)),
|
|
51
|
+
]
|
|
52
|
+
.join("\n")
|
|
53
|
+
.trimEnd()
|
|
54
|
+
.concat("\n");
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeSvg(dbml: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const RENDERER = "@softwaretechnik/dbml-renderer";
|
|
4
|
+
function loadRenderer() {
|
|
5
|
+
for (const from of [path.join(process.cwd(), "package.json"), import.meta.url]) {
|
|
6
|
+
try {
|
|
7
|
+
return createRequire(from)(RENDERER).run;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
throw new Error(`The svg format needs ${RENDERER}: add it to your dev dependencies, then try again.`);
|
|
14
|
+
}
|
|
15
|
+
export function writeSvg(dbml) {
|
|
16
|
+
return loadRenderer()(dbml, "svg");
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tandemcreativedev/strabo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Turn a Postgres schema into a readable record for people and AI: a tidy SQL reference plus DBML, PlantUML and SVG diagrams, generated from pg_dump.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"postgres",
|
|
7
|
+
"pg_dump",
|
|
8
|
+
"schema",
|
|
9
|
+
"dbml",
|
|
10
|
+
"plantuml",
|
|
11
|
+
"erd",
|
|
12
|
+
"supabase",
|
|
13
|
+
"documentation"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Tandem Creative Dev",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/TandemCreativeDev/strabo.git"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"bin": {
|
|
23
|
+
"strabo": "dist/cli.js"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@softwaretechnik/dbml-renderer": "^1.0.31"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@softwaretechnik/dbml-renderer": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@dbml/core": "11.0.1",
|
|
47
|
+
"@softwaretechnik/dbml-renderer": "1.0.31",
|
|
48
|
+
"@types/node": "^22",
|
|
49
|
+
"typescript": "^5.9"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && node scripts/fix-declarations.mjs",
|
|
53
|
+
"typecheck": "tsc --noEmit",
|
|
54
|
+
"test": "node --test 'test/**/*.test.ts'",
|
|
55
|
+
"fixture": "bash test/fixtures/regenerate.sh"
|
|
56
|
+
}
|
|
6
57
|
}
|