Skip to content

Commit 4e89649

Browse files
chore: make some internal functions async
1 parent badebce commit 4e89649

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/core.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ export abstract class APIClient {
304304
return null;
305305
}
306306

307-
buildRequest<Req>(
307+
async buildRequest<Req>(
308308
inputOptions: FinalRequestOptions<Req>,
309309
{ retryCount = 0 }: { retryCount?: number } = {},
310-
): { req: RequestInit; url: string; timeout: number } {
310+
): Promise<{ req: RequestInit; url: string; timeout: number }> {
311311
const options = { ...inputOptions };
312312
const { method, path, query, defaultBaseURL, headers: headers = {} } = options;
313313

@@ -455,7 +455,9 @@ export abstract class APIClient {
455455

456456
await this.prepareOptions(options);
457457

458-
const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
458+
const { req, url, timeout } = await this.buildRequest(options, {
459+
retryCount: maxRetries - retriesRemaining,
460+
});
459461

460462
await this.prepareRequest(req, { url, options });
461463

tests/index.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ describe('instantiate client', () => {
2727
apiEmail: '[email protected]',
2828
});
2929

30-
test('they are used in the request', () => {
31-
const { req } = client.buildRequest({ path: '/foo', method: 'post' });
30+
test('they are used in the request', async () => {
31+
const { req } = await client.buildRequest({ path: '/foo', method: 'post' });
3232
expect((req.headers as Headers)['x-my-default-header']).toEqual('2');
3333
});
3434

35-
test('can ignore `undefined` and leave the default', () => {
36-
const { req } = client.buildRequest({
35+
test('can ignore `undefined` and leave the default', async () => {
36+
const { req } = await client.buildRequest({
3737
path: '/foo',
3838
method: 'post',
3939
headers: { 'X-My-Default-Header': undefined },
4040
});
4141
expect((req.headers as Headers)['x-my-default-header']).toEqual('2');
4242
});
4343

44-
test('can be removed with `null`', () => {
45-
const { req } = client.buildRequest({
44+
test('can be removed with `null`', async () => {
45+
const { req } = await client.buildRequest({
4646
path: '/foo',
4747
method: 'post',
4848
headers: { 'X-My-Default-Header': null },
@@ -290,20 +290,20 @@ describe('request building', () => {
290290
const client = new Cloudflare({ apiKey: '144c9defac04969c7bfad8efaa8ea194', apiEmail: '[email protected]' });
291291

292292
describe('Content-Length', () => {
293-
test('handles multi-byte characters', () => {
294-
const { req } = client.buildRequest({ path: '/foo', method: 'post', body: { value: '—' } });
293+
test('handles multi-byte characters', async () => {
294+
const { req } = await client.buildRequest({ path: '/foo', method: 'post', body: { value: '—' } });
295295
expect((req.headers as Record<string, string>)['content-length']).toEqual('20');
296296
});
297297

298-
test('handles standard characters', () => {
299-
const { req } = client.buildRequest({ path: '/foo', method: 'post', body: { value: 'hello' } });
298+
test('handles standard characters', async () => {
299+
const { req } = await client.buildRequest({ path: '/foo', method: 'post', body: { value: 'hello' } });
300300
expect((req.headers as Record<string, string>)['content-length']).toEqual('22');
301301
});
302302
});
303303

304304
describe('custom headers', () => {
305-
test('handles undefined', () => {
306-
const { req } = client.buildRequest({
305+
test('handles undefined', async () => {
306+
const { req } = await client.buildRequest({
307307
path: '/foo',
308308
method: 'post',
309309
body: { value: 'hello' },

0 commit comments

Comments
 (0)