feat: consume @supabase/postgrest-typegen for type generation#1084
Draft
avallete wants to merge 7 commits into
Draft
feat: consume @supabase/postgrest-typegen for type generation#1084avallete wants to merge 7 commits into
avallete wants to merge 7 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces postgres-meta's embedded type-generation templates/SQL with the extracted
@supabase/postgrest-typegenpackage (the same engine, now living in pg-toolbelt).src/lib/generators.tsbecomes a thin adapter that wrapspgMeta.queryinto the package's structuralQueryableand callsintrospect(), preserving the historicalgetGeneratorMetadatasignature 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
pkg.pr.newpreview build so CI can install and validate it:This is a validation PR to prove postgres-meta builds, type-checks, and tests green against the extracted package. Before it can merge:
@supabase/postgrest-typegenis published to npm.package.jsonfrom thepkg.pr.newURL to the published version and regeneratepackage-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