diff --git a/.changeset/nasty-boats-boil.md b/.changeset/nasty-boats-boil.md new file mode 100644 index 000000000..7d9451d53 --- /dev/null +++ b/.changeset/nasty-boats-boil.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +add and expose new `CachedFetchValue` type 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 35f2702a8..9dc25b513 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 4e87fc6a4..717694f8a 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 + ? CachedFetchValue : CachedFile) & { revalidate?: number | false }; export type IncrementalCache = {