mutano 2.2.0 → 2.4.0
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/dist/main.d.ts +1 -1
- package/dist/main.js +55 -21
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface GenerateContentParams {
|
|
|
11
11
|
export declare function generateContent({ table, describes, config, destination, isCamelCase, enumDeclarations, defaultZodHeader, }: GenerateContentParams): string;
|
|
12
12
|
export declare const defaultKyselyHeader = "import { Generated, ColumnType, Selectable, Insertable, Updateable } from 'kysely';\n\n";
|
|
13
13
|
export declare const defaultZodHeader = "import { z } from 'zod';\n\n";
|
|
14
|
-
export declare function generate(config: Config): Promise<
|
|
14
|
+
export declare function generate(config: Config): Promise<Record<string, string>>;
|
|
15
15
|
type MySQLValidTypes = 'date' | 'datetime' | 'timestamp' | 'time' | 'year' | 'char' | 'varchar' | 'tinytext' | 'text' | 'mediumtext' | 'longtext' | 'json' | 'decimal' | 'tinyint' | 'smallint' | 'mediumint' | 'int' | 'bigint' | 'float' | 'double' | 'enum';
|
|
16
16
|
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';
|
|
17
17
|
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';
|
package/dist/main.js
CHANGED
|
@@ -77,7 +77,6 @@ const stringTypes = {
|
|
|
77
77
|
"mediumtext",
|
|
78
78
|
"longtext",
|
|
79
79
|
"json",
|
|
80
|
-
"decimal",
|
|
81
80
|
"time",
|
|
82
81
|
"year",
|
|
83
82
|
"char",
|
|
@@ -96,9 +95,7 @@ const stringTypes = {
|
|
|
96
95
|
"timetz",
|
|
97
96
|
"interval",
|
|
98
97
|
"name",
|
|
99
|
-
"citext"
|
|
100
|
-
"numeric",
|
|
101
|
-
"decimal"
|
|
98
|
+
"citext"
|
|
102
99
|
],
|
|
103
100
|
sqlite: [
|
|
104
101
|
"text",
|
|
@@ -111,7 +108,7 @@ const stringTypes = {
|
|
|
111
108
|
"clob",
|
|
112
109
|
"json"
|
|
113
110
|
],
|
|
114
|
-
prisma: ["String", "
|
|
111
|
+
prisma: ["String", "BigInt", "Bytes", "Json"]
|
|
115
112
|
};
|
|
116
113
|
const numberTypes = {
|
|
117
114
|
mysql: ["smallint", "mediumint", "int", "bigint", "float", "double"],
|
|
@@ -119,8 +116,6 @@ const numberTypes = {
|
|
|
119
116
|
"smallint",
|
|
120
117
|
"integer",
|
|
121
118
|
"bigint",
|
|
122
|
-
"decimal",
|
|
123
|
-
"numeric",
|
|
124
119
|
"real",
|
|
125
120
|
"double precision",
|
|
126
121
|
"serial",
|
|
@@ -139,12 +134,16 @@ const numberTypes = {
|
|
|
139
134
|
"real",
|
|
140
135
|
"double",
|
|
141
136
|
"double precision",
|
|
142
|
-
"float"
|
|
143
|
-
"numeric",
|
|
144
|
-
"decimal"
|
|
137
|
+
"float"
|
|
145
138
|
],
|
|
146
139
|
prisma: ["Int", "Float"]
|
|
147
140
|
};
|
|
141
|
+
const decimalTypes = {
|
|
142
|
+
mysql: ["decimal"],
|
|
143
|
+
postgres: ["decimal", "numeric"],
|
|
144
|
+
sqlite: ["numeric", "decimal"],
|
|
145
|
+
prisma: ["Decimal"]
|
|
146
|
+
};
|
|
148
147
|
const booleanTypes = {
|
|
149
148
|
mysql: ["tinyint"],
|
|
150
149
|
postgres: ["boolean", "bool"],
|
|
@@ -193,6 +192,12 @@ function getType(op, desc, config, destination, tableName) {
|
|
|
193
192
|
if (booleanTypes[schemaType].includes(type)) {
|
|
194
193
|
return shouldBeNullable ? "boolean | null" : "boolean";
|
|
195
194
|
}
|
|
195
|
+
if (decimalTypes[schemaType].includes(type) || type === "Decimal") {
|
|
196
|
+
if (isKyselyDestination) {
|
|
197
|
+
return shouldBeNullable ? "Decimal | null" : "Decimal";
|
|
198
|
+
}
|
|
199
|
+
return shouldBeNullable ? "string | null" : "string";
|
|
200
|
+
}
|
|
196
201
|
if (schemaType !== "sqlite" && enumTypes[schemaType].includes(type)) {
|
|
197
202
|
const enumType = destination.type === "ts" ? destination.enumType || "union" : "union";
|
|
198
203
|
let enumValues = [];
|
|
@@ -324,6 +329,16 @@ function getType(op, desc, config, destination, tableName) {
|
|
|
324
329
|
if (dateTypes[schemaType].includes(type)) return generateDateLikeField();
|
|
325
330
|
if (stringTypes[schemaType].includes(type)) return generateStringLikeField();
|
|
326
331
|
if (numberTypes[schemaType].includes(type)) return generateNumberLikeField();
|
|
332
|
+
if (decimalTypes[schemaType].includes(type) || type === "Decimal") {
|
|
333
|
+
if (isKyselyDestination) {
|
|
334
|
+
const isNull2 = Null === "YES";
|
|
335
|
+
const hasDefaultValue2 = Default !== null;
|
|
336
|
+
const isGenerated2 = Extra.toLowerCase().includes("auto_increment") || Extra.toLowerCase().includes("default_generated");
|
|
337
|
+
const shouldBeNullable = isNull2 || ["insertable", "updateable"].includes(op) && (hasDefaultValue2 || isGenerated2) || op === "updateable" && !isNull2 && !hasDefaultValue2;
|
|
338
|
+
return shouldBeNullable ? "Decimal | null" : "Decimal";
|
|
339
|
+
}
|
|
340
|
+
return generateStringLikeField();
|
|
341
|
+
}
|
|
327
342
|
if (booleanTypes[schemaType].includes(type)) return generateBooleanLikeField();
|
|
328
343
|
if (schemaType !== "sqlite" && enumTypes[schemaType].includes(type))
|
|
329
344
|
return generateEnumLikeField();
|
|
@@ -361,12 +376,14 @@ export interface ${camelCase(table, { pascalCase: true })} {`;
|
|
|
361
376
|
);
|
|
362
377
|
if (isJsonField) {
|
|
363
378
|
kyselyType = "Json";
|
|
364
|
-
} else
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
379
|
+
} else {
|
|
380
|
+
if (isNullable && !isJsonField) {
|
|
381
|
+
if (!kyselyType.includes("| null")) {
|
|
382
|
+
kyselyType = `${kyselyType} | null`;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (isAutoIncrement || isDefaultGenerated || hasDefaultValue && (isEnum || kyselyType === "string" || kyselyType === "boolean" || kyselyType === "number" || kyselyType === "Decimal" || kyselyType.includes("boolean | null") || kyselyType.includes("string | null") || kyselyType.includes("number | null") || kyselyType.includes("Decimal | null"))) {
|
|
386
|
+
kyselyType = `Generated<${kyselyType}>`;
|
|
370
387
|
}
|
|
371
388
|
}
|
|
372
389
|
content = `${content}
|
|
@@ -779,7 +796,8 @@ async function generate(config) {
|
|
|
779
796
|
const folder = destination.folder || ".";
|
|
780
797
|
const file = suffix !== "" ? `${table}.${suffix}.ts` : `${table}.ts`;
|
|
781
798
|
if (config.dryRun) {
|
|
782
|
-
|
|
799
|
+
const absolutePath = path.resolve(path.join(folder, file));
|
|
800
|
+
dryRunOutput[absolutePath] = content;
|
|
783
801
|
} else {
|
|
784
802
|
const dest = path.join(folder, file);
|
|
785
803
|
dests.push(dest);
|
|
@@ -806,7 +824,7 @@ async function generate(config) {
|
|
|
806
824
|
content
|
|
807
825
|
});
|
|
808
826
|
if (config.dryRun) {
|
|
809
|
-
const tempKey = `${table}.kysely.temp
|
|
827
|
+
const tempKey = path.resolve(`${table}.kysely.temp`);
|
|
810
828
|
dryRunOutput[tempKey] = content;
|
|
811
829
|
}
|
|
812
830
|
}
|
|
@@ -834,6 +852,8 @@ export type JsonPrimitive = boolean | number | string | null;
|
|
|
834
852
|
|
|
835
853
|
export type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
836
854
|
|
|
855
|
+
export type Decimal = ColumnType<string, number | string>
|
|
856
|
+
|
|
837
857
|
`;
|
|
838
858
|
consolidatedContent += "// Table Interfaces\n";
|
|
839
859
|
for (const { content } of tableContents) {
|
|
@@ -855,8 +875,8 @@ export interface ${schemaName} {
|
|
|
855
875
|
}
|
|
856
876
|
consolidatedContent += "}\n";
|
|
857
877
|
if (config.dryRun) {
|
|
858
|
-
const
|
|
859
|
-
dryRunOutput[
|
|
878
|
+
const absolutePath = path.resolve(outFile);
|
|
879
|
+
dryRunOutput[absolutePath] = consolidatedContent;
|
|
860
880
|
for (const key of Object.keys(dryRunOutput)) {
|
|
861
881
|
if (key.endsWith(".kysely.temp")) {
|
|
862
882
|
delete dryRunOutput[key];
|
|
@@ -869,7 +889,21 @@ export interface ${schemaName} {
|
|
|
869
889
|
fs.outputFileSync(dest, consolidatedContent);
|
|
870
890
|
}
|
|
871
891
|
}
|
|
872
|
-
|
|
892
|
+
if (!config.dryRun) {
|
|
893
|
+
const result2 = {};
|
|
894
|
+
for (const dest of dests) {
|
|
895
|
+
const absolutePath = path.resolve(dest);
|
|
896
|
+
const content = fs.readFileSync(dest, "utf8");
|
|
897
|
+
result2[absolutePath] = content;
|
|
898
|
+
}
|
|
899
|
+
return result2;
|
|
900
|
+
}
|
|
901
|
+
const result = {};
|
|
902
|
+
for (const [key, content] of Object.entries(dryRunOutput)) {
|
|
903
|
+
const absolutePath = path.resolve(key);
|
|
904
|
+
result[absolutePath] = content;
|
|
905
|
+
}
|
|
906
|
+
return result;
|
|
873
907
|
}
|
|
874
908
|
export {
|
|
875
909
|
defaultKyselyHeader,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mutano",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
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",
|