Skip to content
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

feat: Plugins for CDC, Resend, and Query Log #69

Merged
merged 6 commits into from
Jan 22, 2025

Conversation

Brayden
Copy link
Member

@Brayden Brayden commented Jan 22, 2025

Purpose

This pull request has some duplicate effort that is introduced in #65 but needed to accomplish what we're presenting here (e.g. persistent web socket connections).

In addition to the above the idea is to introduce a few new plugins to demonstrate the power of the plugin ecosystem and provide some critical features that enable more advanced use-cases.

Change Data Capture
You can subscribe to particular schema/table events (e.g. INSERT's in users table) and be notified in one of two ways currently. You can subscribe via websockets to these CDC events (using the /cdc websocket route) or create a callback listener to the plugin and handle logic manually.

const cdcPlugin = new ChangeDataCapturePlugin({
    stub,
    broadcastAllEvents: false,
    events: [{
        action: 'INSERT',
        schema: 'main',
        table: 'users',
    }]
})
cdcPlugin.onEvent(async (payload) => {
    if (payload.action === 'INSERT' && payload.table === 'users') {

    }
}, ctx)

You can also subscribe by default to all mutation events on the internal data source by toggling the broadcastAllEvents to true.

Resend
Provide your Resend API key and trigger an email to be sent in one line of code. Useful for many use cases that go without saying but works very nicely with CDC events where you can listen for a user signup and immediately have an email triggered to send out to that particular user.

const resendPlugin = new ResendPlugin({ apiKey: 're_XYZ_1234ABCD' })
await resendPlugin.sendEmail('[email protected]', ['[email protected]'], 'Hello, World!', '<p>Dear John</p>');

Query Log
This plugin is meant to track all queries executed over the past 24 hours and the duration each query took. Intent of this plugin is to provide some insights into performance. Optimizations can be made here for more millisecond level TTL enablement.

Tasks

  • Add a /status/trace API endpoint to provide metadata about Starbase deployment
  • Fix transaction queries in internal source
  • DO instance can hold onto web socket connections persistently
  • Change Data Capture plugin to subscribe to data mutations and trigger callback events
  • Change Data Capture events by default fire websocket messages to active admin authorization connections
  • Resend plugin enabling ability to trigger emails
  • Query Log plugin to track executed queries and duration

Verify

Before

After

@Brayden Brayden self-assigned this Jan 22, 2025
@Brayden Brayden added the enhancement New feature or request label Jan 22, 2025
@Brayden Brayden merged commit 1630c1d into main Jan 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant