mutano 3.0.9 → 3.0.10

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 +43 -3
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -282,6 +282,14 @@ function getType(op, desc, config, destination) {
282
282
  if (isZodDestination) {
283
283
  const enumString = `z.enum([${enumValues.map((v) => `'${v}'`).join(",")}])`;
284
284
  const nullishOption = destination.nullish;
285
+ if (op === "insertable" && hasDefaultValue && Default !== null && !isGenerated) {
286
+ if (shouldBeNullable) {
287
+ const nullableMethod = nullishOption ? "nullish" : "nullable";
288
+ return `${enumString}.${nullableMethod}().default('${Default}')`;
289
+ } else {
290
+ return `${enumString}.default('${Default}')`;
291
+ }
292
+ }
285
293
  if (shouldBeNullable && shouldBeOptional) {
286
294
  const nullableMethod = nullishOption ? "nullish" : "nullable";
287
295
  return `${enumString}.${nullableMethod}()`;
@@ -376,6 +384,25 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
376
384
  baseType = isZodDestination ? "z.string()" : "string";
377
385
  }
378
386
  if (isZodDestination) {
387
+ if (op === "insertable" && hasDefaultValue && Default !== null && !isGenerated) {
388
+ let defaultValueFormatted = Default;
389
+ if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
390
+ defaultValueFormatted = `'${Default}'`;
391
+ } else if (typeMappings.booleanTypes.includes(type)) {
392
+ defaultValueFormatted = Default.toLowerCase() === "true" ? "true" : "false";
393
+ } else if (typeMappings.numberTypes.includes(type)) {
394
+ defaultValueFormatted = Default;
395
+ } else {
396
+ defaultValueFormatted = `'${Default}'`;
397
+ }
398
+ if (shouldBeNullable) {
399
+ const nullishOption = destination.nullish;
400
+ const nullableMethod = nullishOption ? "nullish" : "nullable";
401
+ return `${baseType}.${nullableMethod}().default(${defaultValueFormatted})`;
402
+ } else {
403
+ return `${baseType}.default(${defaultValueFormatted})`;
404
+ }
405
+ }
379
406
  if (shouldBeNullable && shouldBeOptional) {
380
407
  const nullishOption = destination.nullish;
381
408
  const nullableMethod = nullishOption ? "nullish" : "nullable";
@@ -854,15 +881,28 @@ function extractPrismaColumnDescriptions(config, entityName, enumDeclarations) {
854
881
  let defaultValue = null;
855
882
  if (field.attributes) {
856
883
  for (const attr of field.attributes) {
857
- if (attr.name === "default") {
884
+ if (attr.name === "updatedAt") {
885
+ defaultGenerated = true;
886
+ } else if (attr.name === "default") {
858
887
  if (attr.args && attr.args.length > 0) {
859
888
  const arg = attr.args[0];
860
889
  if (typeof arg === "object" && "value" in arg) {
861
- if (arg.value === "autoincrement()" || arg.value === "cuid()" || arg.value === "uuid()") {
862
- defaultGenerated = true;
890
+ if (typeof arg.value === "object" && arg.value.type === "function") {
891
+ const functionName = arg.value.name;
892
+ if (functionName === "autoincrement" || functionName === "cuid" || functionName === "uuid" || functionName === "now") {
893
+ defaultGenerated = true;
894
+ }
895
+ } else if (typeof arg.value === "string") {
896
+ let cleanValue = arg.value;
897
+ if (cleanValue.startsWith('"') && cleanValue.endsWith('"')) {
898
+ cleanValue = cleanValue.slice(1, -1);
899
+ }
900
+ defaultValue = cleanValue;
863
901
  } else {
864
902
  defaultValue = String(arg.value);
865
903
  }
904
+ } else if (typeof arg === "string") {
905
+ defaultValue = arg;
866
906
  }
867
907
  }
868
908
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.0.9",
4
+ "version": "3.0.10",
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",