feat: 외교 문서 변경을 입력 원장과 함께 감사 이력으로 저장

This commit is contained in:
2026-09-16 05:46:11 +00:00
parent 8faab62866
commit b9d9b63b14
15 changed files with 576 additions and 45 deletions
+18 -2
View File
@@ -18,6 +18,7 @@ export interface ApiInputPayloadIdentity {
}
interface LockedInputEvent {
sequence: bigint;
target: 'API' | 'ENGINE';
eventType: string;
payload: GamePrisma.JsonValue;
@@ -27,6 +28,14 @@ interface LockedInputEvent {
attempts: number;
}
export interface ApiInputExecutionContext {
requestId: string;
sequence: bigint;
actorUserId: string | null;
eventType: string;
attempt: number;
}
type InputEventOutcome<T> =
{ kind: 'executed'; value: T } | { kind: 'replayed'; value: T } | { kind: 'failed'; error: unknown };
@@ -115,6 +124,7 @@ const lockInputEvent = async (db: DatabaseClient, requestId: string): Promise<Lo
const rows = await db.$queryRaw<LockedInputEvent[]>(
GamePrisma.sql`
SELECT
sequence,
target,
event_type AS "eventType",
payload,
@@ -235,7 +245,7 @@ export const executeInputEvent = async <T>(options: {
payload: unknown;
actorUserId?: string | null;
acquireClockFence?: boolean;
execute(db: DatabaseClient): Promise<T>;
execute(db: DatabaseClient, context?: ApiInputExecutionContext): Promise<T>;
}): Promise<T> => {
const { db, requestId, eventType, payload, execute } = options;
const actorUserId = options.actorUserId ?? null;
@@ -275,7 +285,13 @@ export const executeInputEvent = async <T>(options: {
await savepointDb.$executeRawUnsafe(`SAVEPOINT ${BUSINESS_SAVEPOINT}`);
businessStarted = true;
try {
const value = await execute(transaction);
const value = await execute(transaction, {
requestId,
sequence: row.sequence,
actorUserId,
eventType,
attempt: row.attempts + 1,
});
const durableResult = canonicalJsonValue(value);
await transaction.$executeRaw(GamePrisma.sql`
UPDATE input_event