mutano 3.0.14 → 3.0.16
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 +14 -5
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -243,16 +243,25 @@ function getType(op, desc, config, destination) {
|
|
|
243
243
|
if (isZodDestination && config.magicComments) {
|
|
244
244
|
const zodOverrideType = extractZodExpression(Comment);
|
|
245
245
|
if (zodOverrideType) {
|
|
246
|
-
const shouldBeNullable = isNull
|
|
246
|
+
const shouldBeNullable = isNull;
|
|
247
|
+
const shouldBeOptional = op === "insertable" && (hasDefaultValue || isGenerated) || op === "updateable";
|
|
247
248
|
const nullishOption = destination.nullish;
|
|
248
249
|
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
249
250
|
let finalType = zodOverrideType;
|
|
250
|
-
if (shouldBeNullable) {
|
|
251
|
+
if (shouldBeNullable && shouldBeOptional) {
|
|
251
252
|
if (!zodOverrideType.includes(`.${nullableMethod}()`) && !zodOverrideType.includes(".optional()")) {
|
|
252
253
|
finalType = `${zodOverrideType}.${nullableMethod}()`;
|
|
253
254
|
}
|
|
255
|
+
} else if (shouldBeNullable) {
|
|
256
|
+
if (!zodOverrideType.includes(`.${nullableMethod}()`) && !zodOverrideType.includes(".optional()")) {
|
|
257
|
+
finalType = `${zodOverrideType}.${nullableMethod}()`;
|
|
258
|
+
}
|
|
259
|
+
} else if (shouldBeOptional) {
|
|
260
|
+
if (!zodOverrideType.includes(".optional()") && !zodOverrideType.includes(`.${nullableMethod}()`)) {
|
|
261
|
+
finalType = `${zodOverrideType}.optional()`;
|
|
262
|
+
}
|
|
254
263
|
}
|
|
255
|
-
if ((op === "table" || op === "insertable"
|
|
264
|
+
if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
|
|
256
265
|
let defaultValueFormatted = Default;
|
|
257
266
|
if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
|
|
258
267
|
defaultValueFormatted = `'${Default}'`;
|
|
@@ -301,7 +310,7 @@ function getType(op, desc, config, destination) {
|
|
|
301
310
|
if (isZodDestination) {
|
|
302
311
|
const enumString = `z.enum([${enumValues.map((v) => `'${v}'`).join(",")}])`;
|
|
303
312
|
const nullishOption = destination.nullish;
|
|
304
|
-
if ((op === "table" || op === "insertable"
|
|
313
|
+
if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
|
|
305
314
|
if (shouldBeNullable) {
|
|
306
315
|
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
307
316
|
return `${enumString}.${nullableMethod}().default('${Default}')`;
|
|
@@ -403,7 +412,7 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
|
|
|
403
412
|
baseType = isZodDestination ? "z.string()" : "string";
|
|
404
413
|
}
|
|
405
414
|
if (isZodDestination) {
|
|
406
|
-
if ((op === "table" || op === "insertable"
|
|
415
|
+
if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
|
|
407
416
|
let defaultValueFormatted = Default;
|
|
408
417
|
if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
|
|
409
418
|
defaultValueFormatted = `'${Default}'`;
|
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.16",
|
|
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",
|