feat: implement game API with TRPC and Redis transport
- Added GameApiConfig interface and configuration resolver from environment variables. - Created GameApiContext for managing database and transport dependencies. - Implemented InMemoryTurnDaemonTransport for testing purposes. - Developed RedisTurnDaemonTransport for command and status handling via Redis streams. - Defined TurnDaemonStreamKeys for namespacing Redis streams by profile. - Established TRPC router with endpoints for health check, world state retrieval, and turn daemon commands (run, pause, resume, status). - Integrated Fastify server with TRPC and Redis transport. - Added unit tests for router functionality and stream key generation. - Configured Vitest for testing environment.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import type { TurnDaemonTransport } from './daemon/transport.js';
|
||||
|
||||
export interface GameProfile {
|
||||
id: string;
|
||||
scenario: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface WorldStateRow {
|
||||
scenarioCode: string;
|
||||
currentYear: number;
|
||||
currentMonth: number;
|
||||
tickSeconds: number;
|
||||
config: unknown;
|
||||
meta: unknown;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export interface DatabaseClient {
|
||||
worldState: {
|
||||
findFirst(args?: unknown): Promise<WorldStateRow | null>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface GameApiContext {
|
||||
db: DatabaseClient;
|
||||
turnDaemon: TurnDaemonTransport;
|
||||
profile: GameProfile;
|
||||
}
|
||||
|
||||
export const createGameApiContext = (options: {
|
||||
db: DatabaseClient;
|
||||
turnDaemon: TurnDaemonTransport;
|
||||
profile: GameProfile;
|
||||
}): GameApiContext => {
|
||||
return {
|
||||
db: options.db,
|
||||
turnDaemon: options.turnDaemon,
|
||||
profile: options.profile,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user