Skip to content

Commit 867defe

Browse files
add CachedFetchValue overrides type (#727)
1 parent f9b9ae9 commit 867defe

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

.changeset/nasty-boats-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
add and expose new `CachedFetchValue` type

packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ const buildDynamoKey = (key: string) => {
5050
*/
5151
const multiTierCache: IncrementalCache = {
5252
name: "multi-tier-ddb-s3",
53-
async get(key, isFetch) {
53+
async get<IsFetch extends boolean = false>(key: string, isFetch?: IsFetch) {
5454
// First we check the local cache
55-
const localCacheEntry = localCache.get(key);
55+
const localCacheEntry = localCache.get(key) as
56+
| {
57+
value: CacheValue<IsFetch>;
58+
lastModified: number;
59+
}
60+
| undefined;
61+
5662
if (localCacheEntry) {
5763
if (Date.now() - localCacheEntry.lastModified < localCacheTTL) {
5864
debug("Using local cache without checking ddb");

packages/open-next/src/types/overrides.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,29 @@ export type CachedFile =
5454
meta?: Meta;
5555
};
5656

57-
export type FetchCache = Object;
57+
// type taken from: https://github.com/vercel/next.js/blob/9a1cd356/packages/next/src/server/response-cache/types.ts#L26-L38
58+
export type CachedFetchValue = {
59+
kind: "FETCH";
60+
data: {
61+
headers: { [k: string]: string };
62+
body: string;
63+
url: string;
64+
status?: number;
65+
// field used by older versions of Next.js (see: https://github.com/vercel/next.js/blob/fda1ecc/packages/next/src/server/response-cache/types.ts#L23)
66+
tags?: string[];
67+
};
68+
// tags are only present with file-system-cache
69+
// fetch cache stores tags outside of cache entry
70+
tags?: string[];
71+
};
5872

5973
export type WithLastModified<T> = {
6074
lastModified?: number;
6175
value?: T;
6276
};
6377

6478
export type CacheValue<IsFetch extends boolean> = (IsFetch extends true
65-
? FetchCache
79+
? CachedFetchValue
6680
: CachedFile) & { revalidate?: number | false };
6781

6882
export type IncrementalCache = {

0 commit comments

Comments
 (0)