Skip to content

fix(postgrest-typegen): compile under noUncheckedIndexedAccess - #217

Merged
spydon merged 1 commit into
mainfrom
lukasklingsbo/sdk-1963-fixpostgrest-typegen-compile-under-nouncheckedindexedaccess
Sep 25, 2026
Merged

spydon merged 1 commit into
mainfrom
lukasklingsbo/sdk-1963-fixpostgrest-typegen-compile-under-nouncheckedindexedaccess

Conversation

@spydon

@spydon spydon commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Why

The Supabase CLI type-checks its dependencies from source: apps/cli/tsconfig.json extends @tsconfig/bun and sets customConditions: ["bun"], so tsc follows this package's bun exports condition to src/*.ts instead of dist/*.d.ts. Those files failed the CLI's noUncheckedIndexedAccess flag with 85 errors (TS2532, TS18048, TS2345, TS2322, plus any cascades), which is why the CLI still declares @supabase/postgrest-typegen directly and pins it to dist/index.d.ts through tsconfig.types.json. Every postgrest-typegen release therefore meant bumping two CLI dependencies in lockstep, which the @supabase/typegen registry was meant to remove.

Fixes SDK-1963.

What

  • Enable noUncheckedIndexedAccess in tsconfig.json and tsconfig.build.json.
  • Fix every flagged site in src/generation/{typescript,python,go,swift}.ts without changing output:
    • array[0] behind a length === 1 or length > 0 check becomes a checked local (soleInArg, conflictingFn, enumType).
    • key in record followed by record[key].push(...) becomes record[key]?.push(...).
    • acc[key] ??= []; acc[key].push(x) becomes (acc[key] ??= []).push(x).
    • for (const key in record) record[key].sort(...) iterates Object.values(record) instead.
    • Lookups that must succeed by construction (columnsByTableId[table.id], introspectionBySchema[schema.name], Python's this.schemas[name]) go through small helpers that throw a descriptive error instead of ! assertions. Previously a miss would have been a TypeError on undefined.
    • word[0].toUpperCase() inside if (word) becomes word.charAt(0).
    • The one pre-existing inArgs[0]! in isComputedFieldOf is replaced by the same checked-local pattern.
  • Add tsconfig.consumer.json, which extends @tsconfig/bun with customConditions: ["bun"] and includes src, wired up as bun run check-types:consumer and run in postgrest-typegen-validate.yml. This mirrors the CLI's compiler options so a regression fails here first.
  • Add @tsconfig/bun as a devDependency and document the new command in the package CLAUDE.md.

Verification

  • bun run check-types, bun run check-types:consumer, bun run format-and-lint, bun run knip, bun run build all pass.
  • bun run test: 140 tests pass, 37 inline snapshots unchanged, test/parity/expected/* unchanged. Output is byte-identical.
  • The two test files touched (test/sort.test.ts, test/validation/validate.test.ts) only adapt to the flag; no assertions changed.

Follow-ups

  • packages/typegen should get the same consumer check, but it pins the published @supabase/[email protected], whose src/ still fails under these flags. Adding it now would be red, so it belongs in the pull request that bumps the pin to the release cut from this change.
  • CLI (follow-up to feat(cli): drive gen types languages from the @supabase/typegen registry (SDK-1956) cli#6822 once that release ships): drop the direct @supabase/postgrest-typegen devDependency, its minimumReleaseAgeExclude entry, the paths pin in tsconfig.types.json, the knip.jsonc ignoreDependencies entry, and the version-guard test.

The Supabase CLI type-checks its dependencies from source: its tsconfig
extends @tsconfig/bun and sets customConditions: ["bun"], so tsc follows
this package's bun exports condition to src/*.ts. Those files failed the
CLI's noUncheckedIndexedAccess flag with 85 errors, which forced the CLI
to keep a direct dependency on @supabase/postgrest-typegen pinned to
dist/index.d.ts instead of depending on @supabase/typegen alone.

Enable noUncheckedIndexedAccess in this package and fix every site it
flags in the four generators, without changing output: indexed lookups
now go through optional chaining, a checked local, or a helper that
throws when an entry that must exist by construction is missing.
Inline snapshots and the parity goldens are unchanged.

Add tsconfig.consumer.json, which extends @tsconfig/bun with
customConditions: ["bun"], and run it as check-types:consumer in CI so
a future change cannot reintroduce an unchecked indexed access.

Refs SDK-1963
@spydon
spydon requested review from a team as code owners September 25, 2026 09:39
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: bfbc8773-4a8b-41fc-915b-f23b23952fc8

📥 Commits

Reviewing files that changed from the base of the PR and between de4806e and d239ff7.

⛔ Files ignored due to path filters (1)
  • packages/postgrest-typegen/bun.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • .github/workflows/postgrest-typegen-validate.yml
  • packages/postgrest-typegen/CLAUDE.md
  • packages/postgrest-typegen/package.json
  • packages/postgrest-typegen/src/generation/go.ts
  • packages/postgrest-typegen/src/generation/python.ts
  • packages/postgrest-typegen/src/generation/swift.ts
  • packages/postgrest-typegen/src/generation/typescript.ts
  • packages/postgrest-typegen/test/sort.test.ts
  • packages/postgrest-typegen/test/validation/validate.test.ts
  • packages/postgrest-typegen/tsconfig.build.json
  • packages/postgrest-typegen/tsconfig.consumer.json
  • packages/postgrest-typegen/tsconfig.json

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Type generation now reports clearer errors when required schema or relation metadata is missing, rather than continuing with incomplete information.
    • Improved handling of column grouping and type-name formatting across generated languages.
  • Quality Improvements
    • Added stricter checks for package types, including validation against the configuration used by consumers. This helps catch compatibility issues before release.

Walkthrough

The package enables noUncheckedIndexedAccess in its TypeScript configurations and adds a consumer-mode type-check command to the validation workflow. Generator code updates indexed access, grouping, and schema and relation lookups. Some missing metadata lookups now throw explicit errors.

Priority: ➖ Normal

Change: Refactor

Merge Risk: ⚪ Minimal · up to d239f

The stricter type checks and generator changes have no established merge-blocking issue; proceed with normal validation.


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
spydon merged commit a8a4927 into main Sep 25, 2026
4 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-1963-fixpostgrest-typegen-compile-under-nouncheckedindexedaccess branch September 25, 2026 10:58
spydon pushed a commit that referenced this pull request Sep 25, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.2.5](postgrest-typegen/v0.2.4...postgrest-typegen/v0.2.5)
(2026-09-25)


### Bug Fixes

* **postgrest-typegen:** compile under noUncheckedIndexedAccess
([#217](#217))
([a8a4927](a8a4927))

---
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>
spydon added a commit that referenced this pull request Sep 25, 2026
## Why

postgrest-typegen 0.2.5 (#217, released in #220) is the first version
whose `src/` compiles under `noUncheckedIndexedAccess`. The Supabase CLI
type-checks its dependencies from source through the `bun` exports
condition, so with this pin the CLI can depend on `@supabase/typegen`
alone and drop its direct, `dist`-pinned `@supabase/postgrest-typegen`
dependency.

Second part of [SDK-1963](https://linear.app/supabase/issue/SDK-1963);
the first part was #217.

## What

- Pin `@supabase/postgrest-typegen` to `0.2.5` and update `bun.lock`.
- Add the consumer type-check that #217 deliberately left out of this
package because it could not pass against 0.2.4:
`tsconfig.consumer.json` extends `@tsconfig/bun` with `customConditions:
["bun"]` and includes `src`, wired up as `bun run check-types:consumer`
and run in `typegen-validate.yml`. Because it resolves
`@supabase/postgrest-typegen` to the pinned package's `src/`, it fails
on a future pin bump whose source breaks under the CLI's compiler
options.
- Add `@tsconfig/bun` as a devDependency and document the command in
`CLAUDE.md` and `README.md`.

## Verification

- `bun run check-types`, `bun run check-types:consumer`, `bun run
format-and-lint`, `bun run knip`, `bun run build` pass.
- `bun run test`: 47 tests pass.
- Against the previous pin (0.2.4) the consumer check fails with 85
errors in
`node_modules/@supabase/postgrest-typegen/src/generation/*.ts`, so the
check is exercising the transitive source as intended.

## Follow-up

Once the typegen release cut from this PR is on npm, the CLI can bump
`@supabase/typegen` and remove the direct `@supabase/postgrest-typegen`
devDependency, its `minimumReleaseAgeExclude` entry, the `paths` pin in
`apps/cli/tsconfig.types.json`, the `knip.jsonc` `ignoreDependencies`
entry, and the version-guard test in `types.generator.unit.test.ts`
(follow-up to supabase/cli#6822).
spydon added a commit that referenced this pull request Sep 25, 2026
…en command comments (#223)

Documentation-only follow-up to #217 and #222. No code, workflow, or
configuration changes.

## What changed

- Root `CLAUDE.md`: the release notes for `release-typegen.yml` and
`release-postgrest-typegen.yml` now spell out what on-demand means.
release-please runs only on a manual `workflow_dispatch`, or on a push
that changes the package's manifest file, which happens only when a
release PR merges. Merging ordinary `fix:` or `feat:` commits into
`packages/typegen` or `packages/postgrest-typegen` opens no release PR
until someone dispatches the workflow.
- `packages/postgrest-typegen/CLAUDE.md`: re-align the comment column in
the Commands block. The `check-types:consumer` line added in #217 is
longer than the others, so every comment now starts at the same column
after it.

## Why

After #222 merged, no typegen release workflow run fired and no release
PR appeared. That was expected behavior from the manifest path filter,
but it was not obvious from the docs, so this records it. The typegen
release carrying the postgrest-typegen 0.2.5 pin is therefore waiting on
a manual dispatch.

## Notes for reviewers

This PR originally also passed `skip-github-pull-request` on push runs
of `release-typegen.yml`. That change was dropped because the existing
path filter already gives the described behavior, and it kept the two
release workflows identical apart from the package name.
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