WIP! A BB-style forum, on the ATmosphere!
We're still working... we'll be back soon when we have something to show off!
node
typescript
hono
htmx
atproto
1import type { Jetstream } from "@skyware/jetstream";
2
3/**
4 * Event operation types supported by Jetstream
5 */
6export type EventOperation = "create" | "update" | "delete";
7
8/**
9 * Handler function signature for any event operation
10 */
11export type EventHandler<_T extends string = string> = (event: any) => Promise<void>;
12
13/**
14 * Configuration for a single collection's event handlers
15 */
16export interface CollectionHandlers {
17 collection: string;
18 onCreate?: EventHandler;
19 onUpdate?: EventHandler;
20 onDelete?: EventHandler;
21}
22
23/**
24 * Registry for managing Jetstream event handler registrations.
25 * Eliminates boilerplate by automating handler setup for collections.
26 */
27export class EventHandlerRegistry {
28 private registrations: CollectionHandlers[] = [];
29
30 /**
31 * Register handlers for a collection
32 */
33 register(handlers: CollectionHandlers): this {
34 this.registrations.push(handlers);
35 return this; // Fluent interface
36 }
37
38 /**
39 * Apply all registered handlers to a Jetstream instance
40 */
41 applyTo(jetstream: Jetstream): void {
42 for (const { collection, onCreate, onUpdate, onDelete } of this.registrations) {
43 if (onCreate) {
44 jetstream.onCreate(collection as any, onCreate);
45 }
46 if (onUpdate) {
47 jetstream.onUpdate(collection as any, onUpdate);
48 }
49 if (onDelete) {
50 jetstream.onDelete(collection as any, onDelete);
51 }
52 }
53 }
54
55 /**
56 * Get all registered collection names
57 */
58 getCollections(): string[] {
59 return this.registrations.map((r) => r.collection);
60 }
61
62 /**
63 * Clear all registrations (useful for testing)
64 */
65 clear(): void {
66 this.registrations = [];
67 }
68}