Skip to content

Type the tables in the subscribe callback - #6358

Open
cloutiertyler wants to merge 6 commits into
jlarabie/view-args-lite-ts-builderfrom
tyler/typed-subscribe-callback
Open

cloutiertyler wants to merge 6 commits into
jlarabie/view-args-lite-ts-builderfrom
tyler/typed-subscribe-callback

Conversation

@cloutiertyler

@cloutiertyler cloutiertyler commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description of Changes

Stacked on #6336, this PR types the subscribe(tables => ...) callback, which intersecting the module with UntypedSchemaDef had erased to untyped table refs since #5486 (hence the cast #6336's description recommends for view calls), keys its submodule tables by accessor name as #6089 did for conn.db, and renames the sourceName of table defs and table refs to tableName, since it holds the name SQL uses while the raw def's sourceName is the accessor name.

API and ABI breaking changes

Yes, but only for submodule tables inside the callback, which were keyed by the rest of their canonical name (tables.lib.people_by) and are now keyed by accessor name (tables.lib.peopleBy) like conn.db; that only differs when the two names differ, and code using the old key now fails to compile rather than silently working. Otherwise, only code that can't work today breaks: a callback that names a missing table or column, or passes a mistyped value, now fails to compile instead of failing when it subscribes. The rename doesn't break anything, because sourceName stays as a deprecated alias of tableName and generated bindings never read it.

Rollback safety impact

n/a

Expected complexity level and risk

1

Testing

  • New type test src/sdk/subscription_builder.test-d.ts, which pnpm build typechecks, fails on the old code and passes with the fix
  • Updated the makeFromBuilder tests in tests/query.test.ts for accessor-name keys
  • New test in tests/query.test.ts that sourceName still works as an alias, which fails without the alias
  • pnpm build, pnpm test:unit (except the two wasm test-utils files, which need the Rust build), eslint, and prettier
  • CI

`NamespacedQueryBuilder<RemoteModule & UntypedSchemaDef>` merged
`Record<string, UntypedTableDef>` into the module's tables, so every
entry in the callback was an untyped table ref: unknown tables and
columns compiled, and a view with args wasn't callable without a cast.

The callback now takes `NamespacedQueryBuilder<RemoteModule>`. A
submodule's table, which generated bindings give a dotted accessor
name, stays reachable under its namespace as `makeFromBuilder` puts it
there, untyped as before, since its key is the rest of its
`sourceName`, which the types don't record.

`subscription_builder.test-d.ts` checks this in `pnpm build`.
`makeFromBuilder` grouped a submodule's table by its dotted
`sourceName`, so `lib.peopleBy` was `tables.lib.people_by`, unlike
`conn.db`, reducers and procedures, which #6089 nested by accessor
name. It now nests with `accessorSlot` and is typed with
`NestAccessors`, as `conn.db` is, so namespaced tables are typed too.

The `namespaces` branch of `NamespacedQueryBuilder` is gone: client
bindings never declare `namespaces`, and `makeFromBuilder` never read
it.

This branch has not been deployed

No deployments
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