feat: GamePrisma를 사용하여 데이터베이스 클라이언트 및 관련 타입 정의 업데이트

This commit is contained in:
2026-01-05 15:13:59 +00:00
parent c3b6833172
commit b1f2523fa3
7 changed files with 47 additions and 216 deletions
+11 -112
View File
@@ -1,6 +1,6 @@
import { z } from 'zod';
import type { GameSessionTokenPayload } from '@sammo-ts/common';
import type { DatabaseClient as InfraDatabaseClient, RedisConnector } from '@sammo-ts/infra';
import type { DatabaseClient as InfraDatabaseClient, RedisConnector, GamePrisma } from '@sammo-ts/infra';
import type { TurnDaemonTransport } from './daemon/transport.js';
import type { BattleSimTransport } from './battleSim/transport.js';
@@ -26,119 +26,18 @@ export const zWorldStateMeta = z.object({
});
export type WorldStateMeta = z.infer<typeof zWorldStateMeta>;
export interface WorldStateRow {
scenarioCode: string;
currentYear: number;
currentMonth: number;
tickSeconds: number;
config: unknown;
meta: unknown;
updatedAt: Date;
}
export type WorldStateRow = GamePrisma.WorldStateGetPayload<{}>;
export type GeneralRow = GamePrisma.GeneralGetPayload<{}>;
export type GeneralTurnRow = GamePrisma.GeneralTurnGetPayload<{}>;
export type NationTurnRow = GamePrisma.NationTurnGetPayload<{}>;
export type CityRow = GamePrisma.CityGetPayload<{}>;
export type NationRow = GamePrisma.NationGetPayload<{}>;
export type TroopRow = GamePrisma.TroopGetPayload<{}>;
export interface GeneralRow {
id: number;
userId: string | null;
name: string;
nationId: number;
cityId: number;
troopId: number;
leadership: number;
strength: number;
intel: number;
experience: number;
dedication: number;
officerLevel: number;
personalCode: string;
specialCode: string;
special2Code: string;
horseCode: string;
weaponCode: string;
bookCode: string;
itemCode: string;
injury: number;
gold: number;
rice: number;
crew: number;
crewTypeId: number;
train: number;
atmos: number;
age: number;
npcState: number;
picture: string | null;
meta: unknown;
}
export type JsonValue = GamePrisma.JsonValue;
export type InputJsonValue = GamePrisma.InputJsonValue;
export interface GeneralTurnRow {
id: number;
generalId: number;
turnIdx: number;
actionCode: string;
arg: unknown;
}
export interface NationTurnRow {
id: number;
nationId: number;
officerLevel: number;
turnIdx: number;
actionCode: string;
arg: unknown;
}
export interface CityRow {
id: number;
name: string;
nationId: number;
level: number;
population: number;
populationMax: number;
agriculture: number;
agricultureMax: number;
commerce: number;
commerceMax: number;
security: number;
securityMax: number;
trust: number;
trade: number;
supplyState: number;
frontState: number;
defence: number;
defenceMax: number;
wall: number;
wallMax: number;
region: number;
meta: unknown;
}
export interface NationRow {
id: number;
name: string;
color: string;
capitalCityId: number | null;
gold: number;
rice: number;
tech: number;
level: number;
typeCode: string;
meta: unknown;
}
export interface TroopRow {
troopLeaderId: number;
nationId: number;
name: string;
}
export type DatabaseClient = InfraDatabaseClient<
WorldStateRow,
GeneralRow,
CityRow,
NationRow,
GeneralTurnRow,
NationTurnRow,
TroopRow
>;
export type DatabaseClient = InfraDatabaseClient;
export interface GameApiContext {
db: DatabaseClient;
+5 -4
View File
@@ -2,6 +2,7 @@ import type {
DatabaseClient,
GeneralTurnRow,
NationTurnRow,
InputJsonValue,
} from '../context.js';
export const DEFAULT_TURN_ACTION = '휴식';
@@ -10,13 +11,13 @@ export const MAX_NATION_TURNS = 12;
export interface ReservedTurnEntry {
action: string;
args: Record<string, unknown>;
args: InputJsonValue;
}
export interface ReservedTurnView {
index: number;
action: string;
args: Record<string, unknown>;
args: InputJsonValue;
}
const isRecord = (value: unknown): value is Record<string, unknown> =>
@@ -25,8 +26,8 @@ const isRecord = (value: unknown): value is Record<string, unknown> =>
const normalizeAction = (action: string | null | undefined): string =>
action && action.length > 0 ? action : DEFAULT_TURN_ACTION;
const normalizeArgs = (args: unknown): Record<string, unknown> =>
isRecord(args) ? args : {};
const normalizeArgs = (args: unknown): InputJsonValue =>
isRecord(args) ? (args as InputJsonValue) : {};
const createDefaultEntry = (): ReservedTurnEntry => ({
action: DEFAULT_TURN_ACTION,
+10 -10
View File
@@ -18,7 +18,7 @@ const buildDb = () => {
const generalTurns = new Map<number, GeneralTurnRow[]>();
const nationTurns = new Map<string, NationTurnRow[]>();
const db: DatabaseClient = {
const db = {
worldState: {
findFirst: async () => null,
},
@@ -32,13 +32,13 @@ const buildDb = () => {
findUnique: async () => null,
},
generalTurn: {
findMany: async ({ where }) => generalTurns.get(where.generalId) ?? [],
deleteMany: async ({ where }) => {
findMany: async ({ where }: any) => generalTurns.get(where.generalId) ?? [],
deleteMany: async ({ where }: any) => {
generalTurns.delete(where.generalId);
return {};
},
createMany: async ({ data }) => {
const rows = data.map((row, index) => ({
createMany: async ({ data }: any) => {
const rows = data.map((row: any, index: number) => ({
id: index + 1,
generalId: row.generalId,
turnIdx: row.turnIdx,
@@ -53,14 +53,14 @@ const buildDb = () => {
},
},
nationTurn: {
findMany: async ({ where }) =>
findMany: async ({ where }: any) =>
nationTurns.get(`${where.nationId}:${where.officerLevel}`) ?? [],
deleteMany: async ({ where }) => {
deleteMany: async ({ where }: any) => {
nationTurns.delete(`${where.nationId}:${where.officerLevel}`);
return {};
},
createMany: async ({ data }) => {
const rows = data.map((row, index) => ({
createMany: async ({ data }: any) => {
const rows = data.map((row: any, index: number) => ({
id: index + 1,
nationId: row.nationId,
officerLevel: row.officerLevel,
@@ -76,7 +76,7 @@ const buildDb = () => {
return {};
},
},
};
} as unknown as DatabaseClient;
return { db };
};
+5
View File
@@ -8,6 +8,11 @@ export * from './config.js';
export * from './context.js';
export * from './router.js';
export * from './server.js';
export { GatewayPrisma } from '@sammo-ts/infra';
export type JsonObject = GatewayPrisma.JsonObject;
export type JsonArray = GatewayPrisma.JsonArray;
export * from './orchestrator/profileRepository.js';
export * from './orchestrator/gatewayOrchestrator.js';
export * from './auth/userRepository.js';
export * from './auth/passwordHasher.js';
export * from './auth/inMemoryUserRepository.js';
+1 -1
View File
@@ -1,5 +1,5 @@
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../../../gateway-api/src/router';
import type { AppRouter } from '@sammo-ts/gateway-api';
const getSessionToken = (): string | null => {
if (typeof window === 'undefined') {
+3 -1
View File
@@ -33,7 +33,9 @@
"@sammo-ts/game-engine": ["../../app/game-engine/src/index.ts"],
"@sammo-ts/game-engine/*": ["../../app/game-engine/src/*"],
"@sammo-ts/game-api": ["../../app/game-api/src/index.ts"],
"@sammo-ts/game-api/*": ["../../app/game-api/src/*"]
"@sammo-ts/game-api/*": ["../../app/game-api/src/*"],
"@sammo-ts/gateway-api": ["../../app/gateway-api/src/index.ts"],
"@sammo-ts/gateway-api/*": ["../../app/gateway-api/src/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],