@lunora/svelte 1.0.0-alpha.114 → 1.0.0-alpha.116
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 +29 -13
- package/dist/index.d.ts +29 -13
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{agentChat-CJ048ZZl.mjs → agentChat-CX6dTMoY.mjs} +1 -1
- package/dist/packem_shared/{agentState-CAqcW2tF.mjs → agentState-CS3hHD6A.mjs} +1 -1
- package/dist/packem_shared/{agentToolEvents-Dyu5BFZn.mjs → agentToolEvents-DlVpngzv.mjs} +1 -1
- package/dist/packem_shared/hydratePreloaded-BiEJ5Jt2.mjs +1 -0
- package/dist/packem_shared/infiniteQuery-XmTlOCqB.mjs +1 -0
- package/dist/packem_shared/presence-Ybhe8so-.mjs +1 -0
- package/dist/packem_shared/query-VzaOi1pv.mjs +1 -0
- package/dist/packem_shared/stream-Cxl8guzh.mjs +1 -0
- package/dist/packem_shared/subscription-NVRm3LD-.mjs +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/hydratePreloaded-Douu4xsv.mjs +0 -1
- package/dist/packem_shared/infiniteQuery-BFYk6edW.mjs +0 -1
- package/dist/packem_shared/presence-BcBuOI0s.mjs +0 -1
- package/dist/packem_shared/query-BMl8EN8S.mjs +0 -1
- package/dist/packem_shared/stream-DGLI262b.mjs +0 -1
- package/dist/packem_shared/subscription-B1x2xDOl.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -99,7 +99,8 @@ interface AgentOptions {
|
|
|
99
99
|
/**
|
|
100
100
|
* Called when the live thread subscription reports an error (a session
|
|
101
101
|
* expiry, an RLS denial). Without it such an error is dropped and `thread` /
|
|
102
|
-
* `status` freeze at their last value
|
|
102
|
+
* `status` freeze at their last value — unlike the React, Angular, Solid and Vue
|
|
103
|
+
* ports, this one leaves the value store untouched on error.
|
|
103
104
|
*/
|
|
104
105
|
onError?: SubscriptionErrorCallback;
|
|
105
106
|
/**
|
|
@@ -268,7 +269,8 @@ interface AgentChatOptions {
|
|
|
268
269
|
/**
|
|
269
270
|
* Called when the live history or thread subscription reports an error (a
|
|
270
271
|
* session expiry, an RLS denial). Without it such an error is dropped and
|
|
271
|
-
* `messages` / `status` freeze at their last value
|
|
272
|
+
* `messages` / `status` freeze at their last value — unlike the React, Angular,
|
|
273
|
+
* Solid and Vue ports, this one leaves the value store untouched on error.
|
|
272
274
|
*/
|
|
273
275
|
onError?: SubscriptionErrorCallback;
|
|
274
276
|
/**
|
|
@@ -634,10 +636,11 @@ declare function flags<T extends Record<string, FlagValue>>(client: LunoraClient
|
|
|
634
636
|
* server pushes (a session expiry, an RLS denial); without it such an error is
|
|
635
637
|
* dropped and the store keeps rendering the SSR snapshot as if it were live.
|
|
636
638
|
*
|
|
637
|
-
* Note on SSR: `readable`'s start callback
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
639
|
+
* Note on SSR: `readable`'s start callback DOES run on the server — svelte's
|
|
640
|
+
* server runtime resolves `{$store}` by subscribing to it — so the socket is
|
|
641
|
+
* opened behind an explicit `isBrowser()` guard rather than left to the store's
|
|
642
|
+
* laziness. On the server the store simply holds the seeded value. The token's
|
|
643
|
+
* `value` is the single source of truth for the first paint either way.
|
|
641
644
|
*/
|
|
642
645
|
declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, client?: LunoraClient, options?: {
|
|
643
646
|
onError?: SubscriptionErrorCallback;
|
|
@@ -828,6 +831,12 @@ interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentRef
|
|
|
828
831
|
intervalMs?: number;
|
|
829
832
|
/** The `api.*` reference for the presence listPresent query. */
|
|
830
833
|
listPresent: L;
|
|
834
|
+
/**
|
|
835
|
+
* Called when the `listPresent` subscription reports an error (a session
|
|
836
|
+
* expiry, an RLS denial). Without it — and without reading `error` — such a
|
|
837
|
+
* failure is invisible and `present` freezes at its last value.
|
|
838
|
+
*/
|
|
839
|
+
onError?: SubscriptionErrorCallback;
|
|
831
840
|
/**
|
|
832
841
|
* Stable id for this presence row. Defaults to a fresh per-mount id.
|
|
833
842
|
* Pass a user/connection id to control deduping across tabs.
|
|
@@ -837,6 +846,8 @@ interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentRef
|
|
|
837
846
|
shardKey?: string;
|
|
838
847
|
}
|
|
839
848
|
interface PresenceHandle<L extends ListPresentReference> {
|
|
849
|
+
/** The `listPresent` subscription's last error, or `undefined`. */
|
|
850
|
+
error: Readable<SubscriptionError | undefined>;
|
|
840
851
|
/** The present members for the room. `undefined` until the first push. */
|
|
841
852
|
present: Readable<ReturnOf<L> | undefined>;
|
|
842
853
|
/** This handle's session id. */
|
|
@@ -882,9 +893,11 @@ type QueryStore<F extends FunctionReference> = Readable<ReturnOf<F> | undefined>
|
|
|
882
893
|
* re-emits on every server delta — the Svelte equivalent of React's `useQuery`.
|
|
883
894
|
*
|
|
884
895
|
* The subscription is opened lazily (inside `readable`'s start callback, on the
|
|
885
|
-
* first `$`-read / `.subscribe()`) and
|
|
886
|
-
*
|
|
887
|
-
*
|
|
896
|
+
* first `$`-read / `.subscribe()`) and only in the browser — a server render
|
|
897
|
+
* reads the store's `undefined` seed and opens nothing. It is torn down by the
|
|
898
|
+
* returned stop function when the last subscriber goes away — so a store that's
|
|
899
|
+
* never read opens no socket, and a component that unmounts releases its
|
|
900
|
+
* subscription. Sharing one
|
|
888
901
|
* store across several components shares a single underlying subscription
|
|
889
902
|
* (the `LunoraClient` de-dupes by `(fn, args, shardKey)`).
|
|
890
903
|
*
|
|
@@ -975,8 +988,9 @@ interface StreamHandle<T> {
|
|
|
975
988
|
/**
|
|
976
989
|
* Open a streaming query and expose its chunks, lifecycle status, and last error
|
|
977
990
|
* as Svelte readable stores. The `chunks` store is lazy: the stream opens on the
|
|
978
|
-
* first subscriber to `chunks` and is cancelled when the last one
|
|
979
|
-
* chunks reset on the next open)
|
|
991
|
+
* first browser-side subscriber to `chunks` and is cancelled when the last one
|
|
992
|
+
* leaves (its chunks reset on the next open); a server render opens nothing.
|
|
993
|
+
* `status` and `error` mirror that same stream.
|
|
980
994
|
*
|
|
981
995
|
* Passing `"skip"` as `args` keeps the stores connected but the stream dormant
|
|
982
996
|
* (`chunks` stays empty, `status` stays `"idle"`). The Svelte counterpart to
|
|
@@ -1001,8 +1015,10 @@ interface SubscriptionHandle<T> {
|
|
|
1001
1015
|
/**
|
|
1002
1016
|
* Create a pair of Svelte readable stores that open a live subscription
|
|
1003
1017
|
* against the Lunora backend. `data` updates on every server push; `error`
|
|
1004
|
-
* captures the last subscription error. Both stores are lazy: the
|
|
1005
|
-
* opens on the first subscriber to `data` and tears
|
|
1018
|
+
* captures the last subscription error. Both stores are lazy: the
|
|
1019
|
+
* subscription opens on the first browser-side subscriber to `data` and tears
|
|
1020
|
+
* down when it stops. A server render subscribes too (svelte resolves `{$store}`
|
|
1021
|
+
* that way) and opens nothing.
|
|
1006
1022
|
*
|
|
1007
1023
|
* Passing `"skip"` as `args` keeps the stores connected but the subscription
|
|
1008
1024
|
* dormant (`data` stays `undefined`). Pass an explicit `client` as the first
|
package/dist/index.d.ts
CHANGED
|
@@ -99,7 +99,8 @@ interface AgentOptions {
|
|
|
99
99
|
/**
|
|
100
100
|
* Called when the live thread subscription reports an error (a session
|
|
101
101
|
* expiry, an RLS denial). Without it such an error is dropped and `thread` /
|
|
102
|
-
* `status` freeze at their last value
|
|
102
|
+
* `status` freeze at their last value — unlike the React, Angular, Solid and Vue
|
|
103
|
+
* ports, this one leaves the value store untouched on error.
|
|
103
104
|
*/
|
|
104
105
|
onError?: SubscriptionErrorCallback;
|
|
105
106
|
/**
|
|
@@ -268,7 +269,8 @@ interface AgentChatOptions {
|
|
|
268
269
|
/**
|
|
269
270
|
* Called when the live history or thread subscription reports an error (a
|
|
270
271
|
* session expiry, an RLS denial). Without it such an error is dropped and
|
|
271
|
-
* `messages` / `status` freeze at their last value
|
|
272
|
+
* `messages` / `status` freeze at their last value — unlike the React, Angular,
|
|
273
|
+
* Solid and Vue ports, this one leaves the value store untouched on error.
|
|
272
274
|
*/
|
|
273
275
|
onError?: SubscriptionErrorCallback;
|
|
274
276
|
/**
|
|
@@ -634,10 +636,11 @@ declare function flags<T extends Record<string, FlagValue>>(client: LunoraClient
|
|
|
634
636
|
* server pushes (a session expiry, an RLS denial); without it such an error is
|
|
635
637
|
* dropped and the store keeps rendering the SSR snapshot as if it were live.
|
|
636
638
|
*
|
|
637
|
-
* Note on SSR: `readable`'s start callback
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
639
|
+
* Note on SSR: `readable`'s start callback DOES run on the server — svelte's
|
|
640
|
+
* server runtime resolves `{$store}` by subscribing to it — so the socket is
|
|
641
|
+
* opened behind an explicit `isBrowser()` guard rather than left to the store's
|
|
642
|
+
* laziness. On the server the store simply holds the seeded value. The token's
|
|
643
|
+
* `value` is the single source of truth for the first paint either way.
|
|
641
644
|
*/
|
|
642
645
|
declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, client?: LunoraClient, options?: {
|
|
643
646
|
onError?: SubscriptionErrorCallback;
|
|
@@ -828,6 +831,12 @@ interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentRef
|
|
|
828
831
|
intervalMs?: number;
|
|
829
832
|
/** The `api.*` reference for the presence listPresent query. */
|
|
830
833
|
listPresent: L;
|
|
834
|
+
/**
|
|
835
|
+
* Called when the `listPresent` subscription reports an error (a session
|
|
836
|
+
* expiry, an RLS denial). Without it — and without reading `error` — such a
|
|
837
|
+
* failure is invisible and `present` freezes at its last value.
|
|
838
|
+
*/
|
|
839
|
+
onError?: SubscriptionErrorCallback;
|
|
831
840
|
/**
|
|
832
841
|
* Stable id for this presence row. Defaults to a fresh per-mount id.
|
|
833
842
|
* Pass a user/connection id to control deduping across tabs.
|
|
@@ -837,6 +846,8 @@ interface PresenceOptions<H extends HeartbeatReference, L extends ListPresentRef
|
|
|
837
846
|
shardKey?: string;
|
|
838
847
|
}
|
|
839
848
|
interface PresenceHandle<L extends ListPresentReference> {
|
|
849
|
+
/** The `listPresent` subscription's last error, or `undefined`. */
|
|
850
|
+
error: Readable<SubscriptionError | undefined>;
|
|
840
851
|
/** The present members for the room. `undefined` until the first push. */
|
|
841
852
|
present: Readable<ReturnOf<L> | undefined>;
|
|
842
853
|
/** This handle's session id. */
|
|
@@ -882,9 +893,11 @@ type QueryStore<F extends FunctionReference> = Readable<ReturnOf<F> | undefined>
|
|
|
882
893
|
* re-emits on every server delta — the Svelte equivalent of React's `useQuery`.
|
|
883
894
|
*
|
|
884
895
|
* The subscription is opened lazily (inside `readable`'s start callback, on the
|
|
885
|
-
* first `$`-read / `.subscribe()`) and
|
|
886
|
-
*
|
|
887
|
-
*
|
|
896
|
+
* first `$`-read / `.subscribe()`) and only in the browser — a server render
|
|
897
|
+
* reads the store's `undefined` seed and opens nothing. It is torn down by the
|
|
898
|
+
* returned stop function when the last subscriber goes away — so a store that's
|
|
899
|
+
* never read opens no socket, and a component that unmounts releases its
|
|
900
|
+
* subscription. Sharing one
|
|
888
901
|
* store across several components shares a single underlying subscription
|
|
889
902
|
* (the `LunoraClient` de-dupes by `(fn, args, shardKey)`).
|
|
890
903
|
*
|
|
@@ -975,8 +988,9 @@ interface StreamHandle<T> {
|
|
|
975
988
|
/**
|
|
976
989
|
* Open a streaming query and expose its chunks, lifecycle status, and last error
|
|
977
990
|
* as Svelte readable stores. The `chunks` store is lazy: the stream opens on the
|
|
978
|
-
* first subscriber to `chunks` and is cancelled when the last one
|
|
979
|
-
* chunks reset on the next open)
|
|
991
|
+
* first browser-side subscriber to `chunks` and is cancelled when the last one
|
|
992
|
+
* leaves (its chunks reset on the next open); a server render opens nothing.
|
|
993
|
+
* `status` and `error` mirror that same stream.
|
|
980
994
|
*
|
|
981
995
|
* Passing `"skip"` as `args` keeps the stores connected but the stream dormant
|
|
982
996
|
* (`chunks` stays empty, `status` stays `"idle"`). The Svelte counterpart to
|
|
@@ -1001,8 +1015,10 @@ interface SubscriptionHandle<T> {
|
|
|
1001
1015
|
/**
|
|
1002
1016
|
* Create a pair of Svelte readable stores that open a live subscription
|
|
1003
1017
|
* against the Lunora backend. `data` updates on every server push; `error`
|
|
1004
|
-
* captures the last subscription error. Both stores are lazy: the
|
|
1005
|
-
* opens on the first subscriber to `data` and tears
|
|
1018
|
+
* captures the last subscription error. Both stores are lazy: the
|
|
1019
|
+
* subscription opens on the first browser-side subscriber to `data` and tears
|
|
1020
|
+
* down when it stops. A server render subscribes too (svelte resolves `{$store}`
|
|
1021
|
+
* that way) and opens nothing.
|
|
1006
1022
|
*
|
|
1007
1023
|
* Passing `"skip"` as `args` keeps the stores connected but the subscription
|
|
1008
1024
|
* dormant (`data` stays `undefined`). Pass an explicit `client` as the first
|
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-
|
|
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 +1 @@
|
|
|
1
|
-
import{reconcileOptimistic as k,maxSeq as C}from"@lunora/client";import{writable as g}from"svelte/store";import{i as f}from"./is-browser-BEdfLJHK.mjs";import{isClient as J,NO_MUTATION_REF as O}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as P}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as h}from"./mutation-DLBr5Op1.mjs";import{stream as Q}from"./stream-
|
|
1
|
+
import{reconcileOptimistic as k,maxSeq as C}from"@lunora/client";import{writable as g}from"svelte/store";import{i as f}from"./is-browser-BEdfLJHK.mjs";import{isClient as J,NO_MUTATION_REF as O}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as P}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as h}from"./mutation-DLBr5Op1.mjs";import{stream as Q}from"./stream-Cxl8guzh.mjs";const V={__lunoraRef:""},W=(n,d)=>{const{api:a,cancel:u,limit:l,onError:v,send:E,sendArgs:I,stream:y,threadKey:r}=d,M=h(n,E),_=h(n,u??O),q=h(n,a.agents.agentResolveApproval);let m,o=[],i=[],x=[],S=0;const b=g([]),w=g(),A=g(""),p=()=>{const t=k(i,o);if(t.length===0){b.set(o);return}const s=C(o);b.set([...o,...t.map((e,c)=>({content:e.content,optimistic:!0,role:"user",seq:s+1+c}))])},T=()=>{const t=o.filter(e=>e.role==="assistant").length,s=x.filter(e=>e.kind!=="progress"&&e.threadKey===r&&e.turn>=t).map(e=>e.text).join("");A.set(s)},j=y===void 0?"skip":{key:r},N=f()?Q(n,y??V,j).chunks.subscribe(t=>{x=t,T()}):()=>{},D=l===void 0?{key:r}:{key:r,limit:l},F=f()?n.subscribe(a.agents.agentMessages,D,t=>{o=t,p(),T()},{onError:v}):()=>{},H=f()?n.subscribe(a.agents.agentThread,{key:r},t=>{m=t,w.set(m?.status)},{onError:v}):()=>{},K=async(t,s)=>{const e=S;S+=1;const c=C(o);i=[...k(i,o),{content:t,id:e,maxDurableSeqAtSend:c}],p();try{await M.mutate({input:t,threadKey:r,...I,...s})}catch(z){throw i=i.filter(G=>G.id!==e),p(),z}},R=async(t,s,e)=>{const c=m?.instanceId;if(c===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await q.mutate({decision:t,instanceId:c,threadKey:r,toolCallId:s,...e===void 0?{}:{note:e}})},B=async(t,s)=>R("approve",t,s),L=async(t,s)=>R("reject",t,s),U=async()=>{const t=m?.instanceId;u===void 0||t===void 0||await _.mutate({instanceId:t,threadKey:r})},$=()=>{F(),H(),N()};return{approve:B,cancel:U,messages:{subscribe:b.subscribe},reject:L,send:K,status:{subscribe:w.subscribe},streamingText:{subscribe:A.subscribe},teardown:$}};function rt(n,d){const a=J(n),u=a?n:P();return W(u,a?d:n)}export{rt as agentChat};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{derived as c}from"svelte/store";import{isClient as p}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as f}from"./getLunoraClient-DU7BmZy1.mjs";import{subscription as d}from"./subscription-
|
|
1
|
+
import{derived as c}from"svelte/store";import{isClient as p}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as f}from"./getLunoraClient-DU7BmZy1.mjs";import{subscription as d}from"./subscription-NVRm3LD-.mjs";function h(t,r){const o=p(t),n=o?t:f(),e=o?r:t,{data:i,error:a}=d(n,e.api.agents.agentState,{key:e.threadKey}),s=c(i,m=>m);return{error:a,state:s}}export{h as agentState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{derived as y}from"svelte/store";import{isClient as m}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as I}from"./getLunoraClient-DU7BmZy1.mjs";import{stream as N}from"./stream-
|
|
1
|
+
import{derived as y}from"svelte/store";import{isClient as m}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as I}from"./getLunoraClient-DU7BmZy1.mjs";import{stream as N}from"./stream-Cxl8guzh.mjs";import{subscription as h}from"./subscription-NVRm3LD-.mjs";const k={__lunoraRef:""},q=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(l=>({input:l.input,seq:t.seq,toolCallId:l.id,toolName:l.name,type:"call"}));if(t.role==="tool")return t.status==="awaiting_approval"?[{seq:t.seq,type:"awaiting-approval",...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]:[{output:t.content,seq:t.seq,type:"result",...t.status==="approved"||t.status==="rejected"?{status:t.status}:{},...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]};function K(t,l){const n=m(t),a=n?t:I(),u=n?l:t,{api:p,limit:e,stream:i,threadKey:r}=u,s=e===void 0?{key:r}:{key:r,limit:e},{data:c}=h(a,p.agents.agentMessages,s),v=N(a,i??k,i===void 0?"skip":{key:r});return{events:y([c,v.chunks],([f,C])=>{const d=(f??[]).flatMap(o=>q(o)??[]);for(const o of C)o.kind==="progress"&&o.threadKey===r&&d.push({data:o.data,toolCallId:o.toolCallId,type:"progress"});return d})}}export{K as agentToolEvents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as l}from"svelte/store";import{i as d}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as m}from"./getLunoraClient-DU7BmZy1.mjs";const g=(r,o,e={})=>{const t=o??m(),{args:n,functionPath:s,shardKey:a,value:i}=r,u={__lunoraRef:s};return l(i,f=>d()?t.subscribe(u,n,c=>{f(c)},{onError:e.onError,shardKey:a}):()=>{})};export{g as hydratePreloaded};
|
|
@@ -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",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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{onDestroy as w}from"svelte";import{writable as C,readable as D}from"svelte/store";import{i as g}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as E}from"./getLunoraClient-DU7BmZy1.mjs";const I=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const e=crypto.getRandomValues(new Uint8Array(16));return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},S=1e4,L=(e,t,n)=>{const{heartbeat:o,intervalMs:c=S,listPresent:y,shardKey:i}=n,d=n.sessionId??I();let f=n.data;const s=()=>{const r={roomId:t,sessionId:d,...f===void 0?{}:{data:f}};e.mutation(o,r,{shardKey:i}).catch(()=>{})},h=r=>{f=r,s()},m=()=>{typeof document<"u"&&document.visibilityState==="visible"&&s()};let u,p;g()&&(s(),u=setInterval(s,c),typeof document<"u"&&document.addEventListener("visibilitychange",m),p=e.acquireConnectionContext({roomId:t,sessionId:d},{shardKey:i}));const l=C(),U=D(void 0,r=>{if(g())return e.subscribe(y,{roomId:t},a=>{r(a),l.set(void 0)},{onError:a=>{l.set(a),n.onError?.(a)},shardKey:i})});let v=!1;const b=()=>{v||(v=!0,u!==void 0&&clearInterval(u),typeof document<"u"&&document.removeEventListener("visibilitychange",m),p?.())};try{w(b)}catch{}return{error:{subscribe:l.subscribe},present:U,sessionId:d,setData:h,teardown:b}};function M(e,t,n){const o=typeof e!="string",c=o?e:E();return L(c,o?t:e,o?n:t)}export{M as presence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as u}from"@lunora/client/query";import{readable as d}from"svelte/store";import{i as b}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as v}from"./getLunoraClient-DU7BmZy1.mjs";import{i as y}from"./is-function-reference-abFdrAae.mjs";import{s as R}from"./subscribe-reactive-args-DYKqoWhw.mjs";function q(o,i,t,s){const r=!y(o),a=r?o:v(),c=r?i:o,p=r?t:i,n=(r?s:t)??{};return d(void 0,e=>b()?R(p,f=>(e(void 0),u(a,c,f,{onData:m=>{e(m)},onError:n.onError,onReset:()=>{e(void 0)}},{shardKey:n.shardKey}))):()=>{})}export{q as query};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as p,readable as g}from"svelte/store";import{i as B}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as R}from"./getLunoraClient-DU7BmZy1.mjs";import{i as I}from"./is-function-reference-abFdrAae.mjs";function z(c,u,f,h){const t=!I(c),v=t?c:R(),w=t?u:c,l=t?f:u,E=(t?h:f)??{},{durable:k,maxBuffer:x,shardKey:y}=E,e=p("idle"),n=p();let s;const m=()=>{s?.()},C=g([],b=>{if(b([]),n.set(void 0),!B())return e.set("idle"),()=>{};if(l==="skip")return e.set("idle"),()=>{};e.set("streaming");let o=!0,i=[];const d=v.stream(w,l,{durable:k,maxBuffer:x,shardKey:y}),a=()=>{d.cancel()};return s=a,(async()=>{try{for await(const r of d){if(!o)return;i=[...i,r],b(i)}o&&e.set("complete")}catch(r){if(!o)return;n.set(r instanceof Error?r:new Error(String(r))),e.set("error")}})().catch(()=>{}),()=>{o=!1,a(),s===a&&(s=void 0)}}),S=()=>{m()};return{cancel:m,chunks:C,error:{subscribe:n.subscribe},status:{subscribe:e.subscribe},teardown:S}}export{z as stream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as l}from"@lunora/client/query";import{LunoraError as w}from"@lunora/errors";import{writable as R,readable as h}from"svelte/store";import{i as x}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as y}from"./getLunoraClient-DU7BmZy1.mjs";import{i as C}from"./is-function-reference-abFdrAae.mjs";import{s as E}from"./subscribe-reactive-args-DYKqoWhw.mjs";function q(t,n,i,c){const e=!C(t),m=e?t:y(),d=e?n:t,f=e?i:n,p=(e?c:i)??{},{shardKey:u,onError:v}=p,r=R();return{data:h(void 0,s=>{if(!x())return()=>{};const b=E(f,g=>(s(void 0),r.set(void 0),l(m,d,g,{onData:o=>{s(o),r.set(void 0)},onError:o=>{const a=o.code===void 0?new Error(o.message):new w(o.code,o.message);r.set(a),v?.(a)},onReset:()=>{s(void 0)}},{shardKey:u})));return()=>{b(),r.set(void 0)}}),error:{subscribe:r.subscribe}}}export{q as subscription};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/svelte",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.116",
|
|
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.
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.81",
|
|
58
58
|
"@lunora/errors": "1.0.0-alpha.32",
|
|
59
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
59
|
+
"@lunora/ratelimit": "1.0.0-alpha.40",
|
|
60
60
|
"@visulima/storage-client": "1.0.2"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{readable as d}from"svelte/store";import{getLunoraClient as f}from"./getLunoraClient-DU7BmZy1.mjs";const h=(r,o,e={})=>{const n=o??f(),{args:t,functionPath:a,shardKey:s,value:c}=r,i={__lunoraRef:a};return d(c,l=>n.subscribe(i,t,u=>{l(u)},{onError:e.onError,shardKey:s}))};export{h as hydratePreloaded};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{initialPages as J,derivePaginationStatus as W,applyLoadMore as Z,rebalance as v}from"@lunora/client/pagination";import{derived as x,writable as B,readable as ee,get as L}from"svelte/store";import{getLunoraClient as G}from"./getLunoraClient-DU7BmZy1.mjs";import{i as H}from"./is-function-reference-abFdrAae.mjs";import{i as te,s as re}from"./subscribe-reactive-args-DYKqoWhw.mjs";const ne=/["\\\u0000-\u001F\uD800-\uDFFF]/,q=e=>ne.test(e)?JSON.stringify(e):`"${e}"`,D=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+=D(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+=D(n))}return o+"}"},T=e=>{let r="";for(let u=0;u<e.length;u+=32768)r+=String.fromCharCode(...e.subarray(u,u+32768));return btoa(r)},g="$lunora.wire$",Q=64,z="__proto__",se=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},E=(e,r=0)=>{if(r>Q)throw new RangeError(`wire-codec: value nesting exceeds the ${Q}-level limit`);if(e===void 0)return[g,"undefined"];if(e===null)return null;const a=typeof e;if(a==="bigint")return[g,"bigint",e.toString()];if(a==="number"){const t=e;return Number.isNaN(t)?[g,"nan"]:t===1/0?[g,"inf"]:t===-1/0?[g,"-inf"]:t}if(a!=="object")return e;if(e instanceof Date)return[g,"date",E(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 b=E(t[f],r+1);f===z?Object.defineProperty(s,f,{configurable:!0,enumerable:!0,value:b,writable:!0}):s[f]=b}const n=[g,"error",t.name,t.message,s];return t.cause!==void 0&&n.push(E(t.cause,r+1)),n}if(e instanceof URL)return[g,"url",e.href];if(e instanceof Map)return[g,"map",[...e.entries()].map(([t,s])=>[E(t,r+1),E(s,r+1)])];if(e instanceof Set)return[g,"set",[...e].map(t=>E(t,r+1))];if(e instanceof ArrayBuffer)return[g,"bytes",T(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"?[g,"bytes",T(n)]:[g,"bytes",T(n),s]}if(Array.isArray(e)){const t=e.map(s=>E(s,r+1));return t.length>0&&t[0]===g?[g,"arr",t]:t}if(!se(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=E(s,r+1);t===z?Object.defineProperty(o,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):o[t]=n}return o},oe=e=>D(E(e)),_=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),K=(e,r)=>`${e}::${oe(r)}`,V=(e,r,a,u)=>{const{initialNumItems:o,onError:t,shardKey:s}=u,n=B(J(o)),f=B(),b=B([]),l=new Map,m=new Map,P=new Set;let c=te(a)?"skip":a;const A=()=>{if(c==="skip"){b.set([]);return}const y=c,h=L(n).map(k=>{const i=K(r.__lunoraRef,_(k,y));return l.get(i)});b.set(h)},j=(y,h)=>{if(c==="skip")return;const k=c,i=w=>K(r.__lunoraRef,_(w,k));for(const w of h){const d=i(w);if(l.has(d))continue;const M=y.find(R=>R.lower===w.lower);if(M){const R=l.get(i(M));R&&l.set(d,R)}}},O=()=>{if(c==="skip"){for(const i of m.values())i();m.clear(),b.set([]);return}const y=c,h=L(n),k=new Set;for(const i of h)k.add(K(r.__lunoraRef,_(i,y)));for(const[i,w]of m)k.has(i)||(w(),m.delete(i),P.delete(i),l.delete(i));for(const i of h){const w=_(i,y),d=K(r.__lunoraRef,w);if(m.has(d))continue;P.add(d);const M=e.subscribe(r,w,R=>{if(l.set(d,R),P.delete(d),f.set(void 0),A(),P.size===0){const S=L(n),N=v(S,L(b));N&&(j(S,N),n.set(N),p(),A())}},{onError:R=>{P.delete(d),f.set(R);const S=L(n),N=S.at(-1);S.length>1&&N&&!l.has(d)&&K(r.__lunoraRef,_(N,y))===d&&(n.set(S.slice(0,-1)),p(),A()),t?.(R)},shardKey:s});m.set(d,M)}};let C=!1,I=!1;const p=()=>{if(C){I=!0;return}C=!0;try{do I=!1,O();while(I)}finally{C=!1}},$=()=>{for(const y of m.values())y();m.clear(),l.clear(),P.clear()},F=ee([],y=>{const h=b.subscribe(y),k=re(a,i=>(c=i,p(),A(),()=>{$(),n.set(J(o)),f.set(void 0)}));return()=>{k(),h(),b.set([])}}),X=x(F,y=>W(c==="skip",y).status),Y=y=>{if(c==="skip")return;const h=L(b),{nextCursor:k,status:i}=W(!1,h);if(i!=="CanLoadMore")return;const w=L(n),d=Z(w,k,y);if(!d)return;const M=w.at(-1),R=d.at(-2);if(M&&R){const S=K(r.__lunoraRef,_(M,c)),N=K(r.__lunoraRef,_(R,c));if(S!==N){const U=l.get(S);U&&(l.set(N,U),l.delete(S))}}f.set(void 0),n.set(d),p(),A()};return{error:{subscribe:f.subscribe},loadMore:Y,pageResults:F,status:X}};function le(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:b,loadMore:l,pageResults:m,status:P}=V(t,s,n,f),c=x(m,j=>j.flatMap(O=>O?.page??[])),A=x(P,j=>j==="LoadingFirstPage"||j==="LoadingMore");return{error:b,isLoading:A,loadMore:l,results:c,status:P}}function ye(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:b}=f,{error:l,loadMore:m,pageResults:P,status:c}=V(t,s,n,f),A=x(P,p=>p.flatMap($=>$?[$.page]:[])),j=x(c,p=>p==="LoadingFirstPage"),O=x(c,p=>p==="CanLoadMore"),C=x(c,p=>p==="LoadingMore");return{error:l,fetchNextPage:p=>{m(p??b)},hasNextPage:O,isFetchingNextPage:C,isLoading:j,pages:A,status:c}}export{ye as infiniteQuery,le as paginatedQuery};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{onDestroy as U}from"svelte";import{readable as C}from"svelte/store";import{i as v}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as D}from"./getLunoraClient-DU7BmZy1.mjs";const I=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const t=crypto.getRandomValues(new Uint8Array(16));return Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},w=1e4,E=(t,e,n)=>{const{heartbeat:o,intervalMs:a=w,listPresent:u,shardKey:i}=n,c=n.sessionId??I();let d=n.data;const s=()=>{const r={roomId:e,sessionId:c,...d===void 0?{}:{data:d}};t.mutation(o,r,{shardKey:i}).catch(()=>{})},b=r=>{d=r,s()},l=()=>{typeof document<"u"&&document.visibilityState==="visible"&&s()};let f,y;v()&&(s(),f=setInterval(s,a),typeof document<"u"&&document.addEventListener("visibilitychange",l),y=t.acquireConnectionContext({roomId:e,sessionId:c},{shardKey:i}));const g=C(void 0,r=>{if(v())return t.subscribe(u,{roomId:e},h=>{r(h)},{shardKey:i})});let p=!1;const m=()=>{p||(p=!0,f!==void 0&&clearInterval(f),typeof document<"u"&&document.removeEventListener("visibilitychange",l),y?.())};try{U(m)}catch{}return{present:g,sessionId:c,setData:b,teardown:m}};function A(t,e,n){const o=typeof t!="string",a=o?t:D();return E(a,o?e:t,o?n:e)}export{A as presence};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createQuerySubscription as d}from"@lunora/client/query";import{readable as u}from"svelte/store";import{getLunoraClient as b}from"./getLunoraClient-DU7BmZy1.mjs";import{i as v}from"./is-function-reference-abFdrAae.mjs";import{s as y}from"./subscribe-reactive-args-DYKqoWhw.mjs";function K(r,t,i,s){const o=!v(r),a=o?r:b(),c=o?t:r,p=o?i:t,n=(o?s:i)??{};return u(void 0,e=>y(p,f=>(e(void 0),d(a,c,f,{onData:m=>{e(m)},onError:n.onError,onReset:()=>{e(void 0)}},{shardKey:n.shardKey}))))}export{K as query};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{writable as p,readable as g}from"svelte/store";import{getLunoraClient as R}from"./getLunoraClient-DU7BmZy1.mjs";import{i as B}from"./is-function-reference-abFdrAae.mjs";function j(c,u,l,h){const r=!B(c),v=r?c:R(),w=r?u:c,f=r?l:u,E=(r?h:l)??{},{durable:k,maxBuffer:x,shardKey:y}=E,e=p("idle"),n=p();let s;const b=()=>{s?.()},C=g([],m=>{if(m([]),n.set(void 0),f==="skip")return e.set("idle"),()=>{};e.set("streaming");let o=!0,a=[];const d=v.stream(w,f,{durable:k,maxBuffer:x,shardKey:y}),i=()=>{d.cancel()};return s=i,(async()=>{try{for await(const t of d){if(!o)return;a=[...a,t],m(a)}o&&e.set("complete")}catch(t){if(!o)return;n.set(t instanceof Error?t:new Error(String(t))),e.set("error")}})().catch(()=>{}),()=>{o=!1,i(),s===i&&(s=void 0)}}),S=()=>{b()};return{cancel:b,chunks:C,error:{subscribe:n.subscribe},status:{subscribe:e.subscribe},teardown:S}}export{j as stream};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createQuerySubscription as l}from"@lunora/client/query";import{LunoraError as R}from"@lunora/errors";import{writable as w,readable as h}from"svelte/store";import{getLunoraClient as x}from"./getLunoraClient-DU7BmZy1.mjs";import{i as y}from"./is-function-reference-abFdrAae.mjs";import{s as C}from"./subscribe-reactive-args-DYKqoWhw.mjs";function k(t,n,i,c){const r=!y(t),m=r?t:x(),d=r?n:t,p=r?i:n,f=(r?c:i)??{},{shardKey:u,onError:v}=f,e=w();return{data:h(void 0,s=>{const b=C(p,g=>(s(void 0),e.set(void 0),l(m,d,g,{onData:o=>{s(o),e.set(void 0)},onError:o=>{const a=o.code===void 0?new Error(o.message):new R(o.code,o.message);e.set(a),v?.(a)},onReset:()=>{s(void 0)}},{shardKey:u})));return()=>{b(),e.set(void 0)}}),error:{subscribe:e.subscribe}}}export{k as subscription};
|