@lunora/svelte 1.0.0-alpha.116 → 1.0.0-alpha.118

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
@@ -530,6 +530,14 @@ interface AuthStore {
530
530
  * reader and close when the last unsubscribes. Calling `setToken(jwt)` after
531
531
  * sign-in refreshes both stores.
532
532
  *
533
+ * Both subscribes are client-only, like every other subscribing primitive here:
534
+ * `$token` / `$user` in a template subscribe during `renderToString`. For the
535
+ * user store that is not just a stray listener — the identity store kicks off
536
+ * `getCurrentUser()` on its first subscriber, so an unguarded server render
537
+ * issues a round-trip against a client whose URL does not resolve there. Both
538
+ * stores still report the client's current values on the server; only the live
539
+ * updates are withheld, until hydration.
540
+ *
533
541
  * Pass an explicit client to bypass the ambient context (useful in tests).
534
542
  */
535
543
  declare const auth: (explicitClient?: ReturnType<typeof getLunoraClient>) => AuthStore;
@@ -571,6 +579,12 @@ type ConnectionStatusStore = Readable<ConnectionStatus>;
571
579
  * `$`-read / `.subscribe()`) and is released by the returned stop function when
572
580
  * the last subscriber goes away, so a store that's never read attaches nothing.
573
581
  *
582
+ * Client-only, like every other subscribing primitive here: `$status` in a
583
+ * template subscribes during `renderToString`, so an unguarded start callback
584
+ * registers a listener per server render. The store still reports the client's
585
+ * current status on the server — that value is a plain read, and nothing
586
+ * transitions during a render.
587
+ *
574
588
  * Pass `client` explicitly, or omit it to resolve the ambient client published
575
589
  * by `setLunoraClient` (which must therefore be called during component init,
576
590
  * before this runs).
package/dist/index.d.ts CHANGED
@@ -530,6 +530,14 @@ interface AuthStore {
530
530
  * reader and close when the last unsubscribes. Calling `setToken(jwt)` after
531
531
  * sign-in refreshes both stores.
532
532
  *
533
+ * Both subscribes are client-only, like every other subscribing primitive here:
534
+ * `$token` / `$user` in a template subscribe during `renderToString`. For the
535
+ * user store that is not just a stray listener — the identity store kicks off
536
+ * `getCurrentUser()` on its first subscriber, so an unguarded server render
537
+ * issues a round-trip against a client whose URL does not resolve there. Both
538
+ * stores still report the client's current values on the server; only the live
539
+ * updates are withheld, until hydration.
540
+ *
533
541
  * Pass an explicit client to bypass the ambient context (useful in tests).
534
542
  */
535
543
  declare const auth: (explicitClient?: ReturnType<typeof getLunoraClient>) => AuthStore;
@@ -571,6 +579,12 @@ type ConnectionStatusStore = Readable<ConnectionStatus>;
571
579
  * `$`-read / `.subscribe()`) and is released by the returned stop function when
572
580
  * the last subscriber goes away, so a store that's never read attaches nothing.
573
581
  *
582
+ * Client-only, like every other subscribing primitive here: `$status` in a
583
+ * template subscribes during `renderToString`, so an unguarded start callback
584
+ * registers a listener per server render. The store still reports the client's
585
+ * current status on the server — that value is a plain read, and nothing
586
+ * transitions during a render.
587
+ *
574
588
  * Pass `client` explicitly, or omit it to resolve the ambient client published
575
589
  * by `setLunoraClient` (which must therefore be called during component init,
576
590
  * before this runs).
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{action as t}from"./packem_shared/action-SjeZUGhX.mjs";import{agent as a}from"./packem_shared/agent-WMVWf1Ks.mjs";import{agentChat as f}from"./packem_shared/agentChat-CX6dTMoY.mjs";import{agentState as n}from"./packem_shared/agentState-CS3hHD6A.mjs";import{agentToolEvents as i}from"./packem_shared/agentToolEvents-DlVpngzv.mjs";import{auth as g,authGate as s}from"./packem_shared/auth-Bew4W5n1.mjs";import{connectionStatus as l}from"./packem_shared/connectionStatus-D9A79Eqw.mjs";import{getLunoraClient as h,setLunoraClient as y}from"./packem_shared/getLunoraClient-DU7BmZy1.mjs";import{flag as L,flags as v}from"./packem_shared/flag-Csh9LBiO.mjs";import{hydratePreloaded as S}from"./packem_shared/hydratePreloaded-BiEJ5Jt2.mjs";import{mutation as q}from"./packem_shared/mutation-DLBr5Op1.mjs";import{mutator as E}from"./packem_shared/mutator-DECDuo94.mjs";import{infiniteQuery as P,paginatedQuery as T}from"./packem_shared/infiniteQuery-XmTlOCqB.mjs";import{presence as k}from"./packem_shared/presence-Ybhe8so-.mjs";import{query as z}from"./packem_shared/query-VzaOi1pv.mjs";import{rateLimit as D}from"./packem_shared/rateLimit-Cli38qWO.mjs";import{stream as H}from"./packem_shared/stream-Cxl8guzh.mjs";import{subscription as J}from"./packem_shared/subscription-NVRm3LD-.mjs";import{voiceAgent as M}from"./packem_shared/voiceAgent-KSChAXsW.mjs";export{t as action,a as agent,f as agentChat,n as agentState,i as agentToolEvents,g as auth,s as authGate,l as connectionStatus,L as flag,v as flags,h as getLunoraClient,S as hydratePreloaded,P as infiniteQuery,q as mutation,E as mutator,T as paginatedQuery,k as presence,z as query,D as rateLimit,y as setLunoraClient,H as stream,J as subscription,M as voiceAgent};
1
+ import{action as t}from"./packem_shared/action-SjeZUGhX.mjs";import{agent as a}from"./packem_shared/agent-WMVWf1Ks.mjs";import{agentChat as f}from"./packem_shared/agentChat-CX6dTMoY.mjs";import{agentState as n}from"./packem_shared/agentState-CS3hHD6A.mjs";import{agentToolEvents as i}from"./packem_shared/agentToolEvents-DlVpngzv.mjs";import{auth as g,authGate as s}from"./packem_shared/auth-BrLyP-oa.mjs";import{connectionStatus as l}from"./packem_shared/connectionStatus-DMx3BE5Q.mjs";import{getLunoraClient as h,setLunoraClient as y}from"./packem_shared/getLunoraClient-DU7BmZy1.mjs";import{flag as L,flags as v}from"./packem_shared/flag-Csh9LBiO.mjs";import{hydratePreloaded as S}from"./packem_shared/hydratePreloaded-BiEJ5Jt2.mjs";import{mutation as q}from"./packem_shared/mutation-DLBr5Op1.mjs";import{mutator as E}from"./packem_shared/mutator-DECDuo94.mjs";import{infiniteQuery as P,paginatedQuery as T}from"./packem_shared/infiniteQuery-CSXXv5DY.mjs";import{presence as k}from"./packem_shared/presence-Ybhe8so-.mjs";import{query as z}from"./packem_shared/query-VzaOi1pv.mjs";import{rateLimit as D}from"./packem_shared/rateLimit-Cli38qWO.mjs";import{stream as H}from"./packem_shared/stream-Cxl8guzh.mjs";import{subscription as J}from"./packem_shared/subscription-NVRm3LD-.mjs";import{voiceAgent as M}from"./packem_shared/voiceAgent-KSChAXsW.mjs";export{t as action,a as agent,f as agentChat,n as agentState,i as agentToolEvents,g as auth,s as authGate,l as connectionStatus,L as flag,v as flags,h as getLunoraClient,S as hydratePreloaded,P as infiniteQuery,q as mutation,E as mutator,T as paginatedQuery,k as presence,z as query,D as rateLimit,y as setLunoraClient,H as stream,J as subscription,M as voiceAgent};
@@ -0,0 +1 @@
1
+ import{getIdentityStore as g}from"@lunora/client/auth";import{readable as i,derived as c}from"svelte/store";import{i as a}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as h}from"./getLunoraClient-DU7BmZy1.mjs";const k=o=>{const e=o??h(),n=g(e),s=i(e.getAuthToken(),t=>(t(e.getAuthToken()),a()?e.onAuthTokenChange(l=>{t(l)}):()=>{})),u=i(n.getUser(),t=>(t(n.getUser()),a()?n.subscribe(()=>{t(n.getUser())}):()=>{}));return{setToken:t=>{e.setAuthToken(t)},token:s,user:u}},T=o=>{const{token:e,user:n}=k(o),s=c([e,n],([r,t])=>r!==null&&t===null);return{isAuthenticated:c([e,n],([r,t])=>r!==null&&t!==null),isLoading:s}};export{k as auth,T as authGate};
@@ -0,0 +1 @@
1
+ import{readable as e}from"svelte/store";import{i}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as c}from"./getLunoraClient-DU7BmZy1.mjs";const m=n=>{const t=n??c();return e(t.connectionStatus(),o=>(o(t.connectionStatus()),i()?t.onConnectionStatus(r=>{o(r)}):()=>{}))};export{m as connectionStatus};
@@ -0,0 +1 @@
1
+ import{initialPages as J,derivePaginationStatus as W,applyLoadMore as v,rebalance as ee}from"@lunora/client/pagination";import{derived as _,writable as T,readable as te,get as x}from"svelte/store";import{i as re}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as G}from"./getLunoraClient-DU7BmZy1.mjs";import{i as H}from"./is-function-reference-abFdrAae.mjs";import{i as ne,s as se}from"./subscribe-reactive-args-DYKqoWhw.mjs";const oe=/["\\\u0000-\u001F\uD800-\uDFFF]/,q=e=>oe.test(e)?JSON.stringify(e):`"${e}"`,F=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 q(e);if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e)){let s="[";for(let n=0;n<e.length;n++)n>0&&(s+=","),s+=F(e[n]);return s+"]"}const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const s=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${s} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const a=e,u=Object.keys(a).sort();let o="{",t=!0;for(const s of u){const n=a[s];n!==void 0&&(t?t=!1:o+=",",o+=q(s),o+=":",o+=F(n))}return o+"}"},D=e=>{let r="";for(let u=0;u<e.length;u+=32768)r+=String.fromCharCode(...e.subarray(u,u+32768));return btoa(r)},p="$lunora.wire$",Q=64,z="__proto__",ie=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},M=(e,r=0)=>{if(r>Q)throw new RangeError(`wire-codec: value nesting exceeds the ${Q}-level limit`);if(e===void 0)return[p,"undefined"];if(e===null)return null;const a=typeof e;if(a==="bigint")return[p,"bigint",e.toString()];if(a==="number"){const t=e;return Number.isNaN(t)?[p,"nan"]:t===1/0?[p,"inf"]:t===-1/0?[p,"-inf"]:t}if(a!=="object")return e;if(e instanceof Date)return[p,"date",M(e.getTime(),r+1)];if(e instanceof Error){const t=e,s={};for(const f of Object.keys(t)){if(t[f]===void 0)continue;const g=M(t[f],r+1);f===z?Object.defineProperty(s,f,{configurable:!0,enumerable:!0,value:g,writable:!0}):s[f]=g}const n=[p,"error",String(t.name),String(t.message),s];return t.cause!==void 0&&n.push(M(t.cause,r+1)),n}if(e instanceof URL)return[p,"url",e.href];if(e instanceof Map)return[p,"map",[...e.entries()].map(([t,s])=>[M(t,r+1),M(s,r+1)])];if(e instanceof Set)return[p,"set",[...e].map(t=>M(t,r+1))];if(e instanceof ArrayBuffer)return[p,"bytes",D(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,s=t.constructor.name,n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return s==="Uint8Array"?[p,"bytes",D(n)]:[p,"bytes",D(n),s]}if(Array.isArray(e)){const t=e.map(s=>M(s,r+1));return t.length>0&&t[0]===p?[p,"arr",t]:t}if(!ie(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 u=e,o={};for(const t of Object.keys(u)){const s=u[t];if(s===void 0)continue;const n=M(s,r+1);t===z?Object.defineProperty(o,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):o[t]=n}return o},ce=e=>F(M(e)),O=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),C=(e,r)=>`${e}::${ce(r)}`,V=(e,r,a,u)=>{const{initialNumItems:o,onError:t,shardKey:s}=u,n=T(J(o)),f=T(),g=T([]),l=new Map,b=new Map,P=new Set;let c=ne(a)?"skip":a;const m=()=>{if(c==="skip"){g.set([]);return}const d=c,h=x(n).map(A=>{const i=C(r.__lunoraRef,O(A,d));return l.get(i)});g.set(h)},I=(d,h)=>{if(c==="skip")return;const A=c,i=w=>C(r.__lunoraRef,O(w,A));for(const w of h){const y=i(w);if(l.has(y))continue;const K=d.find(k=>k.lower===w.lower);if(K){const k=l.get(i(K));k&&l.set(y,k)}}},L=()=>{if(c==="skip"){for(const i of b.values())i();b.clear(),g.set([]);return}const d=c,h=x(n),A=new Set;for(const i of h)A.add(C(r.__lunoraRef,O(i,d)));for(const[i,w]of b)A.has(i)||(w(),b.delete(i),P.delete(i),l.delete(i));for(const i of h){const w=O(i,d),y=C(r.__lunoraRef,w);if(b.has(y))continue;P.add(y);const K=e.subscribe(r,w,k=>{if(l.set(y,k),P.delete(y),f.set(void 0),m(),P.size===0){const N=x(n),j=ee(N,x(g));j&&(I(N,j),n.set(j),$(),m())}},{onError:k=>{P.delete(y),f.set(k);const N=x(n),j=N.at(-1);N.length>1&&j&&!l.has(y)&&C(r.__lunoraRef,O(j,d))===y&&(n.set(N.slice(0,-1)),$(),m()),t?.(k)},shardKey:s});b.set(y,K)}};let E=!1,B=!1;const $=()=>{if(E){B=!0;return}E=!0;try{do B=!1,L();while(B)}finally{E=!1}},R=()=>{for(const d of b.values())d();b.clear(),l.clear(),P.clear()},S=te([],d=>{if(!re())return()=>{};const h=g.subscribe(d),A=se(a,i=>(c=i,$(),m(),()=>{R(),n.set(J(o)),f.set(void 0)}));return()=>{A(),h(),g.set([])}}),X=_(S,d=>W(c==="skip",d).status),Y=_(S,()=>c==="skip"),Z=d=>{if(c==="skip")return;const h=x(g),{nextCursor:A,status:i}=W(!1,h);if(i!=="CanLoadMore")return;const w=x(n),y=v(w,A,d);if(!y)return;const K=w.at(-1),k=y.at(-2);if(K&&k){const N=C(r.__lunoraRef,O(K,c)),j=C(r.__lunoraRef,O(k,c));if(N!==j){const U=l.get(N);U&&(l.set(j,U),l.delete(N))}}f.set(void 0),n.set(y),$(),m()};return{error:{subscribe:f.subscribe},loadMore:Z,pageResults:S,skipped:Y,status:X}};function pe(e,r,a,u){const o=!H(e),t=o?e:G(),s=o?r:e,n=o?a:r,f=o?u:a,{error:g,loadMore:l,pageResults:b,skipped:P,status:c}=V(t,s,n,f),m=_(b,L=>L.flatMap(E=>E?.page??[])),I=_([c,P],([L,E])=>!E&&(L==="LoadingFirstPage"||L==="LoadingMore"));return{error:g,isLoading:I,loadMore:l,results:m,status:c}}function ge(e,r,a,u){const o=!H(e),t=o?e:G(),s=o?r:e,n=o?a:r,f=o?u:a,{initialNumItems:g}=f,{error:l,loadMore:b,pageResults:P,skipped:c,status:m}=V(t,s,n,f),I=_(P,R=>R.flatMap(S=>S?[S.page]:[])),L=_([m,c],([R,S])=>!S&&R==="LoadingFirstPage"),E=_(m,R=>R==="CanLoadMore"),B=_([m,c],([R,S])=>!S&&R==="LoadingMore");return{error:l,fetchNextPage:R=>{b(R??g)},hasNextPage:E,isFetchingNextPage:B,isLoading:L,pages:I,status:m}}export{ge as infiniteQuery,pe as paginatedQuery};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/svelte",
3
- "version": "1.0.0-alpha.116",
3
+ "version": "1.0.0-alpha.118",
4
4
  "description": "Svelte adapter for Lunora — live stores, 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 a}from"@lunora/client/auth";import{readable as c,derived as i}from"svelte/store";import{getLunoraClient as g}from"./getLunoraClient-DU7BmZy1.mjs";const h=r=>{const e=r??g(),n=a(e),s=c(e.getAuthToken(),t=>(t(e.getAuthToken()),e.onAuthTokenChange(l=>{t(l)}))),u=c(n.getUser(),t=>(t(n.getUser()),n.subscribe(()=>{t(n.getUser())})));return{setToken:t=>{e.setAuthToken(t)},token:s,user:u}},A=r=>{const{token:e,user:n}=h(r),s=i([e,n],([o,t])=>o!==null&&t===null);return{isAuthenticated:i([e,n],([o,t])=>o!==null&&t!==null),isLoading:s}};export{h as auth,A as authGate};
@@ -1 +0,0 @@
1
- import{readable as r}from"svelte/store";import{getLunoraClient as c}from"./getLunoraClient-DU7BmZy1.mjs";const u=o=>{const t=o??c();return r(t.connectionStatus(),n=>(n(t.connectionStatus()),t.onConnectionStatus(e=>{n(e)})))};export{u as connectionStatus};
@@ -1 +0,0 @@
1
- import{initialPages as J,derivePaginationStatus as W,applyLoadMore as v,rebalance as ee}from"@lunora/client/pagination";import{derived as _,writable as T,readable as te,get as x}from"svelte/store";import{i as re}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as G}from"./getLunoraClient-DU7BmZy1.mjs";import{i as H}from"./is-function-reference-abFdrAae.mjs";import{i as ne,s as se}from"./subscribe-reactive-args-DYKqoWhw.mjs";const oe=/["\\\u0000-\u001F\uD800-\uDFFF]/,q=e=>oe.test(e)?JSON.stringify(e):`"${e}"`,F=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 q(e);if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e)){let s="[";for(let n=0;n<e.length;n++)n>0&&(s+=","),s+=F(e[n]);return s+"]"}const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const s=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${s} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const a=e,u=Object.keys(a).sort();let o="{",t=!0;for(const s of u){const n=a[s];n!==void 0&&(t?t=!1:o+=",",o+=q(s),o+=":",o+=F(n))}return o+"}"},D=e=>{let r="";for(let u=0;u<e.length;u+=32768)r+=String.fromCharCode(...e.subarray(u,u+32768));return btoa(r)},p="$lunora.wire$",Q=64,z="__proto__",ie=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},M=(e,r=0)=>{if(r>Q)throw new RangeError(`wire-codec: value nesting exceeds the ${Q}-level limit`);if(e===void 0)return[p,"undefined"];if(e===null)return null;const a=typeof e;if(a==="bigint")return[p,"bigint",e.toString()];if(a==="number"){const t=e;return Number.isNaN(t)?[p,"nan"]:t===1/0?[p,"inf"]:t===-1/0?[p,"-inf"]:t}if(a!=="object")return e;if(e instanceof Date)return[p,"date",M(e.getTime(),r+1)];if(e instanceof Error){const t=e,s={};for(const f of Object.keys(t)){if(t[f]===void 0)continue;const g=M(t[f],r+1);f===z?Object.defineProperty(s,f,{configurable:!0,enumerable:!0,value:g,writable:!0}):s[f]=g}const n=[p,"error",t.name,t.message,s];return t.cause!==void 0&&n.push(M(t.cause,r+1)),n}if(e instanceof URL)return[p,"url",e.href];if(e instanceof Map)return[p,"map",[...e.entries()].map(([t,s])=>[M(t,r+1),M(s,r+1)])];if(e instanceof Set)return[p,"set",[...e].map(t=>M(t,r+1))];if(e instanceof ArrayBuffer)return[p,"bytes",D(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,s=t.constructor.name,n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return s==="Uint8Array"?[p,"bytes",D(n)]:[p,"bytes",D(n),s]}if(Array.isArray(e)){const t=e.map(s=>M(s,r+1));return t.length>0&&t[0]===p?[p,"arr",t]:t}if(!ie(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 u=e,o={};for(const t of Object.keys(u)){const s=u[t];if(s===void 0)continue;const n=M(s,r+1);t===z?Object.defineProperty(o,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):o[t]=n}return o},ce=e=>F(M(e)),O=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),C=(e,r)=>`${e}::${ce(r)}`,V=(e,r,a,u)=>{const{initialNumItems:o,onError:t,shardKey:s}=u,n=T(J(o)),f=T(),g=T([]),l=new Map,b=new Map,P=new Set;let c=ne(a)?"skip":a;const m=()=>{if(c==="skip"){g.set([]);return}const d=c,S=x(n).map(A=>{const i=C(r.__lunoraRef,O(A,d));return l.get(i)});g.set(S)},I=(d,S)=>{if(c==="skip")return;const A=c,i=w=>C(r.__lunoraRef,O(w,A));for(const w of S){const y=i(w);if(l.has(y))continue;const K=d.find(k=>k.lower===w.lower);if(K){const k=l.get(i(K));k&&l.set(y,k)}}},L=()=>{if(c==="skip"){for(const i of b.values())i();b.clear(),g.set([]);return}const d=c,S=x(n),A=new Set;for(const i of S)A.add(C(r.__lunoraRef,O(i,d)));for(const[i,w]of b)A.has(i)||(w(),b.delete(i),P.delete(i),l.delete(i));for(const i of S){const w=O(i,d),y=C(r.__lunoraRef,w);if(b.has(y))continue;P.add(y);const K=e.subscribe(r,w,k=>{if(l.set(y,k),P.delete(y),f.set(void 0),m(),P.size===0){const N=x(n),j=ee(N,x(g));j&&(I(N,j),n.set(j),$(),m())}},{onError:k=>{P.delete(y),f.set(k);const N=x(n),j=N.at(-1);N.length>1&&j&&!l.has(y)&&C(r.__lunoraRef,O(j,d))===y&&(n.set(N.slice(0,-1)),$(),m()),t?.(k)},shardKey:s});b.set(y,K)}};let E=!1,B=!1;const $=()=>{if(E){B=!0;return}E=!0;try{do B=!1,L();while(B)}finally{E=!1}},R=()=>{for(const d of b.values())d();b.clear(),l.clear(),P.clear()},h=te([],d=>{if(!re())return()=>{};const S=g.subscribe(d),A=se(a,i=>(c=i,$(),m(),()=>{R(),n.set(J(o)),f.set(void 0)}));return()=>{A(),S(),g.set([])}}),X=_(h,d=>W(c==="skip",d).status),Y=_(h,()=>c==="skip"),Z=d=>{if(c==="skip")return;const S=x(g),{nextCursor:A,status:i}=W(!1,S);if(i!=="CanLoadMore")return;const w=x(n),y=v(w,A,d);if(!y)return;const K=w.at(-1),k=y.at(-2);if(K&&k){const N=C(r.__lunoraRef,O(K,c)),j=C(r.__lunoraRef,O(k,c));if(N!==j){const U=l.get(N);U&&(l.set(j,U),l.delete(N))}}f.set(void 0),n.set(y),$(),m()};return{error:{subscribe:f.subscribe},loadMore:Z,pageResults:h,skipped:Y,status:X}};function pe(e,r,a,u){const o=!H(e),t=o?e:G(),s=o?r:e,n=o?a:r,f=o?u:a,{error:g,loadMore:l,pageResults:b,skipped:P,status:c}=V(t,s,n,f),m=_(b,L=>L.flatMap(E=>E?.page??[])),I=_([c,P],([L,E])=>!E&&(L==="LoadingFirstPage"||L==="LoadingMore"));return{error:g,isLoading:I,loadMore:l,results:m,status:c}}function ge(e,r,a,u){const o=!H(e),t=o?e:G(),s=o?r:e,n=o?a:r,f=o?u:a,{initialNumItems:g}=f,{error:l,loadMore:b,pageResults:P,skipped:c,status:m}=V(t,s,n,f),I=_(P,R=>R.flatMap(h=>h?[h.page]:[])),L=_([m,c],([R,h])=>!h&&R==="LoadingFirstPage"),E=_(m,R=>R==="CanLoadMore"),B=_([m,c],([R,h])=>!h&&R==="LoadingMore");return{error:l,fetchNextPage:R=>{b(R??g)},hasNextPage:E,isFetchingNextPage:B,isLoading:L,pages:I,status:m}}export{ge as infiniteQuery,pe as paginatedQuery};