mutano 3.0.18 → 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.
Files changed (2) hide show
  1. package/dist/main.js +23 -12
  2. 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()`;
@@ -892,7 +886,24 @@ function extractPrismaEntities(config) {
892
886
  if (prismaEnum && "name" in prismaEnum && "enumerators" in prismaEnum) {
893
887
  const enumName = prismaEnum.name;
894
888
  const enumerators = prismaEnum.enumerators;
895
- enumDeclarations[enumName] = enumerators.map((e) => e.name);
889
+ enumDeclarations[enumName] = enumerators.map((e) => {
890
+ if ("attributes" in e && e.attributes) {
891
+ const mapAttr = e.attributes.find((attr) => attr.name === "map");
892
+ if (mapAttr && mapAttr.args && mapAttr.args.length > 0) {
893
+ const mapValue = mapAttr.args[0];
894
+ if (typeof mapValue === "object" && "value" in mapValue) {
895
+ let cleanValue = String(mapValue.value);
896
+ if (cleanValue.startsWith('"') && cleanValue.endsWith('"')) {
897
+ cleanValue = cleanValue.slice(1, -1);
898
+ }
899
+ return cleanValue;
900
+ } else if (typeof mapValue === "string") {
901
+ return mapValue;
902
+ }
903
+ }
904
+ }
905
+ return e.name;
906
+ });
896
907
  }
897
908
  }
898
909
  return { tables, views, enumDeclarations };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.0.18",
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",