From a91383ff5126166c8750a4310bf285174fa22016 Mon Sep 17 00:00:00 2001 From: Zeke Foppa Date: Wed, 14 Jan 2026 12:13:22 -0800 Subject: [PATCH 1/2] [react-uuid-in-where-clause]: Rebase changes onto master --- .../bindings-typescript/src/react/useTable.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/crates/bindings-typescript/src/react/useTable.ts b/crates/bindings-typescript/src/react/useTable.ts index fda88a0835f..adef335a68f 100644 --- a/crates/bindings-typescript/src/react/useTable.ts +++ b/crates/bindings-typescript/src/react/useTable.ts @@ -10,6 +10,7 @@ import { type EventContextInterface } from '../sdk/db_connection_impl'; import type { ConnectionState } from './connection_state'; import type { UntypedRemoteModule } from '../sdk/spacetime_module'; import type { RowType, UntypedTableDef } from '../lib/table'; +import { Uuid } from '../lib/uuid'; import type { Prettify } from '../lib/type_util'; export interface UseTableCallbacks { @@ -18,7 +19,7 @@ export interface UseTableCallbacks { onUpdate?: (oldRow: RowType, newRow: RowType) => void; } -export type Value = string | number | boolean; +export type Value = string | number | boolean | Uuid; export type Expr = | { type: 'eq'; key: Column; value: Value } @@ -76,6 +77,7 @@ export function evaluate( ): boolean { switch (expr.type) { case 'eq': { + // The actual value of the Column const v = row[expr.key]; if ( typeof v === 'string' || @@ -84,6 +86,16 @@ export function evaluate( ) { return v === expr.value; } + if (typeof v === 'object') { + // Value of the Column and passed Value are both a Uuid so do an integer comparison. + if (v instanceof Uuid && expr.value instanceof Uuid) { + return v.asBigInt() === expr.value.asBigInt(); + } + // Value of the Column is a Uuid but passed Value is a String so compare them via string. + if (v instanceof Uuid && typeof expr.value === 'string') { + return v.toString() === expr.value; + } + } return false; } case 'and': @@ -105,6 +117,13 @@ function formatValue(v: Value): string { return Number.isFinite(v) ? String(v) : `'${String(v)}'`; case 'boolean': return v ? 'TRUE' : 'FALSE'; + case 'object': { + if (v instanceof Uuid) { + return `'${v.toString()}'`; + } + + return ''; + } } } @@ -290,8 +309,8 @@ export function useTable( } catch { throw new Error( 'Could not find SpacetimeDB client! Did you forget to add a ' + - '`SpacetimeDBProvider`? `useTable` must be used in the React component tree ' + - 'under a `SpacetimeDBProvider` component.' + '`SpacetimeDBProvider`? `useTable` must be used in the React component tree ' + + 'under a `SpacetimeDBProvider` component.' ); } @@ -317,8 +336,8 @@ export function useTable( const table = connection.db[accessorName]; const result: readonly Prettify[] = whereClause ? (Array.from(table.iter()).filter(row => - evaluate(whereClause, row as UseTableRowType) - ) as Prettify[]) + evaluate(whereClause, row as UseTableRowType) + ) as Prettify[]) : (Array.from(table.iter()) as Prettify[]); return [result, subscribeApplied]; // eslint-disable-next-line react-hooks/exhaustive-deps @@ -410,7 +429,7 @@ export function useTable( const connection = connectionState.getConnection(); if (!connection) { - return () => {}; + return () => { }; } const table = connection.db[accessorName]; From 40d56cec3053dc975c4058b630dad9fbf48f7dfd Mon Sep 17 00:00:00 2001 From: Zeke Foppa Date: Wed, 14 Jan 2026 12:14:11 -0800 Subject: [PATCH 2/2] [react-uuid-in-where-clause]: pnpm format --- crates/bindings-typescript/src/react/useTable.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/bindings-typescript/src/react/useTable.ts b/crates/bindings-typescript/src/react/useTable.ts index adef335a68f..569f66fb43f 100644 --- a/crates/bindings-typescript/src/react/useTable.ts +++ b/crates/bindings-typescript/src/react/useTable.ts @@ -87,11 +87,11 @@ export function evaluate( return v === expr.value; } if (typeof v === 'object') { - // Value of the Column and passed Value are both a Uuid so do an integer comparison. + // Value of the Column and passed Value are both a Uuid so do an integer comparison. if (v instanceof Uuid && expr.value instanceof Uuid) { return v.asBigInt() === expr.value.asBigInt(); } - // Value of the Column is a Uuid but passed Value is a String so compare them via string. + // Value of the Column is a Uuid but passed Value is a String so compare them via string. if (v instanceof Uuid && typeof expr.value === 'string') { return v.toString() === expr.value; } @@ -309,8 +309,8 @@ export function useTable( } catch { throw new Error( 'Could not find SpacetimeDB client! Did you forget to add a ' + - '`SpacetimeDBProvider`? `useTable` must be used in the React component tree ' + - 'under a `SpacetimeDBProvider` component.' + '`SpacetimeDBProvider`? `useTable` must be used in the React component tree ' + + 'under a `SpacetimeDBProvider` component.' ); } @@ -336,8 +336,8 @@ export function useTable( const table = connection.db[accessorName]; const result: readonly Prettify[] = whereClause ? (Array.from(table.iter()).filter(row => - evaluate(whereClause, row as UseTableRowType) - ) as Prettify[]) + evaluate(whereClause, row as UseTableRowType) + ) as Prettify[]) : (Array.from(table.iter()) as Prettify[]); return [result, subscribeApplied]; // eslint-disable-next-line react-hooks/exhaustive-deps @@ -429,7 +429,7 @@ export function useTable( const connection = connectionState.getConnection(); if (!connection) { - return () => { }; + return () => {}; } const table = connection.db[accessorName];