Skip to content

Conversation

@kiwicopple
Copy link
Member

@kiwicopple kiwicopple commented Jan 31, 2026

Adds planning docs and documentation for two new type generators:

  • TypeScript Zod (/generators/typescript-zod) — Generates Zod runtime validation schemas from the database, producing Row, Insert, and Update schemas per table. Lets users validate data at runtime, not just at compile time.
  • JSON Schema (/generators/jsonschema) — Generates a JSON Schema (Draft 2020-12) document. Language-agnostic, can be used for validation in any language or as input to other code generators.

Also adds a docs/ folder with documentation for all 6 generators (TypeScript, Go, Swift, Python, and the two new ones). Each doc includes usage examples, type mappings, and query parameters.

What's in this PR

This PR is planning and documentation only — no implementation code yet.

File What it is
plan.md Implementation plan with architecture, type mappings, file changes, and implementation order
docs/typescript.md Docs for the existing TypeScript generator
docs/go.md Docs for the existing Go generator
docs/swift.md Docs for the existing Swift generator
docs/python.md Docs for the existing Python generator
docs/typescript-zod.md Docs for the new Zod generator (planned)
docs/jsonschema.md Docs for the new JSON Schema generator (planned)

Key design decisions

See plan.md for full details.

  • db_driver_type parameter — Both new generators accept direct (default) or postgrest to handle type differences between direct PG drivers and PostgREST (e.g., timestamps as Date vs strings).
  • {language}-{format} naming — The Zod generator is typescript-zod, not just zod, so generators are grouped by language. Extensible for future variants (python-pydantic, typescript-io-ts, etc).
  • Schema namespacing — Zod schemas are nested under per-schema namespace objects to avoid collisions when the same table name exists in multiple schemas.
  • No new dependencies — Zod output is plain TypeScript (users install zod themselves). JSON Schema is plain JSON.
  • Reuses GeneratorMetadata — Zero changes to the core introspection layer.

Users may connect directly to PostgreSQL (not through PostgREST), so
types like timestamp and int8 should map differently depending on the
driver. Both generators now support a db_driver_type query parameter
with postgrest (default) and direct modes.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
These are general-purpose generators not tied to PostgREST, so
direct driver types should be the default. Users going through
PostgREST can opt in with db_driver_type=postgrest.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
@coveralls
Copy link

coveralls commented Jan 31, 2026

Pull Request Test Coverage Report for Build 21581272491

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.907%

Totals Coverage Status
Change from base Build 21434042713: 0.0%
Covered Lines: 6258
Relevant Lines: 7343

💛 - Coveralls

@kiwicopple kiwicopple marked this pull request as draft January 31, 2026 11:45
claude and others added 8 commits January 31, 2026 16:16
…ions

Nest all Zod schemas under per-schema namespace objects (matching the
TypeScript generator's Database type structure) so that tables with
the same name in different schemas (e.g. public.users and auth.users)
don't produce conflicting exports.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Documentation for all 6 generators (TypeScript, Go, Swift, Python,
Zod, JSON Schema) covering endpoints, query parameters, CLI usage,
output structure, type mappings, and features.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Use {language}-{format} naming convention (e.g. typescript-zod) so
generators are grouped by language. This makes it extensible for
future variants like python-pydantic, typescript-io-ts, etc.

Renames: docs, route prefix, template file, CLI command, npm script.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
The types work with Supabase client libraries but are not tied to
them — they can be used with any TypeScript project.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Show practical examples: validating query results, insert data,
API request bodies, and deriving static types with z.infer.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Each doc now has a Usage section right after the intro showing
practical code examples: reading/validating rows, inserts, updates,
and language-specific patterns (Supabase client, FastAPI, Ajv, etc).

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Change import paths to use conventional project-relative paths
(e.g. database/types.ts, database/zod.ts, database/schema.json)
instead of vague names like db-schemas or database.types.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
@kiwicopple kiwicopple changed the title Add Zod and JSON Schema type generators RFC: Add Zod and JSON Schema type generators Jan 31, 2026
Specify target versions explicitly in docs and plan so it's clear
what the generators produce. Zod v4 is the current major version
(released July 2025). JSON Schema Draft 2020-12 is the current
stable specification.

https://claude.ai/code/session_01RqAeSB7evS4BdJVtKhHMdx
Comment on lines +106 to +141
## Output structure

The generator produces a single `Database` type with nested schemas:

```ts
export type Database = {
public: {
Tables: {
users: {
Row: {
id: number
name: string
email: string
created_at: string
}
Insert: {
id?: number // optional (has default)
name: string
email: string
created_at?: string
}
Update: {
id?: number
name?: string
email?: string
created_at?: string
}
Relationships: [...]
}
}
Views: { ... }
Functions: { ... }
Enums: { ... }
CompositeTypes: { ... }
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note

Might wanna do it another way instead. Split things down into interfaces first, then reference them into the Database type something like:

export interface PublicTablesUsersRow {
   ....
}

export interface PublicTablesUsersInsert {
   ...
}

export type Database = {
    public: {
         Tables: {
             Row: PublicTablesUsersRow,
             Insert: PublicTablesUsersInsert,
             ...
         }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants