Update dependencies and improve type safety in webhook handling

This commit updates various dependencies across the project, including a version bump for 'lucide-react' and 'prettier'. Additionally, it improves type safety in the 'database-webhook-handler.service.ts' by making the 'DatabaseChangePayload' and 'handleEvent' function more type-safe.
This commit is contained in:
giancarlo
2024-06-03 00:33:49 +07:00
parent 26b2eed60d
commit 08de59a43a
14 changed files with 138 additions and 74 deletions

View File

@@ -11,7 +11,8 @@ import { getDatabaseWebhookVerifier } from './verifier';
* @name DatabaseChangePayload
* @description Payload for the database change event. Useful for handling custom webhooks.
*/
export type DatabaseChangePayload = RecordChange<keyof Tables>;
export type DatabaseChangePayload<Table extends keyof Tables> =
RecordChange<Table>;
export function getDatabaseWebhookHandlerService() {
return new DatabaseWebhookHandlerService();
@@ -33,7 +34,11 @@ class DatabaseWebhookHandlerService {
async handleWebhook(
request: Request,
params?: {
handleEvent(payload: DatabaseChangePayload): unknown;
handleEvent<Table extends keyof Tables>(
payload: Table extends keyof Tables
? DatabaseChangePayload<Table>
: never,
): unknown;
},
) {
const logger = await getLogger();