···1{
2 "name": "snowflake",
3 "version": "0.0.1",
4- "description": "Simple, single-user event aggregation platform, for use in personal websites and other related places.",
5 "keywords": [
6 "event-aggregation",
7 "event-streaming",
···1{
2 "name": "snowflake",
3 "version": "0.0.1",
4+ "description": "Simple, single-user event aggregation platform, for use in personal websites, analytics and other related places.",
5 "keywords": [
6 "event-aggregation",
7 "event-streaming",
···1+import type { Event } from "$lib/utils/Event";
2+import type { State } from "$lib/utils/State";
00000000000000000000000000000000034+export const events: Event[] = [];
5+export const states: State[] = [];
0000000000000
+10
src/lib/utils/Event.ts
···0000000000
···1+export class Event<T extends object = object> {
2+ public id: string = crypto.randomUUID();
3+ public createdAt: number = Date.now();
4+5+ constructor(
6+ public source: string, // The service name, such as "hytale"
7+ public name: string, // The event name, such as "server.connected"
8+ public data: T = {} as T, // Event specific data, such as { server: { id, name }, user: { id, name } }
9+ ) {}
10+}
+11
src/lib/utils/State.ts
···00000000000
···1+export class State {
2+ public id: string = crypto.randomUUID();
3+ public createdAt: number = Date.now();
4+ public updatedAt: number = Date.now();
5+6+ constructor(
7+ public source: string, // The service name this state connects to, such as "hytale"
8+ public key: string, // The key of the state, such as "current.status", "current.gamemode" or "current.server.name"
9+ public value: string, // The value of the state, such as "online", "offline", "survival", "creative", "server1", "server2"
10+ ) {}
11+}
+10-16
src/routes/events/index.ts
···3// ------------------------------------------------------------
45import { Hono } from "hono";
6-import { Snowflake, Event, events } from "../../lib/stores";
078const app = new Hono();
9···12// ------------------------------------------------------------
1314app.get("/", async (c) => {
15- events.push(
16- new Snowflake(
17- crypto.randomUUID(),
18- "event",
19- new Event("internal", "endpoint.events.get"),
20- ),
21- );
2223 return c.json(events);
24});
2526app.post("/", async (c) => {
27 const body = await c.req.json();
28- if (!body.source || !body.name || !body.data) {
29- return c.json({ error: "Invalid event" }, 400);
00030 }
3132- // Build event and wrap it in a snowflake
33- const event = new Snowflake(
34- crypto.randomUUID(),
35- "event",
36- new Event(body.source, body.name, body.data),
37- );
3839 events.push(event);
40 return c.json(body);