@supawatch/target-dictionary 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Omar Dulaimi
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 ADDED
@@ -0,0 +1,15 @@
1
+ # @supawatch/target-dictionary
2
+
3
+ The data-dictionary target for
4
+ [supawatch](https://github.com/omar-dulaimi/supawatch). Emits
5
+ `schema-dictionary.md`: per-table sections with SQL types, runtime types,
6
+ nullability, keys, identity and default markers, plus enums, domains and
7
+ composite types. Column and table comments come from Postgres itself
8
+ (`comment on ...`), so the database stays the single source of
9
+ documentation truth, and a comment change regenerates the file live.
10
+
11
+ ```ts
12
+ targets: [{ kind: "dictionary" }]
13
+ ```
14
+
15
+ MIT.
@@ -0,0 +1,11 @@
1
+ import type { Snapshot, SnapshotFile, Target, TargetCapabilities, TargetOptions } from "@supawatch/core";
2
+ export type DictionaryTargetOptions = TargetOptions;
3
+ export declare class DictionaryTarget implements Target<DictionaryTargetOptions> {
4
+ readonly name = "dictionary";
5
+ readonly fileExtension = ".md";
6
+ readonly barrel = false;
7
+ readonly capabilities: TargetCapabilities;
8
+ renderTable(): never;
9
+ renderSnapshot(snapshot: Snapshot, _opts: DictionaryTargetOptions): SnapshotFile[];
10
+ }
11
+ export default DictionaryTarget;
package/dist/index.js ADDED
@@ -0,0 +1,91 @@
1
+ function runtimeLabel(runtime) {
2
+ switch (runtime.kind) {
3
+ case "number":
4
+ return runtime.integer ? "number (integer)" : "number";
5
+ case "string":
6
+ return runtime.format ? `string (${runtime.format})` : "string";
7
+ case "boolean":
8
+ return "boolean";
9
+ case "date":
10
+ return "Date";
11
+ case "bytes":
12
+ return "Uint8Array";
13
+ case "json":
14
+ return "json (unknown shape)";
15
+ case "unknown":
16
+ return "unknown";
17
+ case "array":
18
+ return `array of ${runtimeLabel(runtime.element)}`;
19
+ case "enum":
20
+ return `enum: ${runtime.labels.join(", ")}`;
21
+ }
22
+ }
23
+ export class DictionaryTarget {
24
+ name = "dictionary";
25
+ fileExtension = ".md";
26
+ barrel = false;
27
+ capabilities = {
28
+ strictObjects: false,
29
+ brandedTypes: false,
30
+ dateInstances: false,
31
+ };
32
+ renderTable() {
33
+ throw new Error("dictionary is a snapshot-level target");
34
+ }
35
+ renderSnapshot(snapshot, _opts) {
36
+ const lines = [
37
+ "<!-- Generated by supawatch. Do not edit. -->",
38
+ "# Data dictionary",
39
+ "",
40
+ ];
41
+ for (const table of snapshot.tables) {
42
+ const marker = table.kind === "view" ? " (view)" : "";
43
+ lines.push(`## ${table.schema}.${table.name}${marker}`);
44
+ if (table.comment)
45
+ lines.push("", table.comment);
46
+ lines.push("", "| Column | SQL type | Runtime | Nullable | Notes |", "| --- | --- | --- | --- | --- |");
47
+ for (const col of table.columns) {
48
+ const notes = [];
49
+ if (table.primaryKey.includes(col.name))
50
+ notes.push("PK");
51
+ const fk = table.foreignKeys.find((f) => f.columns.includes(col.name));
52
+ if (fk) {
53
+ notes.push(`FK to ${fk.referencedTable}.${fk.referencedColumns[0]}`);
54
+ }
55
+ if (col.identity)
56
+ notes.push(`identity ${col.identity}`);
57
+ if (col.generated)
58
+ notes.push("generated");
59
+ if (col.hasDefault)
60
+ notes.push("has default");
61
+ if (col.comment)
62
+ notes.push(col.comment);
63
+ lines.push(`| ${col.name} | ${col.sqlType} | ${runtimeLabel(col.runtime)} | ${col.nullable ? "yes" : "no"} | ${notes.join("; ")} |`);
64
+ }
65
+ lines.push("");
66
+ }
67
+ if (snapshot.enums.length > 0) {
68
+ lines.push("## Enums", "");
69
+ for (const e of snapshot.enums) {
70
+ lines.push(`- **${e.name}**: ${e.labels.join(", ")}`);
71
+ }
72
+ lines.push("");
73
+ }
74
+ if (snapshot.domains.length > 0) {
75
+ lines.push("## Domains", "");
76
+ for (const d of snapshot.domains) {
77
+ lines.push(`- **${d.name}**: based on ${d.baseTypeName}`);
78
+ }
79
+ lines.push("");
80
+ }
81
+ if (snapshot.composites.length > 0) {
82
+ lines.push("## Composite types", "");
83
+ for (const c of snapshot.composites) {
84
+ lines.push(`- **${c.name}**: ${c.fields.map((f) => `${f.name} ${f.pgTypeName}`).join(", ")}`);
85
+ }
86
+ lines.push("");
87
+ }
88
+ return [{ file: "schema-dictionary.md", content: lines.join("\n") }];
89
+ }
90
+ }
91
+ export default DictionaryTarget;
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@supawatch/target-dictionary",
3
+ "version": "0.2.0",
4
+ "description": "A markdown data dictionary generated from live Postgres by supawatch, comments sourced from the database itself.",
5
+ "keywords": [
6
+ "supabase",
7
+ "postgres",
8
+ "postgresql",
9
+ "codegen",
10
+ "schema",
11
+ "typescript",
12
+ "data-dictionary",
13
+ "documentation",
14
+ "comments"
15
+ ],
16
+ "license": "MIT",
17
+ "author": "Omar Dulaimi",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/omar-dulaimi/supawatch.git",
21
+ "directory": "packages/target-dictionary"
22
+ },
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "dependencies": {
36
+ "@supawatch/core": "0.3.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.20.1",
40
+ "typescript": "^5.9.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc -p tsconfig.json"
44
+ }
45
+ }