feat: refactor DatabaseClient interface and add db module
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type { GameSessionTokenPayload } from '@sammo-ts/common';
|
import type { GameSessionTokenPayload } from '@sammo-ts/common';
|
||||||
import type { Prisma } from '@prisma/client';
|
import type { DatabaseClient as InfraDatabaseClient } from '@sammo-ts/infra';
|
||||||
|
|
||||||
import type { TurnDaemonTransport } from './daemon/transport.js';
|
import type { TurnDaemonTransport } from './daemon/transport.js';
|
||||||
|
|
||||||
@@ -100,54 +100,14 @@ export interface NationRow {
|
|||||||
meta: unknown;
|
meta: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DatabaseClient {
|
export type DatabaseClient = InfraDatabaseClient<
|
||||||
$queryRaw<T = unknown>(query: Prisma.Sql): Promise<T>;
|
WorldStateRow,
|
||||||
worldState: {
|
GeneralRow,
|
||||||
findFirst(args?: unknown): Promise<WorldStateRow | null>;
|
CityRow,
|
||||||
};
|
NationRow,
|
||||||
general: {
|
GeneralTurnRow,
|
||||||
findUnique(args: { where: { id: number } }): Promise<GeneralRow | null>;
|
NationTurnRow
|
||||||
};
|
>;
|
||||||
city: {
|
|
||||||
findUnique(args: { where: { id: number } }): Promise<CityRow | null>;
|
|
||||||
};
|
|
||||||
nation: {
|
|
||||||
findUnique(args: { where: { id: number } }): Promise<NationRow | null>;
|
|
||||||
};
|
|
||||||
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>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GameApiContext {
|
export interface GameApiContext {
|
||||||
db: DatabaseClient;
|
db: DatabaseClient;
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
export interface DatabaseClient<
|
||||||
|
WorldStateRow = unknown,
|
||||||
|
GeneralRow = unknown,
|
||||||
|
CityRow = unknown,
|
||||||
|
NationRow = unknown,
|
||||||
|
GeneralTurnRow = unknown,
|
||||||
|
NationTurnRow = unknown
|
||||||
|
> {
|
||||||
|
$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>;
|
||||||
|
};
|
||||||
|
city: {
|
||||||
|
findUnique(args: { where: { id: number } }): Promise<CityRow | null>;
|
||||||
|
};
|
||||||
|
nation: {
|
||||||
|
findUnique(args: { where: { id: number } }): Promise<NationRow | null>;
|
||||||
|
};
|
||||||
|
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>;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './postgres.js';
|
export * from './postgres.js';
|
||||||
|
export * from './db.js';
|
||||||
export * from './logRepository.js';
|
export * from './logRepository.js';
|
||||||
export * from './redis.js';
|
export * from './redis.js';
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"composite": true,
|
"composite": true,
|
||||||
|
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
"target": "ES2023",
|
"target": "ES2023",
|
||||||
|
|||||||
Reference in New Issue
Block a user