feat: Zod를 사용한 월드 상태 구성 및 메타 타입 추가, 사용자 ID 처리 개선
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
createGamePostgresConnector,
|
||||
type InputJsonValue,
|
||||
type TurnEngineDatabaseClient,
|
||||
type TurnEngineEventCreateManyInput,
|
||||
} from '@sammo-ts/infra';
|
||||
import {
|
||||
@@ -125,7 +124,7 @@ export const seedScenarioToDatabase = async (
|
||||
|
||||
await connector.connect();
|
||||
try {
|
||||
const prisma = connector.prisma as unknown as TurnEngineDatabaseClient;
|
||||
const prisma = connector.prisma;
|
||||
|
||||
if (options.resetTables ?? true) {
|
||||
await prisma.event.deleteMany();
|
||||
|
||||
@@ -2,7 +2,6 @@ import {
|
||||
createGamePostgresConnector,
|
||||
type InputJsonValue,
|
||||
type TurnEngineCityUpdateInput,
|
||||
type TurnEngineDatabaseClient,
|
||||
type TurnEngineDiplomacyCreateManyInput,
|
||||
type TurnEngineDiplomacyUpdateInput,
|
||||
type TurnEngineGeneralCreateManyInput,
|
||||
@@ -238,7 +237,7 @@ export const createDatabaseTurnHooks = async (
|
||||
// 턴 처리 결과를 DB에 반영하는 훅을 만든다.
|
||||
const connector = createGamePostgresConnector({ url: databaseUrl });
|
||||
await connector.connect();
|
||||
const prisma = connector.prisma as unknown as TurnEngineDatabaseClient;
|
||||
const prisma = connector.prisma;
|
||||
|
||||
const hooks: TurnDaemonHooks = {
|
||||
flushChanges: async () => {
|
||||
@@ -346,8 +345,10 @@ export const createDatabaseTurnHooks = async (
|
||||
.map((entry) =>
|
||||
prisma.diplomacy.update({
|
||||
where: {
|
||||
srcNationId: entry.fromNationId,
|
||||
destNationId: entry.toNationId,
|
||||
srcNationId_destNationId: {
|
||||
srcNationId: entry.fromNationId,
|
||||
destNationId: entry.toNationId,
|
||||
},
|
||||
},
|
||||
data: buildDiplomacyUpdate(entry),
|
||||
})
|
||||
|
||||
@@ -36,15 +36,6 @@ export interface GatewayAdminActionConsumer {
|
||||
stop(): Promise<void>;
|
||||
}
|
||||
|
||||
type GatewayProfileRow = {
|
||||
meta: unknown;
|
||||
};
|
||||
|
||||
type GatewayProfileClient = {
|
||||
findUnique(args: unknown): Promise<GatewayProfileRow | null>;
|
||||
update(args: unknown): Promise<void>;
|
||||
};
|
||||
|
||||
const DEFAULT_POLL_MS = 5000;
|
||||
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
||||
@@ -75,9 +66,7 @@ export const createGatewayAdminActionConsumer = async (
|
||||
url: options.gatewayDatabaseUrl ?? options.databaseUrl,
|
||||
});
|
||||
await connector.connect();
|
||||
const prisma = connector.prisma as unknown as {
|
||||
gatewayProfile: GatewayProfileClient;
|
||||
};
|
||||
const prisma = connector.prisma;
|
||||
|
||||
let timer: NodeJS.Timeout | null = null;
|
||||
let inFlight = false;
|
||||
|
||||
@@ -18,15 +18,6 @@ const DEFAULT_CACHE_MS = 2000;
|
||||
const isRunningStatus = (status: string | null | undefined): boolean =>
|
||||
status === 'RUNNING';
|
||||
|
||||
type GatewayProfileRow = {
|
||||
status: string | null;
|
||||
};
|
||||
|
||||
type GatewayProfileClient = {
|
||||
findUnique(args: unknown): Promise<GatewayProfileRow | null>;
|
||||
update(args: unknown): Promise<void>;
|
||||
};
|
||||
|
||||
export const createGatewayProfileGate = async (
|
||||
options: GatewayProfileGateOptions
|
||||
): Promise<GatewayProfileGate> => {
|
||||
@@ -34,9 +25,7 @@ export const createGatewayProfileGate = async (
|
||||
url: options.gatewayDatabaseUrl ?? options.databaseUrl,
|
||||
});
|
||||
await connector.connect();
|
||||
const prisma = connector.prisma as unknown as {
|
||||
gatewayProfile: GatewayProfileClient;
|
||||
};
|
||||
const prisma = connector.prisma;
|
||||
let lastCheckedAt = 0;
|
||||
let cachedPause = false;
|
||||
|
||||
|
||||
@@ -272,7 +272,7 @@ export const createReservedTurnStore = async (
|
||||
const connector = createGamePostgresConnector({ url: options.databaseUrl });
|
||||
await connector.connect();
|
||||
const store = new InMemoryReservedTurnStore(
|
||||
connector.prisma as unknown as ReservedTurnDatabaseClient,
|
||||
connector.prisma,
|
||||
{
|
||||
maxGeneralTurns: options.maxGeneralTurns ?? DEFAULT_GENERAL_TURNS,
|
||||
maxNationTurns: options.maxNationTurns ?? DEFAULT_NATION_TURNS,
|
||||
|
||||
@@ -255,7 +255,7 @@ export const loadTurnWorldFromDatabase = async (
|
||||
const connector = createGamePostgresConnector({ url: options.databaseUrl });
|
||||
await connector.connect();
|
||||
try {
|
||||
const prisma = connector.prisma as unknown as TurnEngineDatabaseClient;
|
||||
const prisma: TurnEngineDatabaseClient = connector.prisma;
|
||||
const worldState = await prisma.worldState.findFirst();
|
||||
if (!worldState) {
|
||||
throw new Error('world_state row is required to start turn daemon.');
|
||||
|
||||
Reference in New Issue
Block a user