@lunora/react 1.0.0-alpha.304 → 1.0.0-alpha.305
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
|
@@ -1266,6 +1266,13 @@ type HeartbeatReference = FunctionReference<"mutation", {
|
|
|
1266
1266
|
type ListPresentReference = FunctionReference<"query", {
|
|
1267
1267
|
roomId: string;
|
|
1268
1268
|
}>;
|
|
1269
|
+
/**
|
|
1270
|
+
* The presence `leave` mutation: `definePresence(...).functions.leave`.
|
|
1271
|
+
*/
|
|
1272
|
+
type LeaveReference = FunctionReference<"mutation", {
|
|
1273
|
+
roomId: string;
|
|
1274
|
+
sessionId: string;
|
|
1275
|
+
}>;
|
|
1269
1276
|
interface UsePresenceOptions<H extends HeartbeatReference, L extends ListPresentReference> {
|
|
1270
1277
|
/** Awareness blob for the first heartbeat (selection, cursor, name, color…). */
|
|
1271
1278
|
data?: Record<string, unknown>;
|
|
@@ -1273,6 +1280,13 @@ interface UsePresenceOptions<H extends HeartbeatReference, L extends ListPresent
|
|
|
1273
1280
|
heartbeat: H;
|
|
1274
1281
|
/** Heartbeat cadence in ms. Defaults to 10s — keep it well under the server TTL. */
|
|
1275
1282
|
intervalMs?: number;
|
|
1283
|
+
/**
|
|
1284
|
+
* The `api.*` reference for the presence `leave` mutation. When given, leaving a room (a room
|
|
1285
|
+
* change, or teardown) removes this session's row there at once, unless another view on the same
|
|
1286
|
+
* client still shows that session in that room; without it the old room lists the session until
|
|
1287
|
+
* its last heartbeat ages out (`ttlMs`).
|
|
1288
|
+
*/
|
|
1289
|
+
leave?: LeaveReference;
|
|
1276
1290
|
/** The `api.*` reference for the presence listPresent query. */
|
|
1277
1291
|
listPresent: L;
|
|
1278
1292
|
/**
|
|
@@ -1576,4 +1590,4 @@ interface UseVoiceAgentResult {
|
|
|
1576
1590
|
* `createSocket`) so the hook is drivable outside a browser.
|
|
1577
1591
|
*/
|
|
1578
1592
|
declare const useVoiceAgent: (options: UseVoiceAgentOptions) => UseVoiceAgentResult;
|
|
1579
|
-
export { type ActionHook, type AdminAuthListResult, type AgentApprovalGrant, type AgentApprovalTarget, type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, type AuthState, Authenticated, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type MutatorHook, type PageItemOf, type PaginatedArgs, type PendingApproval, Unauthenticated, type UseAgentApi, type UseAgentApprovalsApi, type UseAgentApprovalsOptions, type UseAgentApprovalsResult, type UseAgentChatApi, type UseAgentChatOptions, type UseAgentChatResult, type UseAgentOptions, type UseAgentResult, type UseAgentStateApi, type UseAgentStateOptions, type UseAgentStateResult, type UseAgentToolEventsApi, type UseAgentToolEventsOptions, type UseAgentToolEventsResult, type UseAuthResult, type UseAuthSessionsOptions, type UseAuthUsersOptions, type UseHttpStreamOptions, type UseHttpStreamResult, type UseImpersonateResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseLiveTopicOptions, type UseLiveTopicResult, type UseMutationCallOptions, type UseOrganizationsOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseSignUpInvitationsOptions, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, type UseVoiceAgentOptions, type UseVoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, hydratePreloaded, useAction, useAgent, useAgentApprovals, useAgentChat, useAgentState, useAgentToolEvents, useAuth, useAuthSessions, useAuthState, useAuthUsers, useClientQuery, useConnectionStatus, useFlag, useFlags, useHttpStream, useImpersonate, useInfiniteQuery, useLiveTopic, useLunora, useMutation, useMutator, useOrganizations, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useSignUpInvitations, useStream, useSubscription, useSuspenseQuery, useVoiceAgent };
|
|
1593
|
+
export { type ActionHook, type AdminAuthListResult, type AgentApprovalGrant, type AgentApprovalTarget, type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, type AuthState, Authenticated, type FlagValue, type HeartbeatReference, type LeaveReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type MutatorHook, type PageItemOf, type PaginatedArgs, type PendingApproval, Unauthenticated, type UseAgentApi, type UseAgentApprovalsApi, type UseAgentApprovalsOptions, type UseAgentApprovalsResult, type UseAgentChatApi, type UseAgentChatOptions, type UseAgentChatResult, type UseAgentOptions, type UseAgentResult, type UseAgentStateApi, type UseAgentStateOptions, type UseAgentStateResult, type UseAgentToolEventsApi, type UseAgentToolEventsOptions, type UseAgentToolEventsResult, type UseAuthResult, type UseAuthSessionsOptions, type UseAuthUsersOptions, type UseHttpStreamOptions, type UseHttpStreamResult, type UseImpersonateResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseLiveTopicOptions, type UseLiveTopicResult, type UseMutationCallOptions, type UseOrganizationsOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseSignUpInvitationsOptions, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, type UseVoiceAgentOptions, type UseVoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, hydratePreloaded, useAction, useAgent, useAgentApprovals, useAgentChat, useAgentState, useAgentToolEvents, useAuth, useAuthSessions, useAuthState, useAuthUsers, useClientQuery, useConnectionStatus, useFlag, useFlags, useHttpStream, useImpersonate, useInfiniteQuery, useLiveTopic, useLunora, useMutation, useMutator, useOrganizations, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useSignUpInvitations, useStream, useSubscription, useSuspenseQuery, useVoiceAgent };
|
package/dist/index.d.ts
CHANGED
|
@@ -1266,6 +1266,13 @@ type HeartbeatReference = FunctionReference<"mutation", {
|
|
|
1266
1266
|
type ListPresentReference = FunctionReference<"query", {
|
|
1267
1267
|
roomId: string;
|
|
1268
1268
|
}>;
|
|
1269
|
+
/**
|
|
1270
|
+
* The presence `leave` mutation: `definePresence(...).functions.leave`.
|
|
1271
|
+
*/
|
|
1272
|
+
type LeaveReference = FunctionReference<"mutation", {
|
|
1273
|
+
roomId: string;
|
|
1274
|
+
sessionId: string;
|
|
1275
|
+
}>;
|
|
1269
1276
|
interface UsePresenceOptions<H extends HeartbeatReference, L extends ListPresentReference> {
|
|
1270
1277
|
/** Awareness blob for the first heartbeat (selection, cursor, name, color…). */
|
|
1271
1278
|
data?: Record<string, unknown>;
|
|
@@ -1273,6 +1280,13 @@ interface UsePresenceOptions<H extends HeartbeatReference, L extends ListPresent
|
|
|
1273
1280
|
heartbeat: H;
|
|
1274
1281
|
/** Heartbeat cadence in ms. Defaults to 10s — keep it well under the server TTL. */
|
|
1275
1282
|
intervalMs?: number;
|
|
1283
|
+
/**
|
|
1284
|
+
* The `api.*` reference for the presence `leave` mutation. When given, leaving a room (a room
|
|
1285
|
+
* change, or teardown) removes this session's row there at once, unless another view on the same
|
|
1286
|
+
* client still shows that session in that room; without it the old room lists the session until
|
|
1287
|
+
* its last heartbeat ages out (`ttlMs`).
|
|
1288
|
+
*/
|
|
1289
|
+
leave?: LeaveReference;
|
|
1276
1290
|
/** The `api.*` reference for the presence listPresent query. */
|
|
1277
1291
|
listPresent: L;
|
|
1278
1292
|
/**
|
|
@@ -1576,4 +1590,4 @@ interface UseVoiceAgentResult {
|
|
|
1576
1590
|
* `createSocket`) so the hook is drivable outside a browser.
|
|
1577
1591
|
*/
|
|
1578
1592
|
declare const useVoiceAgent: (options: UseVoiceAgentOptions) => UseVoiceAgentResult;
|
|
1579
|
-
export { type ActionHook, type AdminAuthListResult, type AgentApprovalGrant, type AgentApprovalTarget, type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, type AuthState, Authenticated, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type MutatorHook, type PageItemOf, type PaginatedArgs, type PendingApproval, Unauthenticated, type UseAgentApi, type UseAgentApprovalsApi, type UseAgentApprovalsOptions, type UseAgentApprovalsResult, type UseAgentChatApi, type UseAgentChatOptions, type UseAgentChatResult, type UseAgentOptions, type UseAgentResult, type UseAgentStateApi, type UseAgentStateOptions, type UseAgentStateResult, type UseAgentToolEventsApi, type UseAgentToolEventsOptions, type UseAgentToolEventsResult, type UseAuthResult, type UseAuthSessionsOptions, type UseAuthUsersOptions, type UseHttpStreamOptions, type UseHttpStreamResult, type UseImpersonateResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseLiveTopicOptions, type UseLiveTopicResult, type UseMutationCallOptions, type UseOrganizationsOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseSignUpInvitationsOptions, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, type UseVoiceAgentOptions, type UseVoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, hydratePreloaded, useAction, useAgent, useAgentApprovals, useAgentChat, useAgentState, useAgentToolEvents, useAuth, useAuthSessions, useAuthState, useAuthUsers, useClientQuery, useConnectionStatus, useFlag, useFlags, useHttpStream, useImpersonate, useInfiniteQuery, useLiveTopic, useLunora, useMutation, useMutator, useOrganizations, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useSignUpInvitations, useStream, useSubscription, useSuspenseQuery, useVoiceAgent };
|
|
1593
|
+
export { type ActionHook, type AdminAuthListResult, type AgentApprovalGrant, type AgentApprovalTarget, type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, type AuthState, Authenticated, type FlagValue, type HeartbeatReference, type LeaveReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type MutatorHook, type PageItemOf, type PaginatedArgs, type PendingApproval, Unauthenticated, type UseAgentApi, type UseAgentApprovalsApi, type UseAgentApprovalsOptions, type UseAgentApprovalsResult, type UseAgentChatApi, type UseAgentChatOptions, type UseAgentChatResult, type UseAgentOptions, type UseAgentResult, type UseAgentStateApi, type UseAgentStateOptions, type UseAgentStateResult, type UseAgentToolEventsApi, type UseAgentToolEventsOptions, type UseAgentToolEventsResult, type UseAuthResult, type UseAuthSessionsOptions, type UseAuthUsersOptions, type UseHttpStreamOptions, type UseHttpStreamResult, type UseImpersonateResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseLiveTopicOptions, type UseLiveTopicResult, type UseMutationCallOptions, type UseOrganizationsOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseSignUpInvitationsOptions, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, type UseVoiceAgentOptions, type UseVoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, hydratePreloaded, useAction, useAgent, useAgentApprovals, useAgentChat, useAgentState, useAgentToolEvents, useAuth, useAuthSessions, useAuthState, useAuthUsers, useClientQuery, useConnectionStatus, useFlag, useFlags, useHttpStream, useImpersonate, useInfiniteQuery, useLiveTopic, useLunora, useMutation, useMutator, useOrganizations, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useSignUpInvitations, useStream, useSubscription, useSuspenseQuery, useVoiceAgent };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-DgQHaQD5.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-DZhCIjSA.mjs";import{L as f,u as n}from"./packem_shared/lunora-provider-BMJTPKMP.mjs";import{useAction as m}from"./packem_shared/useAction-BGTQyx5l.mjs";import{useAuthSessions as d,useAuthUsers as l,useImpersonate as A,useOrganizations as g,useSignUpInvitations as c}from"./packem_shared/useAuthSessions-Cv3RRW_S.mjs";import{useAgent as U}from"./packem_shared/useAgent-BW4uKe79.mjs";import{useAgentApprovals as S}from"./packem_shared/useAgentApprovals-VbOnL2Lx.mjs";import{useAgentChat as E}from"./packem_shared/useAgentChat-Civzre-d.mjs";import{useAgentState as L}from"./packem_shared/useAgentState-CNZ5F4mc.mjs";import{useAgentToolEvents as v}from"./packem_shared/useAgentToolEvents-Bv7qTf29.mjs";import{default as F}from"./packem_shared/useAuth-C1_ruDmE.mjs";import{default as M}from"./packem_shared/useClientQuery-D-c8YM6Q.mjs";import{default as b}from"./packem_shared/useConnectionStatus-CAmQqRpD.mjs";import{useFlag as O,useFlags as k}from"./packem_shared/useFlag-CWjaNeAp.mjs";import{useHttpStream as V}from"./packem_shared/useHttpStream-C-VR6P1E.mjs";import{default as q}from"./packem_shared/useInfiniteQuery-BIkpHK0e.mjs";import{useLiveTopic as B}from"./packem_shared/useLiveTopic-Cp5b1ncm.mjs";import{useMutation as G}from"./packem_shared/useMutation-D6p61C2U.mjs";import{useMutator as K}from"./packem_shared/useMutator-BtUd-xEA.mjs";import{usePaginatedQuery as W}from"./packem_shared/usePaginatedQuery-B7tBY2XC.mjs";import{hydratePreloaded as Y,usePreloadedQuery as Z}from"./packem_shared/hydratePreloaded-DbwkdExV.mjs";import{usePresence as $}from"./packem_shared/usePresence-
|
|
2
|
+
import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-DgQHaQD5.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-DZhCIjSA.mjs";import{L as f,u as n}from"./packem_shared/lunora-provider-BMJTPKMP.mjs";import{useAction as m}from"./packem_shared/useAction-BGTQyx5l.mjs";import{useAuthSessions as d,useAuthUsers as l,useImpersonate as A,useOrganizations as g,useSignUpInvitations as c}from"./packem_shared/useAuthSessions-Cv3RRW_S.mjs";import{useAgent as U}from"./packem_shared/useAgent-BW4uKe79.mjs";import{useAgentApprovals as S}from"./packem_shared/useAgentApprovals-VbOnL2Lx.mjs";import{useAgentChat as E}from"./packem_shared/useAgentChat-Civzre-d.mjs";import{useAgentState as L}from"./packem_shared/useAgentState-CNZ5F4mc.mjs";import{useAgentToolEvents as v}from"./packem_shared/useAgentToolEvents-Bv7qTf29.mjs";import{default as F}from"./packem_shared/useAuth-C1_ruDmE.mjs";import{default as M}from"./packem_shared/useClientQuery-D-c8YM6Q.mjs";import{default as b}from"./packem_shared/useConnectionStatus-CAmQqRpD.mjs";import{useFlag as O,useFlags as k}from"./packem_shared/useFlag-CWjaNeAp.mjs";import{useHttpStream as V}from"./packem_shared/useHttpStream-C-VR6P1E.mjs";import{default as q}from"./packem_shared/useInfiniteQuery-BIkpHK0e.mjs";import{useLiveTopic as B}from"./packem_shared/useLiveTopic-Cp5b1ncm.mjs";import{useMutation as G}from"./packem_shared/useMutation-D6p61C2U.mjs";import{useMutator as K}from"./packem_shared/useMutator-BtUd-xEA.mjs";import{usePaginatedQuery as W}from"./packem_shared/usePaginatedQuery-B7tBY2XC.mjs";import{hydratePreloaded as Y,usePreloadedQuery as Z}from"./packem_shared/hydratePreloaded-DbwkdExV.mjs";import{usePresence as $}from"./packem_shared/usePresence-D6_7YQqP.mjs";import{default as re}from"./packem_shared/useQuery-DMSZbdFz.mjs";import{useRateLimit as te}from"./packem_shared/useRateLimit-Cckxi8m9.mjs";import{useStream as se}from"./packem_shared/useStream-B_XzhM-6.mjs";import{default as pe}from"./packem_shared/useSubscription-CRqptgB_.mjs";import{default as ne}from"./packem_shared/useSuspenseQuery-B9DrM8Kw.mjs";import{useVoiceAgent as me}from"./packem_shared/useVoiceAgent-BHkPJWuv.mjs";import{createClientQuery as de,getErrorCode as le,getRetryAfterMs as Ae,isConflictError as ge,isForbiddenError as ce,isRateLimitedError as he,isUnauthorizedError as Ue}from"@lunora/client";import{lunoraQueryOptions as Se}from"@lunora/client/query";import{RestrictionError as Ee,UploadControl as Qe,UploadError as Le}from"@visulima/storage-client";import{useChunkedRestUpload as ve,useFileInput as Re,useMultipartUpload as Fe,usePasteUpload as Ie,useTusUpload as Me,useUpload as Te}from"@visulima/storage-client/react";export{o as AuthLoading,t as Authenticated,f as LunoraProvider,Ee as RestrictionError,u as Unauthenticated,Qe as UploadControl,Le as UploadError,de as createClientQuery,le as getErrorCode,Ae as getRetryAfterMs,Y as hydratePreloaded,ge as isConflictError,ce as isForbiddenError,he as isRateLimitedError,Ue as isUnauthorizedError,Se as lunoraQueryOptions,m as useAction,U as useAgent,S as useAgentApprovals,E as useAgentChat,L as useAgentState,v as useAgentToolEvents,F as useAuth,d as useAuthSessions,a as useAuthState,l as useAuthUsers,ve as useChunkedRestUpload,M as useClientQuery,b as useConnectionStatus,Re as useFileInput,O as useFlag,k as useFlags,V as useHttpStream,A as useImpersonate,q as useInfiniteQuery,B as useLiveTopic,n as useLunora,Fe as useMultipartUpload,G as useMutation,K as useMutator,g as useOrganizations,W as usePaginatedQuery,Ie as usePasteUpload,Z as usePreloadedQuery,$ as usePresence,re as useQuery,te as useRateLimit,c as useSignUpInvitations,se as useStream,pe as useSubscription,ne as useSuspenseQuery,Me as useTusUpload,Te as useUpload,me as useVoiceAgent};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{useMemo as O,useState as V,useRef as v,useEffect as g,useCallback as L}from"react";import{u as W}from"./lunora-provider-BMJTPKMP.mjs";const A=e=>{if(!Number.isFinite(e)||e<=0)throw new RangeError(`presence intervalMs must be a positive number, got ${String(e)}`)},h=async e=>{try{await e()}catch{}},S=e=>JSON.stringify([e.shardKey??"",e.roomId,e.sessionId]),M=new WeakMap,D=e=>{let t=M.get(e);return t===void 0&&(t={heartbeats:new Map,leaves:new Map},M.set(e,t)),t},N=(e,t,n)=>{const{heartbeats:r,leaves:a}=D(e),o=S(t),d=a.get(o),s=d===void 0?h(n):d.then(async()=>h(n)),c=r.get(o)??new Set;c.add(s),r.set(o,c),s.then(()=>{c.delete(s),c.size===0&&r.get(o)===c&&r.delete(o)})},F=(e,t,n)=>{const{heartbeats:r,leaves:a}=D(e),o=S(t),d=[...r.get(o)??[]],s=d.length===0?h(n):Promise.all(d).then(async()=>h(n));a.set(o,s),s.then(()=>{a.get(o)===s&&a.delete(o)})},P=new WeakMap,j=(e,t)=>{const n=P.get(e)??new Map,r=S(t);P.set(e,n),n.set(r,(n.get(r)??0)+1);let a=!0;return()=>{if(!a)return!1;a=!1;const o=(n.get(r)??1)-1;return o>0?(n.set(r,o),!1):(n.delete(r),!0)}},x=(e,t)=>{let n;return e.onConnectionStatus(r=>{const a=n!==void 0&&n!=="connected";n=r,a&&r==="connected"&&t()})},H=()=>{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")},J=1e4,z=(e,t)=>{const n=W(),{heartbeat:r,intervalMs:a=J,leave:o,listPresent:d,shardKey:s}=t;A(a);const c=O(()=>t.sessionId??H(),[t.sessionId]),p=JSON.stringify([d.__lunoraRef,e,s??""]),[m,b]=V(),w=m?.client===n&&m.key===p?m:void 0,k=v(t.onError),E=v(o);g(()=>{k.current=t.onError,E.current=o});const I=v(t.data),R=v(!1),U=v({client:n,heartbeat:r,roomId:e,sessionId:c,shardKey:s});g(()=>{U.current={client:n,heartbeat:r,roomId:e,sessionId:c,shardKey:s}});const f=L(()=>{const{client:i,heartbeat:y,roomId:u,sessionId:l,shardKey:K}=U.current,C={roomId:u,sessionId:l,...I.current===void 0?{}:{data:I.current}};N(i,{roomId:u,sessionId:l,shardKey:K},async()=>i.mutation(y,C,{onlineOnly:!0,shardKey:K}))},[]),_=L(i=>{I.current=i,R.current&&f()},[f]);return g(()=>(R.current=!0,()=>{R.current=!1}),[]),g(()=>{f();const i=setInterval(f,a),y=()=>{typeof document<"u"&&document.visibilityState==="visible"&&f()};return typeof document<"u"&&document.addEventListener("visibilitychange",y),()=>{clearInterval(i),typeof document<"u"&&document.removeEventListener("visibilitychange",y)}},[f,a,n,e,c,s]),g(()=>{const i=n.acquireConnectionContext({roomId:e,sessionId:c},{shardKey:s}),y=j(n,{roomId:e,sessionId:c,shardKey:s}),u=x(n,f);return()=>{u(),i();const l=E.current;y()&&l!==void 0&&F(n,{roomId:e,sessionId:c,shardKey:s},async()=>n.mutation(l,{roomId:e,sessionId:c},{onlineOnly:!0,shardKey:s}))}},[n,e,c,s,f]),g(()=>{let i=!1;const y=n.subscribe(d,{roomId:e},u=>{i||b({client:n,error:void 0,key:p,present:u})},{onError:u=>{i||b(l=>({client:n,error:u,key:p,present:l?.client===n&&l.key===p?l.present:void 0})),k.current?.(u)},shardKey:s});return()=>{i=!0,y(),b(void 0)}},[n,d.__lunoraRef,e,p,s]),{error:w?.error,present:w?.present,sessionId:c,setData:_}};export{z as usePresence};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/react",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.305",
|
|
4
4
|
"description": "React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@lunora/client": "^1.0.0-alpha.
|
|
60
|
+
"@lunora/client": "^1.0.0-alpha.303",
|
|
61
61
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
62
62
|
"@lunora/ratelimit": "^1.0.0-alpha.197",
|
|
63
63
|
"@lunora/wire": "1.0.0-alpha.6",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import{useMemo as _,useState as w,useRef as l,useEffect as u,useCallback as E}from"react";import{u as D}from"./lunora-provider-BMJTPKMP.mjs";const V=e=>{if(!Number.isFinite(e)||e<=0)throw new RangeError(`presence intervalMs must be a positive number, got ${String(e)}`)},A=()=>{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,r=>r.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},C=1e4,P=(e,r)=>{const t=D(),{heartbeat:g,intervalMs:y=C,listPresent:m,shardKey:s}=r;V(y);const o=_(()=>r.sessionId??A(),[r.sessionId]),d=JSON.stringify([m.__lunoraRef,e,s??""]),[b,p]=w(),h=b?.client===t&&b.key===d?b:void 0,R=l(r.onError);u(()=>{R.current=r.onError});const v=l(r.data),I=l(!1),S=l({client:t,heartbeat:g,roomId:e,sessionId:o,shardKey:s});u(()=>{S.current={client:t,heartbeat:g,roomId:e,sessionId:o,shardKey:s}});const i=E(()=>{const{client:n,heartbeat:c,roomId:a,sessionId:f,shardKey:k}=S.current,L={roomId:a,sessionId:f,...v.current===void 0?{}:{data:v.current}};n.mutation(c,L,{shardKey:k}).catch(()=>{})},[]),U=E(n=>{v.current=n,I.current&&i()},[i]);return u(()=>(I.current=!0,()=>{I.current=!1}),[]),u(()=>{i();const n=setInterval(i,y),c=()=>{typeof document<"u"&&document.visibilityState==="visible"&&i()};return typeof document<"u"&&document.addEventListener("visibilitychange",c),()=>{clearInterval(n),typeof document<"u"&&document.removeEventListener("visibilitychange",c)}},[i,y,t,e,o,s]),u(()=>t.acquireConnectionContext({roomId:e,sessionId:o},{shardKey:s}),[t,e,o,s]),u(()=>{let n=!1;const c=t.subscribe(m,{roomId:e},a=>{n||p({client:t,error:void 0,key:d,present:a})},{onError:a=>{n||p(f=>({client:t,error:a,key:d,present:f?.client===t&&f.key===d?f.present:void 0})),R.current?.(a)},shardKey:s});return()=>{n=!0,c(),p(void 0)}},[t,m.__lunoraRef,e,d,s]),{error:h?.error,present:h?.present,sessionId:o,setData:U}};export{P as usePresence};
|