mutano 3.0.10 → 3.0.12
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.
- package/dist/main.js +19 -13
- 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
|
-
|
|
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 ${
|
|
495
|
+
})} = z.infer<typeof ${snakeView}_view>
|
|
492
496
|
`;
|
|
493
497
|
}
|
|
494
498
|
return content;
|
|
@@ -602,7 +606,8 @@ function generateKyselyContent({
|
|
|
602
606
|
let fieldType = getType("table", desc, config, destination);
|
|
603
607
|
const isAutoIncrement = desc.Extra.toLowerCase().includes("auto_increment");
|
|
604
608
|
const isDefaultGenerated = desc.Extra.toLowerCase().includes("default_generated");
|
|
605
|
-
|
|
609
|
+
const hasExplicitDefault = desc.Default !== null && !isAutoIncrement && !isDefaultGenerated;
|
|
610
|
+
if (isAutoIncrement || isDefaultGenerated || hasExplicitDefault) {
|
|
606
611
|
fieldType = `Generated<${fieldType.replace(" | null", "")}>${fieldType.includes(" | null") ? " | null" : ""}`;
|
|
607
612
|
}
|
|
608
613
|
content += ` ${fieldName}: ${fieldType};
|
|
@@ -633,7 +638,8 @@ function generateZodContent({
|
|
|
633
638
|
if (!content.includes(header)) {
|
|
634
639
|
content += header;
|
|
635
640
|
}
|
|
636
|
-
|
|
641
|
+
const snakeTable = toSnakeCase(table);
|
|
642
|
+
content += `export const ${snakeTable} = z.object({
|
|
637
643
|
`;
|
|
638
644
|
for (const desc of describes) {
|
|
639
645
|
const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
|
|
@@ -642,7 +648,7 @@ function generateZodContent({
|
|
|
642
648
|
`;
|
|
643
649
|
}
|
|
644
650
|
content += "})\n\n";
|
|
645
|
-
content += `export const insertable_${
|
|
651
|
+
content += `export const insertable_${snakeTable} = z.object({
|
|
646
652
|
`;
|
|
647
653
|
for (const desc of describes) {
|
|
648
654
|
const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
|
|
@@ -651,7 +657,7 @@ function generateZodContent({
|
|
|
651
657
|
`;
|
|
652
658
|
}
|
|
653
659
|
content += "})\n\n";
|
|
654
|
-
content += `export const updateable_${
|
|
660
|
+
content += `export const updateable_${snakeTable} = z.object({
|
|
655
661
|
`;
|
|
656
662
|
for (const desc of describes) {
|
|
657
663
|
const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
|
|
@@ -660,7 +666,7 @@ function generateZodContent({
|
|
|
660
666
|
`;
|
|
661
667
|
}
|
|
662
668
|
content += "})\n\n";
|
|
663
|
-
content += `export const selectable_${
|
|
669
|
+
content += `export const selectable_${snakeTable} = z.object({
|
|
664
670
|
`;
|
|
665
671
|
for (const desc of describes) {
|
|
666
672
|
const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
|
|
@@ -669,13 +675,13 @@ function generateZodContent({
|
|
|
669
675
|
`;
|
|
670
676
|
}
|
|
671
677
|
content += "})\n\n";
|
|
672
|
-
content += `export type ${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof ${
|
|
678
|
+
content += `export type ${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof ${snakeTable}>
|
|
673
679
|
`;
|
|
674
|
-
content += `export type Insertable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof insertable_${
|
|
680
|
+
content += `export type Insertable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof insertable_${snakeTable}>
|
|
675
681
|
`;
|
|
676
|
-
content += `export type Updateable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof updateable_${
|
|
682
|
+
content += `export type Updateable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof updateable_${snakeTable}>
|
|
677
683
|
`;
|
|
678
|
-
content += `export type Selectable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof selectable_${
|
|
684
|
+
content += `export type Selectable${camelCase(`${table}Type`, { pascalCase: true })} = z.infer<typeof selectable_${snakeTable}>
|
|
679
685
|
`;
|
|
680
686
|
return content;
|
|
681
687
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mutano",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.12",
|
|
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",
|