import{r as d}from"./D1iGQ9CU.js";import{a as l,i as W}from"./C2O5Xh9K.js";import{u as c,d as I}from"./aZlQuszk.js";const y="/api/publisher/proxylytics/v1";async function f(e){return await(await l(`${y}/namespaces/${e}`)).json()}async function Y(e,t){const{timespan:s,period:a}=t??{},r=new URLSearchParams;return r.set("group","repo"),s&&r.set("timespan",s),a&&r.set("period",a),await(await l(`${y}/namespaces/${e}/pulls?${r.toString()}`)).json()}async function F(e,t){return await(await l(`${y}/namespaces/${e}/repos/${t}/pulls`)).json()}async function w(e){return await(await l(`${y}/namespaces/${e}/pulls/exports/years`)).json()}async function N(e,t){return await(await l(`${y}/namespaces/${e}/pulls/exports/years/${t}/months`)).json()}async function T(e,t){return await(await l(`${y}/namespaces/${e}/pulls/exports/years/${t}/weeks`)).json()}async function v(e,t,s,a="raw"){const r=await l(`${y}/namespaces/${e}/pulls/exports/years/${t}/months/${s}/${a}`,{noThrowStatuses:[404]});return r.status===404?{data:[]}:await r.json()}async function S(e,t,s,a="raw"){const r=await l(`${y}/namespaces/${e}/pulls/exports/years/${t}/weeks/${s}/${a}`,{noThrowStatuses:[404]});return r.status===404?{data:[]}:await r.json()}const o={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,s,a)=>["dvp",e,"data-for-week",t,s,a],getDataForMonth:(t,s,a)=>["dvp",e,"data-for-month",t,s,a]})};function q(e,t){const s=o.discovery.getNamespaceMetadata(e);return c({queryKey:s,queryFn:()=>f(e),staleTime:Number.POSITIVE_INFINITY,...t})}function E(e,t){const s=o.discovery.getAccessToNamespace(e),a=I();return c({queryKey:s,queryFn:async()=>{try{return await a.fetchQuery(o.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,s){const{timespan:a="months",period:r}=t??{},n=o.namespace(e).getPulls({timespan:a,period:r});return c({queryKey:n,queryFn:()=>Y(e,{timespan:a,period:r}),staleTime:Number.POSITIVE_INFINITY,...s})}function b(e,t,s){const a=o.namespace(e).getRepoPulls(t);return c({queryKey:a,queryFn:()=>F(e,t),staleTime:Number.POSITIVE_INFINITY,...s})}function O(e,t){const s=o.namespace(e).getYearsWithData();return c({queryKey:s,queryFn:()=>w(e),staleTime:Number.POSITIVE_INFINITY,select:a=>a.years.map(r=>r.year).sort((r,n)=>n-r),...t})}function _(e,t,s){const{prefetchedYears:a,...r}=s??{},n=I();return d.useEffect(()=>{if(Array.isArray(a))for(const i of a)n.prefetchQuery(o.namespace(e).getMonthsWithDataForSingleYear(i),()=>N(e,i),{staleTime:Number.POSITIVE_INFINITY})},[e,a,n]),c({queryKey:o.namespace(e).getMonthsWithData(t),queryFn:()=>{const i=t.map(h=>n.fetchQuery(o.namespace(e).getMonthsWithDataForSingleYear(h),()=>N(e,h),{staleTime:Number.POSITIVE_INFINITY}));return Promise.all(i)},staleTime:Number.POSITIVE_INFINITY,select:i=>i.map((u,p)=>u.months.map(m=>({year:t[p],month:m.month}))).flat().sort((u,p)=>u.year===p.year?p.month-u.month:p.year-u.year),...r})}function V(e,t,s){const{prefetchedYears:a,...r}=s??{},n=I();return d.useEffect(()=>{if(Array.isArray(a))for(const i of a)n.prefetchQuery(o.namespace(e).getWeeksWithDataForSingleYear(i),()=>T(e,i),{staleTime:Number.POSITIVE_INFINITY})},[e,a,n]),c({queryKey:o.namespace(e).getWeeksWithData(t),queryFn:()=>{const i=t.map(h=>n.fetchQuery(o.namespace(e).getWeeksWithDataForSingleYear(h),()=>T(e,h),{staleTime:Number.POSITIVE_INFINITY}));return Promise.all(i)},staleTime:Number.POSITIVE_INFINITY,select:i=>i.map((u,p)=>u.weeks.map(m=>({year:t[p],week:m.week}))).flat().sort((u,p)=>u.year===p.year?p.week-u.week:p.year-u.year),...r})}function A(e,t,s,a,r){return c({...r,queryKey:o.namespace(e).getDataForMonth(t,s,a),queryFn:()=>v(e,t,s,a),staleTime:Number.POSITIVE_INFINITY,select:n=>n.data})}function K(e,t,s,a,r){return c({queryKey:o.namespace(e).getDataForWeek(t,s,a),queryFn:()=>S(e,t,s,a),staleTime:Number.POSITIVE_INFINITY,select:n=>n.data,...r})}export{q as a,A as b,K as c,b as d,O as e,_ as f,V as g,M as h,E as u};