{"version":3,"sources":["../../../src/server/request/utils.ts"],"sourcesContent":["import { StaticGenBailoutError } from '../../client/components/static-generation-bailout'\nimport { actionAsyncStorage } from '../app-render/action-async-storage.external'\nimport { afterTaskAsyncStorage } from '../app-render/after-task-async-storage.external'\nimport type { WorkStore } from '../app-render/work-async-storage.external'\nimport type { WorkUnitStore } from '../app-render/work-unit-async-storage.external'\n\nexport function throwWithStaticGenerationBailoutErrorWithDynamicError(\n  route: string,\n  expression: string\n): never {\n  throw new StaticGenBailoutError(\n    `Route ${route} with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`\n  )\n}\n\nexport function throwForSearchParamsAccessInUseCache(\n  workStore: WorkStore,\n  constructorOpt: Function\n): never {\n  const error = new Error(\n    `Route ${workStore.route} used \\`searchParams\\` inside \"use cache\". Accessing dynamic request data inside a cache scope is not supported. If you need some search params inside a cached function await \\`searchParams\\` outside of the cached function and pass only the required search params as arguments to the cached function. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`\n  )\n\n  Error.captureStackTrace(error, constructorOpt)\n  workStore.invalidDynamicUsageError ??= error\n\n  throw error\n}\n\nexport function isRequestApiAllowedInCurrentPhase(\n  workUnitStore: WorkUnitStore\n): boolean {\n  switch (workUnitStore.phase) {\n    case 'action':\n    case 'render': {\n      // The request is still in progress. The API may be disallowed for other reasons,\n      // but not because of phase.\n      return true\n    }\n    case 'after': {\n      // The request has finished.\n\n      // If we're in a Route Handler or a Server Action,\n      // request APIs can be called everywhere, even in after().\n      const actionStore = actionAsyncStorage.getStore()\n      if (actionStore && (actionStore.isAppRoute || actionStore.isAction)) {\n        return true\n      }\n\n      const afterTaskStore = afterTaskAsyncStorage.getStore()\n      if (afterTaskStore) {\n        // We're in an `after` callback. Request APIs are callable if\n        // the `after()` call happened in an action phase:\n        // - in a Route Handler\n        // - in a Server Action's body (but not the render after)\n        //\n        // TODO(after): Is it even possible to have `phase === 'action'` but no `actionStore`?\n        // We should revisit this setup and simplify this.\n        return afterTaskStore.rootTaskSpawnPhase === 'action'\n      }\n\n      // Otherwise, we must be in a page, in the `after` phase.\n      // We don't allow calling request APIs here because we'd miss\n      // them during prerendering and wouldn't know that the page is dynamic.\n      return false\n    }\n  }\n}\n"],"names":["isRequestApiAllowedInCurrentPhase","throwForSearchParamsAccessInUseCache","throwWithStaticGenerationBailoutErrorWithDynamicError","route","expression","StaticGenBailoutError","workStore","constructorOpt","error","Error","captureStackTrace","invalidDynamicUsageError","workUnitStore","phase","actionStore","actionAsyncStorage","getStore","isAppRoute","isAction","afterTaskStore","afterTaskAsyncStorage","rootTaskSpawnPhase"],"mappings":";;;;;;;;;;;;;;;;IA6BgBA,iCAAiC;eAAjCA;;IAdAC,oCAAoC;eAApCA;;IATAC,qDAAqD;eAArDA;;;yCANsB;4CACH;+CACG;AAI/B,SAASA,sDACdC,KAAa,EACbC,UAAkB;IAElB,MAAM,qBAEL,CAFK,IAAIC,8CAAqB,CAC7B,CAAC,MAAM,EAAEF,MAAM,4EAA4E,EAAEC,WAAW,0HAA0H,CAAC,GAD/N,qBAAA;eAAA;oBAAA;sBAAA;IAEN;AACF;AAEO,SAASH,qCACdK,SAAoB,EACpBC,cAAwB;IAExB,MAAMC,QAAQ,qBAEb,CAFa,IAAIC,MAChB,CAAC,MAAM,EAAEH,UAAUH,KAAK,CAAC,2XAA2X,CAAC,GADzY,qBAAA;eAAA;oBAAA;sBAAA;IAEd;IAEAM,MAAMC,iBAAiB,CAACF,OAAOD;IAC/BD,UAAUK,wBAAwB,KAAKH;IAEvC,MAAMA;AACR;AAEO,SAASR,kCACdY,aAA4B;IAE5B,OAAQA,cAAcC,KAAK;QACzB,KAAK;QACL,KAAK;YAAU;gBACb,iFAAiF;gBACjF,4BAA4B;gBAC5B,OAAO;YACT;QACA,KAAK;YAAS;gBACZ,4BAA4B;gBAE5B,kDAAkD;gBAClD,0DAA0D;gBAC1D,MAAMC,cAAc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