@matserdam/prisma-neighborhood 0.0.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.
Files changed (44) hide show
  1. package/README.md +141 -0
  2. package/dist/_tests_/cli.test.d.ts +6 -0
  3. package/dist/_tests_/cli.test.d.ts.map +1 -0
  4. package/dist/_tests_/parser.test.d.ts +6 -0
  5. package/dist/_tests_/parser.test.d.ts.map +1 -0
  6. package/dist/_tests_/renderer.test.d.ts +6 -0
  7. package/dist/_tests_/renderer.test.d.ts.map +1 -0
  8. package/dist/_tests_/traverser.test.d.ts +6 -0
  9. package/dist/_tests_/traverser.test.d.ts.map +1 -0
  10. package/dist/cli/commands.d.ts +18 -0
  11. package/dist/cli/commands.d.ts.map +1 -0
  12. package/dist/cli/index.d.ts +9 -0
  13. package/dist/cli/index.d.ts.map +1 -0
  14. package/dist/cli/options.d.ts +42 -0
  15. package/dist/cli/options.d.ts.map +1 -0
  16. package/dist/cli/types.d.ts +29 -0
  17. package/dist/cli/types.d.ts.map +1 -0
  18. package/dist/cli.d.ts +7 -0
  19. package/dist/cli.d.ts.map +1 -0
  20. package/dist/cli.js +257794 -0
  21. package/dist/index.d.ts +9 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +257949 -0
  24. package/dist/parser/index.d.ts +7 -0
  25. package/dist/parser/index.d.ts.map +1 -0
  26. package/dist/parser/schema-parser.d.ts +24 -0
  27. package/dist/parser/schema-parser.d.ts.map +1 -0
  28. package/dist/parser/types.d.ts +83 -0
  29. package/dist/parser/types.d.ts.map +1 -0
  30. package/dist/renderer/index.d.ts +8 -0
  31. package/dist/renderer/index.d.ts.map +1 -0
  32. package/dist/renderer/mermaid-renderer.d.ts +65 -0
  33. package/dist/renderer/mermaid-renderer.d.ts.map +1 -0
  34. package/dist/renderer/registry.d.ts +79 -0
  35. package/dist/renderer/registry.d.ts.map +1 -0
  36. package/dist/renderer/types.d.ts +94 -0
  37. package/dist/renderer/types.d.ts.map +1 -0
  38. package/dist/traversal/index.d.ts +7 -0
  39. package/dist/traversal/index.d.ts.map +1 -0
  40. package/dist/traversal/model-traverser.d.ts +35 -0
  41. package/dist/traversal/model-traverser.d.ts.map +1 -0
  42. package/dist/traversal/types.d.ts +35 -0
  43. package/dist/traversal/types.d.ts.map +1 -0
  44. package/package.json +66 -0
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # prisma-subgraph-cli
2
+
3
+ CLI tool that generates Entity-Relationship Diagrams from Prisma schemas, starting from a specified model and traversing relationships to a configurable depth.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun install
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ # Basic usage - generate ERD starting from User model (stdout)
15
+ bun src/index.ts -s ./prisma/schema.prisma -m User
16
+
17
+ # With custom depth (default is 3)
18
+ bun src/index.ts -s ./prisma/schema.prisma -m User -d 5
19
+
20
+ # Output to Mermaid file
21
+ bun src/index.ts -s ./prisma/schema.prisma -m User -o diagram.mmd
22
+
23
+ # Export to PNG
24
+ bun src/index.ts -s ./prisma/schema.prisma -m User -o diagram.png
25
+
26
+ # Export to PDF
27
+ bun src/index.ts -s ./prisma/schema.prisma -m User -o diagram.pdf
28
+
29
+ # List available renderers
30
+ bun src/index.ts --list-renderers
31
+
32
+ # Show help
33
+ bun src/index.ts --help
34
+ ```
35
+
36
+ ## Options
37
+
38
+ | Option | Alias | Description | Default |
39
+ |--------|-------|-------------|---------|
40
+ | `--schema <path>` | `-s` | Path to the Prisma schema file | (required) |
41
+ | `--model <name>` | `-m` | Name of the model to start traversal from | (required) |
42
+ | `--depth <n>` | `-d` | Traversal depth | 3 |
43
+ | `--renderer <name>` | `-r` | Diagram renderer | mermaid |
44
+ | `--output <file>` | `-o` | Output file (stdout if omitted) | - |
45
+ | `--list-renderers` | - | Show available renderers | - |
46
+ | `--help` | `-h` | Display help | - |
47
+ | `--version` | `-V` | Output version | - |
48
+
49
+ ### Output Formats
50
+
51
+ The output format is determined by the file extension:
52
+
53
+ | Extension | Format |
54
+ |-----------|--------|
55
+ | `.mmd` | Mermaid text |
56
+ | `.md` | Mermaid text |
57
+ | `.png` | PNG image |
58
+ | `.pdf` | PDF document |
59
+
60
+ ### PNG/PDF Export Requirements
61
+
62
+ PNG and PDF export uses `@mermaid-js/mermaid-cli` which relies on Puppeteer (headless Chromium).
63
+
64
+ #### Platform Compatibility
65
+
66
+ | Platform | Status | Notes |
67
+ |----------|--------|-------|
68
+ | macOS | Works out of the box | No additional setup needed |
69
+ | Windows | Works out of the box | No additional setup needed |
70
+ | Linux | Requires dependencies | See below |
71
+
72
+ #### Linux Dependencies
73
+
74
+ On Linux, Puppeteer requires additional system libraries:
75
+
76
+ ```bash
77
+ # Debian/Ubuntu
78
+ sudo apt-get install -y \
79
+ libnss3 \
80
+ libatk1.0-0 \
81
+ libatk-bridge2.0-0 \
82
+ libcups2 \
83
+ libdrm2 \
84
+ libxkbcommon0 \
85
+ libxcomposite1 \
86
+ libxdamage1 \
87
+ libxrandr2 \
88
+ libgbm1 \
89
+ libasound2 \
90
+ libpangocairo-1.0-0 \
91
+ libgtk-3-0
92
+
93
+ # Alpine (Docker)
94
+ apk add chromium
95
+ ```
96
+
97
+ #### CI/CD Environments
98
+
99
+ For CI pipelines, either:
100
+ - Install the dependencies listed above
101
+ - Use a Docker image with Chromium pre-installed (e.g., `node:18-bullseye`)
102
+
103
+ #### Alternative: Text-only Mode
104
+
105
+ If PNG/PDF export is problematic, you can:
106
+ 1. Output to `.mmd` file and use an online renderer like [mermaid.live](https://mermaid.live)
107
+ 2. Use VS Code with a Mermaid preview extension
108
+ 3. Embed the Mermaid syntax directly in Markdown documentation
109
+
110
+ ## Example Output
111
+
112
+ Given a Prisma schema with User, Post, and Profile models:
113
+
114
+ ```mermaid
115
+ erDiagram
116
+ User {
117
+ Int id PK
118
+ String email UK
119
+ String name
120
+ DateTime createdAt
121
+ }
122
+ Post {
123
+ Int id PK
124
+ String title
125
+ String content
126
+ Boolean published
127
+ Int authorId
128
+ DateTime createdAt
129
+ }
130
+ Profile {
131
+ Int id PK
132
+ String bio
133
+ Int userId UK
134
+ }
135
+ User ||--o{ Post : "posts"
136
+ User ||--|| Profile : "profile"
137
+ ```
138
+
139
+ ## License
140
+
141
+ MIT
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @fileoverview Tests for the CLI interface.
3
+ * Tests cover command-line argument parsing, renderer selection, and output.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=cli.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.test.d.ts","sourceRoot":"","sources":["../../src/_tests_/cli.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @fileoverview Tests for the Prisma schema parser.
3
+ * Tests cover parsing of models, fields, relations, and edge cases.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=parser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.test.d.ts","sourceRoot":"","sources":["../../src/_tests_/parser.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @fileoverview Tests for the renderer system.
3
+ * Tests cover DiagramRenderer interface compliance, Mermaid output, and registry.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=renderer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.test.d.ts","sourceRoot":"","sources":["../../src/_tests_/renderer.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @fileoverview Tests for the model traverser.
3
+ * Tests cover BFS traversal, depth limiting, and cycle detection.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=traverser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traverser.test.d.ts","sourceRoot":"","sources":["../../src/_tests_/traverser.test.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview CLI command definitions using Commander.
3
+ * Defines the main CLI program and its commands.
4
+ */
5
+ import { Command } from "commander";
6
+ /**
7
+ * Creates and configures the CLI program.
8
+ *
9
+ * @returns The configured Commander program
10
+ */
11
+ export declare function createProgram(): Command;
12
+ /**
13
+ * Runs the CLI with the provided arguments.
14
+ *
15
+ * @param args - Command-line arguments (typically process.argv)
16
+ */
17
+ export declare function runCli(args: string[]): Promise<void>;
18
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkCpC;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,CA2BvC;AAqID;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAG1D"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @fileoverview CLI module exports.
3
+ * Provides CLI functionality and type definitions.
4
+ */
5
+ export { createProgram, runCli } from "./commands";
6
+ export { parseCliOptions } from "./options";
7
+ export type { CliOptions } from "./types";
8
+ export { DEFAULT_CLI_OPTIONS } from "./types";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileoverview CLI option parsing utilities.
3
+ * Parses command-line arguments into structured options.
4
+ */
5
+ import type { CliOptions } from "./types";
6
+ /**
7
+ * Result of CLI option parsing.
8
+ */
9
+ export type ParseResult = {
10
+ readonly success: true;
11
+ readonly options: CliOptions;
12
+ } | {
13
+ readonly success: false;
14
+ readonly error: string;
15
+ };
16
+ /**
17
+ * Parse CLI arguments into structured options.
18
+ *
19
+ * Arguments format:
20
+ * prisma-erd [options]
21
+ *
22
+ * Options:
23
+ * -s, --schema <path> Path to the Prisma schema file
24
+ * -m, --model <name> Name of the model to start traversal from
25
+ * -d, --depth <n> Traversal depth (default: 3)
26
+ * -r, --renderer <name> Diagram renderer (default: "mermaid")
27
+ * -o, --output <file> Output file: .mmd, .md (text), .png, .pdf (image)
28
+ * --list-renderers Show available renderers
29
+ *
30
+ * @param args - Command-line arguments (without node and script path)
31
+ * @returns A ParseResult containing the parsed options or an error
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const result = parseCliOptions(['--schema', './schema.prisma', '--model', 'User', '-d', '5']);
36
+ * if (result.success) {
37
+ * console.log(result.options);
38
+ * }
39
+ * ```
40
+ */
41
+ export declare function parseCliOptions(args: string[]): ParseResult;
42
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/cli/options.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C;;GAEG;AACH,MAAM,MAAM,WAAW,GACpB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,WAAW,CAkK3D"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @fileoverview Type definitions for CLI options and configuration.
3
+ */
4
+ /**
5
+ * CLI command options parsed from command-line arguments.
6
+ */
7
+ export interface CliOptions {
8
+ /** Path to the Prisma schema file */
9
+ readonly schema: string;
10
+ /** Name of the model to start traversal from */
11
+ readonly model: string;
12
+ /** Maximum traversal depth (default: 3) */
13
+ readonly depth: number;
14
+ /** Renderer to use (default: "mermaid") */
15
+ readonly renderer: string;
16
+ /** Output file path (stdout if not specified). Extension determines format: .mmd/.md (text), .png/.pdf (image) */
17
+ readonly output?: string;
18
+ /** List available renderers and exit */
19
+ readonly listRenderers: boolean;
20
+ }
21
+ /**
22
+ * Default CLI options.
23
+ */
24
+ export declare const DEFAULT_CLI_OPTIONS: {
25
+ depth: number;
26
+ renderer: string;
27
+ listRenderers: boolean;
28
+ };
29
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cli/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB,2CAA2C;IAC3C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,kHAAkH;IAClH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB,wCAAwC;IACxC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;CAKvB,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview Entry point for the prisma-neighborhood CLI.
4
+ * Generates Entity-Relationship Diagrams from Prisma schemas.
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG"}