mutano 3.0.24 → 3.1.1

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 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
@@ -13,6 +13,7 @@ interface Desc {
13
13
  type Destination = {
14
14
  type: 'zod';
15
15
  useDateType?: boolean;
16
+ useBooleanType?: boolean;
16
17
  useTrim?: boolean;
17
18
  nullish?: boolean;
18
19
  requiredString?: boolean;
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
- baseType = isZodDestination ? "z.boolean()" : "boolean";
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
  }
@@ -690,6 +710,10 @@ function generateZodContent({
690
710
  content += `export const insertable_${snakeTable} = z.object({
691
711
  `;
692
712
  for (const desc of describes) {
713
+ const isAutoGeneratedDatetime = isAutoGeneratedDateTimeField(desc, config.origin.type);
714
+ if (isAutoGeneratedDatetime) {
715
+ continue;
716
+ }
693
717
  const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
694
718
  const fieldType = getType("insertable", desc, config, destination);
695
719
  content += ` ${fieldName}: ${fieldType},
@@ -699,6 +723,10 @@ function generateZodContent({
699
723
  content += `export const updateable_${snakeTable} = z.object({
700
724
  `;
701
725
  for (const desc of describes) {
726
+ const isAutoGeneratedDatetime = isAutoGeneratedDateTimeField(desc, config.origin.type);
727
+ if (isAutoGeneratedDatetime) {
728
+ continue;
729
+ }
702
730
  const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
703
731
  const fieldType = getType("updateable", desc, config, destination);
704
732
  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.24",
4
+ "version": "3.1.1",
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",