Skip to content

feat: consume @supabase/postgrest-typegen for type generation#1084

Draft
avallete wants to merge 7 commits into
masterfrom
claude/funny-tesla-wofjdj
Draft

feat: consume @supabase/postgrest-typegen for type generation#1084
avallete wants to merge 7 commits into
masterfrom
claude/funny-tesla-wofjdj

Conversation

@avallete

Copy link
Copy Markdown
Member

Summary

Replaces postgres-meta's embedded type-generation templates/SQL with the extracted @supabase/postgrest-typegen package (the same engine, now living in pg-toolbelt). src/lib/generators.ts becomes a thin adapter that wraps pgMeta.query into the package's structural Queryable and calls introspect(), preserving the historical getGeneratorMetadata signature and { data, error } contract. The four generator routes and the CLI typegen path are unchanged in behavior — output stays byte-identical (the package has a parity test pinning this).

Depends on

⚠️ Draft — do not merge yet

This is a validation PR to prove postgres-meta builds, type-checks, and tests green against the extracted package. Before it can merge:

  1. pg-toolbelt feat: change pg_authid 2 pg_roles #302 lands and @supabase/postgrest-typegen is published to npm.
  2. Repin package.json from the pkg.pr.new URL to the published version and regenerate package-lock.json.

Until then, kept as a draft so it can't be merged with a preview-build dependency.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B53a2ayu9d16u821FQ5Qqz


Generated by Claude Code

claude and others added 7 commits June 19, 2026 10:25
Integrate the extracted @supabase/postgrest-typegen package as the single
source of truth for type generation, replacing the embedded templates.

- src/lib/generators.ts: rewrite getGeneratorMetadata as a ~30-line adapter
  over the package's introspect(). It wraps pgMeta.query into the package's
  structural Queryable (throws on {error}), preserves the
  Promise<PostgresMetaResult<GeneratorMetadata>> contract, surfaces the first
  query error, and still ends the pool. Re-exports GeneratorMetadata from the
  package.
- src/server/server.ts: getTypeOutput now calls getGeneratorMetadata +
  generateTypescript/Go/Python/Swift, threading GENERATE_TYPES_DEFAULT_SCHEMA,
  POSTGREST_VERSION, detect-1:1, and Swift access-control env values. Behavior
  freeze: the CLI path still only supports included schemas.
- src/server/routes/generators/*.ts: swap `apply` template imports for the
  package's generateX; query params, headers, and error shapes unchanged.
- Delete src/server/templates/*.ts and test/server/templates/go.test.ts;
  re-point test/types.test.ts's pgTypeToTsType import and constants.ts's
  AccessControl import to the package; drop the now-unused VALID_* constants.
- Keep PostgresMetaRelationships.ts and src/lib/sql/*.sql.ts (they back the
  REST endpoints) — accepted temporary duplication.

`npm run check` passes. Full-suite byte-parity validation is Phase 2.3
(PGMETA-114). The dependency is pinned to 1.0.0-alpha.1; local validation
installs it from Verdaccio via an uncommitted scoped .npmrc, and the lockfile
is finalized when the package is published to npm (Phase 3).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B53a2ayu9d16u821FQ5Qqz
The package isn't published to npm yet; pin the dependency to the
pkg.pr.new preview build for pg-toolbelt PR #302 so CI can install it.
The lockfile must be regenerated (`npm install`) in an environment with
network access to pkg.pr.new — the remote sandbox's egress allowlist
blocks that host.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B53a2ayu9d16u821FQ5Qqz
The Go/Python/Swift generators emit objects in GeneratorMetadata order, so
output depended on the order introspection returned rows (environment-dependent
heap order). Apply the package's new sortGeneratorMetadata pass in the
getGeneratorMetadata adapter so all four generators receive canonically-ordered
metadata.

Regenerate the typegen go/python snapshots accordingly: only ordering changes
(the `a_view` view moves to its canonical oid position); struct/class contents
are byte-identical. TypeScript and Swift sort internally and are unaffected.

Requires @supabase/postgrest-typegen with sortGeneratorMetadata
(supabase/pg-toolbelt#302).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B53a2ayu9d16u821FQ5Qqz
Follow-up to the sortGeneratorMetadata semantic-key change
(supabase/pg-toolbelt#302): the canonical order is now schema+name based, so
the Go/Python typegen snapshots are regenerated to alphabetical order. Pure
reorder — struct/class contents are byte-identical. TypeScript/Swift sort
internally and are unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B53a2ayu9d16u821FQ5Qqz
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.

2 participants