6
6
7
7
Generate [ Zod] ( https://github.com/colinhacks/zod ) schemas from Typescript types generated by the Supabase CLI.
8
8
9
- ## Usage
9
+ ## Quick Start
10
10
11
11
``` sh
12
12
$ pnpm add --D supazod
@@ -16,23 +16,141 @@ $ pnpm supazod -i types.ts -o schemas.ts -t schemas.d.ts -s public,schema_a,sche
16
16
17
17
That's it! Check your ` schemas.ts ` file - you should have Zod schemas generated for all your tables, views, enums and functions.
18
18
19
+ ## Generated Output
20
+
21
+ Supazod generates clean, consistent schema names:
22
+
23
+ ``` typescript
24
+ // ✅ Clean naming (v2.0+)
25
+ export const publicUsersInsertSchema = z .object ({... });
26
+ export const publicUsersUpdateSchema = z .object ({... });
27
+ export const publicUserStatusSchema = z .union ([... ]);
28
+ export const publicGetStatusArgsSchema = z .object ({... });
29
+
30
+ // TypeScript types without "Schema" suffix
31
+ export type PublicUsersInsert = z .infer <typeof generated .publicUsersInsertSchema >;
32
+ export type PublicUserStatus = z .infer <typeof generated .publicUserStatusSchema >;
33
+ ```
34
+
35
+ ## Configuration
36
+
37
+ ### TypeScript Configuration (Recommended)
38
+
39
+ Create a ` supazod.config.ts ` file for type-safe configuration with IntelliSense:
40
+
41
+ ``` typescript
42
+ import { defineConfig } from ' supazod' ;
43
+
44
+ export default defineConfig ({
45
+ namingConfig: {
46
+ // TypeScript provides autocomplete for placeholders:
47
+ // {schema}, {table}, {operation}, {function}, {name}
48
+ tableOperationPattern: ' {schema}_{table}_{operation}' ,
49
+ enumPattern: ' {schema}_{name}_Enum' ,
50
+ functionArgsPattern: ' {schema}_{function}_Args' ,
51
+ functionReturnsPattern: ' {schema}_{function}_Returns' ,
52
+
53
+ // Capitalization and formatting
54
+ capitalizeSchema: true ,
55
+ capitalizeNames: true ,
56
+ separator: ' _' ,
57
+ }
58
+ });
59
+ ```
60
+
61
+ ### JSON Configuration
62
+
63
+ ``` json
64
+ {
65
+ "namingConfig" : {
66
+ "tableOperationPattern" : " {schema}_{table}_{operation}" ,
67
+ "enumPattern" : " {schema}_{name}_Enum" ,
68
+ "capitalizeSchema" : true ,
69
+ "capitalizeNames" : true ,
70
+ "separator" : " _"
71
+ }
72
+ }
73
+ ```
74
+
75
+ ** Supported config files:**
76
+ - ` supazod.config.ts ` (recommended)
77
+ - ` supazod.config.js `
78
+ - ` supazod.config.json `
79
+ - ` .supazodrc.ts `
80
+ - ` .supazodrc.js `
81
+ - ` .supazodrc.json `
82
+
19
83
## CLI Options
20
84
21
85
``` sh
22
86
supazod [options]
23
87
24
88
-i, --input < path> Input TypeScript file
25
89
-o, --output < path> Output Zod schemas file
26
- -t, --types-output < path> Output type definitions (optional, defaults to no file )
90
+ -t, --types-output < path> Output type definitions (optional)
27
91
-s, --schema < name> Schema to process (optional, defaults to all)
28
92
--verbose Enable debug logs
93
+
94
+ # Naming Configuration (overrides config file)
95
+ --table-operation-pattern < pattern> Pattern for table operations
96
+ --enum-pattern < pattern> Pattern for enums
97
+ --function-args-pattern < pattern> Pattern for function arguments
98
+ --function-returns-pattern < pattern> Pattern for function returns
99
+ --capitalize-schema < boolean> Capitalize schema names
100
+ --capitalize-names < boolean> Capitalize type names
101
+ --separator < string> Separator between name parts
29
102
```
30
103
104
+ ### Example with Custom Naming
105
+
106
+ ``` sh
107
+ # Generate with custom naming patterns
108
+ $ pnpm supazod -i types.ts -o schemas.ts \
109
+ --table-operation-pattern ' {schema}_{table}_{operation}' \
110
+ --enum-pattern ' {schema}_{name}_Enum' \
111
+ --separator ' _'
112
+ ```
113
+
114
+ ## Available Placeholders
115
+
116
+ - ` {schema} ` - Database schema name (e.g., "public", "auth")
117
+ - ` {table} ` - Table name (e.g., "users", "posts")
118
+ - ` {operation} ` - Operation type ("Insert", "Update", "Row")
119
+ - ` {function} ` - Function name (e.g., "get_status")
120
+ - ` {name} ` - Type name (e.g., "user_status" for enums)
121
+
31
122
## Features
32
123
33
124
- 🎯 ** Complete Coverage** : Full support for tables, views, enums, functions and composite types
34
125
- 🔧 ** Multi-Schema** : Process multiple database schemas with a single command
35
126
- 📦 ** Type Declarations** : Generate corresponding ` .d.ts ` files alongside Zod schemas
127
+ - ⚙️ ** Type-Safe Configuration** : TypeScript config with IntelliSense support
128
+ - 🏷️ ** Flexible Naming** : Customizable naming patterns with placeholders
129
+ - ✨ ** Clean Output** : Fixed schema naming (no more "SchemaSchema" duplication)
130
+
131
+ ## Programmatic API
132
+
133
+ ``` typescript
134
+ import { generateContent } from ' supazod' ;
135
+
136
+ const result = await generateContent ({
137
+ input: ' ./types.ts' ,
138
+ output: ' ./schema.ts' ,
139
+ schema: [' public' ],
140
+ namingConfig: {
141
+ tableOperationPattern: ' {schema}_{table}_{operation}' ,
142
+ enumPattern: ' {schema}_{name}_Enum' ,
143
+ }
144
+ });
145
+ ```
146
+
147
+ ## Migration from v1.x
148
+
149
+ If upgrading from v1.x, see [ MIGRATION.md] ( ./MIGRATION.md ) for detailed migration instructions. The main changes:
150
+
151
+ - ✅ Fixed duplicated "Schema" suffixes (` publicUsersInsertSchemaSchema ` → ` publicUsersInsertSchema ` )
152
+ - ✅ Clean TypeScript type names (removed "Schema" suffix from types)
153
+ - ✅ New type-safe configuration system
36
154
37
155
## Credits
38
156
0 commit comments