mutano 3.0.1 → 3.0.2
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 +3 -11
- package/dist/constants.d.ts +6 -0
- package/dist/database/connection.d.ts +25 -0
- package/dist/database/prisma.d.ts +20 -0
- package/dist/generators/content-generator.d.ts +12 -0
- package/dist/generators/type-generator.d.ts +9 -0
- package/dist/main.d.ts +14 -99
- package/dist/main.js +140 -914
- package/dist/types/index.d.ts +107 -0
- package/dist/types/mappings.d.ts +91 -0
- package/dist/utils/filters.d.ts +23 -0
- package/dist/utils/magic-comments.d.ts +33 -0
- package/package.json +1 -1
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
|
|
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,7 +169,7 @@ 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
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants and default headers for code generation
|
|
3
|
+
*/
|
|
4
|
+
export declare const defaultKyselyHeader = "import { Generated, Insertable, Selectable, Updateable, ColumnType } from 'kysely';\n\n";
|
|
5
|
+
export declare const defaultZodHeader: (version: 3 | 4) => string;
|
|
6
|
+
export declare const kyselyJsonTypes = "// JSON type definitions\nexport type Json = ColumnType<JsonValue, string, string>;\n\nexport type JsonArray = JsonValue[];\n\nexport type JsonObject = {\n [x: string]: JsonValue | undefined;\n};\n\nexport type JsonPrimitive = boolean | number | string | null;\n\nexport type JsonValue = JsonArray | JsonObject | JsonPrimitive;\n\nexport type Generated<T> = T extends ColumnType<infer S, infer I, infer U>\n ? ColumnType<S, I | undefined, U>\n : ColumnType<T, T | undefined, T>\n\nexport type Decimal = ColumnType<string, number | string, number | string>\n\nexport type BigInt = ColumnType<string, number | string, number | string>\n\n";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database connection and schema extraction utilities
|
|
3
|
+
*/
|
|
4
|
+
import knex from 'knex';
|
|
5
|
+
import type { Config, Desc } from '../types/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Create a database connection based on config
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDatabaseConnection(config: Config): knex.Knex<any, unknown[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Extract table names from database
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractTables(db: ReturnType<typeof knex>, config: Config): Promise<string[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Extract view names from database
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractViews(db: ReturnType<typeof knex>, config: Config): Promise<string[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Extract column descriptions for a table or view
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractColumnDescriptions(db: ReturnType<typeof knex>, config: Config, tableName: string): Promise<Desc[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Extract enum values for PostgreSQL user-defined types
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractEnumValues(db: ReturnType<typeof knex>, config: Config, typeName: string): Promise<string[]>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prisma schema extraction utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { Config, Desc } from '../types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Extract tables and views from Prisma schema
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractPrismaEntities(config: Config): {
|
|
9
|
+
tables: string[];
|
|
10
|
+
views: string[];
|
|
11
|
+
enumDeclarations: Record<string, string[]>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Extract column descriptions from Prisma model or view
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractPrismaColumnDescriptions(config: Config, entityName: string, enumDeclarations: Record<string, string[]>): Desc[];
|
|
17
|
+
/**
|
|
18
|
+
* Check if Prisma schema has views enabled
|
|
19
|
+
*/
|
|
20
|
+
export declare function hasViewsEnabled(config: Config): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content generation for tables and views
|
|
3
|
+
*/
|
|
4
|
+
import type { GenerateContentParams, GenerateViewContentParams } from '../types/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Generate content for database views (read-only)
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateViewContent({ view, describes, config, destination, isCamelCase, enumDeclarations: _enumDeclarations, defaultZodHeader, }: GenerateViewContentParams): string;
|
|
9
|
+
/**
|
|
10
|
+
* Generate content for database tables
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateContent({ table, describes, config, destination, isCamelCase, enumDeclarations: _enumDeclarations, defaultZodHeader, }: GenerateContentParams): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type generation logic
|
|
3
|
+
*/
|
|
4
|
+
import type { Config, Desc, Destination } from '../types/index.js';
|
|
5
|
+
export type OperationType = 'table' | 'insertable' | 'updateable' | 'selectable';
|
|
6
|
+
/**
|
|
7
|
+
* Generate the appropriate type for a database field
|
|
8
|
+
*/
|
|
9
|
+
export declare function getType(op: OperationType, desc: Desc, config: Config, destination: Destination): string;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,100 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
1
|
+
/**
|
|
2
|
+
* Mutano - Database schema to TypeScript/Zod/Kysely converter
|
|
3
|
+
* Refactored for better maintainability and modularity
|
|
4
|
+
*/
|
|
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 };
|
|
12
|
+
/**
|
|
13
|
+
* Main generate function - orchestrates the entire schema generation process
|
|
14
|
+
*/
|
|
18
15
|
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 {
|
|
24
|
-
Field: string;
|
|
25
|
-
Default: string | null;
|
|
26
|
-
EnumOptions?: string[];
|
|
27
|
-
Extra: string;
|
|
28
|
-
Type: string;
|
|
29
|
-
Null: 'YES' | 'NO';
|
|
30
|
-
Comment: string;
|
|
31
|
-
}
|
|
32
|
-
export type Destination = {
|
|
33
|
-
type: 'zod';
|
|
34
|
-
version?: 3 | 4;
|
|
35
|
-
header?: string;
|
|
36
|
-
useDateType?: boolean;
|
|
37
|
-
useTrim?: boolean;
|
|
38
|
-
nullish?: boolean;
|
|
39
|
-
requiredString?: boolean;
|
|
40
|
-
folder?: string;
|
|
41
|
-
suffix?: string;
|
|
42
|
-
} | {
|
|
43
|
-
type: 'ts';
|
|
44
|
-
header?: string;
|
|
45
|
-
enumType?: 'enum' | 'union';
|
|
46
|
-
modelType?: 'interface' | 'type';
|
|
47
|
-
folder?: string;
|
|
48
|
-
suffix?: string;
|
|
49
|
-
} | {
|
|
50
|
-
type: 'kysely';
|
|
51
|
-
header?: string;
|
|
52
|
-
schemaName?: string;
|
|
53
|
-
outFile?: string;
|
|
54
|
-
};
|
|
55
|
-
export interface Config {
|
|
56
|
-
origin: {
|
|
57
|
-
type: 'prisma';
|
|
58
|
-
path: string;
|
|
59
|
-
overrideTypes?: {
|
|
60
|
-
[k in PrismaValidTypes]?: string;
|
|
61
|
-
};
|
|
62
|
-
} | {
|
|
63
|
-
type: 'mysql';
|
|
64
|
-
host: string;
|
|
65
|
-
port: number;
|
|
66
|
-
user: string;
|
|
67
|
-
password: string;
|
|
68
|
-
database: string;
|
|
69
|
-
overrideTypes?: {
|
|
70
|
-
[k in MySQLValidTypes]?: string;
|
|
71
|
-
};
|
|
72
|
-
ssl?: Record<string, any>;
|
|
73
|
-
} | {
|
|
74
|
-
type: 'postgres';
|
|
75
|
-
host: string;
|
|
76
|
-
port: number;
|
|
77
|
-
user: string;
|
|
78
|
-
password: string;
|
|
79
|
-
database: string;
|
|
80
|
-
schema?: string;
|
|
81
|
-
overrideTypes?: {
|
|
82
|
-
[k in PostgresValidTypes]?: string;
|
|
83
|
-
};
|
|
84
|
-
ssl?: Record<string, any>;
|
|
85
|
-
} | {
|
|
86
|
-
type: 'sqlite';
|
|
87
|
-
path: string;
|
|
88
|
-
overrideTypes?: {
|
|
89
|
-
[k in SQLiteValidTypes]?: string;
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
destinations: Destination[];
|
|
93
|
-
tables?: string[];
|
|
94
|
-
ignore?: string[];
|
|
95
|
-
camelCase?: boolean;
|
|
96
|
-
silent?: boolean;
|
|
97
|
-
dryRun?: boolean;
|
|
98
|
-
magicComments?: boolean;
|
|
99
|
-
}
|
|
100
|
-
export {};
|