mutano 2.6.4 → 2.6.6

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
@@ -505,6 +505,7 @@ export type UserUpdate = Updateable<UserTable>;
505
505
  | destinations[].useDateType | (Zod only) Use a specialized Zod type for date-like fields instead of string |
506
506
  | destinations[].useTrim | (Zod only) Use `z.string().trim()` instead of `z.string()` |
507
507
  | destinations[].nullish | (Zod only) Use `nullish()` instead of `nullable()` for nullable fields. In updateable schemas, fields that were already nullable will become nullish |
508
+ | destinations[].version | (Zod only) Zod version to use. Defaults to 3. Set to 4 to use Zod v4 |
508
509
  | destinations[].requiredString | (Zod only) Add `min(1)` for non-nullable string fields |
509
510
  | destinations[].enumType | (TypeScript only) How to represent enum types: "union" (default) or "enum" |
510
511
  | destinations[].modelType | (TypeScript only) How to represent models: "interface" (default) or "type" |
package/dist/main.d.ts CHANGED
@@ -10,11 +10,11 @@ export interface GenerateContentParams {
10
10
  destination: Destination;
11
11
  isCamelCase: boolean;
12
12
  enumDeclarations: Record<string, string[]>;
13
- defaultZodHeader: string;
13
+ defaultZodHeader: (version: 3 | 4) => string;
14
14
  }
15
15
  export declare function generateContent({ table, describes, config, destination, isCamelCase, enumDeclarations, defaultZodHeader, }: GenerateContentParams): string;
16
16
  export declare const defaultKyselyHeader = "import { ColumnType, Selectable, Insertable, Updateable } from 'kysely';\n\n";
17
- export declare const defaultZodHeader = "import { z } from 'zod';\n\n";
17
+ export declare const defaultZodHeader: (version: 3 | 4) => string;
18
18
  export declare function generate(config: Config): Promise<Record<string, string>>;
19
19
  type MySQLValidTypes = 'date' | 'datetime' | 'timestamp' | 'time' | 'year' | 'char' | 'varchar' | 'tinytext' | 'text' | 'mediumtext' | 'longtext' | 'json' | 'decimal' | 'tinyint' | 'smallint' | 'mediumint' | 'int' | 'bigint' | 'float' | 'double' | 'enum';
20
20
  type PostgresValidTypes = 'date' | 'timestamp' | 'timestamptz' | 'timestamp without time zone' | 'timestamp with time zone' | 'time' | 'timetz' | 'interval' | 'character' | 'varchar' | 'character varying' | 'text' | 'json' | 'jsonb' | 'uuid' | 'name' | 'citext' | 'numeric' | 'decimal' | 'smallint' | 'integer' | 'bigint' | 'real' | 'double precision' | 'serial' | 'bigserial' | 'boolean' | 'bool' | 'USER-DEFINED';
@@ -31,6 +31,7 @@ export interface Desc {
31
31
  }
32
32
  export type Destination = {
33
33
  type: 'zod';
34
+ version?: 3 | 4;
34
35
  header?: string;
35
36
  useDateType?: boolean;
36
37
  useTrim?: boolean;
package/dist/main.js CHANGED
@@ -508,7 +508,7 @@ export type ${camelCase(table, { pascalCase: true })} = {`;
508
508
  const header = destination.header;
509
509
  content = header ? `${header}
510
510
 
511
- ` : defaultZodHeader2;
511
+ ` : defaultZodHeader2(destination.version || 3);
512
512
  content += `export const ${table} = z.object({`;
513
513
  for (const desc of describes) {
514
514
  const field = isCamelCase ? camelCase(desc.Field) : desc.Field;
@@ -574,7 +574,9 @@ export type Selectable${camelCase(`${table}Type`, {
574
574
  return content;
575
575
  }
576
576
  const defaultKyselyHeader = "import { ColumnType, Selectable, Insertable, Updateable } from 'kysely';\n\n";
577
- const defaultZodHeader = "import { z } from 'zod';\n\n";
577
+ const defaultZodHeader = (version) => `import { z } from 'zod${version === 3 ? "" : "/v4"}';
578
+
579
+ `;
578
580
  async function generate(config) {
579
581
  let tables = [];
580
582
  let prismaTables = [];
@@ -667,7 +669,7 @@ async function generate(config) {
667
669
  });
668
670
  }
669
671
  let describes = [];
670
- for (let table of tables) {
672
+ for (let table of tables.sort((a, b) => a.localeCompare(b))) {
671
673
  if (config.origin.type === "mysql" && db) {
672
674
  const d = await db.raw(`SHOW FULL COLUMNS FROM ${table}`);
673
675
  describes = d[0];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "2.6.4",
4
+ "version": "2.6.6",
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",