feat: 타입 정의 개선 및 any 사용 제거
This commit is contained in:
@@ -14,6 +14,18 @@ const buildDb = () => {
|
||||
const generalTurns = new Map<number, GeneralTurnRow[]>();
|
||||
const nationTurns = new Map<string, NationTurnRow[]>();
|
||||
|
||||
type GeneralTurnFindManyArgs = Parameters<DatabaseClient['generalTurn']['findMany']>[0];
|
||||
type GeneralTurnDeleteManyArgs = NonNullable<Parameters<DatabaseClient['generalTurn']['deleteMany']>[0]>;
|
||||
type GeneralTurnCreateManyArgs = NonNullable<Parameters<DatabaseClient['generalTurn']['createMany']>[0]>;
|
||||
type GeneralTurnCreateManyData = GeneralTurnCreateManyArgs['data'];
|
||||
type GeneralTurnCreateManyRow = GeneralTurnCreateManyData extends Array<infer Row> ? Row : never;
|
||||
|
||||
type NationTurnFindManyArgs = Parameters<DatabaseClient['nationTurn']['findMany']>[0];
|
||||
type NationTurnDeleteManyArgs = NonNullable<Parameters<DatabaseClient['nationTurn']['deleteMany']>[0]>;
|
||||
type NationTurnCreateManyArgs = NonNullable<Parameters<DatabaseClient['nationTurn']['createMany']>[0]>;
|
||||
type NationTurnCreateManyData = NationTurnCreateManyArgs['data'];
|
||||
type NationTurnCreateManyRow = NationTurnCreateManyData extends Array<infer Row> ? Row : never;
|
||||
|
||||
const db = {
|
||||
worldState: {
|
||||
findFirst: async () => null,
|
||||
@@ -28,13 +40,18 @@ const buildDb = () => {
|
||||
findUnique: async () => null,
|
||||
},
|
||||
generalTurn: {
|
||||
findMany: async ({ where }: any) => generalTurns.get(where.generalId) ?? [],
|
||||
deleteMany: async ({ where }: any) => {
|
||||
generalTurns.delete(where.generalId);
|
||||
findMany: async (args?: GeneralTurnFindManyArgs) => {
|
||||
const generalId = typeof args?.where?.generalId === 'number' ? args.where.generalId : undefined;
|
||||
return generalId !== undefined ? (generalTurns.get(generalId) ?? []) : [];
|
||||
},
|
||||
deleteMany: async ({ where }: GeneralTurnDeleteManyArgs) => {
|
||||
if (typeof where.generalId === 'number') {
|
||||
generalTurns.delete(where.generalId);
|
||||
}
|
||||
return {};
|
||||
},
|
||||
createMany: async ({ data }: any) => {
|
||||
const rows = data.map((row: any, index: number) => ({
|
||||
createMany: async ({ data }: GeneralTurnCreateManyArgs) => {
|
||||
const rows = data.map((row: GeneralTurnCreateManyRow, index: number) => ({
|
||||
id: index + 1,
|
||||
generalId: row.generalId,
|
||||
turnIdx: row.turnIdx,
|
||||
@@ -49,13 +66,23 @@ const buildDb = () => {
|
||||
},
|
||||
},
|
||||
nationTurn: {
|
||||
findMany: async ({ where }: any) => nationTurns.get(`${where.nationId}:${where.officerLevel}`) ?? [],
|
||||
deleteMany: async ({ where }: any) => {
|
||||
nationTurns.delete(`${where.nationId}:${where.officerLevel}`);
|
||||
findMany: async (args?: NationTurnFindManyArgs) => {
|
||||
const nationId = typeof args?.where?.nationId === 'number' ? args.where.nationId : undefined;
|
||||
const officerLevel =
|
||||
typeof args?.where?.officerLevel === 'number' ? args.where.officerLevel : undefined;
|
||||
if (nationId === undefined || officerLevel === undefined) {
|
||||
return [];
|
||||
}
|
||||
return nationTurns.get(`${nationId}:${officerLevel}`) ?? [];
|
||||
},
|
||||
deleteMany: async ({ where }: NationTurnDeleteManyArgs) => {
|
||||
if (typeof where.nationId === 'number' && typeof where.officerLevel === 'number') {
|
||||
nationTurns.delete(`${where.nationId}:${where.officerLevel}`);
|
||||
}
|
||||
return {};
|
||||
},
|
||||
createMany: async ({ data }: any) => {
|
||||
const rows = data.map((row: any, index: number) => ({
|
||||
createMany: async ({ data }: NationTurnCreateManyArgs) => {
|
||||
const rows = data.map((row: NationTurnCreateManyRow, index: number) => ({
|
||||
id: index + 1,
|
||||
nationId: row.nationId,
|
||||
officerLevel: row.officerLevel,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { GameApiContext, GameProfile, WorldStateRow } from '../src/context.js';
|
||||
import type { DatabaseClient, GameApiContext, GameProfile, WorldStateRow } from '../src/context.js';
|
||||
import type { RedisConnector } from '@sammo-ts/infra';
|
||||
import { InMemoryBattleSimTransport } from '../src/battleSim/inMemoryTransport.js';
|
||||
import { InMemoryTurnDaemonTransport } from '../src/daemon/inMemoryTransport.js';
|
||||
import { appRouter } from '../src/router.js';
|
||||
@@ -43,12 +44,12 @@ const buildContext = (options?: {
|
||||
},
|
||||
};
|
||||
return {
|
||||
db: db as any,
|
||||
db: db as unknown as DatabaseClient,
|
||||
turnDaemon: transport,
|
||||
battleSim,
|
||||
profile,
|
||||
auth: null,
|
||||
redis: {} as any,
|
||||
redis: {} as unknown as RedisConnector['client'],
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -3,9 +3,11 @@ import { describe, expect, it } from 'vitest';
|
||||
import { InMemoryGatewaySessionService } from '../src/auth/inMemorySessionService.js';
|
||||
import { createInMemoryUserRepository } from '../src/auth/inMemoryUserRepository.js';
|
||||
import { InMemoryOAuthSessionStore } from '../src/auth/oauthSessionStore.js';
|
||||
import type { KakaoOAuthClient } from '../src/auth/kakaoClient.js';
|
||||
import { createGatewayApiContext } from '../src/context.js';
|
||||
import { InMemoryProfileStatusService } from '../src/lobby/profileStatusService.js';
|
||||
import { appRouter } from '../src/router.js';
|
||||
import type { GatewayPrismaClient } from '@sammo-ts/infra';
|
||||
|
||||
const buildCaller = () => {
|
||||
const users = createInMemoryUserRepository();
|
||||
@@ -76,14 +78,14 @@ const buildCaller = () => {
|
||||
flushPublisher,
|
||||
gameTokenSecret: 'test-secret',
|
||||
gameSessionTtlSeconds: 600,
|
||||
kakaoClient: kakaoClient as any,
|
||||
kakaoClient: kakaoClient as unknown as KakaoOAuthClient,
|
||||
oauthSessions,
|
||||
publicBaseUrl: 'http://localhost',
|
||||
profiles,
|
||||
orchestrator,
|
||||
profileStatus,
|
||||
requestHeaders: {},
|
||||
prisma: {} as any,
|
||||
prisma: {} as unknown as GatewayPrismaClient,
|
||||
})
|
||||
);
|
||||
return { caller, oauthSessions };
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import type { inferRouterOutputs } from '@trpc/server';
|
||||
import type { AppRouter } from '@sammo-ts/gateway-api';
|
||||
import DefaultLayout from '../layouts/DefaultLayout.vue';
|
||||
import { trpc } from '../utils/trpc';
|
||||
import { createGameTrpc } from '../utils/gameTrpc';
|
||||
import type { GameRouter } from '../utils/gameTrpc';
|
||||
|
||||
type GatewayRouterOutput = inferRouterOutputs<AppRouter>;
|
||||
type GameRouterOutput = inferRouterOutputs<GameRouter>;
|
||||
type MeOutput = GatewayRouterOutput['me'];
|
||||
type LobbyProfile = GatewayRouterOutput['lobby']['profiles'][number];
|
||||
type LobbyInfo = GameRouterOutput['lobby']['info'];
|
||||
|
||||
const router = useRouter();
|
||||
const me = ref<any>(null);
|
||||
const me = ref<MeOutput>(null);
|
||||
const notice = ref('');
|
||||
const profiles = ref<any[]>([]);
|
||||
const profileDetails = ref<Record<string, any>>({});
|
||||
const profiles = ref<LobbyProfile[]>([]);
|
||||
const profileDetails = ref<Record<string, LobbyInfo | undefined>>({});
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user