Skip to content

fix(bindings-typescript): support cross-bundle Range instances in index scans (#6299) - #6350

Open
Tyagiquamar wants to merge 1 commit into
clockworklabs:masterfrom
Tyagiquamar:fix/ts-range-instanceof-test-utils-6299
Open

Tyagiquamar wants to merge 1 commit into
clockworklabs:masterfrom
Tyagiquamar:fix/ts-range-instanceof-test-utils-6299

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Summary

Fixes #6299.

When using spacetimedb/server/test-utils or module code bundled across entrypoints, filtering or deleting through a table index using a Range instance failed because range instanceof Range evaluated to false.

dist/server/test-utils/index.mjs and dist/server/index.mjs are separate bundles, each inlining its own copy of Range. Consequently:

  1. range instanceof Range evaluates to false across bundles.
  2. The runtime falls back to serializing the Range object as a single point.
  3. On number columns, index scans match no rows. On BigInt-backed columns (like Timestamp), the point serializer throws TypeError: Cannot convert undefined to a BigInt.

Solution

  1. Added Symbol.for('spacetimedb.Range') brand to Range.prototype and added Range.isRange(val) / exported isRange(val) predicate.
  2. In crates/bindings-typescript/src/server/runtime.ts, replaced instanceof Range checks in single-column index filter/delete and multi-column index scan paths with isRange(...).
  3. Added unit and regression tests in crates/bindings-typescript/tests/index_prefix_filter.test.ts verifying that cross-bundle Range instances work seamlessly for both single-column and multi-column btree index filters and deletes.

Verification

  • Ran vitest run tests/index_prefix_filter.test.ts: all 11 tests passed.
  • Ran tsc -p tsconfig.build.json: type check passed.
  • Ran prettier --check on modified files: passed.

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.

Module test harness: index range scans match nothing, or throw, because Range fails instanceof

1 participant