mutano 3.0.0 → 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.
@@ -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
- 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;
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 {};