From d3e8cf6a6c7c30a330488141b6a696c6334625d4 Mon Sep 17 00:00:00 2001 From: Noa Date: Thu, 26 Feb 2026 12:54:08 -0600 Subject: [PATCH 1/2] [TS] Fix error with accessorless explicit indices --- crates/bindings-typescript/src/lib/schema.ts | 31 ++++++++++--------- .../bindings-typescript/src/server/runtime.ts | 10 +++--- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/crates/bindings-typescript/src/lib/schema.ts b/crates/bindings-typescript/src/lib/schema.ts index 22ff25256d0..2c9b60df04f 100644 --- a/crates/bindings-typescript/src/lib/schema.ts +++ b/crates/bindings-typescript/src/lib/schema.ts @@ -104,20 +104,23 @@ export function tableToSchema< // by casting it to an `Array` as `TableToSchema` expects. // This is then used in `TableCacheImpl.constructor` and who knows where else. // We should stop lying about our types. - indexes: tableDef.indexes.map((idx): UntypedIndex => { - const columnIds = - idx.algorithm.tag === 'Direct' - ? [idx.algorithm.value] - : idx.algorithm.value; - return { - name: idx.accessorName!, - unique: tableDef.constraints.some(c => - c.data.value.columns.every(col => columnIds.includes(col)) - ), - algorithm: idx.algorithm.tag.toLowerCase() as 'btree', - columns: columnIds.map(getColName), - }; - }) as T['idxs'], + indexes: tableDef.indexes + .map((idx): UntypedIndex | undefined => { + if (!idx.accessorName) return; + const columnIds = + idx.algorithm.tag === 'Direct' + ? [idx.algorithm.value] + : idx.algorithm.value; + return { + name: idx.accessorName, + unique: tableDef.constraints.some(c => + c.data.value.columns.every(col => columnIds.includes(col)) + ), + algorithm: idx.algorithm.tag.toLowerCase() as 'btree', + columns: columnIds.map(getColName), + }; + }) + .filter(x => !!x) as T['idxs'], tableDef, ...(tableDef.isEvent ? { isEvent: true } : {}), }; diff --git a/crates/bindings-typescript/src/server/runtime.ts b/crates/bindings-typescript/src/server/runtime.ts index c68f3d765d5..e848f64704b 100644 --- a/crates/bindings-typescript/src/server/runtime.ts +++ b/crates/bindings-typescript/src/server/runtime.ts @@ -795,10 +795,12 @@ function makeTableView( } as RangedIndex; } - if (Object.hasOwn(tableView, indexDef.accessorName!)) { - freeze(Object.assign(tableView[indexDef.accessorName!], index)); - } else { - tableView[indexDef.accessorName!] = freeze(index) as any; + if (indexDef.accessorName) { + if (Object.hasOwn(tableView, indexDef.accessorName)) { + freeze(Object.assign(tableView[indexDef.accessorName], index)); + } else { + tableView[indexDef.accessorName] = freeze(index) as any; + } } } From dc22c223e7638a24ed65e9aa2799b2c6510b7f57 Mon Sep 17 00:00:00 2001 From: clockwork-labs-bot Date: Tue, 3 Mar 2026 14:13:25 -0500 Subject: [PATCH 2/2] style: format after merge --- crates/bindings-typescript/src/lib/schema.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/bindings-typescript/src/lib/schema.ts b/crates/bindings-typescript/src/lib/schema.ts index f13dbdf3a99..952402a57c6 100644 --- a/crates/bindings-typescript/src/lib/schema.ts +++ b/crates/bindings-typescript/src/lib/schema.ts @@ -109,7 +109,9 @@ export function tableToSchema< // This is intentionally separate from `schema.idxs`, which keeps the original // user-declared `IndexOpts` shape for type-level inference. const resolvedIndexes: UntypedIndex[] = tableDef.indexes - .filter(idx => typeof idx.accessorName === 'string' && idx.accessorName.length > 0) + .filter( + idx => typeof idx.accessorName === 'string' && idx.accessorName.length > 0 + ) .map(idx => { const accessorName = idx.accessorName!; @@ -138,8 +140,7 @@ export function tableToSchema< algorithm, columns: columnIds.map(getColName) as AllowedCol[], }; - } - ); + }); return { // For client,`schama.tableName` will always be there as canonical name.