Skip to content

Commit cf3c0ae

Browse files
committed
refactor: require request options when needed
1 parent 9be8818 commit cf3c0ae

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/managers/api.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Route } from "@/lib/routes";
21
import type { APIVersion } from "@squarecloud/api-types/v2";
32
import {
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

src/types/api.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Route } from "@/lib/routes";
12
import type {
23
APIApplication,
34
APIApplicationBackup,
@@ -152,3 +153,15 @@ export type APIRequestOptions<T extends APIEndpoint> = {
152153
export 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];

0 commit comments

Comments
 (0)