GET with request deduplication.
(path: string, opts?: RequestOptions)
| 201 | |
| 202 | /** GET with request deduplication. */ |
| 203 | async get<T>(path: string, opts?: RequestOptions): Promise<T> { |
| 204 | const key = path; |
| 205 | const existing = this.inflight.get(key); |
| 206 | if (existing) { |
| 207 | const res = await existing; |
| 208 | if (!res.ok) throw await toApiError(res.clone()); |
| 209 | return res.clone().json() as Promise<T>; |
| 210 | } |
| 211 | |
| 212 | const promise = this.request(path, { method: "GET", signal: opts?.signal }); |
| 213 | this.inflight.set(key, promise); |
| 214 | promise.finally(() => this.inflight.delete(key)); |
| 215 | |
| 216 | const res = await promise; |
| 217 | if (!res.ok) throw await toApiError(res); |
| 218 | return res.json() as Promise<T>; |
| 219 | } |
| 220 | |
| 221 | async post<T>(path: string, body: unknown, opts?: RequestOptions): Promise<T> { |
| 222 | const res = await this.request(path, { |