Repository navigation
feat(ts-sdk): add serverless adapter for @tursodatabase/serverless - #325
Merged
penberg merged 4 commits intoMar 22, 2026
Merged
Conversation
Adds an adapter that wraps @tursodatabase/serverless Connection to be
compatible with AgentFS's DatabasePromise interface, enabling AgentFS
to work with remote Turso/sqld instances over HTTP.
Usage:
import { connect } from "@tursodatabase/serverless";
import { createServerlessAdapter } from "agentfs-sdk/serverless";
const conn = connect({ url: "libsql://mydb.turso.io", authToken: "..." });
const db = createServerlessAdapter(conn);
const agent = await AgentFS.openWith(db);
The key challenge is that DatabasePromise.prepare() is synchronous while
the serverless driver's prepare() is async. The adapter uses a LazyStatement
that defers prepare() until run/get/all is called.
Closes tursodatabase#156
The serverless integration tests require a running sqld instance. Skip them gracefully in CI where sqld is not present.
- Import Connection/Statement types from @tursodatabase/serverless instead of hand-rolled interfaces - Return DatabasePromise type instead of any - Forward pluck() and safeIntegers() to underlying statement - Throw explicit errors for unsupported operations (bind, pragma, backup, serialize, etc.) instead of silent no-ops - Validate connection in connect() with SELECT 1 - Don't cache stmtPromise to avoid stale raw/pluck/safeIntegers state - Test imports from the export path instead of internal source
- Re-add stmtPromise caching to avoid extra HTTP prepare() per call, apply raw/pluck/safeIntegers at execution time on resolved statement - Fix transaction() to return a wrapper function matching DatabasePromise signature: (...bindParameters) => Promise<any> - Add comments explaining the parameter passing convention difference between DatabasePromise (rest params) and serverless (single array)
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.
Adds an adapter that wraps
@tursodatabase/serverlessConnection to be compatible with AgentFS'sDatabasePromiseinterface, enabling AgentFS to work with remote Turso/sqld instances over HTTP.Usage
How it works
The main challenge is that
DatabasePromise.prepare()is synchronous while@tursodatabase/serverless'sprepare()is async (it fetches column metadata over HTTP). The adapter uses aLazyStatementthat defers the actualprepare()call untilrun()/get()/all()is called — those are already async, so the deferral is invisible to callers.Changes
sdk/typescript/src/integrations/serverless/— adapter and exportssdk/typescript/tests/serverless.test.ts— integration tests against a local sqld instancesdk/typescript/package.json— addsagentfs-sdk/serverlessexport path,@tursodatabase/serverlessas optional peer dependencyCloses #156