mutano 3.0.19 → 3.0.20
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 +5 -11
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -246,7 +246,7 @@ function getType(op, desc, config, destination) {
|
|
|
246
246
|
const shouldBeNullable = isNull;
|
|
247
247
|
const shouldBeOptional = op === "insertable" && (hasDefaultValue || isGenerated) || op === "updateable";
|
|
248
248
|
const nullishOption = destination.nullish;
|
|
249
|
-
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
249
|
+
const nullableMethod = nullishOption && op !== "selectable" ? "nullish" : "nullable";
|
|
250
250
|
let finalType = zodOverrideType;
|
|
251
251
|
if (shouldBeNullable && shouldBeOptional) {
|
|
252
252
|
if (!zodOverrideType.includes(`.${nullableMethod}()`) && !zodOverrideType.includes(".optional()")) {
|
|
@@ -283,7 +283,7 @@ function getType(op, desc, config, destination) {
|
|
|
283
283
|
const shouldBeNullable = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
|
|
284
284
|
if (isZodDestination) {
|
|
285
285
|
const nullishOption = destination.nullish;
|
|
286
|
-
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
286
|
+
const nullableMethod = nullishOption && op !== "selectable" ? "nullish" : "nullable";
|
|
287
287
|
return shouldBeNullable ? `${overrideType}.${nullableMethod}()` : overrideType;
|
|
288
288
|
} else {
|
|
289
289
|
return shouldBeNullable ? `${overrideType} | null` : overrideType;
|
|
@@ -310,19 +310,17 @@ function getType(op, desc, config, destination) {
|
|
|
310
310
|
if (isZodDestination) {
|
|
311
311
|
const enumString = `z.enum([${enumValues.map((v) => `'${v}'`).join(",")}])`;
|
|
312
312
|
const nullishOption = destination.nullish;
|
|
313
|
+
const nullableMethod = nullishOption && op !== "selectable" ? "nullish" : "nullable";
|
|
313
314
|
if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
|
|
314
315
|
if (shouldBeNullable) {
|
|
315
|
-
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
316
316
|
return `${enumString}.${nullableMethod}().default('${Default}')`;
|
|
317
317
|
} else {
|
|
318
318
|
return `${enumString}.default('${Default}')`;
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
if (shouldBeNullable && shouldBeOptional) {
|
|
322
|
-
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
323
322
|
return `${enumString}.${nullableMethod}()`;
|
|
324
323
|
} else if (shouldBeNullable) {
|
|
325
|
-
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
326
324
|
return `${enumString}.${nullableMethod}()`;
|
|
327
325
|
} else if (shouldBeOptional) {
|
|
328
326
|
return `${enumString}.optional()`;
|
|
@@ -412,6 +410,8 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
|
|
|
412
410
|
baseType = isZodDestination ? "z.string()" : "string";
|
|
413
411
|
}
|
|
414
412
|
if (isZodDestination) {
|
|
413
|
+
const nullishOption = destination.nullish;
|
|
414
|
+
const nullableMethod = nullishOption && op !== "selectable" ? "nullish" : "nullable";
|
|
415
415
|
if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
|
|
416
416
|
let defaultValueFormatted = Default;
|
|
417
417
|
if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
|
|
@@ -424,20 +424,14 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
|
|
|
424
424
|
defaultValueFormatted = `'${Default}'`;
|
|
425
425
|
}
|
|
426
426
|
if (shouldBeNullable) {
|
|
427
|
-
const nullishOption = destination.nullish;
|
|
428
|
-
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
429
427
|
return `${baseType}.${nullableMethod}().default(${defaultValueFormatted})`;
|
|
430
428
|
} else {
|
|
431
429
|
return `${baseType}.default(${defaultValueFormatted})`;
|
|
432
430
|
}
|
|
433
431
|
}
|
|
434
432
|
if (shouldBeNullable && shouldBeOptional) {
|
|
435
|
-
const nullishOption = destination.nullish;
|
|
436
|
-
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
437
433
|
return `${baseType}.${nullableMethod}()`;
|
|
438
434
|
} else if (shouldBeNullable) {
|
|
439
|
-
const nullishOption = destination.nullish;
|
|
440
|
-
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
441
435
|
return `${baseType}.${nullableMethod}()`;
|
|
442
436
|
} else if (shouldBeOptional) {
|
|
443
437
|
return `${baseType}.optional()`;
|
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.20",
|
|
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",
|