drizzle-docs-generator 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.ja.md +59 -15
  2. package/README.md +55 -11
  3. package/dist/adapter/types.d.ts +40 -0
  4. package/dist/adapter/types.d.ts.map +1 -0
  5. package/dist/adapter/v0-adapter.d.ts +73 -0
  6. package/dist/adapter/v0-adapter.d.ts.map +1 -0
  7. package/dist/adapter/v0-adapter.js +136 -0
  8. package/dist/adapter/v0-adapter.js.map +1 -0
  9. package/dist/adapter/v1-adapter.d.ts +40 -0
  10. package/dist/adapter/v1-adapter.d.ts.map +1 -0
  11. package/dist/adapter/v1-adapter.js +83 -0
  12. package/dist/adapter/v1-adapter.js.map +1 -0
  13. package/dist/cli/index.js +194 -71
  14. package/dist/cli/index.js.map +1 -1
  15. package/dist/cli/integration-test-utils.d.ts +19 -0
  16. package/dist/cli/integration-test-utils.d.ts.map +1 -0
  17. package/dist/formatter/dbml-builder.d.ts +29 -0
  18. package/dist/formatter/dbml-builder.d.ts.map +1 -0
  19. package/dist/formatter/dbml-builder.js +39 -0
  20. package/dist/formatter/dbml-builder.js.map +1 -0
  21. package/dist/formatter/dbml.d.ts +81 -0
  22. package/dist/formatter/dbml.d.ts.map +1 -0
  23. package/dist/formatter/dbml.js +163 -0
  24. package/dist/formatter/dbml.js.map +1 -0
  25. package/dist/formatter/markdown.d.ts +126 -0
  26. package/dist/formatter/markdown.d.ts.map +1 -0
  27. package/dist/formatter/markdown.js +235 -0
  28. package/dist/formatter/markdown.js.map +1 -0
  29. package/dist/formatter/mermaid.d.ts +102 -0
  30. package/dist/formatter/mermaid.d.ts.map +1 -0
  31. package/dist/formatter/mermaid.js +177 -0
  32. package/dist/formatter/mermaid.js.map +1 -0
  33. package/dist/formatter/types.d.ts +37 -0
  34. package/dist/formatter/types.d.ts.map +1 -0
  35. package/dist/generator/common.d.ts +115 -208
  36. package/dist/generator/common.d.ts.map +1 -1
  37. package/dist/generator/common.js +260 -479
  38. package/dist/generator/common.js.map +1 -1
  39. package/dist/generator/mysql.js +3 -3
  40. package/dist/generator/pg.d.ts +8 -7
  41. package/dist/generator/pg.d.ts.map +1 -1
  42. package/dist/generator/pg.js +29 -31
  43. package/dist/generator/pg.js.map +1 -1
  44. package/dist/generator/sqlite.js +3 -3
  45. package/dist/index.d.ts +15 -4
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +22 -18
  48. package/dist/index.js.map +1 -1
  49. package/dist/test-utils/cli-runner.d.ts +4 -1
  50. package/dist/test-utils/cli-runner.d.ts.map +1 -1
  51. package/dist/test-utils/dbml-validator.d.ts +29 -0
  52. package/dist/test-utils/dbml-validator.d.ts.map +1 -1
  53. package/dist/types.d.ts +128 -16
  54. package/dist/types.d.ts.map +1 -1
  55. package/package.json +3 -2
  56. package/dist/generator/index.d.ts +0 -15
  57. package/dist/generator/index.d.ts.map +0 -1
  58. package/dist/parser/index.d.ts +0 -5
  59. package/dist/parser/index.d.ts.map +0 -1
  60. package/dist/test-utils/index.d.ts +0 -7
  61. package/dist/test-utils/index.d.ts.map +0 -1
package/dist/types.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { AnyColumn, Table } from 'drizzle-orm';
2
1
  import { SchemaComments } from './parser/comments';
3
- export type { AnyColumn, Table };
4
2
  /**
5
3
  * Options for DBML generation
6
4
  */
@@ -9,8 +7,6 @@ export interface GenerateOptions<TSchema extends Record<string, unknown>> {
9
7
  schema: TSchema;
10
8
  /** Output file path. If provided, DBML will be written to this file */
11
9
  out?: string;
12
- /** If true, uses relations() definitions instead of foreign keys for references */
13
- relational?: boolean;
14
10
  /**
15
11
  * Path to the source schema file or directory for extracting JSDoc comments and relations.
16
12
  * If a directory is provided, all .ts files will be processed recursively.
@@ -23,10 +19,6 @@ export interface GenerateOptions<TSchema extends Record<string, unknown>> {
23
19
  */
24
20
  comments?: SchemaComments;
25
21
  }
26
- /**
27
- * Supported relation types in DBML
28
- */
29
- export type RelationType = "one-to-one" | "one-to-many" | "many-to-one";
30
22
  /**
31
23
  * Internal representation of a reference/relationship
32
24
  */
@@ -40,14 +32,134 @@ export interface GeneratedRef {
40
32
  onUpdate?: string;
41
33
  }
42
34
  /**
43
- * Column constraint attributes for DBML output
35
+ * Supported database types
36
+ *
37
+ * @remarks
38
+ * TODO: Unify with `Dialect` type in `src/cli/index.ts` when implementing CLI --format option (#59)
39
+ */
40
+ export type DatabaseType = "postgresql" | "mysql" | "sqlite";
41
+ /**
42
+ * Column definition in the intermediate schema
43
+ */
44
+ export interface ColumnDefinition {
45
+ /** Column name */
46
+ name: string;
47
+ /** SQL data type (e.g., "varchar(255)", "integer", "timestamp") */
48
+ type: string;
49
+ /** Whether the column allows NULL values */
50
+ nullable: boolean;
51
+ /** Default value expression (e.g., "now()", "'active'") */
52
+ defaultValue?: string;
53
+ /** Whether this column is a primary key */
54
+ primaryKey: boolean;
55
+ /** Whether this column has a unique constraint */
56
+ unique: boolean;
57
+ /** Whether this column auto-increments */
58
+ autoIncrement?: boolean;
59
+ /** JSDoc comment or description for this column */
60
+ comment?: string;
61
+ }
62
+ /**
63
+ * Index definition in the intermediate schema
64
+ */
65
+ export interface IndexDefinition {
66
+ /** Index name */
67
+ name: string;
68
+ /** Columns included in the index */
69
+ columns: string[];
70
+ /** Whether this is a unique index */
71
+ unique: boolean;
72
+ /** Index type (e.g., "btree", "hash", "gin") - database specific */
73
+ type?: string;
74
+ }
75
+ /**
76
+ * Constraint types
77
+ */
78
+ export type ConstraintType = "primary_key" | "foreign_key" | "unique" | "check" | "not_null";
79
+ /**
80
+ * Constraint definition in the intermediate schema
81
+ */
82
+ export interface ConstraintDefinition {
83
+ /** Constraint name */
84
+ name: string;
85
+ /** Type of constraint */
86
+ type: ConstraintType;
87
+ /** Columns involved in the constraint */
88
+ columns: string[];
89
+ /** SQL definition or expression (for CHECK constraints) */
90
+ definition?: string;
91
+ /** Referenced table (for foreign keys) */
92
+ referencedTable?: string;
93
+ /** Referenced columns (for foreign keys) */
94
+ referencedColumns?: string[];
95
+ }
96
+ /**
97
+ * Table definition in the intermediate schema
98
+ */
99
+ export interface TableDefinition {
100
+ /** Table name */
101
+ name: string;
102
+ /** Schema name (e.g., "public" for PostgreSQL) */
103
+ schema?: string;
104
+ /** JSDoc comment or description for this table */
105
+ comment?: string;
106
+ /** Column definitions */
107
+ columns: ColumnDefinition[];
108
+ /** Index definitions */
109
+ indexes: IndexDefinition[];
110
+ /** Constraint definitions */
111
+ constraints: ConstraintDefinition[];
112
+ }
113
+ /**
114
+ * Relation types for intermediate schema
115
+ */
116
+ export type IntermediateRelationType = "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many";
117
+ /**
118
+ * Relation/Reference definition in the intermediate schema
119
+ */
120
+ export interface RelationDefinition {
121
+ /** Optional relation name */
122
+ name?: string;
123
+ /** Source table name */
124
+ fromTable: string;
125
+ /** Source column names */
126
+ fromColumns: string[];
127
+ /** Target table name */
128
+ toTable: string;
129
+ /** Target column names */
130
+ toColumns: string[];
131
+ /** Relation cardinality */
132
+ type: IntermediateRelationType;
133
+ /** ON DELETE action */
134
+ onDelete?: string;
135
+ /** ON UPDATE action */
136
+ onUpdate?: string;
137
+ }
138
+ /**
139
+ * Enum definition in the intermediate schema (PostgreSQL specific)
140
+ */
141
+ export interface EnumDefinition {
142
+ /** Enum type name */
143
+ name: string;
144
+ /** Schema name (e.g., "public" for PostgreSQL) */
145
+ schema?: string;
146
+ /** Enum values */
147
+ values: string[];
148
+ }
149
+ /**
150
+ * The complete intermediate schema representation
151
+ *
152
+ * This is a database-agnostic representation of a schema that can be
153
+ * used to generate various output formats (DBML, Markdown, JSON, etc.)
44
154
  */
45
- export interface ColumnAttributes {
46
- primaryKey?: boolean;
47
- notNull?: boolean;
48
- unique?: boolean;
49
- increment?: boolean;
50
- default?: string;
51
- note?: string;
155
+ export interface IntermediateSchema {
156
+ /** Database type that this schema was extracted from */
157
+ databaseType: DatabaseType;
158
+ /** Table definitions */
159
+ tables: TableDefinition[];
160
+ /** Relation/Reference definitions */
161
+ relations: RelationDefinition[];
162
+ /** Enum definitions (PostgreSQL specific) */
163
+ enums: EnumDefinition[];
52
164
  }
53
165
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAEjC;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtE,2EAA2E;IAC3E,MAAM,EAAE,OAAO,CAAC;IAChB,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,mFAAmF;IACnF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,aAAa,GAAG,aAAa,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAA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AChC,YAAY,GACZ,aAAa,GACb,aAAa,GACb,cAAc,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,2BAA2B;IAC3B,IAAI,EAAE,wBAAwB,CAAC;IAC/B,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,YAAY,EAAE,YAAY,CAAC;IAC3B,wBAAwB;IACxB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,qCAAqC;IACrC,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,6CAA6C;IAC7C,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-docs-generator",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "A CLI tool that generates DBML files from Drizzle ORM schema definitions.",
5
5
  "keywords": [
6
6
  "cli",
@@ -65,6 +65,7 @@
65
65
  "lint": "oxlint",
66
66
  "format": "oxfmt --write",
67
67
  "format:check": "oxfmt --check",
68
- "typecheck": "tsc --noEmit"
68
+ "typecheck": "tsc --noEmit",
69
+ "generate:examples": "node dist/cli/index.js generate examples/pg/schema.ts -d postgresql -f dbml -o examples/pg/schema.dbml --force && node dist/cli/index.js generate examples/pg/schema.ts -d postgresql -f markdown -o examples/pg/markdown --force && node dist/cli/index.js generate examples/mysql/schema.ts -d mysql -f dbml -o examples/mysql/schema.dbml --force && node dist/cli/index.js generate examples/mysql/schema.ts -d mysql -f markdown -o examples/mysql/markdown --force && node dist/cli/index.js generate examples/sqlite/schema.ts -d sqlite -f dbml -o examples/sqlite/schema.dbml --force && node dist/cli/index.js generate examples/sqlite/schema.ts -d sqlite -f markdown -o examples/sqlite/markdown --force"
69
70
  }
70
71
  }
@@ -1,15 +0,0 @@
1
- /**
2
- * DBML Generator Module
3
- *
4
- * Provides functions to generate DBML from Drizzle ORM schema definitions.
5
- * Supports PostgreSQL, MySQL, and SQLite dialects.
6
- *
7
- * JSDoc comments can be extracted from source files and included as DBML Note clauses.
8
- * Use the `source` option to specify the schema source file or directory, or pass pre-extracted
9
- * comments via the `comments` option.
10
- */
11
- export { pgGenerate, PgGenerator } from './pg';
12
- export { mysqlGenerate, MySqlGenerator } from './mysql';
13
- export { sqliteGenerate, SqliteGenerator } from './sqlite';
14
- export { BaseGenerator, DbmlBuilder, writeDbmlFile } from './common';
15
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC"}
@@ -1,5 +0,0 @@
1
- export { extractComments } from './comments';
2
- export type { SchemaComments, TableComment, ColumnComment } from './comments';
3
- export { extractRelations } from './relations';
4
- export type { ParsedRelation, SchemaRelations } from './relations';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Test utilities for integration testing
3
- */
4
- export { runCli, runGenerate } from './cli-runner.js';
5
- export type { CliResult } from './cli-runner.js';
6
- export { hasAllTables, hasAllColumns, hasReference, hasIndexes, hasTableNote, countTables, countRefs, } from './dbml-validator.js';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,WAAW,EACX,SAAS,GACV,MAAM,qBAAqB,CAAC"}