From 4bb61dcdbf48d06c5c3dcc1ba8d3b01471071b0d Mon Sep 17 00:00:00 2001 From: Brayden Wilmoth Date: Mon, 10 Feb 2025 15:10:14 -0500 Subject: [PATCH 1/2] Handler API with data source --- src/api/index.ts | 8 +++++++- src/handler.ts | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 88934e7..469bf45 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -2,7 +2,13 @@ // You can access these endpoints at the following URL: // https://starbasedb.YOUR-IDENTIFIER.workers.dev/api/your/path/here -export async function handleApiRequest(request: Request): Promise { +import { StarbaseContext } from '../handler' +import { DataSource } from '../types' + +export async function handleApiRequest( + request: Request, + dataSource: DataSource +): Promise { const url = new URL(request.url) // EXAMPLE: diff --git a/src/handler.ts b/src/handler.ts index fd459a9..b5d8122 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -176,7 +176,9 @@ export class StarbaseDB { ) } - this.app.all('/api/*', async (c) => handleApiRequest(c.req.raw)) + this.app.all('/api/*', async (c) => + handleApiRequest(c.req.raw, this.dataSource) + ) // Set up error handlers this.app.notFound(() => { From 9143fed641445820023dd6a48c6d2999f30d7394 Mon Sep 17 00:00:00 2001 From: Brayden Wilmoth Date: Tue, 11 Feb 2025 09:24:52 -0500 Subject: [PATCH 2/2] Async callbacks --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index d4026c9..13af797 100644 --- a/src/index.ts +++ b/src/index.ts @@ -181,11 +181,11 @@ export default { events: [], }) - cdcPlugin.onEvent(({ action, schema, table, data }) => { + cdcPlugin.onEvent(async ({ action, schema, table, data }) => { // Include change data capture code here }, ctx) - cronPlugin.onEvent(({ name, cron_tab, payload }) => { + cronPlugin.onEvent(async ({ name, cron_tab, payload }) => { // Include cron event code here }, ctx)