diff --git a/src/_shims/index-deno.ts b/src/_shims/index-deno.ts index f935ad89..776b09ab 100644 --- a/src/_shims/index-deno.ts +++ b/src/_shims/index-deno.ts @@ -64,7 +64,7 @@ const _Blob = Blob; type _Blob = Blob; export { _Blob as Blob }; -export async function getMultipartRequestOptions>( +export async function getMultipartRequestOptions>( form: FormData, opts: RequestOptions, ): Promise> { diff --git a/src/_shims/index.d.ts b/src/_shims/index.d.ts index 4c359af1..ca17d681 100644 --- a/src/_shims/index.d.ts +++ b/src/_shims/index.d.ts @@ -65,7 +65,7 @@ export type ReadableStream = SelectType; -export function getMultipartRequestOptions>( +export function getMultipartRequestOptions>( form: FormData, opts: RequestOptions, ): Promise>; diff --git a/src/_shims/node-runtime.ts b/src/_shims/node-runtime.ts index 7d24b707..a9c42ebe 100644 --- a/src/_shims/node-runtime.ts +++ b/src/_shims/node-runtime.ts @@ -43,7 +43,7 @@ async function fileFromPath(path: string, ...args: any[]): Promise { const defaultHttpAgent: Agent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 }); const defaultHttpsAgent: Agent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 }); -async function getMultipartRequestOptions>( +async function getMultipartRequestOptions>( form: fd.FormData, opts: RequestOptions, ): Promise> { diff --git a/src/_shims/registry.ts b/src/_shims/registry.ts index 3e28e99c..248f9a5e 100644 --- a/src/_shims/registry.ts +++ b/src/_shims/registry.ts @@ -13,7 +13,7 @@ export interface Shims { Blob: any; File: any; ReadableStream: any; - getMultipartRequestOptions: >( + getMultipartRequestOptions: >( form: Shims['FormData'], opts: RequestOptions, ) => Promise>; diff --git a/src/_shims/web-runtime.ts b/src/_shims/web-runtime.ts index 96cd146c..b905cd6e 100644 --- a/src/_shims/web-runtime.ts +++ b/src/_shims/web-runtime.ts @@ -84,7 +84,7 @@ export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } } } ), - getMultipartRequestOptions: async >( + getMultipartRequestOptions: async >( // @ts-ignore form: FormData, opts: RequestOptions, diff --git a/src/core.ts b/src/core.ts index e49ef39a..facf5961 100644 --- a/src/core.ts +++ b/src/core.ts @@ -208,27 +208,27 @@ export abstract class APIClient { return `stainless-node-retry-${uuid4()}`; } - get(path: string, opts?: PromiseOrValue>): APIPromise { + get(path: string, opts?: PromiseOrValue>): APIPromise { return this.methodRequest('get', path, opts); } - post(path: string, opts?: PromiseOrValue>): APIPromise { + post(path: string, opts?: PromiseOrValue>): APIPromise { return this.methodRequest('post', path, opts); } - patch(path: string, opts?: PromiseOrValue>): APIPromise { + patch(path: string, opts?: PromiseOrValue>): APIPromise { return this.methodRequest('patch', path, opts); } - put(path: string, opts?: PromiseOrValue>): APIPromise { + put(path: string, opts?: PromiseOrValue>): APIPromise { return this.methodRequest('put', path, opts); } - delete(path: string, opts?: PromiseOrValue>): APIPromise { + delete(path: string, opts?: PromiseOrValue>): APIPromise { return this.methodRequest('delete', path, opts); } - private methodRequest( + private methodRequest( method: HTTPMethod, path: string, opts?: PromiseOrValue>, @@ -260,9 +260,7 @@ export abstract class APIClient { return null; } - buildRequest( - options: FinalRequestOptions, - ): { req: RequestInit; url: string; timeout: number } { + buildRequest(options: FinalRequestOptions): { req: RequestInit; url: string; timeout: number } { const { method, path, query, headers: headers = {} } = options; const body = @@ -364,15 +362,15 @@ export abstract class APIClient { return APIError.generate(status, error, message, headers); } - request( + request( options: PromiseOrValue>, remainingRetries: number | null = null, ): APIPromise { return new APIPromise(this.makeRequest(options, remainingRetries)); } - private async makeRequest( - optionsInput: PromiseOrValue, + private async makeRequest( + optionsInput: PromiseOrValue>, retriesRemaining: number | null, ): Promise { const options = await optionsInput; @@ -434,7 +432,7 @@ export abstract class APIClient { return new PagePromise(this, request, Page); } - buildURL>(path: string, query: Req | null | undefined): string { + buildURL(path: string, query: Req | null | undefined): string { const url = isAbsoluteURL(path) ? new URL(path) @@ -608,7 +606,7 @@ export abstract class AbstractPage implements AsyncIterable { ); } const nextOptions = { ...this.options }; - if ('params' in nextInfo) { + if ('params' in nextInfo && typeof nextOptions.query === 'object') { nextOptions.query = { ...nextOptions.query, ...nextInfo.params }; } else if ('url' in nextInfo) { const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()]; @@ -706,7 +704,7 @@ export type Headers = Record; export type DefaultQuery = Record; export type KeysEnum = { [P in keyof Required]: true }; -export type RequestOptions | Readable> = { +export type RequestOptions | Readable> = { method?: HTTPMethod; path?: string; query?: Req | undefined; @@ -743,7 +741,7 @@ const requestOptionsKeys: KeysEnum = { __binaryResponse: true, }; -export const isRequestOptions = (obj: unknown): obj is RequestOptions | Readable> => { +export const isRequestOptions = (obj: unknown): obj is RequestOptions => { return ( typeof obj === 'object' && obj !== null && @@ -752,7 +750,7 @@ export const isRequestOptions = (obj: unknown): obj is RequestOptions | Readable> = RequestOptions & { +export type FinalRequestOptions | Readable> = RequestOptions & { method: HTTPMethod; path: string; }; diff --git a/src/uploads.ts b/src/uploads.ts index bc2afefa..2398baf3 100644 --- a/src/uploads.ts +++ b/src/uploads.ts @@ -184,7 +184,7 @@ export const isMultipartBody = (body: any): body is MultipartBody => * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value. * Otherwise returns the request as is. */ -export const maybeMultipartFormRequestOptions = async >( +export const maybeMultipartFormRequestOptions = async >( opts: RequestOptions, ): Promise> => { if (!hasUploadableValue(opts.body)) return opts; @@ -193,7 +193,7 @@ export const maybeMultipartFormRequestOptions = async >( +export const multipartFormRequestOptions = async >( opts: RequestOptions, ): Promise> => { const form = await createForm(opts.body);