{"version":3,"file":"useApiQueryCache.cjs","names":["API_QUERY_CONTEXT","useGlobalContext","QUERY_CACHE_CONTEXT_KEY"],"sources":["../../../../src/api/hooks/useApiQueryCache/useApiQueryCache.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { QUERY_CACHE_CONTEXT_KEY } from '@pastweb/tools/api/createQueryCache/constants';\nimport { useGlobalContext } from '../../../GlobalContext/useGlobalContext';\nimport { API_QUERY_CONTEXT } from '../../constants';\nimport type { QueryCache } from '@pastweb/tools';\n\n/**\n * Returns the active `QueryCache` for React API integrations.\n *\n * Resolution order:\n * 1. The nearest {@link ApiQueryProvider}\n * 2. The React `GlobalContext` entry installed by {@link installApiCache}\n *\n * Throws when neither provider path is available, because React API hooks need\n * an explicit cache installation point.\n *\n * @returns The active tools `QueryCache`.\n *\n * @example\n * ```tsx\n * function DebugCache() {\n *   const queryCache = useApiQueryCache();\n *   return <pre>{queryCache.getAll().length}</pre>;\n * }\n * ```\n */\nexport function useApiQueryCache(): QueryCache {\n  const queryCache = useContext(API_QUERY_CONTEXT);\n  const globalContext = useGlobalContext();\n  const activeQueryCache = queryCache || globalContext[QUERY_CACHE_CONTEXT_KEY];\n\n  if (!activeQueryCache) {\n    throw new Error(\n      'useApiQueryCache error: queryCache must be installed in the GlobalContext via installApiCache or ApiQueryProvider should be used.'\n    );\n  }\n\n  return activeQueryCache;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,mBAA+B;CAC7C,MAAM,cAAA,GAAA,MAAA,WAAA,CAAwBA,sBAAAA,iBAAiB;CAC/C,MAAM,gBAAgBC,uCAAAA,iBAAiB;CACvC,MAAM,mBAAmB,cAAc,cAAcC,8CAAAA;CAErD,IAAI,CAAC,kBACH,MAAM,IAAI,MACR,mIACF;CAGF,OAAO;AACT"}