{"version":3,"file":"async-storages-PkTXUT16.cjs","names":["RZL_NEXT_KIT_EXTRA"],"sources":["../src/extra/utils/dynamic-import.ts","../src/extra/utils/async-storages.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/** @internal */\nexport function safeImport<T = object>(path: string): T | undefined {\n  try {\n    // eslint-disable-next-line @typescript-eslint/no-require-imports\n    return require(path);\n  } catch (_) {\n    return;\n  }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { safeImport } from \"@/extra/utils/dynamic-import\";\nimport { RZL_NEXT_KIT_EXTRA } from \"./constants\";\n\nconst { FLAG_MESSAGE } = RZL_NEXT_KIT_EXTRA.ERROR;\n\n/** @internal */\nexport function getExpectedRequestStore(callingExpression: string) {\n  const workUnitStoreModule = safeImport<\n    | {\n        getExpectedRequestStore: any;\n      }\n    | {\n        workUnitAsyncStorage: AsyncLocalStorage<any>;\n      }\n  >(\"next/dist/server/app-render/work-unit-async-storage.external\");\n  if (workUnitStoreModule) {\n    if (\"getExpectedRequestStore\" in workUnitStoreModule) {\n      return workUnitStoreModule.getExpectedRequestStore();\n    }\n\n    return workUnitStoreModule.workUnitAsyncStorage.getStore();\n  }\n\n  const requestStoreModule = safeImport<{\n    requestAsyncStorage: AsyncLocalStorage<any>;\n  }>(\"next/dist/client/components/request-async-storage.external\");\n  if (requestStoreModule) {\n    const store = requestStoreModule.requestAsyncStorage.getStore();\n    if (store) return store;\n    throw new Error(\n      FLAG_MESSAGE(\n        `Function \\`${callingExpression}\\` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context`\n      )\n    );\n  }\n\n  throw new Error(\n    FLAG_MESSAGE(\n      `Variant \\`${callingExpression}\\` expects to have requestAsyncStorage, none available.`\n    )\n  );\n}\n\n/** @internal */\nexport function getStaticGenerationStore(callingExpression: string) {\n  const staticGenerationStoreModule = safeImport<{\n    staticGenerationAsyncStorage: any;\n  }>(\"next/dist/client/components/static-generation-async-storage.external\");\n  if (staticGenerationStoreModule) {\n    const staticGenerationStore =\n      (fetch as any).__nextGetStaticStore?.() ??\n      staticGenerationStoreModule.staticGenerationAsyncStorage;\n\n    const store = staticGenerationStore.getStore();\n    if (!store) {\n      throw new Error(\n        FLAG_MESSAGE(\n          `Variant \\`${callingExpression}\\` expects to have staticGenerationAsyncStorage, none available.`\n        )\n      );\n    }\n\n    return store;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;AAEA,SAAgB,WAAuB,MAA6B;CAClE,IAAI;EAEF,OAAO,QAAQ,IAAI;CACrB,SAAS,GAAG;EACV;CACF;AACF;;;;ACHA,MAAM,EAAE,iBAAiBA,qCAAmB;;AAG5C,SAAgB,wBAAwB,mBAA2B;CACjE,MAAM,sBAAsB,WAO1B,8DAA8D;CAChE,IAAI,qBAAqB;EACvB,IAAI,6BAA6B,qBAC/B,OAAO,oBAAoB,wBAAwB;EAGrD,OAAO,oBAAoB,qBAAqB,SAAS;CAC3D;CAEA,MAAM,qBAAqB,WAExB,4DAA4D;CAC/D,IAAI,oBAAoB;EACtB,MAAM,QAAQ,mBAAmB,oBAAoB,SAAS;EAC9D,IAAI,OAAO,OAAO;EAClB,MAAM,IAAI,MACR,aACE,cAAc,kBAAkB,kHAClC,CACF;CACF;CAEA,MAAM,IAAI,MACR,aACE,aAAa,kBAAkB,wDACjC,CACF;AACF;;AAGA,SAAgB,yBAAyB,mBAA2B;CAClE,MAAM,8BAA8B,WAEjC,sEAAsE;CACzE,IAAI,6BAA6B;EAK/B,MAAM,SAHH,MAAc,uBAAuB,KACtC,4BAA4B,6BAEK,CAAC,SAAS;EAC7C,IAAI,CAAC,OACH,MAAM,IAAI,MACR,aACE,aAAa,kBAAkB,iEACjC,CACF;EAGF,OAAO;CACT;AACF"}
