Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/calm-drinks-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/db': patch
---

Fix options parsing for the libsql client connection to ensure that proper values are being set when adding URLSearchParams to the `ASTRO_DB_REMOTE_URL`
25 changes: 19 additions & 6 deletions packages/db/src/runtime/db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function createRemoteDatabaseClient(options: RemoteDbClientOptions) {
}

function createRemoteLibSQLClient(appToken: string, remoteDbURL: URL, rawUrl: string) {
const options: Partial<LibSQLConfig> = Object.fromEntries(remoteDbURL.searchParams.entries());
const options: Record<string, string> = Object.fromEntries(remoteDbURL.searchParams.entries());
remoteDbURL.search = '';

let url = remoteDbURL.toString();
Expand All @@ -81,11 +81,24 @@ function createRemoteLibSQLClient(appToken: string, remoteDbURL: URL, rawUrl: st
url = 'file:' + remoteDbURL.pathname.substring(1);
}

const client = createClient({
...options,
authToken: appToken,
url,
});
// this function parses the options from a `Record<string, string>`
// provided from the object conversion of the searchParams and properly
// verifies that the Config object is providing the correct types.
// without this, there is runtime errors due to incorrect values
function parseOpts(config: Record<string, string>): LibSQLConfig {
return {
... config,
syncInterval: config.syncInterval ? parseInt(options.syncInterval) : undefined,
readYourWrites: config.readYourWrites ? !!config.readYourWrites : undefined,
offline: config.offline ? !!config.offline : undefined,
tls: config.tls ? !!config.tls : undefined,
concurrency: config.concurrency ? parseInt(options.concurrency) : undefined,
authToken: appToken,
url,
}
}

const client = createClient(parseOpts(options));
return drizzleLibsql(client);
}

Expand Down
Loading