@lunora/studio 1.0.0-alpha.52 → 1.0.0-alpha.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/packem_chunks/organizations-panel.js +240 -209
  2. package/dist/standalone/{chunk-KGQGNJJ2.js → chunk-3C3CU2DS.js} +1 -1
  3. package/dist/standalone/chunk-3GVA2ROQ.js +1 -0
  4. package/dist/standalone/{chunk-DTPFXYHG.js → chunk-3MAQAOUA.js} +1 -1
  5. package/dist/standalone/{chunk-XOANGJJP.js → chunk-3XBP6RRG.js} +1 -1
  6. package/dist/standalone/{chunk-4QA5TWYJ.js → chunk-43F677PE.js} +1 -1
  7. package/dist/standalone/{chunk-ZZMGCPXE.js → chunk-5JB7FDCA.js} +1 -1
  8. package/dist/standalone/{chunk-VN2PDOMK.js → chunk-6TMEOFZC.js} +1 -1
  9. package/dist/standalone/{chunk-YA6POZJD.js → chunk-75LPCQ77.js} +1 -1
  10. package/dist/standalone/{chunk-N4NG7HGI.js → chunk-7KSXHCUD.js} +1 -1
  11. package/dist/standalone/{chunk-E3FVNRH7.js → chunk-7N5KFSSB.js} +1 -1
  12. package/dist/standalone/{chunk-TSLR3ZU2.js → chunk-ALL4U2C5.js} +1 -1
  13. package/dist/standalone/{chunk-OSPEOESV.js → chunk-C4QK2DJN.js} +1 -1
  14. package/dist/standalone/{chunk-6TYT447C.js → chunk-CODD62OJ.js} +1 -1
  15. package/dist/standalone/{chunk-T3UCZ5PJ.js → chunk-CRY26DNY.js} +1 -1
  16. package/dist/standalone/{chunk-FJV4UNYY.js → chunk-CZGILAZI.js} +1 -1
  17. package/dist/standalone/{chunk-FWTZYHX4.js → chunk-DMFVDMUJ.js} +1 -1
  18. package/dist/standalone/{chunk-VLIRTNLA.js → chunk-FFVSSWU2.js} +1 -1
  19. package/dist/standalone/{chunk-ZECNJ4FG.js → chunk-GPQX3AEO.js} +1 -1
  20. package/dist/standalone/{chunk-BE24FXAK.js → chunk-HRHG4HOZ.js} +1 -1
  21. package/dist/standalone/{chunk-Q7TKOAGT.js → chunk-HZKFL2M7.js} +1 -1
  22. package/dist/standalone/{chunk-LDEVBRDZ.js → chunk-I7Y7ST5Y.js} +1 -1
  23. package/dist/standalone/{chunk-ZETIKSQJ.js → chunk-IC7XYSER.js} +1 -1
  24. package/dist/standalone/{chunk-CP2EQVLU.js → chunk-IEKK5GO6.js} +1 -1
  25. package/dist/standalone/{chunk-LVH4KLXS.js → chunk-ISOUWAPB.js} +1 -1
  26. package/dist/standalone/chunk-LOYE7OU2.js +11 -0
  27. package/dist/standalone/{chunk-VC5RNEHU.js → chunk-LT7IG26L.js} +1 -1
  28. package/dist/standalone/{chunk-KKJZL75J.js → chunk-NXAKNU3L.js} +1 -1
  29. package/dist/standalone/{chunk-Q7PYLDZU.js → chunk-OETK333R.js} +1 -1
  30. package/dist/standalone/{chunk-7SN6J4DZ.js → chunk-PWKD5FTM.js} +1 -1
  31. package/dist/standalone/{chunk-DBLAQC32.js → chunk-R2MAZ2OH.js} +1 -1
  32. package/dist/standalone/{chunk-IMZKGRPW.js → chunk-S7RKDQPS.js} +1 -1
  33. package/dist/standalone/{chunk-VZFJI6XE.js → chunk-SXAFEREK.js} +1 -1
  34. package/dist/standalone/{chunk-2ZL6MXBC.js → chunk-T7FHIJ2T.js} +1 -1
  35. package/dist/standalone/{chunk-DANDBL6P.js → chunk-TC4KPQJ7.js} +2 -2
  36. package/dist/standalone/{chunk-UX53GWGU.js → chunk-USYCKPUK.js} +1 -1
  37. package/dist/standalone/{chunk-G465LTLD.js → chunk-VY6AI3RI.js} +1 -1
  38. package/dist/standalone/{chunk-AVONJCNY.js → chunk-WXUUGXDV.js} +1 -1
  39. package/dist/standalone/{chunk-ONSKQCYN.js → chunk-XXAW7V4T.js} +1 -1
  40. package/dist/standalone/{chunk-4ELN4RE4.js → chunk-XXXNY3DK.js} +1 -1
  41. package/dist/standalone/{chunk-KDZJ5A3R.js → chunk-YFZ27MEC.js} +1 -1
  42. package/dist/standalone/{chunk-RXVQJ4DO.js → chunk-ZQQ3MFEQ.js} +1 -1
  43. package/dist/standalone/{chunk-WJ6OBCUM.js → chunk-ZVT4GJEI.js} +1 -1
  44. package/dist/standalone/studio.js +1 -1
  45. package/package.json +4 -4
  46. package/dist/standalone/chunk-AJ2B326V.js +0 -1
  47. package/dist/standalone/chunk-L2YBC2BV.js +0 -11
@@ -0,0 +1,11 @@
1
+ import{a as dt}from"./chunk-3OA7PECS.js";import{b as l}from"./chunk-22C6COGE.js";import{a as o,e as R,f as K,g as ht,h as pr}from"./chunk-RRCPZMC2.js";var Kt=R(ht(),1);var M=class{static{o(this,"Subscribable")}constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var yr=class extends M{static{o(this,"FocusManager")}#t;#e;#r;constructor(){super(),this.#r=t=>{if(typeof window<"u"&&window.addEventListener){let e=o(()=>t(),"listener");return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}}}onSubscribe(){this.#e||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#r=t,this.#e?.(),this.#e=t(e=>{typeof e=="boolean"?this.setFocused(e):this.onFocus()})}setFocused(t){this.#t!==t&&(this.#t=t,this.onFocus())}onFocus(){let t=this.isFocused();this.listeners.forEach(e=>{e(t)})}isFocused(){return typeof this.#t=="boolean"?this.#t:globalThis.document?.visibilityState!=="hidden"}},Y=new yr;var br={setTimeout:o((t,e)=>setTimeout(t,e),"setTimeout"),clearTimeout:o(t=>clearTimeout(t),"clearTimeout"),setInterval:o((t,e)=>setInterval(t,e),"setInterval"),clearInterval:o(t=>clearInterval(t),"clearInterval")},vr=class{static{o(this,"TimeoutManager")}#t=br;#e=!1;setTimeoutProvider(t){this.#e&&t!==this.#t&&console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",{previous:this.#t,provider:t}),this.#t=t,this.#e=!1}setTimeout(t,e){return this.#e=!0,this.#t.setTimeout(t,e)}clearTimeout(t){this.#t.clearTimeout(t)}setInterval(t,e){return this.#e=!0,this.#t.setInterval(t,e)}clearInterval(t){this.#t.clearInterval(t)}},F=new vr;function lt(t){setTimeout(t,0)}o(lt,"systemSetTimeoutZero");var He=typeof window>"u"||"Deno"in globalThis;function S(){}o(S,"noop");function pt(t,e){return typeof t=="function"?t(e):t}o(pt,"functionalUpdate");function se(t){return typeof t=="number"&&t>=0&&t!==1/0}o(se,"isValidTimeout");function ye(t,e){return Math.max(t+(e||0)-Date.now(),0)}o(ye,"timeUntilStale");function x(t,e){return typeof t=="function"?t(e):t}o(x,"resolveStaleTime");function A(t,e){return typeof t=="function"?t(e):t}o(A,"resolveQueryBoolean");function be(t,e){let{type:r="all",exact:s,fetchStatus:i,predicate:n,queryKey:a,stale:u}=t;if(a){if(s){if(e.queryHash!==ie(a,e.options))return!1}else if(!W(e.queryKey,a))return!1}if(r!=="all"){let c=e.isActive();if(r==="active"&&!c||r==="inactive"&&c)return!1}return!(typeof u=="boolean"&&e.isStale()!==u||i&&i!==e.state.fetchStatus||n&&!n(e))}o(be,"matchQuery");function ve(t,e){let{exact:r,status:s,predicate:i,mutationKey:n}=t;if(n){if(!e.options.mutationKey)return!1;if(r){if(j(e.options.mutationKey)!==j(n))return!1}else if(!W(e.options.mutationKey,n))return!1}return!(s&&e.state.status!==s||i&&!i(e))}o(ve,"matchMutation");function ie(t,e){return(e?.queryKeyHashFn||j)(t)}o(ie,"hashQueryKeyByOptions");function j(t){return JSON.stringify(t,(e,r)=>Ue(r)?Object.keys(r).sort().reduce((s,i)=>(s[i]=r[i],s),{}):r)}o(j,"hashKey");function W(t,e){return t===e?!0:typeof t!=typeof e?!1:t&&e&&typeof t=="object"&&typeof e=="object"?Object.keys(e).every(r=>W(t[r],e[r])):!1}o(W,"partialMatchKey");var gr=Object.prototype.hasOwnProperty;function pe(t,e,r=0){if(t===e)return t;if(r>500)return e;let s=ft(t)&&ft(e);if(!s&&!(Ue(t)&&Ue(e)))return e;let n=(s?t:Object.keys(t)).length,a=s?e:Object.keys(e),u=a.length,c=s?new Array(u):{},d=0;for(let h=0;h<u;h++){let f=s?h:a[h],m=t[f],p=e[f];if(m===p){c[f]=m,(s?h<n:gr.call(t,f))&&d++;continue}if(m===null||p===null||typeof m!="object"||typeof p!="object"){c[f]=p;continue}let y=pe(m,p,r+1);c[f]=y,y===m&&d++}return n===u&&d===n?t:c}o(pe,"replaceEqualDeep");function ge(t,e){if(!e||Object.keys(t).length!==Object.keys(e).length)return!1;for(let r in t)if(t[r]!==e[r])return!1;return!0}o(ge,"shallowEqualObjects");function ft(t){return Array.isArray(t)&&t.length===Object.keys(t).length}o(ft,"isPlainArray");function Ue(t){if(!mt(t))return!1;let e=t.constructor;if(e===void 0)return!0;let r=e.prototype;return!(!mt(r)||!r.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(t)!==Object.prototype)}o(Ue,"isPlainObject");function mt(t){return Object.prototype.toString.call(t)==="[object Object]"}o(mt,"hasObjectPrototype");function yt(t){return new Promise(e=>{F.setTimeout(e,t)})}o(yt,"sleep");function ne(t,e,r){if(typeof r.structuralSharing=="function")return r.structuralSharing(t,e);if(r.structuralSharing!==!1){try{return pe(t,e)}catch(s){throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${r.queryHash}]: ${s}`),s}return pe(t,e)}return e}o(ne,"replaceData");function Sr(t){return t}o(Sr,"keepPreviousData");function bt(t,e,r=0){let s=[...t,e];return r&&s.length>r?s.slice(1):s}o(bt,"addToEnd");function vt(t,e,r=0){let s=[e,...t];return r&&s.length>r?s.slice(0,-1):s}o(vt,"addToStart");var $=Symbol();function Se(t,e){return t.queryFn===$&&console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${t.queryHash}'`),!t.queryFn&&e?.initialPromise?()=>e.initialPromise:!t.queryFn||t.queryFn===$?()=>Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)):t.queryFn}o(Se,"ensureQueryFn");function we(t,e){return typeof t=="function"?t(...e):!!t}o(we,"shouldThrowError");function gt(t,e,r){let s=!1,i;return Object.defineProperty(t,"signal",{enumerable:!0,get:o(()=>(i??=e(),s||(s=!0,i.aborted?r():i.addEventListener("abort",r,{once:!0})),i),"get")}),t}o(gt,"addConsumeAwareSignal");var N=(()=>{let t=o(()=>He,"isServerFn");return{isServer(){return t()},setIsServer(e){t=e}}})();function oe(){let t,e,r=new Promise((i,n)=>{t=i,e=n});r.status="pending",r.catch(()=>{});function s(i){Object.assign(r,i),delete r.resolve,delete r.reject}return o(s,"finalize"),r.resolve=i=>{s({status:"fulfilled",value:i}),t(i)},r.reject=i=>{s({status:"rejected",reason:i}),e(i)},r}o(oe,"pendingThenable");var St=lt;function wr(){let t=[],e=0,r=o(u=>{u()},"notifyFn"),s=o(u=>{u()},"batchNotifyFn"),i=St,n=o(u=>{e?t.push(u):i(()=>{r(u)})},"schedule"),a=o(()=>{let u=t;t=[],u.length&&i(()=>{s(()=>{u.forEach(c=>{r(c)})})})},"flush");return{batch:o(u=>{let c;e++;try{c=u()}finally{e--,e||a()}return c},"batch"),batchCalls:o(u=>(...c)=>{n(()=>{u(...c)})},"batchCalls"),schedule:n,setNotifyFunction:o(u=>{r=u},"setNotifyFunction"),setBatchNotifyFunction:o(u=>{s=u},"setBatchNotifyFunction"),setScheduler:o(u=>{i=u},"setScheduler")}}o(wr,"createNotifyManager");var v=wr();var Tr=class extends M{static{o(this,"OnlineManager")}#t=!0;#e;#r;constructor(){super(),this.#r=t=>{if(typeof window<"u"&&window.addEventListener){let e=o(()=>t(!0),"onlineListener"),r=o(()=>t(!1),"offlineListener");return window.addEventListener("online",e,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",r)}}}}onSubscribe(){this.#e||this.setEventListener(this.#r)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#r=t,this.#e?.(),this.#e=t(this.setOnline.bind(this))}setOnline(t){this.#t!==t&&(this.#t=t,this.listeners.forEach(r=>{r(t)}))}isOnline(){return this.#t}},Z=new Tr;function Er(t){return Math.min(1e3*2**t,3e4)}o(Er,"defaultRetryDelay");function Qe(t){return(t??"online")==="online"?Z.isOnline():!0}o(Qe,"canFetch");var Te=class extends Error{static{o(this,"CancelledError")}constructor(t){super("CancelledError"),this.revert=t?.revert,this.silent=t?.silent}};function Ee(t){let e=!1,r=0,s,i=oe(),n=o(()=>i.status!=="pending","isResolved"),a=o(b=>{if(!n()){let g=new Te(b);m(g),t.onCancel?.(g)}},"cancel"),u=o(()=>{e=!0},"cancelRetry"),c=o(()=>{e=!1},"continueRetry"),d=o(()=>Y.isFocused()&&(t.networkMode==="always"||Z.isOnline())&&t.canRun(),"canContinue"),h=o(()=>Qe(t.networkMode)&&t.canRun(),"canStart"),f=o(b=>{n()||(s?.(),i.resolve(b))},"resolve"),m=o(b=>{n()||(s?.(),i.reject(b))},"reject"),p=o(()=>new Promise(b=>{s=o(g=>{(n()||d())&&b(g)},"continueFn"),t.onPause?.()}).then(()=>{s=void 0,n()||t.onContinue?.()}),"pause"),y=o(()=>{if(n())return;let b,g=r===0?t.initialPromise:void 0;try{b=g??t.fn()}catch(E){b=Promise.reject(E)}Promise.resolve(b).then(f).catch(E=>{if(n())return;let I=t.retry??(N.isServer()?0:3),U=t.retryDelay??Er,B=typeof U=="function"?U(r,E):U,q=I===!0||typeof I=="number"&&r<I||typeof I=="function"&&I(r,E);if(e||!q){m(E);return}r++,t.onFail?.(r,E),yt(B).then(()=>d()?void 0:p()).then(()=>{e?m(E):y()})})},"run");return{promise:i,status:o(()=>i.status,"status"),cancel:a,continue:o(()=>(s?.(),i),"continue"),cancelRetry:u,continueRetry:c,canStart:h,start:o(()=>(h()?y():p().then(y),i),"start")}}o(Ee,"createRetryer");var Ce=class{static{o(this,"Removable")}#t;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),se(this.gcTime)&&(this.#t=F.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,t??(N.isServer()?1/0:300*1e3))}clearGcTimeout(){this.#t!==void 0&&(F.clearTimeout(this.#t),this.#t=void 0)}};function Tt(t){return{onFetch:o((e,r)=>{let s=e.options,i=e.fetchOptions?.meta?.fetchMore?.direction,n=e.state.data?.pages||[],a=e.state.data?.pageParams||[],u={pages:[],pageParams:[]},c=0,d=o(async()=>{let h=!1,f=o(y=>{gt(y,()=>e.signal,()=>h=!0)},"addSignalProperty"),m=Se(e.options,e.fetchOptions),p=o(async(y,b,g)=>{if(h)return Promise.reject(e.signal.reason);if(b==null&&y.pages.length)return Promise.resolve(y);let I=o(()=>{let De={client:e.client,queryKey:e.queryKey,pageParam:b,direction:g?"backward":"forward",meta:e.options.meta};return f(De),De},"createQueryFnContext")(),U=await m(I),{maxPages:B}=e.options,q=g?vt:bt;return{pages:q(y.pages,U,B),pageParams:q(y.pageParams,b,B)}},"fetchPage");if(i&&n.length){let y=i==="backward",b=y?Cr:wt,g={pages:n,pageParams:a},E=b(s,g);u=await p(g,E,y)}else{let y=t??n.length;do{let b=c===0?a[0]??s.initialPageParam:wt(s,u);if(c>0&&b==null)break;u=await p(u,b),c++}while(c<y)}return u},"fetchFn");e.options.persister?e.fetchFn=()=>e.options.persister?.(d,{client:e.client,queryKey:e.queryKey,meta:e.options.meta,signal:e.signal},r):e.fetchFn=d},"onFetch")}}o(Tt,"infiniteQueryBehavior");function wt(t,{pages:e,pageParams:r}){let s=e.length-1;return e.length>0?t.getNextPageParam(e[s],e,r[s],r):void 0}o(wt,"getNextPageParam");function Cr(t,{pages:e,pageParams:r}){return e.length>0?t.getPreviousPageParam?.(e[0],e,r[0],r):void 0}o(Cr,"getPreviousPageParam");var It=class extends Ce{static{o(this,"Query")}#t;#e;#r;#s;#n;#i;#a;#o;constructor(t){super(),this.#o=!1,this.#a=t.defaultOptions,this.setOptions(t.options),this.observers=[],this.#n=t.client,this.#s=this.#n.getQueryCache(),this.queryKey=t.queryKey,this.queryHash=t.queryHash,this.#e=Ct(this.options),this.state=t.state??this.#e,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#t}get promise(){return this.#i?.promise}setOptions(t){if(this.options={...this.#a,...t},t?._type&&(this.#t=t._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let e=Ct(this.options);e.data!==void 0&&(this.setState(Et(e.data,e.dataUpdatedAt)),this.#e=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#s.remove(this)}setData(t,e){let r=ne(this.state.data,t,this.options);return this.#c({data:r,type:"success",dataUpdatedAt:e?.updatedAt,manual:e?.manual}),r}setState(t){this.#c({type:"setState",state:t})}cancel(t){let e=this.#i?.promise;return this.#i?.cancel(t),e?e.then(S).catch(S):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#e}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(t=>A(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===$||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0?this.observers.some(t=>x(t.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(t=0){return this.state.data===void 0?!0:t==="static"?!1:this.state.isInvalidated?!0:!ye(this.state.dataUpdatedAt,t)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#i?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#i?.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),this.#s.notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(e=>e!==t),this.observers.length||(this.#i&&(this.#o||this.#h()?this.#i.cancel({revert:!0}):this.#i.cancelRetry()),this.scheduleGc()),this.#s.notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}#h(){return this.state.fetchStatus==="paused"&&this.state.status==="pending"}invalidate(){this.state.isInvalidated||this.#c({type:"invalidate"})}async fetch(t,e){if(this.state.fetchStatus!=="idle"&&this.#i?.status()!=="rejected"){if(this.state.data!==void 0&&e?.cancelRefetch)this.cancel({silent:!0});else if(this.#i)return this.#i.continueRetry(),this.#i.promise}if(t&&this.setOptions(t),!this.options.queryFn){let c=this.observers.find(d=>d.options.queryFn);c&&this.setOptions(c.options)}Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']");let r=new AbortController,s=o(c=>{Object.defineProperty(c,"signal",{enumerable:!0,get:o(()=>(this.#o=!0,r.signal),"get")})},"addSignalProperty"),i=o(()=>{let c=Se(this.options,e),h=o(()=>{let f={client:this.#n,queryKey:this.queryKey,meta:this.meta};return s(f),f},"createQueryFnContext")();return this.#o=!1,this.options.persister?this.options.persister(c,h,this):c(h)},"fetchFn"),a=o(()=>{let c={fetchOptions:e,options:this.options,queryKey:this.queryKey,client:this.#n,state:this.state,fetchFn:i};return s(c),c},"createFetchContext")();(this.#t==="infinite"?Tt(this.options.pages):this.options.behavior)?.onFetch(a,this),this.#r=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#c({type:"fetch",meta:a.fetchOptions?.meta}),this.#i=Ee({initialPromise:e?.initialPromise,fn:a.fetchFn,onCancel:o(c=>{c instanceof Te&&c.revert&&this.setState({...this.#r,fetchStatus:"idle"}),r.abort()},"onCancel"),onFail:o((c,d)=>{this.#c({type:"failed",failureCount:c,error:d})},"onFail"),onPause:o(()=>{this.#c({type:"pause"})},"onPause"),onContinue:o(()=>{this.#c({type:"continue"})},"onContinue"),retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:o(()=>!0,"canRun")});try{let c=await this.#i.start();if(c===void 0)throw console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),new Error(`${this.queryHash} data is undefined`);return this.setData(c),this.#s.config.onSuccess?.(c,this),this.#s.config.onSettled?.(c,this.state.error,this),c}catch(c){if(c instanceof Te){if(c.silent)return this.#i.promise;if(c.revert){if(this.state.data===void 0)throw c;return this.state.data}}throw this.#c({type:"error",error:c}),this.#s.config.onError?.(c,this),this.#s.config.onSettled?.(this.state.data,c,this),c}finally{this.scheduleGc()}}#c(t){let e=o(r=>{switch(t.type){case"failed":return{...r,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...Be(r.data,this.options),fetchMeta:t.meta??null};case"success":let s={...r,...Et(t.data,t.dataUpdatedAt),dataUpdateCount:r.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return this.#r=t.manual?s:void 0,s;case"error":let i=t.error;return{...r,error:i,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:i,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...t.state}}},"reducer");this.state=e(this.state),v.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),this.#s.notify({query:this,type:"updated",action:t})})}};function Be(t,e){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Qe(e.networkMode)?"fetching":"paused",...t===void 0&&{error:null,status:"pending"}}}o(Be,"fetchState");function Et(t,e){return{data:t,dataUpdatedAt:e??Date.now(),error:null,isInvalidated:!1,status:"success"}}o(Et,"successState");function Ct(t){let e=typeof t.initialData=="function"?t.initialData():t.initialData,r=e!==void 0,s=r?typeof t.initialDataUpdatedAt=="function"?t.initialDataUpdatedAt():t.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:r?s??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}o(Ct,"getDefaultState");var Ke=class extends M{static{o(this,"QueryObserver")}constructor(t,e){super(),this.options=e,this.#t=t,this.#o=null,this.#a=oe(),this.bindMethods(),this.setOptions(e)}#t;#e=void 0;#r=void 0;#s=void 0;#n;#i;#a;#o;#h;#c;#m;#d;#l;#u;#p=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#e.addObserver(this),At(this.#e,this.options)?this.#f():this.updateResult(),this.#g())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return qe(this.#e,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return qe(this.#e,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#S(),this.#w(),this.#e.removeObserver(this)}setOptions(t){let e=this.options,r=this.#e;if(this.options=this.#t.defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof A(this.options.enabled,this.#e)!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#T(),this.#e.setOptions(this.options),e._defaulted&&!ge(this.options,e)&&this.#t.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#e,observer:this});let s=this.hasListeners();s&&kt(this.#e,r,this.options,e)&&this.#f(),this.updateResult(),s&&(this.#e!==r||A(this.options.enabled,this.#e)!==A(e.enabled,this.#e)||x(this.options.staleTime,this.#e)!==x(e.staleTime,this.#e))&&this.#y();let i=this.#b();s&&(this.#e!==r||A(this.options.enabled,this.#e)!==A(e.enabled,this.#e)||i!==this.#u)&&this.#v(i)}getOptimisticResult(t){let e=this.#t.getQueryCache().build(this.#t,t),r=this.createResult(e,t);return Ar(this,r)&&(this.#s=r,this.#i=this.options,this.#n=this.#e.state),r}getCurrentResult(){return this.#s}trackResult(t,e){return new Proxy(t,{get:o((r,s)=>(this.trackProp(s),e?.(s),s==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&this.#a.status==="pending"&&this.#a.reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(r,s)),"get")})}trackProp(t){this.#p.add(t)}getCurrentQuery(){return this.#e}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){let e=this.#t.defaultQueryOptions(t),r=this.#t.getQueryCache().build(this.#t,e);return r.fetch().then(()=>this.createResult(r,e))}fetch(t){return this.#f({...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#s))}#f(t){this.#T();let e=this.#e.fetch(this.options,t);return t?.throwOnError||(e=e.catch(S)),e}#y(){this.#S();let t=x(this.options.staleTime,this.#e);if(N.isServer()||this.#s.isStale||!se(t))return;let r=ye(this.#s.dataUpdatedAt,t)+1;this.#d=F.setTimeout(()=>{this.#s.isStale||this.updateResult()},r)}#b(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.#e):this.options.refetchInterval)??!1}#v(t){this.#w(),this.#u=t,!(N.isServer()||A(this.options.enabled,this.#e)===!1||!se(this.#u)||this.#u===0)&&(this.#l=F.setInterval(()=>{(this.options.refetchIntervalInBackground||Y.isFocused())&&this.#f()},this.#u))}#g(){this.#y(),this.#v(this.#b())}#S(){this.#d!==void 0&&(F.clearTimeout(this.#d),this.#d=void 0)}#w(){this.#l!==void 0&&(F.clearInterval(this.#l),this.#l=void 0)}createResult(t,e){let r=this.#e,s=this.options,i=this.#s,n=this.#n,a=this.#i,c=t!==r?t.state:this.#r,{state:d}=t,h={...d},f=!1,m;if(e._optimisticResults){let _=this.hasListeners(),re=!_&&At(t,e),le=_&&kt(t,r,e,s);(re||le)&&(h={...h,...Be(d.data,t.options)}),e._optimisticResults==="isRestoring"&&(h.fetchStatus="idle")}let{error:p,errorUpdatedAt:y,status:b}=h;m=h.data;let g=!1;if(e.placeholderData!==void 0&&m===void 0&&b==="pending"){let _;i?.isPlaceholderData&&e.placeholderData===a?.placeholderData?(_=i.data,g=!0):_=typeof e.placeholderData=="function"?e.placeholderData(this.#m?.state.data,this.#m):e.placeholderData,_!==void 0&&(b="success",m=ne(i?.data,_,e),f=!0)}if(e.select&&m!==void 0&&!g)if(i&&m===n?.data&&e.select===this.#h)m=this.#c;else try{this.#h=e.select,m=e.select(m),m=ne(i?.data,m,e),this.#c=m,this.#o=null}catch(_){this.#o=_}this.#o&&(p=this.#o,m=this.#c,y=Date.now(),b="error");let E=h.fetchStatus==="fetching",I=b==="pending",U=b==="error",B=I&&E,q=m!==void 0,H={status:b,fetchStatus:h.fetchStatus,isPending:I,isSuccess:b==="success",isError:U,isInitialLoading:B,isLoading:B,data:m,dataUpdatedAt:h.dataUpdatedAt,error:p,errorUpdatedAt:y,failureCount:h.fetchFailureCount,failureReason:h.fetchFailureReason,errorUpdateCount:h.errorUpdateCount,isFetched:t.isFetched(),isFetchedAfterMount:h.dataUpdateCount>c.dataUpdateCount||h.errorUpdateCount>c.errorUpdateCount,isFetching:E,isRefetching:E&&!I,isLoadingError:U&&!q,isPaused:h.fetchStatus==="paused",isPlaceholderData:f,isRefetchError:U&&q,isStale:je(t,e),refetch:this.refetch,promise:this.#a,isEnabled:A(e.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){let _=H.data!==void 0,re=H.status==="error"&&!_,le=o(me=>{re?me.reject(H.error):_&&me.resolve(H.data)},"finalizeThenableIfPossible"),ut=o(()=>{let me=this.#a=H.promise=oe();le(me)},"recreateThenable"),fe=this.#a;switch(fe.status){case"pending":t.queryHash===r.queryHash&&le(fe);break;case"fulfilled":(re||H.data!==fe.value)&&ut();break;case"rejected":(!re||H.error!==fe.reason)&&ut();break}}return H}updateResult(){let t=this.#s,e=this.createResult(this.#e,this.options);if(this.#n=this.#e.state,this.#i=this.options,this.#n.data!==void 0&&(this.#m=this.#e),ge(e,t))return;this.#s=e;let r=o(()=>{if(!t)return!0;let{notifyOnChangeProps:s}=this.options,i=typeof s=="function"?s():s;if(i==="all"||!i&&!this.#p.size)return!0;let n=new Set(i??this.#p);return this.options.throwOnError&&n.add("error"),Object.keys(this.#s).some(a=>{let u=a;return this.#s[u]!==t[u]&&n.has(u)})},"shouldNotifyListeners");this.#E({listeners:r()})}#T(){let t=this.#t.getQueryCache().build(this.#t,this.options);if(t===this.#e)return;let e=this.#e;this.#e=t,this.#r=t.state,this.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#g()}#E(t){v.batch(()=>{t.listeners&&this.listeners.forEach(e=>{e(this.#s)}),this.#t.getQueryCache().notify({query:this.#e,type:"observerResultsUpdated"})})}};function Ir(t,e){return A(e.enabled,t)!==!1&&t.state.data===void 0&&!(t.state.status==="error"&&A(e.retryOnMount,t)===!1)}o(Ir,"shouldLoadOnMount");function At(t,e){return Ir(t,e)||t.state.data!==void 0&&qe(t,e,e.refetchOnMount)}o(At,"shouldFetchOnMount");function qe(t,e,r){if(A(e.enabled,t)!==!1&&x(e.staleTime,t)!=="static"){let s=typeof r=="function"?r(t):r;return s==="always"||s!==!1&&je(t,e)}return!1}o(qe,"shouldFetchOn");function kt(t,e,r,s){return(t!==e||A(s.enabled,t)===!1)&&(!r.suspense||t.state.status!=="error")&&je(t,r)}o(kt,"shouldFetchOptionally");function je(t,e){return A(e.enabled,t)!==!1&&t.isStaleByTime(x(e.staleTime,t))}o(je,"isStale");function Ar(t,e){return!ge(t.getCurrentResult(),e)}o(Ar,"shouldAssignObserverCurrentProperties");var _t=class extends Ce{static{o(this,"Mutation")}#t;#e;#r;#s;constructor(t){super(),this.#t=t.client,this.mutationId=t.mutationId,this.#r=t.mutationCache,this.#e=[],this.state=t.state||kr(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){this.#e.includes(t)||(this.#e.push(t),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#e=this.#e.filter(e=>e!==t),this.scheduleGc(),this.#r.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#e.length||(this.state.status==="pending"?this.scheduleGc():this.#r.remove(this))}continue(){return this.#s?.continue()??this.execute(this.state.variables)}async execute(t){let e=o(()=>{this.#n({type:"continue"})},"onContinue"),r={client:this.#t,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#s=Ee({fn:o(()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),"fn"),onFail:o((n,a)=>{this.#n({type:"failed",failureCount:n,error:a})},"onFail"),onPause:o(()=>{this.#n({type:"pause"})},"onPause"),onContinue:e,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:o(()=>this.#r.canRun(this),"canRun")});let s=this.state.status==="pending",i=!this.#s.canStart();try{if(s)e();else{this.#n({type:"pending",variables:t,isPaused:i}),this.#r.config.onMutate&&await this.#r.config.onMutate(t,this,r);let a=await this.options.onMutate?.(t,r);a!==this.state.context&&this.#n({type:"pending",context:a,variables:t,isPaused:i})}let n=await this.#s.start();return await this.#r.config.onSuccess?.(n,t,this.state.context,this,r),await this.options.onSuccess?.(n,t,this.state.context,r),await this.#r.config.onSettled?.(n,null,this.state.variables,this.state.context,this,r),await this.options.onSettled?.(n,null,t,this.state.context,r),this.#n({type:"success",data:n}),n}catch(n){try{await this.#r.config.onError?.(n,t,this.state.context,this,r)}catch(a){Promise.reject(a)}try{await this.options.onError?.(n,t,this.state.context,r)}catch(a){Promise.reject(a)}try{await this.#r.config.onSettled?.(void 0,n,this.state.variables,this.state.context,this,r)}catch(a){Promise.reject(a)}try{await this.options.onSettled?.(void 0,n,t,this.state.context,r)}catch(a){Promise.reject(a)}throw this.#n({type:"error",error:n}),n}finally{this.#r.runNext(this)}}#n(t){let e=o(r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}},"reducer");this.state=e(this.state),v.batch(()=>{this.#e.forEach(r=>{r.onMutationUpdate(t)}),this.#r.notify({mutation:this,type:"updated",action:t})})}};function kr(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}o(kr,"getDefaultState");var Rt=class extends M{static{o(this,"MutationCache")}constructor(t={}){super(),this.config=t,this.#t=new Set,this.#e=new Map,this.#r=0}#t;#e;#r;build(t,e,r){let s=new _t({client:t,mutationCache:this,mutationId:++this.#r,options:t.defaultMutationOptions(e),state:r});return this.add(s),s}add(t){this.#t.add(t);let e=Ie(t);if(typeof e=="string"){let r=this.#e.get(e);r?r.push(t):this.#e.set(e,[t])}this.notify({type:"added",mutation:t})}remove(t){if(this.#t.delete(t)){let e=Ie(t);if(typeof e=="string"){let r=this.#e.get(e);if(r)if(r.length>1){let s=r.indexOf(t);s!==-1&&r.splice(s,1)}else r[0]===t&&this.#e.delete(e)}}this.notify({type:"removed",mutation:t})}canRun(t){let e=Ie(t);if(typeof e=="string"){let s=this.#e.get(e)?.find(i=>i.state.status==="pending");return!s||s===t}else return!0}runNext(t){let e=Ie(t);return typeof e=="string"?this.#e.get(e)?.find(s=>s!==t&&s.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){v.batch(()=>{this.#t.forEach(t=>{this.notify({type:"removed",mutation:t})}),this.#t.clear(),this.#e.clear()})}getAll(){return Array.from(this.#t)}find(t){let e={exact:!0,...t};return this.getAll().find(r=>ve(e,r))}findAll(t={}){return this.getAll().filter(e=>ve(t,e))}notify(t){v.batch(()=>{this.listeners.forEach(e=>{e(t)})})}resumePausedMutations(){let t=this.getAll().filter(e=>e.state.isPaused);return v.batch(()=>Promise.all(t.map(e=>e.continue().catch(S))))}};function Ie(t){return t.options.scope?.id}o(Ie,"scopeFor");var Ot=class extends M{static{o(this,"QueryCache")}constructor(t={}){super(),this.config=t,this.#t=new Map}#t;build(t,e,r){let s=e.queryKey,i=e.queryHash??ie(s,e),n=this.get(i);return n||(n=new It({client:t,queryKey:s,queryHash:i,options:t.defaultQueryOptions(e),state:r,defaultOptions:t.getQueryDefaults(s)}),this.add(n)),n}add(t){this.#t.has(t.queryHash)||(this.#t.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){let e=this.#t.get(t.queryHash);e&&(t.destroy(),e===t&&this.#t.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){v.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return this.#t.get(t)}getAll(){return[...this.#t.values()]}find(t){let e={exact:!0,...t};return this.getAll().find(r=>be(e,r))}findAll(t={}){let e=this.getAll();return Object.keys(t).length>0?e.filter(r=>be(t,r)):e}notify(t){v.batch(()=>{this.listeners.forEach(e=>{e(t)})})}onFocus(){v.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){v.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}};var $e=class{static{o(this,"QueryClient")}#t;#e;#r;#s;#n;#i;#a;#o;constructor(t={}){this.#t=t.queryCache||new Ot,this.#e=t.mutationCache||new Rt,this.#r=t.defaultOptions||{},this.#s=new Map,this.#n=new Map,this.#i=0}mount(){this.#i++,this.#i===1&&(this.#a=Y.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#t.onFocus())}),this.#o=Z.subscribe(async t=>{t&&(await this.resumePausedMutations(),this.#t.onOnline())}))}unmount(){this.#i--,this.#i===0&&(this.#a?.(),this.#a=void 0,this.#o?.(),this.#o=void 0)}isFetching(t){return this.#t.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#e.findAll({...t,status:"pending"}).length}getQueryData(t){let e=this.defaultQueryOptions({queryKey:t});return this.#t.get(e.queryHash)?.state.data}ensureQueryData(t){let e=this.defaultQueryOptions(t),r=this.#t.build(this,e),s=r.state.data;return s===void 0?this.fetchQuery(t):(t.revalidateIfStale&&r.isStaleByTime(x(e.staleTime,r))&&this.prefetchQuery(e),Promise.resolve(s))}getQueriesData(t){return this.#t.findAll(t).map(({queryKey:e,state:r})=>{let s=r.data;return[e,s]})}setQueryData(t,e,r){let s=this.defaultQueryOptions({queryKey:t}),n=this.#t.get(s.queryHash)?.state.data,a=pt(e,n);if(a!==void 0)return this.#t.build(this,s).setData(a,{...r,manual:!0})}setQueriesData(t,e,r){return v.batch(()=>this.#t.findAll(t).map(({queryKey:s})=>[s,this.setQueryData(s,e,r)]))}getQueryState(t){let e=this.defaultQueryOptions({queryKey:t});return this.#t.get(e.queryHash)?.state}removeQueries(t){let e=this.#t;v.batch(()=>{e.findAll(t).forEach(r=>{e.remove(r)})})}resetQueries(t,e){let r=this.#t;return v.batch(()=>(r.findAll(t).forEach(s=>{s.reset()}),this.refetchQueries({type:"active",...t},e)))}cancelQueries(t,e={}){let r={revert:!0,...e},s=v.batch(()=>this.#t.findAll(t).map(i=>i.cancel(r)));return Promise.all(s).then(S).catch(S)}invalidateQueries(t,e={}){return v.batch(()=>(this.#t.findAll(t).forEach(r=>{r.invalidate()}),t?.refetchType==="none"?Promise.resolve():this.refetchQueries({...t,type:t?.refetchType??t?.type??"active"},e)))}refetchQueries(t,e={}){let r={...e,cancelRefetch:e.cancelRefetch??!0},s=v.batch(()=>this.#t.findAll(t).filter(i=>!i.isDisabled()&&!i.isStatic()).map(i=>{let n=i.fetch(void 0,r);return r.throwOnError||(n=n.catch(S)),i.state.fetchStatus==="paused"?Promise.resolve():n}));return Promise.all(s).then(S)}fetchQuery(t){let e=this.defaultQueryOptions(t);e.retry===void 0&&(e.retry=!1);let r=this.#t.build(this,e);return r.isStaleByTime(x(e.staleTime,r))?r.fetch(e):Promise.resolve(r.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(S).catch(S)}fetchInfiniteQuery(t){return t._type="infinite",this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(S).catch(S)}ensureInfiniteQueryData(t){return t._type="infinite",this.ensureQueryData(t)}resumePausedMutations(){return Z.isOnline()?this.#e.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#t}getMutationCache(){return this.#e}getDefaultOptions(){return this.#r}setDefaultOptions(t){this.#r=t}setQueryDefaults(t,e){this.#s.set(j(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){let e=[...this.#s.values()],r={};return e.forEach(s=>{W(t,s.queryKey)&&Object.assign(r,s.defaultOptions)}),r}setMutationDefaults(t,e){this.#n.set(j(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){let e=[...this.#n.values()],r={};return e.forEach(s=>{W(t,s.mutationKey)&&Object.assign(r,s.defaultOptions)}),r}defaultQueryOptions(t){if(t._defaulted)return t;let e={...this.#r.queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=ie(e.queryKey,e)),e.refetchOnReconnect===void 0&&(e.refetchOnReconnect=e.networkMode!=="always"),e.throwOnError===void 0&&(e.throwOnError=!!e.suspense),!e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),e.queryFn===$&&(e.enabled=!1),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#r.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#t.clear(),this.#e.clear()}};var ee=R(K(),1),Pt=R(dt(),1);var ae=ee.createContext(void 0),We=o(t=>{let e=ee.useContext(ae);if(t)return t;if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e},"useQueryClient"),Ve=o(({client:t,children:e})=>(ee.useEffect(()=>(t.mount(),()=>{t.unmount()}),[t]),(0,Pt.jsx)(ae.Provider,{value:t,children:e})),"QueryClientProvider");var Ae=R(K(),1);var Lt=Ae.createContext(!1),xt=o(()=>Ae.useContext(Lt),"useIsRestoring"),Eo=Lt.Provider;var ce=R(K(),1),_r=R(dt(),1);function Rr(){let t=!1;return{clearReset:o(()=>{t=!1},"clearReset"),reset:o(()=>{t=!0},"reset"),isReset:o(()=>t,"isReset")}}o(Rr,"createValue");var Or=ce.createContext(Rr()),Mt=o(()=>ce.useContext(Or),"useQueryErrorResetBoundary");var Ft=R(K(),1);var Nt=o((t,e,r)=>{let s=r?.state.error&&typeof t.throwOnError=="function"?we(t.throwOnError,[r.state.error,r]):t.throwOnError;(t.suspense||t.experimental_prefetchInRender||s)&&(e.isReset()||(t.retryOnMount=!1))},"ensurePreventErrorBoundaryRetry"),Dt=o(t=>{Ft.useEffect(()=>{t.clearReset()},[t])},"useClearResetErrorBoundary"),Ut=o(({result:t,errorResetBoundary:e,throwOnError:r,query:s,suspense:i})=>t.isError&&!e.isReset()&&!t.isFetching&&s&&(i&&t.data===void 0||we(r,[t.error,s])),"getHasError");var Ht=o(t=>{if(t.suspense){let r=o(i=>i==="static"?i:Math.max(i??1e3,1e3),"clamp"),s=t.staleTime;t.staleTime=typeof s=="function"?(...i)=>r(s(...i)):r(s),typeof t.gcTime=="number"&&(t.gcTime=Math.max(t.gcTime,1e3))}},"ensureSuspenseTimers"),Qt=o((t,e)=>t.isLoading&&t.isFetching&&!e,"willFetch"),Bt=o((t,e)=>t?.suspense&&e.isPending,"shouldSuspend"),Ge=o((t,e,r)=>e.fetchOptimistic(t).catch(()=>{r.clearReset()}),"fetchOptimistic");var Q=R(K(),1);function qt(t,e,r){if(typeof t!="object"||Array.isArray(t))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');let s=xt(),i=Mt(),n=We(r),a=n.defaultQueryOptions(t);n.getDefaultOptions().queries?._experimental_beforeQuery?.(a);let u=n.getQueryCache().get(a.queryHash);a.queryFn||console.error(`[${a.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`);let c=t.subscribed!==!1;a._optimisticResults=s?"isRestoring":c?"optimistic":void 0,Ht(a),Nt(a,i,u),Dt(i);let d=!n.getQueryCache().get(a.queryHash),[h]=Q.useState(()=>new e(n,a)),f=h.getOptimisticResult(a),m=!s&&c;if(Q.useSyncExternalStore(Q.useCallback(p=>{let y=m?h.subscribe(v.batchCalls(p)):S;return h.updateResult(),y},[h,m]),()=>h.getCurrentResult(),()=>h.getCurrentResult()),Q.useEffect(()=>{h.setOptions(a)},[a,h]),Bt(a,f))throw Ge(a,h,i);if(Ut({result:f,errorResetBoundary:i,throwOnError:a.throwOnError,query:u,suspense:a.suspense}))throw f.error;return n.getDefaultOptions().queries?._experimental_afterQuery?.(a,f),a.experimental_prefetchInRender&&!N.isServer()&&Qt(f,s)&&(d?Ge(a,h,i):u?.promise)?.catch(S).finally(()=>{h.updateResult()}),a.notifyOnChangeProps?f:h.trackResult(f)}o(qt,"useBaseQuery");function Pr(t,e){return qt(t,Ke,e)}o(Pr,"useQuery");var V=R(K(),1),ze=R(pr(),1);var jt=(0,V.createContext)(null),Lr=o(()=>new $e({defaultOptions:{mutations:{retry:0},queries:{gcTime:5*6e4,retry:0,staleTime:Number.POSITIVE_INFINITY}}}),"createDefaultQueryClient"),xr=o(t=>{let e=(0,Kt.c)(9),{children:r,client:s,queryClient:i}=t,n=(0,V.use)(ae),a;e[0]!==n||e[1]!==i?(a=o(()=>i??n??Lr(),"t1"),e[0]=n,e[1]=i,e[2]=a):a=e[2];let[u]=(0,V.useState)(a),c=i??n??u;if(!c)throw new l("INTERNAL","LunoraProvider: failed to resolve a QueryClient");let d;e[3]!==r||e[4]!==s?(d=(0,ze.jsxDEV)(jt,{value:s,children:r},void 0,!1),e[3]=r,e[4]=s,e[5]=d):d=e[5];let h=d;if(n===c)return h;let f;return e[6]!==h||e[7]!==c?(f=(0,ze.jsxDEV)(Ve,{client:c,children:h},void 0,!1),e[6]=h,e[7]=c,e[8]=f):f=e[8],f},"LunoraProvider"),Je=o(()=>{let t=(0,V.use)(jt);if(!t)throw new l("INTERNAL","useLunora must be used inside <LunoraProvider />");return t},"useLunora");var $t=R(ht(),1),Wt=R(K(),1);var Mr=o(()=>{let t=(0,$t.c)(4),e=Je(),r,s,i;return t[0]!==e?(r=o(n=>e.onConnectionStatus(()=>{n()}),"t0"),s=o(()=>e.connectionStatus(),"t1"),i=o(()=>e.connectionStatus(),"t2"),t[0]=e,t[1]=r,t[2]=s,t[3]=i):(r=t[1],s=t[2],i=t[3]),(0,Wt.useSyncExternalStore)(r,s,i)},"useConnectionStatus");var Vt=o(()=>{let t=null;return{get:o(()=>t,"get"),set:o(e=>{t=e},"set")}},"createInMemoryBookmarkStorage");var ke=class{static{o(this,"ClientQueryStore")}values=new Map;subscribers=new Map;get(e){return this.values.has(e.key)?this.values.get(e.key):e.defaultValue}set(e,r){if(r===void 0){this.reset(e);return}this.values.set(e.key,r),this.notify(e.key,r)}reset(e){this.values.delete(e.key),this.notify(e.key,e.defaultValue)}subscribe(e,r){let s=this.subscribers.get(e.key);return s||(s=new Set,this.subscribers.set(e.key,s)),s.add(r),()=>{s.delete(r),s.size===0&&this.subscribers.delete(e.key)}}notify(e,r){let s=this.subscribers.get(e);if(s)for(let i of s)try{i(r)}catch{}}};var Gt=0,Fr="lunora-bridge",Nr=1e3,Dr=3e3,_e=class{static{o(this,"TabCoordinator")}bc;tabId;heartbeatInterval;leaderTimeout;knownLeader=void 0;leader=!1;running=!1;lastHeartbeat=0;heartbeatTimer=void 0;leaderCheckTimer=void 0;onBecomeLeader;onStopBeingLeader;onSubscriptionData;onSubscriptionError;constructor(e={}){if(Gt+=1,this.tabId=`tab_${String(Gt)}_${crypto.randomUUID()}`,this.heartbeatInterval=e.heartbeatInterval??Nr,this.leaderTimeout=e.leaderTimeout??Dr,this.onBecomeLeader=e.onBecomeLeader,this.onStopBeingLeader=e.onStopBeingLeader,this.onSubscriptionData=e.onSubscriptionData,this.onSubscriptionError=e.onSubscriptionError,typeof BroadcastChannel>"u"){this.bc=void 0;return}this.bc=new BroadcastChannel(e.channelName??Fr),this.bc.addEventListener("message",r=>{this.handleMessage(r.data)})}start(){if(!this.running){if(this.running=!0,this.bc===void 0){this.becomeLeader();return}this.broadcast({type:"claim-leadership",tabId:this.tabId,ts:Date.now()}),setTimeout(()=>{this.running&&this.knownLeader===void 0&&this.becomeLeader()},this.leaderTimeout),this.leaderCheckTimer=setInterval(()=>{this.checkLeaderHealth()},this.leaderTimeout),this.heartbeatTimer=setInterval(()=>{this.sendHeartbeat()},this.heartbeatInterval)}}stop(){this.running=!1,this.leader&&(this.broadcast({type:"yield-leadership",tabId:this.tabId}),this.leader=!1,this.knownLeader=void 0,this.onStopBeingLeader?.()),this.heartbeatTimer!==void 0&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=void 0),this.leaderCheckTimer!==void 0&&(clearInterval(this.leaderCheckTimer),this.leaderCheckTimer=void 0),this.bc?.close()}isLeader(){return this.leader}get leaderTabId(){return this.knownLeader}get id(){return this.tabId}get isRunning(){return this.running}broadcastSubscriptionData(e,r){this.leader&&this.broadcast({type:"subscription-data",tabId:this.tabId,key:e,data:r})}broadcastSubscriptionError(e,r){this.leader&&this.broadcast({type:"subscription-error",tabId:this.tabId,key:e,error:r})}broadcast(e){this.bc?.postMessage(e)}handleMessage(e){switch(e.type){case"claim-leadership":{this.handleClaimLeadership(e);break}case"heartbeat":{this.handleHeartbeat(e);break}case"subscription-data":{if(this.leader||e.tabId===this.tabId)break;this.onSubscriptionData?.(e.key,e.data);break}case"subscription-error":{if(this.leader||e.tabId===this.tabId)break;this.onSubscriptionError?.(e.key,e.error);break}case"yield-leadership":{this.knownLeader===e.tabId&&(this.knownLeader=void 0);break}}}handleClaimLeadership(e){if(e.tabId!==this.tabId){if(this.leader){this.broadcast({type:"heartbeat",tabId:this.tabId,ts:Date.now()});return}this.knownLeader===void 0&&e.tabId<this.tabId&&(this.knownLeader=e.tabId,this.lastHeartbeat=e.ts)}}handleHeartbeat(e){if(e.tabId!==this.tabId){if(this.leader){this.resolveLeaderVsLeaderTieBreak(e);return}this.lastHeartbeat=e.ts,this.knownLeader=e.tabId}}resolveLeaderVsLeaderTieBreak(e){e.tabId<this.tabId?(this.leader=!1,this.knownLeader=e.tabId,this.lastHeartbeat=e.ts,this.onStopBeingLeader?.()):this.broadcast({type:"heartbeat",tabId:this.tabId,ts:Date.now()})}becomeLeader(){this.leader||(this.leader=!0,this.knownLeader=this.tabId,this.lastHeartbeat=Date.now(),this.onBecomeLeader?.(),this.broadcast({type:"heartbeat",tabId:this.tabId,ts:Date.now()}))}sendHeartbeat(){this.leader&&this.broadcast({type:"heartbeat",tabId:this.tabId,ts:Date.now()})}checkLeaderHealth(){this.running&&(this.leader||this.knownLeader!==void 0&&Date.now()-this.lastHeartbeat>this.leaderTimeout&&(this.knownLeader=void 0,this.broadcast({type:"claim-leadership",tabId:this.tabId,ts:Date.now()}),setTimeout(()=>{this.running&&this.knownLeader===void 0&&this.becomeLeader()},this.leaderTimeout)))}};var Xe="_creationTime",Ur=o(t=>{if(typeof t!="object"||t===null)return;let e=t._id;return typeof e=="string"?e:void 0},"rowId"),Hr=o(t=>{let e;for(let r of t){let s=r[Xe];if(typeof s=="number"){if(e!==void 0){if(s<e)return!0;if(s>e)return!1}e=s}}return!1},"isDescending"),Qr=o((t,e)=>{let r=e[Xe];if(typeof r!="number")return t.length;let s=Hr(t);for(let[i,n]of t.entries()){let a=n[Xe];if(typeof a=="number"&&(s?a<r:a>r))return i}return t.length},"insertionIndex"),zt=o(t=>{if(typeof t!="object"||t===null)return!1;let e=t;return typeof e.key=="string"&&typeof e.table=="string"&&(e.op==="insert"||e.op==="update"||e.op==="delete")},"isMutationDelta"),Jt=o((t,e)=>{if(!Array.isArray(t))return;let r=[];for(let c of t){if(Ur(c)===void 0)return;r.push(c)}let{key:s,op:i,row:n}=e;if(i==="delete"){let c=r.filter(d=>d._id!==s);return c.length===r.length?[...r]:c}if(n===void 0)return;let a=r.findIndex(c=>c._id===s);if(a===-1){let c=[...r];return c.splice(Qr(r,n),0,n),c}let u=[...r];return u[a]=n,u},"applyDelta");var Br=1024,Re=o(t=>{let e=t.maxBuffer??Br,r=[],s=[],i=!1,n,a=!1,u=o(()=>{let f=s.shift();if(!f)return!1;if(n)return f.reject(n),!0;if(r.length>0){let m=r.shift();return f.resolve({done:!1,value:m}),!0}return i?(f.resolve({done:!0,value:void 0}),!0):(s.unshift(f),!1)},"flushOne"),c={complete(){if(!(i||n))for(i=!0;u(););},fail(f){if(!(i||n))for(n=f,r.length=0;u(););},push(f){if(!(i||n||a)){if(r.length>=e){c.fail(new l("STREAM_BACKPRESSURE",`stream buffer overflow (max=${e.toString()}); the consumer cannot keep up with the producer`));return}r.push(f),u()}}},d=o(()=>{if(!a){a=!0,i=!0,r.length=0;try{t.onCancel()}catch{}for(;u(););}},"cancel");return{handle:c,iterable:{cancel:d,[Symbol.asyncIterator](){return{next(){if(n)return Promise.reject(n);if(r.length>0){let f=r.shift();return Promise.resolve({done:!1,value:f})}return i?Promise.resolve({done:!0,value:void 0}):new Promise((f,m)=>{s.push({reject:m,resolve:f})})},return(){return d(),Promise.resolve({done:!0,value:void 0})}}}}}},"createStream");var Xt=/^ /u,Yt=o(t=>typeof t=="object"&&t!==null?JSON.stringify(t):String(t),"parameterToString"),qr=o(t=>{let e="",r=[];for(let s of t.split(`
2
+ `))s.startsWith("event:")?e=s.slice(6).replace(Xt,""):s.startsWith("data:")&&r.push(s.slice(5).replace(Xt,""));return{data:r.join(`
3
+ `),event:e}},"parseSseFrame"),Kr=o((t,e,r)=>{let s=e.params??{},i=t.path.split("/").map(c=>{if(!c.startsWith(":"))return c;let d=c.slice(1),h=s[d];if(h===void 0)throw new l("HTTP_STREAM_MISSING_PARAM",`httpStream: missing path param ":${d}" for route ${t.path}`);return encodeURIComponent(Yt(h))}).join("/"),n=new URLSearchParams;for(let[c,d]of Object.entries(e.searchParams??{}))d!==void 0&&n.set(c,Yt(d));let a=n.toString();return`${r.endsWith("/")?r.slice(0,-1):r}${i}${a===""?"":`?${a}`}`},"buildHttpStreamUrl"),jr=o((t,e)=>{if(t.event==="complete")return e.complete(),!0;if(t.event==="error"){let r={};try{r=JSON.parse(t.data)}catch{}let s=typeof r.message=="string"?r.message:"stream error",i=typeof r.code=="string"?r.code:"HTTP_STREAM_ERROR";return e.fail(new l(i,s)),!0}if((t.event===""||t.event==="message")&&t.data!=="")try{e.push(JSON.parse(t.data))}catch{return e.fail(new l("HTTP_STREAM_BAD_CHUNK","httpStream: malformed SSE chunk (invalid JSON)")),!0}return!1},"handleSseFrame"),$r=o(async(t,e)=>{let r=t.getReader(),s=new TextDecoder,i="",n=o(()=>{let a=i.indexOf(`
4
+
5
+ `);for(;a!==-1;){let u=qr(i.slice(0,a));if(i=i.slice(a+2),jr(u,e))return!0;a=i.indexOf(`
6
+
7
+ `)}return!1},"drainFrames");for(;;){let{done:a,value:u}=await r.read();if(a)break;if(i+=s.decode(u,{stream:!0}).replaceAll(`\r
8
+ `,`
9
+ `),n()){await r.cancel().catch(()=>{});return}}i+=s.decode().replaceAll(`\r
10
+ `,`
11
+ `),n()||e.fail(new l("HTTP_STREAM_INTERRUPTED","httpStream: stream ended without a complete frame"))},"pumpSseBody"),Zt=o((t,e,r={})=>{let s=r.fetch??(typeof fetch=="function"?fetch.bind(globalThis):void 0);if(!s)throw new l("INTERNAL","httpStream: no `fetch` implementation available");let i=Kr(t,e??{},r.baseUrl??""),n=new AbortController,a;r.signal&&(r.signal.aborted?n.abort():(a=o(()=>{n.abort()},"onExternalAbort"),r.signal.addEventListener("abort",a,{once:!0})));let u=o(()=>{a&&r.signal?.removeEventListener("abort",a)},"detachExternalAbort"),{handle:c,iterable:d}=Re({maxBuffer:r.maxBuffer,onCancel:o(()=>{n.abort()},"onCancel")});return(async()=>{try{let h=await s(i,{headers:{accept:"text/event-stream",...r.headers},method:t.method,signal:n.signal});if(!h.ok){await h.body?.cancel().catch(()=>{}),c.fail(new l("HTTP_STREAM_STATUS",`httpStream: request failed (status ${h.status.toString()})`,{status:h.status}));return}if(!h.body){c.fail(new l("HTTP_STREAM_NO_BODY","httpStream: response has no body"));return}await $r(h.body,c)}finally{u()}})().catch(h=>{if(n.signal.aborted){c.complete();return}if(h instanceof Error&&"code"in h){c.fail(h);return}c.fail(new l("HTTP_STREAM_TRANSPORT",h instanceof Error?h.message:String(h),{cause:h}))}),d},"httpStream");var Wr=o((t,e)=>t<e?-1:t>e?1:0,"compareKeys"),Ze=o(t=>{if(t===void 0)return"null";if(typeof t=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key \u2014 pass it as a string, or use stableWireKey");if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(n=>Ze(n)).join(",")}]`;let e=Object.getPrototypeOf(t);if(e!==null&&e!==Object.prototype){let n=t.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${n} in a stable JSON cache key \u2014 only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}let r=t,s=Object.keys(r).toSorted(Wr),i=[];for(let n of s){let a=r[n];a!==void 0&&i.push(`${JSON.stringify(n)}:${Ze(a)}`)}return`{${i.join(",")}}`},"stableStringify"),Ye=o(t=>{let e="";for(let s=0;s<t.length;s+=32768)e+=String.fromCharCode(...t.subarray(s,s+32768));return btoa(e)},"toBase64"),Vr=o(t=>{let e=atob(t),r=new Uint8Array(e.length);for(let s=0;s<e.length;s+=1)r[s]=e.codePointAt(s)??0;return r},"fromBase64"),C="$lunora.wire$",Oe=64,er=1024,tr="__proto__",rr={BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int8Array,Int16Array,Int32Array,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array},sr={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},O=o((t,e=0)=>{if(e>Oe)throw new RangeError(`wire-codec: value nesting exceeds the ${Oe}-level limit`);if(t===void 0)return[C,"undefined"];if(t===null)return null;let r=typeof t;if(r==="bigint")return[C,"bigint",t.toString()];if(r==="number"){let a=t;return Number.isNaN(a)?[C,"nan"]:a===1/0?[C,"inf"]:a===-1/0?[C,"-inf"]:a}if(r!=="object")return t;if(t instanceof Date)return[C,"date",O(t.getTime(),e+1)];if(t instanceof Error){let a=t,u={};for(let d of Object.keys(a))a[d]!==void 0&&(u[d]=O(a[d],e+1));let c=[C,"error",a.name,a.message,u];return a.cause!==void 0&&c.push(O(a.cause,e+1)),c}if(t instanceof URL)return[C,"url",t.href];if(t instanceof Map)return[C,"map",[...t.entries()].map(([a,u])=>[O(a,e+1),O(u,e+1)])];if(t instanceof Set)return[C,"set",[...t].map(a=>O(a,e+1))];if(t instanceof ArrayBuffer)return[C,"bytes",Ye(new Uint8Array(t)),"ArrayBuffer"];if(ArrayBuffer.isView(t)){let a=t,u=a.constructor.name,c=new Uint8Array(a.buffer,a.byteOffset,a.byteLength);return u==="Uint8Array"?[C,"bytes",Ye(c)]:[C,"bytes",Ye(c),u]}if(Array.isArray(t)){let a=t.map(u=>O(u,e+1));return a.length>0&&a[0]===C?[C,"arr",a]:a}let s=Object.getPrototypeOf(t);if(s!==null&&s!==Object.prototype){let a=t.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${a} over the Lunora wire \u2014 only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}let i=t,n={};for(let a of Object.keys(i)){let u=i[a];u!==void 0&&(n[a]=O(u,e+1))}return n},"encodeWire"),w=o((t,e=0)=>{if(e>Oe)throw new RangeError(`wire-codec: value nesting exceeds the ${Oe}-level limit`);if(t===null||typeof t!="object")return t;if(Array.isArray(t)){if(t[0]===C)switch(t[1]){case"-inf":return-1/0;case"arr":return t[2].map(n=>w(n,e+1));case"bigint":{let n=t[2];if(typeof n!="string"||n.length>er||!/^-?\d+$/.test(n))throw new RangeError(`wire-codec: invalid or over-long bigint (max ${er} digits)`);return BigInt(n)}case"date":return new Date(w(t[2],e+1));case"map":return new Map(t[2].map(([n,a])=>[w(n,e+1),w(a,e+1)]));case"set":return new Set(t[2].map(n=>w(n,e+1)));case"url":return new URL(t[2]);case"error":{let n=t[2],a=t[3],u=(Object.hasOwn(sr,n)?sr[n]:void 0)??Error,c=new u(a);c.name!==n&&Object.defineProperty(c,"name",{configurable:!0,value:n,writable:!0});let d=w(t[4],e+1);for(let h of Object.keys(d))h===tr?Object.defineProperty(c,h,{configurable:!0,enumerable:!0,value:d[h],writable:!0}):c[h]=d[h];return t.length>5&&Object.defineProperty(c,"cause",{configurable:!0,value:w(t[5],e+1),writable:!0}),c}case"bytes":{let n=Vr(t[2]),a=t[3]??"Uint8Array";if(a==="ArrayBuffer")return n.buffer.byteLength===n.byteLength?n.buffer:n.slice().buffer;let u=Object.hasOwn(rr,a)?rr[a]:void 0;return u?new u(n.slice().buffer):n}case"inf":return 1/0;case"nan":return Number.NaN;case"undefined":return;default:return t.map(n=>w(n,e+1))}return t.map(i=>w(i,e+1))}let r=t,s={};for(let i of Object.keys(r)){let n=w(r[i],e+1);i===tr?Object.defineProperty(s,i,{configurable:!0,enumerable:!0,value:n,writable:!0}):s[i]=n}return s},"decodeWire"),G=o(t=>Ze(O(t)),"stableWireKey");var D=class t{static{o(this,"SubscriptionRegistry")}static key(e,r,s){return`${e}::${G(r)}::${s??""}`}byKey=new Map;byId=new Map;get(e){return this.byKey.get(e)}getById(e){return this.byId.get(e)}add(e){this.byKey.set(t.key(e.fn.__lunoraRef,e.args,e.shardKey),e),this.byId.set(e.id,e)}remove(e){let r=t.key(e.fn.__lunoraRef,e.args,e.shardKey);this.byKey.get(r)===e&&this.byKey.delete(r),this.byId.delete(e.id)}all(){return[...this.byKey.values()]}};var he=o((t,e)=>{let r=t;for(let s of e)try{r=s.transform(r)}catch{}return r},"foldOptimistic"),ue=o((t,e)=>{if(e!==t.lastValue){t.lastValue=e;for(let r of t.callbacks)try{r(e)}catch{}}},"notifySubscription"),et=o((t,e)=>{let r;try{r=e(t.lastValue)}catch{return}let s={id:Symbol("optimistic"),transform:e};t.optimisticLayers.push(s),ue(t,r);let i=o(()=>{let a=t.optimisticLayers.findIndex(u=>u.id===s.id);return a===-1?!1:(t.optimisticLayers.splice(a,1),!0)},"remove"),n=o(()=>{ue(t,he(t.serverBase,t.optimisticLayers))},"refold");return{confirm:o(a=>{if(a===void 0){i();return}s.commitCursor=a,t.serverCursor!==void 0&&t.serverCursor>=a&&i()&&n()},"confirm"),rollback:o(()=>{i()&&n()},"rollback")}},"applyOptimisticLayer"),tt=o((t,e)=>{if(e===void 0||t.optimisticLayers.length===0)return!1;let r=t.optimisticLayers.length;return t.optimisticLayers=t.optimisticLayers.filter(s=>s.commitCursor===void 0||s.commitCursor>e),t.optimisticLayers.length!==r},"dropConfirmedLayers"),ir=o((t,e)=>{let r=[],s=[],i=o((a,u)=>t.get(D.key(a,u,e)),"findState");return{confirms:r,rollbacks:s,store:{getAllQueries:o(a=>{let u=[];for(let c of t.all())c.fn.__lunoraRef===a.__lunoraRef&&(c.shardKey??"")===(e??"")&&u.push({args:c.args,value:c.lastValue});return u},"getAllQueries"),getQuery:o((a,u)=>i(a.__lunoraRef,u??{})?.lastValue,"getQuery"),setQuery:o((a,u,c)=>{let d=i(a.__lunoraRef,u??{});if(!d)return;let h=et(d,()=>c);h&&(r.push(h.confirm),s.push(h.rollback))},"setQuery")}}},"createLocalStore");var rt=o((t,e)=>t!==void 0&&e!==t,"isStaleVersion"),nr=0,Le=o(()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();nr+=1;let t=typeof crypto<"u"&&typeof crypto.getRandomValues=="function"?[...crypto.getRandomValues(new Uint8Array(8))].map(e=>e.toString(16).padStart(2,"0")).join(""):Math.random().toString(16).slice(2,12);return`m_${Date.now().toString(36)}_${nr.toString(36)}_${t}`},"nextId"),te=o((t,e,r,s)=>{if(t){t({error:r,mutationId:s,operation:e});return}console.warn(`[lunora] offline-queue persistence ${e} failed`,r)},"reportPersistenceError"),Pe=class{static{o(this,"OfflineQueue")}queueBeforeFirstConnect;maxItems;onPersistenceError;persistence;onEvict;onSizeChange;version;items=[];constructor(e={},r={}){this.maxItems=e.maxItems??1e3,this.queueBeforeFirstConnect=e.queueBeforeFirstConnect??!1,this.onPersistenceError=e.onPersistenceError,this.persistence=r.persistence,this.onEvict=r.onEvict,this.onSizeChange=r.onSizeChange,this.version=r.version}get size(){return this.items.length}enqueue(e){let r=e;for(r.id??=Le(),this.items.push(r),this.persistence?.append({args:r.args,functionPath:r.functionPath,id:r.id,identity:r.identity,shardKey:r.shardKey,...this.version===void 0?{}:{version:this.version}}).catch(s=>{te(this.onPersistenceError,"append",s,r.id)});this.items.length>this.maxItems;){let s=this.items.shift();if(s){s.id&&this.persistence?.remove(s.id).catch(n=>{te(this.onPersistenceError,"remove",n,s.id)});let i=new Error("offline queue overflow");i.code="OFFLINE_QUEUE_OVERFLOW",s.reject(i),this.onEvict?.(s,i)}}this.notifySize()}async hydrate(){if(!this.persistence)return[];let e;try{e=await this.persistence.load()}catch(i){throw te(this.onPersistenceError,"load",i),i}let r=new Set,s=[];for(let i of e)if(!(this.items.some(n=>n.id===i.id)||s.some(n=>n.id===i.id))){if(rt(this.version,i.version)){this.persistence.remove(i.id).catch(n=>{te(this.onPersistenceError,"remove",n,i.id)});continue}s.push({args:i.args,functionPath:i.functionPath,id:i.id,identity:i.identity,reject:o(()=>{},"reject"),resolve:o(()=>{},"resolve"),shardKey:i.shardKey}),r.add(i.shardKey)}return this.items.unshift(...s),this.notifySize(),[...r]}drain(e){if(!e){let i=[...this.items];return this.items.length=0,this.notifySize(),i}let r=[],s=[];for(let i of this.items)(e(i)?r:s).push(i);return this.items.length=0,this.items.push(...s),this.notifySize(),r}requeue(e){e.length!==0&&(this.items.unshift(...e),this.notifySize())}drainConflict(){let e=[],r=[];for(let s of this.items)if(s.precondition!==void 0&&!s.precondition()){let i=new Error("offline mutation skipped: precondition failed before replay");i.code="OFFLINE_PRECONDITION_FAILED",s.reject(i),e.push(s)}else r.push(s);return e.length>0&&(this.items.length=0,this.items.push(...r),this.notifySize()),e}clear(){for(let e of this.items){let r=new Error("CLIENT_CLOSED");r.code="CLIENT_CLOSED",e.reject(r)}this.items.length=0,this.notifySize()}notifySize(){this.onSizeChange?.(this.items.length)}};var P=o(t=>new Promise((e,r)=>{t.addEventListener("success",()=>{e(t.result)}),t.addEventListener("error",()=>{r(t.error??new Error("IndexedDB request failed"))})}),"promisifyRequest"),xe=o((t,e,r,s)=>{let i;return()=>i||(i=new Promise((n,a)=>{let u=t.open(e,r);u.addEventListener("upgradeneeded",()=>{s(u.result)}),u.addEventListener("success",()=>{n(u.result)}),u.addEventListener("error",()=>{a(u.error??new Error("IndexedDB open failed"))})}),i)},"createDatabaseOpener"),Me=o((t,e)=>async(r,s)=>{let n=(await t()).transaction(e,r),a=await s(n.objectStore(e));return await new Promise((u,c)=>{n.addEventListener("complete",()=>{u()}),n.addEventListener("error",()=>{c(n.error??new Error("IndexedDB transaction failed"))}),n.addEventListener("abort",()=>{c(n.error??new Error("IndexedDB transaction aborted"))})}),a},"createWithStore");var Gr="lunora-outbox",zr="offline-mutations",or="by_id",Jr=o((t={})=>{let e=t.indexedDB??(typeof indexedDB>"u"?void 0:indexedDB);if(!e)throw new l("INTERNAL","createIndexedDbPersistence: no IndexedDB available \u2014 pass `indexedDB` or use createInMemoryPersistence()");let r=t.databaseName??Gr,s=t.storeName??zr,i=xe(e,r,1,a=>{a.objectStoreNames.contains(s)||a.createObjectStore(s,{autoIncrement:!0}).createIndex(or,"id",{unique:!0})}),n=Me(i,s);return{append:o(async a=>{await n("readwrite",u=>P(u.add(a)))},"append"),clear:o(async()=>{await n("readwrite",a=>P(a.clear()))},"clear"),load:o(async()=>n("readonly",a=>P(a.getAll())),"load"),remove:o(async a=>{await n("readwrite",async u=>{let c=await P(u.index(or).getKey(a));c!==void 0&&await P(u.delete(c))})},"remove")}},"createIndexedDbPersistence"),ar=o((t,e=!0)=>{if(t!==!1){if(t)return t;if(!(!e||typeof indexedDB>"u"))return Jr()}},"resolvePersistenceAdapter");var Fe=o((t,e,r)=>`${t}::${e}::${r??""}`,"queryCacheKey"),Xr=500;var Yr="lunora-query-cache",Zr="query-cache",cr="by_ts",es=1,ts=o((t={})=>{let e=t.indexedDB??(typeof indexedDB>"u"?void 0:indexedDB);if(!e)throw new l("INTERNAL","createIndexedDbQueryCache: no IndexedDB available \u2014 pass `indexedDB` or use createInMemoryQueryCache()");let r=t.databaseName??Yr,s=t.storeName??Zr,i=t.maxEntries??Xr,n=xe(e,r,es,c=>{c.objectStoreNames.contains(s)||c.createObjectStore(s,{keyPath:"key"}).createIndex(cr,"ts",{unique:!1})}),a=Me(n,s),u=o(async c=>{let h=await P(c.count())-i;h<=0||await new Promise((f,m)=>{let p=c.index(cr).openCursor();p.addEventListener("success",()=>{let y=p.result;if(!y||h<=0){f();return}y.delete(),h-=1,y.continue()}),p.addEventListener("error",()=>{m(p.error??new Error("IndexedDB eviction failed"))})})},"evict");return{clear:o(async()=>{await a("readwrite",c=>P(c.clear()))},"clear"),load:o(async()=>a("readonly",c=>P(c.getAll())),"load"),put:o(async(c,d)=>{await a("readwrite",async h=>{await P(h.put({...d,key:c})),await u(h)})},"put"),remove:o(async c=>{await a("readwrite",d=>P(d.delete(c)))},"remove")}},"createIndexedDbQueryCache"),ur=o(t=>{if(t!==!1){if(t)return t;if(!(typeof indexedDB>"u"))return ts()}},"resolveQueryCacheAdapter");var st=o((t={},e=Math.random)=>{let r=t.initialDelayMs??250,s=t.maxDelayMs??3e4,i=t.jitter??!0,n=0;return{next(){let a=Math.min(s,r*2**n);if(n+=1,!i)return a;let u=a/2;return Math.floor(u+e()*(a-u))},reset(){n=0}}},"createReconnect");var it=500,rs=o((t,e)=>{if(t.size<e)return;let r=t.keys().next().value;r!==void 0&&t.delete(r)},"evictOldestEntry"),X=class{static{o(this,"Listeners")}listeners=new Set;add(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}emit(...e){let[r]=e;for(let s of this.listeners)try{s(r)}catch{}}clear(){this.listeners.clear()}},ss="/_lunora/rpc",hr="/_lunora/rpc-batch",is="/_lunora/ws",nt=o(t=>t===void 0||t===""?"":`&bucket=${encodeURIComponent(t)}`,"bucketQuery"),ot=o(t=>{for(let e=t.length-1;e>=0;e-=1)t[e]?.()},"rollbackOptimistic"),ns=o((t,e)=>{for(let r of e)r.op==="delete"?t.delete(r.key):r.value!==void 0&&t.set(r.key,r.value)},"applyRowOpsToView"),os="lunora-ping",as=3e4,cs=1e4,us=250,hs=64,ds="/_lunora/admin/shard-traffic",ls="/_lunora/admin/scheduled",fs="/_lunora/admin/scheduled/status",ms="/_lunora/admin/scheduled/ws",ps="/_lunora/admin/scheduled/cancel",ys="/_lunora/admin/scheduled/dead",bs="/_lunora/admin/scheduled/dead/retry",vs="/_lunora/admin/scheduled/dead/cancel",gs="/_lunora/admin/workflows/instances",Ss="/_lunora/admin/workflows/instance",ws="/_lunora/admin/workflows/status",Ne="/_lunora/admin/storage",Ts="/_lunora/admin/storage/url",Es="/_lunora/admin/storage/buckets",Cs="/_lunora/admin/functions",Is="/_lunora/admin/cron-jobs",As="/_lunora/admin/cron-jobs/run",ks="/_lunora/admin/openapi",_s="/_lunora/admin/openrpc",Rs="/_lunora/admin/global/tables",Os="/_lunora/admin/global/table",Ps="/_lunora/admin/global/facet",Ls="/_lunora/admin/vector/indexes",xs="/_lunora/admin/vector/query",Ms="/_lunora/admin/kv/namespaces",Fs="/_lunora/admin/kv/keys",at="/_lunora/admin/kv/value",Ns="/_lunora/admin/auth/users",dr="/_lunora/admin/auth/sessions",Ds="/_lunora/admin/auth/users/create",Us="/_lunora/admin/auth/users/role",Hs="/_lunora/admin/auth/users/ban",Qs="/_lunora/admin/auth/users/unban",Bs="/_lunora/admin/auth/users/password",qs="/_lunora/admin/auth/users/remove",Ks="/_lunora/admin/auth/users/impersonate",js="/_lunora/admin/auth/sessions/revoke",$s="/_lunora/admin/auth/sessions/revoke-all",Ws="/_lunora/admin/auth/capabilities",Vs="/_lunora/admin/auth/users/update",Gs="/_lunora/admin/auth/accounts",zs="/_lunora/admin/auth/accounts/unlink",Js="/_lunora/admin/auth/passkeys",Xs="/_lunora/admin/auth/passkeys/delete",Ys="/_lunora/admin/auth/two-factor/disable",Zs="/_lunora/admin/auth/organizations",ei="/_lunora/admin/auth/organizations/members",ti="/_lunora/admin/auth/organizations/invitations",ri="/_lunora/admin/auth/organizations/members/remove",si="/_lunora/admin/auth/organizations/invitations/cancel",ii="/_lunora/admin/auth/config",ni="/_lunora/admin/auth/organizations/create",oi="/_lunora/admin/auth/organizations/update",ai="/_lunora/admin/auth/organizations/remove",ci="/_lunora/admin/auth/organizations/members/add",ui="/_lunora/admin/auth/organizations/members/invite",hi="/_lunora/admin/auth/organizations/members/role",di="/_lunora/admin/auth/organizations/teams",li="/_lunora/admin/auth/organizations/teams/create",fi="/_lunora/admin/auth/organizations/teams/update",mi="/_lunora/admin/auth/organizations/teams/remove",pi="/_lunora/admin/auth/organizations/teams/members",yi="/_lunora/admin/auth/organizations/teams/members/add",bi="/_lunora/admin/auth/organizations/teams/members/remove",vi="/_lunora/admin/auth/organizations/roles",gi="/_lunora/admin/auth/organizations/roles/create",Si="/_lunora/admin/auth/organizations/roles/update",wi="/_lunora/admin/auth/organizations/roles/remove",Ti="/api/auth",Ei="/get-session",lr=o(t=>t.startsWith("https://")?`wss://${t.slice(8)}`:t.startsWith("http://")?`ws://${t.slice(7)}`:t,"deriveWsUrl"),z=o((t,e)=>`${t.endsWith("/")?t.slice(0,-1):t}${e}`,"joinUrl"),L=o((t,e)=>{let r=new URLSearchParams;for(let[i,n]of Object.entries(e))n!==void 0&&n!==""&&r.set(i,String(n));let s=r.toString();return s===""?t:`${t}?${s}`},"withQuery"),T=o(t=>t??"","connectionKey"),Ci=o(t=>{let e=t.error,r=typeof e?.code=="string"?e.code:void 0,s=typeof e?.message=="string"?e.message:void 0,i=(typeof t.message=="string"?t.message:void 0)??s??"stream error";return r===void 0?new Error(i):new l(r,i)},"buildStreamError"),fr=o(t=>{let e=t.error,r=typeof e?.code=="string"?e.code:void 0,s=typeof e?.message=="string"?e.message:void 0;return{message:(typeof t.message=="string"?t.message:void 0)??s??"subscription error",...r===void 0?{}:{code:r}}},"buildSubscriptionError"),mr=o((t,e)=>{for(let r of t)try{r(e)}catch{}},"fanSubscriptionError"),Ii=new TextDecoder,Ai=o(t=>{if(typeof t=="string")return t;if(t instanceof ArrayBuffer)return Ii.decode(t)},"decodeServerFrame"),k=o((t,e)=>{if(!t.socket||t.wsState!=="open")return!1;try{return t.socket.send(JSON.stringify(e)),!0}catch{return!1}},"sendOn"),de=o(t=>{let e=new Error(t.message??"request failed");return e.code=t.code,t.data!==void 0&&(e.data=w(t.data)),t.hint!==void 0&&(e.hint=t.hint),t.docsUrl!==void 0&&(e.docsUrl=t.docsUrl),e},"reconstructError"),J=o((t,e)=>{try{return O(t)}catch(r){let s=r instanceof Error?r.message:String(r);throw new TypeError(`LunoraClient: cannot encode ${e} \u2014 ${s}`,r instanceof Error?{cause:r}:void 0)}},"encodeCallArgs"),ki=o((t,e)=>{let r=Array.from({length:e});for(let s of t){if(typeof s.id!="number"||s.id<0||s.id>=e)continue;let i=s.body;r[s.id]=i&&"error"in i&&i.error?{error:de(i.error),ok:!1}:{ok:!0,value:w(i?.result)}}return r.map(s=>s??{error:new Error("batch call returned no result"),ok:!1})},"demuxBatchResults"),_i=new Set(["SHARD_ERROR","SHARD_UNAVAILABLE"]),Ri=Promise.resolve(),ct=class t{static{o(this,"LunoraClient")}static MAX_POKE_BUFFERS=256;static createClientQuery(e,r){return{defaultValue:r,key:e}}url;wsUrl;clientQueryStore;wsToken;authBasePath;fetchImpl;WebSocketImpl;bookmark;reconnectOptions;connectTimeoutMs;heartbeatIntervalMs;offlineQueue;outbox;clientId;readyResolved=!1;readyResolve;readyPromise;clientWatermarks=new Map;outboxMutationCounter=0;onPersistenceError;persistence;persistenceVersion;outboxLeaderRelease;queryCache;hydratedQueryCache=new Map;pendingCacheWrites=new Map;cacheFlushTimer;subscriptions=new D;tabCoordinator;connections=new Map;defaultConnectionContext;connectionContexts=new Map;connectionContextHolders=new Map;authToken=null;authSubject=void 0;queuedIdentities=new Map;closed=!1;authTokenListeners=new X;statusListeners=new X;tokenExpiredListeners=new X;mutationSettledListeners=new X;pendingChangeListeners=new X;whisperHandlers=new Map;lastStatus="idle";nextSubId=0;nextStreamId=0;streams=new Map;shapeSubscriptions=new Map;pokeBuffers=new Map;nextShapeId=0;constructor(e){this.url=e.url,this.wsUrl=e.wsUrl??z(lr(e.url),is),this.wsToken=e.wsToken;let r=e.authBasePath??Ti;this.authBasePath=r.endsWith("/")?r.slice(0,-1):r,this.fetchImpl=e.fetch??(typeof fetch=="function"?fetch.bind(globalThis):void 0),this.WebSocketImpl=e.WebSocket??(typeof WebSocket=="function"?WebSocket:void 0),this.bookmark=e.bookmarkStorage??Vt(),this.reconnectOptions=e.reconnect,this.heartbeatIntervalMs=e.heartbeatIntervalMs??as,this.connectTimeoutMs=e.connectTimeoutMs??cs,this.defaultConnectionContext=e.connectionContext,this.persistence=ar(e.persistence,e.outbox===void 0),this.persistenceVersion=e.persistenceVersion,this.queryCache=ur(e.queryCache),this.onPersistenceError=e.offlineQueue?.onPersistenceError,this.clientQueryStore=new ke,e.crossTabSync?(this.tabCoordinator=new _e({onBecomeLeader:o(()=>{for(let s of this.subscriptions.all())this.ensureSocket(s.shardKey),this.sendSubscribeIfOpen(s)},"onBecomeLeader"),onStopBeingLeader:o(()=>{for(let[s,i]of this.connections)i.socket?.close(),this.connections.delete(s)},"onStopBeingLeader"),onSubscriptionData:o((s,i)=>{let n=this.subscriptions.get(s);if(n){n.serverBase=i;let a=n.optimisticLayers.length===0?i:he(i,n.optimisticLayers);n.lastValue=a;for(let u of n.callbacks)try{u(a)}catch{}}},"onSubscriptionData"),onSubscriptionError:o((s,i)=>{let n=this.subscriptions.get(s);if(n)for(let a of n.errorCallbacks)try{a(i)}catch{}},"onSubscriptionError")}),this.tabCoordinator.start()):this.tabCoordinator=void 0,e.hydrateOnStart&&this.queryCache?this.readyPromise=new Promise(s=>{this.readyResolve=s}):(this.readyResolved=!0,this.readyPromise=Ri),this.offlineQueue=new Pe(e.offlineQueue,{onEvict:o((s,i)=>{this.emitItemSettled(s,"rejected",i)},"onEvict"),onSizeChange:o(s=>{this.pendingChangeListeners.emit(s)},"onSizeChange"),persistence:this.persistence,version:e.persistenceVersion}),this.outbox=e.outbox,this.clientId=e.clientId??`client-${Le()}`,this.persistence&&queueMicrotask(()=>{this.hydrateAsOutboxLeader()}),this.queryCache&&queueMicrotask(()=>{o(async()=>{try{await this.hydrateQueryCache()}catch{}finally{this.readyResolved=!0,this.readyResolve?.()}},"hydration")().catch(()=>{})})}setAuthToken(e,r){let s=this.authToken!==e,i=this.identityFingerprint();this.authToken=e,r!==void 0&&(this.authSubject=r);let n=this.identityFingerprint();n!==i&&(s?this.rejectQueuedForIdentityChange():this.restampQueuedIdentity(i,n)),s&&this.authTokenListeners.emit(e)}getAuthToken(){return this.authToken}currentIdentity(){return this.identityFingerprint()}clientIdentifier(){return this.clientId}confirmedMutationWatermark(e){return this.clientWatermarks.get(e??"")??0}async callMutator(e,r,s){let i=s?.clientSeq;if(i!==void 0&&(!Number.isInteger(i)||i<=0))throw new l("INTERNAL",`callMutator: clientSeq must be a positive integer, got ${String(i)}`);let n=s?.shardKey??"",a,u=await this.rpc(e,r,s?.shardKey,{captureBookmark:!0,clientId:this.clientId,clientSeq:i,onMutationAck:o(d=>{a=d},"onMutationAck")});return a!==void 0&&a>(this.clientWatermarks.get(n)??0)&&this.clientWatermarks.set(n,a),{applied:a===void 0||a===i,result:u}}onAuthTokenChange(e){return this.authTokenListeners.add(e)}async getCurrentUser(){if(this.closed||!this.fetchImpl)return null;let e={};this.authToken&&(e.authorization=`Bearer ${this.authToken}`);try{let r=await this.fetchImpl(z(this.url,`${this.authBasePath}${Ei}`),{credentials:"include",headers:e,method:"GET"});return r.ok?(await r.json())?.user??null:null}catch{return null}}setWsToken(e){if(this.wsToken!==e){this.wsToken=e;for(let r of this.connections.values())if(r.socket)try{r.socket.close()}catch{}}}setConnectionContext(e,r={}){let s=T(r.shardKey);e===void 0?this.connectionContexts.delete(s):this.connectionContexts.set(s,e),this.refreshConnectionContext(s)}acquireConnectionContext(e,r={}){let s=T(r.shardKey),i={context:e},n=this.connectionContextHolders.get(s);n?n.push(i):this.connectionContextHolders.set(s,[i]),this.refreshConnectionContext(s);let a=!1;return()=>{if(a)return;a=!0;let u=this.connectionContextHolders.get(s);if(!u)return;let c=u.indexOf(i);c!==-1&&u.splice(c,1),u.length===0&&this.connectionContextHolders.delete(s),this.refreshConnectionContext(s)}}whisperSubscribe(e,r,s={}){let i=T(s.shardKey),n=this.whisperHandlers.get(i);n||(n=new Map,this.whisperHandlers.set(i,n));let a=n.get(e),u=a===void 0;if(a||(a=new Set,n.set(e,a)),a.add(r),this.ensureSocket(s.shardKey),u){let c=this.getConnection(s.shardKey);c&&k(c,{topic:e,type:"whisper_subscribe"})}return()=>{let c=this.whisperHandlers.get(i),d=c?.get(e);if(!d?.delete(r)||d.size>0)return;c?.delete(e),c?.size===0&&this.whisperHandlers.delete(i);let h=this.getConnection(s.shardKey);h&&k(h,{topic:e,type:"whisper_unsubscribe"})}}whisper(e,r,s={}){this.ensureSocket(s.shardKey);let i=this.getConnection(s.shardKey);i&&k(i,{data:J(r??null,`whisper data for topic '${e}'`),topic:e,type:"whisper"})}onTokenExpired(e){return this.tokenExpiredListeners.add(e)}connectionStatus(){return this.computeStatus()}onConnectionStatus(e){let r=this.statusListeners.add(e);return e(this.computeStatus()),r}pendingCount(){return this.offlineQueue.size}onPendingChange(e){let r=this.pendingChangeListeners.add(e);return e(this.offlineQueue.size),r}onMutationSettled(e){return this.mutationSettledListeners.add(e)}getWebSocketImpl(){return this.WebSocketImpl}getClientQuery(e){return this.clientQueryStore.get(e)}setClientQuery(e,r){this.clientQueryStore.set(e,r)}subscribeClientQuery(e,r){return this.clientQueryStore.subscribe(e,r)}resetClientQuery(e){this.clientQueryStore.reset(e)}snapshotPrecondition(e,r,s){let i=this.peekActiveQueryValue(e.__lunoraRef,r,s),n=i===void 0?void 0:G(i);return()=>{let a=this.peekActiveQueryValue(e.__lunoraRef,r,s);return n===void 0&&a===void 0?!0:n===void 0||a===void 0?!1:G(a)===n}}whenReady(){return this.readyPromise}get isReady(){return this.readyResolved}peekHydratedQuery(e,r,s){if(!this.readyResolved)return;let i=G(r),n=Fe(e,i,s),a=this.hydratedQueryCache.get(n);if(a!==void 0)return a.identity===this.identityFingerprint()?a.value:void 0}peekActiveQueryValue(e,r,s){let i=D.key(e,r,s);return this.subscriptions.get(i)?.lastValue}async query(e,r,s={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return await this.rpc(e.__lunoraRef,r,s.shardKey,{attachBookmark:!0})}async batch(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");if(!this.fetchImpl)throw new l("INTERNAL","LunoraClient: no `fetch` implementation available");if(e.length===0)return[];let r=await this.fetchImpl(z(this.url,hr),{body:JSON.stringify({calls:e.map((n,a)=>({args:J(n.args??{},`args for batch call '${n.fn.__lunoraRef}'`),functionPath:n.fn.__lunoraRef,id:a,shardKey:n.shardKey}))}),headers:this.rpcRequestHeaders({attachBookmark:!0}),method:"POST"}),s=r.headers.get("x-d1-bookmark");s&&this.bookmark.set(s);let i;try{i=await r.json()}catch{throw new l("INTERNAL",`LunoraClient: batch response was not JSON (status ${r.status.toString()})`)}if(!r.ok||i.error&&!i.results)throw i.error?de(i.error):new l("INTERNAL",`LunoraClient: batch request failed (status ${r.status.toString()})`);return ki(i.results??[],e.length)}async mutation(e,r,s={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let i=r,n=s.mutationId??Le(),{confirms:a,rollbacks:u}=this.applyOptimisticUpdates(e.__lunoraRef,i,s.shardKey,s.optimistic);s.optimisticUpdate&&this.applyOptimisticUpdate(s.optimisticUpdate,r,s.shardKey,u,a);let c=this.getConnection(s.shardKey),d=c?.wsState??"idle",h=c?.socket!==void 0,f=c?.wasEverConnected??!1,{queueBeforeFirstConnect:m}=this.offlineQueue,p=f||m,y=this.WebSocketImpl!==void 0&&p;if(d!=="open"&&!h&&y||d==="connecting"&&p)return this.enqueueOfflineMutation(e,i,s.shardKey,n,u,a,s.precondition);try{let g,E=await this.rpc(e.__lunoraRef,i,s.shardKey,{captureBookmark:!0,mutationId:n,onCommitCursor:o(I=>{g=I},"onCommitCursor")});for(let I of a)I(g);return E}catch(g){throw ot(u),g}}async action(e,r,s={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return await this.rpc(e.__lunoraRef,r,s.shardKey)}async shardTraffic(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=await this.adminFetch(ds,"POST",{table:e});return{failed:r.failed??0,ok:r.ok??0,shards:r.shards??[]}}async listScheduledJobs(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return(await this.adminFetch(ls,"GET")).records??[]}async schedulerStatus(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let e=await this.adminFetch(fs,"GET");return{backlog:e.backlog??0,inFlight:e.inFlight??0,pools:e.pools??[]}}async cancelScheduledJob(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return{cancelled:(await this.adminFetch(ps,"POST",{id:e})).cancelled===!0}}async listDeadJobs(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return(await this.adminFetch(ys,"GET")).records??[]}async retryDeadJob(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return{retried:(await this.adminFetch(bs,"POST",{id:e})).retried===!0}}async removeDeadJob(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return{removed:(await this.adminFetch(vs,"POST",{id:e})).removed===!0}}async listWorkflowInstances(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=new URLSearchParams({name:e.name});e.status!==void 0&&r.set("status",e.status),e.page!==void 0&&r.set("page",String(e.page)),e.perPage!==void 0&&r.set("perPage",String(e.perPage));let s=await this.adminFetch(`${gs}?${r.toString()}`,"GET");return{configured:s.configured,instances:s.instances??[],page:s.page??1,perPage:s.perPage??e.perPage??0,totalCount:s.totalCount}}async getWorkflowInstance(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=new URLSearchParams({id:e.id,name:e.name}),s=await this.adminFetch(`${Ss}?${r.toString()}`,"GET");return{createdOn:s.createdOn,endedOn:s.endedOn,error:s.error,id:s.id??e.id,output:s.output,params:s.params,startedOn:s.startedOn,status:s.status??"unknown",steps:s.steps??[]}}async setWorkflowInstanceStatus(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return{status:(await this.adminFetch(ws,"POST",{action:e.action,id:e.id,name:e.name})).status??"unknown"}}subscribeScheduledJobs(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");if(this.WebSocketImpl===void 0)return()=>{};let r=z(lr(this.url),ms),s=st(this.reconnectOptions),i,n,a=!1,u=o(h=>{if(a||this.WebSocketImpl===void 0)return;let f=h===void 0?r:`${r}?token=${encodeURIComponent(h)}`;i=new this.WebSocketImpl(f),i.addEventListener("open",()=>{s.reset()}),i.addEventListener("message",m=>{try{let p=JSON.parse(typeof m.data=="string"?m.data:"");p.type==="jobs"&&Array.isArray(p.records)&&e(p.records)}catch{}}),i.addEventListener("close",()=>{i=void 0,a||(n=setTimeout(d,s.next()))}),i.addEventListener("error",()=>{})},"openWith"),c=o(async h=>{let f;try{f=await h()}catch{a||(n=setTimeout(d,s.next()));return}u(f)},"connectWithProvider"),d=o(()=>{if(a||this.WebSocketImpl===void 0)return;let{wsToken:h}=this;if(typeof h=="function"){c(h).catch(()=>{});return}u(h)},"connect");return d(),()=>{a=!0,n!==void 0&&clearTimeout(n),i?.close()}}async listFunctions(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return(await this.adminFetch(Cs,"GET")).functions??[]}async getCronJobs(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return(await this.adminFetch(Is,"GET")).jobs??[]}async runCronJob(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=await this.adminFetch(As,"POST",{name:e});return{name:r.name??e,ran:r.ran===!0}}async fetchOpenApi(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return await this.adminFetch(ks,"GET")}async fetchOpenRpc(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return await this.adminFetch(_s,"GET")}async listStorageObjects(e={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=new URLSearchParams;e.prefix!==void 0&&e.prefix!==""&&r.set("prefix",e.prefix),e.cursor!==void 0&&e.cursor!==""&&r.set("cursor",e.cursor),e.limit!==void 0&&r.set("limit",String(e.limit)),e.bucket!==void 0&&e.bucket!==""&&r.set("bucket",e.bucket);let s=r.toString(),i=s===""?Ne:`${Ne}?${s}`,n=await this.adminFetch(i,"GET");return{cursor:n.cursor,objects:n.objects??[]}}async deleteStorageObject(e,r){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let s=`${Ne}?key=${encodeURIComponent(e)}${nt(r?.bucket)}`,i=await this.adminFetch(s,"DELETE");return{deleted:i.deleted??!0,key:i.key??e}}async listStorageBuckets(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return(await this.adminFetch(Es,"GET")).buckets??[]}async uploadStorageObject(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=`${Ne}?key=${encodeURIComponent(e.key)}${nt(e.bucket)}`,s=await this.adminFetch(r,"PUT",e.body,e.contentType);return{etag:s.etag,key:s.key??e.key}}async signedStorageUrl(e,r){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let s=r?.expiresInSeconds,i=s===void 0?"":`&expiresIn=${encodeURIComponent(s.toString())}`,n=`${Ts}?key=${encodeURIComponent(e)}${i}${nt(r?.bucket)}`,a=await this.adminFetch(n,"GET");if(typeof a.url!="string")throw new TypeError("LunoraClient: storage URL endpoint returned no `url`");return a.url}async listGlobalTables(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return await this.adminFetch(Rs,"GET")}async readGlobalTablePage(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=new URLSearchParams({table:e.table});return e.limit!==void 0&&r.set("limit",String(e.limit)),e.offset!==void 0&&r.set("offset",String(e.offset)),e.filters!==void 0&&e.filters.length>0&&r.set("filters",JSON.stringify(e.filters)),await this.adminFetch(`${Os}?${r.toString()}`,"GET")}async facetGlobalColumn(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=new URLSearchParams({column:e.column,table:e.table});return e.limit!==void 0&&r.set("limit",String(e.limit)),e.filters!==void 0&&e.filters.length>0&&r.set("filters",JSON.stringify(e.filters)),await this.adminFetch(`${Ps}?${r.toString()}`,"GET")}async listVectorIndexes(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return(await this.adminFetch(Ls,"GET")).indexes??[]}async queryVectorIndex(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return(await this.adminFetch(xs,"POST",e)).matches??[]}async listKvNamespaces(){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");return(await this.adminFetch(Ms,"GET")).namespaces??[]}async listKvKeys(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=L(Fs,{cursor:e.cursor,limit:e.limit,namespace:e.namespace,prefix:e.prefix});return await this.adminFetch(r,"GET")}async getKvValue(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=L(at,{key:e.key,namespace:e.namespace});return await this.adminFetch(r,"GET")}async putKvValue(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");await this.adminFetch(at,"PUT",e)}async deleteKvKey(e){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=L(at,{key:e.key,namespace:e.namespace});await this.adminFetch(r,"DELETE")}async listAuthUsers(e={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=L(Ns,{filterField:e.filterField,filterValue:e.filterValue,limit:e.limit,offset:e.offset,search:e.search,searchField:e.searchField,sortBy:e.sortBy,sortDirection:e.sortDirection});return await this.adminFetch(r,"GET")}async createAuthUser(e){return await this.adminFetch(Ds,"POST",e)}async setAuthUserRole(e){return await this.adminFetch(Us,"POST",e)}async banAuthUser(e){return await this.adminFetch(Hs,"POST",e)}async unbanAuthUser(e){return await this.adminFetch(Qs,"POST",e)}async setAuthUserPassword(e){await this.adminFetch(Bs,"POST",e)}async removeAuthUser(e){await this.adminFetch(qs,"POST",e)}async impersonateAuthUser(e){return await this.adminFetch(Ks,"POST",e)}async revokeAuthSession(e){await this.adminFetch(js,"POST",e)}async revokeAuthUserSessions(e){await this.adminFetch($s,"POST",e)}async getAuthCapabilities(){return await this.adminFetch(Ws,"GET")}async updateAuthUser(e){return await this.adminFetch(Vs,"POST",e)}async listAuthAccounts(e){return await this.adminFetch(L(Gs,{userId:e.userId}),"GET")}async unlinkAuthAccount(e){await this.adminFetch(zs,"POST",e)}async listAuthPasskeys(e){return await this.adminFetch(L(Js,{userId:e.userId}),"GET")}async deleteAuthPasskey(e){await this.adminFetch(Xs,"POST",e)}async disableAuthTwoFactor(e){await this.adminFetch(Ys,"POST",e)}async listAuthOrganizations(e={}){return await this.adminFetch(L(Zs,{limit:e.limit,offset:e.offset}),"GET")}async listAuthOrgMembers(e){let r=L(ei,{limit:e.limit,offset:e.offset,organizationId:e.organizationId});return await this.adminFetch(r,"GET")}async listAuthOrgInvitations(e){let r=L(ti,{limit:e.limit,offset:e.offset,organizationId:e.organizationId});return await this.adminFetch(r,"GET")}async removeAuthOrgMember(e){await this.adminFetch(ri,"POST",e)}async cancelAuthOrgInvitation(e){await this.adminFetch(si,"POST",e)}async getAuthConfig(){return await this.adminFetch(ii,"GET")}async createAuthOrganization(e){return await this.adminFetch(ni,"POST",e)}async updateAuthOrganization(e){return await this.adminFetch(oi,"POST",e)}async deleteAuthOrganization(e){await this.adminFetch(ai,"POST",e)}async addAuthOrgMember(e){return await this.adminFetch(ci,"POST",e)}async inviteAuthOrgMember(e){return await this.adminFetch(ui,"POST",e)}async setAuthOrgMemberRole(e){return await this.adminFetch(hi,"POST",e)}async listAuthOrgTeams(e){let r=L(di,{limit:e.limit,offset:e.offset,organizationId:e.organizationId});return await this.adminFetch(r,"GET")}async createAuthOrgTeam(e){return await this.adminFetch(li,"POST",e)}async updateAuthOrgTeam(e){return await this.adminFetch(fi,"POST",e)}async removeAuthOrgTeam(e){await this.adminFetch(mi,"POST",e)}async listAuthOrgTeamMembers(e){let r=L(pi,{limit:e.limit,offset:e.offset,teamId:e.teamId});return await this.adminFetch(r,"GET")}async addAuthOrgTeamMember(e){return await this.adminFetch(yi,"POST",e)}async removeAuthOrgTeamMember(e){await this.adminFetch(bi,"POST",e)}async listAuthOrgRoles(e){let r=L(vi,{limit:e.limit,offset:e.offset,organizationId:e.organizationId});return await this.adminFetch(r,"GET")}async createAuthOrgRole(e){return await this.adminFetch(gi,"POST",e)}async updateAuthOrgRole(e){return await this.adminFetch(Si,"POST",e)}async deleteAuthOrgRole(e){await this.adminFetch(wi,"POST",e)}async listAuthSessions(e={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let r=new URLSearchParams;e.userId!==void 0&&e.userId!==""&&r.set("userId",e.userId),e.limit!==void 0&&r.set("limit",String(e.limit)),e.offset!==void 0&&r.set("offset",String(e.offset));let s=r.toString();return await this.adminFetch(s===""?dr:`${dr}?${s}`,"GET")}subscribe(e,r,s,i={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");let n=r??{},a=D.key(e.__lunoraRef,n,i.shardKey),u=this.subscriptions.get(a),c=s,d=i.onError;if(!u){this.nextSubId+=1;let f=`sub_${this.nextSubId.toString()}`,m=G(n),p=this.takeHydratedCache(e.__lunoraRef,m,i.shardKey);u={acked:!1,args:n,argsKey:m,callbacks:new Set,checkpointCallbacks:new Set,errorCallbacks:new Set,fn:e,id:f,lastValue:p?.value,optimisticLayers:[],serverBase:p?.value,serverCursor:p?.serverCursor,shardKey:i.shardKey,...p?.serverEpoch===void 0?{}:{serverEpoch:p.serverEpoch}},this.subscriptions.add(u)}if(u.callbacks.add(c),d&&u.errorCallbacks.add(d),i.onCheckpoint&&u.checkpointCallbacks.add(i.onCheckpoint),u.lastValue!==void 0)try{c(u.lastValue)}catch{}this.ensureSocket(i.shardKey),this.sendSubscribeIfOpen(u);let h=u;return()=>{if(h.callbacks.delete(c),d&&h.errorCallbacks.delete(d),i.onCheckpoint&&h.checkpointCallbacks.delete(i.onCheckpoint),h.callbacks.size===0){let f=this.getConnection(h.shardKey);!(f&&k(f,{id:h.id,type:"unsubscribe"}))&&f&&f.pendingUnsubscribes.push({id:h.id,type:"unsubscribe"}),this.subscriptions.remove(h)}}}subscribeShape(e,r,s={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");this.nextShapeId+=1;let i=`shape_${this.nextShapeId.toString()}`,n={args:e.args,callbacks:new Set([r]),errorCallbacks:s.onError?new Set([s.onError]):new Set,id:i,name:e.name,onCheckpoint:s.onCheckpoint,rows:new Map,shardKey:s.shardKey,wireArgs:e.args===void 0?void 0:J(e.args,`shape args for '${e.name}'`)};return this.shapeSubscriptions.set(i,n),this.ensureSocket(s.shardKey),this.sendShapeSubscribeIfOpen(n),()=>{this.shapeSubscriptions.delete(i);let a=this.getConnection(n.shardKey);!(a&&k(a,{id:i,type:"shape_unsubscribe"}))&&a&&a.pendingUnsubscribes.push({id:i,type:"shape_unsubscribe"})}}stream(e,r,s={}){if(this.closed)throw new l("INTERNAL","LunoraClient is closed");if(this.WebSocketImpl===void 0)throw new l("INTERNAL","LunoraClient: streams require a WebSocket implementation");this.nextStreamId+=1;let i=`stream_${this.nextStreamId.toString()}`,{shardKey:n}=s,a=r??{},{handle:u,iterable:c}=Re({maxBuffer:s.maxBuffer,onCancel:o(()=>{let m=this.getConnection(n);m&&k(m,{id:i,type:"unsubscribe"}),this.streams.delete(i)},"onCancel")});this.streams.set(i,{handle:u,shardKey:n}),this.ensureSocket(n);let d=this.getConnection(n),h={id:i,query:{args:J(a,`stream args for '${e.__lunoraRef}'`),functionPath:e.__lunoraRef,shardKey:n},type:"stream"};if(!(d?.wsState==="open"&&k(d,h))&&d){for(d.pendingStreams=d.pendingStreams??[];d.pendingStreams.length>=hs;){let p=d.pendingStreams.shift()?.id,y=p?this.streams.get(p):void 0;y&&(y.handle.fail(new l("STREAM_QUEUE_OVERFLOW","stream-start frame evicted while socket was unreachable")),this.streams.delete(p))}d.pendingStreams.push(h)}return c}httpStream(e,r,s={}){if(this.closed)throw new l("CLIENT_CLOSED","LunoraClient is closed");if(!this.fetchImpl)throw new l("INTERNAL","LunoraClient: no `fetch` implementation available");let i={...this.authToken?{authorization:`Bearer ${this.authToken}`}:{},...s.headers};return Zt(e,r,{baseUrl:this.url,fetch:this.fetchImpl,headers:i,maxBuffer:s.maxBuffer,signal:s.signal})}close(){this.closed=!0,this.outboxLeaderRelease?.(),this.outboxLeaderRelease=void 0;for(let e of this.streams.values())e.handle.fail(new l("CLIENT_CLOSED","LunoraClient closed"));this.streams.clear();for(let e of this.connections.values()){if(e.reconnectTimer!==void 0&&(clearTimeout(e.reconnectTimer),e.reconnectTimer=void 0),e.connectTimer!==void 0&&(clearTimeout(e.connectTimer),e.connectTimer=void 0),this.stopHeartbeat(e),e.socket){try{e.socket.close()}catch{}e.socket=void 0}e.wsState="closed"}this.offlineQueue.clear(),this.queuedIdentities.clear(),this.cacheFlushTimer!==void 0&&(clearTimeout(this.cacheFlushTimer),this.cacheFlushTimer=void 0),this.pendingCacheWrites.size>0&&this.flushQueryCacheWrites().catch(()=>{}),this.authTokenListeners.clear(),this.statusListeners.clear(),this.tokenExpiredListeners.clear(),this.mutationSettledListeners.clear(),this.pendingChangeListeners.clear(),this.whisperHandlers.clear(),this.shapeSubscriptions.clear(),this.pokeBuffers.clear(),this.tabCoordinator?.stop(),this.tabCoordinator=void 0}async enqueueOfflineMutation(e,r,s,i,n,a,u){let c=this.identityFingerprint();if(this.outbox){this.outboxMutationCounter+=1;let d=this.outboxMutationCounter;try{await this.outbox.enqueue({args:r,clientId:this.clientId,functionPath:e.__lunoraRef,idempotencyKey:`${this.clientId}:${String(d)}`,identity:c,mutationId:d,shardKey:s})}catch(h){throw ot(n),h instanceof Error?h:new Error(String(h))}for(let h of a)h(void 0);return}return new Promise((d,h)=>{let f={args:r,functionPath:e.__lunoraRef,liveAwaiter:!0,id:i,identity:c,precondition:u,onCommit:o(m=>{for(let p of a)p(m)},"onCommit"),reject:o(m=>{this.queuedIdentities.delete(i),ot(n),h(m instanceof Error?m:new Error(String(m)))},"reject"),resolve:d,shardKey:s};this.offlineQueue.enqueue(f),f.id!==void 0&&this.queuedIdentities.set(f.id,c)})}async hydratePersistedQueue(){try{let e=await this.offlineQueue.hydrate();for(let r of e)this.ensureSocket(r)}catch{}}hydrateAsOutboxLeader(){let e=o(()=>{this.hydratePersistedQueue().catch(()=>{})},"hydrate"),r=globalThis.navigator?.locks;if(!r){e();return}r.request(`lunora:outbox-leader:${this.url}`,()=>(this.closed||e(),new Promise(s=>{if(this.closed){s();return}this.outboxLeaderRelease=s}))).catch(e)}async hydrateQueryCache(){if(this.queryCache)try{let e=await this.queryCache.load();for(let{key:r,...s}of e){if(rt(this.persistenceVersion,s.version)){this.queryCache.remove(r).catch(()=>{});continue}this.hydratedQueryCache.set(r,s)}}catch{}}takeHydratedCache(e,r,s){let i=Fe(e,r,s),n=this.hydratedQueryCache.get(i);if(n!==void 0)return this.hydratedQueryCache.delete(i),n.identity===this.identityFingerprint()?n:void 0}persistQueryValue(e){let r=e.serverBase;if(!this.queryCache||r===void 0)return;let s=Fe(e.fn.__lunoraRef,e.argsKey,e.shardKey);this.pendingCacheWrites.set(s,{identity:this.identityFingerprint(),serverCursor:e.serverCursor,ts:Date.now(),value:r,...e.serverEpoch===void 0?{}:{serverEpoch:e.serverEpoch},...this.persistenceVersion===void 0?{}:{version:this.persistenceVersion}}),this.cacheFlushTimer??=setTimeout(()=>{this.flushQueryCacheWrites().catch(()=>{})},us)}async flushQueryCacheWrites(){this.cacheFlushTimer=void 0;let{queryCache:e}=this;if(!e){this.pendingCacheWrites.clear();return}let r=[...this.pendingCacheWrites.entries()];this.pendingCacheWrites.clear(),await Promise.allSettled(r.map(([s,i])=>e.put(s,i)))}computeStatus(){let e=[...this.connections.values()];return e.length===0?"idle":e.some(r=>r.wsState==="open")?"connected":e.some(r=>r.wsState==="connecting")?"connecting":"offline"}emitConnectionStatus(){let e=this.computeStatus();e!==this.lastStatus&&(this.lastStatus=e,this.statusListeners.emit(e))}emitItemSettled(e,r,s){this.mutationSettledListeners.emit({args:e.args,code:s===void 0?void 0:s.code,error:s,functionPath:e.functionPath,hadAwaiter:e.liveAwaiter??!1,id:e.id??"",shardKey:e.shardKey,status:r})}applyOptimisticUpdates(e,r,s,i){let n=[],a=[];if(!i)return{confirms:n,rollbacks:a};let u=D.key(e,r,s),c=this.subscriptions.get(u);if(c){let d=et(c,i);d&&(n.push(d.confirm),a.push(d.rollback))}return{confirms:n,rollbacks:a}}applyOptimisticUpdate(e,r,s,i,n){let{confirms:a,rollbacks:u,store:c}=ir(this.subscriptions,s);try{e(c,r)}catch{for(let d=u.length-1;d>=0;d-=1)u[d]?.();return}i.push(...u),n.push(...a)}getConnection(e){return this.connections.get(T(e))}getOrCreateConnection(e){let r=T(e),s=this.connections.get(r);return s||(s={connectTimer:void 0,heartbeatTimer:void 0,pendingUnsubscribes:[],reconnect:st(this.reconnectOptions),reconnectTimer:void 0,shardKey:e,socket:void 0,wasEverConnected:!1,wsState:"idle"},this.connections.set(r,s)),s}wsUrlFor(e,r){let s=[];if(e!==void 0&&s.push(`shard=${encodeURIComponent(e)}`),r!==void 0&&s.push(`token=${encodeURIComponent(r)}`),s.length===0)return this.wsUrl;let i=this.wsUrl.includes("?")?"&":"?";return`${this.wsUrl}${i}${s.join("&")}`}rpcRequestHeaders(e){let r={"content-type":"application/json"};if(this.authToken&&(r.authorization=`Bearer ${this.authToken}`),e.mutationId&&(r["x-lunora-mutation-id"]=e.mutationId),e.clientId!==void 0&&(r["x-lunora-client-id"]=e.clientId),e.clientSeq!==void 0&&(r["x-lunora-client-seq"]=e.clientSeq.toString()),e.attachBookmark){let s=this.bookmark.get();s&&(r["x-d1-bookmark"]=s)}return r}async rpc(e,r,s,i={}){if(!this.fetchImpl)throw new l("INTERNAL","LunoraClient: no `fetch` implementation available");let n=this.rpcRequestHeaders(i),a=await this.fetchImpl(z(this.url,ss),{body:JSON.stringify({args:J(r,`args for '${e}'`),functionPath:e,shardKey:s}),headers:n,method:"POST"});if(i.captureBookmark){let c=a.headers.get("x-d1-bookmark");c&&this.bookmark.set(c)}let u;try{u=await a.json()}catch{let c=a.statusText?` ${a.statusText}`:"";throw new l("INTERNAL",`LunoraClient: response was not JSON (status ${a.status.toString()}${c})`)}if("error"in u)throw de(u.error);if(!a.ok){let c=a.statusText?` ${a.statusText}`:"";throw new l("INTERNAL",`LunoraClient: request failed (status ${a.status.toString()}${c})`)}return i.onMutationAck?.(u.lastMutationId),i.onCommitCursor?.(u.commitCursor),w(u.result)}async adminFetch(e,r,s,i){if(!this.fetchImpl)throw new l("INTERNAL","LunoraClient: no `fetch` implementation available");let n={};this.authToken&&(n.authorization=`Bearer ${this.authToken}`);let a=s instanceof ArrayBuffer||s instanceof Blob,u;s===void 0?u=void 0:a?(u=s,i!==void 0&&(n["content-type"]=i)):(u=JSON.stringify(s),n["content-type"]="application/json");let c=await this.fetchImpl(z(this.url,e),{body:u,headers:n,method:r}),d;try{d=await c.json()}catch{let h=c.statusText?` ${c.statusText}`:"";throw new l("INTERNAL",`LunoraClient: response was not JSON (status ${c.status.toString()}${h})`)}if(typeof d=="object"&&d!==null&&"error"in d){let h=d.error,f=new Error(h.message??"admin request failed");throw f.code=h.code,f}if(!c.ok){let h=c.statusText?` ${c.statusText}`:"";throw new l("INTERNAL",`LunoraClient: admin request failed (status ${c.status.toString()}${h})`)}return d}effectiveConnectionContext(e){let r=this.connectionContextHolders.get(e);return r&&r.length>0?r[r.length-1]?.context:this.connectionContexts.get(e)??this.defaultConnectionContext}refreshConnectionContext(e){let r=this.connections.get(e);r?.wsState==="open"&&this.sendConnectEnvelope(r)}sendConnectEnvelope(e){let r=this.effectiveConnectionContext(T(e.shardKey));k(e,{clientId:this.clientId,id:"connect",type:"connect",...r===void 0?{}:{context:r}})}resendShapeSubscriptions(e){for(let r of this.shapeSubscriptions.values())T(r.shardKey)===T(e)&&this.sendShapeSubscribeIfOpen(r)}ensureSocket(e){if(this.closed||this.WebSocketImpl===void 0||this.tabCoordinator&&!this.tabCoordinator.isLeader())return;let r=this.getOrCreateConnection(e);if(!(r.wsState==="open"||r.wsState==="connecting")){if(r.wsState="connecting",this.emitConnectionStatus(),typeof this.wsToken=="function"){this.openSocketWithProvidedToken(r,e,this.wsToken).catch(()=>{});return}this.openSocket(r,e,this.wsToken)}}async openSocketWithProvidedToken(e,r,s){let i;try{i=await s()}catch{this.handleDisconnect(e);return}this.closed||this.WebSocketImpl===void 0||e.wsState!=="connecting"||e.socket!==void 0||this.openSocket(e,r,i)}openSocket(e,r,s){if(this.WebSocketImpl===void 0)return;let i=new this.WebSocketImpl(this.wsUrlFor(r,s));e.socket=i,this.connectTimeoutMs>0&&(e.connectTimer=setTimeout(()=>{if(e.connectTimer=void 0,!(e.socket!==i||e.wsState!=="connecting")){try{i.close()}catch{}this.handleDisconnect(e)}},this.connectTimeoutMs)),i.addEventListener("open",()=>{if(e.socket!==i)return;e.connectTimer!==void 0&&(clearTimeout(e.connectTimer),e.connectTimer=void 0),e.wsState="open",e.wasEverConnected=!0,e.reconnect.reset(),this.emitConnectionStatus(),this.sendConnectEnvelope(e),this.markShardPendingAck(r);for(let a of this.subscriptions.all())T(a.shardKey)===T(r)&&this.sendSubscribeIfOpen(a);if(this.resendShapeSubscriptions(r),e.pendingUnsubscribes.length>0){let a=e.pendingUnsubscribes;e.pendingUnsubscribes=[];for(let{id:u,type:c}of a)k(e,{id:u,type:c})}if(e.pendingStreams&&e.pendingStreams.length>0){let a=e.pendingStreams;e.pendingStreams=[];for(let u of a)k(e,u)}let n=this.whisperHandlers.get(T(r));if(n)for(let a of n.keys())k(e,{topic:a,type:"whisper_subscribe"});this.flushOfflineQueue(r).catch(()=>{}),this.startHeartbeat(e)}),i.addEventListener("message",n=>{this.handleServerMessage(n.data,r)}),i.addEventListener("close",n=>{e.socket===i&&(n?.code===4001&&this.notifyTokenExpired(),this.handleDisconnect(e))}),i.addEventListener("error",()=>{e.socket===i&&(e.wsState==="connecting"||e.wsState==="open")&&this.handleDisconnect(e)})}handleDisconnect(e){if(this.closed||e.wsState==="idle"||e.wsState==="closed")return;this.stopHeartbeat(e),e.connectTimer!==void 0&&(clearTimeout(e.connectTimer),e.connectTimer=void 0),e.socket=void 0,e.wsState="idle",this.emitConnectionStatus(),this.markShardPendingAck(e.shardKey);let r=new Set((e.pendingStreams??[]).map(i=>i.id));for(let[i,n]of this.streams)T(n.shardKey)===T(e.shardKey)&&!r.has(i)&&(n.handle.fail(new l("STREAM_DISCONNECTED","stream terminated: WebSocket disconnected")),this.streams.delete(i));if(this.WebSocketImpl===void 0)return;let s=e.reconnect.next();e.reconnectTimer=setTimeout(()=>{e.reconnectTimer=void 0,this.ensureSocket(e.shardKey)},s)}startHeartbeat(e){this.stopHeartbeat(e),!(this.heartbeatIntervalMs<=0)&&(e.heartbeatTimer=setInterval(()=>{if(!(e.wsState!=="open"||!e.socket))try{e.socket.send(os)}catch{}},this.heartbeatIntervalMs))}stopHeartbeat(e){e.heartbeatTimer!==void 0&&(clearInterval(e.heartbeatTimer),e.heartbeatTimer=void 0)}markShardPendingAck(e){let r=T(e);for(let s of this.subscriptions.all())T(s.shardKey)===r&&(s.acked=!1)}sendSubscribeIfOpen(e){let r=this.getConnection(e.shardKey);if(r?.wsState!=="open"||e.acked)return;let s=e.fn.__lunoraTable??e.fn.__lunoraRef;k(r,{id:e.id,query:{args:O(e.args),functionPath:e.fn.__lunoraRef,table:s,...e.serverCursor===void 0?{}:{sinceSeq:e.serverCursor},...e.serverEpoch===void 0?{}:{sinceEpoch:e.serverEpoch}},type:"subscribe"})}sendShapeSubscribeIfOpen(e){let r=this.getConnection(e.shardKey);r?.wsState==="open"&&k(r,{id:e.id,shape:{name:e.name,...e.wireArgs===void 0?{}:{args:e.wireArgs}},type:"shape_subscribe",...e.serverCursor===void 0?{}:{sinceCheckpoint:e.serverCursor},...e.serverEpoch===void 0?{}:{sinceEpoch:e.serverEpoch}})}handleServerMessage(e,r){let s=Ai(e);if(s===void 0)return;let i;try{i=JSON.parse(s)}catch{return}switch(i.type){case"ack":{let n=this.subscriptions.getById(i.id);n&&(n.acked=!0);return}case"chunk":{let{data:n,id:a}=i;this.streams.get(a)?.handle.push(w(n));return}case"complete":{this.handleCompleteMessage(i.id);return}case"data":case"delta":{this.handleDataMessage(i);return}case"error":{this.handleErrorMessage(i);break}case"pokeEnd":{this.handlePokeEnd(i);break}case"pokePart":{this.handlePokePart(i);break}case"pokeStart":{this.handlePokeStart(i);break}case"resume":{this.handleResumeMessage(i);break}case"settled":{this.handleSettledMessage(i);break}case"whisper":{this.dispatchWhisper(i,r);break}}}handleErrorMessage(e){if(e.error?.code==="TOKEN_EXPIRED"){this.notifyTokenExpired();return}let{id:s}=e,i=s===void 0?void 0:this.streams.get(s);if(i&&s!==void 0){i.handle.fail(Ci(e)),this.streams.delete(s);return}let n=s===void 0?void 0:this.subscriptions.getById(s);if(n){mr(n.errorCallbacks,fr(e));return}let a=s===void 0?void 0:this.shapeSubscriptions.get(s);a&&mr(a.errorCallbacks,fr(e))}handlePokeStart(e){rs(this.pokeBuffers,t.MAX_POKE_BUFFERS),this.pokeBuffers.set(e.pokeId,{baseCheckpoint:e.baseCheckpoint,epoch:e.epoch,lastMutationId:new Map,parts:new Map})}handlePokePart(e){let r=this.pokeBuffers.get(e.pokeId);if(!r)return;let s=r.parts.get(e.shapeId)??[];for(let i of e.rowsPatch)s.push(i.value===void 0?i:{...i,value:w(i.value)});r.parts.set(e.shapeId,s),e.lastMutationId!==void 0&&r.lastMutationId.set(e.shapeId,e.lastMutationId)}handlePokeEnd(e){let r=this.pokeBuffers.get(e.pokeId);if(r){this.pokeBuffers.delete(e.pokeId);for(let[s,i]of r.parts){let n=this.shapeSubscriptions.get(s);if(!n)continue;let a=r.epoch!==void 0&&n.serverEpoch!==void 0&&r.epoch!==n.serverEpoch,u=r.baseCheckpoint!==void 0&&n.serverCursor!==void 0&&n.serverCursor!==r.baseCheckpoint;if(a||u){n.rows.clear(),n.serverCursor=void 0,n.serverEpoch=void 0,this.emitShapeRows(n),this.sendShapeSubscribeIfOpen(n);continue}ns(n.rows,i),e.checkpoint!==void 0&&(n.serverCursor=e.checkpoint),e.epoch!==void 0&&(n.serverEpoch=e.epoch);let c=r.lastMutationId.get(s);c!==void 0&&(n.lastMutationId=c),this.emitShapeRows(n),n.onCheckpoint?.({checkpoint:n.serverCursor,mutationId:n.lastMutationId})}}}emitShapeRows(e){let r=[...e.rows.values()];for(let s of e.callbacks)try{s(r)}catch{}}handleDataMessage(e){let{id:r}=e,s=r?this.subscriptions.getById(r):void 0;if(!s)return;let i=this.resolveDataPayload(e,s);if(s.serverBase=i,e.cursor!==void 0&&(s.serverCursor=e.cursor),e.epoch!==void 0&&(s.serverEpoch=e.epoch),this.persistQueryValue(s),tt(s,s.serverCursor),ue(s,s.optimisticLayers.length===0?i:he(i,s.optimisticLayers)),this.tabCoordinator?.isLeader()){let n=D.key(s.fn.__lunoraRef,s.args,s.shardKey);this.tabCoordinator.broadcastSubscriptionData(n,i)}}handleResumeMessage(e){let r=this.subscriptions.getById(e.id);r&&this.ackAndAdvanceCursor(r,e.cursor,e.epoch)}handleSettledMessage(e){let r=this.subscriptions.getById(e.id);if(r){this.ackAndAdvanceCursor(r,e.cursor,e.epoch),e.lastMutationId!==void 0&&(r.lastMutationId=e.lastMutationId);for(let s of r.checkpointCallbacks)s({checkpoint:r.serverCursor,mutationId:r.lastMutationId})}}ackAndAdvanceCursor(e,r,s){e.acked=!0,(r!==void 0&&r!==e.serverCursor||s!==void 0&&s!==e.serverEpoch)&&(r!==void 0&&(e.serverCursor=r),s!==void 0&&(e.serverEpoch=s),this.persistQueryValue(e),tt(e,e.serverCursor)&&ue(e,he(e.serverBase,e.optimisticLayers)))}resolveDataPayload(e,r){if("data"in e&&e.data!==void 0)return w(e.data);let s=w(e.delta);if(zt(s)&&r.serverBase!==void 0){let i=Jt(r.serverBase,s);if(i!==void 0)return i}return s}dispatchWhisper(e,r){let s=this.whisperHandlers.get(T(r))?.get(e.topic);if(!s)return;let i=w(e.data);for(let n of s)try{n(i,e.from)}catch{}}notifyTokenExpired(){this.tokenExpiredListeners.emit()}handleCompleteMessage(e){let r=this.streams.get(e);if(r){r.handle.complete(),this.streams.delete(e);return}let s=this.subscriptions.getById(e);s&&this.subscriptions.remove(s)}unpersist(e){e&&this.persistence?.remove(e).catch(r=>{te(this.onPersistenceError,"remove",r,e)})}identityFingerprint(){if(this.authSubject!==void 0)return this.authSubject===null?null:`subj:${this.authSubject}`;let e=this.authToken;return e===null?null:this.hashToken(e)}hashToken(e){let r=2166136261,s=5381;for(let i=0;i<e.length;i+=1){let n=e.charCodeAt(i);r^=n,r=Math.imul(r,16777619),s=Math.imul(s,33)+n}return`${e.length.toString(36)}:${(r>>>0).toString(36)}:${(s>>>0).toString(36)}`}isSameCredentialUnderTokenHash(e){if(e===null||e.startsWith("subj:"))return!1;let r=this.authToken;return r===null?!1:this.hashToken(r)===e}rejectQueuedForIdentityChange(){let e=this.offlineQueue.drain();for(let r of e){this.queuedIdentities.delete(r.id??""),this.unpersist(r.id);let s=new Error("offline mutation discarded: auth identity changed before replay");s.code="OFFLINE_IDENTITY_CHANGED",r.reject(s),this.emitItemSettled(r,"rejected",s)}this.clearQueryCacheForIdentityChange()}restampQueuedIdentity(e,r){for(let[s,i]of this.queuedIdentities)i===e&&this.queuedIdentities.set(s,r)}clearQueryCacheForIdentityChange(){this.cacheFlushTimer!==void 0&&(clearTimeout(this.cacheFlushTimer),this.cacheFlushTimer=void 0),this.pendingCacheWrites.clear(),this.hydratedQueryCache.clear(),this.queryCache?.clear().catch(()=>{})}async flushOfflineQueue(e){let r=this.offlineQueue.drainConflict();for(let d of r){this.unpersist(d.id),this.queuedIdentities.delete(d.id??"");let h=new Error("offline mutation skipped: precondition failed before replay");h.code="OFFLINE_PRECONDITION_FAILED",this.emitItemSettled(d,"rejected",h)}let s=T(e),i=this.offlineQueue.drain(d=>T(d.shardKey)===s);if(i.length===0)return;let n=this.identityFingerprint(),a=[];for(let d of i)this.passesReplayIdentityGate(d,n)&&a.push(d);if(a.length===0)return;let u=this.encodableOrSettleTerminal(a);if(u.length===0)return;if(u.length===1){await this.replaySequential(u);return}let c=[];for(let d=0;d<u.length;d+=it){let h=u.slice(d,d+it),f=await this.replayBatched(h);if(c.push(...f.requeue),f.stop){c.push(...u.slice(d+it));break}}c.length>0&&this.offlineQueue.requeue(c)}encodableOrSettleTerminal(e){let r=[];for(let s of e)try{J(s.args,`args for '${s.functionPath}'`),r.push(s)}catch(i){this.settleReplayTerminal(s,i instanceof Error?i:new Error(String(i)))}return r}passesReplayIdentityGate(e,r){let s=e.id===void 0?void 0:this.queuedIdentities.get(e.id),i=s===void 0?e.identity:s;if(i!==void 0&&i!==r&&!this.isSameCredentialUnderTokenHash(i)){this.queuedIdentities.delete(e.id??""),this.unpersist(e.id);let n=new Error("offline mutation skipped: auth identity changed before replay");return n.code="OFFLINE_IDENTITY_CHANGED",e.reject(n),this.emitItemSettled(e,"rejected",n),!1}return this.queuedIdentities.delete(e.id??""),!0}settleReplaySuccess(e,r,s){this.unpersist(e.id),e.onCommit?.(s),e.resolve(r),this.emitItemSettled(e,"committed")}settleReplayTerminal(e,r){this.unpersist(e.id),e.reject(r),this.emitItemSettled(e,"rejected",r)}async replaySequential(e){for(let r=0;r<e.length;r+=1){let s=e[r];if(s)try{let i,n=await this.rpc(s.functionPath,s.args,s.shardKey,{captureBookmark:!0,mutationId:s.id,onCommitCursor:o(a=>{i=a},"onCommitCursor")});this.settleReplaySuccess(s,n,i)}catch(i){if(i.code!==void 0){this.settleReplayTerminal(s,i);continue}this.offlineQueue.requeue(e.slice(r));return}}}async replayBatched(e){if(!this.fetchImpl)return{requeue:e,stop:!0};let r;try{r=await this.fetchImpl(z(this.url,hr),{body:JSON.stringify({calls:e.map((n,a)=>({args:J(n.args,`args for '${n.functionPath}'`),functionPath:n.functionPath,id:a,mutationId:n.id,shardKey:n.shardKey}))}),headers:this.rpcRequestHeaders({attachBookmark:!0}),method:"POST"})}catch{return{requeue:e,stop:!0}}let s=r.headers.get("x-d1-bookmark");s&&this.bookmark.set(s);let i;try{i=await r.json()}catch{return{requeue:e,stop:!0}}if(!i.results){if(i.error){let n=de(i.error);for(let a of e)this.settleReplayTerminal(a,n);return{requeue:[],stop:!1}}return{requeue:e,stop:!0}}return{requeue:this.settleReplayBatchSlots(e,i.results),stop:!1}}settleReplayBatchSlots(e,r){let s=new Map;for(let n of r)typeof n.id=="number"&&n.body!==void 0&&s.set(n.id,n.body);let i=[];for(let[n,a]of e.entries()){let u=s.get(n);u===void 0?i.push(a):"error"in u?_i.has(u.error.code)?i.push(a):this.settleReplayTerminal(a,de(u.error)):this.settleReplaySuccess(a,w(u.result),u.commitCursor)}return i}};export{ct as a,Sr as b,We as c,Pr as d,xr as e,Je as f,Mr as g};
@@ -1 +1 @@
1
- import{a as le}from"./chunk-LAK5VSPI.js";import{b as ae}from"./chunk-KJJ3WM6H.js";import{a as ne}from"./chunk-TQ36RWOP.js";import{a as oe}from"./chunk-AITOCPML.js";import{a as re}from"./chunk-2K47A3P6.js";import{a as se}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as K}from"./chunk-RXVQJ4DO.js";import{a as te}from"./chunk-LUP4YTBS.js";import{b as ee}from"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import{R as E}from"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import"./chunk-O3NAGRTR.js";import{b as D}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as U}from"./chunk-G7ZBM54M.js";import"./chunk-L2YBC2BV.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as Z}from"./chunk-TAD43CG5.js";import{d as X}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as i,e as z,f as Te,g as qe,h as Pe,j as R}from"./chunk-RRCPZMC2.js";var T=z(qe(),1);var m=z(Te(),1);var r=z(Pe(),1);var Y=400,Me=36,Oe={height:Y,overflow:"auto"},ue={left:0,position:"absolute",top:0,width:"100%"},Ae={debug:"secondary",error:"destructive",info:"outline",warn:"secondary"},Fe={error:"destructive",ok:"secondary"},_e=i(a=>{let e=(0,T.c)(21),{entry:t,index:l,measureRef:n,start:o}=a,d=`translateY(${String(o)}px)`,v;e[0]!==d?(v={...ue,transform:d},e[0]=d,e[1]=v):v=e[1];let f=v,u;e[2]!==t.timestamp?(u=new Date(t.timestamp).toLocaleString(),e[2]=t.timestamp,e[3]=u):u=e[3];let c;e[4]!==u?(c=(0,r.jsxDEV)("span",{className:"w-44 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:u},void 0,!1),e[4]=u,e[5]=c):c=e[5];let y=Ae[t.level],g;e[6]!==t.level||e[7]!==y?(g=(0,r.jsxDEV)("span",{className:"w-20 shrink-0",role:"gridcell",children:(0,r.jsxDEV)(D,{variant:y,children:t.level},void 0,!1)},void 0,!1),e[6]=t.level,e[7]=y,e[8]=g):g=e[8];let b=t.functionPath??"\u2014",p;e[9]!==b?(p=(0,r.jsxDEV)("span",{className:"w-48 shrink-0 truncate text-muted-foreground",role:"gridcell",children:b},void 0,!1),e[9]=b,e[10]=p):p=e[10];let h;e[11]!==t.message?(h=(0,r.jsxDEV)("span",{className:"flex-1 truncate",role:"gridcell",children:t.message},void 0,!1),e[11]=t.message,e[12]=h):h=e[12];let x;return e[13]!==l||e[14]!==n||e[15]!==f||e[16]!==c||e[17]!==g||e[18]!==p||e[19]!==h?(x=(0,r.jsxDEV)("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":l,"data-testid":"lg-row",ref:n,role:"row",style:f,children:[c,g,p,h]},void 0,!0),e[13]=l,e[14]=n,e[15]=f,e[16]=c,e[17]=g,e[18]=p,e[19]=h,e[20]=x):x=e[20],x},"LogRow"),ie=i(a=>a.length===0?"\u2014":a.join(", "),"tablesLabel"),Ve=i(a=>{let e=(0,T.c)(37),{entry:t,index:l,measureRef:n,start:o}=a,d=`translateY(${String(o)}px)`,v;e[0]!==d?(v={...ue,transform:d},e[0]=d,e[1]=v):v=e[1];let f=v,u;e[2]!==t.ts?(u=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=u):u=e[3];let c;e[4]!==u?(c=(0,r.jsxDEV)("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:u},void 0,!1),e[4]=u,e[5]=c):c=e[5];let y=Fe[t.outcome],g;e[6]!==t.outcome||e[7]!==y?(g=(0,r.jsxDEV)("span",{className:"w-16 shrink-0",role:"gridcell",children:(0,r.jsxDEV)(D,{variant:y,children:t.outcome},void 0,!1)},void 0,!1),e[6]=t.outcome,e[7]=y,e[8]=g):g=e[8];let b;e[9]!==t.functionPath?(b=(0,r.jsxDEV)("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:t.functionPath,children:t.functionPath},void 0,!1),e[9]=t.functionPath,e[10]=b):b=e[10];let p=t.shardKey??"\u2014",h;e[11]!==p?(h=(0,r.jsxDEV)("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:p},void 0,!1),e[11]=p,e[12]=h):h=e[12];let x=t.userId??"\u2014",L;e[13]!==x?(L=(0,r.jsxDEV)("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:x},void 0,!1),e[13]=x,e[14]=L):L=e[14];let k;e[15]!==t.durationMs?(k=Math.round(t.durationMs),e[15]=t.durationMs,e[16]=k):k=e[16];let I=`${String(k)}ms`,w;e[17]!==I?(w=(0,r.jsxDEV)("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:I},void 0,!1),e[17]=I,e[18]=w):w=e[18];let S;e[19]!==t.errorMessage||e[20]!==t.outcome||e[21]!==t.tablesRead||e[22]!==t.tablesWritten?(S=t.outcome==="error"&&t.errorMessage!==void 0?t.errorMessage:`r:${ie(t.tablesRead)} \xB7 w:${ie(t.tablesWritten)}`,e[19]=t.errorMessage,e[20]=t.outcome,e[21]=t.tablesRead,e[22]=t.tablesWritten,e[23]=S):S=e[23];let N;e[24]!==S?(N=(0,r.jsxDEV)("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:S},void 0,!1),e[24]=S,e[25]=N):N=e[25];let C;return e[26]!==l||e[27]!==n||e[28]!==f||e[29]!==L||e[30]!==w||e[31]!==N||e[32]!==c||e[33]!==g||e[34]!==b||e[35]!==h?(C=(0,r.jsxDEV)("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":l,"data-testid":"lg-req-row",ref:n,role:"row",style:f,children:[c,g,b,h,L,w,N]},void 0,!0),e[26]=l,e[27]=n,e[28]=f,e[29]=L,e[30]=w,e[31]=N,e[32]=c,e[33]=g,e[34]=b,e[35]=h,e[36]=C):C=e[36],C},"RequestRow"),de=i(a=>{let{entries:e}=a??{};return Array.isArray(e)?e:[]},"entriesOf"),$e=i(a=>{let e={};return a.functionPathPrefix.trim()!==""&&(e.functionPathPrefix=a.functionPathPrefix.trim()),a.userId.trim()!==""&&(e.userId=a.userId.trim()),a.tableTouched.trim()!==""&&(e.tableTouched=a.tableTouched.trim()),(a.outcome==="ok"||a.outcome==="error")&&(e.outcome=a.outcome),e},"buildRequestQuery"),me=["debug","info","warn","error"],Be={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},ze=i((a,e)=>{let t=e.search.trim().toLowerCase(),l=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-Be[e.range];return a.filter(o=>e.levels.size>0&&!e.levels.has(o.level)||o.timestamp<n||l!==""&&!(o.functionPath??"").toLowerCase().includes(l)?!1:t===""||o.message.toLowerCase().includes(t))},"filterLogs"),De="\u2014",Ke=i(a=>{let e=new Map,t=new Map;for(let o of a){e.set(o.level,(e.get(o.level)??0)+1);let d=o.functionPath??De;t.set(d,(t.get(d)??0)+1)}let l=me.filter(o=>e.has(o)).map(o=>({count:e.get(o)??0,key:o})),n=[...t.entries()].map(([o,d])=>({count:d,key:o})).toSorted((o,d)=>d.count===o.count?o.key.localeCompare(d.key):d.count-o.count);return{byLevel:l,byPath:n,total:a.length}},"summarizeLogs"),Ue=i(a=>{let e=(0,T.c)(11),{level:t,onToggle:l,selected:n}=a,o;e[0]!==t||e[1]!==l?(o=i(()=>{l(t)},"t1"),e[0]=t,e[1]=l,e[2]=o):o=e[2];let d=o,v=n?"border-border bg-muted font-medium":"border-input text-muted-foreground",f;e[3]!==v?(f=R("rounded-md border px-2 py-1 text-xs",v),e[3]=v,e[4]=f):f=e[4];let u=`logs-level-${t}`,c;return e[5]!==t||e[6]!==d||e[7]!==n||e[8]!==f||e[9]!==u?(c=(0,r.jsxDEV)("button",{"aria-pressed":n,className:f,"data-testid":u,onClick:d,type:"button",children:t},void 0,!1),e[5]=t,e[6]=d,e[7]=n,e[8]=f,e[9]=u,e[10]=c):c=e[10],c},"LevelToggle"),ce=i(a=>{let e=(0,T.c)(7),{bucket:t}=a,l;e[0]!==t.key?(l=(0,r.jsxDEV)("span",{className:"truncate text-muted-foreground",role:"gridcell",children:t.key},void 0,!1),e[0]=t.key,e[1]=l):l=e[1];let n;e[2]!==t.count?(n=(0,r.jsxDEV)("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:t.count},void 0,!1),e[2]=t.count,e[3]=n):n=e[3];let o;return e[4]!==l||e[5]!==n?(o=(0,r.jsxDEV)("div",{className:"flex items-center justify-between gap-4 px-3 py-1 font-mono text-xs","data-testid":"logs-summary-row",role:"row",children:[l,n]},void 0,!0),e[4]=l,e[5]=n,e[6]=o):o=e[6],o},"SummaryBucketRow"),nt=i(({initialShardKey:a})=>{let e=X(),[t,l]=(0,m.useState)("requests"),[n,o]=(0,m.useState)(a??""),[d,v]=(0,m.useState)(""),[f,u]=(0,m.useState)(()=>new Set),[c,y]=(0,m.useState)(""),[g,b]=(0,m.useState)("all"),[p,h]=(0,m.useState)(!1),[x,L]=(0,m.useState)(""),[k,I]=(0,m.useState)(""),[w,S]=(0,m.useState)(""),[N,C]=(0,m.useState)("all"),q=re(n.trim(),400),fe=$e({functionPathPrefix:x,outcome:N,tableTouched:w,userId:k}),Q=K(U.getRequestLog,fe,{enabled:t==="requests",live:!0,shardKey:q}),W=K(U.getLogs,{},{enabled:t==="errors",live:!0,shardKey:q}),A=t==="requests"?Q:W,{error:G,errorSource:he,isLoading:H,liveError:ge}=A,ve=de(W.data),j=de(Q.data);(0,m.useEffect)(()=>{A.data!==void 0&&ee(q)},[A.data,q]);let F=ze(ve,{levels:f,now:Date.now(),path:c,range:g,search:d}),_=Ke(F),V=t==="requests"?j.length:F.length,$=t==="errors"&&p,P=(0,m.useMemo)(()=>G!==null?"error":V===0?H?$?"summary":"list":"empty":$?"summary":"list",[V,H,G,$]),J=(0,m.useRef)(null),M=ae({count:V,estimateSize:i(()=>Me,"estimateSize"),getScrollElement:i(()=>J.current,"getScrollElement"),initialRect:{height:Y,width:800},observeElementRect:i((s,B)=>le(s,B,Y),"observeElementRect"),overscan:8}),pe=M.getVirtualItems(),be={height:M.getTotalSize(),position:"relative",width:"100%"},xe=i(s=>{v(s.target.value)},"onSearchChange"),ye=i(s=>{u(B=>{let O=new Set(B);return O.has(s)?O.delete(s):O.add(s),O})},"toggleLevel"),we=i(s=>{y(s.target.value)},"onLogPathChange"),Ne=i(s=>{b(s.target.value)},"onTimeRangeChange"),Le=i(()=>{h(s=>!s)},"toggleSummary"),Se=i(s=>{L(s.target.value)},"onPathChange"),ke=i(s=>{I(s.target.value)},"onUserChange"),Ce=i(s=>{S(s.target.value)},"onTableChange"),Ee=i(s=>{C(s.target.value)},"onOutcomeChange"),Ie=i(()=>{l("requests"),h(!1)},"showRequests"),Re=i(()=>{l("errors"),h(!1)},"showErrors");return(0,r.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxDEV)("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[(0,r.jsxDEV)("button",{"aria-selected":t==="requests",className:R("px-3 py-1 text-sm",t==="requests"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-requests",onClick:Ie,role:"tab",type:"button",children:e("Requests")},void 0,!1),(0,r.jsxDEV)("button",{"aria-selected":t==="errors",className:R("px-3 py-1 text-sm",t==="errors"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-errors",onClick:Re,role:"tab",type:"button",children:e("Errors")},void 0,!1)]},void 0,!0),(0,r.jsxDEV)(te,{onChange:o,testId:"lg-shard-input",value:n},void 0,!1),(0,r.jsxDEV)(oe,{message:ge,prefix:"lg"},void 0,!1),(0,r.jsxDEV)("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:ne,rel:"noreferrer",target:"_blank",children:e("Open in Cloudflare")},void 0,!1)]},void 0,!0),t==="errors"&&(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxDEV)(E,{"aria-label":e("Search messages"),className:"h-8 w-48","data-testid":"lg-search",onChange:xe,placeholder:e("search message"),value:d},void 0,!1),(0,r.jsxDEV)(E,{"aria-label":e("Function path"),className:"h-8 w-40","data-testid":"logs-path-filter",onChange:we,placeholder:e("filter path"),value:c},void 0,!1),(0,r.jsxDEV)("div",{"aria-label":e("Level filter"),className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:me.map(s=>(0,r.jsxDEV)(Ue,{level:s,onToggle:ye,selected:f.has(s)},s,!1))},void 0,!1),(0,r.jsxDEV)("select",{"aria-label":e("Time range"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"logs-time-range",onChange:Ne,value:g,children:[(0,r.jsxDEV)("option",{value:"all",children:e("All time")},void 0,!1),(0,r.jsxDEV)("option",{value:"5m",children:e("Last 5m")},void 0,!1),(0,r.jsxDEV)("option",{value:"15m",children:e("Last 15m")},void 0,!1),(0,r.jsxDEV)("option",{value:"1h",children:e("Last hour")},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("button",{"aria-pressed":p,className:R("h-8 rounded-md border px-3 text-sm",p?"border-border bg-muted font-medium":"border-input text-muted-foreground"),"data-testid":"logs-summary-toggle",onClick:Le,type:"button",children:e(p?"List":"Summary")},void 0,!1)]},void 0,!0),t==="requests"&&(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxDEV)(E,{"aria-label":e("Function path"),className:"h-8 w-44","data-testid":"lg-req-path",onChange:Se,placeholder:e("file:function"),value:x},void 0,!1),(0,r.jsxDEV)(E,{"aria-label":e("User id"),className:"h-8 w-32","data-testid":"lg-req-user",onChange:ke,placeholder:e("userId"),value:k},void 0,!1),(0,r.jsxDEV)(E,{"aria-label":e("Table touched"),className:"h-8 w-32","data-testid":"lg-req-table",onChange:Ce,placeholder:e("table"),value:w},void 0,!1),(0,r.jsxDEV)("select",{"aria-label":e("Outcome filter"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"lg-req-outcome",onChange:Ee,value:N,children:[(0,r.jsxDEV)("option",{value:"all",children:e("all")},void 0,!1),(0,r.jsxDEV)("option",{value:"ok",children:e("ok")},void 0,!1),(0,r.jsxDEV)("option",{value:"error",children:e("error")},void 0,!1)]},void 0,!0)]},void 0,!0),P==="error"&&(0,r.jsxDEV)(se,{error:he,testId:"lg-error"},void 0,!1),P==="empty"&&(0,r.jsxDEV)(Z,{description:e("Function and request logs for this shard show up here as your app handles traffic."),icon:(0,r.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,r.jsxDEV)("path",{d:"M4 5h16M4 12h16M4 19h10"},void 0,!1)},void 0,!1),testId:"lg-empty",title:e("No logs.")},void 0,!1),P==="summary"&&(0,r.jsxDEV)("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[(0,r.jsxDEV)("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:e("{count} entries",{count:_.total})},void 0,!1),(0,r.jsxDEV)("div",{children:[(0,r.jsxDEV)("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By level")},void 0,!1),(0,r.jsxDEV)("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:_.byLevel.map(s=>(0,r.jsxDEV)(ce,{bucket:s},s.key,!1))},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{children:[(0,r.jsxDEV)("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By function")},void 0,!1),(0,r.jsxDEV)("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:_.byPath.map(s=>(0,r.jsxDEV)(ce,{bucket:s},s.key,!1))},void 0,!1)]},void 0,!0)]},void 0,!0),P==="list"&&(0,r.jsxDEV)("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:J,style:Oe,children:(0,r.jsxDEV)("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:be,children:pe.map(s=>t==="requests"?(0,r.jsxDEV)(Ve,{entry:j[s.index],index:s.index,measureRef:M.measureElement,start:s.start},s.key,!1):(0,r.jsxDEV)(_e,{entry:F[s.index],index:s.index,measureRef:M.measureElement,start:s.start},s.key,!1))},void 0,!1)},void 0,!1)]},void 0,!0)},"LogsPanel");export{nt as LogsPanel,ze as filterLogs,Ke as summarizeLogs};
1
+ import{a as le}from"./chunk-LAK5VSPI.js";import{b as ae}from"./chunk-KJJ3WM6H.js";import{a as ne}from"./chunk-TQ36RWOP.js";import{a as oe}from"./chunk-AITOCPML.js";import{a as re}from"./chunk-2K47A3P6.js";import{a as se}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as K}from"./chunk-ZQQ3MFEQ.js";import{a as te}from"./chunk-LUP4YTBS.js";import{b as ee}from"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import{R as E}from"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import"./chunk-O3NAGRTR.js";import{b as D}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as U}from"./chunk-G7ZBM54M.js";import"./chunk-LOYE7OU2.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as Z}from"./chunk-TAD43CG5.js";import{d as X}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as i,e as z,f as Te,g as qe,h as Pe,j as R}from"./chunk-RRCPZMC2.js";var T=z(qe(),1);var m=z(Te(),1);var r=z(Pe(),1);var Y=400,Me=36,Oe={height:Y,overflow:"auto"},ue={left:0,position:"absolute",top:0,width:"100%"},Ae={debug:"secondary",error:"destructive",info:"outline",warn:"secondary"},Fe={error:"destructive",ok:"secondary"},_e=i(a=>{let e=(0,T.c)(21),{entry:t,index:l,measureRef:n,start:o}=a,d=`translateY(${String(o)}px)`,v;e[0]!==d?(v={...ue,transform:d},e[0]=d,e[1]=v):v=e[1];let f=v,u;e[2]!==t.timestamp?(u=new Date(t.timestamp).toLocaleString(),e[2]=t.timestamp,e[3]=u):u=e[3];let c;e[4]!==u?(c=(0,r.jsxDEV)("span",{className:"w-44 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:u},void 0,!1),e[4]=u,e[5]=c):c=e[5];let y=Ae[t.level],g;e[6]!==t.level||e[7]!==y?(g=(0,r.jsxDEV)("span",{className:"w-20 shrink-0",role:"gridcell",children:(0,r.jsxDEV)(D,{variant:y,children:t.level},void 0,!1)},void 0,!1),e[6]=t.level,e[7]=y,e[8]=g):g=e[8];let b=t.functionPath??"\u2014",p;e[9]!==b?(p=(0,r.jsxDEV)("span",{className:"w-48 shrink-0 truncate text-muted-foreground",role:"gridcell",children:b},void 0,!1),e[9]=b,e[10]=p):p=e[10];let h;e[11]!==t.message?(h=(0,r.jsxDEV)("span",{className:"flex-1 truncate",role:"gridcell",children:t.message},void 0,!1),e[11]=t.message,e[12]=h):h=e[12];let x;return e[13]!==l||e[14]!==n||e[15]!==f||e[16]!==c||e[17]!==g||e[18]!==p||e[19]!==h?(x=(0,r.jsxDEV)("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":l,"data-testid":"lg-row",ref:n,role:"row",style:f,children:[c,g,p,h]},void 0,!0),e[13]=l,e[14]=n,e[15]=f,e[16]=c,e[17]=g,e[18]=p,e[19]=h,e[20]=x):x=e[20],x},"LogRow"),ie=i(a=>a.length===0?"\u2014":a.join(", "),"tablesLabel"),Ve=i(a=>{let e=(0,T.c)(37),{entry:t,index:l,measureRef:n,start:o}=a,d=`translateY(${String(o)}px)`,v;e[0]!==d?(v={...ue,transform:d},e[0]=d,e[1]=v):v=e[1];let f=v,u;e[2]!==t.ts?(u=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=u):u=e[3];let c;e[4]!==u?(c=(0,r.jsxDEV)("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:u},void 0,!1),e[4]=u,e[5]=c):c=e[5];let y=Fe[t.outcome],g;e[6]!==t.outcome||e[7]!==y?(g=(0,r.jsxDEV)("span",{className:"w-16 shrink-0",role:"gridcell",children:(0,r.jsxDEV)(D,{variant:y,children:t.outcome},void 0,!1)},void 0,!1),e[6]=t.outcome,e[7]=y,e[8]=g):g=e[8];let b;e[9]!==t.functionPath?(b=(0,r.jsxDEV)("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:t.functionPath,children:t.functionPath},void 0,!1),e[9]=t.functionPath,e[10]=b):b=e[10];let p=t.shardKey??"\u2014",h;e[11]!==p?(h=(0,r.jsxDEV)("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:p},void 0,!1),e[11]=p,e[12]=h):h=e[12];let x=t.userId??"\u2014",L;e[13]!==x?(L=(0,r.jsxDEV)("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:x},void 0,!1),e[13]=x,e[14]=L):L=e[14];let k;e[15]!==t.durationMs?(k=Math.round(t.durationMs),e[15]=t.durationMs,e[16]=k):k=e[16];let I=`${String(k)}ms`,w;e[17]!==I?(w=(0,r.jsxDEV)("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:I},void 0,!1),e[17]=I,e[18]=w):w=e[18];let S;e[19]!==t.errorMessage||e[20]!==t.outcome||e[21]!==t.tablesRead||e[22]!==t.tablesWritten?(S=t.outcome==="error"&&t.errorMessage!==void 0?t.errorMessage:`r:${ie(t.tablesRead)} \xB7 w:${ie(t.tablesWritten)}`,e[19]=t.errorMessage,e[20]=t.outcome,e[21]=t.tablesRead,e[22]=t.tablesWritten,e[23]=S):S=e[23];let N;e[24]!==S?(N=(0,r.jsxDEV)("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:S},void 0,!1),e[24]=S,e[25]=N):N=e[25];let C;return e[26]!==l||e[27]!==n||e[28]!==f||e[29]!==L||e[30]!==w||e[31]!==N||e[32]!==c||e[33]!==g||e[34]!==b||e[35]!==h?(C=(0,r.jsxDEV)("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":l,"data-testid":"lg-req-row",ref:n,role:"row",style:f,children:[c,g,b,h,L,w,N]},void 0,!0),e[26]=l,e[27]=n,e[28]=f,e[29]=L,e[30]=w,e[31]=N,e[32]=c,e[33]=g,e[34]=b,e[35]=h,e[36]=C):C=e[36],C},"RequestRow"),de=i(a=>{let{entries:e}=a??{};return Array.isArray(e)?e:[]},"entriesOf"),$e=i(a=>{let e={};return a.functionPathPrefix.trim()!==""&&(e.functionPathPrefix=a.functionPathPrefix.trim()),a.userId.trim()!==""&&(e.userId=a.userId.trim()),a.tableTouched.trim()!==""&&(e.tableTouched=a.tableTouched.trim()),(a.outcome==="ok"||a.outcome==="error")&&(e.outcome=a.outcome),e},"buildRequestQuery"),me=["debug","info","warn","error"],Be={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},ze=i((a,e)=>{let t=e.search.trim().toLowerCase(),l=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-Be[e.range];return a.filter(o=>e.levels.size>0&&!e.levels.has(o.level)||o.timestamp<n||l!==""&&!(o.functionPath??"").toLowerCase().includes(l)?!1:t===""||o.message.toLowerCase().includes(t))},"filterLogs"),De="\u2014",Ke=i(a=>{let e=new Map,t=new Map;for(let o of a){e.set(o.level,(e.get(o.level)??0)+1);let d=o.functionPath??De;t.set(d,(t.get(d)??0)+1)}let l=me.filter(o=>e.has(o)).map(o=>({count:e.get(o)??0,key:o})),n=[...t.entries()].map(([o,d])=>({count:d,key:o})).toSorted((o,d)=>d.count===o.count?o.key.localeCompare(d.key):d.count-o.count);return{byLevel:l,byPath:n,total:a.length}},"summarizeLogs"),Ue=i(a=>{let e=(0,T.c)(11),{level:t,onToggle:l,selected:n}=a,o;e[0]!==t||e[1]!==l?(o=i(()=>{l(t)},"t1"),e[0]=t,e[1]=l,e[2]=o):o=e[2];let d=o,v=n?"border-border bg-muted font-medium":"border-input text-muted-foreground",f;e[3]!==v?(f=R("rounded-md border px-2 py-1 text-xs",v),e[3]=v,e[4]=f):f=e[4];let u=`logs-level-${t}`,c;return e[5]!==t||e[6]!==d||e[7]!==n||e[8]!==f||e[9]!==u?(c=(0,r.jsxDEV)("button",{"aria-pressed":n,className:f,"data-testid":u,onClick:d,type:"button",children:t},void 0,!1),e[5]=t,e[6]=d,e[7]=n,e[8]=f,e[9]=u,e[10]=c):c=e[10],c},"LevelToggle"),ce=i(a=>{let e=(0,T.c)(7),{bucket:t}=a,l;e[0]!==t.key?(l=(0,r.jsxDEV)("span",{className:"truncate text-muted-foreground",role:"gridcell",children:t.key},void 0,!1),e[0]=t.key,e[1]=l):l=e[1];let n;e[2]!==t.count?(n=(0,r.jsxDEV)("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:t.count},void 0,!1),e[2]=t.count,e[3]=n):n=e[3];let o;return e[4]!==l||e[5]!==n?(o=(0,r.jsxDEV)("div",{className:"flex items-center justify-between gap-4 px-3 py-1 font-mono text-xs","data-testid":"logs-summary-row",role:"row",children:[l,n]},void 0,!0),e[4]=l,e[5]=n,e[6]=o):o=e[6],o},"SummaryBucketRow"),nt=i(({initialShardKey:a})=>{let e=X(),[t,l]=(0,m.useState)("requests"),[n,o]=(0,m.useState)(a??""),[d,v]=(0,m.useState)(""),[f,u]=(0,m.useState)(()=>new Set),[c,y]=(0,m.useState)(""),[g,b]=(0,m.useState)("all"),[p,h]=(0,m.useState)(!1),[x,L]=(0,m.useState)(""),[k,I]=(0,m.useState)(""),[w,S]=(0,m.useState)(""),[N,C]=(0,m.useState)("all"),q=re(n.trim(),400),fe=$e({functionPathPrefix:x,outcome:N,tableTouched:w,userId:k}),Q=K(U.getRequestLog,fe,{enabled:t==="requests",live:!0,shardKey:q}),W=K(U.getLogs,{},{enabled:t==="errors",live:!0,shardKey:q}),A=t==="requests"?Q:W,{error:G,errorSource:he,isLoading:H,liveError:ge}=A,ve=de(W.data),j=de(Q.data);(0,m.useEffect)(()=>{A.data!==void 0&&ee(q)},[A.data,q]);let F=ze(ve,{levels:f,now:Date.now(),path:c,range:g,search:d}),_=Ke(F),V=t==="requests"?j.length:F.length,$=t==="errors"&&p,P=(0,m.useMemo)(()=>G!==null?"error":V===0?H?$?"summary":"list":"empty":$?"summary":"list",[V,H,G,$]),J=(0,m.useRef)(null),M=ae({count:V,estimateSize:i(()=>Me,"estimateSize"),getScrollElement:i(()=>J.current,"getScrollElement"),initialRect:{height:Y,width:800},observeElementRect:i((s,B)=>le(s,B,Y),"observeElementRect"),overscan:8}),pe=M.getVirtualItems(),be={height:M.getTotalSize(),position:"relative",width:"100%"},xe=i(s=>{v(s.target.value)},"onSearchChange"),ye=i(s=>{u(B=>{let O=new Set(B);return O.has(s)?O.delete(s):O.add(s),O})},"toggleLevel"),we=i(s=>{y(s.target.value)},"onLogPathChange"),Ne=i(s=>{b(s.target.value)},"onTimeRangeChange"),Le=i(()=>{h(s=>!s)},"toggleSummary"),Se=i(s=>{L(s.target.value)},"onPathChange"),ke=i(s=>{I(s.target.value)},"onUserChange"),Ce=i(s=>{S(s.target.value)},"onTableChange"),Ee=i(s=>{C(s.target.value)},"onOutcomeChange"),Ie=i(()=>{l("requests"),h(!1)},"showRequests"),Re=i(()=>{l("errors"),h(!1)},"showErrors");return(0,r.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxDEV)("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[(0,r.jsxDEV)("button",{"aria-selected":t==="requests",className:R("px-3 py-1 text-sm",t==="requests"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-requests",onClick:Ie,role:"tab",type:"button",children:e("Requests")},void 0,!1),(0,r.jsxDEV)("button",{"aria-selected":t==="errors",className:R("px-3 py-1 text-sm",t==="errors"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-errors",onClick:Re,role:"tab",type:"button",children:e("Errors")},void 0,!1)]},void 0,!0),(0,r.jsxDEV)(te,{onChange:o,testId:"lg-shard-input",value:n},void 0,!1),(0,r.jsxDEV)(oe,{message:ge,prefix:"lg"},void 0,!1),(0,r.jsxDEV)("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:ne,rel:"noreferrer",target:"_blank",children:e("Open in Cloudflare")},void 0,!1)]},void 0,!0),t==="errors"&&(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxDEV)(E,{"aria-label":e("Search messages"),className:"h-8 w-48","data-testid":"lg-search",onChange:xe,placeholder:e("search message"),value:d},void 0,!1),(0,r.jsxDEV)(E,{"aria-label":e("Function path"),className:"h-8 w-40","data-testid":"logs-path-filter",onChange:we,placeholder:e("filter path"),value:c},void 0,!1),(0,r.jsxDEV)("div",{"aria-label":e("Level filter"),className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:me.map(s=>(0,r.jsxDEV)(Ue,{level:s,onToggle:ye,selected:f.has(s)},s,!1))},void 0,!1),(0,r.jsxDEV)("select",{"aria-label":e("Time range"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"logs-time-range",onChange:Ne,value:g,children:[(0,r.jsxDEV)("option",{value:"all",children:e("All time")},void 0,!1),(0,r.jsxDEV)("option",{value:"5m",children:e("Last 5m")},void 0,!1),(0,r.jsxDEV)("option",{value:"15m",children:e("Last 15m")},void 0,!1),(0,r.jsxDEV)("option",{value:"1h",children:e("Last hour")},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("button",{"aria-pressed":p,className:R("h-8 rounded-md border px-3 text-sm",p?"border-border bg-muted font-medium":"border-input text-muted-foreground"),"data-testid":"logs-summary-toggle",onClick:Le,type:"button",children:e(p?"List":"Summary")},void 0,!1)]},void 0,!0),t==="requests"&&(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,r.jsxDEV)(E,{"aria-label":e("Function path"),className:"h-8 w-44","data-testid":"lg-req-path",onChange:Se,placeholder:e("file:function"),value:x},void 0,!1),(0,r.jsxDEV)(E,{"aria-label":e("User id"),className:"h-8 w-32","data-testid":"lg-req-user",onChange:ke,placeholder:e("userId"),value:k},void 0,!1),(0,r.jsxDEV)(E,{"aria-label":e("Table touched"),className:"h-8 w-32","data-testid":"lg-req-table",onChange:Ce,placeholder:e("table"),value:w},void 0,!1),(0,r.jsxDEV)("select",{"aria-label":e("Outcome filter"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"lg-req-outcome",onChange:Ee,value:N,children:[(0,r.jsxDEV)("option",{value:"all",children:e("all")},void 0,!1),(0,r.jsxDEV)("option",{value:"ok",children:e("ok")},void 0,!1),(0,r.jsxDEV)("option",{value:"error",children:e("error")},void 0,!1)]},void 0,!0)]},void 0,!0),P==="error"&&(0,r.jsxDEV)(se,{error:he,testId:"lg-error"},void 0,!1),P==="empty"&&(0,r.jsxDEV)(Z,{description:e("Function and request logs for this shard show up here as your app handles traffic."),icon:(0,r.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,r.jsxDEV)("path",{d:"M4 5h16M4 12h16M4 19h10"},void 0,!1)},void 0,!1),testId:"lg-empty",title:e("No logs.")},void 0,!1),P==="summary"&&(0,r.jsxDEV)("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[(0,r.jsxDEV)("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:e("{count} entries",{count:_.total})},void 0,!1),(0,r.jsxDEV)("div",{children:[(0,r.jsxDEV)("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By level")},void 0,!1),(0,r.jsxDEV)("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:_.byLevel.map(s=>(0,r.jsxDEV)(ce,{bucket:s},s.key,!1))},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{children:[(0,r.jsxDEV)("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By function")},void 0,!1),(0,r.jsxDEV)("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:_.byPath.map(s=>(0,r.jsxDEV)(ce,{bucket:s},s.key,!1))},void 0,!1)]},void 0,!0)]},void 0,!0),P==="list"&&(0,r.jsxDEV)("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:J,style:Oe,children:(0,r.jsxDEV)("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:be,children:pe.map(s=>t==="requests"?(0,r.jsxDEV)(Ve,{entry:j[s.index],index:s.index,measureRef:M.measureElement,start:s.start},s.key,!1):(0,r.jsxDEV)(_e,{entry:F[s.index],index:s.index,measureRef:M.measureElement,start:s.start},s.key,!1))},void 0,!1)},void 0,!1)]},void 0,!0)},"LogsPanel");export{nt as LogsPanel,ze as filterLogs,Ke as summarizeLogs};
@@ -1 +1 @@
1
- import{a as U}from"./chunk-J6J54MBP.js";import{a as G}from"./chunk-EEWKIQUE.js";import{a as Q}from"./chunk-RXVQJ4DO.js";import{a as W,b as H,c as K,d as F,e as p,f as x}from"./chunk-GTM65MVX.js";import{a as A,e as D}from"./chunk-SEU5V7I6.js";import{c as te}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import{b as ee}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as P}from"./chunk-L2YBC2BV.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as R}from"./chunk-TAD43CG5.js";import{d as q,h as Y,l as V,p as j}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as f,e as M,f as oe,g as se,h as re}from"./chunk-RRCPZMC2.js";var Z=M(se(),1),z=M(oe(),1);var t=M(re(),1);var ae=M(se(),1);var X=M(oe(),1);var u=M(re(),1);var ce=f(s=>Number.isFinite(s)?j(s,"\u2014"):"\u2014","formatScheduledFor"),ie=f(s=>s.toSorted((e,c)=>e.scheduledFor-c.scheduledFor),"sortByDue"),de=f(s=>{let e=(0,ae.c)(33),c;e[0]!==s?(c=s===void 0?{}:s,e[0]=s,e[1]=c):c=e[1];let{cancelJob:n,loadJobs:m}=c,r=P(),o=q(),l=m===void 0,k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=["lunora-scheduled-jobs"],e[2]=k):k=e[2];let v;e[3]!==r||e[4]!==m?(v=f(async()=>{let d=await(m??(()=>r.listScheduledJobs()))();return ie(d)},"t3"),e[3]=r,e[4]=m,e[5]=v):v=e[5];let a=Q(k,v),[i,h]=(0,X.useState)(void 0),[S,C]=(0,X.useState)(void 0),g,T;e[6]!==r||e[7]!==l?(g=f(()=>{if(l)return r.subscribeScheduledJobs(d=>{C(void 0),h(ie(d))})},"t4"),T=[l,r],e[6]=r,e[7]=l,e[8]=g,e[9]=T):(g=e[8],T=e[9]),(0,X.useEffect)(g,T);let b;e[10]!==a?(b=f(()=>{a.refetch()},"t6"),e[10]=a,e[11]=b):b=e[11],U(b,!l);let J;e:{if(n!==void 0){J=n;break e}let d;e[12]!==r||e[13]!==m?(d=m===void 0?O=>r.cancelScheduledJob(O):void 0,e[12]=r,e[13]=m,e[14]=d):d=e[14],J=d}let y=J,w=i??a.data,$=S??a.error,I;e[15]!==y||e[16]!==a||e[17]!==l?(I=f(async d=>{if(y!==void 0){C(void 0);try{await y(d),l||a.refetch()}catch(O){C(Y(O))}}},"t8"),e[15]=y,e[16]=a,e[17]=l,e[18]=I):I=e[18];let E=I,L;e[19]!==$?(L=$!==null&&(0,u.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"sj-error",role:"alert",children:$},void 0,!1),e[19]=$,e[20]=L):L=e[20];let N;e[21]!==w?.length||e[22]!==o?(N=w?.length===0&&(0,u.jsxDEV)(R,{description:o("Jobs queued with runAfter / runAt will appear here."),icon:(0,u.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[(0,u.jsxDEV)("circle",{cx:"12",cy:"12",r:"9"},void 0,!1),(0,u.jsxDEV)("path",{d:"M12 7.5V12l4 2"},void 0,!1)]},void 0,!0),testId:"sj-empty",title:o("No scheduled jobs.")},void 0,!1),e[21]=w?.length,e[22]=o,e[23]=N):N=e[23];let B;e[24]!==E||e[25]!==y||e[26]!==w||e[27]!==o?(B=w!==void 0&&w.length>0&&(0,u.jsxDEV)(A,{className:"overflow-hidden py-0",children:(0,u.jsxDEV)(D,{className:"px-0",children:(0,u.jsxDEV)(W,{"data-testid":"sj-table",children:[(0,u.jsxDEV)(H,{children:(0,u.jsxDEV)(F,{children:[(0,u.jsxDEV)(p,{children:o("function")},void 0,!1),(0,u.jsxDEV)(p,{children:o("scheduled for")},void 0,!1),(0,u.jsxDEV)(p,{children:o("pool")},void 0,!1),(0,u.jsxDEV)(p,{children:o("attempts")},void 0,!1),(0,u.jsxDEV)(p,{children:o("shard")},void 0,!1),(0,u.jsxDEV)(p,{children:o("id")},void 0,!1),y!==void 0&&(0,u.jsxDEV)(p,{"aria-label":o("Actions")},void 0,!1)]},void 0,!0)},void 0,!1),(0,u.jsxDEV)(K,{children:w.map(d=>(0,u.jsxDEV)(F,{"data-testid":`sj-row-${d.id}`,children:[(0,u.jsxDEV)(x,{className:"font-mono text-xs",children:d.functionPath},void 0,!1),(0,u.jsxDEV)(x,{className:"text-muted-foreground tabular-nums",children:ce(d.scheduledFor)},void 0,!1),(0,u.jsxDEV)(x,{className:"font-mono text-xs",children:d.pool??""},void 0,!1),(0,u.jsxDEV)(x,{className:"tabular-nums",children:d.attempts??0},void 0,!1),(0,u.jsxDEV)(x,{children:d.shardKey??""},void 0,!1),(0,u.jsxDEV)(x,{className:"font-mono text-xs",children:d.id},void 0,!1),y!==void 0&&(0,u.jsxDEV)(x,{className:"text-right",children:(0,u.jsxDEV)(G,{confirmLabel:o("Cancel job?"),onConfirm:f(()=>{V(E(d.id))},"onConfirm"),testId:`sj-cancel-${d.id}`,children:o("Cancel")},void 0,!1)},void 0,!1)]},d.id,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),e[24]=E,e[25]=y,e[26]=w,e[27]=o,e[28]=B):B=e[28];let _;return e[29]!==N||e[30]!==B||e[31]!==L?(_=(0,u.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-scheduled-jobs",children:[L,N,B]},void 0,!0),e[29]=N,e[30]=B,e[31]=L,e[32]=_):_=e[32],_},"ScheduledJobs");var fe={kind:"idle"},ue=f(({loadCronJobs:s,runCronJob:e}={})=>{let c=P(),n=q(),[m,r]=(0,z.useState)({}),o=Q(["lunora-cron-jobs",s?"custom":"default"],()=>(s??(()=>c.getCronJobs()))()),{data:l,error:k}=o,v=(0,z.useMemo)(()=>e!==void 0?e:s===void 0?i=>c.runCronJob(i):void 0,[c,s,e]),a=f(async i=>{if(v!==void 0){r(h=>({...h,[i]:{kind:"running"}}));try{await v(i),r(h=>({...h,[i]:{kind:"ok"}})),o.refetch()}catch(h){r(S=>({...S,[i]:{kind:"error",message:Y(h)}}))}}},"run");return(0,t.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-cron-triggers",children:[k!==null&&(0,t.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"cron-error",role:"alert",children:k},void 0,!1),l?.length===0&&(0,t.jsxDEV)(R,{description:n("Triggers declared with the cronJobs() builder appear here."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[(0,t.jsxDEV)("circle",{cx:"12",cy:"12",r:"9"},void 0,!1),(0,t.jsxDEV)("path",{d:"M12 7.5V12l4 2"},void 0,!1)]},void 0,!0),testId:"cron-empty",title:n("No cron triggers.")},void 0,!1),l!==void 0&&l.length>0&&(0,t.jsxDEV)(A,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(D,{className:"px-0",children:(0,t.jsxDEV)(W,{"data-testid":"cron-table",children:[(0,t.jsxDEV)(H,{children:(0,t.jsxDEV)(F,{children:[(0,t.jsxDEV)(p,{children:n("name")},void 0,!1),(0,t.jsxDEV)(p,{children:n("schedule")},void 0,!1),(0,t.jsxDEV)(p,{children:n("target")},void 0,!1),(0,t.jsxDEV)(p,{children:n("shard")},void 0,!1),v!==void 0&&(0,t.jsxDEV)(p,{"aria-label":n("Actions")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(K,{children:l.map(i=>{let h=m[i.name]??fe;return(0,t.jsxDEV)(F,{"data-testid":`cron-row-${i.name}`,children:[(0,t.jsxDEV)(x,{children:i.name},void 0,!1),(0,t.jsxDEV)(x,{className:"font-mono text-xs tabular-nums",children:i.cron},void 0,!1),(0,t.jsxDEV)(x,{children:(0,t.jsxDEV)("span",{className:"flex items-center gap-2",children:[i.workflow===void 0?(0,t.jsxDEV)(ee,{variant:"outline",children:n("function")},void 0,!1):(0,t.jsxDEV)(ee,{variant:"secondary",children:n("workflow")},void 0,!1),(0,t.jsxDEV)("span",{className:"font-mono text-xs",children:i.workflow??i.functionPath},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(x,{children:i.shardKey??""},void 0,!1),v!==void 0&&(0,t.jsxDEV)(x,{className:"text-right",children:(0,t.jsxDEV)("span",{className:"flex items-center justify-end gap-2",children:[h.kind==="ok"&&(0,t.jsxDEV)("span",{className:"text-xs text-muted-foreground","data-testid":`cron-ran-${i.name}`,children:n("ran")},void 0,!1),h.kind==="error"&&(0,t.jsxDEV)("span",{className:"text-xs text-destructive","data-testid":`cron-run-error-${i.name}`,role:"alert",children:h.message},void 0,!1),(0,t.jsxDEV)(G,{confirmLabel:n("Run now?"),disabled:h.kind==="running",onConfirm:f(()=>{V(a(i.name))},"onConfirm"),testId:`cron-run-${i.name}`,children:h.kind==="running"?n("Running\u2026"):n("Run now")},void 0,!1)]},void 0,!0)},void 0,!1)]},`${i.cron}:${i.name}`,!0)})},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1)]},void 0,!0)},"CronTriggersPanel"),he=f(s=>Number.isFinite(s)?j(s,"\u2014"):"\u2014","formatScheduledFor"),ve=f(s=>{let e=(0,Z.c)(34),c;e[0]!==s?(c=s===void 0?{}:s,e[0]=s,e[1]=c):c=e[1];let{loadJobs:n,removeJob:m,retryJob:r}=c,o=P(),l=q(),k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=["lunora-dead-jobs"],e[2]=k):k=e[2];let v;e[3]!==o||e[4]!==n?(v=f(async()=>(await(n??(()=>o.listDeadJobs()))()).toSorted(me),"t3"),e[3]=o,e[4]=n,e[5]=v):v=e[5];let a=Q(k,v),i=a.data,[h,S]=(0,z.useState)(void 0),C=a.error??h,g=n===void 0,T;e[6]!==o||e[7]!==g||e[8]!==r?(T=r??(g?d=>o.retryDeadJob(d):void 0),e[6]=o,e[7]=g,e[8]=r,e[9]=T):T=e[9];let b=T,J;e[10]!==o||e[11]!==g||e[12]!==m?(J=m??(g?d=>o.removeDeadJob(d):void 0),e[10]=o,e[11]=g,e[12]=m,e[13]=J):J=e[13];let y=J,w;e[14]!==a?(w=f(()=>{a.refetch()},"t6"),e[14]=a,e[15]=w):w=e[15],U(w,!0);let $;e[16]!==a?($=f(async d=>{S(void 0);try{await d,a.refetch()}catch(O){S(Y(O))}},"t7"),e[16]=a,e[17]=$):$=e[17];let I=$,E=b!==void 0||y!==void 0,L;e[18]!==C?(L=C!==void 0&&(0,t.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"dlq-error",role:"alert",children:C},void 0,!1),e[18]=C,e[19]=L):L=e[19];let N;e[20]!==i?.length||e[21]!==l?(N=i?.length===0&&(0,t.jsxDEV)(R,{description:l("Jobs that exhaust their retry budget are parked here instead of being dropped."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsxDEV)("path",{d:"M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14"},void 0,!1)},void 0,!1),testId:"dlq-empty",title:l("No dead-letter jobs.")},void 0,!1),e[20]=i?.length,e[21]=l,e[22]=N):N=e[22];let B;e[23]!==I||e[24]!==E||e[25]!==i||e[26]!==y||e[27]!==b||e[28]!==l?(B=i!==void 0&&i.length>0&&(0,t.jsxDEV)(A,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(D,{className:"px-0",children:(0,t.jsxDEV)(W,{"data-testid":"dlq-table",children:[(0,t.jsxDEV)(H,{children:(0,t.jsxDEV)(F,{children:[(0,t.jsxDEV)(p,{children:l("function")},void 0,!1),(0,t.jsxDEV)(p,{children:l("attempts")},void 0,!1),(0,t.jsxDEV)(p,{children:l("last tried")},void 0,!1),(0,t.jsxDEV)(p,{children:l("pool")},void 0,!1),(0,t.jsxDEV)(p,{children:l("shard")},void 0,!1),(0,t.jsxDEV)(p,{children:l("id")},void 0,!1),E&&(0,t.jsxDEV)(p,{"aria-label":l("Actions")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(K,{children:i.map(d=>(0,t.jsxDEV)(F,{"data-testid":`dlq-row-${d.id}`,children:[(0,t.jsxDEV)(x,{className:"font-mono text-xs",children:d.functionPath},void 0,!1),(0,t.jsxDEV)(x,{className:"tabular-nums",children:d.attempts??0},void 0,!1),(0,t.jsxDEV)(x,{className:"text-muted-foreground tabular-nums",children:he(d.scheduledFor)},void 0,!1),(0,t.jsxDEV)(x,{className:"font-mono text-xs",children:d.pool??""},void 0,!1),(0,t.jsxDEV)(x,{children:d.shardKey??""},void 0,!1),(0,t.jsxDEV)(x,{className:"font-mono text-xs",children:d.id},void 0,!1),E&&(0,t.jsxDEV)(x,{className:"text-right",children:(0,t.jsxDEV)("div",{className:"flex justify-end gap-1.5",children:[b!==void 0&&(0,t.jsxDEV)(te,{"data-testid":`dlq-retry-${d.id}`,onClick:f(()=>{V(I(b(d.id)))},"onClick"),size:"sm",type:"button",variant:"outline",children:l("Retry")},void 0,!1),y!==void 0&&(0,t.jsxDEV)(G,{confirmLabel:l("Drop job?"),onConfirm:f(()=>{V(I(y(d.id)))},"onConfirm"),testId:`dlq-remove-${d.id}`,children:l("Drop")},void 0,!1)]},void 0,!0)},void 0,!1)]},d.id,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),e[23]=I,e[24]=E,e[25]=i,e[26]=y,e[27]=b,e[28]=l,e[29]=B):B=e[29];let _;return e[30]!==B||e[31]!==L||e[32]!==N?(_=(0,t.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-dead-letter",children:[L,N,B]},void 0,!0),e[30]=B,e[31]=L,e[32]=N,e[33]=_):_=e[33],_},"DeadLetterJobs");function me(s,e){return(e.attempts??0)-(s.attempts??0)}f(me,"_temp$1");var le=f(s=>{let e=(0,Z.c)(8),{label:c,testId:n,value:m}=s,r;e[0]!==c?(r=(0,t.jsxDEV)("span",{className:"text-xs text-muted-foreground",children:c},void 0,!1),e[0]=c,e[1]=r):r=e[1];let o;e[2]!==n||e[3]!==m?(o=(0,t.jsxDEV)("span",{className:"text-2xl font-semibold tabular-nums","data-testid":n,children:m},void 0,!1),e[2]=n,e[3]=m,e[4]=o):o=e[4];let l;return e[5]!==r||e[6]!==o?(l=(0,t.jsxDEV)(A,{className:"flex-1 py-0",children:(0,t.jsxDEV)(D,{className:"flex flex-col gap-1 p-4",children:[r,o]},void 0,!0)},void 0,!1),e[5]=r,e[6]=o,e[7]=l):l=e[7],l},"StatTile"),pe=f(s=>{let e=(0,Z.c)(25),c;e[0]!==s?(c=s===void 0?{}:s,e[0]=s,e[1]=c):c=e[1];let{loadStatus:n}=c,m=P(),r=q(),o=n===void 0,l;e[2]!==o?(l=["lunora-scheduler-status",o],e[2]=o,e[3]=l):l=e[3];let k;e[4]!==m||e[5]!==n?(k=f(async()=>{let J=await(n??(()=>m.schedulerStatus()))();return{...J,pools:J.pools.toSorted(xe)}},"t4"),e[4]=m,e[5]=n,e[6]=k):k=e[6];let v=Q(l,k),{data:a,error:i}=v,h;e[7]!==v?(h=f(()=>{v.refetch()},"t5"),e[7]=v,e[8]=h):h=e[8],U(h,!0);let S;e[9]!==i?(S=i!==null&&(0,t.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"pools-error",role:"alert",children:i},void 0,!1),e[9]=i,e[10]=S):S=e[10];let C;e[11]!==a||e[12]!==r?(C=a!==void 0&&(0,t.jsxDEV)("div",{className:"flex gap-3","data-testid":"pools-totals",children:[(0,t.jsxDEV)(le,{label:r("backlog"),testId:"pools-backlog",value:a.backlog},void 0,!1),(0,t.jsxDEV)(le,{label:r("in flight"),testId:"pools-inflight",value:a.inFlight},void 0,!1),(0,t.jsxDEV)(le,{label:r("pools"),testId:"pools-count",value:a.pools.length},void 0,!1)]},void 0,!0),e[11]=a,e[12]=r,e[13]=C):C=e[13];let g;e[14]!==a?.pools.length||e[15]!==r?(g=a?.pools.length===0&&(0,t.jsxDEV)(R,{description:r("Pools created with createWorkpool appear here once they have activity."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsxDEV)("path",{d:"M4 7h16M4 12h16M4 17h16"},void 0,!1)},void 0,!1),testId:"pools-empty",title:r("No workpools.")},void 0,!1),e[14]=a?.pools.length,e[15]=r,e[16]=g):g=e[16];let T;e[17]!==a||e[18]!==r?(T=a!==void 0&&a.pools.length>0&&(0,t.jsxDEV)(A,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(D,{className:"px-0",children:(0,t.jsxDEV)(W,{"data-testid":"pools-table",children:[(0,t.jsxDEV)(H,{children:(0,t.jsxDEV)(F,{children:[(0,t.jsxDEV)(p,{children:r("pool")},void 0,!1),(0,t.jsxDEV)(p,{children:r("queued")},void 0,!1),(0,t.jsxDEV)(p,{children:r("in flight")},void 0,!1),(0,t.jsxDEV)(p,{children:r("max concurrency")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(K,{children:a.pools.map(ge)},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),e[17]=a,e[18]=r,e[19]=T):T=e[19];let b;return e[20]!==S||e[21]!==C||e[22]!==g||e[23]!==T?(b=(0,t.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-scheduler-pools",children:[S,C,g,T]},void 0,!0),e[20]=S,e[21]=C,e[22]=g,e[23]=T,e[24]=b):b=e[24],b},"SchedulerPoolsPanel");function xe(s,e){return e.queued-s.queued}f(xe,"_temp");function ge(s){return(0,t.jsxDEV)(F,{"data-testid":`pools-row-${s.name}`,children:[(0,t.jsxDEV)(x,{className:"font-mono text-xs",children:s.name},void 0,!1),(0,t.jsxDEV)(x,{className:"tabular-nums",children:s.queued},void 0,!1),(0,t.jsxDEV)(x,{className:"tabular-nums",children:[s.inFlight," / ",s.maxConcurrency]},void 0,!0),(0,t.jsxDEV)(x,{className:"tabular-nums",children:s.maxConcurrency},void 0,!1)]},s.name,!0)}f(ge,"_temp2");var be=["jobs","dead","pools","cron"],We=f(s=>{let e=(0,Z.c)(41),c;e[0]!==s?(c=s===void 0?{}:s,e[0]=s,e[1]=c):c=e[1];let{loadCronJobs:n,scheduledCancel:m,scheduledLoad:r}=c,o=q(),[l,k]=(0,z.useState)("jobs"),v;e[2]!==o?(v=o("Cron triggers"),e[2]=o,e[3]=v):v=e[3];let a;e[4]!==o?(a=o("Dead letter"),e[4]=o,e[5]=a):a=e[5];let i;e[6]!==o?(i=o("Scheduled jobs"),e[6]=o,e[7]=i):i=e[7];let h;e[8]!==o?(h=o("Pools"),e[8]=o,e[9]=h):h=e[9];let S;e[10]!==v||e[11]!==a||e[12]!==i||e[13]!==h?(S={cron:v,dead:a,jobs:i,pools:h},e[10]=v,e[11]=a,e[12]=i,e[13]=h,e[14]=S):S=e[14];let C=S,g;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=f(N=>{k(N.currentTarget.dataset.view)},"t7"),e[15]=g):g=e[15];let T=g,b;e[16]!==o?(b=o("Schedule view"),e[16]=o,e[17]=b):b=e[17];let J;e[18]!==l||e[19]!==C?(J=be.map(N=>(0,t.jsxDEV)(te,{"aria-selected":l===N,"data-testid":`schedule-view-${N}`,"data-view":N,onClick:T,role:"tab",size:"sm",type:"button",variant:l===N?"default":"outline",children:C[N]},N,!1)),e[18]=l,e[19]=C,e[20]=J):J=e[20];let y;e[21]!==b||e[22]!==J?(y=(0,t.jsxDEV)("div",{"aria-label":b,className:"flex gap-1.5","data-testid":"schedule-view-toggle",role:"tablist",children:J},void 0,!1),e[21]=b,e[22]=J,e[23]=y):y=e[23];let w;e[24]!==m||e[25]!==r||e[26]!==l?(w=l==="jobs"&&(0,t.jsxDEV)(de,{cancelJob:m,loadJobs:r},void 0,!1),e[24]=m,e[25]=r,e[26]=l,e[27]=w):w=e[27];let $;e[28]!==l?($=l==="dead"&&(0,t.jsxDEV)(ve,{},void 0,!1),e[28]=l,e[29]=$):$=e[29];let I;e[30]!==l?(I=l==="pools"&&(0,t.jsxDEV)(pe,{},void 0,!1),e[30]=l,e[31]=I):I=e[31];let E;e[32]!==n||e[33]!==l?(E=l==="cron"&&(0,t.jsxDEV)(ue,{loadCronJobs:n},void 0,!1),e[32]=n,e[33]=l,e[34]=E):E=e[34];let L;return e[35]!==y||e[36]!==w||e[37]!==$||e[38]!==I||e[39]!==E?(L=(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-schedule",children:[y,w,$,I,E]},void 0,!0),e[35]=y,e[36]=w,e[37]=$,e[38]=I,e[39]=E,e[40]=L):L=e[40],L},"SchedulePanel");export{We as SchedulePanel};
1
+ import{a as U}from"./chunk-J6J54MBP.js";import{a as G}from"./chunk-EEWKIQUE.js";import{a as Q}from"./chunk-ZQQ3MFEQ.js";import{a as W,b as H,c as K,d as F,e as p,f as x}from"./chunk-GTM65MVX.js";import{a as A,e as D}from"./chunk-SEU5V7I6.js";import{c as te}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import{b as ee}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as P}from"./chunk-LOYE7OU2.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as R}from"./chunk-TAD43CG5.js";import{d as q,h as Y,l as V,p as j}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as f,e as M,f as oe,g as se,h as re}from"./chunk-RRCPZMC2.js";var Z=M(se(),1),z=M(oe(),1);var t=M(re(),1);var ae=M(se(),1);var X=M(oe(),1);var u=M(re(),1);var ce=f(s=>Number.isFinite(s)?j(s,"\u2014"):"\u2014","formatScheduledFor"),ie=f(s=>s.toSorted((e,c)=>e.scheduledFor-c.scheduledFor),"sortByDue"),de=f(s=>{let e=(0,ae.c)(33),c;e[0]!==s?(c=s===void 0?{}:s,e[0]=s,e[1]=c):c=e[1];let{cancelJob:n,loadJobs:m}=c,r=P(),o=q(),l=m===void 0,k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=["lunora-scheduled-jobs"],e[2]=k):k=e[2];let v;e[3]!==r||e[4]!==m?(v=f(async()=>{let d=await(m??(()=>r.listScheduledJobs()))();return ie(d)},"t3"),e[3]=r,e[4]=m,e[5]=v):v=e[5];let a=Q(k,v),[i,h]=(0,X.useState)(void 0),[S,C]=(0,X.useState)(void 0),g,T;e[6]!==r||e[7]!==l?(g=f(()=>{if(l)return r.subscribeScheduledJobs(d=>{C(void 0),h(ie(d))})},"t4"),T=[l,r],e[6]=r,e[7]=l,e[8]=g,e[9]=T):(g=e[8],T=e[9]),(0,X.useEffect)(g,T);let b;e[10]!==a?(b=f(()=>{a.refetch()},"t6"),e[10]=a,e[11]=b):b=e[11],U(b,!l);let J;e:{if(n!==void 0){J=n;break e}let d;e[12]!==r||e[13]!==m?(d=m===void 0?O=>r.cancelScheduledJob(O):void 0,e[12]=r,e[13]=m,e[14]=d):d=e[14],J=d}let y=J,w=i??a.data,$=S??a.error,I;e[15]!==y||e[16]!==a||e[17]!==l?(I=f(async d=>{if(y!==void 0){C(void 0);try{await y(d),l||a.refetch()}catch(O){C(Y(O))}}},"t8"),e[15]=y,e[16]=a,e[17]=l,e[18]=I):I=e[18];let E=I,L;e[19]!==$?(L=$!==null&&(0,u.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"sj-error",role:"alert",children:$},void 0,!1),e[19]=$,e[20]=L):L=e[20];let N;e[21]!==w?.length||e[22]!==o?(N=w?.length===0&&(0,u.jsxDEV)(R,{description:o("Jobs queued with runAfter / runAt will appear here."),icon:(0,u.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[(0,u.jsxDEV)("circle",{cx:"12",cy:"12",r:"9"},void 0,!1),(0,u.jsxDEV)("path",{d:"M12 7.5V12l4 2"},void 0,!1)]},void 0,!0),testId:"sj-empty",title:o("No scheduled jobs.")},void 0,!1),e[21]=w?.length,e[22]=o,e[23]=N):N=e[23];let B;e[24]!==E||e[25]!==y||e[26]!==w||e[27]!==o?(B=w!==void 0&&w.length>0&&(0,u.jsxDEV)(A,{className:"overflow-hidden py-0",children:(0,u.jsxDEV)(D,{className:"px-0",children:(0,u.jsxDEV)(W,{"data-testid":"sj-table",children:[(0,u.jsxDEV)(H,{children:(0,u.jsxDEV)(F,{children:[(0,u.jsxDEV)(p,{children:o("function")},void 0,!1),(0,u.jsxDEV)(p,{children:o("scheduled for")},void 0,!1),(0,u.jsxDEV)(p,{children:o("pool")},void 0,!1),(0,u.jsxDEV)(p,{children:o("attempts")},void 0,!1),(0,u.jsxDEV)(p,{children:o("shard")},void 0,!1),(0,u.jsxDEV)(p,{children:o("id")},void 0,!1),y!==void 0&&(0,u.jsxDEV)(p,{"aria-label":o("Actions")},void 0,!1)]},void 0,!0)},void 0,!1),(0,u.jsxDEV)(K,{children:w.map(d=>(0,u.jsxDEV)(F,{"data-testid":`sj-row-${d.id}`,children:[(0,u.jsxDEV)(x,{className:"font-mono text-xs",children:d.functionPath},void 0,!1),(0,u.jsxDEV)(x,{className:"text-muted-foreground tabular-nums",children:ce(d.scheduledFor)},void 0,!1),(0,u.jsxDEV)(x,{className:"font-mono text-xs",children:d.pool??""},void 0,!1),(0,u.jsxDEV)(x,{className:"tabular-nums",children:d.attempts??0},void 0,!1),(0,u.jsxDEV)(x,{children:d.shardKey??""},void 0,!1),(0,u.jsxDEV)(x,{className:"font-mono text-xs",children:d.id},void 0,!1),y!==void 0&&(0,u.jsxDEV)(x,{className:"text-right",children:(0,u.jsxDEV)(G,{confirmLabel:o("Cancel job?"),onConfirm:f(()=>{V(E(d.id))},"onConfirm"),testId:`sj-cancel-${d.id}`,children:o("Cancel")},void 0,!1)},void 0,!1)]},d.id,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),e[24]=E,e[25]=y,e[26]=w,e[27]=o,e[28]=B):B=e[28];let _;return e[29]!==N||e[30]!==B||e[31]!==L?(_=(0,u.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-scheduled-jobs",children:[L,N,B]},void 0,!0),e[29]=N,e[30]=B,e[31]=L,e[32]=_):_=e[32],_},"ScheduledJobs");var fe={kind:"idle"},ue=f(({loadCronJobs:s,runCronJob:e}={})=>{let c=P(),n=q(),[m,r]=(0,z.useState)({}),o=Q(["lunora-cron-jobs",s?"custom":"default"],()=>(s??(()=>c.getCronJobs()))()),{data:l,error:k}=o,v=(0,z.useMemo)(()=>e!==void 0?e:s===void 0?i=>c.runCronJob(i):void 0,[c,s,e]),a=f(async i=>{if(v!==void 0){r(h=>({...h,[i]:{kind:"running"}}));try{await v(i),r(h=>({...h,[i]:{kind:"ok"}})),o.refetch()}catch(h){r(S=>({...S,[i]:{kind:"error",message:Y(h)}}))}}},"run");return(0,t.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-cron-triggers",children:[k!==null&&(0,t.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"cron-error",role:"alert",children:k},void 0,!1),l?.length===0&&(0,t.jsxDEV)(R,{description:n("Triggers declared with the cronJobs() builder appear here."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[(0,t.jsxDEV)("circle",{cx:"12",cy:"12",r:"9"},void 0,!1),(0,t.jsxDEV)("path",{d:"M12 7.5V12l4 2"},void 0,!1)]},void 0,!0),testId:"cron-empty",title:n("No cron triggers.")},void 0,!1),l!==void 0&&l.length>0&&(0,t.jsxDEV)(A,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(D,{className:"px-0",children:(0,t.jsxDEV)(W,{"data-testid":"cron-table",children:[(0,t.jsxDEV)(H,{children:(0,t.jsxDEV)(F,{children:[(0,t.jsxDEV)(p,{children:n("name")},void 0,!1),(0,t.jsxDEV)(p,{children:n("schedule")},void 0,!1),(0,t.jsxDEV)(p,{children:n("target")},void 0,!1),(0,t.jsxDEV)(p,{children:n("shard")},void 0,!1),v!==void 0&&(0,t.jsxDEV)(p,{"aria-label":n("Actions")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(K,{children:l.map(i=>{let h=m[i.name]??fe;return(0,t.jsxDEV)(F,{"data-testid":`cron-row-${i.name}`,children:[(0,t.jsxDEV)(x,{children:i.name},void 0,!1),(0,t.jsxDEV)(x,{className:"font-mono text-xs tabular-nums",children:i.cron},void 0,!1),(0,t.jsxDEV)(x,{children:(0,t.jsxDEV)("span",{className:"flex items-center gap-2",children:[i.workflow===void 0?(0,t.jsxDEV)(ee,{variant:"outline",children:n("function")},void 0,!1):(0,t.jsxDEV)(ee,{variant:"secondary",children:n("workflow")},void 0,!1),(0,t.jsxDEV)("span",{className:"font-mono text-xs",children:i.workflow??i.functionPath},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(x,{children:i.shardKey??""},void 0,!1),v!==void 0&&(0,t.jsxDEV)(x,{className:"text-right",children:(0,t.jsxDEV)("span",{className:"flex items-center justify-end gap-2",children:[h.kind==="ok"&&(0,t.jsxDEV)("span",{className:"text-xs text-muted-foreground","data-testid":`cron-ran-${i.name}`,children:n("ran")},void 0,!1),h.kind==="error"&&(0,t.jsxDEV)("span",{className:"text-xs text-destructive","data-testid":`cron-run-error-${i.name}`,role:"alert",children:h.message},void 0,!1),(0,t.jsxDEV)(G,{confirmLabel:n("Run now?"),disabled:h.kind==="running",onConfirm:f(()=>{V(a(i.name))},"onConfirm"),testId:`cron-run-${i.name}`,children:h.kind==="running"?n("Running\u2026"):n("Run now")},void 0,!1)]},void 0,!0)},void 0,!1)]},`${i.cron}:${i.name}`,!0)})},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1)]},void 0,!0)},"CronTriggersPanel"),he=f(s=>Number.isFinite(s)?j(s,"\u2014"):"\u2014","formatScheduledFor"),ve=f(s=>{let e=(0,Z.c)(34),c;e[0]!==s?(c=s===void 0?{}:s,e[0]=s,e[1]=c):c=e[1];let{loadJobs:n,removeJob:m,retryJob:r}=c,o=P(),l=q(),k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=["lunora-dead-jobs"],e[2]=k):k=e[2];let v;e[3]!==o||e[4]!==n?(v=f(async()=>(await(n??(()=>o.listDeadJobs()))()).toSorted(me),"t3"),e[3]=o,e[4]=n,e[5]=v):v=e[5];let a=Q(k,v),i=a.data,[h,S]=(0,z.useState)(void 0),C=a.error??h,g=n===void 0,T;e[6]!==o||e[7]!==g||e[8]!==r?(T=r??(g?d=>o.retryDeadJob(d):void 0),e[6]=o,e[7]=g,e[8]=r,e[9]=T):T=e[9];let b=T,J;e[10]!==o||e[11]!==g||e[12]!==m?(J=m??(g?d=>o.removeDeadJob(d):void 0),e[10]=o,e[11]=g,e[12]=m,e[13]=J):J=e[13];let y=J,w;e[14]!==a?(w=f(()=>{a.refetch()},"t6"),e[14]=a,e[15]=w):w=e[15],U(w,!0);let $;e[16]!==a?($=f(async d=>{S(void 0);try{await d,a.refetch()}catch(O){S(Y(O))}},"t7"),e[16]=a,e[17]=$):$=e[17];let I=$,E=b!==void 0||y!==void 0,L;e[18]!==C?(L=C!==void 0&&(0,t.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"dlq-error",role:"alert",children:C},void 0,!1),e[18]=C,e[19]=L):L=e[19];let N;e[20]!==i?.length||e[21]!==l?(N=i?.length===0&&(0,t.jsxDEV)(R,{description:l("Jobs that exhaust their retry budget are parked here instead of being dropped."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsxDEV)("path",{d:"M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14"},void 0,!1)},void 0,!1),testId:"dlq-empty",title:l("No dead-letter jobs.")},void 0,!1),e[20]=i?.length,e[21]=l,e[22]=N):N=e[22];let B;e[23]!==I||e[24]!==E||e[25]!==i||e[26]!==y||e[27]!==b||e[28]!==l?(B=i!==void 0&&i.length>0&&(0,t.jsxDEV)(A,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(D,{className:"px-0",children:(0,t.jsxDEV)(W,{"data-testid":"dlq-table",children:[(0,t.jsxDEV)(H,{children:(0,t.jsxDEV)(F,{children:[(0,t.jsxDEV)(p,{children:l("function")},void 0,!1),(0,t.jsxDEV)(p,{children:l("attempts")},void 0,!1),(0,t.jsxDEV)(p,{children:l("last tried")},void 0,!1),(0,t.jsxDEV)(p,{children:l("pool")},void 0,!1),(0,t.jsxDEV)(p,{children:l("shard")},void 0,!1),(0,t.jsxDEV)(p,{children:l("id")},void 0,!1),E&&(0,t.jsxDEV)(p,{"aria-label":l("Actions")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(K,{children:i.map(d=>(0,t.jsxDEV)(F,{"data-testid":`dlq-row-${d.id}`,children:[(0,t.jsxDEV)(x,{className:"font-mono text-xs",children:d.functionPath},void 0,!1),(0,t.jsxDEV)(x,{className:"tabular-nums",children:d.attempts??0},void 0,!1),(0,t.jsxDEV)(x,{className:"text-muted-foreground tabular-nums",children:he(d.scheduledFor)},void 0,!1),(0,t.jsxDEV)(x,{className:"font-mono text-xs",children:d.pool??""},void 0,!1),(0,t.jsxDEV)(x,{children:d.shardKey??""},void 0,!1),(0,t.jsxDEV)(x,{className:"font-mono text-xs",children:d.id},void 0,!1),E&&(0,t.jsxDEV)(x,{className:"text-right",children:(0,t.jsxDEV)("div",{className:"flex justify-end gap-1.5",children:[b!==void 0&&(0,t.jsxDEV)(te,{"data-testid":`dlq-retry-${d.id}`,onClick:f(()=>{V(I(b(d.id)))},"onClick"),size:"sm",type:"button",variant:"outline",children:l("Retry")},void 0,!1),y!==void 0&&(0,t.jsxDEV)(G,{confirmLabel:l("Drop job?"),onConfirm:f(()=>{V(I(y(d.id)))},"onConfirm"),testId:`dlq-remove-${d.id}`,children:l("Drop")},void 0,!1)]},void 0,!0)},void 0,!1)]},d.id,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),e[23]=I,e[24]=E,e[25]=i,e[26]=y,e[27]=b,e[28]=l,e[29]=B):B=e[29];let _;return e[30]!==B||e[31]!==L||e[32]!==N?(_=(0,t.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-dead-letter",children:[L,N,B]},void 0,!0),e[30]=B,e[31]=L,e[32]=N,e[33]=_):_=e[33],_},"DeadLetterJobs");function me(s,e){return(e.attempts??0)-(s.attempts??0)}f(me,"_temp$1");var le=f(s=>{let e=(0,Z.c)(8),{label:c,testId:n,value:m}=s,r;e[0]!==c?(r=(0,t.jsxDEV)("span",{className:"text-xs text-muted-foreground",children:c},void 0,!1),e[0]=c,e[1]=r):r=e[1];let o;e[2]!==n||e[3]!==m?(o=(0,t.jsxDEV)("span",{className:"text-2xl font-semibold tabular-nums","data-testid":n,children:m},void 0,!1),e[2]=n,e[3]=m,e[4]=o):o=e[4];let l;return e[5]!==r||e[6]!==o?(l=(0,t.jsxDEV)(A,{className:"flex-1 py-0",children:(0,t.jsxDEV)(D,{className:"flex flex-col gap-1 p-4",children:[r,o]},void 0,!0)},void 0,!1),e[5]=r,e[6]=o,e[7]=l):l=e[7],l},"StatTile"),pe=f(s=>{let e=(0,Z.c)(25),c;e[0]!==s?(c=s===void 0?{}:s,e[0]=s,e[1]=c):c=e[1];let{loadStatus:n}=c,m=P(),r=q(),o=n===void 0,l;e[2]!==o?(l=["lunora-scheduler-status",o],e[2]=o,e[3]=l):l=e[3];let k;e[4]!==m||e[5]!==n?(k=f(async()=>{let J=await(n??(()=>m.schedulerStatus()))();return{...J,pools:J.pools.toSorted(xe)}},"t4"),e[4]=m,e[5]=n,e[6]=k):k=e[6];let v=Q(l,k),{data:a,error:i}=v,h;e[7]!==v?(h=f(()=>{v.refetch()},"t5"),e[7]=v,e[8]=h):h=e[8],U(h,!0);let S;e[9]!==i?(S=i!==null&&(0,t.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"pools-error",role:"alert",children:i},void 0,!1),e[9]=i,e[10]=S):S=e[10];let C;e[11]!==a||e[12]!==r?(C=a!==void 0&&(0,t.jsxDEV)("div",{className:"flex gap-3","data-testid":"pools-totals",children:[(0,t.jsxDEV)(le,{label:r("backlog"),testId:"pools-backlog",value:a.backlog},void 0,!1),(0,t.jsxDEV)(le,{label:r("in flight"),testId:"pools-inflight",value:a.inFlight},void 0,!1),(0,t.jsxDEV)(le,{label:r("pools"),testId:"pools-count",value:a.pools.length},void 0,!1)]},void 0,!0),e[11]=a,e[12]=r,e[13]=C):C=e[13];let g;e[14]!==a?.pools.length||e[15]!==r?(g=a?.pools.length===0&&(0,t.jsxDEV)(R,{description:r("Pools created with createWorkpool appear here once they have activity."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsxDEV)("path",{d:"M4 7h16M4 12h16M4 17h16"},void 0,!1)},void 0,!1),testId:"pools-empty",title:r("No workpools.")},void 0,!1),e[14]=a?.pools.length,e[15]=r,e[16]=g):g=e[16];let T;e[17]!==a||e[18]!==r?(T=a!==void 0&&a.pools.length>0&&(0,t.jsxDEV)(A,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(D,{className:"px-0",children:(0,t.jsxDEV)(W,{"data-testid":"pools-table",children:[(0,t.jsxDEV)(H,{children:(0,t.jsxDEV)(F,{children:[(0,t.jsxDEV)(p,{children:r("pool")},void 0,!1),(0,t.jsxDEV)(p,{children:r("queued")},void 0,!1),(0,t.jsxDEV)(p,{children:r("in flight")},void 0,!1),(0,t.jsxDEV)(p,{children:r("max concurrency")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(K,{children:a.pools.map(ge)},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),e[17]=a,e[18]=r,e[19]=T):T=e[19];let b;return e[20]!==S||e[21]!==C||e[22]!==g||e[23]!==T?(b=(0,t.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-scheduler-pools",children:[S,C,g,T]},void 0,!0),e[20]=S,e[21]=C,e[22]=g,e[23]=T,e[24]=b):b=e[24],b},"SchedulerPoolsPanel");function xe(s,e){return e.queued-s.queued}f(xe,"_temp");function ge(s){return(0,t.jsxDEV)(F,{"data-testid":`pools-row-${s.name}`,children:[(0,t.jsxDEV)(x,{className:"font-mono text-xs",children:s.name},void 0,!1),(0,t.jsxDEV)(x,{className:"tabular-nums",children:s.queued},void 0,!1),(0,t.jsxDEV)(x,{className:"tabular-nums",children:[s.inFlight," / ",s.maxConcurrency]},void 0,!0),(0,t.jsxDEV)(x,{className:"tabular-nums",children:s.maxConcurrency},void 0,!1)]},s.name,!0)}f(ge,"_temp2");var be=["jobs","dead","pools","cron"],We=f(s=>{let e=(0,Z.c)(41),c;e[0]!==s?(c=s===void 0?{}:s,e[0]=s,e[1]=c):c=e[1];let{loadCronJobs:n,scheduledCancel:m,scheduledLoad:r}=c,o=q(),[l,k]=(0,z.useState)("jobs"),v;e[2]!==o?(v=o("Cron triggers"),e[2]=o,e[3]=v):v=e[3];let a;e[4]!==o?(a=o("Dead letter"),e[4]=o,e[5]=a):a=e[5];let i;e[6]!==o?(i=o("Scheduled jobs"),e[6]=o,e[7]=i):i=e[7];let h;e[8]!==o?(h=o("Pools"),e[8]=o,e[9]=h):h=e[9];let S;e[10]!==v||e[11]!==a||e[12]!==i||e[13]!==h?(S={cron:v,dead:a,jobs:i,pools:h},e[10]=v,e[11]=a,e[12]=i,e[13]=h,e[14]=S):S=e[14];let C=S,g;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=f(N=>{k(N.currentTarget.dataset.view)},"t7"),e[15]=g):g=e[15];let T=g,b;e[16]!==o?(b=o("Schedule view"),e[16]=o,e[17]=b):b=e[17];let J;e[18]!==l||e[19]!==C?(J=be.map(N=>(0,t.jsxDEV)(te,{"aria-selected":l===N,"data-testid":`schedule-view-${N}`,"data-view":N,onClick:T,role:"tab",size:"sm",type:"button",variant:l===N?"default":"outline",children:C[N]},N,!1)),e[18]=l,e[19]=C,e[20]=J):J=e[20];let y;e[21]!==b||e[22]!==J?(y=(0,t.jsxDEV)("div",{"aria-label":b,className:"flex gap-1.5","data-testid":"schedule-view-toggle",role:"tablist",children:J},void 0,!1),e[21]=b,e[22]=J,e[23]=y):y=e[23];let w;e[24]!==m||e[25]!==r||e[26]!==l?(w=l==="jobs"&&(0,t.jsxDEV)(de,{cancelJob:m,loadJobs:r},void 0,!1),e[24]=m,e[25]=r,e[26]=l,e[27]=w):w=e[27];let $;e[28]!==l?($=l==="dead"&&(0,t.jsxDEV)(ve,{},void 0,!1),e[28]=l,e[29]=$):$=e[29];let I;e[30]!==l?(I=l==="pools"&&(0,t.jsxDEV)(pe,{},void 0,!1),e[30]=l,e[31]=I):I=e[31];let E;e[32]!==n||e[33]!==l?(E=l==="cron"&&(0,t.jsxDEV)(ue,{loadCronJobs:n},void 0,!1),e[32]=n,e[33]=l,e[34]=E):E=e[34];let L;return e[35]!==y||e[36]!==w||e[37]!==$||e[38]!==I||e[39]!==E?(L=(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-schedule",children:[y,w,$,I,E]},void 0,!0),e[35]=y,e[36]=w,e[37]=$,e[38]=I,e[39]=E,e[40]=L):L=e[40],L},"SchedulePanel");export{We as SchedulePanel};
@@ -1 +1 @@
1
- import{a as se}from"./chunk-SDQE2IUJ.js";import"./chunk-X4QFAAZ5.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-KEGAWN6Y.js";import{a as te}from"./chunk-XNJNSCLM.js";import{a as z,b as V,c as P,e as D}from"./chunk-SEU5V7I6.js";import{d as X,f as ee}from"./chunk-2MLA6WFH.js";import"./chunk-HV7G6DFP.js";import{c as I}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-CKSHCYGC.js";import{a as J}from"./chunk-G7ZBM54M.js";import{f as Q}from"./chunk-L2YBC2BV.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as U}from"./chunk-TAD43CG5.js";import{d as O,f as H,g as Y,h as G,l as Z}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as k,e as j,f as ie,g as le,h as oe}from"./chunk-RRCPZMC2.js";var W=j(le(),1),T=j(ie(),1);var o=j(oe(),1);var de=H(J.runSql),ae=k(($,e)=>{let s=Q(),[f,t]=(0,T.useState)(void 0),[i,d]=(0,T.useState)(void 0),[l,c]=(0,T.useState)(!0),q=(0,T.useCallback)(async a=>{c(!0);try{let x=await s.query(de,{sql:$},Y(e));a.cancelled||(t(x),d(void 0))}catch(x){a.cancelled||(t(void 0),d(G(x)))}finally{a.cancelled||c(!1)}},[s,$,e]);return(0,T.useEffect)(()=>{let a={cancelled:!1};return Z(q(a)),()=>{a.cancelled=!0}},[q]),{error:i,loading:l,result:f}},"useRunSql"),re="lunora-studio-dashboards",B={shardKey:"",sql:"",title:""},ne=k($=>{let e=(0,W.c)(54),{onEdit:s,onRemove:f,widget:t}=$,i=O(),{error:d,loading:l,result:c}=ae(t.sql,t.shardKey??""),q;e[0]!==s||e[1]!==t.id?(q=k(()=>{s(t.id)},"t1"),e[0]=s,e[1]=t.id,e[2]=q):q=e[2];let a=q,x;e[3]!==f||e[4]!==t.id?(x=k(()=>{f(t.id)},"t2"),e[3]=f,e[4]=t.id,e[5]=x):x=e[5];let K=x,M=`dashboards-widget-${t.id}`,S;e[6]!==t.title?(S=(0,o.jsxDEV)(P,{className:"min-w-0 truncate",title:t.title,children:t.title},void 0,!1),e[6]=t.title,e[7]=S):S=e[7];let L;e[8]!==i?(L=i("Edit widget"),e[8]=i,e[9]=L):L=e[9];let R=`dashboards-widget-edit-${t.id}`,A;e[10]!==i?(A=i("Edit widget"),e[10]=i,e[11]=A):A=e[11];let w;e[12]===Symbol.for("react.memo_cache_sentinel")?(w=(0,o.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,o.jsxDEV)("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"},void 0,!1)},void 0,!1),e[12]=w):w=e[12];let C;e[13]!==a||e[14]!==L||e[15]!==R||e[16]!==A?(C=(0,o.jsxDEV)(I,{"aria-label":L,"data-testid":R,onClick:a,size:"icon-xs",title:A,type:"button",variant:"ghost",children:w},void 0,!1),e[13]=a,e[14]=L,e[15]=R,e[16]=A,e[17]=C):C=e[17];let b;e[18]!==i?(b=i("Remove widget"),e[18]=i,e[19]=b):b=e[19];let E=`dashboards-widget-remove-${t.id}`,m;e[20]!==i?(m=i("Remove widget"),e[20]=i,e[21]=m):m=e[21];let p;e[22]===Symbol.for("react.memo_cache_sentinel")?(p=(0,o.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,o.jsxDEV)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"},void 0,!1)},void 0,!1),e[22]=p):p=e[22];let u;e[23]!==K||e[24]!==b||e[25]!==E||e[26]!==m?(u=(0,o.jsxDEV)(I,{"aria-label":b,"data-testid":E,onClick:K,size:"icon-xs",title:m,type:"button",variant:"ghost",children:p},void 0,!1),e[23]=K,e[24]=b,e[25]=E,e[26]=m,e[27]=u):u=e[27];let h;e[28]!==u||e[29]!==C?(h=(0,o.jsxDEV)("div",{className:"flex shrink-0 items-center gap-1",children:[C,u]},void 0,!0),e[28]=u,e[29]=C,e[30]=h):h=e[30];let v;e[31]!==h||e[32]!==S?(v=(0,o.jsxDEV)(V,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[S,h]},void 0,!0),e[31]=h,e[32]=S,e[33]=v):v=e[33];let g;e[34]!==d||e[35]!==t.id?(g=d!==void 0&&(0,o.jsxDEV)(te,{className:"font-mono text-xs",testId:`dashboards-widget-error-${t.id}`,variant:"destructive",children:d},void 0,!1),e[34]=d,e[35]=t.id,e[36]=g):g=e[36];let N;e[37]!==d||e[38]!==l||e[39]!==c||e[40]!==i||e[41]!==t.id?(N=d===void 0&&l&&c===void 0&&(0,o.jsxDEV)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${t.id}`,children:i("Running\u2026")},void 0,!1),e[37]=d,e[38]=l,e[39]=c,e[40]=i,e[41]=t.id,e[42]=N):N=e[42];let r;e[43]!==d||e[44]!==c?(r=d===void 0&&c!==void 0&&(0,o.jsxDEV)(se,{result:c},void 0,!1),e[43]=d,e[44]=c,e[45]=r):r=e[45];let n;e[46]!==g||e[47]!==N||e[48]!==r?(n=(0,o.jsxDEV)(D,{className:"min-h-32 py-2",children:[g,N,r]},void 0,!0),e[46]=g,e[47]=N,e[48]=r,e[49]=n):n=e[49];let y;return e[50]!==v||e[51]!==n||e[52]!==M?(y=(0,o.jsxDEV)(z,{"data-testid":M,children:[v,n]},void 0,!0),e[50]=v,e[51]=n,e[52]=M,e[53]=y):y=e[53],y},"WidgetCard"),ce=k($=>{let e=(0,W.c)(58),{draft:s,editing:f,onCancel:t,onChange:i,onSubmit:d}=$,l=O(),c;e[0]!==s||e[1]!==i?(c=k(_=>{i({...s,title:_.target.value})},"t1"),e[0]=s,e[1]=i,e[2]=c):c=e[2];let q=c,a;e[3]!==s||e[4]!==i?(a=k(_=>{i({...s,sql:_.target.value})},"t2"),e[3]=s,e[4]=i,e[5]=a):a=e[5];let x=a,K;e[6]!==s||e[7]!==i?(K=k(_=>{i({...s,shardKey:_.target.value})},"t3"),e[6]=s,e[7]=i,e[8]=K):K=e[8];let M=K,S;e[9]!==d?(S=k(()=>{d()},"t4"),e[9]=d,e[10]=S):S=e[10];let L=S,R;e[11]!==s.sql||e[12]!==s.title?(R=s.title.trim()!==""&&s.sql.trim()!=="",e[11]=s.sql,e[12]=s.title,e[13]=R):R=e[13];let A=R,w;e[14]!==l?(w=l("Widget title"),e[14]=l,e[15]=w):w=e[15];let C;e[16]!==l?(C=l("Widget title"),e[16]=l,e[17]=C):C=e[17];let b;e[18]!==s.title||e[19]!==q||e[20]!==w||e[21]!==C?(b=(0,o.jsxDEV)("input",{"aria-label":w,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:q,placeholder:C,type:"text",value:s.title},void 0,!1),e[18]=s.title,e[19]=q,e[20]=w,e[21]=C,e[22]=b):b=e[22];let E;e[23]!==l?(E=l("SQL query"),e[23]=l,e[24]=E):E=e[24];let m;e[25]!==s.sql||e[26]!==x||e[27]!==E?(m=(0,o.jsxDEV)("textarea",{"aria-label":E,className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:x,placeholder:"SELECT author, COUNT(*) AS messages FROM \u2026",spellCheck:!1,value:s.sql},void 0,!1),e[25]=s.sql,e[26]=x,e[27]=E,e[28]=m):m=e[28];let p;e[29]!==l?(p=l("Shard key (optional)"),e[29]=l,e[30]=p):p=e[30];let u;e[31]!==l?(u=l("Shard key (optional)"),e[31]=l,e[32]=u):u=e[32];let h;e[33]!==s.shardKey||e[34]!==M||e[35]!==p||e[36]!==u?(h=(0,o.jsxDEV)("input",{"aria-label":p,className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:M,placeholder:u,type:"text",value:s.shardKey},void 0,!1),e[33]=s.shardKey,e[34]=M,e[35]=p,e[36]=u,e[37]=h):h=e[37];let v;e[38]!==l?(v=l("Cancel"),e[38]=l,e[39]=v):v=e[39];let g;e[40]!==t||e[41]!==v?(g=(0,o.jsxDEV)(I,{"data-testid":"dashboards-form-cancel",onClick:t,size:"sm",type:"button",variant:"outline",children:v},void 0,!1),e[40]=t,e[41]=v,e[42]=g):g=e[42];let N=!A,r;e[43]!==f||e[44]!==l?(r=l(f?"Save widget":"Add widget"),e[43]=f,e[44]=l,e[45]=r):r=e[45];let n;e[46]!==L||e[47]!==N||e[48]!==r?(n=(0,o.jsxDEV)(I,{"data-testid":"dashboards-form-save",disabled:N,onClick:L,size:"sm",type:"button",children:r},void 0,!1),e[46]=L,e[47]=N,e[48]=r,e[49]=n):n=e[49];let y;e[50]!==g||e[51]!==n?(y=(0,o.jsxDEV)("div",{className:"flex items-center justify-end gap-2",children:[g,n]},void 0,!0),e[50]=g,e[51]=n,e[52]=y):y=e[52];let F;return e[53]!==m||e[54]!==h||e[55]!==y||e[56]!==b?(F=(0,o.jsxDEV)(z,{"data-testid":"dashboards-form",children:(0,o.jsxDEV)(D,{className:"flex flex-col gap-3 py-4",children:[b,m,h,y]},void 0,!0)},void 0,!1),e[53]=m,e[54]=h,e[55]=y,e[56]=b,e[57]=F):F=e[57],F},"WidgetForm"),xe=k($=>{let e=(0,W.c)(39),{initialShardKey:s}=$,f=O(),[t,i]=X(re),[d,l]=(0,T.useState)(B),[c,q]=(0,T.useState)(null),[a,x]=(0,T.useState)(!1),K;e[0]!==s?(K=k(()=>{q(null),l({...B,shardKey:s??""}),x(!0)},"t1"),e[0]=s,e[1]=K):K=e[1];let M=K,S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=k(()=>{x(!1),q(null),l(B)},"t2"),e[2]=S):S=e[2];let L=S,R;e[3]!==t?(R=k(r=>{let n=t.find(y=>y.id===r);n!==void 0&&(q(r),l({shardKey:n.shardKey??"",sql:n.sql,title:n.title}),x(!0))},"t3"),e[3]=t,e[4]=R):R=e[4];let A=R,w;e[5]!==i?(w=k(r=>{i(n=>n.filter(y=>y.id!==r))},"t4"),e[5]=i,e[6]=w):w=e[6];let C=w,b;e[7]!==d.shardKey||e[8]!==d.sql||e[9]!==d.title||e[10]!==c||e[11]!==i?(b=k(()=>{let r=d.title.trim(),n=d.sql.trim();if(r===""||n==="")return;let y=d.shardKey.trim();i(c===null?F=>[...F,{id:ee("w"),shardKey:y,sql:n,title:r}]:F=>F.map(_=>_.id===c?{..._,shardKey:y,sql:n,title:r}:_)),L()},"t5"),e[7]=d.shardKey,e[8]=d.sql,e[9]=d.title,e[10]=c,e[11]=i,e[12]=b):b=e[12];let E=b,m;e[13]!==f?(m=f("Chart widgets backed by saved read-only SQL queries."),e[13]=f,e[14]=m):m=e[14];let p;e[15]!==m?(p=(0,o.jsxDEV)("p",{className:"text-sm text-muted-foreground",children:m},void 0,!1),e[15]=m,e[16]=p):p=e[16];let u;e[17]!==a||e[18]!==M||e[19]!==f?(u=!a&&(0,o.jsxDEV)(I,{"data-testid":"dashboards-add",onClick:M,size:"sm",type:"button",children:f("Add widget")},void 0,!1),e[17]=a,e[18]=M,e[19]=f,e[20]=u):u=e[20];let h;e[21]!==p||e[22]!==u?(h=(0,o.jsxDEV)("div",{className:"flex items-center justify-between",children:[p,u]},void 0,!0),e[21]=p,e[22]=u,e[23]=h):h=e[23];let v;e[24]!==d||e[25]!==c||e[26]!==a||e[27]!==E?(v=a&&(0,o.jsxDEV)(ce,{draft:d,editing:c!==null,onCancel:L,onChange:l,onSubmit:E},void 0,!1),e[24]=d,e[25]=c,e[26]=a,e[27]=E,e[28]=v):v=e[28];let g;e[29]!==a||e[30]!==A||e[31]!==C||e[32]!==f||e[33]!==t?(g=t.length===0&&!a?(0,o.jsxDEV)(U,{description:f("Add a widget to chart a saved SQL query on this browser."),testId:"dashboards-empty",title:f("No widgets yet")},void 0,!1):(0,o.jsxDEV)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:t.map(r=>(0,o.jsxDEV)(ne,{onEdit:A,onRemove:C,widget:r},r.id,!1))},void 0,!1),e[29]=a,e[30]=A,e[31]=C,e[32]=f,e[33]=t,e[34]=g):g=e[34];let N;return e[35]!==v||e[36]!==g||e[37]!==h?(N=(0,o.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[h,v,g]},void 0,!0),e[35]=v,e[36]=g,e[37]=h,e[38]=N):N=e[38],N},"DashboardsPanel");export{xe as default};
1
+ import{a as se}from"./chunk-SDQE2IUJ.js";import"./chunk-X4QFAAZ5.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-KEGAWN6Y.js";import{a as te}from"./chunk-XNJNSCLM.js";import{a as z,b as V,c as P,e as D}from"./chunk-SEU5V7I6.js";import{d as X,f as ee}from"./chunk-2MLA6WFH.js";import"./chunk-HV7G6DFP.js";import{c as I}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-CKSHCYGC.js";import{a as J}from"./chunk-G7ZBM54M.js";import{f as Q}from"./chunk-LOYE7OU2.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as U}from"./chunk-TAD43CG5.js";import{d as O,f as H,g as Y,h as G,l as Z}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as k,e as j,f as ie,g as le,h as oe}from"./chunk-RRCPZMC2.js";var W=j(le(),1),T=j(ie(),1);var o=j(oe(),1);var de=H(J.runSql),ae=k(($,e)=>{let s=Q(),[f,t]=(0,T.useState)(void 0),[i,d]=(0,T.useState)(void 0),[l,c]=(0,T.useState)(!0),q=(0,T.useCallback)(async a=>{c(!0);try{let x=await s.query(de,{sql:$},Y(e));a.cancelled||(t(x),d(void 0))}catch(x){a.cancelled||(t(void 0),d(G(x)))}finally{a.cancelled||c(!1)}},[s,$,e]);return(0,T.useEffect)(()=>{let a={cancelled:!1};return Z(q(a)),()=>{a.cancelled=!0}},[q]),{error:i,loading:l,result:f}},"useRunSql"),re="lunora-studio-dashboards",B={shardKey:"",sql:"",title:""},ne=k($=>{let e=(0,W.c)(54),{onEdit:s,onRemove:f,widget:t}=$,i=O(),{error:d,loading:l,result:c}=ae(t.sql,t.shardKey??""),q;e[0]!==s||e[1]!==t.id?(q=k(()=>{s(t.id)},"t1"),e[0]=s,e[1]=t.id,e[2]=q):q=e[2];let a=q,x;e[3]!==f||e[4]!==t.id?(x=k(()=>{f(t.id)},"t2"),e[3]=f,e[4]=t.id,e[5]=x):x=e[5];let K=x,M=`dashboards-widget-${t.id}`,S;e[6]!==t.title?(S=(0,o.jsxDEV)(P,{className:"min-w-0 truncate",title:t.title,children:t.title},void 0,!1),e[6]=t.title,e[7]=S):S=e[7];let L;e[8]!==i?(L=i("Edit widget"),e[8]=i,e[9]=L):L=e[9];let R=`dashboards-widget-edit-${t.id}`,A;e[10]!==i?(A=i("Edit widget"),e[10]=i,e[11]=A):A=e[11];let w;e[12]===Symbol.for("react.memo_cache_sentinel")?(w=(0,o.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,o.jsxDEV)("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"},void 0,!1)},void 0,!1),e[12]=w):w=e[12];let C;e[13]!==a||e[14]!==L||e[15]!==R||e[16]!==A?(C=(0,o.jsxDEV)(I,{"aria-label":L,"data-testid":R,onClick:a,size:"icon-xs",title:A,type:"button",variant:"ghost",children:w},void 0,!1),e[13]=a,e[14]=L,e[15]=R,e[16]=A,e[17]=C):C=e[17];let b;e[18]!==i?(b=i("Remove widget"),e[18]=i,e[19]=b):b=e[19];let E=`dashboards-widget-remove-${t.id}`,m;e[20]!==i?(m=i("Remove widget"),e[20]=i,e[21]=m):m=e[21];let p;e[22]===Symbol.for("react.memo_cache_sentinel")?(p=(0,o.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,o.jsxDEV)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"},void 0,!1)},void 0,!1),e[22]=p):p=e[22];let u;e[23]!==K||e[24]!==b||e[25]!==E||e[26]!==m?(u=(0,o.jsxDEV)(I,{"aria-label":b,"data-testid":E,onClick:K,size:"icon-xs",title:m,type:"button",variant:"ghost",children:p},void 0,!1),e[23]=K,e[24]=b,e[25]=E,e[26]=m,e[27]=u):u=e[27];let h;e[28]!==u||e[29]!==C?(h=(0,o.jsxDEV)("div",{className:"flex shrink-0 items-center gap-1",children:[C,u]},void 0,!0),e[28]=u,e[29]=C,e[30]=h):h=e[30];let v;e[31]!==h||e[32]!==S?(v=(0,o.jsxDEV)(V,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[S,h]},void 0,!0),e[31]=h,e[32]=S,e[33]=v):v=e[33];let g;e[34]!==d||e[35]!==t.id?(g=d!==void 0&&(0,o.jsxDEV)(te,{className:"font-mono text-xs",testId:`dashboards-widget-error-${t.id}`,variant:"destructive",children:d},void 0,!1),e[34]=d,e[35]=t.id,e[36]=g):g=e[36];let N;e[37]!==d||e[38]!==l||e[39]!==c||e[40]!==i||e[41]!==t.id?(N=d===void 0&&l&&c===void 0&&(0,o.jsxDEV)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${t.id}`,children:i("Running\u2026")},void 0,!1),e[37]=d,e[38]=l,e[39]=c,e[40]=i,e[41]=t.id,e[42]=N):N=e[42];let r;e[43]!==d||e[44]!==c?(r=d===void 0&&c!==void 0&&(0,o.jsxDEV)(se,{result:c},void 0,!1),e[43]=d,e[44]=c,e[45]=r):r=e[45];let n;e[46]!==g||e[47]!==N||e[48]!==r?(n=(0,o.jsxDEV)(D,{className:"min-h-32 py-2",children:[g,N,r]},void 0,!0),e[46]=g,e[47]=N,e[48]=r,e[49]=n):n=e[49];let y;return e[50]!==v||e[51]!==n||e[52]!==M?(y=(0,o.jsxDEV)(z,{"data-testid":M,children:[v,n]},void 0,!0),e[50]=v,e[51]=n,e[52]=M,e[53]=y):y=e[53],y},"WidgetCard"),ce=k($=>{let e=(0,W.c)(58),{draft:s,editing:f,onCancel:t,onChange:i,onSubmit:d}=$,l=O(),c;e[0]!==s||e[1]!==i?(c=k(_=>{i({...s,title:_.target.value})},"t1"),e[0]=s,e[1]=i,e[2]=c):c=e[2];let q=c,a;e[3]!==s||e[4]!==i?(a=k(_=>{i({...s,sql:_.target.value})},"t2"),e[3]=s,e[4]=i,e[5]=a):a=e[5];let x=a,K;e[6]!==s||e[7]!==i?(K=k(_=>{i({...s,shardKey:_.target.value})},"t3"),e[6]=s,e[7]=i,e[8]=K):K=e[8];let M=K,S;e[9]!==d?(S=k(()=>{d()},"t4"),e[9]=d,e[10]=S):S=e[10];let L=S,R;e[11]!==s.sql||e[12]!==s.title?(R=s.title.trim()!==""&&s.sql.trim()!=="",e[11]=s.sql,e[12]=s.title,e[13]=R):R=e[13];let A=R,w;e[14]!==l?(w=l("Widget title"),e[14]=l,e[15]=w):w=e[15];let C;e[16]!==l?(C=l("Widget title"),e[16]=l,e[17]=C):C=e[17];let b;e[18]!==s.title||e[19]!==q||e[20]!==w||e[21]!==C?(b=(0,o.jsxDEV)("input",{"aria-label":w,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:q,placeholder:C,type:"text",value:s.title},void 0,!1),e[18]=s.title,e[19]=q,e[20]=w,e[21]=C,e[22]=b):b=e[22];let E;e[23]!==l?(E=l("SQL query"),e[23]=l,e[24]=E):E=e[24];let m;e[25]!==s.sql||e[26]!==x||e[27]!==E?(m=(0,o.jsxDEV)("textarea",{"aria-label":E,className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:x,placeholder:"SELECT author, COUNT(*) AS messages FROM \u2026",spellCheck:!1,value:s.sql},void 0,!1),e[25]=s.sql,e[26]=x,e[27]=E,e[28]=m):m=e[28];let p;e[29]!==l?(p=l("Shard key (optional)"),e[29]=l,e[30]=p):p=e[30];let u;e[31]!==l?(u=l("Shard key (optional)"),e[31]=l,e[32]=u):u=e[32];let h;e[33]!==s.shardKey||e[34]!==M||e[35]!==p||e[36]!==u?(h=(0,o.jsxDEV)("input",{"aria-label":p,className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:M,placeholder:u,type:"text",value:s.shardKey},void 0,!1),e[33]=s.shardKey,e[34]=M,e[35]=p,e[36]=u,e[37]=h):h=e[37];let v;e[38]!==l?(v=l("Cancel"),e[38]=l,e[39]=v):v=e[39];let g;e[40]!==t||e[41]!==v?(g=(0,o.jsxDEV)(I,{"data-testid":"dashboards-form-cancel",onClick:t,size:"sm",type:"button",variant:"outline",children:v},void 0,!1),e[40]=t,e[41]=v,e[42]=g):g=e[42];let N=!A,r;e[43]!==f||e[44]!==l?(r=l(f?"Save widget":"Add widget"),e[43]=f,e[44]=l,e[45]=r):r=e[45];let n;e[46]!==L||e[47]!==N||e[48]!==r?(n=(0,o.jsxDEV)(I,{"data-testid":"dashboards-form-save",disabled:N,onClick:L,size:"sm",type:"button",children:r},void 0,!1),e[46]=L,e[47]=N,e[48]=r,e[49]=n):n=e[49];let y;e[50]!==g||e[51]!==n?(y=(0,o.jsxDEV)("div",{className:"flex items-center justify-end gap-2",children:[g,n]},void 0,!0),e[50]=g,e[51]=n,e[52]=y):y=e[52];let F;return e[53]!==m||e[54]!==h||e[55]!==y||e[56]!==b?(F=(0,o.jsxDEV)(z,{"data-testid":"dashboards-form",children:(0,o.jsxDEV)(D,{className:"flex flex-col gap-3 py-4",children:[b,m,h,y]},void 0,!0)},void 0,!1),e[53]=m,e[54]=h,e[55]=y,e[56]=b,e[57]=F):F=e[57],F},"WidgetForm"),xe=k($=>{let e=(0,W.c)(39),{initialShardKey:s}=$,f=O(),[t,i]=X(re),[d,l]=(0,T.useState)(B),[c,q]=(0,T.useState)(null),[a,x]=(0,T.useState)(!1),K;e[0]!==s?(K=k(()=>{q(null),l({...B,shardKey:s??""}),x(!0)},"t1"),e[0]=s,e[1]=K):K=e[1];let M=K,S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=k(()=>{x(!1),q(null),l(B)},"t2"),e[2]=S):S=e[2];let L=S,R;e[3]!==t?(R=k(r=>{let n=t.find(y=>y.id===r);n!==void 0&&(q(r),l({shardKey:n.shardKey??"",sql:n.sql,title:n.title}),x(!0))},"t3"),e[3]=t,e[4]=R):R=e[4];let A=R,w;e[5]!==i?(w=k(r=>{i(n=>n.filter(y=>y.id!==r))},"t4"),e[5]=i,e[6]=w):w=e[6];let C=w,b;e[7]!==d.shardKey||e[8]!==d.sql||e[9]!==d.title||e[10]!==c||e[11]!==i?(b=k(()=>{let r=d.title.trim(),n=d.sql.trim();if(r===""||n==="")return;let y=d.shardKey.trim();i(c===null?F=>[...F,{id:ee("w"),shardKey:y,sql:n,title:r}]:F=>F.map(_=>_.id===c?{..._,shardKey:y,sql:n,title:r}:_)),L()},"t5"),e[7]=d.shardKey,e[8]=d.sql,e[9]=d.title,e[10]=c,e[11]=i,e[12]=b):b=e[12];let E=b,m;e[13]!==f?(m=f("Chart widgets backed by saved read-only SQL queries."),e[13]=f,e[14]=m):m=e[14];let p;e[15]!==m?(p=(0,o.jsxDEV)("p",{className:"text-sm text-muted-foreground",children:m},void 0,!1),e[15]=m,e[16]=p):p=e[16];let u;e[17]!==a||e[18]!==M||e[19]!==f?(u=!a&&(0,o.jsxDEV)(I,{"data-testid":"dashboards-add",onClick:M,size:"sm",type:"button",children:f("Add widget")},void 0,!1),e[17]=a,e[18]=M,e[19]=f,e[20]=u):u=e[20];let h;e[21]!==p||e[22]!==u?(h=(0,o.jsxDEV)("div",{className:"flex items-center justify-between",children:[p,u]},void 0,!0),e[21]=p,e[22]=u,e[23]=h):h=e[23];let v;e[24]!==d||e[25]!==c||e[26]!==a||e[27]!==E?(v=a&&(0,o.jsxDEV)(ce,{draft:d,editing:c!==null,onCancel:L,onChange:l,onSubmit:E},void 0,!1),e[24]=d,e[25]=c,e[26]=a,e[27]=E,e[28]=v):v=e[28];let g;e[29]!==a||e[30]!==A||e[31]!==C||e[32]!==f||e[33]!==t?(g=t.length===0&&!a?(0,o.jsxDEV)(U,{description:f("Add a widget to chart a saved SQL query on this browser."),testId:"dashboards-empty",title:f("No widgets yet")},void 0,!1):(0,o.jsxDEV)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:t.map(r=>(0,o.jsxDEV)(ne,{onEdit:A,onRemove:C,widget:r},r.id,!1))},void 0,!1),e[29]=a,e[30]=A,e[31]=C,e[32]=f,e[33]=t,e[34]=g):g=e[34];let N;return e[35]!==v||e[36]!==g||e[37]!==h?(N=(0,o.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[h,v,g]},void 0,!0),e[35]=v,e[36]=g,e[37]=h,e[38]=N):N=e[38],N},"DashboardsPanel");export{xe as default};
@@ -1 +1 @@
1
- import{a as y}from"./chunk-RXVQJ4DO.js";import{f as m}from"./chunk-L2YBC2BV.js";import{h as d,l as g}from"./chunk-ITQKVEP7.js";import{a as o,e as f,f as A,g as b}from"./chunk-RRCPZMC2.js";var p=f(b(),1);var c=f(A(),1);var h={capabilities:{accounts:!0,admin:!0,organization:!1,passkey:!1,twoFactor:!1},emailAndPassword:!1,organization:{enabled:!1,roles:!1,teams:!1},plugins:[],rateLimit:{enabled:!1},session:{},socialProviders:[],userFields:[]},L=o(()=>{let e=(0,p.c)(6),t=m(),a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=["lunora-auth-config"],e[0]=a):a=e[0];let s;e[1]!==t?(s=o(()=>t.getAuthConfig(),"t1"),e[1]=t,e[2]=s):s=e[2];let{data:u,isLoading:i}=y(a,s),r=u??h,l=!i,n;return e[3]!==r||e[4]!==l?(n={config:r,ready:l},e[3]=r,e[4]=l,e[5]=n):n=e[5],n},"useAuthConfig"),w=o(()=>{let[e,t]=(0,c.useState)(!1),[a,s]=(0,c.useState)(null);return{busy:e,error:a,run:o(i=>{g((async()=>{t(!0),s(null);try{await i()}catch(r){s(d(r))}finally{t(!1)}})())},"run")}},"useAsyncSubmit");export{L as a,w as b};
1
+ import{a as y}from"./chunk-ZQQ3MFEQ.js";import{f as m}from"./chunk-LOYE7OU2.js";import{h as d,l as g}from"./chunk-ITQKVEP7.js";import{a as o,e as f,f as A,g as b}from"./chunk-RRCPZMC2.js";var p=f(b(),1);var c=f(A(),1);var h={capabilities:{accounts:!0,admin:!0,organization:!1,passkey:!1,twoFactor:!1},emailAndPassword:!1,organization:{enabled:!1,roles:!1,teams:!1},plugins:[],rateLimit:{enabled:!1},session:{},socialProviders:[],userFields:[]},L=o(()=>{let e=(0,p.c)(6),t=m(),a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=["lunora-auth-config"],e[0]=a):a=e[0];let s;e[1]!==t?(s=o(()=>t.getAuthConfig(),"t1"),e[1]=t,e[2]=s):s=e[2];let{data:u,isLoading:i}=y(a,s),r=u??h,l=!i,n;return e[3]!==r||e[4]!==l?(n={config:r,ready:l},e[3]=r,e[4]=l,e[5]=n):n=e[5],n},"useAuthConfig"),w=o(()=>{let[e,t]=(0,c.useState)(!1),[a,s]=(0,c.useState)(null);return{busy:e,error:a,run:o(i=>{g((async()=>{t(!0),s(null);try{await i()}catch(r){s(d(r))}finally{t(!1)}})())},"run")}},"useAsyncSubmit");export{L as a,w as b};