Skip to content

Commit 5836c26

Browse files
fix: fix useSpacetimeDBQuery returns untyped rows for TanStack Start (#4488)
# Description of Changes - Fix useSpacetimeDBQuery returns untyped rows for TanStack Start Closes #4441 <!-- Please describe your change, mention any related tickets, and so on here. --> # API and ABI breaking changes <!-- If this is an API or ABI breaking change, please apply the corresponding GitHub label. --> # Expected complexity level and risk <!-- How complicated do you think these changes are? Grade on a scale from 1 to 5, where 1 is a trivial change, and 5 is a deep-reaching and complex change. This complexity rating applies not only to the complexity apparent in the diff, but also to its interactions with existing and future code. If you answered more than a 2, explain what is complex about the PR, and what other components it interacts with in potentially concerning ways. --> # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [ ] <!-- maybe a test you want to do --> - [ ] <!-- maybe a test you want a reviewer to do, so they can check it off when they're satisfied. -->
1 parent 7470eb2 commit 5836c26

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

crates/bindings-typescript/src/tanstack/SpacetimeDBQueryClient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import type {
44
QueryFunction,
55
} from '@tanstack/react-query';
66
import {
7+
type Query,
8+
toSql,
79
type BooleanExpr,
810
evaluateBooleanExpr,
911
getQueryAccessorName,
1012
getQueryWhereClause,
1113
} from '../lib/query';
1214

13-
type QueryInput = { toSql(): string } & Record<string, any>;
15+
type QueryInput = Query<any>;
1416

1517
const queryRegistry = new Map<
1618
string,
@@ -51,7 +53,7 @@ export function spacetimeDBQuery(
5153
const query = queryOrSkip;
5254
const accessorName = getQueryAccessorName(query);
5355
const whereExpr = getQueryWhereClause(query);
54-
const querySql = query.toSql();
56+
const querySql = toSql(query);
5557

5658
queryRegistry.set(querySql, { accessorName, whereExpr });
5759

crates/bindings-typescript/src/tanstack/hooks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
UseSuspenseQueryResult,
77
} from '@tanstack/react-query';
88
import type { UntypedTableDef, RowType } from '../lib/table';
9+
import type { Query } from '../lib/query';
910
import { spacetimeDBQuery } from './SpacetimeDBQueryClient';
1011

1112
export type UseSpacetimeDBQueryResult<T> = [
@@ -29,7 +30,7 @@ export type UseSpacetimeDBSuspenseQueryResult<T> = [
2930
// useSpacetimeDBQuery(tables.user.where(r => r.online.eq(true)))
3031
// useSpacetimeDBQuery(condition ? tables.user : 'skip')
3132
export function useSpacetimeDBQuery<TableDef extends UntypedTableDef>(
32-
queryOrSkip: ({ toSql(): string } & Record<string, any>) | 'skip',
33+
queryOrSkip: Query<TableDef> | 'skip',
3334
// any useQuery option (e.g. enabled, refetchInterval, select, placeholderData),
3435
// except queryKey, queryFn, and meta (managed internally)
3536
options?: Omit<
@@ -60,7 +61,7 @@ export function useSpacetimeDBQuery<TableDef extends UntypedTableDef>(
6061
// until data is ready, a parent <Suspense fallback={…}> handles the loading UI.
6162
// does not support 'skip' because useSuspenseQuery must always resolve
6263
export function useSpacetimeDBSuspenseQuery<TableDef extends UntypedTableDef>(
63-
query: { toSql(): string } & Record<string, any>,
64+
query: Query<TableDef>,
6465
options?: Omit<
6566
UseSuspenseQueryOptions<
6667
RowType<TableDef>[],

0 commit comments

Comments
 (0)