mutano 3.0.2 → 3.0.4

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
@@ -173,7 +173,7 @@ export type UserUpdate = Updateable<UserTable>;
173
173
 
174
174
  ## Magic Comments
175
175
 
176
- Override types for specific columns using database comments (MySQL/PostgreSQL only):
176
+ Override types for specific columns using database comments:
177
177
 
178
178
  ```sql
179
179
  CREATE TABLE `user` (
package/dist/main.d.ts CHANGED
@@ -1,15 +1,170 @@
1
+ /**
2
+ * Core types and interfaces for Mutano
3
+ */
4
+ interface Desc {
5
+ Field: string;
6
+ Default: string | null;
7
+ Extra: string;
8
+ Null: string;
9
+ Type: string;
10
+ Comment: string;
11
+ EnumOptions?: string[];
12
+ }
13
+ type Destination = {
14
+ type: 'zod';
15
+ useDateType?: boolean;
16
+ useTrim?: boolean;
17
+ nullish?: boolean;
18
+ requiredString?: boolean;
19
+ version?: 3 | 4;
20
+ header?: string;
21
+ folder?: string;
22
+ suffix?: string;
23
+ } | {
24
+ type: 'ts';
25
+ enumType?: 'union' | 'enum';
26
+ modelType?: 'interface' | 'type';
27
+ header?: string;
28
+ folder?: string;
29
+ suffix?: string;
30
+ } | {
31
+ type: 'kysely';
32
+ schemaName?: string;
33
+ header?: string;
34
+ folder?: string;
35
+ suffix?: string;
36
+ outFile?: string;
37
+ };
38
+ interface Config {
39
+ origin: {
40
+ type: 'prisma';
41
+ path: string;
42
+ overrideTypes?: {
43
+ [k in PrismaValidTypes]?: string;
44
+ };
45
+ } | {
46
+ type: 'mysql';
47
+ host: string;
48
+ port: number;
49
+ user: string;
50
+ password: string;
51
+ database: string;
52
+ overrideTypes?: {
53
+ [k in MySQLValidTypes]?: string;
54
+ };
55
+ ssl?: Record<string, any>;
56
+ } | {
57
+ type: 'postgres';
58
+ host: string;
59
+ port: number;
60
+ user: string;
61
+ password: string;
62
+ database: string;
63
+ schema?: string;
64
+ overrideTypes?: {
65
+ [k in PostgresValidTypes]?: string;
66
+ };
67
+ ssl?: Record<string, any>;
68
+ } | {
69
+ type: 'sqlite';
70
+ path: string;
71
+ overrideTypes?: {
72
+ [k in SQLiteValidTypes]?: string;
73
+ };
74
+ };
75
+ destinations: Destination[];
76
+ tables?: string[];
77
+ views?: string[];
78
+ ignore?: string[];
79
+ ignoreViews?: string[];
80
+ camelCase?: boolean;
81
+ silent?: boolean;
82
+ dryRun?: boolean;
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;
103
+ }
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
+
1
159
  /**
2
160
  * Mutano - Database schema to TypeScript/Zod/Kysely converter
3
161
  * Refactored for better maintainability and modularity
4
162
  */
5
- import type { Config } from './types/index.js';
6
- import { defaultKyselyHeader, defaultZodHeader } from './constants.js';
7
- export { extractTypeExpression, extractTSExpression, extractKyselyExpression, extractZodExpression } from './utils/magic-comments.js';
8
- export type { Config, Desc, Destination } from './types/index.js';
9
- export { generateContent, generateViewContent } from './generators/content-generator.js';
10
- export { getType } from './generators/type-generator.js';
11
- export { defaultKyselyHeader, defaultZodHeader };
163
+
12
164
  /**
13
165
  * Main generate function - orchestrates the entire schema generation process
14
166
  */
15
- export declare function generate(config: Config): Promise<Record<string, string>>;
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 };