Fix SurrealDB peer runtime identity - #6
Open
JustKira wants to merge 1 commit into
Open
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
rowan-baker
reviewed
Jul 4, 2026
Author
|
Actually my bad i push incorrect commit this shouldn't be pushed like 900+ lines changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a runtime class identity issue in the published adapter build.
The adapter source imports
RecordIdfromsurrealdb, but the current Bun build can bundle dependencies intodist/index.js. That means the published adapter can contain a private bundled copy of SurrealDB's runtime classes.A consuming app also imports
surrealdbfor its ownSurrealclient. Even when both copies are the same package version, they are separate JavaScript class identities:The adapter creates a record id for the Surreal row id slot:
But if that
RecordIdcomes from the adapter's bundled copy, the app's Surreal client may not recognize it as its ownRecordIdclass when encoding query bindings. The malformed binding can create rows like:instead of:
Before
flowchart TD BA["Better Auth"] Adapter["@surrealdb/better-auth dist"] Bundled["bundled surrealdb copy<br/>RecordId class B"] AppClient["consumer app surrealdb<br/>Surreal client + RecordId class A"] DB["SurrealDB"] Bad["created row:<br/>user:{ }"] BA -->|"id = UUID string"| Adapter Adapter -->|"new RecordId('user', id)"| Bundled Bundled -->|"RecordId class B"| AppClient AppClient -->|"does not recognize class B"| DB DB --> Bad style Bad fill:#ffd6d6,stroke:#aa0000,color:#000After
flowchart TD BA["Better Auth"] Adapter["@surrealdb/better-auth dist"] AppRuntime["consumer app surrealdb<br/>Surreal client + RecordId class A"] DB["SurrealDB"] Good["created row:<br/>user:⟨uuid⟩"] Adapter -->|"import { RecordId } from 'surrealdb'"| AppRuntime BA -->|"id = UUID string"| Adapter Adapter -->|"new RecordId('user', id)<br/>using class A"| AppRuntime AppRuntime -->|"recognized RecordId"| DB DB --> Good style Good fill:#d8ffd8,stroke:#008a00,color:#000Why both changes are needed
This PR makes two packaging changes:
and:
--packages externalkeepssurrealdbas an external import indist/index.jsinstead of bundling it.peerDependencies.surrealdbensures the adapter does not install or own a nested SurrealDB runtime and instead uses the consumer app's installedsurrealdb.Together they preserve the invariant:
peerDependenciesalone is not enough ifdist/index.jsalready contains bundled SurrealDB code.--packages externalalone is not enough if the adapter can still install a nestednode_modules/surrealdbcopy.Id semantics
This does not change Better Auth id semantics.
Better Auth-facing ids remain strings:
Only the SurrealDB intrinsic row id slot is converted to
RecordIdat query time:Correct flow:
Summary
The source logic using
new RecordId(...)is not the bug by itself. The bug is when thatRecordIdcomes from a bundled/private copy ofsurrealdbinstead of the samesurrealdbruntime used by the consuming app'sSurrealclient.This PR fixes that by externalizing package imports during build and making
surrealdba peer dependency.