kozukata-toa/src/servers/aimedb/types/handlers.ts

32 lines
974 B
TypeScript

import type { PacketHeaderStruct } from "./header";
import type { StructConstructor } from "typed-struct";
export type AimeDBHandlerReturnType<S extends string> = InstanceType<
StructConstructor<Record<string, unknown>, S>
>;
export type AimeDBReturnTypes =
| "__no_body"
| "AimeAccountExtendedResponse"
| "AimeAccountResponse"
| "AimeLogExtendedResponse"
| "CampaignClearInfoResponse"
| "CampaignResponse"
| "FelicaExtendedLookupResponse"
| "FelicaLookupResponse"
| "OldCampaignResponse";
type MaybePromise<T> = Promise<T> | T;
/**
* Base type for all AimeDB command handlers.
*
* All AimeDB handlers must modify the request header and only return the request body.
* The base handler will merge them into one.
*/
export type AimeDBHandlerFn<S extends AimeDBReturnTypes = "__no_body"> = (
header: InstanceType<typeof PacketHeaderStruct>,
data: Buffer
) => MaybePromise<(S extends "__no_body" ? never : AimeDBHandlerReturnType<S>) | null | undefined>;