mutano 3.0.12 → 3.0.14
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 +29 -7
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ type PrismaValidTypes = 'String' | 'Boolean' | 'Int' | 'BigInt' | 'Float' | 'Dec
|
|
|
110
110
|
/**
|
|
111
111
|
* Constants and default headers for code generation
|
|
112
112
|
*/
|
|
113
|
-
declare const defaultKyselyHeader = "import {
|
|
113
|
+
declare const defaultKyselyHeader = "import { Insertable, Selectable, Updateable, ColumnType } from 'kysely';\n\n";
|
|
114
114
|
declare const defaultZodHeader: (version: 3 | 4) => string;
|
|
115
115
|
|
|
116
116
|
/**
|
package/dist/main.js
CHANGED
|
@@ -246,7 +246,26 @@ function getType(op, desc, config, destination) {
|
|
|
246
246
|
const shouldBeNullable = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
|
|
247
247
|
const nullishOption = destination.nullish;
|
|
248
248
|
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
249
|
-
|
|
249
|
+
let finalType = zodOverrideType;
|
|
250
|
+
if (shouldBeNullable) {
|
|
251
|
+
if (!zodOverrideType.includes(`.${nullableMethod}()`) && !zodOverrideType.includes(".optional()")) {
|
|
252
|
+
finalType = `${zodOverrideType}.${nullableMethod}()`;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if ((op === "table" || op === "insertable" || op === "selectable") && hasDefaultValue && Default !== null && !isGenerated) {
|
|
256
|
+
let defaultValueFormatted = Default;
|
|
257
|
+
if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
|
|
258
|
+
defaultValueFormatted = `'${Default}'`;
|
|
259
|
+
} else if (typeMappings.booleanTypes.includes(type)) {
|
|
260
|
+
defaultValueFormatted = Default.toLowerCase() === "true" ? "true" : "false";
|
|
261
|
+
} else if (typeMappings.numberTypes.includes(type)) {
|
|
262
|
+
defaultValueFormatted = Default;
|
|
263
|
+
} else {
|
|
264
|
+
defaultValueFormatted = `'${Default}'`;
|
|
265
|
+
}
|
|
266
|
+
finalType = `${finalType}.default(${defaultValueFormatted})`;
|
|
267
|
+
}
|
|
268
|
+
return finalType;
|
|
250
269
|
}
|
|
251
270
|
}
|
|
252
271
|
const overrideTypes = config.origin.overrideTypes;
|
|
@@ -604,11 +623,14 @@ function generateKyselyContent({
|
|
|
604
623
|
for (const desc of describes) {
|
|
605
624
|
const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
|
|
606
625
|
let fieldType = getType("table", desc, config, destination);
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
626
|
+
const hasMagicComment = config.magicComments && (desc.Comment.includes("@kysely(") || desc.Comment.includes("@ts("));
|
|
627
|
+
if (!hasMagicComment) {
|
|
628
|
+
const isAutoIncrement = desc.Extra.toLowerCase().includes("auto_increment");
|
|
629
|
+
const isDefaultGenerated = desc.Extra.toLowerCase().includes("default_generated");
|
|
630
|
+
const hasExplicitDefault = desc.Default !== null && !isAutoIncrement && !isDefaultGenerated;
|
|
631
|
+
if (isAutoIncrement || isDefaultGenerated || hasExplicitDefault) {
|
|
632
|
+
fieldType = `Generated<${fieldType.replace(" | null", "")}>${fieldType.includes(" | null") ? " | null" : ""}`;
|
|
633
|
+
}
|
|
612
634
|
}
|
|
613
635
|
content += ` ${fieldName}: ${fieldType};
|
|
614
636
|
`;
|
|
@@ -933,7 +955,7 @@ function extractPrismaColumnDescriptions(config, entityName, enumDeclarations) {
|
|
|
933
955
|
});
|
|
934
956
|
}
|
|
935
957
|
|
|
936
|
-
const defaultKyselyHeader = "import {
|
|
958
|
+
const defaultKyselyHeader = "import { Insertable, Selectable, Updateable, ColumnType } from 'kysely';\n\n";
|
|
937
959
|
const defaultZodHeader = (version) => "import { z } from 'zod" + (version === 3 ? "" : "/v4") + "';\n\n";
|
|
938
960
|
const kyselyJsonTypes = `// JSON type definitions
|
|
939
961
|
export type Json = ColumnType<JsonValue, string, string>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mutano",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.14",
|
|
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",
|