134 lines
3.5 KiB
TypeScript
134 lines
3.5 KiB
TypeScript
import type { z } from "zod";
|
|
import { playerStateSchema, serverTimeSchema } from "./entities";
|
|
import {
|
|
acknowledgeSummariesRequestSchema,
|
|
acknowledgeSummariesResponseSchema,
|
|
assignPilotRequestSchema,
|
|
bayResponseSchema,
|
|
buyShipRequestSchema,
|
|
contractBoardRequestSchema,
|
|
contractBoardResponseSchema,
|
|
createDispatchRequestSchema,
|
|
createGuestResponseSchema,
|
|
dispatchResponseSchema,
|
|
emptyRequestSchema,
|
|
hirePilotRequestSchema,
|
|
leaseBayRequestSchema,
|
|
pilotResponseSchema,
|
|
shipResponseSchema,
|
|
spendSkillPointRequestSchema,
|
|
unassignPilotRequestSchema,
|
|
} from "./requests";
|
|
|
|
export interface RouteDef {
|
|
method: "GET" | "POST";
|
|
/** Under `/api` (decision 0.5.20). `:name` segments are path parameters. */
|
|
path: string;
|
|
/** Path parameters plus body: every `:name` in the path is a field here. */
|
|
request: z.ZodType;
|
|
/** Body of the 2xx response. Errors always use `errorResponseSchema`. */
|
|
response: z.ZodType;
|
|
/** Whether a session is required. */
|
|
auth: boolean;
|
|
}
|
|
|
|
/** Every endpoint of the base game: the contract between server and client. */
|
|
export const routes = {
|
|
getServerTime: {
|
|
method: "GET",
|
|
path: "/api/time",
|
|
request: emptyRequestSchema,
|
|
response: serverTimeSchema,
|
|
auth: false,
|
|
},
|
|
createGuest: {
|
|
method: "POST",
|
|
path: "/api/guest",
|
|
request: emptyRequestSchema,
|
|
response: createGuestResponseSchema,
|
|
auth: false,
|
|
},
|
|
getPlayerState: {
|
|
method: "GET",
|
|
path: "/api/state",
|
|
request: emptyRequestSchema,
|
|
response: playerStateSchema,
|
|
auth: true,
|
|
},
|
|
getContractBoard: {
|
|
method: "GET",
|
|
path: "/api/bays/:locationId/board",
|
|
request: contractBoardRequestSchema,
|
|
response: contractBoardResponseSchema,
|
|
auth: true,
|
|
},
|
|
getTutorialBoard: {
|
|
method: "GET",
|
|
path: "/api/tutorial/board",
|
|
request: emptyRequestSchema,
|
|
response: contractBoardResponseSchema,
|
|
auth: true,
|
|
},
|
|
createDispatch: {
|
|
method: "POST",
|
|
path: "/api/dispatches",
|
|
request: createDispatchRequestSchema,
|
|
response: dispatchResponseSchema,
|
|
auth: true,
|
|
},
|
|
buyShip: {
|
|
method: "POST",
|
|
path: "/api/ships",
|
|
request: buyShipRequestSchema,
|
|
response: shipResponseSchema,
|
|
auth: true,
|
|
},
|
|
leaseBay: {
|
|
method: "POST",
|
|
path: "/api/bays",
|
|
request: leaseBayRequestSchema,
|
|
response: bayResponseSchema,
|
|
auth: true,
|
|
},
|
|
hirePilot: {
|
|
method: "POST",
|
|
path: "/api/pilots",
|
|
request: hirePilotRequestSchema,
|
|
response: pilotResponseSchema,
|
|
auth: true,
|
|
},
|
|
assignPilot: {
|
|
method: "POST",
|
|
path: "/api/pilots/:pilotId/assign",
|
|
request: assignPilotRequestSchema,
|
|
response: pilotResponseSchema,
|
|
auth: true,
|
|
},
|
|
unassignPilot: {
|
|
method: "POST",
|
|
path: "/api/pilots/:pilotId/unassign",
|
|
request: unassignPilotRequestSchema,
|
|
response: pilotResponseSchema,
|
|
auth: true,
|
|
},
|
|
spendSkillPoint: {
|
|
method: "POST",
|
|
path: "/api/pilots/:pilotId/skills",
|
|
request: spendSkillPointRequestSchema,
|
|
response: pilotResponseSchema,
|
|
auth: true,
|
|
},
|
|
acknowledgeSummaries: {
|
|
method: "POST",
|
|
path: "/api/summaries/acknowledge",
|
|
request: acknowledgeSummariesRequestSchema,
|
|
response: acknowledgeSummariesResponseSchema,
|
|
auth: true,
|
|
},
|
|
} as const satisfies Record<string, RouteDef>;
|
|
|
|
export type Routes = typeof routes;
|
|
export type RouteName = keyof Routes;
|
|
export type RouteRequest<N extends RouteName> = z.input<Routes[N]["request"]>;
|
|
export type RouteResponse<N extends RouteName> = z.output<Routes[N]["response"]>;
|