Skip to content

feat: add supabase_typegen package generating typed table definitions#1635

Draft
spydon wants to merge 8 commits into
feat/typed-table-accessfrom
feat/supabase-gen
Draft

feat: add supabase_typegen package generating typed table definitions#1635
spydon wants to merge 8 commits into
feat/typed-table-accessfrom
feat/supabase-gen

Conversation

@spydon

@spydon spydon commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feature (draft, layer 2 of the typed table access work, stacked on #1634). Adds a new supabase_typegen package: a standalone code generator that turns a database schema into the typed table definitions introduced in #1634, so users get the fully typed surface without writing any of it by hand.

Linear: SDK-1362

What is the new behavior?

dart run supabase_typegen --url https://your-project.supabase.co --key $SUPABASE_ANON_KEY

reads the OpenAPI (Swagger 2.0) description that PostgREST serves at the API root and emits one Dart file containing, per table:

  • a zero-cost row extension type over the decoded JSON map with typed getters (DateTime parsing, double/num coercion, List casts, Postgres enum mapping),
  • Insert and Update value extension types that implement Map<String, dynamic>, with required parameters derived from NOT NULL-without-default columns and null-aware omission for everything else; explicit SQL NULL writes go through generated set…ToNull copy methods that only exist for nullable columns,
  • a PostgrestTable definition plus TableColumn tokens for compile-time checked filters,
  • Dart enums for Postgres enums with wire-name mapping (toString returns the wire name so enum values work directly in filters).

See packages/supabase_typegen/test/goldens/supabase_schema.dart for what the output looks like for the fixture schema.

Design choices worth reviewing:

  • Introspection source: the PostgREST OpenAPI description. It needs nothing but a URL and an API key, which makes the tool trivially usable against local and hosted projects (the same approach supadart proved viable). The parser is a pure function over the JSON document, so a higher-fidelity pg-meta or direct Postgres backend can be added behind the same SchemaDescription model later.
  • Nullability heuristic: OpenAPI cannot distinguish nullable columns from NOT NULL columns with a database default, so getters are non-nullable only for required columns and primary keys; everything else is conservatively nullable. Documented in the README as the main reason to add a pg-meta backend eventually.
  • Naming: books emits BooksRow/BooksInsert/BooksUpdate plus a Books namespace class (no English singularization, so names stay predictable). Identifiers are sanitized against Dart reserved words and Map member names with a $ suffix, and collisions are deduplicated.
  • Lint-clean output: the emitted code (checked in as a golden) passes supabase_lints and DCM with zero issues, including the strict extension type rules.

Deliberately deferred: foreign key relationship getters (the fk targets are already parsed into the model) and typed rpc functions.

Additional context

  • The package is excluded from the SDK compliance scan via .sdk-parse-ignore since it is a development-time tool, not SDK client surface; the symbol, drift and schema checks pass locally against the base branch.
  • supabase_typegen is added to the CI dart test matrix; tests are fully mocked/fixture-based (introspection unit tests, a whitespace-insensitive golden comparison with a tool/regenerate_goldens.dart refresh script, and behavior tests that run the generated golden code against a mock HTTP client to verify wire formats end to end).
  • publish_to: none until the API settles.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b94bc9fd-c625-40c6-90ea-d958883d4e50

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/supabase-gen

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

spydon added a commit that referenced this pull request Jul 23, 2026
## What kind of change does this PR introduce?

Feature. Adds an empty skeleton for a new `supabase_typegen` package so
we can publish it to pub.dev and reserve the name.

The full generator implementation lands separately in #1635; this PR
intentionally contains only the minimal publishable placeholder.

## What is the new behavior?

A new `packages/supabase_typegen` package containing:

- a publishable `pubspec.yaml` (version `0.1.0`, no `publish_to: none`)
so the melos release pipeline picks it up,
- a placeholder library, `README`, `CHANGELOG` and `LICENSE`,
- `supabase_lints` wired in via `analysis_options.yaml` (analyzes
clean).

It is wired into:

- the root workspace in `pubspec.yaml`,
- the Dart CI test matrix in `test.yml`,
- the pana release matrix in `release-pana.yml`,
- the SDK compliance parse ignore (`.sdk-parse-ignore`), since it is a
development-time tool rather than SDK client surface.

## Additional context

The README and CHANGELOG flag `0.1.0` as a name-reserving placeholder;
the generator implementation will replace it in a later release.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a new `supabase_typegen` package placeholder (v0.1.0) to
generate typed Dart table definitions from Supabase schemas.
* **Documentation**
* Added initial README and changelog entries documenting current
placeholder status and reserved pub.dev name.
* **CI / Chores**
* Updated release and test workflows to run checks for
`supabase_typegen` when relevant, including coverage carryforward.
* Excluded `supabase_typegen` from SDK public API scanning
(development-time generator).
* **Legal**
  * Added the MIT license for the new package.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@spydon
spydon force-pushed the feat/typed-table-access branch from 17d12c1 to 6a64143 Compare July 23, 2026 11:48
@spydon
spydon force-pushed the feat/supabase-gen branch from 07cdee7 to c795ded Compare July 23, 2026 11:53
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.

1 participant