UNPKG

mongoku

Version:

[![CI](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml/badge.svg)](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml)

2 lines (1 loc) 9.71 kB
import{a0 as K,P as S,b9 as F,b as g,g as o,O as T,ba as se,a8 as ne,u as U,d as c,p as ie,t as j,a as oe,c as w,s as z,e as ae,r as q,f as ce}from"./IwGwbOe7.js";import{n as B,a as ue,p as de,b as W,c as J,v as he}from"./Dzt_TFtX.js";import{q as m,l as V,c as G,p as Q,a as k,b as le,H as E,g as fe,R as ye,d as L,u as pe,e as C}from"./v8XDA7ui.js";import{f as P,a as _,c as me,t as ve}from"./DaMh_eeB.js";import{s as ge}from"./BDGd1aqF.js";import{s as D}from"./BUO1EOQu.js";import{p as xe,i as I}from"./CCOVnadf.js";import{s as R}from"./DqxUmOYD.js";import{b as _e}from"./CkMoyTwc.js";const N=Symbol("sveltekit.query_function_id"),O=Symbol("sveltekit.query_override_key"),M=Symbol("sveltekit.query_resource_key");function Y(){try{return K(B),!0}catch{return!1}}function X(){return S(()=>{const s=ue.current?.to?.url??de.url;return{"x-sveltekit-pathname":s.pathname,"x-sveltekit-search":s.search}})}async function be(s,e){const t=await fetch(s,{headers:{"Content-Type":"application/json",...e}});if(!t.ok)throw new E(500,"Failed to execute remote function");const n=await t.json();return(await we(n)).result}async function we(s){if(s.type==="redirect")throw await fe(s.location),new ye(307,s.location);if(s.type==="error")throw new E(s.status??500,s.error);return s}function qe(s){const e=new Set,t=[],n=new Set;for(const r of s){if(typeof r=="function"){if(Object.hasOwn(r,N)){const i=r[N],a=m.get(i)??V.get(i);if(a)for(const l of a.keys())n.add(G(i,l));continue}if(Object.hasOwn(r,O)){const i=r[O];if(n.add(i),e.has(i))throw new Error("Multiple overrides for the same query are not allowed in a single updates() invocation");e.add(i),t.push(r);continue}t.push(r);continue}if(typeof r=="object"&&r!==null&&Object.hasOwn(r,M)){n.add(r[M]);continue}throw new Error("updates() expects a query or live query function, query resource, or query override")}return{overrides:t,refreshes:n}}function Z(s,e,t){const n=Q(s,k.decoders);for(const[r,i]of Object.entries(n)){const a=le(r),l=e.get(a.id)?.get(a.payload);l?.resource&&t(l.resource,i)}}const ke=s=>{Z(s,m,(e,t)=>{t.type==="result"?e?.set(t.data):e?.fail(new E(t.status??500,t.error))})},Oe=s=>{Z(s,V,(e,t)=>{t.type==="result"?(e?.set(t.data),e?.reconnect()):e?.fail(new E(t.status??500,t.error))})};function u(s){let e=g(0);const t=n=>{let r=null,i=null,a;F(e);const l={"Content-Type":"application/json",...X()},y=(async()=>{try{if(await Promise.resolve(),a)throw a;const p=await fetch(`${W}/${J}/remote/${s}`,{method:"POST",body:JSON.stringify({payload:L(n,k.hooks.transport,!1),refreshes:Array.from(i??[])}),headers:l});if(!p.ok)throw new Error("Failed to execute remote function");const d=await p.json();if(d.type==="redirect")throw new Error("Redirects are not allowed in commands. Return a result instead and use goto on the client");if(d.type==="error")throw new E(d.status??500,d.error);return d.refreshes&&ke(d.refreshes),d.reconnects&&Oe(d.reconnects),Q(d.result,k.decoders)}finally{r?.forEach(p=>p()),F(e,-1)}})();let v=!1;return y.updates=(...p)=>{if(v)return console.warn("Updates can only be sent once per command invocation. Ignoring additional updates."),y;v=!0;try{({refreshes:i,overrides:r}=qe(p))}catch(d){a=d}return y},y};return Object.defineProperty(t,"pending",{get:()=>o(e)}),t}new TextDecoder;const A=`sveltekit:${he}`;let Ee;(async()=>{if(typeof caches<"u")try{Ee=await caches.open(A);const s=await caches.keys();for(const e of s)e.startsWith("sveltekit:")&&e!==A&&await caches.delete(e)}catch(s){console.warn("Failed to initialize SvelteKit cache:",s)}})();const H=new Map;typeof FinalizationRegistry>"u"||new FinalizationRegistry(s=>{const e=H.get(s);e&&e.deref()===void 0&&H.delete(s)});function Se(){let s,e;return{promise:new Promise((n,r)=>{s=n,e=r}),resolve:s,reject:e}}function x(s){const e=t=>new je(s,t,async(n,r)=>{const i=`${W}/${J}/remote/${s}${r?`?payload=${r}`:""}`,a=await pe(n,()=>be(i,X()));return Q(a,k.decoders)});return Object.defineProperty(e,N,{value:s}),e}class Pe{#t;#s;#e=g(!0);#r=[];#a=g(!1);#d=g();#n=g(null);#c=g(ne([]));#i=U(()=>{if(o(this.#a))return o(this.#c).reduce((e,t)=>t(e),o(this.#d))});#o=g(void 0);#h=U(()=>{const e=this.#l();return o(this.#c).length,(t,n)=>{const r=e.then(T).then(()=>o(this.#i));return t||n?r.then(t,n):r}});constructor(e,t){this.#t=e,this.#s=t}#l(){return S(()=>c(this.#n,o(this.#n)??this.#y())),o(this.#n)}#u(){T().then(()=>this.#l())}#f(){this.#r.forEach(e=>e(void 0)),this.#r.length=0}#y(){c(this.#e,!0);const{promise:e,resolve:t,reject:n}=Se();return this.#r.push(t),Promise.resolve(this.#s()).then(r=>{const i=this.#r.indexOf(t);i!==-1&&(S(()=>{this.#r.splice(0,i).forEach(a=>a(void 0)),c(this.#a,!0),c(this.#e,!1),c(this.#d,r),c(this.#o,void 0)}),t(void 0))}).catch(r=>{const i=this.#r.indexOf(t);i!==-1&&(S(()=>{this.#r.splice(0,i).forEach(a=>a(void 0)),c(this.#o,r),c(this.#e,!1)}),n(r))}),e}get then(){return this.#u(),o(this.#h)}get catch(){return this.#u(),o(this.#h),e=>o(this.#h)(void 0,e)}get finally(){return this.#u(),o(this.#h),e=>o(this.#h)(t=>(e(),t),t=>{throw e(),t})}get current(){return this.#u(),o(this.#i)}get error(){return this.#u(),o(this.#o)}get loading(){return this.#u(),o(this.#e)}get ready(){return this.#u(),o(this.#a)}refresh(){return delete C[this.#t],c(this.#n,this.#y())}set(e){this.#f(),c(this.#a,!0),c(this.#e,!1),c(this.#o,void 0),c(this.#d,e),c(this.#n,Promise.resolve())}fail(e){this.#f(),c(this.#e,!1),c(this.#o,e);const t=Promise.reject(e);t.catch(B),c(this.#n,t)}withOverride(e){o(this.#c).push(e);const t=()=>{const n=o(this.#c).indexOf(e);n!==-1&&o(this.#c).splice(n,1)};return Object.defineProperty(t,O,{value:this.#t}),t}get[Symbol.toStringTag](){return"Query"}}class je{#t;#s;#e;#r;#a=!0;#d=Y();constructor(e,t,n){if(this.#t=e,this.#e=L(t,k.hooks.transport),this.#s=G(e,this.#e),Object.defineProperty(this,M,{value:this.#s}),this.#r=n,!this.#d){this.#a=!1;return}const r=this.#n();K(()=>()=>{const i=this.#c(r);T().then(i)})}#n(){let e=m.get(this.#t);e||(e=new Map,m.set(this.#t,e));let t=e.get(this.#e);if(!t){const n=t={count:0,resource:null,cleanup:null};n.cleanup=se(()=>{n.resource=new Pe(this.#s,()=>this.#r(this.#s,this.#e))}),e.set(this.#e,t)}return t.count+=1,t}#c(e,t=!0){return this.#a&&=!t,e.count-=1,()=>{const n=m.get(this.#t),r=n?.get(this.#e);r?.count===0&&(r.cleanup(),n?.delete(this.#e)),n?.size===0&&m.delete(this.#t)}}#i(){return m.get(this.#t)?.get(this.#e)?.resource}get current(){return this.#i()?.current}get error(){return this.#i()?.error}get loading(){return this.#i()?.loading??!1}get ready(){return this.#i()?.ready??!1}run(){if(Y())throw new Error("On the client, .run() can only be called outside render, e.g. in universal `load` functions and event handlers. In render, await the query directly");return Object.hasOwn(C,this.#s)?Promise.resolve(C[this.#s]):this.#r(this.#s,this.#e)}refresh(){return this.#i()?.refresh()??Promise.resolve()}set(e){this.#i()?.set(e)}withOverride(e){const t=this.#n(),n=t.resource.withOverride(e),r=()=>{n(),this.#c(t,!1)()};return Object.defineProperty(r,O,{value:n[O]}),r}#o(){if(!this.#d)throw new Error("This query was not created in a reactive context and cannot be awaited. Use `.run()` to execute the query instead.");if(!this.#a)throw new Error("This query instance is no longer active and can no longer be awaited. This typically means you created the query in a tracking context and stashed it somewhere outside of a tracking context.");const e=m.get(this.#t)?.get(this.#e);if(!e)throw new Error("No cached query found. This should be impossible. Please file a bug report.");return e.resource}get then(){const e=this.#o();return e.then.bind(e)}get catch(){const e=this.#o();return e.catch.bind(e)}get finally(){const e=this.#o();return e.finally.bind(e)}get[Symbol.toStringTag](){return"QueryProxy"}}const He=u("xxtqbu/addServer"),Ke=u("xxtqbu/auditSchema"),Be=u("xxtqbu/countDocuments"),We=x("xxtqbu/countDocumentsByTimeRange"),Je=u("xxtqbu/createIndex"),Ve=u("xxtqbu/deleteDocument"),Ge=u("xxtqbu/deleteMany"),Le=x("xxtqbu/detectPrimaryNode"),Xe=u("xxtqbu/dropCollection"),Ze=u("xxtqbu/dropDatabase"),$e=u("xxtqbu/dropIndex"),et=x("xxtqbu/explainQuery"),tt=x("xxtqbu/fetchMappedDocument"),rt=x("xxtqbu/getIndexStatsFromNodes");x("xxtqbu/getIndexStatsWithReadPreference");const st=x("xxtqbu/getServerNodes"),nt=u("xxtqbu/hideIndex"),it=u("xxtqbu/insertDocument"),ot=u("xxtqbu/loadDocuments"),at=u("xxtqbu/removeServer"),ct=u("xxtqbu/retryConnection"),ut=u("xxtqbu/unhideIndex"),dt=u("xxtqbu/updateDocument"),ht=u("xxtqbu/updateMany");var De=P("<span> </span>"),Ie=P('<div class="flex gap-2 items-center"><!></div>'),Re=P('<div><div style="color: var(--text);"><!></div> <!></div>'),Te=P("<div><!> <!></div>");function lt(s,e){ie(e,!0);let t=xe(e,"ref",15);var n=Te(),r=w(n);{var i=l=>{var y=Re(),v=w(y),p=w(v);{var d=h=>{var f=De(),b=w(f,!0);q(f),j(()=>ge(b,e.title)),_(h,f)},$=h=>{var f=me(),b=ce(f);D(b,()=>e.title),_(h,f)},ee=h=>{var f=ve(" ");_(h,f)};I(p,h=>{typeof e.title=="string"?h(d):e.title?h($,1):h(ee,-1)})}q(v);var te=z(v,2);{var re=h=>{var f=Ie(),b=w(f);D(b,()=>e.actions),q(f),_(h,f)};I(te,h=>{e.actions&&h(re)})}q(y),j(()=>{R(y,1,`px-3 sm:px-4 py-2 flex justify-between items-center ${e.children?"border-b border-[var(--border-color)]":""}`),R(v,1,`text-sm font-medium ${e.titleClass??""}`)}),_(l,y)};I(r,l=>{(e.title||e.actions)&&l(i)})}var a=z(r,2);D(a,()=>e.children??ae),q(n),_e(n,l=>t(l),()=>t()),j(()=>R(n,1,`rounded-2xl border border-[var(--border-color)] bg-[var(--light-background)]/70 shadow-sm ${e.class??""}`)),_(s,n),oe()}export{lt as P,Xe as a,Ve as b,Ke as c,Ze as d,He as e,at as f,tt as g,st as h,it as i,Le as j,rt as k,$e as l,Je as m,ut as n,nt as o,We as p,ot as q,ct as r,Be as s,et as t,dt as u,ht as v,Ge as w};