From 826b4212e54deb50b7e3221c828123234b6d24d0 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 6 Aug 2023 09:27:24 +0000 Subject: [PATCH] =?UTF-8?q?=EA=B0=95=EB=A0=A5=ED=95=9C=20API=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/Login/LoginByID.ts | 15 + server/api/Login/LoginByToken.ts | 15 + server/api/Login/ReqNonce.ts | 15 + server/api/Login/index.ts | 11 + server/api/base.ts | 51 ++-- server/api/serverAPI.ts | 17 +- .../clientAPI.ts => apiStructure/defs.ts} | 136 +++------ server/apiStructure/sammoRootAPI.ts | 45 +++ server/clientAPI/generator.ts | 81 ++++++ server/clientAPI/sammoRootAPI.ts | 51 +--- server/util/callSammoAPI.ts | 274 ------------------ 11 files changed, 266 insertions(+), 445 deletions(-) create mode 100644 server/api/Login/LoginByID.ts create mode 100644 server/api/Login/LoginByToken.ts create mode 100644 server/api/Login/ReqNonce.ts create mode 100644 server/api/Login/index.ts rename server/{clientAPI/clientAPI.ts => apiStructure/defs.ts} (60%) create mode 100644 server/apiStructure/sammoRootAPI.ts create mode 100644 server/clientAPI/generator.ts delete mode 100644 server/util/callSammoAPI.ts diff --git a/server/api/Login/LoginByID.ts b/server/api/Login/LoginByID.ts new file mode 100644 index 0000000..d7daf23 --- /dev/null +++ b/server/api/Login/LoginByID.ts @@ -0,0 +1,15 @@ +import { POST } from "../base"; +import type { structure } from "../../apiStructure/sammoRootAPI"; +import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs"; + +type BaseAPI = typeof structure.Login.LoginByID; +type RType = ExtractResponse; +type EType = ExtractError; +type QType = ExtractQuery; + +export class LoginByID extends POST{ + protected LoginByID = Symbol("LoginByID");//TODO: remove this + protected override async api(query: QType): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/server/api/Login/LoginByToken.ts b/server/api/Login/LoginByToken.ts new file mode 100644 index 0000000..ad4582e --- /dev/null +++ b/server/api/Login/LoginByToken.ts @@ -0,0 +1,15 @@ +import { POST } from "../base"; +import type { structure } from "../../apiStructure/sammoRootAPI"; +import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs"; + +type BaseAPI = typeof structure.Login.LoginByToken; +type RType = ExtractResponse; +type EType = ExtractError; +type QType = ExtractQuery; + +export class LoginByToken extends POST{ + protected LoginByToken = Symbol("LoginByToken");//TODO: remove this + protected override async api(query: QType): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/server/api/Login/ReqNonce.ts b/server/api/Login/ReqNonce.ts new file mode 100644 index 0000000..04e3547 --- /dev/null +++ b/server/api/Login/ReqNonce.ts @@ -0,0 +1,15 @@ +import { POST } from "../base"; +import type { structure } from "../../apiStructure/sammoRootAPI"; +import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs"; + +type BaseAPI = typeof structure.Login.ReqNonce; +type RType = ExtractResponse; +type EType = ExtractError; +type QType = ExtractQuery; + +export class ReqNonce extends POST{ + protected ReqNonce = Symbol("ReqNonce");//TODO: remove this + protected override async api(query: QType): Promise { + throw new Error("Method not implemented."); + } +} \ No newline at end of file diff --git a/server/api/Login/index.ts b/server/api/Login/index.ts new file mode 100644 index 0000000..1cef147 --- /dev/null +++ b/server/api/Login/index.ts @@ -0,0 +1,11 @@ +import { structure } from "../../apiStructure/sammoRootAPI"; +import { APINamespaceType } from "../base"; +import { LoginByID } from "./LoginByID"; +import { LoginByToken } from "./LoginByToken"; +import { ReqNonce } from "./ReqNonce"; + +export const Login = { + LoginByID, + LoginByToken, + ReqNonce, +} satisfies APINamespaceType; \ No newline at end of file diff --git a/server/api/base.ts b/server/api/base.ts index 9201658..3f43b90 100644 --- a/server/api/base.ts +++ b/server/api/base.ts @@ -1,22 +1,8 @@ import type { Request, Response } from 'express'; - -export interface ValidResponse { - result: true; -} - -export type recoveryMethod = 'refreshEntirePage' | 'retryAPI' | 'gameLogin' | 'gatewayLogin' | 'gatewayPIN'; - -export interface InvalidResponse { - result: false; - reason: string; - recovery?: recoveryMethod; -} +import type { APICallT, Callable, DefAPINamespace, EmptyAPICallT, HttpMethod, InvalidResponse, RawArgType, ValidResponse, recoveryMethod } from '../apiStructure/defs'; export const treatedSpecial = Symbol('treatedSpecial'); -export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head'; -export type RawArgType = Record | Record[] | undefined; - export type APINamespace = { [key: string]: APINamespace | GET @@ -29,14 +15,14 @@ export type APINamespace = { } export abstract class APIExecuter{ - readonly abstract reqType: HttpMethod | HttpMethod[]; + readonly abstract reqType: HttpMethod; protected abstract parseQuery(expressReq: Request): Promise; - protected abstract api(query: Q, expressReq: Request, expressRes: Response): Promise; + protected abstract api(query: Q, expressReq: Request, expressRes: Response): Promise; public async run(expressReq: Request, expressRes: Response): Promise { const query = await this.parseQuery(expressReq); //TODO: middleware (인증, 요구사항, 아마도 decorator) const result = await this.api(query, expressReq, expressRes); - if (result === treatedSpecial) { + if (result === true) { return; } expressRes.json(result); @@ -77,4 +63,31 @@ export abstract class PATCH extends APIBodyParseExecuter{ readonly reqType = 'head'; -} \ No newline at end of file +} + +export function raiseError(reason: string, recovery?: recoveryMethod): InvalidResponse { + if (recovery) { + return { + result: false, + reason, + recovery, + }; + } + return { + result: false, + reason, + }; +} + +export type GetClassGenerator = { + prototype: T +}; +export type APIServerType = + T extends APICallT ? GetClassGenerator> : + never; +export type APINamespaceType = { + [K in keyof T]: + T[K] extends Callable ? APIServerType : + T[K] extends DefAPINamespace ? APINamespaceType : + never; +}; \ No newline at end of file diff --git a/server/api/serverAPI.ts b/server/api/serverAPI.ts index 9752086..234490d 100644 --- a/server/api/serverAPI.ts +++ b/server/api/serverAPI.ts @@ -6,20 +6,13 @@ export function buildAPISystem { - await executer.run(req, res); - }); - continue; - } - for(const type of new Set(executer.reqType)){ - router[type](key, async (req, res) => { - await executer.run(req, res); - }); - } + router[executer.reqType](key, async (req, res) => { + await executer.run(req, res); + }); + continue; } else { router.use(key, buildAPISystem(value)); } diff --git a/server/clientAPI/clientAPI.ts b/server/apiStructure/defs.ts similarity index 60% rename from server/clientAPI/clientAPI.ts rename to server/apiStructure/defs.ts index 754daa9..d17ca37 100644 --- a/server/clientAPI/clientAPI.ts +++ b/server/apiStructure/defs.ts @@ -1,11 +1,10 @@ -import ky from 'ky'; -import type { APIExecuter, APINamespace, HttpMethod, InvalidResponse, RawArgType, ValidResponse } from '../api/base.js'; -import isArray from 'lodash-es/isArray.js'; -import isEmpty from 'lodash-es/isEmpty.js'; +import { APIExecuter } from "../api/base"; -const apiPath = process.env.API_ROOT_PATH ?? process.env.VITE_API_ROOT_PATH ?? '/api'; +export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head'; +export type RawArgType = Record | Record[] | undefined; -interface BasicAPICallT< + +export interface BasicAPICallT< ArgType extends RawArgType, ResultType extends ValidResponse, ErrorType extends InvalidResponse @@ -15,7 +14,7 @@ interface BasicAPICallT< (args: ArgType, returnError: true): Promise; } -interface EmptyAPICallT { +export interface EmptyAPICallT { (): Promise; (args: undefined): Promise; (args: undefined, returnError: false): Promise; @@ -65,8 +64,7 @@ export async function GET< ErrorType extends InvalidResponse, ArgType extends undefined = undefined >(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call GET. ${args}, ${returnError}. Use auto-generated path API.`); - return callClientAPI("get", [], args, undefined, true); + throw `Can't directly call GET. ${args}, ${returnError}. Use auto-generated path API.` } export async function POST( @@ -86,8 +84,7 @@ export async function POST< ErrorType extends InvalidResponse, ArgType extends RawArgType = RawArgType >(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call POST. ${args}, ${returnError}. Use auto-generated path API.`); - return callClientAPI("post", [], args, undefined, true); + throw `Can't directly call POST. ${args}, ${returnError}. Use auto-generated path API.` } export async function PUT( @@ -107,8 +104,7 @@ export async function PUT< ErrorType extends InvalidResponse, ArgType extends RawArgType = RawArgType >(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call PUT. ${args}, ${returnError}. Use auto-generated path API.`); - return callClientAPI("put", [], args, undefined, true); + throw `Can't directly call PUT. ${args}, ${returnError}. Use auto-generated path API.`; } export async function PATCH( @@ -128,8 +124,7 @@ export async function PATCH< ErrorType extends InvalidResponse, ArgType extends RawArgType = RawArgType >(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call PATCH. ${args}, ${returnError}. Use auto-generated path API.`); - return callClientAPI("patch", [], args, undefined, true); + throw `Can't directly call PATCH. ${args}, ${returnError}. Use auto-generated path API.` } export async function HEAD( @@ -149,8 +144,7 @@ export async function HEAD< ErrorType extends InvalidResponse, ArgType extends undefined = undefined >(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call HEAD. ${args}, ${returnError}. Use auto-generated path API.`); - return callClientAPI("head", [], args, undefined, true); + throw `Can't directly call HEAD. ${args}, ${returnError}. Use auto-generated path API.`; } export async function DELETE( @@ -170,85 +164,39 @@ export async function DELETE< ErrorType extends InvalidResponse, ArgType extends RawArgType = RawArgType >(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call DELETE. ${args}, ${returnError}. Use auto-generated path API.`); - return callClientAPI("patch", [], args, undefined, true); + throw `Can't directly call DELETE. ${args}, ${returnError}. Use auto-generated path API.`; } -export async function callClientAPI( - method: HttpMethod, - path: string | string[], - args: RawArgType, - paramArgs: Record | undefined -): Promise; -export async function callClientAPI( - method: HttpMethod, - path: string | string[], - args: RawArgType, - paramArgs: Record | undefined, - returnError: false -): Promise; -export async function callClientAPI( - method: HttpMethod, - path: string | string[], - args: RawArgType, - paramArgs: Record | undefined, - returnError: true -): Promise; -export async function callClientAPI( - method: HttpMethod, - path: string | string[], - args: RawArgType, - paramArgs: Record | undefined, - returnError = false -): Promise { - if (isArray(path)) { - path = path.join("/"); - } - - if (args && isEmpty(args)) { - args = undefined; - } - - const result = (await (() => { - if (method == "get") { - return ky(apiPath, { - searchParams: { - ...paramArgs, - ...(args as typeof paramArgs), - path, - }, - method, - headers: { - "content-type": "application/json", - }, - timeout: 30000, - retry: 0, - }); - } - return ky(apiPath, { - searchParams: { - ...paramArgs, - path, - }, - method, - json: args, - headers: { - "content-type": "application/json", - }, - timeout: 30000, - retry: 0, - }); - })().json()) as ErrorType | ResultType; - - if (!result.result) { - if (returnError) { - return result; - } - throw result.reason; - } - return result; +export interface ValidResponse { + result: true; } -//TODO: type이 하나 만들어져야 함. 이것은 typescript의 type system으로. -//TODO: const로 실제 구조가 하나 더 만들어 져야 함. 이것은 위의 type을 satisfy하여야 함. +export type recoveryMethod = 'refreshEntirePage' | 'retryAPI' | 'gameLogin' | 'gatewayLogin' | 'gateway2FA' | 'gameQuota'; +export interface InvalidResponse { + result: false; + reason: string; + recovery?: recoveryMethod; +} + +type ExtractValid = T extends ValidResponse ? T : never; +type ExtractInvalid = T extends InvalidResponse ? T : never; + +export type Callable = (...args: any)=>any; + +export type ExtractResponse = ExtractValid>>; +export type ExtractError = ExtractInvalid>>; +export type ExtractQuery = Parameters[0]; + +export type DefAPINamespace = { + [key: string]: DefAPINamespace + | typeof GET + | typeof POST + | typeof PUT + | typeof DELETE + | typeof PATCH + | typeof HEAD + ; +} + +export type APICompatType = T extends APICallT ? APICallT : never; \ No newline at end of file diff --git a/server/apiStructure/sammoRootAPI.ts b/server/apiStructure/sammoRootAPI.ts new file mode 100644 index 0000000..69399c7 --- /dev/null +++ b/server/apiStructure/sammoRootAPI.ts @@ -0,0 +1,45 @@ +import { type APICallT, GET, POST } from "./defs"; + +export type LoginResponse = { + result: true, + nextToken: [number, string] | undefined, +} + +export type LoginFailed = { + result: false, + reqOTP: boolean, + reason: string, +} + + +export type AutoLoginNonceResponse = { + result: true, + loginNonce: string, +}; + +export type AutoLoginResponse = { + result: true, + nextToken: [number, string] | undefined, +} + + +export type AutoLoginFailed = { + result: false, + silent: boolean, + reason: string, +} + +/** @internal */ +export const structure = { + Login: { + LoginByID: POST as APICallT<{ + username: string, + password: string, + }, LoginResponse, LoginFailed>, + LoginByToken: POST as APICallT<{ + hashedToken: string, + token_id: number, + }, AutoLoginResponse, AutoLoginFailed>, + ReqNonce: GET as APICallT + }, +} as const; \ No newline at end of file diff --git a/server/clientAPI/generator.ts b/server/clientAPI/generator.ts new file mode 100644 index 0000000..fc0547b --- /dev/null +++ b/server/clientAPI/generator.ts @@ -0,0 +1,81 @@ +import isArray from "lodash-es/isArray"; +import isEmpty from "lodash-es/isEmpty"; +import ky from "ky"; +import type { HttpMethod, InvalidResponse, RawArgType, ValidResponse } from "../apiStructure/defs"; + +const apiPath = process.env.API_ROOT_PATH ?? process.env.VITE_API_ROOT_PATH ?? '/api'; + +export async function callClientAPI( + method: HttpMethod, + path: string | string[], + args: RawArgType, + paramArgs: Record | undefined +): Promise; +export async function callClientAPI( + method: HttpMethod, + path: string | string[], + args: RawArgType, + paramArgs: Record | undefined, + returnError: false +): Promise; +export async function callClientAPI( + method: HttpMethod, + path: string | string[], + args: RawArgType, + paramArgs: Record | undefined, + returnError: true +): Promise; +export async function callClientAPI( + method: HttpMethod, + path: string | string[], + args: RawArgType, + paramArgs: Record | undefined, + returnError = false +): Promise { + if (isArray(path)) { + path = path.join("/"); + } + + if (args && isEmpty(args)) { + args = undefined; + } + + const result = (await (() => { + if (method == "get") { + return ky(apiPath, { + searchParams: { + ...paramArgs, + ...(args as typeof paramArgs), + path, + }, + method, + headers: { + "content-type": "application/json", + }, + timeout: 30000, + retry: 0, + }); + } + return ky(apiPath, { + searchParams: { + ...paramArgs, + path, + }, + method, + json: args, + headers: { + "content-type": "application/json", + }, + timeout: 30000, + retry: 0, + }); + })().json()) as ErrorType | ResultType; + + if (!result.result) { + if (returnError) { + return result; + } + throw result.reason; + } + return result; +} \ No newline at end of file diff --git a/server/clientAPI/sammoRootAPI.ts b/server/clientAPI/sammoRootAPI.ts index c893961..90d98ac 100644 --- a/server/clientAPI/sammoRootAPI.ts +++ b/server/clientAPI/sammoRootAPI.ts @@ -1,51 +1,10 @@ import { APIPathGen } from "../api/APIPathGen"; -import { RawArgType } from "../api/base"; -import { APICallT, APITail, GET, POST, callClientAPI, extractHttpMethod } from "./clientAPI"; +import { extractHttpMethod } from "../apiStructure/defs"; +import type { APITail, RawArgType } from "../apiStructure/defs"; +import { structure } from "../apiStructure/sammoRootAPI"; +import { callClientAPI } from "./generator"; -export type LoginResponse = { - result: true, - nextToken: [number, string] | undefined, -} - -export type LoginFailed = { - result: false, - reqOTP: boolean, - reason: string, -} - - -export type AutoLoginNonceResponse = { - result: true, - loginNonce: string, -}; - -export type AutoLoginResponse = { - result: true, - nextToken: [number, string] | undefined, -} - - -export type AutoLoginFailed = { - result: false, - silent: boolean, - reason: string, -} - -const apiRealPath = { - Login: { - LoginByID: POST as APICallT<{ - username: string, - password: string, - }, LoginResponse, LoginFailed>, - LoginByToken: POST as APICallT<{ - hashedToken: string, - token_id: number, - }, AutoLoginResponse, AutoLoginFailed>, - ReqNonce: GET as APICallT - }, -} as const; - -export const SammoRootAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => { +export const SammoRootAPI = APIPathGen(structure, (path: string[], tail: APITail, pathParam) => { const method = extractHttpMethod(tail); return (args?: RawArgType, returnError?: boolean) => { if (returnError) { diff --git a/server/util/callSammoAPI.ts b/server/util/callSammoAPI.ts deleted file mode 100644 index fa65dad..0000000 --- a/server/util/callSammoAPI.ts +++ /dev/null @@ -1,274 +0,0 @@ -import ky from "ky"; -import { isArray, isEmpty } from "lodash-es"; - -export type ValidResponse = { - result: true; -}; - -export type APIRecoveryType = "login" | "2fa" | "gateway" | "game_login" | "game_quota"; -export const APIRecoveryConst = { - Login: 'login', - TwoFactorAuth: '2fa', - Gateway: 'gateway', - GameLogin: 'game_login', - GameQuota: 'game_quota', -} as const; - -export type InvalidResponse = { - result: false; - reason: string; - recovery?: APIRecoveryType; - recovery_arg?: string | number; -}; - -export type RawArgType = Record | Record[] | undefined; - -interface BasicAPICallT< - ArgType extends RawArgType, - ResultType extends ValidResponse, - ErrorType extends InvalidResponse -> { - (args: ArgType): Promise; - (args: ArgType, returnError: false): Promise; - (args: ArgType, returnError: true): Promise; -} - -interface EmptyAPICallT { - (): Promise; - (args: undefined): Promise; - (args: undefined, returnError: false): Promise; - (args: undefined, returnError: true): Promise; -} - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export type ArgTypeOf = T extends APICallT ? A : never; - -export type APICallT< - ArgType extends RawArgType, - ResultType extends ValidResponse = ValidResponse, - ErrorType extends InvalidResponse = InvalidResponse -> = ArgType extends undefined ? EmptyAPICallT : BasicAPICallT; - -type HttpMethod = "get" | "post" | "put" | "patch" | "head" | "delete"; -export type APITail = typeof GET | typeof POST | typeof PUT | typeof PATCH | typeof HEAD | typeof DELETE; - -const httpMethodMap = new Map([ - [GET, "get"], - [POST, "post"], - [PUT, "put"], - [PATCH, "patch"], - [HEAD, "head"], - [DELETE, "delete"], -]); - -export function extractHttpMethod(tail: APITail): HttpMethod { - return httpMethodMap.get(tail) ?? "post"; -} - -const apiTarget = "api.php"; -let apiPath = apiTarget; - -export function setSammoAPIPrefix(prefix: string) { - apiPath = `${prefix}/${apiTarget}`; -} - -export async function callSammoAPI( - method: HttpMethod, - path: string | string[], - args: RawArgType, - paramArgs: Record | undefined -): Promise; -export async function callSammoAPI( - method: HttpMethod, - path: string | string[], - args: RawArgType, - paramArgs: Record | undefined, - returnError: false -): Promise; -export async function callSammoAPI( - method: HttpMethod, - path: string | string[], - args: RawArgType, - paramArgs: Record | undefined, - returnError: true -): Promise; -export async function callSammoAPI( - method: HttpMethod, - path: string | string[], - args: RawArgType, - paramArgs: Record | undefined, - returnError = false -): Promise { - if (isArray(path)) { - path = path.join("/"); - } - - if (args && isEmpty(args)) { - args = undefined; - } - - const result = (await (() => { - if (method == "get") { - return ky(apiPath, { - searchParams: { - ...paramArgs, - ...(args as typeof paramArgs), - path, - }, - method, - headers: { - "content-type": "application/json", - }, - timeout: 30000, - retry: 0, - }); - } - return ky("api.php", { - searchParams: { - ...paramArgs, - path, - }, - method, - json: args, - headers: { - "content-type": "application/json", - }, - timeout: 30000, - retry: 0, - }); - })().json()) as ErrorType | ResultType; - - if (!result.result) { - if (returnError) { - return result; - } - throw result.reason; - } - return result; -} - -export async function GET( - args?: ArgType -): Promise; -export async function GET( - args: ArgType | undefined, - returnError: false -): Promise; -export async function GET< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends undefined = undefined ->(args: ArgType | undefined, returnError: true): Promise; -export async function GET< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends undefined = undefined ->(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call GET. ${args}, ${returnError}. Use auto-generated path API.`); - return callSammoAPI("get", [], args, undefined, true); -} - -export async function POST( - args?: ArgType -): Promise; -export async function POST( - args: ArgType | undefined, - returnError: false -): Promise; -export async function POST< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends RawArgType = RawArgType ->(args: ArgType | undefined, returnError: true): Promise; -export async function POST< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends RawArgType = RawArgType ->(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call POST. ${args}, ${returnError}. Use auto-generated path API.`); - return callSammoAPI("post", [], args, undefined, true); -} - -export async function PUT( - args?: ArgType -): Promise; -export async function PUT( - args: ArgType | undefined, - returnError: false -): Promise; -export async function PUT< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends RawArgType = RawArgType ->(args: ArgType | undefined, returnError: true): Promise; -export async function PUT< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends RawArgType = RawArgType ->(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call PUT. ${args}, ${returnError}. Use auto-generated path API.`); - return callSammoAPI("put", [], args, undefined, true); -} - -export async function PATCH( - args?: ArgType -): Promise; -export async function PATCH( - args: ArgType | undefined, - returnError: false -): Promise; -export async function PATCH< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends RawArgType = RawArgType ->(args: ArgType | undefined, returnError: true): Promise; -export async function PATCH< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends RawArgType = RawArgType ->(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call PATCH. ${args}, ${returnError}. Use auto-generated path API.`); - return callSammoAPI("patch", [], args, undefined, true); -} - -export async function HEAD( - args?: ArgType -): Promise; -export async function HEAD( - args: ArgType | undefined, - returnError: false -): Promise; -export async function HEAD< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends undefined = undefined ->(args: ArgType | undefined, returnError: true): Promise; -export async function HEAD< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends undefined = undefined ->(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call HEAD. ${args}, ${returnError}. Use auto-generated path API.`); - return callSammoAPI("head", [], args, undefined, true); -} - -export async function DELETE( - args?: ArgType -): Promise; -export async function DELETE( - args: ArgType | undefined, - returnError: false -): Promise; -export async function DELETE< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends RawArgType = RawArgType ->(args: ArgType | undefined, returnError: true): Promise; -export async function DELETE< - ResultType extends ValidResponse, - ErrorType extends InvalidResponse, - ArgType extends RawArgType = RawArgType ->(args?: ArgType, returnError = false): Promise { - console.error(`Can't directly call DELETE. ${args}, ${returnError}. Use auto-generated path API.`); - return callSammoAPI("patch", [], args, undefined, true); -}