diff --git a/app/game-api/src/context.ts b/app/game-api/src/context.ts index 4dba225..966528d 100644 --- a/app/game-api/src/context.ts +++ b/app/game-api/src/context.ts @@ -1,5 +1,5 @@ import type { GameSessionTokenPayload } from '@sammo-ts/common'; -import type { Prisma } from '@prisma/client'; +import type { DatabaseClient as InfraDatabaseClient } from '@sammo-ts/infra'; import type { TurnDaemonTransport } from './daemon/transport.js'; @@ -100,54 +100,14 @@ export interface NationRow { meta: unknown; } -export interface DatabaseClient { - $queryRaw(query: Prisma.Sql): Promise; - worldState: { - findFirst(args?: unknown): Promise; - }; - general: { - findUnique(args: { where: { id: number } }): Promise; - }; - city: { - findUnique(args: { where: { id: number } }): Promise; - }; - nation: { - findUnique(args: { where: { id: number } }): Promise; - }; - generalTurn: { - findMany(args: { - where: { generalId: number }; - orderBy?: { turnIdx: 'asc' | 'desc' }[]; - }): Promise; - deleteMany(args: { where: { generalId: number } }): Promise; - createMany(args: { - data: Array<{ - generalId: number; - turnIdx: number; - actionCode: string; - arg: unknown; - }>; - }): Promise; - }; - nationTurn: { - findMany(args: { - where: { nationId: number; officerLevel: number }; - orderBy?: { turnIdx: 'asc' | 'desc' }[]; - }): Promise; - deleteMany(args: { - where: { nationId: number; officerLevel: number }; - }): Promise; - createMany(args: { - data: Array<{ - nationId: number; - officerLevel: number; - turnIdx: number; - actionCode: string; - arg: unknown; - }>; - }): Promise; - }; -} +export type DatabaseClient = InfraDatabaseClient< + WorldStateRow, + GeneralRow, + CityRow, + NationRow, + GeneralTurnRow, + NationTurnRow +>; export interface GameApiContext { db: DatabaseClient; diff --git a/packages/infra/src/db.ts b/packages/infra/src/db.ts new file mode 100644 index 0000000..ccb4288 --- /dev/null +++ b/packages/infra/src/db.ts @@ -0,0 +1,58 @@ +export interface DatabaseClient< + WorldStateRow = unknown, + GeneralRow = unknown, + CityRow = unknown, + NationRow = unknown, + GeneralTurnRow = unknown, + NationTurnRow = unknown +> { + $queryRaw( + query: TemplateStringsArray, + ...values: unknown[] + ): Promise; + worldState: { + findFirst(args?: unknown): Promise; + }; + general: { + findUnique(args: { where: { id: number } }): Promise; + }; + city: { + findUnique(args: { where: { id: number } }): Promise; + }; + nation: { + findUnique(args: { where: { id: number } }): Promise; + }; + generalTurn: { + findMany(args: { + where: { generalId: number }; + orderBy?: { turnIdx: 'asc' | 'desc' }[]; + }): Promise; + deleteMany(args: { where: { generalId: number } }): Promise; + createMany(args: { + data: Array<{ + generalId: number; + turnIdx: number; + actionCode: string; + arg: unknown; + }>; + }): Promise; + }; + nationTurn: { + findMany(args: { + where: { nationId: number; officerLevel: number }; + orderBy?: { turnIdx: 'asc' | 'desc' }[]; + }): Promise; + deleteMany(args: { + where: { nationId: number; officerLevel: number }; + }): Promise; + createMany(args: { + data: Array<{ + nationId: number; + officerLevel: number; + turnIdx: number; + actionCode: string; + arg: unknown; + }>; + }): Promise; + }; +} diff --git a/packages/infra/src/index.ts b/packages/infra/src/index.ts index 1ab8565..1d804de 100644 --- a/packages/infra/src/index.ts +++ b/packages/infra/src/index.ts @@ -1,3 +1,4 @@ export * from './postgres.js'; +export * from './db.js'; export * from './logRepository.js'; export * from './redis.js'; diff --git a/packages/logic/tsconfig.json b/packages/logic/tsconfig.json index ecf14f7..416792a 100644 --- a/packages/logic/tsconfig.json +++ b/packages/logic/tsconfig.json @@ -4,6 +4,7 @@ "outDir": "dist", "rootDir": "src", "composite": true, + "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", "module": "NodeNext", "moduleResolution": "NodeNext", "target": "ES2023",