From 007842853cc2ea027686acef3967e689cf38535d Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 6 Feb 2025 12:22:06 +0000 Subject: [PATCH 1/3] add `CachedFetchValue` overrides type --- packages/open-next/src/types/overrides.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/open-next/src/types/overrides.ts b/packages/open-next/src/types/overrides.ts index 4e87fc6a..42442375 100644 --- a/packages/open-next/src/types/overrides.ts +++ b/packages/open-next/src/types/overrides.ts @@ -54,7 +54,21 @@ export type CachedFile = meta?: Meta; }; -export type FetchCache = Object; +// type taken from: https://github.com/vercel/next.js/blob/9a1cd356/packages/next/src/server/response-cache/types.ts#L26-L38 +export type CachedFetchValue = { + kind: "FETCH"; + data: { + headers: { [k: string]: string }; + body: string; + url: string; + status?: number; + // 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) + tags?: string[]; + }; + // tags are only present with file-system-cache + // fetch cache stores tags outside of cache entry + tags?: string[]; +}; export type WithLastModified = { lastModified?: number; @@ -62,7 +76,7 @@ export type WithLastModified = { }; export type CacheValue = (IsFetch extends true - ? FetchCache + ? Partial : CachedFile) & { revalidate?: number | false }; export type IncrementalCache = { From 4376a2f36db3ffe6a1a81c14715861431455b9b2 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 6 Feb 2025 22:29:01 +0000 Subject: [PATCH 2/3] remove the unnecessary `Partial` --- .../overrides/incrementalCache/multi-tier-ddb-s3.ts | 10 ++++++++-- packages/open-next/src/types/overrides.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts b/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts index 35f2702a..9dc25b51 100644 --- a/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts +++ b/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts @@ -50,9 +50,15 @@ const buildDynamoKey = (key: string) => { */ const multiTierCache: IncrementalCache = { name: "multi-tier-ddb-s3", - async get(key, isFetch) { + async get(key: string, isFetch?: IsFetch) { // First we check the local cache - const localCacheEntry = localCache.get(key); + const localCacheEntry = localCache.get(key) as + | { + value: CacheValue; + lastModified: number; + } + | undefined; + if (localCacheEntry) { if (Date.now() - localCacheEntry.lastModified < localCacheTTL) { debug("Using local cache without checking ddb"); diff --git a/packages/open-next/src/types/overrides.ts b/packages/open-next/src/types/overrides.ts index 42442375..717694f8 100644 --- a/packages/open-next/src/types/overrides.ts +++ b/packages/open-next/src/types/overrides.ts @@ -76,7 +76,7 @@ export type WithLastModified = { }; export type CacheValue = (IsFetch extends true - ? Partial + ? CachedFetchValue : CachedFile) & { revalidate?: number | false }; export type IncrementalCache = { From 0ad078e84ef80186c1836d96b86f758af43d64be Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Thu, 6 Feb 2025 22:33:44 +0000 Subject: [PATCH 3/3] add changeset --- .changeset/nasty-boats-boil.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nasty-boats-boil.md diff --git a/.changeset/nasty-boats-boil.md b/.changeset/nasty-boats-boil.md new file mode 100644 index 00000000..7d9451d5 --- /dev/null +++ b/.changeset/nasty-boats-boil.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +add and expose new `CachedFetchValue` type