feat: GamePrisma를 사용하여 데이터베이스 클라이언트 및 관련 타입 정의 업데이트
This commit is contained in:
+11
-112
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
@@ -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,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') {
|
||||
|
||||
@@ -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"],
|
||||
|
||||
+12
-88
@@ -1,89 +1,13 @@
|
||||
export interface DatabaseClient<
|
||||
WorldStateRow = unknown,
|
||||
GeneralRow = unknown,
|
||||
CityRow = unknown,
|
||||
NationRow = unknown,
|
||||
GeneralTurnRow = unknown,
|
||||
NationTurnRow = unknown,
|
||||
TroopRow = unknown
|
||||
> {
|
||||
$transaction<T = unknown>(
|
||||
queries: Array<Promise<T>>
|
||||
): Promise<T[]>;
|
||||
$queryRaw<T = unknown>(
|
||||
query: TemplateStringsArray,
|
||||
...values: unknown[]
|
||||
): Promise<T>;
|
||||
worldState: {
|
||||
findFirst(args?: unknown): Promise<WorldStateRow | null>;
|
||||
};
|
||||
general: {
|
||||
findUnique(args: { where: { id: number } }): Promise<GeneralRow | null>;
|
||||
findFirst(args: {
|
||||
where: { userId?: string; npcState?: number | { gt: number } };
|
||||
select?: { name?: boolean; picture?: boolean };
|
||||
}): Promise<GeneralRow | null>;
|
||||
findMany(args: {
|
||||
where?: { nationId?: number };
|
||||
}): Promise<GeneralRow[]>;
|
||||
count(args?: {
|
||||
where?: { npcState?: number | { gt: number } };
|
||||
}): Promise<number>;
|
||||
update(args: {
|
||||
where: { id: number };
|
||||
data: Partial<GeneralRow>;
|
||||
}): Promise<GeneralRow>;
|
||||
updateMany(args: {
|
||||
where: { troopId?: number };
|
||||
data: Partial<GeneralRow>;
|
||||
}): Promise<unknown>;
|
||||
};
|
||||
city: {
|
||||
findUnique(args: { where: { id: number } }): Promise<CityRow | null>;
|
||||
};
|
||||
nation: {
|
||||
findUnique(args: { where: { id: number } }): Promise<NationRow | null>;
|
||||
count(args?: { where?: { level?: { gt: number } } }): Promise<number>;
|
||||
};
|
||||
generalTurn: {
|
||||
findMany(args: {
|
||||
where: { generalId: number };
|
||||
orderBy?: { turnIdx: 'asc' | 'desc' }[];
|
||||
}): Promise<GeneralTurnRow[]>;
|
||||
deleteMany(args: { where: { generalId: number } }): Promise<unknown>;
|
||||
createMany(args: {
|
||||
data: Array<{
|
||||
generalId: number;
|
||||
turnIdx: number;
|
||||
actionCode: string;
|
||||
arg: unknown;
|
||||
}>;
|
||||
}): Promise<unknown>;
|
||||
};
|
||||
nationTurn: {
|
||||
findMany(args: {
|
||||
where: { nationId: number; officerLevel: number };
|
||||
orderBy?: { turnIdx: 'asc' | 'desc' }[];
|
||||
}): Promise<NationTurnRow[]>;
|
||||
deleteMany(args: {
|
||||
where: { nationId: number; officerLevel: number };
|
||||
}): Promise<unknown>;
|
||||
createMany(args: {
|
||||
data: Array<{
|
||||
nationId: number;
|
||||
officerLevel: number;
|
||||
turnIdx: number;
|
||||
actionCode: string;
|
||||
arg: unknown;
|
||||
}>;
|
||||
}): Promise<unknown>;
|
||||
};
|
||||
troop: {
|
||||
findUnique(args: {
|
||||
where: { troopLeaderId: number };
|
||||
}): Promise<TroopRow | null>;
|
||||
deleteMany(args: {
|
||||
where: { troopLeaderId: number };
|
||||
}): Promise<unknown>;
|
||||
};
|
||||
import type { GamePrisma, GamePrismaClient } from './gamePrisma.js';
|
||||
|
||||
export interface DatabaseClient {
|
||||
$transaction: GamePrismaClient['$transaction'];
|
||||
$queryRaw: GamePrismaClient['$queryRaw'];
|
||||
worldState: GamePrisma.WorldStateDelegate;
|
||||
general: GamePrisma.GeneralDelegate;
|
||||
city: GamePrisma.CityDelegate;
|
||||
nation: GamePrisma.NationDelegate;
|
||||
generalTurn: GamePrisma.GeneralTurnDelegate;
|
||||
nationTurn: GamePrisma.NationTurnDelegate;
|
||||
troop: GamePrisma.TroopDelegate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user