mutano 3.0.1 → 3.0.3

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/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Convert database schemas to TypeScript types, Zod schemas, or Kysely definitions.
4
4
 
5
- **Supports:** MySQL, PostgreSQL, SQLite, Prisma • **Features:** Views, Magic Comments, Type Overrides, Multiple Outputs
5
+ - **Supports:** MySQL, PostgreSQL, SQLite, Prisma
6
+ - **Features:** Views, Magic Comments, Type Overrides, Multiple Outputs
6
7
 
7
8
  ## Installation
8
9
 
@@ -51,15 +52,6 @@ await generate({
51
52
  })
52
53
  ```
53
54
 
54
- ## Database Support
55
-
56
- | Database | Connection | Views | Magic Comments |
57
- |----------|------------|-------|----------------|
58
- | **MySQL** | Host/Port | ✅ | ✅ |
59
- | **PostgreSQL** | Host/Port | ✅ | ✅ |
60
- | **SQLite** | File Path | ✅ | ❌ |
61
- | **Prisma** | Schema File | ✅ | ❌ |
62
-
63
55
  ## Output Examples
64
56
 
65
57
  **Zod Schema:**
@@ -177,11 +169,11 @@ export type UserUpdate = Updateable<UserTable>;
177
169
  | `includeViews` | Process database views |
178
170
  | `camelCase` | Convert to camelCase |
179
171
  | `dryRun` | Return content without writing files |
180
- | `magicComments` | Enable @zod/@ts/@kysely comments |
172
+ | `magicComments` | Enable @zod/@ts/@kysely comments (Obs.: no SQLite support) |
181
173
 
182
174
  ## Magic Comments
183
175
 
184
- Override types for specific columns using database comments (MySQL/PostgreSQL only):
176
+ Override types for specific columns using database comments:
185
177
 
186
178
  ```sql
187
179
  CREATE TABLE `user` (
package/dist/main.d.ts CHANGED
@@ -1,58 +1,41 @@
1
- export declare const extractTypeExpression: (comment: string, prefix: string) => string;
2
- export declare const extractTSExpression: (comment: string) => string;
3
- export declare const extractKyselyExpression: (comment: string) => string;
4
- export declare const extractZodExpression: (comment: string) => string;
5
- export declare function getType(op: 'table' | 'insertable' | 'updateable' | 'selectable', desc: Desc, config: Config, destination: Destination, tableName?: string): string;
6
- export interface GenerateContentParams {
7
- table: string;
8
- describes: Desc[];
9
- config: Config;
10
- destination: Destination;
11
- isCamelCase: boolean;
12
- enumDeclarations: Record<string, string[]>;
13
- defaultZodHeader: (version: 3 | 4) => string;
14
- }
15
- export declare function generateContent({ table, describes, config, destination, isCamelCase, enumDeclarations, defaultZodHeader, }: GenerateContentParams): string;
16
- export declare const defaultKyselyHeader = "import { ColumnType, Selectable, Insertable, Updateable } from 'kysely';\n\n";
17
- export declare const defaultZodHeader: (version: 3 | 4) => string;
18
- export declare function generate(config: Config): Promise<Record<string, string>>;
19
- type MySQLValidTypes = 'date' | 'datetime' | 'timestamp' | 'time' | 'year' | 'char' | 'varchar' | 'tinytext' | 'text' | 'mediumtext' | 'longtext' | 'json' | 'decimal' | 'tinyint' | 'smallint' | 'mediumint' | 'int' | 'bigint' | 'float' | 'double' | 'enum';
20
- type PostgresValidTypes = 'date' | 'timestamp' | 'timestamptz' | 'timestamp without time zone' | 'timestamp with time zone' | 'time' | 'timetz' | 'interval' | 'character' | 'varchar' | 'character varying' | 'text' | 'json' | 'jsonb' | 'uuid' | 'name' | 'citext' | 'numeric' | 'decimal' | 'smallint' | 'integer' | 'bigint' | 'real' | 'double precision' | 'serial' | 'bigserial' | 'boolean' | 'bool' | 'USER-DEFINED';
21
- type SQLiteValidTypes = 'datetime' | 'text' | 'character' | 'varchar' | 'varying character' | 'nchar' | 'native character' | 'nvarchar' | 'clob' | 'json' | 'int' | 'integer' | 'tinyint' | 'smallint' | 'mediumint' | 'bigint' | 'unsigned big int' | 'int2' | 'int8' | 'real' | 'double' | 'double precision' | 'float' | 'numeric' | 'decimal' | 'boolean';
22
- type PrismaValidTypes = 'DateTime' | 'String' | 'Decimal' | 'BigInt' | 'Bytes' | 'Json' | 'Int' | 'Float' | 'Boolean' | 'Enum';
23
- export interface Desc {
1
+ /**
2
+ * Core types and interfaces for Mutano
3
+ */
4
+ interface Desc {
24
5
  Field: string;
25
6
  Default: string | null;
26
- EnumOptions?: string[];
27
7
  Extra: string;
8
+ Null: string;
28
9
  Type: string;
29
- Null: 'YES' | 'NO';
30
10
  Comment: string;
11
+ EnumOptions?: string[];
31
12
  }
32
- export type Destination = {
13
+ type Destination = {
33
14
  type: 'zod';
34
- version?: 3 | 4;
35
- header?: string;
36
15
  useDateType?: boolean;
37
16
  useTrim?: boolean;
38
17
  nullish?: boolean;
39
18
  requiredString?: boolean;
19
+ version?: 3 | 4;
20
+ header?: string;
40
21
  folder?: string;
41
22
  suffix?: string;
42
23
  } | {
43
24
  type: 'ts';
44
- header?: string;
45
- enumType?: 'enum' | 'union';
25
+ enumType?: 'union' | 'enum';
46
26
  modelType?: 'interface' | 'type';
27
+ header?: string;
47
28
  folder?: string;
48
29
  suffix?: string;
49
30
  } | {
50
31
  type: 'kysely';
51
- header?: string;
52
32
  schemaName?: string;
33
+ header?: string;
34
+ folder?: string;
35
+ suffix?: string;
53
36
  outFile?: string;
54
37
  };
55
- export interface Config {
38
+ interface Config {
56
39
  origin: {
57
40
  type: 'prisma';
58
41
  path: string;
@@ -91,10 +74,97 @@ export interface Config {
91
74
  };
92
75
  destinations: Destination[];
93
76
  tables?: string[];
77
+ views?: string[];
94
78
  ignore?: string[];
79
+ ignoreViews?: string[];
95
80
  camelCase?: boolean;
96
81
  silent?: boolean;
97
82
  dryRun?: boolean;
98
83
  magicComments?: boolean;
84
+ includeViews?: boolean;
85
+ }
86
+ interface GenerateContentParams {
87
+ table: string;
88
+ describes: Desc[];
89
+ config: Config;
90
+ destination: Destination;
91
+ isCamelCase: boolean;
92
+ enumDeclarations: Record<string, string[]>;
93
+ defaultZodHeader: (version: 3 | 4) => string;
94
+ }
95
+ interface GenerateViewContentParams {
96
+ view: string;
97
+ describes: Desc[];
98
+ config: Config;
99
+ destination: Destination;
100
+ isCamelCase: boolean;
101
+ enumDeclarations: Record<string, string[]>;
102
+ defaultZodHeader: (version: 3 | 4) => string;
99
103
  }
100
- export {};
104
+ type MySQLValidTypes = 'tinyint' | 'smallint' | 'mediumint' | 'int' | 'bigint' | 'decimal' | 'float' | 'double' | 'bit' | 'char' | 'varchar' | 'binary' | 'varbinary' | 'tinyblob' | 'blob' | 'mediumblob' | 'longblob' | 'tinytext' | 'text' | 'mediumtext' | 'longtext' | 'enum' | 'set' | 'date' | 'time' | 'datetime' | 'timestamp' | 'year' | 'json';
105
+ type PostgresValidTypes = 'smallint' | 'integer' | 'bigint' | 'decimal' | 'numeric' | 'real' | 'double precision' | 'smallserial' | 'serial' | 'bigserial' | 'money' | 'character varying' | 'varchar' | 'character' | 'char' | 'text' | 'bytea' | 'timestamp' | 'timestamp with time zone' | 'timestamp without time zone' | 'date' | 'time' | 'time with time zone' | 'time without time zone' | 'interval' | 'boolean' | 'enum' | 'point' | 'line' | 'lseg' | 'box' | 'path' | 'polygon' | 'circle' | 'cidr' | 'inet' | 'macaddr' | 'bit' | 'bit varying' | 'uuid' | 'xml' | 'json' | 'jsonb' | 'int4range' | 'int8range' | 'numrange' | 'tsrange' | 'tstzrange' | 'daterange' | 'name' | 'citext';
106
+ type SQLiteValidTypes = 'integer' | 'real' | 'text' | 'blob' | 'numeric' | 'boolean' | 'date' | 'datetime' | 'character' | 'varchar' | 'varying character' | 'nchar' | 'native character' | 'nvarchar' | 'clob' | 'double' | 'double precision' | 'float' | 'int' | 'int2' | 'int8' | 'bigint' | 'unsigned big int' | 'mediumint' | 'tinyint' | 'smallint' | 'decimal' | 'json';
107
+ type PrismaValidTypes = 'String' | 'Boolean' | 'Int' | 'BigInt' | 'Float' | 'Decimal' | 'DateTime' | 'Json' | 'Bytes' | 'Unsupported';
108
+
109
+ /**
110
+ * Constants and default headers for code generation
111
+ */
112
+ declare const defaultKyselyHeader = "import { Generated, Insertable, Selectable, Updateable, ColumnType } from 'kysely';\n\n";
113
+ declare const defaultZodHeader: (version: 3 | 4) => string;
114
+
115
+ /**
116
+ * Utilities for parsing magic comments (@zod, @ts, @kysely)
117
+ */
118
+ /**
119
+ * Extract type expression from a comment with a given prefix
120
+ * Handles nested parentheses, brackets, and braces
121
+ */
122
+ declare const extractTypeExpression: (comment: string, prefix: string) => string | null;
123
+ /**
124
+ * Extract TypeScript type expression from @ts() comment
125
+ */
126
+ declare const extractTSExpression: (comment: string) => string | null;
127
+ /**
128
+ * Extract Kysely type expression from @kysely() comment
129
+ */
130
+ declare const extractKyselyExpression: (comment: string) => string | null;
131
+ /**
132
+ * Extract Zod type expression from @zod() comment
133
+ */
134
+ declare const extractZodExpression: (comment: string) => string | null;
135
+
136
+ /**
137
+ * Content generation for tables and views
138
+ */
139
+
140
+ /**
141
+ * Generate content for database views (read-only)
142
+ */
143
+ declare function generateViewContent({ view, describes, config, destination, isCamelCase, enumDeclarations: _enumDeclarations, defaultZodHeader, }: GenerateViewContentParams): string;
144
+ /**
145
+ * Generate content for database tables
146
+ */
147
+ declare function generateContent({ table, describes, config, destination, isCamelCase, enumDeclarations: _enumDeclarations, defaultZodHeader, }: GenerateContentParams): string;
148
+
149
+ /**
150
+ * Core type generation logic
151
+ */
152
+
153
+ type OperationType = 'table' | 'insertable' | 'updateable' | 'selectable';
154
+ /**
155
+ * Generate the appropriate type for a database field
156
+ */
157
+ declare function getType(op: OperationType, desc: Desc, config: Config, destination: Destination): string;
158
+
159
+ /**
160
+ * Mutano - Database schema to TypeScript/Zod/Kysely converter
161
+ * Refactored for better maintainability and modularity
162
+ */
163
+
164
+ /**
165
+ * Main generate function - orchestrates the entire schema generation process
166
+ */
167
+ declare function generate(config: Config): Promise<Record<string, string>>;
168
+
169
+ export { defaultKyselyHeader, defaultZodHeader, extractKyselyExpression, extractTSExpression, extractTypeExpression, extractZodExpression, generate, generateContent, generateViewContent, getType };
170
+ export type { Config, Desc, Destination };