Skip to content

Commit 0cc2da2

Browse files
phpnodeseambot
andauthored
fix: SeamHttpRequest implements Promise<T> rather than PromiseLike<T> (#70)
* SeamHttpRequest must implement Promise<T> rather than PromiseLike<T> to avoid breaking consumers * Remove async modifier * ci: Format code * Export SeamHttpRequest from root --------- Co-authored-by: Seam Bot <devops@getseam.com>
1 parent 49b4564 commit 0cc2da2

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/lib/seam/connect/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from './routes/index.js'
1414
export * from './seam-http.js'
1515
export * from './seam-http-error.js'
1616
export * from './seam-http-multi-workspace.js'
17+
export * from './seam-http-request.js'
1718
export {
1819
isApiKey,
1920
isClientSessionToken,

src/lib/seam/connect/seam-http-request.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ export class SeamHttpRequest<
2424
const TResponse,
2525
const TResponseKey extends keyof TResponse | undefined,
2626
> implements
27-
PromiseLike<
27+
Promise<
2828
TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
2929
>
3030
{
31+
readonly [Symbol.toStringTag]: string = 'SeamHttpRequest'
32+
3133
readonly #parent: SeamHttpRequestParent
3234
readonly #config: SeamHttpRequestConfig<TResponseKey>
3335

@@ -105,7 +107,7 @@ export class SeamHttpRequest<
105107
return data
106108
}
107109

108-
then<
110+
async then<
109111
TResult1 = TResponseKey extends keyof TResponse
110112
? TResponse[TResponseKey]
111113
: undefined,
@@ -123,8 +125,30 @@ export class SeamHttpRequest<
123125
| ((reason: any) => TResult2 | PromiseLike<TResult2>)
124126
| null
125127
| undefined,
126-
): PromiseLike<TResult1 | TResult2> {
127-
return this.execute().then(onfulfilled, onrejected)
128+
): Promise<TResult1 | TResult2> {
129+
return await this.execute().then(onfulfilled, onrejected)
130+
}
131+
132+
async catch<TResult = never>(
133+
onrejected?:
134+
| ((reason: any) => TResult | PromiseLike<TResult>)
135+
| null
136+
| undefined,
137+
): Promise<
138+
| (TResponseKey extends keyof TResponse
139+
? TResponse[TResponseKey]
140+
: undefined)
141+
| TResult
142+
> {
143+
return await this.execute().catch(onrejected)
144+
}
145+
146+
async finally(
147+
onfinally?: (() => void) | null | undefined,
148+
): Promise<
149+
TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
150+
> {
151+
return await this.execute().finally(onfinally)
128152
}
129153
}
130154

0 commit comments

Comments
 (0)