mutano 2.3.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.js +35 -16
- package/package.json +1 -1
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}
|
|
@@ -835,6 +852,8 @@ export type JsonPrimitive = boolean | number | string | null;
|
|
|
835
852
|
|
|
836
853
|
export type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
837
854
|
|
|
855
|
+
export type Decimal = ColumnType<string, number | string>
|
|
856
|
+
|
|
838
857
|
`;
|
|
839
858
|
consolidatedContent += "// Table Interfaces\n";
|
|
840
859
|
for (const { content } of tableContents) {
|
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",
|