File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 1- import type { Route } from "@/lib/routes" ;
21import type { APIVersion } from "@squarecloud/api-types/v2" ;
32import {
43 type APIEndpoint ,
4+ type APIRequestArgs ,
55 type APIRequestOptions ,
66 type APIResponse ,
77 SquareCloudAPIError ,
@@ -13,9 +13,8 @@ export class APIManager {
1313
1414 constructor ( protected readonly apiKey : string ) { }
1515
16- async request < T extends APIEndpoint , U extends APIRequestOptions < T > > (
17- path : Route < T > ,
18- options ?: U ,
16+ async request < T extends APIEndpoint > (
17+ ...[ path , options ] : APIRequestArgs < T >
1918 ) : Promise < APIResponse < T > > {
2019 const { url, init } = this . parseRequestOptions ( path , options ) ;
2120
Original file line number Diff line number Diff line change 1+ import type { Route } from "@/lib/routes" ;
12import type {
23 APIApplication ,
34 APIApplicationBackup ,
@@ -152,3 +153,15 @@ export type APIRequestOptions<T extends APIEndpoint> = {
152153export type APIResponse < T extends APIEndpoint > = APIPayload <
153154 APIEndpoints [ T ] [ "response" ]
154155> ;
156+
157+ export type QueryOrBody =
158+ | { query : any }
159+ | { body : any }
160+ | { method : APIMethod } ;
161+
162+ export type APIRequestArgs <
163+ T extends APIEndpoint ,
164+ U extends APIRequestOptions < T > = APIRequestOptions < T > ,
165+ > = U extends QueryOrBody
166+ ? [ path : Route < T > , options : U ]
167+ : [ path : Route < T > , options ?: U ] ;
You can’t perform that action at this time.
0 commit comments