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 +1 -1
- package/dist/main.d.ts +163 -8
- package/dist/main.js +891 -38
- package/package.json +8 -8
- package/dist/constants.d.ts +0 -6
- package/dist/database/connection.d.ts +0 -25
- package/dist/database/prisma.d.ts +0 -20
- package/dist/generators/content-generator.d.ts +0 -12
- package/dist/generators/type-generator.d.ts +0 -9
- package/dist/types/index.d.ts +0 -107
- package/dist/types/mappings.d.ts +0 -91
- package/dist/utils/filters.d.ts +0 -23
- package/dist/utils/magic-comments.d.ts +0 -33
package/package.json
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mutano",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.4",
|
|
5
5
|
"description": "Converts Prisma/MySQL/PostgreSQL/SQLite schemas to Zod/TS/Kysely interfaces",
|
|
6
6
|
"author": "Alisson Cavalcante Agiani <thelinuxlich@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": "git@github.com:thelinuxlich/mutano.git",
|
|
9
9
|
"main": "dist/main.js",
|
|
10
10
|
"types": "dist/main.d.ts",
|
|
11
|
-
"files": [
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
12
14
|
"scripts": {
|
|
13
|
-
"build": "
|
|
15
|
+
"build": "pkgroll",
|
|
14
16
|
"test": "vitest run"
|
|
15
17
|
},
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"@mrleebo/prisma-ast": "^0.13.0",
|
|
20
|
+
"@types/fs-extra": "^11.0.4",
|
|
21
|
+
"@types/pg": "^8.15.5",
|
|
18
22
|
"camelcase": "^8.0.0",
|
|
19
23
|
"fs-extra": "^11.3.2",
|
|
20
24
|
"knex": "^3.1.0",
|
|
@@ -24,11 +28,7 @@
|
|
|
24
28
|
},
|
|
25
29
|
"devDependencies": {
|
|
26
30
|
"@electric-sql/pglite": "^0.3.8",
|
|
27
|
-
"
|
|
28
|
-
"@types/pg": "^8.15.5",
|
|
29
|
-
"esbuild": "^0.25.9",
|
|
30
|
-
"ts-node": "^10.9.2",
|
|
31
|
-
"tsx": "4.19.4",
|
|
31
|
+
"pkgroll": "^2.15.4",
|
|
32
32
|
"typescript": "^5.9.2",
|
|
33
33
|
"vitest": "^3.2.4"
|
|
34
34
|
}
|
package/dist/constants.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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";
|
|
@@ -1,25 +0,0 @@
|
|
|
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[]>;
|
|
@@ -1,20 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
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;
|
|
@@ -1,9 +0,0 @@
|
|
|
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/types/index.d.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core types and interfaces for Mutano
|
|
3
|
-
*/
|
|
4
|
-
export 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
|
-
export 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
|
-
export 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
|
-
export 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
|
-
export 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
|
-
export 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
|
-
export 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
|
-
export 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
|
-
export type PrismaValidTypes = 'String' | 'Boolean' | 'Int' | 'BigInt' | 'Float' | 'Decimal' | 'DateTime' | 'Json' | 'Bytes' | 'Unsupported';
|
package/dist/types/mappings.d.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database type mappings for different database systems
|
|
3
|
-
*/
|
|
4
|
-
export declare const prismaValidTypes: readonly ["String", "Boolean", "Int", "BigInt", "Float", "Decimal", "DateTime", "Json", "Bytes", "Unsupported"];
|
|
5
|
-
export declare const dateTypes: {
|
|
6
|
-
mysql: string[];
|
|
7
|
-
postgres: string[];
|
|
8
|
-
sqlite: string[];
|
|
9
|
-
prisma: string[];
|
|
10
|
-
};
|
|
11
|
-
export declare const stringTypes: {
|
|
12
|
-
mysql: string[];
|
|
13
|
-
postgres: string[];
|
|
14
|
-
sqlite: string[];
|
|
15
|
-
prisma: string[];
|
|
16
|
-
};
|
|
17
|
-
export declare const bigIntTypes: {
|
|
18
|
-
mysql: string[];
|
|
19
|
-
postgres: string[];
|
|
20
|
-
sqlite: string[];
|
|
21
|
-
prisma: string[];
|
|
22
|
-
};
|
|
23
|
-
export declare const numberTypes: {
|
|
24
|
-
mysql: string[];
|
|
25
|
-
postgres: string[];
|
|
26
|
-
sqlite: string[];
|
|
27
|
-
prisma: string[];
|
|
28
|
-
};
|
|
29
|
-
export declare const decimalTypes: {
|
|
30
|
-
mysql: string[];
|
|
31
|
-
postgres: string[];
|
|
32
|
-
sqlite: string[];
|
|
33
|
-
prisma: string[];
|
|
34
|
-
};
|
|
35
|
-
export declare const booleanTypes: {
|
|
36
|
-
mysql: string[];
|
|
37
|
-
postgres: string[];
|
|
38
|
-
sqlite: string[];
|
|
39
|
-
prisma: string[];
|
|
40
|
-
};
|
|
41
|
-
export declare const enumTypes: {
|
|
42
|
-
mysql: string[];
|
|
43
|
-
postgres: string[];
|
|
44
|
-
sqlite: string[];
|
|
45
|
-
prisma: string[];
|
|
46
|
-
};
|
|
47
|
-
export declare const enumRegex: RegExp;
|
|
48
|
-
/**
|
|
49
|
-
* Get the appropriate type mappings for a database type
|
|
50
|
-
*/
|
|
51
|
-
export declare function getTypeMappings(dbType: 'mysql' | 'postgres' | 'sqlite' | 'prisma'): {
|
|
52
|
-
dateTypes: string[];
|
|
53
|
-
stringTypes: string[];
|
|
54
|
-
bigIntTypes: string[];
|
|
55
|
-
numberTypes: string[];
|
|
56
|
-
decimalTypes: string[];
|
|
57
|
-
booleanTypes: string[];
|
|
58
|
-
enumTypes: string[];
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Check if a type is a JSON type
|
|
62
|
-
*/
|
|
63
|
-
export declare function isJsonType(type: string): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Check if a type is a date type for a specific database
|
|
66
|
-
*/
|
|
67
|
-
export declare function isDateType(type: string, dbType: 'mysql' | 'postgres' | 'sqlite' | 'prisma'): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Check if a type is a string type for a specific database
|
|
70
|
-
*/
|
|
71
|
-
export declare function isStringType(type: string, dbType: 'mysql' | 'postgres' | 'sqlite' | 'prisma'): boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Check if a type is a number type for a specific database
|
|
74
|
-
*/
|
|
75
|
-
export declare function isNumberType(type: string, dbType: 'mysql' | 'postgres' | 'sqlite' | 'prisma'): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Check if a type is a bigint type for a specific database
|
|
78
|
-
*/
|
|
79
|
-
export declare function isBigIntType(type: string, dbType: 'mysql' | 'postgres' | 'sqlite' | 'prisma'): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Check if a type is a decimal type for a specific database
|
|
82
|
-
*/
|
|
83
|
-
export declare function isDecimalType(type: string, dbType: 'mysql' | 'postgres' | 'sqlite' | 'prisma'): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Check if a type is a boolean type for a specific database
|
|
86
|
-
*/
|
|
87
|
-
export declare function isBooleanType(type: string, dbType: 'mysql' | 'postgres' | 'sqlite' | 'prisma'): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Check if a type is an enum type for a specific database
|
|
90
|
-
*/
|
|
91
|
-
export declare function isEnumType(type: string, dbType: 'mysql' | 'postgres' | 'sqlite' | 'prisma'): boolean;
|
package/dist/utils/filters.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for filtering tables and views
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Filter entities (tables or views) based on include/exclude patterns
|
|
6
|
-
*/
|
|
7
|
-
export declare function filterEntities(entities: string[], included?: string[], ignored?: string[]): string[];
|
|
8
|
-
/**
|
|
9
|
-
* Filter tables based on configuration
|
|
10
|
-
*/
|
|
11
|
-
export declare function filterTables(tables: string[], includedTables?: string[], ignoredTables?: string[]): string[];
|
|
12
|
-
/**
|
|
13
|
-
* Filter views based on configuration
|
|
14
|
-
*/
|
|
15
|
-
export declare function filterViews(views: string[], includedViews?: string[], ignoredViews?: string[]): string[];
|
|
16
|
-
/**
|
|
17
|
-
* Create entity objects with type information
|
|
18
|
-
*/
|
|
19
|
-
export interface EntityInfo {
|
|
20
|
-
name: string;
|
|
21
|
-
type: 'table' | 'view';
|
|
22
|
-
}
|
|
23
|
-
export declare function createEntityList(tables: string[], views: string[]): EntityInfo[];
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for parsing magic comments (@zod, @ts, @kysely)
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Extract type expression from a comment with a given prefix
|
|
6
|
-
* Handles nested parentheses, brackets, and braces
|
|
7
|
-
*/
|
|
8
|
-
export declare const extractTypeExpression: (comment: string, prefix: string) => string | null;
|
|
9
|
-
/**
|
|
10
|
-
* Extract TypeScript type expression from @ts() comment
|
|
11
|
-
*/
|
|
12
|
-
export declare const extractTSExpression: (comment: string) => string | null;
|
|
13
|
-
/**
|
|
14
|
-
* Extract Kysely type expression from @kysely() comment
|
|
15
|
-
*/
|
|
16
|
-
export declare const extractKyselyExpression: (comment: string) => string | null;
|
|
17
|
-
/**
|
|
18
|
-
* Extract Zod type expression from @zod() comment
|
|
19
|
-
*/
|
|
20
|
-
export declare const extractZodExpression: (comment: string) => string | null;
|
|
21
|
-
/**
|
|
22
|
-
* Check if a comment contains any magic comment
|
|
23
|
-
*/
|
|
24
|
-
export declare const hasMagicComment: (comment: string) => boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Parse all magic comments from a comment string
|
|
27
|
-
*/
|
|
28
|
-
export interface MagicComments {
|
|
29
|
-
zod?: string;
|
|
30
|
-
ts?: string;
|
|
31
|
-
kysely?: string;
|
|
32
|
-
}
|
|
33
|
-
export declare const parseMagicComments: (comment: string) => MagicComments;
|