mutano 3.0.10 → 3.0.11

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 +17 -12
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -282,7 +282,7 @@ 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) {
285
+ if ((op === "table" || op === "insertable" || op === "selectable") && hasDefaultValue && Default !== null && !isGenerated) {
286
286
  if (shouldBeNullable) {
287
287
  const nullableMethod = nullishOption ? "nullish" : "nullable";
288
288
  return `${enumString}.${nullableMethod}().default('${Default}')`;
@@ -384,7 +384,7 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
384
384
  baseType = isZodDestination ? "z.string()" : "string";
385
385
  }
386
386
  if (isZodDestination) {
387
- if (op === "insertable" && hasDefaultValue && Default !== null && !isGenerated) {
387
+ if ((op === "table" || op === "insertable" || op === "selectable") && hasDefaultValue && Default !== null && !isGenerated) {
388
388
  let defaultValueFormatted = Default;
389
389
  if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
390
390
  defaultValueFormatted = `'${Default}'`;
@@ -425,6 +425,9 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
425
425
  }
426
426
  }
427
427
 
428
+ function toSnakeCase(str) {
429
+ return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
430
+ }
428
431
  function generateViewContent({
429
432
  view,
430
433
  describes,
@@ -476,7 +479,8 @@ function generateViewContent({
476
479
  }
477
480
  content += `// View schema (read-only)
478
481
  `;
479
- content += `export const ${view}_view = z.object({
482
+ const snakeView = toSnakeCase(view);
483
+ content += `export const ${snakeView}_view = z.object({
480
484
  `;
481
485
  for (const desc of describes) {
482
486
  const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
@@ -488,7 +492,7 @@ function generateViewContent({
488
492
  const pascalView = camelCase(view, { pascalCase: true });
489
493
  content += `export type ${camelCase(`${pascalView}ViewType`, {
490
494
  pascalCase: true
491
- })} = z.infer<typeof ${view}_view>
495
+ })} = z.infer<typeof ${snakeView}_view>
492
496
  `;
493
497
  }
494
498
  return content;
@@ -633,7 +637,8 @@ function generateZodContent({
633
637
  if (!content.includes(header)) {
634
638
  content += header;
635
639
  }
636
- content += `export const ${table} = z.object({
640
+ const snakeTable = toSnakeCase(table);
641
+ content += `export const ${snakeTable} = z.object({
637
642
  `;
638
643
  for (const desc of describes) {
639
644
  const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
@@ -642,7 +647,7 @@ function generateZodContent({
642
647
  `;
643
648
  }
644
649
  content += "})\n\n";
645
- content += `export const insertable_${table} = z.object({
650
+ content += `export const insertable_${snakeTable} = z.object({
646
651
  `;
647
652
  for (const desc of describes) {
648
653
  const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
@@ -651,7 +656,7 @@ function generateZodContent({
651
656
  `;
652
657
  }
653
658
  content += "})\n\n";
654
- content += `export const updateable_${table} = z.object({
659
+ content += `export const updateable_${snakeTable} = z.object({
655
660
  `;
656
661
  for (const desc of describes) {
657
662
  const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
@@ -660,7 +665,7 @@ function generateZodContent({
660
665
  `;
661
666
  }
662
667
  content += "})\n\n";
663
- content += `export const selectable_${table} = z.object({
668
+ content += `export const selectable_${snakeTable} = z.object({
664
669
  `;
665
670
  for (const desc of describes) {
666
671
  const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
@@ -669,13 +674,13 @@ function generateZodContent({
669
674
  `;
670
675
  }
671
676
  content += "})\n\n";
672
- content += `export type ${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof ${table}>
677
+ content += `export type ${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof ${snakeTable}>
673
678
  `;
674
- content += `export type Insertable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof insertable_${table}>
679
+ content += `export type Insertable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof insertable_${snakeTable}>
675
680
  `;
676
- content += `export type Updateable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof updateable_${table}>
681
+ content += `export type Updateable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof updateable_${snakeTable}>
677
682
  `;
678
- content += `export type Selectable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof selectable_${table}>
683
+ content += `export type Selectable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof selectable_${snakeTable}>
679
684
  `;
680
685
  return content;
681
686
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.0.10",
4
+ "version": "3.0.11",
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",