feat: eslint 적용 및 관련 코드 일괄 수정

This commit is contained in:
2026-01-05 15:46:47 +00:00
parent cb312f02b3
commit c965b1120f
387 changed files with 39808 additions and 38800 deletions
@@ -10,9 +10,7 @@ export const getNextTickTime = (lastTurnTime: Date, turnTermMinutes: number): Da
// 월 기준 턴 그리드에 맞춰 다음 틱 경계를 계산한다.
const base = getCutTurnBase(lastTurnTime);
const elapsedMinutes = Math.floor(
(lastTurnTime.getTime() - base.getTime()) / MINUTES_TO_MS
);
const elapsedMinutes = Math.floor((lastTurnTime.getTime() - base.getTime()) / MINUTES_TO_MS);
const alignedMinutes = elapsedMinutes - (elapsedMinutes % turnTermMinutes);
return new Date(base.getTime() + (alignedMinutes + turnTermMinutes) * MINUTES_TO_MS);
};
@@ -11,19 +11,14 @@ export interface TurnDaemonStreamKeys {
eventStream: string;
}
export const buildTurnDaemonStreamKeys = (
profileName: string
): TurnDaemonStreamKeys => ({
export const buildTurnDaemonStreamKeys = (profileName: string): TurnDaemonStreamKeys => ({
commandStream: `sammo:${profileName}:turn-daemon:commands`,
eventStream: `sammo:${profileName}:turn-daemon:events`,
});
interface RedisStreamClient {
xAdd(stream: string, id: string, message: Record<string, string>): Promise<string>;
xRead(
streams: { key: string; id: string },
options?: { BLOCK?: number; COUNT?: number }
): Promise<unknown>;
xRead(streams: { key: string; id: string }, options?: { BLOCK?: number; COUNT?: number }): Promise<unknown>;
}
type RedisStreamReadResponse = Array<{
@@ -68,18 +63,13 @@ const parseCommandEnvelope = (raw: string): TurnDaemonCommandEnvelope | null =>
}
};
const normalizeCommand = (
envelope: TurnDaemonCommandEnvelope
): TurnDaemonCommand | null => {
const normalizeCommand = (envelope: TurnDaemonCommandEnvelope): TurnDaemonCommand | null => {
const command = envelope.command as TurnDaemonCommand & {
requestId?: string;
};
switch (command.type) {
case 'troopJoin': {
if (
typeof command.generalId !== 'number' ||
typeof command.troopId !== 'number'
) {
if (typeof command.generalId !== 'number' || typeof command.troopId !== 'number') {
return null;
}
return {
@@ -100,10 +90,7 @@ const normalizeCommand = (
};
}
case 'getStatus': {
const requestId =
typeof command.requestId === 'string'
? command.requestId
: envelope.requestId;
const requestId = typeof command.requestId === 'string' ? command.requestId : envelope.requestId;
return { type: 'getStatus', requestId };
}
case 'run':
@@ -116,9 +103,7 @@ const normalizeCommand = (
}
};
export class RedisTurnDaemonCommandStream
implements TurnDaemonControlQueue, TurnDaemonCommandResponder
{
export class RedisTurnDaemonCommandStream implements TurnDaemonControlQueue, TurnDaemonCommandResponder {
private readonly client: RedisStreamClient;
private readonly keys: TurnDaemonStreamKeys;
private readonly localQueue: TurnDaemonCommand[] = [];
@@ -151,10 +136,7 @@ export class RedisTurnDaemonCommandStream
return this.localQueue.shift() ?? null;
}
const blockMs =
deadlineMs === null
? 0
: Math.max(0, deadlineMs - Date.now());
const blockMs = deadlineMs === null ? 0 : Math.max(0, deadlineMs - Date.now());
if (deadlineMs !== null && blockMs === 0) {
return null;
}
@@ -174,24 +156,15 @@ export class RedisTurnDaemonCommandStream
return this.localQueue.length;
}
async publishStatus(
requestId: string,
status: TurnDaemonStatus
): Promise<void> {
async publishStatus(requestId: string, status: TurnDaemonStatus): Promise<void> {
await this.publishEvent({ type: 'status', requestId, status }, requestId);
}
async publishCommandResult(
requestId: string,
result: TurnDaemonCommandResult
): Promise<void> {
async publishCommandResult(requestId: string, result: TurnDaemonCommandResult): Promise<void> {
await this.publishEvent({ type: 'commandResult', result }, requestId);
}
private async publishEvent(
event: TurnDaemonEvent,
requestId?: string
): Promise<void> {
private async publishEvent(event: TurnDaemonEvent, requestId?: string): Promise<void> {
const envelope: TurnDaemonEventEnvelope = {
requestId,
sentAt: new Date().toISOString(),
@@ -185,9 +185,10 @@ export class TurnDaemonLifecycle {
const nextGeneralTurnTime = await this.stateStore.loadNextGeneralTurnTime();
const nextTickTime = this.getNextTickTime(lastTurnTime);
// 가장 빠른 장수 턴과 현재 틱 경계 중 먼저 오는 시각을 선택한다.
const nextTurnTime = nextGeneralTurnTime && nextGeneralTurnTime.getTime() <= nextTickTime.getTime()
? nextGeneralTurnTime
: nextTickTime;
const nextTurnTime =
nextGeneralTurnTime && nextGeneralTurnTime.getTime() <= nextTickTime.getTime()
? nextGeneralTurnTime
: nextTickTime;
this.status.nextTurnTime = nextTurnTime.toISOString();
return nextTurnTime;
@@ -228,10 +229,7 @@ export class TurnDaemonLifecycle {
return;
case 'getStatus': {
if (command.requestId) {
await this.commandResponder?.publishStatus(
command.requestId,
this.getStatus()
);
await this.commandResponder?.publishStatus(command.requestId, this.getStatus());
}
return;
}
@@ -277,9 +275,7 @@ export class TurnDaemonLifecycle {
): Promise<void> {
let result: TurnDaemonCommandResult | null = null;
try {
result = this.commandHandler
? await this.commandHandler.handle(command)
: null;
result = this.commandHandler ? await this.commandHandler.handle(command) : null;
if (!result) {
result = {
type: command.type,
@@ -290,8 +286,7 @@ export class TurnDaemonLifecycle {
} as TurnDaemonCommandResult;
}
} catch (error) {
const reason =
error instanceof Error ? error.message : 'Unknown command error.';
const reason = error instanceof Error ? error.message : 'Unknown command error.';
result = {
type: command.type,
ok: false,
@@ -302,10 +297,7 @@ export class TurnDaemonLifecycle {
}
if (this.commandResponder && command.requestId) {
await this.commandResponder.publishCommandResult(
command.requestId,
result
);
await this.commandResponder.publishCommandResult(command.requestId, result);
}
}
@@ -327,8 +319,7 @@ export class TurnDaemonLifecycle {
this.status.state = 'paused';
this.status.paused = true;
this.errorPaused = true;
this.status.lastError =
error instanceof Error ? error.message : 'Unknown turn daemon error.';
this.status.lastError = error instanceof Error ? error.message : 'Unknown turn daemon error.';
await this.hooks?.onRunError?.(error);
return;
} finally {
+1 -4
View File
@@ -24,10 +24,7 @@ export interface TurnDaemonCommandHandler {
export interface TurnDaemonCommandResponder {
publishStatus(requestId: string, status: TurnDaemonStatus): Promise<void>;
publishCommandResult(
requestId: string,
result: TurnDaemonCommandResult
): Promise<void>;
publishCommandResult(requestId: string, result: TurnDaemonCommandResult): Promise<void>;
}
export type { Clock } from '@sammo-ts/common';