Skip to content

Export AsyncDatabaseConnection types in @powersync/web #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LucDeCaf
Copy link
Contributor

@LucDeCaf LucDeCaf commented Jul 6, 2025

The entire change is adding one more file's types to packages/web/src/index.ts.

Long story short, I need access to these types in my codebase :)

Copy link

changeset-bot bot commented Jul 6, 2025

⚠️ No Changeset found

Latest commit: 2ffb955

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@Chriztiaan
Copy link
Contributor

Hey @LucDeCaf, that file contains internal members which we might have not exposed intentionally so that we might be able to drop it in the future without being a breaking change - in which case I might suggest making your own copies of the types on your side. Any thoughts @stevensJourney?

@stevensJourney
Copy link
Collaborator

Indeed these are currently internals.

I do see that devs might want access to these internals in order to build custom database workers - e.g. if custom SQLite functions are desired.

I quite like having the freedom to change these interfaces without making breaking changes.

If users really have a pressing need for this - one potential workaround might be to mark these exports as @internal and/or maybe also expose them separately from the main package exports in index.ts with a subpath export. Users of those APIs would need to understand the risk of breaking changes.

@LucDeCaf
Copy link
Contributor Author

LucDeCaf commented Jul 7, 2025

@Chriztiaan @stevensJourney I think it would be useful to have access to these functions - right now I just modify the powersync/web folder in node_modules, but that doesn't feel like a very robust solution. My reasoning for why it might make sense to expose these APIs is that the port returned by the public facing shareConnection API proxies into OpenAsyncDatabaseConnection.

Example: this snippet uses only public APIs except for those in AsyncDatabaseConnection:

const powersync = new PowerSyncDatabase({ /* ... */ });

// Obtain a port for use elsewhere (eg. in a custom worker)
const db = powersync.database; // Will be of type WebDBAdapter unless using SSR
const { port } = await db.shareConnection();
const resolvedOptions = db.getConfiguration();

// my_worker.ts
const remote = Comlink.wrap<OpenAsyncDatabaseConnection>(port);
const connection: AsyncDatabaseConnection = await remote(resolvedOptions);

It's worth noting that WebDBAdapter isn't public either, but the method is still publicly available via PowerSyncDatabase.database.

If we don't want to expose the API that's fine too, like I said it would just be nice 👍

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.

3 participants