mutano 3.0.13 → 3.0.15

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 +30 -8
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -246,7 +246,26 @@ function getType(op, desc, config, destination) {
246
246
  const shouldBeNullable = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
247
247
  const nullishOption = destination.nullish;
248
248
  const nullableMethod = nullishOption ? "nullish" : "nullable";
249
- return shouldBeNullable ? zodOverrideType.includes(`.${nullableMethod}()`) || zodOverrideType.includes(".optional()") ? zodOverrideType : `${zodOverrideType}.${nullableMethod}()` : zodOverrideType;
249
+ let finalType = zodOverrideType;
250
+ if (shouldBeNullable) {
251
+ if (!zodOverrideType.includes(`.${nullableMethod}()`) && !zodOverrideType.includes(".optional()")) {
252
+ finalType = `${zodOverrideType}.${nullableMethod}()`;
253
+ }
254
+ }
255
+ if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
256
+ let defaultValueFormatted = Default;
257
+ if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
258
+ defaultValueFormatted = `'${Default}'`;
259
+ } else if (typeMappings.booleanTypes.includes(type)) {
260
+ defaultValueFormatted = Default.toLowerCase() === "true" ? "true" : "false";
261
+ } else if (typeMappings.numberTypes.includes(type)) {
262
+ defaultValueFormatted = Default;
263
+ } else {
264
+ defaultValueFormatted = `'${Default}'`;
265
+ }
266
+ finalType = `${finalType}.default(${defaultValueFormatted})`;
267
+ }
268
+ return finalType;
250
269
  }
251
270
  }
252
271
  const overrideTypes = config.origin.overrideTypes;
@@ -282,7 +301,7 @@ function getType(op, desc, config, destination) {
282
301
  if (isZodDestination) {
283
302
  const enumString = `z.enum([${enumValues.map((v) => `'${v}'`).join(",")}])`;
284
303
  const nullishOption = destination.nullish;
285
- if ((op === "table" || op === "insertable" || op === "selectable") && hasDefaultValue && Default !== null && !isGenerated) {
304
+ if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
286
305
  if (shouldBeNullable) {
287
306
  const nullableMethod = nullishOption ? "nullish" : "nullable";
288
307
  return `${enumString}.${nullableMethod}().default('${Default}')`;
@@ -384,7 +403,7 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
384
403
  baseType = isZodDestination ? "z.string()" : "string";
385
404
  }
386
405
  if (isZodDestination) {
387
- if ((op === "table" || op === "insertable" || op === "selectable") && hasDefaultValue && Default !== null && !isGenerated) {
406
+ if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
388
407
  let defaultValueFormatted = Default;
389
408
  if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
390
409
  defaultValueFormatted = `'${Default}'`;
@@ -604,11 +623,14 @@ function generateKyselyContent({
604
623
  for (const desc of describes) {
605
624
  const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
606
625
  let fieldType = getType("table", desc, config, destination);
607
- const isAutoIncrement = desc.Extra.toLowerCase().includes("auto_increment");
608
- const isDefaultGenerated = desc.Extra.toLowerCase().includes("default_generated");
609
- const hasExplicitDefault = desc.Default !== null && !isAutoIncrement && !isDefaultGenerated;
610
- if (isAutoIncrement || isDefaultGenerated || hasExplicitDefault) {
611
- fieldType = `Generated<${fieldType.replace(" | null", "")}>${fieldType.includes(" | null") ? " | null" : ""}`;
626
+ const hasMagicComment = config.magicComments && (desc.Comment.includes("@kysely(") || desc.Comment.includes("@ts("));
627
+ if (!hasMagicComment) {
628
+ const isAutoIncrement = desc.Extra.toLowerCase().includes("auto_increment");
629
+ const isDefaultGenerated = desc.Extra.toLowerCase().includes("default_generated");
630
+ const hasExplicitDefault = desc.Default !== null && !isAutoIncrement && !isDefaultGenerated;
631
+ if (isAutoIncrement || isDefaultGenerated || hasExplicitDefault) {
632
+ fieldType = `Generated<${fieldType.replace(" | null", "")}>${fieldType.includes(" | null") ? " | null" : ""}`;
633
+ }
612
634
  }
613
635
  content += ` ${fieldName}: ${fieldType};
614
636
  `;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.0.13",
4
+ "version": "3.0.15",
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",