Skip to content

Commit

Permalink
fix(fetchache): respect additional parameters passed to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Sep 9, 2022
1 parent 8606f54 commit f1db96f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-pumas-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'fetchache': patch
---

Respect additional parameters to fetch
8 changes: 4 additions & 4 deletions packages/fetchache/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface FetchacheCacheEntry {
body: string;
}

type FetchFn = WindowOrWorkerGlobalScope['fetch'];
type FetchFn = (input: URL | RequestInfo, init: RequestInit, ...rest: any[]) => Promise<Response>;

export interface FetchacheOptions {
fetch: FetchFn;
Expand All @@ -15,7 +15,7 @@ export interface FetchacheOptions {
}

export function fetchFactory({ fetch, Response, cache }: FetchacheOptions): FetchFn {
return async (input, init) => {
return async (input: URL | RequestInfo, init: RequestInit, ...rest: any[]) => {
let url: string;
let method = 'GET';
let headers: HeadersInit = {};
Expand All @@ -34,7 +34,7 @@ export function fetchFactory({ fetch, Response, cache }: FetchacheOptions): Fetc
const entry = await cache.get(cacheKey);
const policyRequest = policyRequestFrom(url, method, headers);
if (!entry) {
const response = await fetch(input, init);
const response = await fetch(input, init, ...rest);

const policy = new CachePolicy(policyRequest, policyResponseFrom(response));

Expand Down Expand Up @@ -65,7 +65,7 @@ export function fetchFactory({ fetch, Response, cache }: FetchacheOptions): Fetc
...headers,
...(revalidationHeaders as HeadersInit),
},
});
}, ...rest);

const revalidationPolicyRequest = policyRequestFrom(url, method, revalidationHeaders as HeadersInit);

Expand Down

0 comments on commit f1db96f

Please sign in to comment.