Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions crates/bindings-typescript/src/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ export function tableToSchema<
// Build fully-resolved runtime index metadata from the host-facing RawTableDef.
// This is intentionally separate from `schema.idxs`, which keeps the original
// user-declared `IndexOpts` shape for type-level inference.
const resolvedIndexes: UntypedIndex<AllowedCol>[] = tableDef.indexes.map(
idx => {
const accessorName = idx.accessorName;
if (typeof accessorName !== 'string' || accessorName.length === 0) {
throw new TypeError(
`Index '${idx.sourceName ?? '<unknown>'}' on table '${tableDef.sourceName}' is missing accessor name`
);
}
const resolvedIndexes: UntypedIndex<AllowedCol>[] = tableDef.indexes
.filter(
idx => typeof idx.accessorName === 'string' && idx.accessorName.length > 0
)
.map(idx => {
const accessorName = idx.accessorName!;

const columnIds =
idx.algorithm.tag === 'Direct'
Expand All @@ -142,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.
Expand Down
16 changes: 9 additions & 7 deletions crates/bindings-typescript/src/server/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,13 +796,15 @@ function makeTableView(
} as RangedIndex<any, any>;
}

// IMPORTANT: duplicate accessor handling.
// When multiple raw indexes share the same accessor name, we merge index
// methods onto a single accessor object instead of throwing.
if (Object.hasOwn(tableView, accessorName)) {
freeze(Object.assign((tableView as any)[accessorName], index));
} else {
(tableView as any)[accessorName] = freeze(index);
if (accessorName) {
// IMPORTANT: duplicate accessor handling.
// When multiple raw indexes share the same accessor name, we merge index
// methods onto a single accessor object instead of throwing.
if (Object.hasOwn(tableView, accessorName)) {
freeze(Object.assign((tableView as any)[accessorName], index));
} else {
(tableView as any)[accessorName] = freeze(index);
}
}
}

Expand Down
Loading