Skip to content

Conversation

@Adammatthiesen
Copy link
Member

@Adammatthiesen Adammatthiesen commented May 9, 2025

Changes

  • What does this change?
  • Be short and concise. Bullet points can help!
  • Before/after screenshots can help as well.
  • Don't forget a changeset! pnpm exec changeset

This PR ensures proper params are being parsed and sent to the libsql Client, due to URLSearchParams being a Record<string, string> this object requires parsing to ensure the values are being parsed to number or boolean.

See https://discord.com/channels/830184174198718474/1370190284855705680 for context.

Testing

Added a new unit test for ensuring the URL parsing is correct in various circumstances.

Docs

This PR corrects internal logic to reflect the information on the docs. No docs changes needed.

@changeset-bot
Copy link

changeset-bot bot commented May 9, 2025

🦋 Changeset detected

Latest commit: 637d863

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ematipico
Copy link
Member

Can we add some tests @Adammatthiesen ?

@Adammatthiesen
Copy link
Member Author

Can we add some tests @Adammatthiesen ?

Uhhh, how would I implement a test for this? 😅

Not exactly sure how I would setup that test... What this is being used for is setting up the libsql client to use an embedded replica of a remote server which creates a local (file or in memory) copy of the remote db that gets synced back and forth to the remote during runtime.

@ematipico
Copy link
Member

Can we add some tests @Adammatthiesen ?

Uhhh, how would I implement a test for this? 😅

Not exactly sure how I would setup that test... What this is being used for is setting up the libsql client to use an embedded replica of a remote server which creates a local (file or in memory) copy of the remote db that gets synced back and forth to the remote during runtime.

We could export the function and they have a simple unit test that covers the basics. What worries me is that you haven't written anything under the testing section, so it's hard to understand what we're fixing and the fix works.

@Adammatthiesen
Copy link
Member Author

Can we add some tests @Adammatthiesen ?

Uhhh, how would I implement a test for this? 😅
Not exactly sure how I would setup that test... What this is being used for is setting up the libsql client to use an embedded replica of a remote server which creates a local (file or in memory) copy of the remote db that gets synced back and forth to the remote during runtime.

We could export the function and they have a simple unit test that covers the basics. What worries me is that you haven't written anything under the testing section, so it's hard to understand what we're fixing and the fix works.

Your talking about the parse options function correct? To be clear, the issue is the following, currently if you have the following ENV variable from the astro docs:

ASTRO_DB_REMOTE_URL=file://local-copy.db?encryptionKey=your-encryption-key&syncInterval=60&syncUrl=libsql%3A%2F%2Fyour.server.io

it would be parsed as all strings for the config object, which would be invalid. Since the libSQLConfig object type wants the syncInterval needs to be a number for example. but it is currently being parsed as a string.

So current functionality would parse it as:

{
  url: "file://local-copy.db",
  encryptionKey: "your-encryption-key",
  syncInterval: "60",
  syncUrl: "libsql://your.server.io",
}

When it SHOULD be getting parsed as:

{
  url: "file://local-copy.db",
  encryptionKey: "your-encryption-key",
  syncInterval: 60, // <-- This is supposed to be a number according to the libSQL Config type
  syncUrl: "libsql://your.server.io",
}

@ematipico
Copy link
Member

ematipico commented May 9, 2025

As for the test, I suggest the following:

  • Extract the function outside createRemoteLibSQLClient
  • The function will accept config and options too
  • export the function
  • Then create a new file inside this folder https://github.com/withastro/astro/tree/main/packages/db/test/unit, we can call it db-client.test.js
  • When import the function from the dist/ folder e.g.
     import { parseOpts } from "../../dist/runtime/db-client.js"
  • Test with assertions. We can use assert.deepEqual, and we use the example you shared with us
  • The folder has other tests and assertions, you can use them as examples

Let me know if you have more questions

@Adammatthiesen
Copy link
Member Author

As for the test, I suggest the following:

  • Extract the function outside createRemoteLibSQLClient
  • The function will accept config and options too
  • export the function
  • Then create a new file inside this folder https://github.com/withastro/astro/tree/main/packages/db/test/unit, we can call it db-client.test.js
  • When import the function from the dist/ folder e.g.
     import { parseOpts } from "../../dist/runtime/db-client.js"
  • Test with assertions. We can use assert.deepEqual, and we use the example you shared with us
  • The folder has other tests and assertions, you can use them as examples

Let me know if you have more questions

Will get to work on that here soon, sorry passed out after i sent that last message 😅

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 🙏

@ematipico ematipico merged commit 83193d4 into withastro:main May 10, 2025
14 checks passed
@astrobot-houston astrobot-houston mentioned this pull request May 10, 2025
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
* update AstroDB client

* Update packages/db/src/runtime/db-client.ts

Co-authored-by: Luiz Ferraz <[email protected]>

* add test

* fix function to ensure only values that are passed are actually being passed

---------

Co-authored-by: Luiz Ferraz <[email protected]>
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.

4 participants