@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
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @fileoverview Parser module exports.
3
+ * Provides schema parsing functionality and type definitions.
4
+ */
5
+ export { parseSchema } from "./schema-parser";
6
+ export type { Field, Model, ParsedSchema, ParseResult, ParserOptions, Relation, RelationType, ScalarType, } from "./types";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EACX,KAAK,EACL,KAAK,EACL,YAAY,EACZ,WAAW,EACX,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,UAAU,GACV,MAAM,SAAS,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @fileoverview Prisma schema parser using @prisma/internals.
3
+ * Parses Prisma schema files and converts them to our internal representation.
4
+ */
5
+ import type { ParseResult, ParserOptions } from "./types";
6
+ /**
7
+ * Parses a Prisma schema file and returns a structured representation.
8
+ *
9
+ * Uses @prisma/internals getDMMF to parse the schema file and extract
10
+ * model definitions, fields, and relationships.
11
+ *
12
+ * @param options - Parser configuration options
13
+ * @returns A ParseResult containing the parsed schema or an error
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const result = await parseSchema({ schemaPath: './prisma/schema.prisma' });
18
+ * if (result.success) {
19
+ * console.log(result.schema.models);
20
+ * }
21
+ * ```
22
+ */
23
+ export declare function parseSchema(options: ParserOptions): Promise<ParseResult>;
24
+ //# sourceMappingURL=schema-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-parser.d.ts","sourceRoot":"","sources":["../../src/parser/schema-parser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAGX,WAAW,EACX,aAAa,EAGb,MAAM,SAAS,CAAC;AAmEjB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,WAAW,CAChC,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,WAAW,CAAC,CA6GtB"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @fileoverview Type definitions for parsed Prisma schema models.
3
+ * These types provide a clean internal representation independent of Prisma internals.
4
+ */
5
+ /**
6
+ * Represents the cardinality of a relationship between models.
7
+ * - ONE_TO_ONE: Single record on both sides
8
+ * - ONE_TO_MANY: Single record on one side, multiple on the other
9
+ * - MANY_TO_MANY: Multiple records on both sides
10
+ */
11
+ export type RelationType = "ONE_TO_ONE" | "ONE_TO_MANY" | "MANY_TO_MANY";
12
+ /**
13
+ * Represents a relationship between two models in the schema.
14
+ */
15
+ export interface Relation {
16
+ /** The name of the related model */
17
+ readonly relatedModel: string;
18
+ /** The type of relationship (cardinality) */
19
+ readonly type: RelationType;
20
+ /** The field name on this model that defines the relation */
21
+ readonly fieldName: string;
22
+ /** Whether this is the owning side of the relation (has the foreign key) */
23
+ readonly isOwner: boolean;
24
+ }
25
+ /**
26
+ * Scalar field types supported in Prisma schemas.
27
+ */
28
+ export type ScalarType = "String" | "Int" | "BigInt" | "Float" | "Decimal" | "Boolean" | "DateTime" | "Json" | "Bytes";
29
+ /**
30
+ * Represents a field in a Prisma model.
31
+ */
32
+ export interface Field {
33
+ /** The field name */
34
+ readonly name: string;
35
+ /** The field type (scalar type or model name for relations) */
36
+ readonly type: string;
37
+ /** Whether the field is required (not nullable) */
38
+ readonly isRequired: boolean;
39
+ /** Whether the field is a list (array) */
40
+ readonly isList: boolean;
41
+ /** Whether this field is the primary key */
42
+ readonly isPrimaryKey: boolean;
43
+ /** Whether this field is unique */
44
+ readonly isUnique: boolean;
45
+ /** Whether this field is a relation to another model */
46
+ readonly isRelation: boolean;
47
+ }
48
+ /**
49
+ * Represents a parsed Prisma model with its fields and relations.
50
+ */
51
+ export interface Model {
52
+ /** The model name */
53
+ readonly name: string;
54
+ /** All fields in the model */
55
+ readonly fields: readonly Field[];
56
+ /** Relations to other models */
57
+ readonly relations: readonly Relation[];
58
+ }
59
+ /**
60
+ * Represents the complete parsed schema containing all models.
61
+ */
62
+ export interface ParsedSchema {
63
+ /** All models in the schema, keyed by model name */
64
+ readonly models: ReadonlyMap<string, Model>;
65
+ }
66
+ /**
67
+ * Configuration options for the schema parser.
68
+ */
69
+ export interface ParserOptions {
70
+ /** Path to the Prisma schema file */
71
+ readonly schemaPath: string;
72
+ }
73
+ /**
74
+ * Result of a parsing operation.
75
+ */
76
+ export type ParseResult = {
77
+ readonly success: true;
78
+ readonly schema: ParsedSchema;
79
+ } | {
80
+ readonly success: false;
81
+ readonly error: string;
82
+ };
83
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/parser/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,aAAa,GAAG,cAAc,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,oCAAoC;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAE5B,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GACnB,QAAQ,GACR,KAAK,GACL,QAAQ,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,UAAU,GACV,MAAM,GACN,OAAO,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,KAAK;IACrB,qBAAqB;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAEzB,4CAA4C;IAC5C,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAE/B,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACrB,qBAAqB;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAElC,gCAAgC;IAChC,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,qCAAqC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACpB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GACzD;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @fileoverview Renderer module exports.
3
+ * Provides diagram rendering functionality and type definitions.
4
+ */
5
+ export { MermaidRenderer } from "./mermaid-renderer";
6
+ export { RendererRegistry, rendererRegistry } from "./registry";
7
+ export type { DiagramRenderer, ExportFormat, ExportResult, RendererRegistration, RenderResult, } from "./types";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/renderer/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,YAAY,GACZ,MAAM,SAAS,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @fileoverview Mermaid ERD renderer implementation.
3
+ * Converts traversed models to Mermaid Entity-Relationship Diagram syntax.
4
+ */
5
+ import type { TraversedModel } from "../traversal/types";
6
+ import type { DiagramRenderer, ExportFormat } from "./types";
7
+ /**
8
+ * Mermaid ERD renderer implementation.
9
+ * Generates Mermaid Entity-Relationship Diagram syntax from traversed models.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const renderer = new MermaidRenderer();
14
+ * const output = renderer.render(traversedModels);
15
+ * console.log(output);
16
+ * // erDiagram
17
+ * // User {
18
+ * // Int id PK
19
+ * // String email UK
20
+ * // ...
21
+ * // }
22
+ * ```
23
+ */
24
+ export declare class MermaidRenderer implements DiagramRenderer {
25
+ /** Unique renderer identifier */
26
+ readonly name = "mermaid";
27
+ /** Human-readable description */
28
+ readonly description = "Mermaid ERD syntax - supports PNG/PDF export via mermaid-cli";
29
+ /**
30
+ * Generate Mermaid ERD syntax from traversed models.
31
+ *
32
+ * The output includes:
33
+ * - Entity definitions with fields and types
34
+ * - Primary key (PK) and unique (UK) markers
35
+ * - Relationship lines between entities
36
+ *
37
+ * @param models - The traversed models to render
38
+ * @returns The Mermaid ERD syntax as a string
39
+ */
40
+ render(models: readonly TraversedModel[]): string;
41
+ /**
42
+ * Export the diagram to PNG or PDF format.
43
+ * Uses mermaid-cli (@mermaid-js/mermaid-cli) for rendering.
44
+ *
45
+ * @param content - The Mermaid diagram content
46
+ * @param outputPath - Path to write the output file
47
+ * @param format - The export format (png or pdf)
48
+ * @throws Error if mermaid-cli is not available or export fails
49
+ */
50
+ export(content: string, outputPath: string, format: ExportFormat): Promise<void>;
51
+ /**
52
+ * Whether this renderer supports export functionality.
53
+ * @returns True - MermaidRenderer supports PNG/PDF export
54
+ */
55
+ supportsExport(): boolean;
56
+ /**
57
+ * Run mermaid-cli to convert the diagram to an image.
58
+ *
59
+ * @param inputPath - Path to the input .mmd file
60
+ * @param outputPath - Path to write the output file
61
+ * @param format - The export format
62
+ */
63
+ private runMermaidCli;
64
+ }
65
+ //# sourceMappingURL=mermaid-renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mermaid-renderer.d.ts","sourceRoot":"","sources":["../../src/renderer/mermaid-renderer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAgB7D;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,eAAgB,YAAW,eAAe;IACtD,iCAAiC;IACjC,QAAQ,CAAC,IAAI,aAAa;IAE1B,iCAAiC;IACjC,QAAQ,CAAC,WAAW,kEAC4C;IAEhE;;;;;;;;;;OAUG;IACH,MAAM,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM;IA0EjD;;;;;;;;OAQG;IACG,MAAM,CACX,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC;IAmBhB;;;OAGG;IACH,cAAc,IAAI,OAAO;IAIzB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;CA4CrB"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @fileoverview Renderer registry for managing diagram renderers.
3
+ * Provides a central registry with default renderer support.
4
+ */
5
+ import type { DiagramRenderer, RendererRegistration } from "./types";
6
+ /**
7
+ * Registry for managing diagram renderers.
8
+ * Supports registration, lookup, and listing of renderers.
9
+ */
10
+ export declare class RendererRegistry {
11
+ /** Map of renderer name to renderer instance */
12
+ private readonly renderers;
13
+ /** The name of the default renderer */
14
+ private defaultRendererName;
15
+ /**
16
+ * Register a renderer with the registry.
17
+ *
18
+ * @param registration - The renderer registration configuration
19
+ * @throws Error if a renderer with the same name is already registered
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * registry.register({
24
+ * renderer: new MermaidRenderer(),
25
+ * isDefault: true
26
+ * });
27
+ * ```
28
+ */
29
+ register(registration: RendererRegistration): void;
30
+ /**
31
+ * Get a renderer by name.
32
+ *
33
+ * @param name - The renderer name to look up
34
+ * @returns The renderer, or undefined if not found
35
+ */
36
+ get(name: string): DiagramRenderer | undefined;
37
+ /**
38
+ * Get the default renderer.
39
+ *
40
+ * @returns The default renderer, or undefined if no default is set
41
+ */
42
+ getDefault(): DiagramRenderer | undefined;
43
+ /**
44
+ * Get the name of the default renderer.
45
+ *
46
+ * @returns The default renderer name
47
+ */
48
+ getDefaultName(): string;
49
+ /**
50
+ * Check if a renderer is registered.
51
+ *
52
+ * @param name - The renderer name to check
53
+ * @returns True if the renderer is registered
54
+ */
55
+ has(name: string): boolean;
56
+ /**
57
+ * Get all registered renderers.
58
+ *
59
+ * @returns An array of all registered renderers
60
+ */
61
+ list(): readonly DiagramRenderer[];
62
+ /**
63
+ * Get all renderer names.
64
+ *
65
+ * @returns An array of all registered renderer names
66
+ */
67
+ listNames(): readonly string[];
68
+ /**
69
+ * Clear all registered renderers.
70
+ * Primarily used for testing.
71
+ */
72
+ clear(): void;
73
+ }
74
+ /**
75
+ * The global renderer registry instance.
76
+ * Use this instance for registering and looking up renderers.
77
+ */
78
+ export declare const rendererRegistry: RendererRegistry;
79
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/renderer/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAKrE;;;GAGG;AACH,qBAAa,gBAAgB;IAC5B,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsC;IAEhE,uCAAuC;IACvC,OAAO,CAAC,mBAAmB,CAAiC;IAE5D;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,YAAY,EAAE,oBAAoB,GAAG,IAAI;IAiBlD;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAI9C;;;;OAIG;IACH,UAAU,IAAI,eAAe,GAAG,SAAS;IAIzC;;;;OAIG;IACH,cAAc,IAAI,MAAM;IAIxB;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B;;;;OAIG;IACH,IAAI,IAAI,SAAS,eAAe,EAAE;IAIlC;;;;OAIG;IACH,SAAS,IAAI,SAAS,MAAM,EAAE;IAI9B;;;OAGG;IACH,KAAK,IAAI,IAAI;CAIb;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,kBAAyB,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @fileoverview Type definitions for the pluggable renderer system.
3
+ * Defines the DiagramRenderer interface and registry types for extensibility.
4
+ */
5
+ import type { TraversedModel } from "../traversal/types";
6
+ /**
7
+ * Supported export formats for diagram rendering.
8
+ */
9
+ export type ExportFormat = "png" | "pdf";
10
+ /**
11
+ * Interface for diagram renderers.
12
+ * Implementations convert traversed models to diagram syntax and optionally
13
+ * support exporting to image formats.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * class MermaidRenderer implements DiagramRenderer {
18
+ * readonly name = "mermaid";
19
+ *
20
+ * render(models: TraversedModel[]): string {
21
+ * // Generate Mermaid ERD syntax
22
+ * return "erDiagram\\n...";
23
+ * }
24
+ *
25
+ * async export(content: string, outputPath: string, format: ExportFormat): Promise<void> {
26
+ * // Use mermaid-cli to render to PNG/PDF
27
+ * }
28
+ * }
29
+ * ```
30
+ */
31
+ export interface DiagramRenderer {
32
+ /**
33
+ * Unique renderer identifier (e.g., "mermaid", "plantuml").
34
+ * Used for CLI flag matching and registry lookup.
35
+ */
36
+ readonly name: string;
37
+ /**
38
+ * Human-readable description of the renderer.
39
+ * Displayed in --list-renderers output.
40
+ */
41
+ readonly description: string;
42
+ /**
43
+ * Generate diagram text from traversed models.
44
+ *
45
+ * @param models - The traversed models to render
46
+ * @returns The diagram syntax as a string
47
+ */
48
+ render(models: readonly TraversedModel[]): string;
49
+ /**
50
+ * Export the diagram to a file format (PNG/PDF) if supported.
51
+ * This method is optional - not all renderers support export.
52
+ *
53
+ * @param content - The rendered diagram content
54
+ * @param outputPath - Path to write the output file
55
+ * @param format - The export format (png or pdf)
56
+ * @throws Error if export is not supported or fails
57
+ */
58
+ export?(content: string, outputPath: string, format: ExportFormat): Promise<void>;
59
+ /**
60
+ * Whether this renderer supports export functionality.
61
+ * @returns True if export() is implemented and functional
62
+ */
63
+ supportsExport(): boolean;
64
+ }
65
+ /**
66
+ * Configuration for renderer registration.
67
+ */
68
+ export interface RendererRegistration {
69
+ /** The renderer instance */
70
+ readonly renderer: DiagramRenderer;
71
+ /** Whether this is the default renderer */
72
+ readonly isDefault?: boolean;
73
+ }
74
+ /**
75
+ * Result of a render operation.
76
+ */
77
+ export type RenderResult = {
78
+ readonly success: true;
79
+ readonly output: string;
80
+ } | {
81
+ readonly success: false;
82
+ readonly error: string;
83
+ };
84
+ /**
85
+ * Result of an export operation.
86
+ */
87
+ export type ExportResult = {
88
+ readonly success: true;
89
+ readonly outputPath: string;
90
+ } | {
91
+ readonly success: false;
92
+ readonly error: string;
93
+ };
94
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/renderer/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,eAAe;IAC/B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAAC;IAElD;;;;;;;;OAQG;IACH,MAAM,CAAC,CACN,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,YAAY,GAClB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB;;;OAGG;IACH,cAAc,IAAI,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,4BAA4B;IAC5B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IAEnC,2CAA2C;IAC3C,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,YAAY,GACrB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @fileoverview Traversal module exports.
3
+ * Provides model traversal functionality and type definitions.
4
+ */
5
+ export { traverseModels } from "./model-traverser";
6
+ export type { TraversalOptions, TraversalResult, TraversedModel, } from "./types";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/traversal/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EACX,gBAAgB,EAChB,eAAe,EACf,cAAc,GACd,MAAM,SAAS,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @fileoverview Model traverser for depth-limited BFS traversal.
3
+ * Traverses model relationships from a starting model with configurable depth.
4
+ */
5
+ import type { ParsedSchema } from "../parser/types";
6
+ import type { TraversalOptions, TraversalResult } from "./types";
7
+ /**
8
+ * Performs a breadth-first traversal of model relationships starting from
9
+ * a specified model, with configurable depth limiting.
10
+ *
11
+ * The traversal:
12
+ * - Starts from the specified model at depth 0
13
+ * - Visits all related models at each subsequent depth level
14
+ * - Tracks visited models to prevent cycles
15
+ * - Stops when max depth is reached or all reachable models are visited
16
+ *
17
+ * @param schema - The parsed schema containing all models
18
+ * @param options - Traversal configuration options
19
+ * @returns A TraversalResult containing the traversed models or an error
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const result = traverseModels(schema, {
24
+ * startModel: 'User',
25
+ * maxDepth: 2
26
+ * });
27
+ * if (result.success) {
28
+ * for (const { model, depth } of result.models) {
29
+ * console.log(`${model.name} at depth ${depth}`);
30
+ * }
31
+ * }
32
+ * ```
33
+ */
34
+ export declare function traverseModels(schema: ParsedSchema, options: TraversalOptions): TraversalResult;
35
+ //# sourceMappingURL=model-traverser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-traverser.d.ts","sourceRoot":"","sources":["../../src/traversal/model-traverser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAS,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EACX,gBAAgB,EAChB,eAAe,EAEf,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,gBAAgB,GACvB,eAAe,CAkEjB"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @fileoverview Type definitions for model traversal.
3
+ * These types support BFS traversal of model relationships with depth limiting.
4
+ */
5
+ import type { Model } from "../parser/types";
6
+ /**
7
+ * Represents a model that has been visited during traversal,
8
+ * including its depth level from the starting model.
9
+ */
10
+ export interface TraversedModel {
11
+ /** The traversed model */
12
+ readonly model: Model;
13
+ /** The depth level from the starting model (0 = starting model) */
14
+ readonly depth: number;
15
+ }
16
+ /**
17
+ * Configuration options for model traversal.
18
+ */
19
+ export interface TraversalOptions {
20
+ /** The name of the model to start traversal from */
21
+ readonly startModel: string;
22
+ /** Maximum depth to traverse (default: 3) */
23
+ readonly maxDepth?: number;
24
+ }
25
+ /**
26
+ * Result of a traversal operation.
27
+ */
28
+ export type TraversalResult = {
29
+ readonly success: true;
30
+ readonly models: readonly TraversedModel[];
31
+ } | {
32
+ readonly success: false;
33
+ readonly error: string;
34
+ };
35
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/traversal/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEtB,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,6CAA6C;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GACxB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GACtE;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@matserdam/prisma-neighborhood",
3
+ "version": "0.0.1",
4
+ "description": "CLI tool that generates ERD diagrams from Prisma schemas with configurable depth traversal",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js"
11
+ }
12
+ },
13
+ "bin": {
14
+ "prisma-neighborhood": "./dist/cli.js",
15
+ "prisma-hood": "./dist/cli.js"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc --emitDeclarationOnly && bun run build:cli && bun run build:index",
24
+ "build:cli": "bun build src/cli.ts --outfile dist/cli.js --format cjs --target node",
25
+ "build:index": "bun build src/index.ts --outfile dist/index.js --format cjs --target node",
26
+ "dev": "bun run src/cli.ts",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
29
+ "typecheck": "tsc --noEmit",
30
+ "lint": "bunx @biomejs/biome check src/",
31
+ "lint:fix": "bunx @biomejs/biome check src/ --write",
32
+ "prepack": "bun run build",
33
+ "generate:examples": "bash scripts/generate-examples.sh"
34
+ },
35
+ "dependencies": {
36
+ "@prisma/internals": "^7.2.0",
37
+ "commander": "^14.0.0"
38
+ },
39
+ "devDependencies": {
40
+ "@mermaid-js/mermaid-cli": "^11.0.0",
41
+ "@types/bun": "latest",
42
+ "typescript": "^5.0.0",
43
+ "vitest": "^4.0.16"
44
+ },
45
+ "keywords": [
46
+ "prisma",
47
+ "erd",
48
+ "diagram",
49
+ "mermaid",
50
+ "cli",
51
+ "neighborhood",
52
+ "subgraph"
53
+ ],
54
+ "author": "",
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "git+https://github.com/Matserdam/prisma-neighbourhood.git"
58
+ },
59
+ "license": "MIT",
60
+ "engines": {
61
+ "node": ">=18.0.0"
62
+ },
63
+ "publishConfig": {
64
+ "access": "public"
65
+ }
66
+ }