(function(){try{var g=typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};g["__faroBundleId_hub-ui"]="1776361634403-2195cb2175"}catch(l){}})();import{r as d}from"./c2heove9.js";import{f as l,i as W}from"./ct82etp1.js";import{u as p,a as I}from"./clkkthq4.js";const m="/api/publisher/proxylytics/v1";async function f(e){return await(await l(`${m}/namespaces/${e}`)).json()}async function Y(e,t){const{timespan:a,period:s}=t??{},r=new URLSearchParams;return r.set("group","repo"),a&&r.set("timespan",a),s&&r.set("period",s),await(await l(`${m}/namespaces/${e}/pulls?${r.toString()}`)).json()}async function F(e){return await(await l(`${m}/namespaces/${e}/pulls/exports/years`)).json()}async function N(e,t){return await(await l(`${m}/namespaces/${e}/pulls/exports/years/${t}/months`)).json()}async function T(e,t){return await(await l(`${m}/namespaces/${e}/pulls/exports/years/${t}/weeks`)).json()}async function w(e,t,a,s="raw"){const r=await l(`${m}/namespaces/${e}/pulls/exports/years/${t}/months/${a}/${s}`,{noThrowStatuses:[404]});return r.status===404?{data:[]}:await r.json()}async function v(e,t,a,s="raw"){const r=await l(`${m}/namespaces/${e}/pulls/exports/years/${t}/weeks/${a}/${s}`,{noThrowStatuses:[404]});return r.status===404?{data:[]}:await r.json()}const i={discovery:{getAccessToNamespace:e=>["dvp",e,"access"],getNamespaceMetadata:e=>["dvp",e,"metadata"]},getBatchReposPulls:e=>["dvp","batch-repos-pulls",...e],namespace:e=>({getPulls:t=>["dvp",e,"pulls",t.timespan,t.period],getRepoPulls:t=>["dvp",e,"repo",t],getYearsWithData:()=>["dvp",e,"years-with-data"],getWeeksWithDataForSingleYear:t=>["dvp",e,"weeks-with-data-single-year",t],getWeeksWithData:t=>["dvp",e,"weeks-with-data",t],getMonthsWithDataForSingleYear:t=>["dvp",e,"months-with-data-single-year",t],getMonthsWithData:t=>["dvp",e,"months-with-data",t],getDataForWeek:(t,a,s)=>["dvp",e,"data-for-week",t,a,s],getDataForMonth:(t,a,s)=>["dvp",e,"data-for-month",t,a,s]})};function P(e,t){const a=i.discovery.getNamespaceMetadata(e);return p({queryKey:a,queryFn:()=>f(e),staleTime:Number.POSITIVE_INFINITY,...t})}function q(e,t){const a=i.discovery.getAccessToNamespace(e),s=I();return p({queryKey:a,queryFn:async()=>{try{return await s.fetchQuery(i.discovery.getNamespaceMetadata(e),()=>f(e),{staleTime:Number.POSITIVE_INFINITY}),{hasInsightsAccess:!0}}catch(r){if(W(r)&&r.response.status===404)return{hasInsightsAccess:!1};throw r}},staleTime:Number.POSITIVE_INFINITY,...t})}function M(e,t,a){const{timespan:s="months",period:r}=t??{},n=i.namespace(e).getPulls({timespan:s,period:r});return p({queryKey:n,queryFn:()=>Y(e,{timespan:s,period:r}),staleTime:Number.POSITIVE_INFINITY,...a})}function E(e,t){const a=i.namespace(e).getYearsWithData();return p({queryKey:a,queryFn:()=>F(e),staleTime:Number.POSITIVE_INFINITY,select:s=>s.years.map(r=>r.year).sort((r,n)=>n-r),...t})}function b(e,t,a){const{prefetchedYears:s,...r}=a??{},n=I();return d.useEffect(()=>{if(Array.isArray(s))for(const o of s)n.prefetchQuery(i.namespace(e).getMonthsWithDataForSingleYear(o),()=>N(e,o),{staleTime:Number.POSITIVE_INFINITY})},[e,s,n]),p({queryKey:i.namespace(e).getMonthsWithData(t),queryFn:()=>{const o=t.map(h=>n.fetchQuery(i.namespace(e).getMonthsWithDataForSingleYear(h),()=>N(e,h),{staleTime:Number.POSITIVE_INFINITY}));return Promise.all(o)},staleTime:Number.POSITIVE_INFINITY,select:o=>o.map((u,c)=>u.months.map(y=>({year:t[c],month:y.month}))).flat().sort((u,c)=>u.year===c.year?c.month-u.month:c.year-u.year),...r})}function O(e,t,a){const{prefetchedYears:s,...r}=a??{},n=I();return d.useEffect(()=>{if(Array.isArray(s))for(const o of s)n.prefetchQuery(i.namespace(e).getWeeksWithDataForSingleYear(o),()=>T(e,o),{staleTime:Number.POSITIVE_INFINITY})},[e,s,n]),p({queryKey:i.namespace(e).getWeeksWithData(t),queryFn:()=>{const o=t.map(h=>n.fetchQuery(i.namespace(e).getWeeksWithDataForSingleYear(h),()=>T(e,h),{staleTime:Number.POSITIVE_INFINITY}));return Promise.all(o)},staleTime:Number.POSITIVE_INFINITY,select:o=>o.map((u,c)=>u.weeks.map(y=>({year:t[c],week:y.week}))).flat().sort((u,c)=>u.year===c.year?c.week-u.week:c.year-u.year),...r})}function _(e,t,a,s,r){return p({...r,queryKey:i.namespace(e).getDataForMonth(t,a,s),queryFn:()=>w(e,t,a,s),staleTime:Number.POSITIVE_INFINITY,select:n=>n.data})}function V(e,t,a,s,r){return p({queryKey:i.namespace(e).getDataForWeek(t,a,s),queryFn:()=>v(e,t,a,s),staleTime:Number.POSITIVE_INFINITY,select:n=>n.data,...r})}export{P as a,_ as b,V as c,M as d,E as e,b as f,O as g,q as u};