import type { Router, HasRequiredKeys, Prettify, UnionToIntersection, Endpoint, HTTPMethod } from "@colyseus/better-call"; import { ColyseusSDK } from "./Client.ts"; /** * TODO: we should clean up the types repetition in this file. */ type IsAny = 0 extends 1 & T ? true : false; type IsAnyOrAnyIndexed = IsAny extends true ? true : (string extends keyof T ? true : (number extends keyof T ? (symbol extends keyof T ? true : false) : false)); type HasRequired = keyof RequiredOptionKeys extends never ? false : true; type InferContext = T extends (ctx: infer Ctx) => any ? Ctx extends object ? Ctx : never : never; type WithRequired = Prettify; }>; type WithoutServerOnly> = { [K in keyof T]: T[K] extends Endpoint ? O extends { metadata: { SERVER_ONLY: true; }; } ? never : T[K] : T[K]; }; type MethodOptions = API extends { [key: string]: infer T; } ? T extends Endpoint ? O["method"] extends M ? { [key in T["path"]]: T; } : O["method"] extends M[] ? M extends O["method"][number] ? { [key in T["path"]]: T; } : {} : O["method"] extends "*" ? { [key in T["path"]]: T; } : {} : {} : {}; type IsUndeclaredSchema = [T] extends [never] ? true : string extends keyof NonNullable ? true : false; export type RequiredOptionKeys = (IsAny extends true ? {} : NonNullable extends object ? HasRequiredKeys> extends true ? { body: true; } : {} : { body: true; }) & (IsUndeclaredSchema extends true ? {} : HasRequiredKeys> extends true ? { query: true; } : {}) & (IsUndeclaredSchema extends true ? {} : HasRequiredKeys> extends true ? { params: true; } : {}); type CommonHeaders = { accept: "application/json" | "text/plain" | "application/octet-stream"; "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream"; authorization: "Bearer" | "Basic"; }; type FetchRequestOptions = any, Params extends Record | Array | undefined = any, Res = any, ExtraOptions extends Record = {}> = Prettify & { /** * Headers */ headers?: CommonHeaders | Headers | HeadersInit; /** * Body */ body?: Body; /** * Query parameters (key-value pairs) */ query?: Query; /** * Dynamic parameters. * * If url is defined as /path/:id, params will be { id: string } */ params?: Params; }>; type FetchResponse = { raw: Response; data: T; headers: Headers; status: number; statusText: string; }; export declare function isJSONSerializable(value: any): boolean; export type ResponseType = "json" | "text" | "blob"; export declare function detectResponseType(request: Response): ResponseType; type InferredAPI = R extends { endpoints: Record; } ? WithoutServerOnly : WithoutServerOnly>; type InferReturnType = IsAnyOrAnyIndexed extends true ? any : Awaited>; export type FetchFn = (url: string | URL | Request, init?: RequestInit) => Promise; export declare class HTTP { authToken: string | undefined; options: FetchRequestOptions; private sdk; private _fetchFn; del: { = InferredAPI, OPT extends Prettify>> = UnionToIntersection> extends infer T ? { [K_1 in keyof T]: T[K_1]; } : never, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends true ? K : never), options: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : WithRequired, keyof RequiredOptionKeys>): Promise>>; = InferredAPI, OPT extends Prettify>> = UnionToIntersection> extends infer T ? { [K_1 in keyof T]: T[K_1]; } : never, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends false ? K : never), options?: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : FetchRequestOptions): Promise>>; }; constructor(sdk: ColyseusSDK, baseOptions: FetchRequestOptions, fetchFn?: FetchFn); /** * Lazily resolve the fetch implementation. * Falls back to XMLHttpRequest when fetch is unavailable (e.g. Cocos Creator Native). */ private get fetchFn(); private request; get = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends true ? K : never), options: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : WithRequired, keyof RequiredOptionKeys>): Promise>>; get = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends false ? K : never), options?: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : FetchRequestOptions): Promise>>; post = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: (IsAnyOrAnyIndexed extends true ? string : never) | (IsAny extends true ? string : never) | (HasRequired extends true ? K : never), options: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : (IsAny extends true ? FetchRequestOptions : WithRequired, keyof RequiredOptionKeys>)): Promise>>; post = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: (IsAnyOrAnyIndexed extends true ? string : never) | (IsAny extends true ? string : never) | (HasRequired extends false ? K : never), options?: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : (IsAny extends true ? FetchRequestOptions : FetchRequestOptions)): Promise>>; delete = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends true ? K : never), options: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : WithRequired, keyof RequiredOptionKeys>): Promise>>; delete = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends false ? K : never), options?: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : FetchRequestOptions): Promise>>; patch = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends true ? K : never), options: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : WithRequired, keyof RequiredOptionKeys>): Promise>>; patch = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends false ? K : never), options?: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : FetchRequestOptions): Promise>>; put = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends true ? K : never), options: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : WithRequired, keyof RequiredOptionKeys>): Promise>>; put = InferredAPI, OPT extends Prettify>> = Prettify>>, K extends keyof OPT = keyof OPT, C extends InferContext = InferContext>(path: IsAnyOrAnyIndexed extends true ? string : (HasRequired extends false ? K : never), options?: IsAnyOrAnyIndexed extends true ? FetchRequestOptions : FetchRequestOptions): Promise>>; protected executeRequest(method: M, path: any, requestOptions?: any): Promise; } export {};