Skip to content

Commit c95c2c1

Browse files
committed
docs: update README for quick start, generated output, and configuration details
- Changed "Usage" section to "Quick Start" for clarity. - Added "Generated Output" section showcasing clean schema naming. - Included detailed "Configuration" instructions for TypeScript and JSON formats. - Added CLI options for naming configuration and examples for custom naming patterns.
1 parent 04e7829 commit c95c2c1

File tree

1 file changed

+120
-2
lines changed

1 file changed

+120
-2
lines changed

README.md

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Generate [Zod](https://github.com/colinhacks/zod) schemas from Typescript types generated by the Supabase CLI.
88

9-
## Usage
9+
## Quick Start
1010

1111
```sh
1212
$ 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
1616

1717
That's it! Check your `schemas.ts` file - you should have Zod schemas generated for all your tables, views, enums and functions.
1818

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+
1983
## CLI Options
2084

2185
```sh
2286
supazod [options]
2387

2488
-i, --input <path> Input TypeScript file
2589
-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)
2791
-s, --schema <name> Schema to process (optional, defaults to all)
2892
--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
29102
```
30103

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+
31122
## Features
32123

33124
- 🎯 **Complete Coverage**: Full support for tables, views, enums, functions and composite types
34125
- 🔧 **Multi-Schema**: Process multiple database schemas with a single command
35126
- 📦 **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
36154

37155
## Credits
38156

0 commit comments

Comments
 (0)