tursodatabase / tursodatabase/libsql-client-ts
Design suggestions for beta CDC support
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 576
- Forks
- 69
- PR merge metrics
- No merged PRs in 30d
Description
I've been looking into the new beta /listen endpoint and wondering how consumers would be using this from Typescript SDK.
There is currently no "native" support for SSE on the server side (nodejs process) for SSE that supports authorization headers.
I did manage to find a polly-fill of sorts that adds support for headers and usable from nodejs
API Suggestion
The browser based SSE implementation is based on EventEmitter interface and I think its a good idea to stick to that, would async/await being common we should support that too.
We could expose a cdc property with on(...) method for supported events insert | update | delete.
const turso = createClient({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});
// non-async
turso.cdc.on("insert", "myTable", (event) => {
// user code here
});
// async
turso.cdc.on("insert", "myTable", async (event) => {
// user code here
});
Small problem is that current implementation doesn't provide information about what's actually changed, it's just a signal to say an event of insert | update | delete as occurred.
User on discord notrab suggested using triggers to track changes and manage a audit log table. I had a similar idea in previous discussion of CDC and think its clever and probably easiest to implement.
Decision now becomes, does this belong in the SDK as a plugin/extension that allows the user to install the triggers and audit log table OR should this be in documentation that a user will need to manually install ?
My two cents would be that we manage this as some sort of plugin/extension that is opt-in and is an optional configuration property. I think it could work like this:
- configure plugin in
createClientconstructor createClientwould install triggers and name spaced audit log table- consumer can register
turso.cdc.on(...)handlers and listen for events - "closing" the client should uninstall triggers and audit log table
Let me know your thoughts. I would also be happy to start on a prototype to get a feel for what works well internally and is easy to manage from consumer side.
Cheers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the beta /listen endpoint and linked pull request #1388, then inspect the TypeScript SDK's createClient entry point. The proposal needs a decided design for optional trigger and audit-log setup, cdc event handlers, and client cleanup; done would require an agreed API and implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100