Skip to content

feat(postgrest-typegen): formatter hook, oxfmt default, concurrent introspection - #118

Merged
spydon merged 3 commits into
mainfrom
feat/postgrest-typegen-format-hook
Aug 31, 2026
Merged

feat(postgrest-typegen): formatter hook, oxfmt default, concurrent introspection#118
spydon merged 3 commits into
mainfrom
feat/postgrest-typegen-format-hook

Conversation

@spydon

@spydon spydon commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional format callback to GenerateTypescriptOptions for the TypeScript generator, and switches the default formatter itself from prettier to oxfmt.

This unblocks supabase/postgres-meta#1084, whose description flags that @supabase/postgrest-typegen formats inline with prettier and exposed no formatting hook yet, which that PR states should land here first. Tracked in Linear as SDK-1649.

The review comment on that PR (supabase/postgres-meta#1084 (comment)) measured prettier at roughly 73-92% of generateTypescript's time and made two asks against this package:

  1. "A formatter-choice option... worth raising against postgrest-typegen — it already uses oxfmt/oxlint on its own source, so the dependency is familiar there." Addressed by the format option.
  2. "~90% of type generation is prettier... oxfmt is roughly an order of magnitude faster on this kind of workload." Addressed by switching the default itself, not just making it overridable.

Neither of these fully eliminates main-thread blocking on its own; that review's own benchmark achieved its largest win (~1000ms -> ~21ms main-thread block) by additionally wrapping the entire generateTypescript() call in a worker, which is an architecture choice for the consumer (postgres-meta) to make, not something needed here.

Changes

  • introspect() now issues its ten introspection queries under Promise.all instead of awaiting them one at a time. The same review flagged that postgres-meta's CLI path (supabase gen types) went from parallel to sequential in the migration, adding one round trip per query on remote databases; this restores the old parallelism for every consumer. A pooled Queryable runs the queries in parallel, a single-connection one pipelines them.

  • GenerateTypescriptOptions.format?: (code: string) => Promise<string> — optional, defaults to a new oxfmt-backed formatter (semi: false, printWidth: 80 to match prettier's default and minimize output churn).

  • prettier dropped as a dependency; oxfmt moves from a devDependency to a runtime dependency.

  • The nightly parity job against real postgres-meta (still prettier-formatted) now canonicalizes postgres-meta's TypeScript output through this package's own oxfmt formatter before diffing, so it keeps catching real content drift without flagging the formatter swap itself every night.

  • test/parity/expected/typescript.txt and the inline snapshots in test/generation/typescript.test.ts regenerated for the new formatter's output. Verified the only remaining differences from the previous prettier-formatted goldens are formatter style choices (confirmed by reformatting the old prettier golden through the new oxfmt formatter and diffing against a fresh regeneration; the only residual difference is oxfmt adding parentheses around a conditional type in a couple of generic-default positions, which is semantically inert).

Test plan

  • bun run check-types
  • bun run format-and-lint
  • bun run knip
  • bun run build
  • bun run test (93 pass, including a regression test asserting a custom format callback is invoked and its output is used verbatim)

Add an optional `format` callback to GenerateTypescriptOptions, defaulting
to prettier.format so existing callers see no behavior change. Callers on
a latency-sensitive path, like postgres-meta's hosted generator route, can
substitute a worker-pool-backed formatter instead of blocking the event
loop on every call.
@spydon
spydon requested a review from a team as a code owner August 31, 2026 10:14
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 10fbe7cc-dad9-4dc7-8106-03598552d9c2


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.

@avallete avallete left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❤️

… to oxfmt

Replace prettier with oxfmt as the default formatter for generated
TypeScript output. Prettier spends 73-92% of generateTypescript's runtime
on large schemas; oxfmt is roughly an order of magnitude faster for this
kind of machine-generated output that nobody diffs by hand. printWidth is
pinned to 80 to match prettier's default and keep output churn to a
formatter-only, mostly cosmetic diff (oxfmt's default is 100).

The prettier dependency is dropped; oxfmt moves from a devDependency (used
only for this package's own source) to a runtime dependency. The `format`
option's signature drops the now formatter-specific `prettier.Options`
parameter in favor of a plain `(code: string) => Promise<string>`; since
`format` itself is new and unreleased in this same PR, this is not a
breaking change to any shipped version.

The nightly parity job against real postgres-meta (which still formats
with prettier) now canonicalizes postgres-meta's output through this
package's own oxfmt formatter before diffing, so the comparison reflects
generator content, not which formatting engine produced it.
@spydon
spydon requested a review from a team as a code owner August 31, 2026 10:24
@spydon spydon changed the title feat(postgrest-typegen): allow injecting a custom TypeScript formatter feat(postgrest-typegen): formatter hook, oxfmt default, concurrent introspection Aug 31, 2026
@spydon
spydon merged commit fa2286c into main Aug 31, 2026
7 checks passed
@spydon
spydon deleted the feat/postgrest-typegen-format-hook branch August 31, 2026 11:45
@supabase-releaser supabase-releaser Bot mentioned this pull request Aug 31, 2026
spydon added a commit that referenced this pull request Aug 31, 2026
…mits (#120)

## Summary

Removes the `release-as` entries from `release-please-config.json` for
both packages.

`release-as` pins every release PR to that exact version. The pins were
used to force the initial versions when the per-package release-please
setup landed (#111/#112), but both packages have since shipped those
versions (`capability-matrix` 1.6.0, `postgrest-typegen` 0.1.0), so the
pins now block any further version bump.

Concretely: #118 landed as a `feat` on `postgrest-typegen`, which with
`bump-minor-pre-major: true` should produce 0.2.0, but the release PR
#119 proposed a no-op `v0.1.0...v0.1.0` release with only a changelog
change because the config forced 0.1.0 again. `capability-matrix` would
hit the same wall on its next release.

Once this merges, release-please will refresh #119 to a proper 0.2.0
(changelog, `package.json`, and manifest bump).

## Test plan

- [x] `release-please-config.json` still validates against its $schema
(structure unchanged, only the two `release-as` keys removed)
- [ ] After merge: release-please refreshes #119 to `postgrest-typegen:
0.2.0`
@supabase-releaser supabase-releaser Bot mentioned this pull request Aug 31, 2026
spydon pushed a commit that referenced this pull request Aug 31, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>postgrest-typegen: 0.2.0</summary>

##
[0.2.0](postgrest-typegen-v0.1.0...postgrest-typegen-v0.2.0)
(2026-08-31)


### Features

* **postgrest-typegen:** formatter hook, oxfmt default, concurrent
introspection ([#118](#118))
([fa2286c](fa2286c))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
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.

3 participants