@lunora/solid 1.0.0-alpha.6 → 1.0.0-alpha.61
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/LICENSE.md +6 -0
- package/README.md +4 -0
- package/dist/index.d.mts +926 -213
- package/dist/index.d.ts +926 -213
- package/dist/index.mjs +1 -12
- package/dist/packem_shared/AuthLoading-6vueEnV0.mjs +1 -0
- package/dist/packem_shared/LunoraContext-dPcjtn6R.mjs +1 -0
- package/dist/packem_shared/LunoraProvider-BKWckcDR.mjs +1 -0
- package/dist/packem_shared/createAction-M4s8XBXV.mjs +1 -0
- package/dist/packem_shared/createAgent-DTUKko5X.mjs +1 -0
- package/dist/packem_shared/createAgentChat-BjVMwDVY.mjs +1 -0
- package/dist/packem_shared/createAgentState-DIknFZyn.mjs +1 -0
- package/dist/packem_shared/createAgentToolEvents-BZDqkzK6.mjs +1 -0
- package/dist/packem_shared/createConnectionStatus-BnlXYWeE.mjs +1 -0
- package/dist/packem_shared/createFlag-l_riySES.mjs +1 -0
- package/dist/packem_shared/createInfiniteQuery-CAU4Yr4Z.mjs +1 -0
- package/dist/packem_shared/createMutation-DcSsIbGF.mjs +1 -0
- package/dist/packem_shared/createMutator-q9cMjGKv.mjs +1 -0
- package/dist/packem_shared/createPresence-Da_DdL7L.mjs +1 -0
- package/dist/packem_shared/createQuery-DnfKuyeU.mjs +1 -0
- package/dist/packem_shared/createRateLimit-CIVWrD5H.mjs +1 -0
- package/dist/packem_shared/createStream-B10b3ijV.mjs +1 -0
- package/dist/packem_shared/createSubscription-D9e8lT1C.mjs +1 -0
- package/dist/packem_shared/createVoiceAgent-BjL6DH05.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-CnJNitir.mjs +1 -0
- package/dist/packem_shared/solid-compat-ByG5HD_F.mjs +1 -0
- package/dist/packem_shared/stable-key-ITGZkfuz.mjs +1 -0
- package/dist/server.mjs +1 -1
- package/dist/upload.d.mts +2 -0
- package/dist/upload.d.ts +2 -0
- package/dist/upload.mjs +1 -0
- package/package.json +10 -4
- package/dist/packem_shared/AuthLoading-RMT5Q_eE.mjs +0 -73
- package/dist/packem_shared/LunoraContext-C9SpKj54.mjs +0 -12
- package/dist/packem_shared/LunoraProvider-B5BJFk3K.mjs +0 -17
- package/dist/packem_shared/createConnectionStatus-D8GPatZX.mjs +0 -14
- package/dist/packem_shared/createFlag-BDunYuaH.mjs +0 -106
- package/dist/packem_shared/createInfiniteQuery-DyMvQ2Qy.mjs +0 -196
- package/dist/packem_shared/createMutation-C7BxzO0y.mjs +0 -36
- package/dist/packem_shared/createPresence-DiAak1Jw.mjs +0 -78
- package/dist/packem_shared/createQuery-D8mdHfyQ.mjs +0 -28
- package/dist/packem_shared/createRateLimit-BA2f8XyF.mjs +0 -76
- package/dist/packem_shared/createSubscription-BM2fw8hw.mjs +0 -39
- package/dist/packem_shared/hydratePreloaded-CaT1kDBH.mjs +0 -25
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { AuthLoading, Authenticated, Unauthenticated, createAuth } from './packem_shared/AuthLoading-RMT5Q_eE.mjs';
|
|
3
|
-
export { default as createConnectionStatus } from './packem_shared/createConnectionStatus-D8GPatZX.mjs';
|
|
4
|
-
export { createFlag, createFlags } from './packem_shared/createFlag-BDunYuaH.mjs';
|
|
5
|
-
export { createMutation, createMutationForClient } from './packem_shared/createMutation-C7BxzO0y.mjs';
|
|
6
|
-
export { createInfiniteQuery, createPaginatedQuery } from './packem_shared/createInfiniteQuery-DyMvQ2Qy.mjs';
|
|
7
|
-
export { createPresence } from './packem_shared/createPresence-DiAak1Jw.mjs';
|
|
8
|
-
export { createQuery } from './packem_shared/createQuery-D8mdHfyQ.mjs';
|
|
9
|
-
export { createRateLimit } from './packem_shared/createRateLimit-BA2f8XyF.mjs';
|
|
10
|
-
export { createSubscription } from './packem_shared/createSubscription-BM2fw8hw.mjs';
|
|
11
|
-
export { default as hydratePreloaded } from './packem_shared/hydratePreloaded-CaT1kDBH.mjs';
|
|
12
|
-
export { LunoraProvider } from './packem_shared/LunoraProvider-B5BJFk3K.mjs';
|
|
1
|
+
import{LunoraContext as r,useLunora as o}from"./packem_shared/LunoraContext-dPcjtn6R.mjs";import{createAction as c,createActionForClient as n}from"./packem_shared/createAction-M4s8XBXV.mjs";import{createAgent as m}from"./packem_shared/createAgent-DTUKko5X.mjs";import{createAgentChat as x}from"./packem_shared/createAgentChat-BjVMwDVY.mjs";import{createAgentState as u}from"./packem_shared/createAgentState-DIknFZyn.mjs";import{createAgentToolEvents as A}from"./packem_shared/createAgentToolEvents-BZDqkzK6.mjs";import{AuthLoading as l,Authenticated as s,Unauthenticated as h,createAuth as C}from"./packem_shared/AuthLoading-6vueEnV0.mjs";import{default as y}from"./packem_shared/createConnectionStatus-BnlXYWeE.mjs";import{createFlag as P,createFlags as S}from"./packem_shared/createFlag-l_riySES.mjs";import{createMutation as Q,createMutationForClient as v}from"./packem_shared/createMutation-DcSsIbGF.mjs";import{createMutator as E}from"./packem_shared/createMutator-q9cMjGKv.mjs";import{createInfiniteQuery as R,createPaginatedQuery as T}from"./packem_shared/createInfiniteQuery-CAU4Yr4Z.mjs";import{createPresence as V}from"./packem_shared/createPresence-Da_DdL7L.mjs";import{createQuery as k}from"./packem_shared/createQuery-DnfKuyeU.mjs";import{createRateLimit as w}from"./packem_shared/createRateLimit-CIVWrD5H.mjs";import{createStream as B}from"./packem_shared/createStream-B10b3ijV.mjs";import{createSubscription as G}from"./packem_shared/createSubscription-D9e8lT1C.mjs";import{createVoiceAgent as J}from"./packem_shared/createVoiceAgent-BjL6DH05.mjs";import{default as N}from"./packem_shared/hydratePreloaded-CnJNitir.mjs";import{LunoraProvider as W}from"./packem_shared/LunoraProvider-BKWckcDR.mjs";export{l as AuthLoading,s as Authenticated,r as LunoraContext,W as LunoraProvider,h as Unauthenticated,c as createAction,n as createActionForClient,m as createAgent,x as createAgentChat,u as createAgentState,A as createAgentToolEvents,C as createAuth,y as createConnectionStatus,P as createFlag,S as createFlags,R as createInfiniteQuery,Q as createMutation,v as createMutationForClient,E as createMutator,T as createPaginatedQuery,V as createPresence,k as createQuery,w as createRateLimit,B as createStream,G as createSubscription,J as createVoiceAgent,N as hydratePreloaded,o as useLunora};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getIdentityStore as i}from"@lunora/client/auth";import{createSignal as r,onCleanup as g,createComponent as k,Show as m}from"solid-js";import{useLunora as T}from"./LunoraContext-dPcjtn6R.mjs";const d=()=>{const t=T(),e=i(t),[n,u]=r(t.getAuthToken()),[c,l]=r(e.getUser()),a=t.onAuthTokenChange(o=>{u(()=>o)}),h=e.subscribe(()=>{l(()=>e.getUser())});return g(()=>{a(),h()}),{setToken:o=>{t.setAuthToken(o)},token:n,user:c}},f=m,s=t=>e=>{const n=d();return k(f,{get children(){return e.children},get when(){return t(n)}})},b=s(({token:t,user:e})=>t()===null?!1:e()!==null),w=s(({token:t,user:e})=>t()===null?!1:e()===null),C=s(({token:t,user:e})=>t()===null?e()===null:!1);export{w as AuthLoading,b as Authenticated,C as Unauthenticated,d as createAuth};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as o}from"@lunora/errors";import{createContext as t,useContext as e}from"solid-js";const n=t(),s=()=>{let r;try{r=e(n)}catch{r=void 0}if(!r)throw new o("INTERNAL","useLunora must be used inside <LunoraProvider />");return r};export{n as LunoraContext,s as useLunora};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createComponent as e}from"solid-js";import{LunoraContext as o}from"./LunoraContext-dPcjtn6R.mjs";import{p as t}from"./solid-compat-ByG5HD_F.mjs";const a=r=>e(t(o),{get children(){return r.children},get value(){return r.client}});export{a as LunoraProvider};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createCallRunner as m}from"@lunora/client";import{createSignal as r}from"solid-js";import{useLunora as p}from"./LunoraContext-dPcjtn6R.mjs";const u=(t,c)=>{const[s,n]=r(void 0),[a,e]=r(void 0),[i,l]=r(!1);return{call:m((o,d)=>t.action(c,o,d),{setError:e,setPending:l,setResult:o=>{n(()=>o),e(void 0)}}),data:s,error:a,pending:i,reset:()=>{n(()=>{}),e(void 0)}}},R=t=>u(p(),t);export{R as createAction,u as createActionForClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as s}from"solid-js";import{createMutation as i}from"./createMutation-DcSsIbGF.mjs";import{createSubscription as M}from"./createSubscription-D9e8lT1C.mjs";const l={__lunoraRef:""},c=t=>typeof t=="function"?t():t,K=t=>{const{api:u,cancel:r,run:d,runArgs:f,threadKey:n}=t,o=i(d),m=i(r??l),{data:p}=M(u.agents.agentThread,()=>({key:c(n)})),a=s(()=>p()),y=s(()=>a()?.status),g=async(e,h)=>{await o.mutate({input:e,threadKey:c(n),...f,...h})};return{cancel:async()=>{const e=a()?.instanceId;r===void 0||e===void 0||await m.mutate({instanceId:e,threadKey:c(n)})},pending:o.pending,run:g,status:y,thread:a}};export{l as NO_MUTATION_REF,K as createAgent,c as resolveMaybe};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{reconcileOptimistic as v,maxSeq as A}from"@lunora/client";import{createSignal as F,createMemo as c}from"solid-js";import{resolveMaybe as a,NO_MUTATION_REF as U}from"./createAgent-DTUKko5X.mjs";import{createMutation as u}from"./createMutation-DcSsIbGF.mjs";import{createStream as $}from"./createStream-B10b3ijV.mjs";import{createSubscription as M}from"./createSubscription-D9e8lT1C.mjs";const z={__lunoraRef:""},X=R=>{const{api:m,cancel:l,limit:p,send:S,sendArgs:k,stream:h,threadKey:r}=R,{data:w}=M(m.agents.agentMessages,()=>{const t=a(r);return p===void 0?{key:t}:{key:t,limit:p}}),{data:x}=M(m.agents.agentThread,()=>({key:a(r)})),I=h===void 0?"skip":()=>({key:a(r)}),{chunks:b}=$(h??z,I),_=u(S),K=u(l??U),O=u(m.agents.agentResolveApproval),[T,g]=F([]);let f=0;const d=c(()=>x()),j=c(()=>d()?.status),i=c(()=>w()??[]),q=c(()=>{const t=i(),n=v(T(),t);if(n.length===0)return t;const e=A(t);return[...t,...n.map((s,o)=>({content:s.content,optimistic:!0,role:"user",seq:e+1+o}))]}),E=c(()=>{const t=a(r),n=i().filter(e=>e.role==="assistant").length;return b().filter(e=>e.kind!=="progress"&&e.threadKey===t&&e.turn>=n).map(e=>e.text).join("")}),C=async(t,n)=>{const e=f;f+=1;const s=A(i());g(o=>[...v(o,i()),{content:t,id:e,maxDurableSeqAtSend:s}]);try{await _.mutate({input:t,threadKey:a(r),...k,...n})}catch(o){throw g(D=>D.filter(N=>N.id!==e)),o}},y=async(t,n,e)=>{const s=d()?.instanceId;if(s===void 0)throw new Error(`createAgentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await O.mutate({decision:t,instanceId:s,threadKey:a(r),toolCallId:n,...e===void 0?{}:{note:e}})};return{approve:async(t,n)=>y("approve",t,n),cancel:async()=>{const t=d()?.instanceId;l===void 0||t===void 0||await K.mutate({instanceId:t,threadKey:a(r)})},messages:q,reject:async(t,n)=>y("reject",t,n),send:C,status:j,streamingText:E}};export{X as createAgentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as o}from"solid-js";import{resolveMaybe as n}from"./createAgent-DTUKko5X.mjs";import{createSubscription as c}from"./createSubscription-D9e8lT1C.mjs";const p=e=>{const{data:t,error:r}=c(e.api.agents.agentState,()=>({key:n(e.threadKey)})),a=o(()=>t());return{error:r,state:a}};export{p as createAgentState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as v}from"solid-js";import{resolveMaybe as n}from"./createAgent-DTUKko5X.mjs";import{createStream as f}from"./createStream-B10b3ijV.mjs";import{createSubscription as y}from"./createSubscription-D9e8lT1C.mjs";const C={__lunoraRef:""},I=[],N=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(r=>({input:r.input,seq:t.seq,toolCallId:r.id,toolName:r.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}}]},_=t=>{const{api:r,limit:a,stream:i,threadKey:e}=t,u=()=>{const l=n(e);return a===void 0?{key:l}:{key:l,limit:a}},{data:p}=y(r.agents.agentMessages,u),s=i===void 0?"skip":()=>({key:n(e)}),{chunks:c}=f(i??C,s);return{events:v(()=>{const l=n(e),d=(p()??I).flatMap(o=>N(o)??[]);for(const o of c())o.kind==="progress"&&o.threadKey===l&&d.push({data:o.data,toolCallId:o.toolCallId,type:"progress"});return d})}};export{_ as createAgentToolEvents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as s}from"solid-js";import{useLunora as a}from"./LunoraContext-dPcjtn6R.mjs";import{o as r}from"./solid-compat-ByG5HD_F.mjs";const m=()=>{const t=a(),[o,n]=s(t.connectionStatus());return r(()=>t.onConnectionStatus(e=>{n(e)})),o};export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as l}from"solid-js";import{s as m}from"./stable-key-ITGZkfuz.mjs";import{useLunora as p}from"./LunoraContext-dPcjtn6R.mjs";import{resolveMaybe as n}from"./createAgent-DTUKko5X.mjs";import{t as y}from"./solid-compat-ByG5HD_F.mjs";const $="__lunora_flags__:eval",_=t=>{const e=typeof t;return e==="boolean"||e==="number"||e==="string"?e:"object"},v={__lunoraRef:$},d=t=>t===void 0?"":m(t),F=(t,e,s)=>{const a=p(),c=_(e),[b,u]=l(e);return y(()=>`${n(t)} ${d(n(s))}`,()=>{const i=n(t),r=n(s);u(()=>e);let o;try{o=a.subscribe(v,{context:r,default:e,key:i,type:c},f=>{u(()=>f)})}catch{return}return o}),b},L=(t,e)=>{const s=p(),[a,c]=l(t),b=m(t);return y(()=>`${b} ${d(n(e))}`,()=>{const u=n(e);c(()=>t);const i=[];for(const[r,o]of Object.entries(t))try{i.push(s.subscribe(v,{context:u,default:o,key:r,type:_(o)},f=>{c(g=>({...g,[r]:f}))}))}catch{}return()=>{for(const r of i)r()}}),a};export{F as createFlag,L as createFlags};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{initialPages as T,derivePaginationStatus as B,applyLoadMore as z,rebalance as G}from"@lunora/client/pagination";import{createMemo as A,createSignal as U}from"solid-js";import{s as H}from"./stable-key-ITGZkfuz.mjs";import{useLunora as V}from"./LunoraContext-dPcjtn6R.mjs";import{t as $}from"./solid-compat-ByG5HD_F.mjs";const E=e=>{let n="";for(let u=0;u<e.length;u+=32768)n+=String.fromCharCode(...e.subarray(u,u+32768));return btoa(n)},f="$lunora.wire$",F=64,X="__proto__",Y=e=>{if(e===null||typeof e!="object")return!1;const n=Object.getPrototypeOf(e);return n===null||n===Object.prototype},P=(e,n=0)=>{if(n>F)throw new RangeError(`wire-codec: value nesting exceeds the ${F}-level limit`);if(e===void 0)return[f,"undefined"];if(e===null)return null;const l=typeof e;if(l==="bigint")return[f,"bigint",e.toString()];if(l==="number"){const t=e;return Number.isNaN(t)?[f,"nan"]:t===1/0?[f,"inf"]:t===-1/0?[f,"-inf"]:t}if(l!=="object")return e;if(e instanceof Date)return[f,"date",P(e.getTime(),n+1)];if(e instanceof Error){const t=e,r={};for(const d of Object.keys(t))t[d]!==void 0&&(r[d]=P(t[d],n+1));const o=[f,"error",t.name,t.message,r];return t.cause!==void 0&&o.push(P(t.cause,n+1)),o}if(e instanceof URL)return[f,"url",e.href];if(e instanceof Map)return[f,"map",[...e.entries()].map(([t,r])=>[P(t,n+1),P(r,n+1)])];if(e instanceof Set)return[f,"set",[...e].map(t=>P(t,n+1))];if(e instanceof ArrayBuffer)return[f,"bytes",E(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,r=t.constructor.name,o=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return r==="Uint8Array"?[f,"bytes",E(o)]:[f,"bytes",E(o),r]}if(Array.isArray(e)){const t=e.map(r=>P(r,n+1));return t.length>0&&t[0]===f?[f,"arr",t]:t}if(!Y(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,m={};for(const t of Object.keys(u)){const r=u[t];if(r===void 0)continue;const o=P(r,n+1);t===X?Object.defineProperty(m,t,{configurable:!0,enumerable:!0,value:o,writable:!0}):m[t]=o}return m},J=e=>H(P(e)),h=(e,n)=>({...n,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),L=(e,n)=>`${e}::${J(n)}`,D=(e,n,l)=>{const u=V(),{initialNumItems:m,shardKey:t}=l,r=()=>typeof n=="function"?n():n,[o,d]=U(T(m)),g=new Map,[M,N]=U([]),y=new Map,S=new Set,x=(s,c)=>{const p=s.map(i=>{const a=L(e.__lunoraRef,h(i,c));return g.get(a)});N(p)},Q=(s,c,p)=>{const i=a=>L(e.__lunoraRef,h(a,p));for(const a of c){const b=i(a);if(g.has(b))continue;const k=s.find(w=>w.lower===a.lower);if(k){const w=g.get(i(k));w&&g.set(b,w)}}},W=(s,c)=>{const p=new Set;for(const i of s)p.add(L(e.__lunoraRef,h(i,c)));for(const[i,a]of y)p.has(i)||(a(),y.delete(i),S.delete(i),g.delete(i));for(const i of s){const a=h(i,c),b=L(e.__lunoraRef,a);if(y.has(b))continue;S.add(b);const k=u.subscribe(e,a,w=>{g.set(b,w),S.delete(b);const R=r();if(R!=="skip"&&(x(o(),R),S.size===0)){const _=o(),j=G(_,M());j&&(Q(_,j,R),d(j))}},{shardKey:t});y.set(b,k)}};let K=!1,O=!1;const C=(s,c)=>{if(K){O=!0;return}K=!0;try{let p=s,i=c;do{O=!1,W(p,i);const a=r();if(a==="skip")break;p=o(),i=a}while(O)}finally{K=!1}},I=()=>{for(const s of y.values())s();y.clear(),g.clear(),S.clear()};$(r,s=>(I(),d(T(m)),N([]),s!=="skip"&&(C(o(),s),x(o(),s)),I)),$(o,s=>{const c=r();c!=="skip"&&(C(s,c),x(s,c))});const q=A(()=>{const s=r()==="skip";return B(s,M()).status});return{loadMore:s=>{const c=r();if(c==="skip")return;const{nextCursor:p,status:i}=B(!1,M());if(i!=="CanLoadMore")return;const a=z(o(),p,s);if(!a)return;const b=o().at(-1),k=a.at(-2);if(b&&k){const w=L(e.__lunoraRef,h(b,c)),R=L(e.__lunoraRef,h(k,c));if(w!==R){const _=g.get(w);_&&g.set(R,_)}}d(a)},pageResults:M,status:q}},se=(e,n,l)=>{const{loadMore:u,pageResults:m,status:t}=D(e,n,l),r=A(()=>m().flatMap(d=>d?.page??[]));return{isLoading:A(()=>t()==="LoadingFirstPage"||t()==="LoadingMore"),loadMore:u,results:r,status:t}},oe=(e,n,l)=>{const{initialNumItems:u}=l,{loadMore:m,pageResults:t,status:r}=D(e,n,l),o=A(()=>t().flatMap(y=>y?[y.page]:[])),d=A(()=>r()==="LoadingFirstPage"),g=A(()=>r()==="CanLoadMore"),M=A(()=>r()==="LoadingMore");return{fetchNextPage:y=>{m(y??u)},hasNextPage:g,isFetchingNextPage:M,isLoading:d,pages:o,status:r}};export{oe as createInfiniteQuery,se as createPaginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createCallRunner as l}from"@lunora/client";import{createSignal as s}from"solid-js";import{useLunora as p}from"./LunoraContext-dPcjtn6R.mjs";const v=(e,o)=>{const[r,t]=s(void 0),[n,a]=s(void 0),[c,u]=s(!1),m=l((i,d)=>e.mutation(o,i,d),{setError:a,setPending:u,setResult:i=>{t(()=>i),a(void 0)}});return{data:r,error:n,mutate:m,pending:c,reset:()=>{t(()=>{}),a(void 0)}}},R=e=>{const o=p();return v({mutation:(r,t,n)=>o.mutation(r,t,n)},e)};export{R as createMutation,v as createMutationForClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutatorRunner as c}from"@lunora/client";import{createSignal as t}from"solid-js";const p=e=>{const[r,o]=t(void 0),[n,s]=t(!1),{mutate:i,reset:a}=c(e,{setError:o,setPending:s});return{error:r,isError:()=>r()!==void 0,mutate:i,pending:n,reset:a}};export{p as createMutator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as g}from"solid-js";import{useLunora as S}from"./LunoraContext-dPcjtn6R.mjs";import{o as D}from"./solid-compat-ByG5HD_F.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("")}}return Date.now().toString(36)},U=1e4,C=(t,e)=>{const r=S(),{heartbeat:d,intervalMs:u=U,listPresent:f,shardKey:i}=e,s=e.sessionId??I(),[l,m]=g(void 0);let a=e.data;const o=()=>{const n={roomId:t,sessionId:s,...a===void 0?{}:{data:a}};r.mutation(d,n,{shardKey:i}).catch(()=>{})},y=n=>{a=n,o()};return D(()=>{o();const n=setInterval(o,u),c=()=>{typeof document<"u"&&document.visibilityState==="visible"&&o()};typeof document<"u"&&document.addEventListener("visibilitychange",c);const p=r.acquireConnectionContext({roomId:t,sessionId:s},{shardKey:i}),v=r.subscribe(f,{roomId:t},b=>{m(()=>b)},{shardKey:i});return()=>{clearInterval(n),typeof document<"u"&&document.removeEventListener("visibilitychange",c),p(),v()}}),{present:l,sessionId:s,setData:y}};export{C as createPresence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as a}from"@lunora/client/query";import{createSignal as f}from"solid-js";import{useLunora as m}from"./LunoraContext-dPcjtn6R.mjs";import{t as p}from"./solid-compat-ByG5HD_F.mjs";const Q=(t,e,o={})=>{const n=m(),{shardKey:s}=o,[c,r]=f(void 0);return p(()=>typeof e=="function"?e():e,u=>a(n,t,u,{onData:i=>{r(()=>i)},onReset:()=>{r(()=>{})}},{shardKey:s})),c};export{Q as createQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{evaluate as u}from"@lunora/ratelimit";import{createSignal as d,createMemo as p,onCleanup as w}from"solid-js";const A=(r,v={})=>{const n=v.now??Date.now,f=v.tickMs??1e3;let t;const[m,k]=d(0),a=()=>{k(e=>e+1)},s=p(()=>{const e=n()+m()*0;return u(r,t,{consume:!1,count:1,now:e,reserve:!1}).status});let o;const c=()=>{o!==void 0&&(clearInterval(o),o=void 0)},i=()=>{s().ok||o!==void 0||(o=setInterval(()=>{a(),s().ok&&c()},f))};return w(c),i(),{check:(e=1)=>u(r,t,{consume:!1,count:e,now:n(),reserve:!1}).status.ok,consume:(e=1)=>{const l=u(r,t,{consume:!0,count:e,now:n(),reserve:!1});return l.value!==void 0&&(t=l.value),a(),i(),l.status},disabled:()=>!s().ok,ok:()=>s().ok,reset:()=>{t=void 0,c(),a()},retryAfter:()=>s().retryAfter}};export{A as createRateLimit};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as a,onCleanup as S}from"solid-js";import{useLunora as x}from"./LunoraContext-dPcjtn6R.mjs";import{t as C}from"./solid-compat-ByG5HD_F.mjs";const K=(d,o,s={})=>{const h=x(),[p,i]=a([]),[v,f]=a(void 0),[k,e]=a("idle"),y=typeof o=="function"?o:()=>o;let t;const u=()=>{t?.()};return C(y,l=>{if(i(()=>[]),f(()=>{}),l==="skip"){e("idle");return}e("streaming");let n=!0;const m=h.stream(d,l,{maxBuffer:s.maxBuffer,shardKey:s.shardKey}),c=()=>{m.cancel()};return t=c,(async()=>{try{for await(const r of m){if(!n)return;i(E=>[...E,r])}n&&e("complete")}catch(r){if(!n)return;f(()=>r instanceof Error?r:new Error(String(r))),e("error")}})().catch(()=>{}),()=>{n=!1,c(),t===c&&(t=void 0)}}),S(()=>{u()}),{cancel:u,chunks:p,error:v,status:k}};export{K as createStream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as v}from"@lunora/client/query";import{LunoraError as p}from"@lunora/errors";import{createSignal as a}from"solid-js";import{useLunora as u}from"./LunoraContext-dPcjtn6R.mjs";import{t as l}from"./solid-compat-ByG5HD_F.mjs";const D=(i,r,d={})=>{const s=u(),[c,e]=a(void 0),[m,t]=a(void 0);return l(typeof r=="function"?r:()=>r,n=>{if(n==="skip"){e(()=>{}),t(()=>{});return}return v(s,i,n,{onData:o=>{e(()=>o),t(()=>{})},onError:o=>{const f=o.code?new p(o.code,o.message):new Error(o.message);t(()=>f),e(()=>{})},onReset:()=>{e(()=>{})}},{shardKey:d.shardKey})}),{data:c,error:m}};export{D as createSubscription};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as w,onCleanup as B}from"solid-js";import{useLunora as $}from"./LunoraContext-dPcjtn6R.mjs";import{resolveMaybe as J}from"./createAgent-DTUKko5X.mjs";const K=16e3,G=e=>{if(e.length===0)return 0;let s=0;for(const o of e)s+=o*o;return Math.sqrt(s/e.length)},j=(e,s)=>{const o=s/K,a=o>1?Math.floor(e.length/o):e.length,l=new ArrayBuffer(a*2),i=new DataView(l);for(let u=0;u<a;u+=1){const k=e[Math.floor(u*o)]??0,f=Math.max(-1,Math.min(1,k));i.setInt16(u*2,f<0?f*32768:f*32767,!0)}return new Uint8Array(l)},z=async e=>{const s=globalThis,o=s.navigator?.mediaDevices?.getUserMedia.bind(s.navigator.mediaDevices),a=s.AudioContext??s.webkitAudioContext;if(!o||!a)throw new Error("createVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const l=await o({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,u=i.createMediaStreamSource(l),k=i.createScriptProcessor(4096,1,1);let f=!1,A=!1,d=0,p=0;return k.onaudioprocess=r=>{const h=r.inputBuffer.getChannelData(0),g=f?0:G(h);if(e.onLevel(g),f)return;if(e.onAudio(j(h,i.sampleRate)),e.isSpeaking()){p=g>=e.interruptThreshold?p+1:0,p>=e.interruptChunks&&(p=0,e.onInterrupt());return}p=0;const E=h.length/i.sampleRate*1e3;if(g>=e.silenceThreshold){A=!0,d=0;return}A&&(d+=E,d>=e.silenceDurationMs&&(A=!1,d=0,e.onSilence()))},u.connect(k),k.connect(i.destination),{setMuted:r=>{f=r},stop:()=>{k.disconnect(),u.disconnect();for(const r of l.getTracks())r.stop();i.close()}}},Q=()=>{const e=globalThis,s=e.AudioContext??e.webkitAudioContext;if(!s)throw new Error("createVoiceAgent: audio playback requires AudioContext (no browser audio available)");const o=new s,a=new Set;let l=0,i=Promise.resolve(),u=0;const k=async(d,p)=>{if(p!==u)return;let r;try{r=await o.decodeAudioData(d.buffer)}catch{return}if(p!==u)return;const h=o.createBufferSource();h.buffer=r,h.connect(o.destination);const g=Math.max(o.currentTime,l);h.start(g),l=g+r.duration,a.add(h),h.onended=()=>{a.delete(h)}},f=d=>{const p=Uint8Array.from(d),r=u;i=i.then(()=>k(p,r))},A=()=>{u+=1;for(const d of a)try{d.stop()}catch{}a.clear(),l=o.currentTime};return{enqueue:f,interrupt:A,stop:()=>{A(),o.close()}}},D=1,X=.01,Y=1200,Z=.15,ee=3,te=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,ne=e=>{const s=e.__lunoraRef,o=s.startsWith("agents:")?s.slice(7):s;return o.endsWith("Voice")?o.slice(0,-5):o},oe=(e,s,o)=>{const a=te(e),l=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:o});return`${l}/_lunora/voice/${encodeURIComponent(s)}?${i.toString()}`},ie=e=>{const{createMicrophone:s=z,createSpeaker:o=Q,createSocket:a,interruptChunks:l=ee,interruptThreshold:i=Z,silenceDurationMs:u=Y,silenceThreshold:k=X,threadKey:f,voice:A}=e,d=$(),[p,r]=w("idle"),[h,g]=w(!1),[E,x]=w(""),[F,y]=w(""),[I,_]=w(0),[U,L]=w(!1),[N,T]=w(void 0);let c,b=!1;const M=t=>{const n=c?.socket;return n?.readyState===D?(n.send(JSON.stringify(t)),!0):!1},C=()=>{const t=c;if(c=void 0,t){t.microphone?.stop(),t.speaker?.stop();try{t.socket.close()}catch{}}b=!1,g(!1),r("idle"),_(0)},P=C,W=t=>{const n=c;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),r("speaking"),y(m=>m+t.text);break}case"assistant_done":{n&&(n.speaking=!1),y(t.text),r("listening");break}case"error":{n&&(n.speaking=!1),T(new Error(t.message)),r("listening");break}case"interrupted":{n&&(n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),r("listening");break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),g(!0),r("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),x(t.text),y(""),r("thinking");break}}},V=t=>{const n=c;!n||n.suppressAudio||(n.speaker??=o({audioFormat:n.audioFormat}),n.speaking=!0,r("speaking"),n.speaker.enqueue(t))},H=async()=>{if(!(c||b)){b=!0,T(void 0),x(""),y("");try{const t=oe(d.url,ne(A),J(f)),m=(a??(S=>new globalThis.WebSocket(S)))(t);m.binaryType="arraybuffer";const v={audioFormat:"mp3",microphone:void 0,socket:m,speaker:void 0,speaking:!1,suppressAudio:!1};c=v,m.onmessage=S=>{if(typeof S.data=="string"){try{W(JSON.parse(S.data))}catch{}return}V(new Uint8Array(S.data))},m.onerror=()=>{T(new Error("createVoiceAgent: voice socket error"))},m.onclose=()=>{c===v&&C()};const R=await s({interruptChunks:l,interruptThreshold:i,isSpeaking:()=>c?.speaking??!1,onAudio:S=>{m.readyState===D&&m.send(S)},onInterrupt:()=>{M({type:"interrupt"}),c?.speaker?.interrupt(),c&&(c.speaking=!1,c.suppressAudio=!0),r("listening")},onLevel:S=>{_(S)},onSilence:()=>{M({type:"commit"}),r("thinking")},silenceDurationMs:u,silenceThreshold:k});c===v?(v.microphone=R,L(!1),r("listening")):R.stop()}catch(t){T(t instanceof Error?t:new Error(String(t))),C()}finally{b=!1}}},O=()=>{const t=!U();return c?.microphone?.setMuted(t),L(t),t},q=t=>{M({text:t,type:"text"})&&r("thinking")};return B(C),{audioLevel:I,connected:h,endCall:P,error:N,interimTranscript:F,isMuted:U,sendText:q,startCall:H,status:p,toggleMute:O,transcript:E}};export{ie as createVoiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createSignal as i}from"solid-js";import{useLunora as d}from"./LunoraContext-dPcjtn6R.mjs";import{o as l}from"./solid-compat-ByG5HD_F.mjs";const b=t=>{const o=d(),{args:a,functionPath:e,shardKey:r,value:n}=t,[s,c]=i(n),u={__lunoraRef:e};return l(()=>o.subscribe(u,a,f=>c(()=>f),{shardKey:r})),s};export{b as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as f}from"@lunora/errors";import*as n from"solid-js";const e=n,s=typeof e.onSettled=="function",r=(o,t)=>{if(o===void 0)throw new f("INTERNAL",`@lunora/solid could not find \`${t}\` on the installed solid-js. Expected Solid 1.x (which exports it) or 2.x (which exports \`onSettled\`); found neither.`);return o},u=(o,t)=>{if(s){n.createEffect(o,t);return}const d=r(e.on,"on");n.createEffect(d(o,c=>{const i=t(c);i&&n.onCleanup(i)}))},a=o=>{if(s){r(e.onSettled,"onSettled")(o);return}r(e.onMount,"onMount")(()=>{const t=o();t&&n.onCleanup(t)})},p=o=>{const{Provider:t}=o;return t??o};export{a as o,p,u as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const f=(t,n)=>t<n?-1:t>n?1:0,s=t=>{if(t===void 0)return"null";if(typeof t=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(typeof t=="number"){if(Number.isNaN(t))return"nan";if(t===1/0)return"inf";if(t===-1/0)return"-inf";if(Object.is(t,-0))return"-0"}if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(r=>s(r)).join(",")}]`;const n=Object.getPrototypeOf(t);if(n!==null&&n!==Object.prototype){const r=t.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${r} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const i=t,y=Object.keys(i).toSorted(f),e=[];for(const r of y){const o=i[r];o!==void 0&&e.push(`${JSON.stringify(r)}:${s(o)}`)}return`{${e.join(",")}}`};export{s};
|
package/dist/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createServerClient as d,deserializePreloaded as l,getServerSession as a,preloadQuery as o,preloadedQueryResult as i,serializePreloaded as s}from"@lunora/client/ssr";export{d as createServerClient,l as deserializePreloaded,a as getServerSession,o as preloadQuery,i as preloadedQueryResult,s as serializePreloaded};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { RestrictionError, UploadControl, UploadError, type UploadMethod, type UploadRestrictions, type UploadResult } from '@visulima/storage-client';
|
|
2
|
+
export { type CreateChunkedRestUploadOptions, type CreateChunkedRestUploadReturn, type CreateFileInputOptions, type CreateFileInputReturn, type CreateMultipartUploadOptions, type CreateMultipartUploadReturn, type CreatePasteUploadOptions, type CreatePasteUploadReturn, type CreateTusUploadOptions, type CreateTusUploadReturn, type CreateUploadOptions, type CreateUploadReturn, createChunkedRestUpload, createFileInput, createMultipartUpload, createPasteUpload, createTusUpload, createUpload } from '@visulima/storage-client/solid';
|
package/dist/upload.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { RestrictionError, UploadControl, UploadError, type UploadMethod, type UploadRestrictions, type UploadResult } from '@visulima/storage-client';
|
|
2
|
+
export { type CreateChunkedRestUploadOptions, type CreateChunkedRestUploadReturn, type CreateFileInputOptions, type CreateFileInputReturn, type CreateMultipartUploadOptions, type CreateMultipartUploadReturn, type CreatePasteUploadOptions, type CreatePasteUploadReturn, type CreateTusUploadOptions, type CreateTusUploadReturn, type CreateUploadOptions, type CreateUploadReturn, createChunkedRestUpload, createFileInput, createMultipartUpload, createPasteUpload, createTusUpload, createUpload } from '@visulima/storage-client/solid';
|
package/dist/upload.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{RestrictionError as o,UploadControl as t,UploadError as a}from"@visulima/storage-client";import{createChunkedRestUpload as l,createFileInput as d,createMultipartUpload as c,createPasteUpload as U,createTusUpload as i,createUpload as n}from"@visulima/storage-client/solid";export{o as RestrictionError,t as UploadControl,a as UploadError,l as createChunkedRestUpload,d as createFileInput,c as createMultipartUpload,U as createPasteUpload,i as createTusUpload,n as createUpload};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/solid",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.61",
|
|
4
4
|
"description": "SolidJS adapter for Lunora — live queries, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -44,17 +44,23 @@
|
|
|
44
44
|
"types": "./dist/server.d.ts",
|
|
45
45
|
"import": "./dist/server.mjs"
|
|
46
46
|
},
|
|
47
|
+
"./upload": {
|
|
48
|
+
"types": "./dist/upload.d.ts",
|
|
49
|
+
"import": "./dist/upload.mjs"
|
|
50
|
+
},
|
|
47
51
|
"./package.json": "./package.json"
|
|
48
52
|
},
|
|
49
53
|
"publishConfig": {
|
|
50
54
|
"access": "public"
|
|
51
55
|
},
|
|
52
56
|
"dependencies": {
|
|
53
|
-
"@lunora/client": "1.0.0-alpha.
|
|
54
|
-
"@lunora/
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.58",
|
|
58
|
+
"@lunora/errors": "1.0.0-alpha.23",
|
|
59
|
+
"@lunora/ratelimit": "1.0.0-alpha.26",
|
|
60
|
+
"@visulima/storage-client": "1.0.2"
|
|
55
61
|
},
|
|
56
62
|
"peerDependencies": {
|
|
57
|
-
"solid-js": "^1.9.0"
|
|
63
|
+
"solid-js": "^1.9.0 || ^2.0.0-rc.0"
|
|
58
64
|
},
|
|
59
65
|
"peerDependenciesMeta": {
|
|
60
66
|
"solid-js": {
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { createComponent, memo } from 'solid-js/web';
|
|
2
|
-
import { getIdentityStore } from '@lunora/client/auth';
|
|
3
|
-
import { Show, createSignal, onCleanup } from 'solid-js';
|
|
4
|
-
import { useLunora } from './LunoraContext-C9SpKj54.mjs';
|
|
5
|
-
|
|
6
|
-
const createAuth = () => {
|
|
7
|
-
const client = useLunora();
|
|
8
|
-
const store = getIdentityStore(client);
|
|
9
|
-
const [token, setTokenSignal] = createSignal(client.getAuthToken());
|
|
10
|
-
const [user, setUserSignal] = createSignal(store.getUser());
|
|
11
|
-
const unsubToken = client.onAuthTokenChange((next) => {
|
|
12
|
-
setTokenSignal(() => next);
|
|
13
|
-
});
|
|
14
|
-
const unsubUser = store.subscribe(() => {
|
|
15
|
-
setUserSignal(() => store.getUser());
|
|
16
|
-
});
|
|
17
|
-
onCleanup(() => {
|
|
18
|
-
unsubToken();
|
|
19
|
-
unsubUser();
|
|
20
|
-
});
|
|
21
|
-
const setToken = (next) => {
|
|
22
|
-
client.setAuthToken(next);
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
setToken,
|
|
26
|
-
token,
|
|
27
|
-
user
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
const Authenticated = (props) => {
|
|
31
|
-
const {
|
|
32
|
-
token,
|
|
33
|
-
user
|
|
34
|
-
} = createAuth();
|
|
35
|
-
return createComponent(Show, {
|
|
36
|
-
get when() {
|
|
37
|
-
return memo(() => token() === null)() ? false : user() !== null;
|
|
38
|
-
},
|
|
39
|
-
get children() {
|
|
40
|
-
return props.children;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
const AuthLoading = (props) => {
|
|
45
|
-
const {
|
|
46
|
-
token,
|
|
47
|
-
user
|
|
48
|
-
} = createAuth();
|
|
49
|
-
return createComponent(Show, {
|
|
50
|
-
get when() {
|
|
51
|
-
return memo(() => token() === null)() ? false : user() === null;
|
|
52
|
-
},
|
|
53
|
-
get children() {
|
|
54
|
-
return props.children;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
const Unauthenticated = (props) => {
|
|
59
|
-
const {
|
|
60
|
-
token,
|
|
61
|
-
user
|
|
62
|
-
} = createAuth();
|
|
63
|
-
return createComponent(Show, {
|
|
64
|
-
get when() {
|
|
65
|
-
return memo(() => token() === null)() ? user() === null : false;
|
|
66
|
-
},
|
|
67
|
-
get children() {
|
|
68
|
-
return props.children;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export { AuthLoading, Authenticated, Unauthenticated, createAuth };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from 'solid-js';
|
|
2
|
-
|
|
3
|
-
const LunoraContext = createContext();
|
|
4
|
-
const useLunora = () => {
|
|
5
|
-
const client = useContext(LunoraContext);
|
|
6
|
-
if (!client) {
|
|
7
|
-
throw new Error("useLunora must be used inside <LunoraProvider />");
|
|
8
|
-
}
|
|
9
|
-
return client;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { LunoraContext, useLunora };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createComponent } from 'solid-js/web';
|
|
2
|
-
import { LunoraContext } from './LunoraContext-C9SpKj54.mjs';
|
|
3
|
-
|
|
4
|
-
const LunoraProvider = (props) => (
|
|
5
|
-
// `props.client` is read lazily inside the JSX so Solid tracks it: swapping
|
|
6
|
-
// the client prop re-provides the new value to descendants.
|
|
7
|
-
createComponent(LunoraContext.Provider, {
|
|
8
|
-
get value() {
|
|
9
|
-
return props.client;
|
|
10
|
-
},
|
|
11
|
-
get children() {
|
|
12
|
-
return props.children;
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
export { LunoraProvider };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createSignal, onCleanup } from 'solid-js';
|
|
2
|
-
import { useLunora } from './LunoraContext-C9SpKj54.mjs';
|
|
3
|
-
|
|
4
|
-
const createConnectionStatus = () => {
|
|
5
|
-
const client = useLunora();
|
|
6
|
-
const [status, setStatus] = createSignal(client.connectionStatus());
|
|
7
|
-
const unsubscribe = client.onConnectionStatus((next) => {
|
|
8
|
-
setStatus(next);
|
|
9
|
-
});
|
|
10
|
-
onCleanup(unsubscribe);
|
|
11
|
-
return status;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { createConnectionStatus as default };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
2
|
-
import { useLunora } from './LunoraContext-C9SpKj54.mjs';
|
|
3
|
-
|
|
4
|
-
const compareKeys = (a, b) => {
|
|
5
|
-
if (a < b) {
|
|
6
|
-
return -1;
|
|
7
|
-
}
|
|
8
|
-
return a > b ? 1 : 0;
|
|
9
|
-
};
|
|
10
|
-
const stableStringify = (value) => {
|
|
11
|
-
if (value === void 0) {
|
|
12
|
-
return "null";
|
|
13
|
-
}
|
|
14
|
-
if (value === null || typeof value !== "object") {
|
|
15
|
-
return JSON.stringify(value);
|
|
16
|
-
}
|
|
17
|
-
if (Array.isArray(value)) {
|
|
18
|
-
return `[${value.map((item) => stableStringify(item)).join(",")}]`;
|
|
19
|
-
}
|
|
20
|
-
const record = value;
|
|
21
|
-
const keys = Object.keys(record).toSorted(compareKeys);
|
|
22
|
-
const parts = [];
|
|
23
|
-
for (const key of keys) {
|
|
24
|
-
const raw = record[key];
|
|
25
|
-
if (raw === void 0) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
parts.push(`${JSON.stringify(key)}:${stableStringify(raw)}`);
|
|
29
|
-
}
|
|
30
|
-
return `{${parts.join(",")}}`;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
|
|
34
|
-
const flagKind = (value) => {
|
|
35
|
-
const kind = typeof value;
|
|
36
|
-
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
37
|
-
return kind;
|
|
38
|
-
}
|
|
39
|
-
return "object";
|
|
40
|
-
};
|
|
41
|
-
const flagsReference = {
|
|
42
|
-
__lunoraRef: FLAGS_EVAL_PATH
|
|
43
|
-
};
|
|
44
|
-
const resolveMaybe = (value) => typeof value === "function" ? value() : value;
|
|
45
|
-
const serializeContext = (context) => context === void 0 ? "" : stableStringify(context);
|
|
46
|
-
const createFlag = (key, defaultValue, context) => {
|
|
47
|
-
const client = useLunora();
|
|
48
|
-
const type = flagKind(defaultValue);
|
|
49
|
-
const [value, setValue] = createSignal(defaultValue);
|
|
50
|
-
createEffect(on(() => `${resolveMaybe(key)} ${serializeContext(resolveMaybe(context))}`, () => {
|
|
51
|
-
const currentKey = resolveMaybe(key);
|
|
52
|
-
const currentContext = resolveMaybe(context);
|
|
53
|
-
setValue(() => defaultValue);
|
|
54
|
-
let unsubscribe;
|
|
55
|
-
try {
|
|
56
|
-
unsubscribe = client.subscribe(flagsReference, {
|
|
57
|
-
context: currentContext,
|
|
58
|
-
default: defaultValue,
|
|
59
|
-
key: currentKey,
|
|
60
|
-
type
|
|
61
|
-
}, (next) => {
|
|
62
|
-
setValue(() => next);
|
|
63
|
-
});
|
|
64
|
-
} catch {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
onCleanup(unsubscribe);
|
|
68
|
-
}));
|
|
69
|
-
return value;
|
|
70
|
-
};
|
|
71
|
-
const createFlags = (flags, context) => {
|
|
72
|
-
const client = useLunora();
|
|
73
|
-
const [values, setValues] = createSignal(flags);
|
|
74
|
-
const spec = stableStringify(flags);
|
|
75
|
-
createEffect(on(() => `${spec} ${serializeContext(resolveMaybe(context))}`, () => {
|
|
76
|
-
const currentContext = resolveMaybe(context);
|
|
77
|
-
setValues(() => flags);
|
|
78
|
-
const unsubscribes = [];
|
|
79
|
-
for (const [key, defaultValue] of Object.entries(flags)) {
|
|
80
|
-
try {
|
|
81
|
-
unsubscribes.push(client.subscribe(flagsReference, {
|
|
82
|
-
context: currentContext,
|
|
83
|
-
default: defaultValue,
|
|
84
|
-
key,
|
|
85
|
-
type: flagKind(defaultValue)
|
|
86
|
-
}, (next) => {
|
|
87
|
-
setValues((previous) => {
|
|
88
|
-
return {
|
|
89
|
-
...previous,
|
|
90
|
-
[key]: next
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
}));
|
|
94
|
-
} catch {
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
onCleanup(() => {
|
|
98
|
-
for (const unsubscribe of unsubscribes) {
|
|
99
|
-
unsubscribe();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}));
|
|
103
|
-
return values;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export { createFlag, createFlags };
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
|
|
2
|
-
import { createMemo, createSignal, createEffect, on, onCleanup } from 'solid-js';
|
|
3
|
-
import { useLunora } from './LunoraContext-C9SpKj54.mjs';
|
|
4
|
-
|
|
5
|
-
const buildPageArgs = (page, baseArgs) => {
|
|
6
|
-
return {
|
|
7
|
-
...baseArgs,
|
|
8
|
-
paginationOpts: {
|
|
9
|
-
cursor: page.lower,
|
|
10
|
-
endCursor: page.upper,
|
|
11
|
-
numItems: page.numItems
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${JSON.stringify(pageArgs)}`;
|
|
16
|
-
const createPaginatedCore = (function_, args, options) => {
|
|
17
|
-
const client = useLunora();
|
|
18
|
-
const {
|
|
19
|
-
initialNumItems,
|
|
20
|
-
shardKey
|
|
21
|
-
} = options;
|
|
22
|
-
const resolveArgs = () => typeof args === "function" ? args() : args;
|
|
23
|
-
const [pages, setPages] = createSignal(initialPages(initialNumItems));
|
|
24
|
-
const resultsByKey = /* @__PURE__ */ new Map();
|
|
25
|
-
const [pageResults, setPageResults] = createSignal([]);
|
|
26
|
-
const activeSubs = /* @__PURE__ */ new Map();
|
|
27
|
-
const pendingPageKeys = /* @__PURE__ */ new Set();
|
|
28
|
-
const rebuildPageResults = (currentPages, baseArgs) => {
|
|
29
|
-
const updated = currentPages.map((page) => {
|
|
30
|
-
const key = buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs));
|
|
31
|
-
return resultsByKey.get(key);
|
|
32
|
-
});
|
|
33
|
-
setPageResults(updated);
|
|
34
|
-
};
|
|
35
|
-
const syncSubscriptions = (currentPages, baseArgs) => {
|
|
36
|
-
const wantedKeys = /* @__PURE__ */ new Set();
|
|
37
|
-
for (const page of currentPages) {
|
|
38
|
-
wantedKeys.add(buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs)));
|
|
39
|
-
}
|
|
40
|
-
for (const [key, unsub] of activeSubs) {
|
|
41
|
-
if (!wantedKeys.has(key)) {
|
|
42
|
-
unsub();
|
|
43
|
-
activeSubs.delete(key);
|
|
44
|
-
pendingPageKeys.delete(key);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
for (const page of currentPages) {
|
|
48
|
-
const pageArgs = buildPageArgs(page, baseArgs);
|
|
49
|
-
const key = buildPageKey(function_["__lunoraRef"], pageArgs);
|
|
50
|
-
if (activeSubs.has(key)) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
pendingPageKeys.add(key);
|
|
54
|
-
const unsub = client.subscribe(function_, pageArgs, (value) => {
|
|
55
|
-
resultsByKey.set(key, value);
|
|
56
|
-
pendingPageKeys.delete(key);
|
|
57
|
-
const currentArgs = resolveArgs();
|
|
58
|
-
if (currentArgs === "skip") {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
rebuildPageResults(pages(), currentArgs);
|
|
62
|
-
if (pendingPageKeys.size === 0) {
|
|
63
|
-
const next = rebalance(pages(), pageResults());
|
|
64
|
-
if (next) {
|
|
65
|
-
setPages(next);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}, {
|
|
69
|
-
shardKey
|
|
70
|
-
});
|
|
71
|
-
activeSubs.set(key, unsub);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const teardownAll = () => {
|
|
75
|
-
for (const unsub of activeSubs.values()) {
|
|
76
|
-
unsub();
|
|
77
|
-
}
|
|
78
|
-
activeSubs.clear();
|
|
79
|
-
resultsByKey.clear();
|
|
80
|
-
pendingPageKeys.clear();
|
|
81
|
-
};
|
|
82
|
-
createEffect(on(resolveArgs, (current) => {
|
|
83
|
-
teardownAll();
|
|
84
|
-
setPages(initialPages(initialNumItems));
|
|
85
|
-
setPageResults([]);
|
|
86
|
-
if (current !== "skip") {
|
|
87
|
-
syncSubscriptions(pages(), current);
|
|
88
|
-
rebuildPageResults(pages(), current);
|
|
89
|
-
}
|
|
90
|
-
onCleanup(teardownAll);
|
|
91
|
-
}));
|
|
92
|
-
createEffect(on(pages, (currentPages) => {
|
|
93
|
-
const current = resolveArgs();
|
|
94
|
-
if (current !== "skip") {
|
|
95
|
-
syncSubscriptions(currentPages, current);
|
|
96
|
-
rebuildPageResults(currentPages, current);
|
|
97
|
-
}
|
|
98
|
-
}));
|
|
99
|
-
const status = createMemo(() => {
|
|
100
|
-
const skipped = resolveArgs() === "skip";
|
|
101
|
-
return derivePaginationStatus(skipped, pageResults()).status;
|
|
102
|
-
});
|
|
103
|
-
const loadMore = (numberItems) => {
|
|
104
|
-
const current = resolveArgs();
|
|
105
|
-
if (current === "skip") {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const {
|
|
109
|
-
nextCursor,
|
|
110
|
-
status: currentStatus
|
|
111
|
-
} = derivePaginationStatus(false, pageResults());
|
|
112
|
-
if (currentStatus !== "CanLoadMore") {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const next = applyLoadMore(pages(), nextCursor, numberItems);
|
|
116
|
-
if (!next) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const oldTail = pages().at(-1);
|
|
120
|
-
const newPinnedPage = next.at(-2);
|
|
121
|
-
if (oldTail && newPinnedPage) {
|
|
122
|
-
const oldKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(oldTail, current));
|
|
123
|
-
const newKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(newPinnedPage, current));
|
|
124
|
-
if (oldKey !== newKey) {
|
|
125
|
-
const carried = resultsByKey.get(oldKey);
|
|
126
|
-
if (carried) {
|
|
127
|
-
resultsByKey.set(newKey, carried);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
setPages(next);
|
|
132
|
-
};
|
|
133
|
-
return {
|
|
134
|
-
loadMore,
|
|
135
|
-
pageResults,
|
|
136
|
-
status
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
const createPaginatedQuery = (function_, args, options) => {
|
|
140
|
-
const {
|
|
141
|
-
loadMore,
|
|
142
|
-
pageResults,
|
|
143
|
-
status
|
|
144
|
-
} = createPaginatedCore(function_, args, options);
|
|
145
|
-
const results = createMemo(() => {
|
|
146
|
-
const items = [];
|
|
147
|
-
for (const page of pageResults()) {
|
|
148
|
-
if (page) {
|
|
149
|
-
items.push(...page.page);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return items;
|
|
153
|
-
});
|
|
154
|
-
const isLoading = createMemo(() => status() === "LoadingFirstPage" || status() === "LoadingMore");
|
|
155
|
-
return {
|
|
156
|
-
isLoading,
|
|
157
|
-
loadMore,
|
|
158
|
-
results,
|
|
159
|
-
status
|
|
160
|
-
};
|
|
161
|
-
};
|
|
162
|
-
const createInfiniteQuery = (function_, args, options) => {
|
|
163
|
-
const {
|
|
164
|
-
initialNumItems
|
|
165
|
-
} = options;
|
|
166
|
-
const {
|
|
167
|
-
loadMore,
|
|
168
|
-
pageResults,
|
|
169
|
-
status
|
|
170
|
-
} = createPaginatedCore(function_, args, options);
|
|
171
|
-
const pages = createMemo(() => {
|
|
172
|
-
const result = [];
|
|
173
|
-
for (const page of pageResults()) {
|
|
174
|
-
if (page) {
|
|
175
|
-
result.push(page.page);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return result;
|
|
179
|
-
});
|
|
180
|
-
const isLoading = createMemo(() => status() === "LoadingFirstPage");
|
|
181
|
-
const hasNextPage = createMemo(() => status() === "CanLoadMore");
|
|
182
|
-
const isFetchingNextPage = createMemo(() => status() === "LoadingMore");
|
|
183
|
-
const fetchNextPage = (numberItems) => {
|
|
184
|
-
loadMore(numberItems ?? initialNumItems);
|
|
185
|
-
};
|
|
186
|
-
return {
|
|
187
|
-
fetchNextPage,
|
|
188
|
-
hasNextPage,
|
|
189
|
-
isFetchingNextPage,
|
|
190
|
-
isLoading,
|
|
191
|
-
pages,
|
|
192
|
-
status
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
export { createInfiniteQuery, createPaginatedQuery };
|