(descriptor: RequestDescriptor, requestOptions?: RequestOptions)
| 141 | const fetch = options.fetch ?? globalThis.fetch |
| 142 | |
| 143 | const prepare = (descriptor: RequestDescriptor, requestOptions?: RequestOptions) => { |
| 144 | const url = new URL(descriptor.path, options.baseUrl) |
| 145 | for (const [key, value] of Object.entries(descriptor.query ?? {})) appendQuery(url.searchParams, key, value) |
| 146 | const headers = new Headers(options.headers) |
| 147 | for (const [key, value] of Object.entries(descriptor.headers ?? {})) { |
| 148 | if (value !== undefined && value !== null) headers.set(key, String(value)) |
| 149 | } |
| 150 | for (const [key, value] of new Headers(requestOptions?.headers)) headers.set(key, value) |
| 151 | if (descriptor.body !== undefined && !headers.has("content-type")) headers.set("content-type", "application/json") |
| 152 | return { |
| 153 | url, |
| 154 | init: { |
| 155 | method: descriptor.method, |
| 156 | signal: requestOptions?.signal, |
| 157 | headers, |
| 158 | body: descriptor.body === undefined ? undefined : JSON.stringify(descriptor.body), |
| 159 | } satisfies RequestInit, |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | const execute = async (descriptor: RequestDescriptor, requestOptions?: RequestOptions) => { |
| 164 | try { |
no test coverage detected