mutano 3.0.23 → 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 -5
  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
  }
@@ -399,7 +403,7 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
399
403
  const requiredString = destination.requiredString;
400
404
  baseType = "z.string()";
401
405
  if (useTrim && op !== "selectable") baseType += ".trim()";
402
- if (requiredString && !shouldBeNullable && op !== "selectable") baseType += ".min(1)";
406
+ if (requiredString && !shouldBeNullable && op !== "selectable" && !(op === "updateable" && hasDefaultValue)) baseType += ".min(1)";
403
407
  } else {
404
408
  baseType = "string";
405
409
  }
@@ -409,7 +413,7 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
409
413
  if (isZodDestination) {
410
414
  const nullishOption = destination.nullish;
411
415
  const nullableMethod = nullishOption && op !== "selectable" ? "nullish" : "nullable";
412
- if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
416
+ if ((op === "table" || op === "insertable" || op === "updateable") && hasDefaultValue && Default !== null && !isGenerated) {
413
417
  let defaultValueFormatted = Default;
414
418
  if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
415
419
  defaultValueFormatted = `'${Default}'`;
@@ -420,8 +424,12 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
420
424
  } else {
421
425
  defaultValueFormatted = `'${Default}'`;
422
426
  }
423
- if (shouldBeNullable) {
427
+ if (shouldBeNullable && shouldBeOptional) {
424
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})`;
425
433
  } else {
426
434
  return `${baseType}.default(${defaultValueFormatted})`;
427
435
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.0.23",
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",