mutano 3.0.24 → 3.1.0
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/README.md +10 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +25 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,6 +145,7 @@ export type UpdateableUser = Updateable<User>;
|
|
|
145
145
|
|
|
146
146
|
// Zod specific
|
|
147
147
|
useDateType?: boolean,
|
|
148
|
+
useBooleanType?: boolean,
|
|
148
149
|
useTrim?: boolean,
|
|
149
150
|
nullish?: boolean,
|
|
150
151
|
requiredString?: boolean,
|
|
@@ -159,6 +160,15 @@ export type UpdateableUser = Updateable<User>;
|
|
|
159
160
|
}
|
|
160
161
|
```
|
|
161
162
|
|
|
163
|
+
### Zod Configuration Options
|
|
164
|
+
|
|
165
|
+
- **`useDateType`**: When `true`, generates `z.union([z.number(), z.string(), z.date()]).pipe(z.coerce.date())` instead of `z.date()` for date fields
|
|
166
|
+
- **`useBooleanType`**: When `true`, generates `z.union([z.number(), z.string(), z.boolean()]).pipe(z.coerce.boolean())` instead of `z.boolean()` for boolean fields
|
|
167
|
+
- **`useTrim`**: When `true`, adds `.trim()` to string fields
|
|
168
|
+
- **`nullish`**: When `true`, uses `.nullish()` instead of `.nullable()` for nullable fields (except selectable schemas)
|
|
169
|
+
- **`requiredString`**: When `true`, adds `.min(1)` validation to required string fields
|
|
170
|
+
- **`version`**: Zod version (3 or 4) for compatibility
|
|
171
|
+
|
|
162
172
|
### Global Options
|
|
163
173
|
| Option | Description |
|
|
164
174
|
|--------|-------------|
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -396,7 +396,16 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
|
|
|
396
396
|
baseType = "number";
|
|
397
397
|
}
|
|
398
398
|
} else if (typeMappings.booleanTypes.includes(type)) {
|
|
399
|
-
|
|
399
|
+
if (isZodDestination) {
|
|
400
|
+
const useBooleanType = destination.useBooleanType;
|
|
401
|
+
if (useBooleanType) {
|
|
402
|
+
baseType = "z.union([z.number(), z.string(), z.boolean()]).pipe(z.coerce.boolean())";
|
|
403
|
+
} else {
|
|
404
|
+
baseType = "z.boolean()";
|
|
405
|
+
}
|
|
406
|
+
} else {
|
|
407
|
+
baseType = "boolean";
|
|
408
|
+
}
|
|
400
409
|
} else if (typeMappings.stringTypes.includes(type)) {
|
|
401
410
|
if (isZodDestination) {
|
|
402
411
|
const useTrim = destination.useTrim;
|
|
@@ -461,6 +470,17 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
|
|
|
461
470
|
}
|
|
462
471
|
}
|
|
463
472
|
|
|
473
|
+
function isAutoGeneratedDateTimeField(desc, schemaType) {
|
|
474
|
+
const { Type, Extra } = desc;
|
|
475
|
+
const type = schemaType === "prisma" ? Type : Type.toLowerCase();
|
|
476
|
+
const typeMappings = getTypeMappings(schemaType);
|
|
477
|
+
const isDateField = typeMappings.dateTypes.includes(type);
|
|
478
|
+
if (!isDateField) {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
const isGenerated = Extra.toLowerCase().includes("auto_increment") || Extra.toLowerCase().includes("default_generated");
|
|
482
|
+
return isGenerated;
|
|
483
|
+
}
|
|
464
484
|
function toSnakeCase(str) {
|
|
465
485
|
return str.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
|
|
466
486
|
}
|
|
@@ -699,6 +719,10 @@ function generateZodContent({
|
|
|
699
719
|
content += `export const updateable_${snakeTable} = z.object({
|
|
700
720
|
`;
|
|
701
721
|
for (const desc of describes) {
|
|
722
|
+
const isAutoGeneratedDatetime = isAutoGeneratedDateTimeField(desc, config.origin.type);
|
|
723
|
+
if (isAutoGeneratedDatetime) {
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
702
726
|
const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
|
|
703
727
|
const fieldType = getType("updateable", desc, config, destination);
|
|
704
728
|
content += ` ${fieldName}: ${fieldType},
|
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.1.0",
|
|
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",
|