mutano 3.0.22 → 3.0.24

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.
Files changed (2) hide show
  1. package/dist/main.js +13 -8
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -311,9 +311,13 @@ function getType(op, desc, config, destination) {
311
311
  const enumString = `z.enum([${enumValues.map((v) => `'${v}'`).join(",")}])`;
312
312
  const nullishOption = destination.nullish;
313
313
  const nullableMethod = nullishOption && op !== "selectable" ? "nullish" : "nullable";
314
- if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
315
- if (shouldBeNullable) {
314
+ if ((op === "table" || op === "insertable" || op === "updateable") && hasDefaultValue && Default !== null && !isGenerated) {
315
+ if (shouldBeNullable && shouldBeOptional) {
316
316
  return `${enumString}.${nullableMethod}().default('${Default}')`;
317
+ } else if (shouldBeNullable) {
318
+ return `${enumString}.${nullableMethod}().default('${Default}')`;
319
+ } else if (shouldBeOptional) {
320
+ return `${enumString}.optional().default('${Default}')`;
317
321
  } else {
318
322
  return `${enumString}.default('${Default}')`;
319
323
  }
@@ -388,9 +392,6 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
388
392
  } else if (typeMappings.numberTypes.includes(type)) {
389
393
  if (isZodDestination) {
390
394
  baseType = "z.number()";
391
- if (!shouldBeNullable && !hasDefaultValue) {
392
- baseType += ".nonnegative()";
393
- }
394
395
  } else {
395
396
  baseType = "number";
396
397
  }
@@ -402,7 +403,7 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
402
403
  const requiredString = destination.requiredString;
403
404
  baseType = "z.string()";
404
405
  if (useTrim && op !== "selectable") baseType += ".trim()";
405
- if (requiredString && !shouldBeNullable && op !== "selectable") baseType += ".min(1)";
406
+ if (requiredString && !shouldBeNullable && op !== "selectable" && !(op === "updateable" && hasDefaultValue)) baseType += ".min(1)";
406
407
  } else {
407
408
  baseType = "string";
408
409
  }
@@ -412,7 +413,7 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
412
413
  if (isZodDestination) {
413
414
  const nullishOption = destination.nullish;
414
415
  const nullableMethod = nullishOption && op !== "selectable" ? "nullish" : "nullable";
415
- if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
416
+ if ((op === "table" || op === "insertable" || op === "updateable") && hasDefaultValue && Default !== null && !isGenerated) {
416
417
  let defaultValueFormatted = Default;
417
418
  if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
418
419
  defaultValueFormatted = `'${Default}'`;
@@ -423,8 +424,12 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
423
424
  } else {
424
425
  defaultValueFormatted = `'${Default}'`;
425
426
  }
426
- if (shouldBeNullable) {
427
+ if (shouldBeNullable && shouldBeOptional) {
427
428
  return `${baseType}.${nullableMethod}().default(${defaultValueFormatted})`;
429
+ } else if (shouldBeNullable) {
430
+ return `${baseType}.${nullableMethod}().default(${defaultValueFormatted})`;
431
+ } else if (shouldBeOptional) {
432
+ return `${baseType}.optional().default(${defaultValueFormatted})`;
428
433
  } else {
429
434
  return `${baseType}.default(${defaultValueFormatted})`;
430
435
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.0.22",
4
+ "version": "3.0.24",
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",