mutano 2.5.0 → 2.6.1
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 +27 -6
- package/package.json +31 -31
package/dist/main.js
CHANGED
|
@@ -93,14 +93,19 @@ const stringTypes = {
|
|
|
93
93
|
"clob",
|
|
94
94
|
"json"
|
|
95
95
|
],
|
|
96
|
-
prisma: ["String", "
|
|
96
|
+
prisma: ["String", "Bytes", "Json"]
|
|
97
|
+
};
|
|
98
|
+
const bigIntTypes = {
|
|
99
|
+
mysql: ["bigint"],
|
|
100
|
+
postgres: ["bigint"],
|
|
101
|
+
sqlite: ["bigint"],
|
|
102
|
+
prisma: ["BigInt"]
|
|
97
103
|
};
|
|
98
104
|
const numberTypes = {
|
|
99
|
-
mysql: ["smallint", "mediumint", "int", "
|
|
105
|
+
mysql: ["smallint", "mediumint", "int", "float", "double"],
|
|
100
106
|
postgres: [
|
|
101
107
|
"smallint",
|
|
102
108
|
"integer",
|
|
103
|
-
"bigint",
|
|
104
109
|
"real",
|
|
105
110
|
"double precision",
|
|
106
111
|
"serial",
|
|
@@ -112,7 +117,6 @@ const numberTypes = {
|
|
|
112
117
|
"tinyint",
|
|
113
118
|
"smallint",
|
|
114
119
|
"mediumint",
|
|
115
|
-
"bigint",
|
|
116
120
|
"unsigned big int",
|
|
117
121
|
"int2",
|
|
118
122
|
"int8",
|
|
@@ -184,6 +188,12 @@ function getType(op, desc, config, destination, tableName) {
|
|
|
184
188
|
if (booleanTypes[schemaType].includes(type)) {
|
|
185
189
|
return shouldBeNullable ? "boolean | null" : "boolean";
|
|
186
190
|
}
|
|
191
|
+
if (bigIntTypes[schemaType].includes(type) || type === "BigInt") {
|
|
192
|
+
if (isKyselyDestination) {
|
|
193
|
+
return shouldBeNullable ? "BigInt | null" : "BigInt";
|
|
194
|
+
}
|
|
195
|
+
return shouldBeNullable ? "string | null" : "string";
|
|
196
|
+
}
|
|
187
197
|
if (decimalTypes[schemaType].includes(type) || type === "Decimal") {
|
|
188
198
|
if (isKyselyDestination) {
|
|
189
199
|
return shouldBeNullable ? "Decimal | null" : "Decimal";
|
|
@@ -321,6 +331,16 @@ function getType(op, desc, config, destination, tableName) {
|
|
|
321
331
|
if (dateTypes[schemaType].includes(type)) return generateDateLikeField();
|
|
322
332
|
if (stringTypes[schemaType].includes(type)) return generateStringLikeField();
|
|
323
333
|
if (numberTypes[schemaType].includes(type)) return generateNumberLikeField();
|
|
334
|
+
if (bigIntTypes[schemaType].includes(type) || type === "BigInt") {
|
|
335
|
+
if (isKyselyDestination) {
|
|
336
|
+
const isNull2 = Null === "YES";
|
|
337
|
+
const hasDefaultValue2 = Default !== null;
|
|
338
|
+
const isGenerated2 = Extra.toLowerCase().includes("auto_increment") || Extra.toLowerCase().includes("default_generated");
|
|
339
|
+
const shouldBeNullable = isNull2 || ["insertable", "updateable"].includes(op) && (hasDefaultValue2 || isGenerated2) || op === "updateable" && !isNull2 && !hasDefaultValue2;
|
|
340
|
+
return shouldBeNullable ? "BigInt | null" : "BigInt";
|
|
341
|
+
}
|
|
342
|
+
return generateStringLikeField();
|
|
343
|
+
}
|
|
324
344
|
if (decimalTypes[schemaType].includes(type) || type === "Decimal") {
|
|
325
345
|
if (isKyselyDestination) {
|
|
326
346
|
const isNull2 = Null === "YES";
|
|
@@ -372,7 +392,7 @@ export interface ${camelCase(table, { pascalCase: true })} {`;
|
|
|
372
392
|
if (isNullable && !kyselyType.includes("| null")) {
|
|
373
393
|
kyselyType = `${kyselyType} | null`;
|
|
374
394
|
}
|
|
375
|
-
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"))) {
|
|
395
|
+
if (isAutoIncrement || isDefaultGenerated || hasDefaultValue && (isEnum || kyselyType === "string" || kyselyType === "boolean" || kyselyType === "number" || kyselyType === "Decimal" || kyselyType === "BigInt" || kyselyType.includes("boolean | null") || kyselyType.includes("string | null") || kyselyType.includes("number | null") || kyselyType.includes("Decimal | null") || kyselyType.includes("BigInt | null"))) {
|
|
376
396
|
kyselyType = `Generated<${kyselyType}>`;
|
|
377
397
|
}
|
|
378
398
|
} else if (isJsonField) {
|
|
@@ -383,7 +403,7 @@ export interface ${camelCase(table, { pascalCase: true })} {`;
|
|
|
383
403
|
kyselyType = `${kyselyType} | null`;
|
|
384
404
|
}
|
|
385
405
|
}
|
|
386
|
-
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"))) {
|
|
406
|
+
if (isAutoIncrement || isDefaultGenerated || hasDefaultValue && (isEnum || kyselyType === "string" || kyselyType === "boolean" || kyselyType === "number" || kyselyType === "Decimal" || kyselyType === "BigInt" || kyselyType.includes("boolean | null") || kyselyType.includes("string | null") || kyselyType.includes("number | null") || kyselyType.includes("Decimal | null") || kyselyType.includes("BigInt | null"))) {
|
|
387
407
|
kyselyType = `Generated<${kyselyType}>`;
|
|
388
408
|
}
|
|
389
409
|
}
|
|
@@ -855,6 +875,7 @@ export type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
|
855
875
|
|
|
856
876
|
export type Decimal = ColumnType<string, number | string>
|
|
857
877
|
|
|
878
|
+
export type BigInt = ColumnType<string, number | string>
|
|
858
879
|
`;
|
|
859
880
|
consolidatedContent += "// Table Interfaces\n";
|
|
860
881
|
for (const { content } of tableContents) {
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
"name": "mutano",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.6.1",
|
|
5
|
+
"description": "Converts Prisma/MySQL/PostgreSQL/SQLite schemas to Zod/TS/Kysely interfaces",
|
|
6
|
+
"author": "Alisson Cavalcante Agiani <thelinuxlich@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": "git@github.com:thelinuxlich/mutano.git",
|
|
9
|
+
"main": "dist/main.js",
|
|
10
|
+
"types": "dist/main.d.ts",
|
|
11
|
+
"files": ["dist"],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "esbuild src/main.ts --format=esm --platform=node --outfile=dist/main.js && tsc src/main.ts -d --emitDeclarationOnly --esModuleInterop --outDir dist",
|
|
14
|
+
"test": "vitest run"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@mrleebo/prisma-ast": "^0.12.1",
|
|
18
|
+
"camelcase": "^8.0.0",
|
|
19
|
+
"fs-extra": "^11.3.0",
|
|
20
|
+
"knex": "^3.1.0",
|
|
21
|
+
"mysql2": "^3.14.1",
|
|
22
|
+
"pg": "^8.16.0",
|
|
23
|
+
"sqlite3": "^5.1.7"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/fs-extra": "^11.0.4",
|
|
27
|
+
"esbuild": "^0.25.4",
|
|
28
|
+
"ts-node": "^10.9.2",
|
|
29
|
+
"tsx": "^4.19.4",
|
|
30
|
+
"typescript": "^5.8.3",
|
|
31
|
+
"vitest": "^3.1.3"
|
|
32
|
+
}
|
|
33
33
|
}
|