{"version":3,"sources":["../../../../src/server/web/spec-extension/unstable-cache.ts"],"sourcesContent":["import type { IncrementalCache } from '../../lib/incremental-cache'\n\nimport { CACHE_ONE_YEAR_SECONDS } from '../../../lib/constants'\nimport { validateRevalidate, validateTags } from '../../lib/patch-fetch'\nimport { encodeHeaderSafe } from '../../lib/encode-header-safe'\nimport {\n  workAsyncStorage,\n  type WorkStore,\n} from '../../app-render/work-async-storage.external'\nimport {\n  getCacheSignal,\n  getDraftModeProviderForCacheScope,\n  workUnitAsyncStorage,\n} from '../../app-render/work-unit-async-storage.external'\nimport {\n  CachedRouteKind,\n  IncrementalCacheKind,\n  type CachedFetchData,\n} from '../../response-cache'\nimport type {\n  UnstableCacheStore,\n  WorkUnitStore,\n} from '../../app-render/work-unit-async-storage.external'\n\ntype Callback = (...args: any[]) => Promise<any>\n\nlet noStoreFetchIdx = 0\n\nasync function cacheNewResult<T>(\n  result: T,\n  incrementalCache: IncrementalCache,\n  cacheKey: string,\n  tags: string[],\n  revalidate: number | false | undefined,\n  fetchIdx: number,\n  fetchUrl: string\n): Promise<unknown> {\n  await incrementalCache.set(\n    cacheKey,\n    {\n      kind: CachedRouteKind.FETCH,\n      data: {\n        headers: {},\n        // TODO: handle non-JSON values?\n        body: JSON.stringify(result),\n        status: 200,\n        url: '',\n      } satisfies CachedFetchData,\n      revalidate:\n        typeof revalidate !== 'number' ? CACHE_ONE_YEAR_SECONDS : revalidate,\n    },\n    { fetchCache: true, tags, fetchIdx, fetchUrl }\n  )\n  return\n}\n\n/**\n * This function allows you to cache the results of expensive operations, like database queries, and reuse them across multiple requests.\n *\n * Read more: [Next.js Docs: `unstable_cache`](https://nextjs.org/docs/app/api-reference/functions/unstable_cache)\n */\nexport function unstable_cache<T extends Callback>(\n  cb: T,\n  keyParts?: string[],\n  options: {\n    /**\n     * The revalidation interval in seconds.\n     */\n    revalidate?: number | false\n    tags?: string[]\n  } = {}\n): T {\n  if (options.revalidate === 0) {\n    throw new Error(\n      `Invariant revalidate: 0 can not be passed to unstable_cache(), must be \"false\" or \"> 0\" ${cb.toString()}`\n    )\n  }\n\n  // Validate the tags provided are valid\n  const tags = options.tags\n    ? validateTags(options.tags, `unstable_cache ${cb.toString()}`)\n    : []\n\n  // Validate the revalidate option, and adopt the normalized value, which\n  // maps `false` and `Infinity` to INFINITE_CACHE so that the stored value\n  // survives JSON serialization.\n  const revalidate = validateRevalidate(\n    options.revalidate,\n    `unstable_cache ${cb.name || cb.toString()}`\n  )\n\n  // Stash the fixed part of the key at construction time. The invocation key will combine\n  // the fixed key with the arguments when actually called\n  // @TODO if cb.toString() is long we should hash it\n  // @TODO come up with a collision-free way to combine keyParts\n  // @TODO consider validating the keyParts are all strings. TS can't provide runtime guarantees\n  // and the error produced by accidentally using something that cannot be safely coerced is likely\n  // hard to debug\n  const fixedKey = `${cb.toString()}-${\n    Array.isArray(keyParts) && keyParts.join(',')\n  }`\n\n  const cachedCb = async (...args: any[]) => {\n    const workStore = workAsyncStorage.getStore()\n    const workUnitStore = workUnitAsyncStorage.getStore()\n\n    // We must be able to find the incremental cache otherwise we throw\n    const maybeIncrementalCache:\n      | import('../../lib/incremental-cache').IncrementalCache\n      | undefined =\n      workStore?.incrementalCache || (globalThis as any).__incrementalCache\n\n    if (!maybeIncrementalCache) {\n      throw new Error(\n        `Invariant: incrementalCache missing in unstable_cache ${cb.toString()}`\n      )\n    }\n    const incrementalCache = maybeIncrementalCache\n\n    const cacheSignal = workUnitStore ? getCacheSignal(workUnitStore) : null\n    if (cacheSignal) {\n      cacheSignal.beginRead()\n    }\n    try {\n      // If there's no request store, we aren't in a request (or we're not in\n      // app router) and if there's no static generation store, we aren't in app\n      // router. Default to an empty pathname and search params when there's no\n      // request store or static generation store available.\n      const fetchUrlPrefix =\n        workStore && workUnitStore\n          ? getFetchUrlPrefix(workStore, workUnitStore)\n          : ''\n\n      // Construct the complete cache key for this function invocation\n      // @TODO stringify is likely not safe here. We will coerce undefined to null which will make\n      // the keyspace smaller than the execution space\n      const invocationKey = `${fixedKey}-${JSON.stringify(args)}`\n      const cacheKey =\n        await incrementalCache.generateSimpleCacheKey(invocationKey)\n      // $urlWithPath,$sortedQueryStringKeys,$hashOfEveryThingElse\n      //\n      // A cache implementation may serialize this name into an HTTP request\n      // header, so it is encoded here. Both parts can carry a character above\n      // U+00FF: the search parameters are decoded, and a JavaScript identifier\n      // may hold one. The character class leaves the separating spaces and the\n      // URL punctuation untouched, so the shape above is preserved.\n      //\n      // `toWellFormed` replaces lone surrogates, which `cb.name` can hold and\n      // which `encodeURIComponent` rejects. The name identifies the call for\n      // debug metrics, so a replacement character is an acceptable trade for\n      // not failing the render.\n      const fetchUrl = encodeHeaderSafe(\n        `unstable_cache ${fetchUrlPrefix} ${cb.name ? ` ${cb.name}` : cacheKey}`.toWellFormed()\n      )\n      const fetchIdx =\n        (workStore ? workStore.nextFetchId : noStoreFetchIdx) ?? 1\n\n      const implicitTags = workUnitStore?.implicitTags\n\n      const innerCacheStore: UnstableCacheStore = {\n        type: 'unstable-cache',\n        phase: 'render',\n        implicitTags,\n        draftMode:\n          workUnitStore &&\n          workStore &&\n          getDraftModeProviderForCacheScope(workStore, workUnitStore),\n        rootParams: undefined,\n      }\n\n      if (workStore) {\n        workStore.nextFetchId = fetchIdx + 1\n\n        // We are in an App Router context. We try to return the cached entry if it exists and is valid\n        // If the entry is fresh we return it. If the entry is stale we return it but revalidate the entry in\n        // the background. If the entry is missing or invalid we generate a new entry and return it.\n\n        let isNestedUnstableCache = false\n\n        if (workUnitStore) {\n          switch (workUnitStore.type) {\n            case 'cache':\n            case 'private-cache':\n            case 'prerender':\n            case 'prerender-runtime':\n            case 'prerender-ppr':\n            case 'prerender-legacy':\n              // We update the store's revalidate property if the revalidate option is a higher precedence\n              // revalidate === undefined doesn't affect timing.\n              // revalidate === INFINITE_CACHE (from `false` or `Infinity`) doesn't shrink timing. it stays at the maximum.\n              if (typeof revalidate === 'number') {\n                if (workUnitStore.revalidate < revalidate) {\n                  // The store is already revalidating on a shorter time interval, leave it alone\n                } else {\n                  workUnitStore.revalidate = revalidate\n                }\n              }\n\n              // We need to accumulate the tags for this invocation within the store\n              const collectedTags = workUnitStore.tags\n              if (collectedTags === null) {\n                workUnitStore.tags = tags.slice()\n              } else {\n                for (const tag of tags) {\n                  // @TODO refactor tags to be a set to avoid this O(n) lookup\n                  if (!collectedTags.includes(tag)) {\n                    collectedTags.push(tag)\n                  }\n                }\n              }\n              break\n            case 'unstable-cache':\n              isNestedUnstableCache = true\n              break\n            case 'prerender-client':\n            case 'validation-client':\n            case 'request':\n            case 'generate-static-params':\n              break\n            default:\n              workUnitStore satisfies never\n          }\n        }\n\n        if (\n          // when we are nested inside of other unstable_cache's\n          // we should bypass cache similar to fetches\n          !isNestedUnstableCache &&\n          workStore.fetchCache !== 'force-no-store' &&\n          !workStore.isOnDemandRevalidate &&\n          !incrementalCache.isOnDemandRevalidate &&\n          !workStore.isDraftMode\n        ) {\n          // We attempt to get the current cache entry from the incremental cache.\n          const cacheEntry = await incrementalCache.get(cacheKey, {\n            kind: IncrementalCacheKind.FETCH,\n            revalidate,\n            tags,\n            softTags: implicitTags?.tags,\n            fetchIdx,\n            fetchUrl,\n          })\n\n          if (cacheEntry && cacheEntry.value) {\n            // The entry exists and has a value\n            if (cacheEntry.value.kind !== CachedRouteKind.FETCH) {\n              // The entry is invalid and we need a special warning\n              // @TODO why do we warn this way? Should this just be an error? How are these errors surfaced\n              // so bugs can be reported\n              // @TODO the invocation key can have sensitive data in it. we should not log this entire object\n              console.error(\n                `Invariant invalid cacheEntry returned for ${invocationKey}`\n              )\n              // will fall through to generating a new cache entry below\n            } else {\n              // We have a valid cache entry so we will be returning it. We also check to see if we need\n              // to background revalidate it by checking if it is stale.\n              const cachedResponse =\n                cacheEntry.value.data.body !== undefined\n                  ? JSON.parse(cacheEntry.value.data.body)\n                  : undefined\n\n              if (cacheEntry.isStale) {\n                if (!workStore.pendingRevalidates) {\n                  workStore.pendingRevalidates = {}\n                }\n\n                // Check if there's already a pending revalidation to avoid duplicate work\n                if (!workStore.pendingRevalidates[invocationKey]) {\n                  // Create the revalidation promise\n                  const revalidationPromise = workUnitAsyncStorage\n                    .run(innerCacheStore, cb, ...args)\n                    .then(async (result) => {\n                      await cacheNewResult(\n                        result,\n                        incrementalCache,\n                        cacheKey,\n                        tags,\n                        revalidate,\n                        fetchIdx,\n                        fetchUrl\n                      )\n                      return result\n                    })\n                    .catch((err) => {\n                      // @TODO This error handling seems wrong. We swallow the error?\n                      console.error(\n                        `revalidating cache with key: ${invocationKey}`,\n                        err\n                      )\n                      // Return the stale value on error for foreground revalidation\n                      return cachedResponse\n                    })\n\n                  // Attach the empty catch here so we don't get a \"unhandled promise\n                  // rejection\" warning. (Behavior is matched with patch-fetch)\n                  if (workStore.isStaticGeneration) {\n                    revalidationPromise.catch(() => {})\n                  }\n\n                  workStore.pendingRevalidates[invocationKey] =\n                    revalidationPromise\n                }\n\n                // Check if we need to do foreground revalidation\n                if (workStore.isStaticGeneration) {\n                  // When the page is revalidating and the cache entry is stale,\n                  // we need to wait for fresh data (blocking revalidate). The\n                  // `await` here keeps `cacheSignal.endRead` (in the outer\n                  // `finally`) suspended until the recompute + cacheNewResult\n                  // actually complete, so the prospective prerender's\n                  // `cacheSignal` doesn't resolve `cacheReady` prematurely.\n                  return await workStore.pendingRevalidates[invocationKey]\n                }\n                // Otherwise, we're doing background revalidation - return stale immediately\n              }\n\n              // We had a valid cache entry so we return it here\n              return cachedResponse\n            }\n          }\n        }\n\n        // If we got this far then we had an invalid cache entry and need to generate a new one\n        const result = await workUnitAsyncStorage.run(\n          innerCacheStore,\n          cb,\n          ...args\n        )\n\n        if (!workStore.isDraftMode) {\n          if (!workStore.pendingRevalidates) {\n            workStore.pendingRevalidates = {}\n          }\n\n          // We need to push the cache result promise to pending\n          // revalidates otherwise it won't be awaited and is just\n          // dangling\n          workStore.pendingRevalidates[invocationKey] = cacheNewResult(\n            result,\n            incrementalCache,\n            cacheKey,\n            tags,\n            revalidate,\n            fetchIdx,\n            fetchUrl\n          )\n        }\n\n        return result\n      } else {\n        noStoreFetchIdx += 1\n        // We are in Pages Router or were called outside of a render. We don't have a store\n        // so we just call the callback directly when it needs to run.\n        // If the entry is fresh we return it. If the entry is stale we return it but revalidate the entry in\n        // the background. If the entry is missing or invalid we generate a new entry and return it.\n\n        if (!incrementalCache.isOnDemandRevalidate) {\n          // We aren't doing an on demand revalidation so we check use the cache if valid\n          const cacheEntry = await incrementalCache.get(cacheKey, {\n            kind: IncrementalCacheKind.FETCH,\n            revalidate,\n            tags,\n            fetchIdx,\n            fetchUrl,\n            softTags: implicitTags?.tags,\n          })\n\n          if (cacheEntry && cacheEntry.value) {\n            // The entry exists and has a value\n            if (cacheEntry.value.kind !== CachedRouteKind.FETCH) {\n              // The entry is invalid and we need a special warning\n              // @TODO why do we warn this way? Should this just be an error? How are these errors surfaced\n              // so bugs can be reported\n              console.error(\n                `Invariant invalid cacheEntry returned for ${invocationKey}`\n              )\n              // will fall through to generating a new cache entry below\n            } else if (!cacheEntry.isStale) {\n              // We have a valid cache entry and it is fresh so we return it\n              return cacheEntry.value.data.body !== undefined\n                ? JSON.parse(cacheEntry.value.data.body)\n                : undefined\n            }\n          }\n        }\n\n        // If we got this far then we had an invalid cache entry and need to generate a new one\n        const result = await workUnitAsyncStorage.run(\n          innerCacheStore,\n          cb,\n          ...args\n        )\n\n        // we need to wait setting the new cache result here as\n        // we don't have pending revalidates on workStore to\n        // push to and we can't have a dangling promise\n        await cacheNewResult(\n          result,\n          incrementalCache,\n          cacheKey,\n          tags,\n          revalidate,\n          fetchIdx,\n          fetchUrl\n        )\n        return result\n      }\n    } finally {\n      if (cacheSignal) {\n        cacheSignal.endRead()\n      }\n    }\n  }\n  // TODO: once AsyncLocalStorage.run() returns the correct types this override will no longer be necessary\n  return cachedCb as unknown as T\n}\n\nfunction getFetchUrlPrefix(\n  workStore: WorkStore,\n  workUnitStore: WorkUnitStore\n): string {\n  switch (workUnitStore.type) {\n    case 'request':\n      const pathname = workUnitStore.url.pathname\n      const searchParams = new URLSearchParams(workUnitStore.url.search)\n\n      const sortedSearch = [...searchParams.keys()]\n        .sort((a, b) => a.localeCompare(b))\n        .map((key) => `${key}=${searchParams.get(key)}`)\n        .join('&')\n\n      return `${pathname}${sortedSearch.length ? '?' : ''}${sortedSearch}`\n    case 'prerender':\n    case 'prerender-client':\n    case 'validation-client':\n    case 'prerender-runtime':\n    case 'prerender-ppr':\n    case 'prerender-legacy':\n    case 'cache':\n    case 'private-cache':\n    case 'unstable-cache':\n    case 'generate-static-params':\n      return workStore.route\n    default:\n      return workUnitStore satisfies never\n  }\n}\n"],"names":["unstable_cache","noStoreFetchIdx","cacheNewResult","result","incrementalCache","cacheKey","tags","revalidate","fetchIdx","fetchUrl","set","kind","CachedRouteKind","FETCH","data","headers","body","JSON","stringify","status","url","CACHE_ONE_YEAR_SECONDS","fetchCache","cb","keyParts","options","Error","toString","validateTags","validateRevalidate","name","fixedKey","Array","isArray","join","cachedCb","args","workStore","workAsyncStorage","getStore","workUnitStore","workUnitAsyncStorage","maybeIncrementalCache","globalThis","__incrementalCache","cacheSignal","getCacheSignal","beginRead","fetchUrlPrefix","getFetchUrlPrefix","invocationKey","generateSimpleCacheKey","encodeHeaderSafe","toWellFormed","nextFetchId","implicitTags","innerCacheStore","type","phase","draftMode","getDraftModeProviderForCacheScope","rootParams","undefined","isNestedUnstableCache","collectedTags","slice","tag","includes","push","isOnDemandRevalidate","isDraftMode","cacheEntry","get","IncrementalCacheKind","softTags","value","console","error","cachedResponse","parse","isStale","pendingRevalidates","revalidationPromise","run","then","catch","err","isStaticGeneration","endRead","pathname","searchParams","URLSearchParams","search","sortedSearch","keys","sort","a","b","localeCompare","map","key","length","route"],"mappings":";;;;+BA6DgBA;;;eAAAA;;;2BA3DuB;4BACU;kCAChB;0CAI1B;8CAKA;+BAKA;AAQP,IAAIC,kBAAkB;AAEtB,eAAeC,eACbC,MAAS,EACTC,gBAAkC,EAClCC,QAAgB,EAChBC,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