import Lacuna from '../lacuna'; import { spliceBuildingIds } from './util'; import type { ServerResponse } from './server'; abstract class Endpoint { abstract lacuna: Lacuna; abstract module: string; callWithSession(method: string, params: any) { return this.lacuna.server.call({ module: this.module, method, params, addSession: true }); } /** * Wraps a call whose result carries an id-keyed `buildings` map, splicing the * map key onto each row as `id` (see util#spliceBuildingIds). */ protected withBuildingIds(promise: Promise>): Promise> { return promise.then((res) => { const buildings = (res.result as { buildings?: Record } | undefined) ?.buildings; if (buildings) spliceBuildingIds(buildings); return res; }); } callWithoutSession(method: string, params: any) { return this.lacuna.server.call({ module: this.module, method, params, addSession: false }); } /** For RPC methods with no working /v2 equivalent. See Server#callLegacy. */ callLegacyWithSession(method: string, params: any) { return this.lacuna.server.callLegacy({ module: this.module, method, params, addSession: true, }); } } export default Endpoint;