feat: initial import.

This commit is contained in:
mattia
2025-01-04 14:56:35 +01:00
commit 7751d37249
33 changed files with 6201 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import { GetSessionResponse } from "../contract";
import { db } from "./init";
export async function getSession(id: string): Promise<GetSessionResponse> {
// extract the session
const session = await db
.selectFrom("session_info")
.where("id", "=", id)
.select(["game_name", "version"])
.executeTakeFirstOrThrow();
// get all the connected log entries
const logEntries = await db
.selectFrom("log_entries")
.where("session_info_id", "=", id)
.select(["id", "message", "timestamp"])
.orderBy("timestamp", "asc")
.execute();
// get all the metadata for the log entries
const metadata = await db
.selectFrom("log_metadata")
.where(
"log_entry_id",
"in",
logEntries.map((entry) => entry.id)
)
.select(["log_entry_id", "key", "value"])
.execute();
// buidl the object accordingly
return {
game_name: session.game_name,
version: session.version,
log_entries: logEntries.map((entry) => ({
message: entry.message,
timestamp: entry.timestamp,
metadata: metadata
.filter((m) => m.log_entry_id === entry.id)
.reduce((acc, m) => ({ ...acc, [m.key]: m.value }), {}),
})),
};
}