import schema from "@/api/API.json" assert { type: "json" }; import { API, Error } from "@/api/API"; import { nanoid } from "nanoid"; import { Schema as Inventory } from "@/api/Inventory"; export type OperationNames = keyof API; export type OperationArgs = API[T]["arguments"]; export type OperationResponse = API[T]["return"]; export type ApiEnvelope = | { status: "success"; data: T; op_key: string; } | Error; export type Services = NonNullable; export type ServiceNames = keyof Services; export type ClanService = Services[T]; export type ClanServiceInstance = NonNullable< Services[T] >[string]; export type SuccessQuery = Extract< OperationResponse, { status: "success" } >; export type SuccessData = SuccessQuery["data"]; export type ErrorQuery = Extract< OperationResponse, { status: "error" } >; export type ErrorData = ErrorQuery["errors"]; export type ClanOperations = { [K in OperationNames]: (str: string) => void; }; export interface GtkResponse { result: T; op_key: string; } export const callApi = async ( method: K, args: OperationArgs, ): Promise> => { console.log("Calling API", method, args); const response = await ( window as unknown as Record< OperationNames, ( args: OperationArgs, ) => Promise> > )[method](args); return response as OperationResponse; };