import { HTTPService } from './services/http-router.js'; import { InvitationsRoute } from './routes/invitations.js'; import { StorageSQLite, StoreSQLite } from './services/invitation-store.js'; import { SSEBroadcaster } from './services/sse-broadcast.js'; import type { InvitationSchema } from './utils/invitation-parser.js'; export class App { static async create() { // TODO: Make this configurable const invitationStoragePath = "./xo-invitations.db"; // Create the invitation store (this is a in-memory store for now) const storage = await StorageSQLite.createOrOpen(invitationStoragePath); const invitationStore = await storage.createOrGetStore("invitations"); // Create the SSE Broadcaster const sseBroadcaster = new SSEBroadcaster(); // Create the Invitation route, passing in the invitation store and sse broadcaster const invitationsRoute = new InvitationsRoute(invitationStore, sseBroadcaster); // Create the HTTP service, passing in the invitation route const http = new HTTPService([ invitationsRoute, ]); // Create the app instance, passing in the HTTP service return new App(http); } /** * Create a new instance of App. * @param http - The HTTP service instance. */ constructor(private readonly http: HTTPService) {} async start() { // Start the HTTP service await this.http.start(); } } // Create the app instance and start it const app = await App.create(); await app.start();