@lunora/vue 1.0.0-alpha.117 → 1.0.0-alpha.119

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.
package/dist/index.d.mts CHANGED
@@ -564,6 +564,14 @@ interface UseAuthResult {
564
564
  * Multiple `useAuth` instances within the same effect scope share a single
565
565
  * per-client identity store (from `@lunora/client/auth`) — a `setToken` from
566
566
  * one component re-renders every watcher with the freshly-resolved user.
567
+ *
568
+ * Both subscribes are client-only, for the same reason as `useFlags`: this
569
+ * runs synchronously inside `setup()` during `renderToString`, and that render
570
+ * scope is never stopped, so `onScopeDispose` never fires. For the identity
571
+ * subscribe that is not just a stray listener — the store kicks off
572
+ * `getCurrentUser()` on its first subscriber, so an unguarded server render
573
+ * issues a round-trip against a client whose URL does not resolve there. Both
574
+ * refs still hold the client's current values; live updates start at hydration.
567
575
  */
568
576
  declare const useAuth: () => UseAuthResult;
569
577
  /**
@@ -577,6 +585,13 @@ declare const useAuth: () => UseAuthResult;
577
585
  * Teardown is wired to the active effect scope (`onScopeDispose`), so the
578
586
  * status listener is released on component unmount (or `effectScope().stop()`).
579
587
  * Call inside `setup()` / an active effect scope.
588
+ *
589
+ * Client-only, for the same reason as `useFlags`: this runs synchronously
590
+ * inside `setup()` during `renderToString`, and that render scope is never
591
+ * stopped — `onScopeDispose` therefore never fires and an unguarded listener
592
+ * would stay registered on the client for the lifetime of the server process,
593
+ * one per rendered request. The ref still holds the client's current status,
594
+ * which is what the SSR HTML should show; live updates start at hydration.
580
595
  */
581
596
  declare const useConnectionStatus: () => Readonly<Ref<ConnectionStatus>>;
582
597
  /** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
package/dist/index.d.ts CHANGED
@@ -564,6 +564,14 @@ interface UseAuthResult {
564
564
  * Multiple `useAuth` instances within the same effect scope share a single
565
565
  * per-client identity store (from `@lunora/client/auth`) — a `setToken` from
566
566
  * one component re-renders every watcher with the freshly-resolved user.
567
+ *
568
+ * Both subscribes are client-only, for the same reason as `useFlags`: this
569
+ * runs synchronously inside `setup()` during `renderToString`, and that render
570
+ * scope is never stopped, so `onScopeDispose` never fires. For the identity
571
+ * subscribe that is not just a stray listener — the store kicks off
572
+ * `getCurrentUser()` on its first subscriber, so an unguarded server render
573
+ * issues a round-trip against a client whose URL does not resolve there. Both
574
+ * refs still hold the client's current values; live updates start at hydration.
567
575
  */
568
576
  declare const useAuth: () => UseAuthResult;
569
577
  /**
@@ -577,6 +585,13 @@ declare const useAuth: () => UseAuthResult;
577
585
  * Teardown is wired to the active effect scope (`onScopeDispose`), so the
578
586
  * status listener is released on component unmount (or `effectScope().stop()`).
579
587
  * Call inside `setup()` / an active effect scope.
588
+ *
589
+ * Client-only, for the same reason as `useFlags`: this runs synchronously
590
+ * inside `setup()` during `renderToString`, and that render scope is never
591
+ * stopped — `onScopeDispose` therefore never fires and an unguarded listener
592
+ * would stay registered on the client for the lifetime of the server process,
593
+ * one per rendered request. The ref still holds the client's current status,
594
+ * which is what the SSR HTML should show; live updates start at hydration.
580
595
  */
581
596
  declare const useConnectionStatus: () => Readonly<Ref<ConnectionStatus>>;
582
597
  /** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{AuthLoading as r,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-nfI43dvD.mjs";import{hydratePreloaded as a}from"./packem_shared/hydratePreloaded-BpzZkPH4.mjs";import{LUNORA_INJECTION_KEY as f,createLunora as m,provideLunora as p,useLunora as x}from"./packem_shared/LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{useAction as A}from"./packem_shared/useAction-C4VLsh4M.mjs";import{useAgent as d}from"./packem_shared/useAgent-BLhUb7TW.mjs";import{useAgentChat as h}from"./packem_shared/useAgentChat-D9dYI4Pq.mjs";import{useAgentState as l}from"./packem_shared/useAgentState-eXsZU41P.mjs";import{useAgentToolEvents as Q}from"./packem_shared/useAgentToolEvents-CXb7Vtcn.mjs";import{useAuth as b}from"./packem_shared/useAuth-DJ9902_4.mjs";import{default as E}from"./packem_shared/useConnectionStatus-BSFJBnmi.mjs";import{useFlag as N,useFlags as P}from"./packem_shared/useFlag-xVfWC_c6.mjs";import{useMutation as v}from"./packem_shared/useMutation-D6PkaNaE.mjs";import{useMutator as M}from"./packem_shared/useMutator-CO7nXlRf.mjs";import{useInfiniteQuery as R,usePaginatedQuery as U}from"./packem_shared/useInfiniteQuery-PpVC-DWP.mjs";import{usePresence as J}from"./packem_shared/usePresence-CQ8zOCOI.mjs";import{subscribeToQuery as V,useQuery as Y}from"./packem_shared/subscribeToQuery-G5w094pU.mjs";import{useRateLimit as k}from"./packem_shared/useRateLimit-zoPsflSG.mjs";import{useStream as w}from"./packem_shared/useStream-COVzNdKq.mjs";import{useSubscription as B}from"./packem_shared/useSubscription-ImlDfQGg.mjs";import{useVoiceAgent as G}from"./packem_shared/useVoiceAgent-BEGHhbmX.mjs";export{r as AuthLoading,t as Authenticated,f as LUNORA_INJECTION_KEY,u as Unauthenticated,m as createLunora,a as hydratePreloaded,p as provideLunora,V as subscribeToQuery,A as useAction,d as useAgent,h as useAgentChat,l as useAgentState,Q as useAgentToolEvents,b as useAuth,E as useConnectionStatus,N as useFlag,P as useFlags,R as useInfiniteQuery,x as useLunora,v as useMutation,M as useMutator,U as usePaginatedQuery,J as usePresence,Y as useQuery,k as useRateLimit,w as useStream,B as useSubscription,G as useVoiceAgent};
1
+ import{AuthLoading as r,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-Dp-20UXt.mjs";import{hydratePreloaded as a}from"./packem_shared/hydratePreloaded-BpzZkPH4.mjs";import{LUNORA_INJECTION_KEY as f,createLunora as m,provideLunora as p,useLunora as x}from"./packem_shared/LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{useAction as A}from"./packem_shared/useAction-C4VLsh4M.mjs";import{useAgent as d}from"./packem_shared/useAgent-BLhUb7TW.mjs";import{useAgentChat as h}from"./packem_shared/useAgentChat-D9dYI4Pq.mjs";import{useAgentState as l}from"./packem_shared/useAgentState-eXsZU41P.mjs";import{useAgentToolEvents as Q}from"./packem_shared/useAgentToolEvents-CXb7Vtcn.mjs";import{useAuth as b}from"./packem_shared/useAuth-axmO2A7B.mjs";import{default as E}from"./packem_shared/useConnectionStatus-CCUbKnj2.mjs";import{useFlag as N,useFlags as P}from"./packem_shared/useFlag-xVfWC_c6.mjs";import{useMutation as v}from"./packem_shared/useMutation-D6PkaNaE.mjs";import{useMutator as M}from"./packem_shared/useMutator-CO7nXlRf.mjs";import{useInfiniteQuery as R,usePaginatedQuery as U}from"./packem_shared/useInfiniteQuery-T4qCkGfy.mjs";import{usePresence as J}from"./packem_shared/usePresence-CQ8zOCOI.mjs";import{subscribeToQuery as V,useQuery as Y}from"./packem_shared/subscribeToQuery-G5w094pU.mjs";import{useRateLimit as k}from"./packem_shared/useRateLimit-zoPsflSG.mjs";import{useStream as w}from"./packem_shared/useStream-COVzNdKq.mjs";import{useSubscription as B}from"./packem_shared/useSubscription-ImlDfQGg.mjs";import{useVoiceAgent as G}from"./packem_shared/useVoiceAgent-BEGHhbmX.mjs";export{r as AuthLoading,t as Authenticated,f as LUNORA_INJECTION_KEY,u as Unauthenticated,m as createLunora,a as hydratePreloaded,p as provideLunora,V as subscribeToQuery,A as useAction,d as useAgent,h as useAgentChat,l as useAgentState,Q as useAgentToolEvents,b as useAuth,E as useConnectionStatus,N as useFlag,P as useFlags,R as useInfiniteQuery,x as useLunora,v as useMutation,M as useMutator,U as usePaginatedQuery,J as usePresence,Y as useQuery,k as useRateLimit,w as useStream,B as useSubscription,G as useVoiceAgent};
@@ -1 +1 @@
1
- import{defineComponent as o,computed as a}from"vue";import{useAuth as l}from"./useAuth-DJ9902_4.mjs";const r=o({name:"Authenticated",setup(s,{slots:t}){const{token:e,user:n}=l(),u=a(()=>e.value!==null&&n.value!==null);return()=>u.value?t.default?.():void 0}}),c=o({name:"Unauthenticated",setup(s,{slots:t}){const{token:e,user:n}=l(),u=a(()=>e.value!==null&&n.value===null);return()=>!u.value&&e.value===null?t.default?.():void 0}}),p=o({name:"AuthLoading",setup(s,{slots:t}){const{token:e,user:n}=l(),u=a(()=>e.value!==null&&n.value===null);return()=>u.value?t.default?.():void 0}});export{p as AuthLoading,r as Authenticated,c as Unauthenticated};
1
+ import{defineComponent as o,computed as a}from"vue";import{useAuth as l}from"./useAuth-axmO2A7B.mjs";const r=o({name:"Authenticated",setup(s,{slots:t}){const{token:e,user:n}=l(),u=a(()=>e.value!==null&&n.value!==null);return()=>u.value?t.default?.():void 0}}),c=o({name:"Unauthenticated",setup(s,{slots:t}){const{token:e,user:n}=l(),u=a(()=>e.value!==null&&n.value===null);return()=>!u.value&&e.value===null?t.default?.():void 0}}),p=o({name:"AuthLoading",setup(s,{slots:t}){const{token:e,user:n}=l(),u=a(()=>e.value!==null&&n.value===null);return()=>u.value?t.default?.():void 0}});export{p as AuthLoading,r as Authenticated,c as Unauthenticated};
@@ -0,0 +1 @@
1
+ import{getIdentityStore as g}from"@lunora/client/auth";import{ref as u,readonly as o,onScopeDispose as h}from"vue";import{i as m}from"./is-browser-BEdfLJHK.mjs";import{useLunora as p}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const U=()=>{const e=p(),t=g(e),n=u(e.getAuthToken()),s=u(t.getUser()),c=()=>{n.value=e.getAuthToken()},i=()=>{s.value=t.getUser()},r=f=>{e.setAuthToken(f)};if(!m())return{setToken:r,token:o(n),user:o(s)};const k=e.onAuthTokenChange(c),a=t.subscribe(i);return h(()=>{k(),a()}),{setToken:r,token:o(n),user:o(s)}};export{U as useAuth};
@@ -0,0 +1 @@
1
+ import{shallowRef as r}from"vue";import{i as e}from"./is-browser-BEdfLJHK.mjs";import{useLunora as i}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{o as u}from"./scope-dispose-Mq3k4nvP.mjs";const p=()=>{const t=i(),o=r(t.connectionStatus());if(!e())return o;const n=t.onConnectionStatus(s=>{o.value=s});return u(n),o};export{p as default};
@@ -0,0 +1 @@
1
+ import{shallowRef as _,watch as v,toValue as O,onScopeDispose as q,computed as E}from"vue";import{initialPages as $,derivePaginationStatus as D,rebalance as z,applyLoadMore as G}from"@lunora/client/pagination";import{i as H}from"./is-browser-BEdfLJHK.mjs";import{useLunora as X}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const Y=/["\\\u0000-\u001F\uD800-\uDFFF]/,T=e=>Y.test(e)?JSON.stringify(e):`"${e}"`,x=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(typeof e=="number"){if(Number.isNaN(e))return"nan";if(e===1/0)return"inf";if(e===-1/0)return"-inf";if(Object.is(e,-0))return"-0"}if(typeof e=="string")return T(e);if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e)){let o="[";for(let n=0;n<e.length;n++)n>0&&(o+=","),o+=x(e[n]);return o+"]"}const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const o=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${o} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const y=e,f=Object.keys(y).sort();let a="{",t=!0;for(const o of f){const n=y[o];n!==void 0&&(t?t=!1:a+=",",a+=T(o),a+=":",a+=x(n))}return a+"}"},F=e=>{let r="";for(let f=0;f<e.length;f+=32768)r+=String.fromCharCode(...e.subarray(f,f+32768));return btoa(r)},d="$lunora.wire$",U=64,J="__proto__",Z=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},h=(e,r=0)=>{if(r>U)throw new RangeError(`wire-codec: value nesting exceeds the ${U}-level limit`);if(e===void 0)return[d,"undefined"];if(e===null)return null;const y=typeof e;if(y==="bigint")return[d,"bigint",e.toString()];if(y==="number"){const t=e;return Number.isNaN(t)?[d,"nan"]:t===1/0?[d,"inf"]:t===-1/0?[d,"-inf"]:t}if(y!=="object")return e;if(e instanceof Date)return[d,"date",h(e.getTime(),r+1)];if(e instanceof Error){const t=e,o={};for(const c of Object.keys(t)){if(t[c]===void 0)continue;const b=h(t[c],r+1);c===J?Object.defineProperty(o,c,{configurable:!0,enumerable:!0,value:b,writable:!0}):o[c]=b}const n=[d,"error",String(t.name),String(t.message),o];return t.cause!==void 0&&n.push(h(t.cause,r+1)),n}if(e instanceof URL)return[d,"url",e.href];if(e instanceof Map)return[d,"map",[...e.entries()].map(([t,o])=>[h(t,r+1),h(o,r+1)])];if(e instanceof Set)return[d,"set",[...e].map(t=>h(t,r+1))];if(e instanceof ArrayBuffer)return[d,"bytes",F(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,o=t.constructor.name,n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return o==="Uint8Array"?[d,"bytes",F(n)]:[d,"bytes",F(n),o]}if(Array.isArray(e)){const t=e.map(o=>h(o,r+1));return t.length>0&&t[0]===d?[d,"arr",t]:t}if(!Z(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const f=e,a={};for(const t of Object.keys(f)){const o=f[t];if(o===void 0)continue;const n=h(o,r+1);t===J?Object.defineProperty(a,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):a[t]=n}return a},W=e=>x(h(e)),M=(e,r)=>`${e}::${W(r)}`,R=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),Q=(e,r,y)=>{const f=X(),{initialNumItems:a,onError:t,shardKey:o}=y,n=_($(a)),c=_([]),b=_(void 0);let j;const k=new Map,m=new Map,w=new Set,K=(s,i)=>{c.value=s.map(P=>{const l=M(e.__lunoraRef,R(P,i));return m.get(l)})},V=(s,i,P)=>{const l=g=>M(e.__lunoraRef,R(g,P));for(const g of i){const p=l(g);if(m.has(p))continue;const A=s.find(u=>u.lower===g.lower);if(A){const u=m.get(l(A));u&&m.set(p,u)}}},C=(s,i)=>{const P=new Set;for(const l of s)P.add(M(e.__lunoraRef,R(l,i)));for(const[l,g]of k)P.has(l)||(g(),k.delete(l),m.delete(l),w.delete(l));for(const l of s){const g=R(l,i),p=M(e.__lunoraRef,g);if(k.has(p))continue;w.add(p);const A=f.subscribe(e,g,u=>{m.set(p,u),w.delete(p),b.value=void 0;const S=O(r);if(K(n.value,S),w.size===0){const N=n.value,L=z(N,c.value);L&&(V(N,L,S),n.value=L)}},{onError:u=>{w.delete(p),b.value=u;const S=n.value,N=S.at(-1);S.length>1&&N&&!m.has(p)&&M(e.__lunoraRef,R(N,i))===p&&(n.value=S.slice(0,-1)),t?.(u)},shardKey:o});k.set(p,A)}},I=()=>{for(const s of k.values())s();k.clear(),m.clear(),w.clear()};v(()=>W(O(r)),()=>{if(!H())return;const s=O(r);I(),n.value=$(a),c.value=[],b.value=void 0,j=void 0,s!=="skip"&&(C(n.value,s),K(n.value,s))},{immediate:!0}),v(()=>n.value,s=>{const i=O(r);j=void 0,i!=="skip"&&(C(s,i),K(s,i))}),q(I);const B=_("LoadingFirstPage");return v([()=>O(r),c],([s,i])=>{B.value=D(s==="skip",i).status},{immediate:!0}),{error:b,loadMore:s=>{const i=O(r);if(i==="skip")return;const{nextCursor:P,status:l}=D(!1,c.value);if(l!=="CanLoadMore"||P===j)return;const g=G(n.value,P,s);if(!g)return;j=P,b.value=void 0;const p=n.value.at(-1),A=g.at(-2);if(p&&A){const u=M(e.__lunoraRef,R(p,i)),S=M(e.__lunoraRef,R(A,i)),N=k.get(u);if(N&&u!==S){const L=m.get(u);L&&m.set(S,L),N(),k.delete(u),m.delete(u),w.delete(u)}}n.value=g},pageResults:c,status:B}},se=(e,r,y)=>{const{error:f,loadMore:a,pageResults:t,status:o}=Q(e,r,y),n=E(()=>t.value.flatMap(b=>b?.page??[])),c=E(()=>O(r)!=="skip"&&(o.value==="LoadingFirstPage"||o.value==="LoadingMore"));return{error:f,isLoading:c,loadMore:a,results:n,status:o}},ie=(e,r,y)=>{const{initialNumItems:f}=y,{error:a,loadMore:t,pageResults:o,status:n}=Q(e,r,y),c=E(()=>o.value.flatMap(w=>w?[w.page]:[])),b=E(()=>O(r)!=="skip"&&n.value==="LoadingFirstPage"),j=E(()=>n.value==="CanLoadMore"),k=E(()=>O(r)!=="skip"&&n.value==="LoadingMore");return{error:a,fetchNextPage:w=>{t(w??f)},hasNextPage:j,isFetchingNextPage:k,isLoading:b,pages:c,status:n}};export{ie as useInfiniteQuery,se as usePaginatedQuery};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/vue",
3
- "version": "1.0.0-alpha.117",
3
+ "version": "1.0.0-alpha.119",
4
4
  "description": "Vue adapter for Lunora — live composables, optimistic mutations, and reactive loaders",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -54,9 +54,9 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@lunora/client": "1.0.0-alpha.81",
58
- "@lunora/errors": "1.0.0-alpha.32",
59
- "@lunora/ratelimit": "1.0.0-alpha.40",
57
+ "@lunora/client": "1.0.0-alpha.83",
58
+ "@lunora/errors": "1.0.0-alpha.34",
59
+ "@lunora/ratelimit": "1.0.0-alpha.42",
60
60
  "@visulima/storage-client": "1.0.2"
61
61
  },
62
62
  "peerDependencies": {
@@ -1 +0,0 @@
1
- import{getIdentityStore as T}from"@lunora/client/auth";import{ref as s,onScopeDispose as a,readonly as r}from"vue";import{useLunora as i}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const b=()=>{const e=i(),o=T(e),t=s(e.getAuthToken()),n=s(o.getUser()),u=()=>{t.value=e.getAuthToken()},c=()=>{n.value=o.getUser()},k=e.onAuthTokenChange(u),g=o.subscribe(c);return a(()=>{k(),g()}),{setToken:h=>{e.setAuthToken(h)},token:r(t),user:r(n)}};export{b as useAuth};
@@ -1 +0,0 @@
1
- import{shallowRef as e}from"vue";import{useLunora as r}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{o as u}from"./scope-dispose-Mq3k4nvP.mjs";const m=()=>{const o=r(),t=e(o.connectionStatus()),n=o.onConnectionStatus(s=>{t.value=s});return u(n),t};export{m as default};
@@ -1 +0,0 @@
1
- import{shallowRef as _,watch as v,toValue as O,onScopeDispose as q,computed as E}from"vue";import{initialPages as $,derivePaginationStatus as D,rebalance as z,applyLoadMore as G}from"@lunora/client/pagination";import{i as H}from"./is-browser-BEdfLJHK.mjs";import{useLunora as X}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const Y=/["\\\u0000-\u001F\uD800-\uDFFF]/,T=e=>Y.test(e)?JSON.stringify(e):`"${e}"`,x=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(typeof e=="number"){if(Number.isNaN(e))return"nan";if(e===1/0)return"inf";if(e===-1/0)return"-inf";if(Object.is(e,-0))return"-0"}if(typeof e=="string")return T(e);if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e)){let o="[";for(let n=0;n<e.length;n++)n>0&&(o+=","),o+=x(e[n]);return o+"]"}const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const o=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${o} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const y=e,f=Object.keys(y).sort();let a="{",t=!0;for(const o of f){const n=y[o];n!==void 0&&(t?t=!1:a+=",",a+=T(o),a+=":",a+=x(n))}return a+"}"},F=e=>{let r="";for(let f=0;f<e.length;f+=32768)r+=String.fromCharCode(...e.subarray(f,f+32768));return btoa(r)},d="$lunora.wire$",U=64,J="__proto__",Z=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},S=(e,r=0)=>{if(r>U)throw new RangeError(`wire-codec: value nesting exceeds the ${U}-level limit`);if(e===void 0)return[d,"undefined"];if(e===null)return null;const y=typeof e;if(y==="bigint")return[d,"bigint",e.toString()];if(y==="number"){const t=e;return Number.isNaN(t)?[d,"nan"]:t===1/0?[d,"inf"]:t===-1/0?[d,"-inf"]:t}if(y!=="object")return e;if(e instanceof Date)return[d,"date",S(e.getTime(),r+1)];if(e instanceof Error){const t=e,o={};for(const c of Object.keys(t)){if(t[c]===void 0)continue;const b=S(t[c],r+1);c===J?Object.defineProperty(o,c,{configurable:!0,enumerable:!0,value:b,writable:!0}):o[c]=b}const n=[d,"error",t.name,t.message,o];return t.cause!==void 0&&n.push(S(t.cause,r+1)),n}if(e instanceof URL)return[d,"url",e.href];if(e instanceof Map)return[d,"map",[...e.entries()].map(([t,o])=>[S(t,r+1),S(o,r+1)])];if(e instanceof Set)return[d,"set",[...e].map(t=>S(t,r+1))];if(e instanceof ArrayBuffer)return[d,"bytes",F(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,o=t.constructor.name,n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return o==="Uint8Array"?[d,"bytes",F(n)]:[d,"bytes",F(n),o]}if(Array.isArray(e)){const t=e.map(o=>S(o,r+1));return t.length>0&&t[0]===d?[d,"arr",t]:t}if(!Z(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const f=e,a={};for(const t of Object.keys(f)){const o=f[t];if(o===void 0)continue;const n=S(o,r+1);t===J?Object.defineProperty(a,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):a[t]=n}return a},W=e=>x(S(e)),M=(e,r)=>`${e}::${W(r)}`,R=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),Q=(e,r,y)=>{const f=X(),{initialNumItems:a,onError:t,shardKey:o}=y,n=_($(a)),c=_([]),b=_(void 0);let j;const k=new Map,m=new Map,w=new Set,K=(s,i)=>{c.value=s.map(P=>{const l=M(e.__lunoraRef,R(P,i));return m.get(l)})},V=(s,i,P)=>{const l=g=>M(e.__lunoraRef,R(g,P));for(const g of i){const p=l(g);if(m.has(p))continue;const A=s.find(u=>u.lower===g.lower);if(A){const u=m.get(l(A));u&&m.set(p,u)}}},C=(s,i)=>{const P=new Set;for(const l of s)P.add(M(e.__lunoraRef,R(l,i)));for(const[l,g]of k)P.has(l)||(g(),k.delete(l),m.delete(l),w.delete(l));for(const l of s){const g=R(l,i),p=M(e.__lunoraRef,g);if(k.has(p))continue;w.add(p);const A=f.subscribe(e,g,u=>{m.set(p,u),w.delete(p),b.value=void 0;const h=O(r);if(K(n.value,h),w.size===0){const N=n.value,L=z(N,c.value);L&&(V(N,L,h),n.value=L)}},{onError:u=>{w.delete(p),b.value=u;const h=n.value,N=h.at(-1);h.length>1&&N&&!m.has(p)&&M(e.__lunoraRef,R(N,i))===p&&(n.value=h.slice(0,-1)),t?.(u)},shardKey:o});k.set(p,A)}},I=()=>{for(const s of k.values())s();k.clear(),m.clear(),w.clear()};v(()=>W(O(r)),()=>{if(!H())return;const s=O(r);I(),n.value=$(a),c.value=[],b.value=void 0,j=void 0,s!=="skip"&&(C(n.value,s),K(n.value,s))},{immediate:!0}),v(()=>n.value,s=>{const i=O(r);j=void 0,i!=="skip"&&(C(s,i),K(s,i))}),q(I);const B=_("LoadingFirstPage");return v([()=>O(r),c],([s,i])=>{B.value=D(s==="skip",i).status},{immediate:!0}),{error:b,loadMore:s=>{const i=O(r);if(i==="skip")return;const{nextCursor:P,status:l}=D(!1,c.value);if(l!=="CanLoadMore"||P===j)return;const g=G(n.value,P,s);if(!g)return;j=P,b.value=void 0;const p=n.value.at(-1),A=g.at(-2);if(p&&A){const u=M(e.__lunoraRef,R(p,i)),h=M(e.__lunoraRef,R(A,i)),N=k.get(u);if(N&&u!==h){const L=m.get(u);L&&m.set(h,L),N(),k.delete(u),m.delete(u),w.delete(u)}}n.value=g},pageResults:c,status:B}},se=(e,r,y)=>{const{error:f,loadMore:a,pageResults:t,status:o}=Q(e,r,y),n=E(()=>t.value.flatMap(b=>b?.page??[])),c=E(()=>O(r)!=="skip"&&(o.value==="LoadingFirstPage"||o.value==="LoadingMore"));return{error:f,isLoading:c,loadMore:a,results:n,status:o}},ie=(e,r,y)=>{const{initialNumItems:f}=y,{error:a,loadMore:t,pageResults:o,status:n}=Q(e,r,y),c=E(()=>o.value.flatMap(w=>w?[w.page]:[])),b=E(()=>O(r)!=="skip"&&n.value==="LoadingFirstPage"),j=E(()=>n.value==="CanLoadMore"),k=E(()=>O(r)!=="skip"&&n.value==="LoadingMore");return{error:a,fetchNextPage:w=>{t(w??f)},hasNextPage:j,isFetchingNextPage:k,isLoading:b,pages:c,status:n}};export{ie as useInfiniteQuery,se as usePaginatedQuery};