@lunora/angular 1.0.0-alpha.23 → 1.0.0-alpha.24
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
|
@@ -125,7 +125,7 @@ interface AgentOptions {
|
|
|
125
125
|
api: AgentApi;
|
|
126
126
|
/**
|
|
127
127
|
* Optional app mutation over the agent's cancel path
|
|
128
|
-
* (`ctx.agents
|
|
128
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
129
129
|
* When omitted (or no run is in flight) {@link AgentResult.cancel} is a no-op.
|
|
130
130
|
*/
|
|
131
131
|
cancel?: FunctionReference<"mutation">;
|
|
@@ -138,7 +138,7 @@ interface AgentOptions {
|
|
|
138
138
|
destroyRef?: DestroyRef;
|
|
139
139
|
/**
|
|
140
140
|
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
141
|
-
* `ctx.agents
|
|
141
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
142
142
|
* {@link AgentOptions.runArgs} and the per-call args.
|
|
143
143
|
*/
|
|
144
144
|
run: FunctionReference<"mutation">;
|
|
@@ -174,7 +174,7 @@ interface AgentResult {
|
|
|
174
174
|
* conversation surface (durable history + streaming + approvals) use `agentChat`.
|
|
175
175
|
*
|
|
176
176
|
* `run` and `cancel` stay generic over the app-defined mutations that wrap
|
|
177
|
-
* `ctx.agents
|
|
177
|
+
* `ctx.agents.<name>.run` / `.cancel`, so the primitive hard-codes no function
|
|
178
178
|
* names beyond the `agents:*` surface.
|
|
179
179
|
*
|
|
180
180
|
* Call from an injection context (component/service field or constructor); pass an
|
|
@@ -232,7 +232,7 @@ interface AgentChatOptions {
|
|
|
232
232
|
api: AgentChatApi;
|
|
233
233
|
/**
|
|
234
234
|
* Optional app mutation over the agent's cancel path
|
|
235
|
-
* (`ctx.agents
|
|
235
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
236
236
|
* When omitted (or no run is in flight) {@link AgentChatResult.cancel} is a
|
|
237
237
|
* no-op.
|
|
238
238
|
*/
|
|
@@ -248,7 +248,7 @@ interface AgentChatOptions {
|
|
|
248
248
|
limit?: number;
|
|
249
249
|
/**
|
|
250
250
|
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
251
|
-
* `ctx.agents
|
|
251
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
252
252
|
* {@link AgentChatOptions.sendArgs} and the per-call args.
|
|
253
253
|
*/
|
|
254
254
|
send: FunctionReference<"mutation">;
|
|
@@ -363,7 +363,7 @@ interface AgentStateResult<T> {
|
|
|
363
363
|
* only on a real `setState`. The Angular counterpart to React's `useAgentState`,
|
|
364
364
|
* re-expressed with signals.
|
|
365
365
|
*
|
|
366
|
-
* Generic over the app's state shape (`agentState
|
|
366
|
+
* Generic over the app's state shape (`agentState<SupportState>(...)`, itself a
|
|
367
367
|
* record) — the reference is typed as an optional record because codegen cannot see
|
|
368
368
|
* the per-agent state type; the generic casts to `T`. The `extends` bound (not a
|
|
369
369
|
* bare unbounded type parameter) is required: this `.ts` file is parsed JSX-aware by
|
|
@@ -1225,9 +1225,9 @@ type CreateSpeaker = (config: {
|
|
|
1225
1225
|
audioFormat: VoiceAudioFormat;
|
|
1226
1226
|
}) => VoiceSpeaker;
|
|
1227
1227
|
/**
|
|
1228
|
-
* The `agents
|
|
1228
|
+
* The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
|
|
1229
1229
|
* live, WS-backed session keyed by `threadKey`. A structural subset of the
|
|
1230
|
-
* generated member, so passing `api.agents
|
|
1230
|
+
* generated member, so passing `api.agents.<name>Voice` type-checks.
|
|
1231
1231
|
* @experimental
|
|
1232
1232
|
*/
|
|
1233
1233
|
type VoiceReference = FunctionReference<"stream", {
|
|
@@ -1284,7 +1284,7 @@ interface VoiceAgentOptions {
|
|
|
1284
1284
|
silenceThreshold?: number;
|
|
1285
1285
|
/** The thread to converse on — shared with the agent's text turns. Resolved when the call opens. */
|
|
1286
1286
|
threadKey: string;
|
|
1287
|
-
/** The generated `api.agents
|
|
1287
|
+
/** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
|
|
1288
1288
|
voice: VoiceReference;
|
|
1289
1289
|
}
|
|
1290
1290
|
/**
|
|
@@ -1320,7 +1320,7 @@ interface VoiceAgentResult {
|
|
|
1320
1320
|
* WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
|
|
1321
1321
|
* streams the agent's synthesized speech back through the browser's audio output,
|
|
1322
1322
|
* and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
|
|
1323
|
-
* `audioLevel`) to Angular signals. Pass the generated `api.agents
|
|
1323
|
+
* `audioLevel`) to Angular signals. Pass the generated `api.agents.<name>Voice`
|
|
1324
1324
|
* reference (never a string), matching `agentChat`'s reference-passing style. The
|
|
1325
1325
|
* Angular counterpart to React's `useVoiceAgent`, re-expressed with signals; the
|
|
1326
1326
|
* per-call connection lives in a closure variable (the primitive runs once per
|
package/dist/index.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ interface AgentOptions {
|
|
|
125
125
|
api: AgentApi;
|
|
126
126
|
/**
|
|
127
127
|
* Optional app mutation over the agent's cancel path
|
|
128
|
-
* (`ctx.agents
|
|
128
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
129
129
|
* When omitted (or no run is in flight) {@link AgentResult.cancel} is a no-op.
|
|
130
130
|
*/
|
|
131
131
|
cancel?: FunctionReference<"mutation">;
|
|
@@ -138,7 +138,7 @@ interface AgentOptions {
|
|
|
138
138
|
destroyRef?: DestroyRef;
|
|
139
139
|
/**
|
|
140
140
|
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
141
|
-
* `ctx.agents
|
|
141
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
142
142
|
* {@link AgentOptions.runArgs} and the per-call args.
|
|
143
143
|
*/
|
|
144
144
|
run: FunctionReference<"mutation">;
|
|
@@ -174,7 +174,7 @@ interface AgentResult {
|
|
|
174
174
|
* conversation surface (durable history + streaming + approvals) use `agentChat`.
|
|
175
175
|
*
|
|
176
176
|
* `run` and `cancel` stay generic over the app-defined mutations that wrap
|
|
177
|
-
* `ctx.agents
|
|
177
|
+
* `ctx.agents.<name>.run` / `.cancel`, so the primitive hard-codes no function
|
|
178
178
|
* names beyond the `agents:*` surface.
|
|
179
179
|
*
|
|
180
180
|
* Call from an injection context (component/service field or constructor); pass an
|
|
@@ -232,7 +232,7 @@ interface AgentChatOptions {
|
|
|
232
232
|
api: AgentChatApi;
|
|
233
233
|
/**
|
|
234
234
|
* Optional app mutation over the agent's cancel path
|
|
235
|
-
* (`ctx.agents
|
|
235
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
236
236
|
* When omitted (or no run is in flight) {@link AgentChatResult.cancel} is a
|
|
237
237
|
* no-op.
|
|
238
238
|
*/
|
|
@@ -248,7 +248,7 @@ interface AgentChatOptions {
|
|
|
248
248
|
limit?: number;
|
|
249
249
|
/**
|
|
250
250
|
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
251
|
-
* `ctx.agents
|
|
251
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
252
252
|
* {@link AgentChatOptions.sendArgs} and the per-call args.
|
|
253
253
|
*/
|
|
254
254
|
send: FunctionReference<"mutation">;
|
|
@@ -363,7 +363,7 @@ interface AgentStateResult<T> {
|
|
|
363
363
|
* only on a real `setState`. The Angular counterpart to React's `useAgentState`,
|
|
364
364
|
* re-expressed with signals.
|
|
365
365
|
*
|
|
366
|
-
* Generic over the app's state shape (`agentState
|
|
366
|
+
* Generic over the app's state shape (`agentState<SupportState>(...)`, itself a
|
|
367
367
|
* record) — the reference is typed as an optional record because codegen cannot see
|
|
368
368
|
* the per-agent state type; the generic casts to `T`. The `extends` bound (not a
|
|
369
369
|
* bare unbounded type parameter) is required: this `.ts` file is parsed JSX-aware by
|
|
@@ -1225,9 +1225,9 @@ type CreateSpeaker = (config: {
|
|
|
1225
1225
|
audioFormat: VoiceAudioFormat;
|
|
1226
1226
|
}) => VoiceSpeaker;
|
|
1227
1227
|
/**
|
|
1228
|
-
* The `agents
|
|
1228
|
+
* The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
|
|
1229
1229
|
* live, WS-backed session keyed by `threadKey`. A structural subset of the
|
|
1230
|
-
* generated member, so passing `api.agents
|
|
1230
|
+
* generated member, so passing `api.agents.<name>Voice` type-checks.
|
|
1231
1231
|
* @experimental
|
|
1232
1232
|
*/
|
|
1233
1233
|
type VoiceReference = FunctionReference<"stream", {
|
|
@@ -1284,7 +1284,7 @@ interface VoiceAgentOptions {
|
|
|
1284
1284
|
silenceThreshold?: number;
|
|
1285
1285
|
/** The thread to converse on — shared with the agent's text turns. Resolved when the call opens. */
|
|
1286
1286
|
threadKey: string;
|
|
1287
|
-
/** The generated `api.agents
|
|
1287
|
+
/** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
|
|
1288
1288
|
voice: VoiceReference;
|
|
1289
1289
|
}
|
|
1290
1290
|
/**
|
|
@@ -1320,7 +1320,7 @@ interface VoiceAgentResult {
|
|
|
1320
1320
|
* WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
|
|
1321
1321
|
* streams the agent's synthesized speech back through the browser's audio output,
|
|
1322
1322
|
* and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
|
|
1323
|
-
* `audioLevel`) to Angular signals. Pass the generated `api.agents
|
|
1323
|
+
* `audioLevel`) to Angular signals. Pass the generated `api.agents.<name>Voice`
|
|
1324
1324
|
* reference (never a string), matching `agentChat`'s reference-passing style. The
|
|
1325
1325
|
* Angular counterpart to React's `useVoiceAgent`, re-expressed with signals; the
|
|
1326
1326
|
* per-call connection lives in a closure variable (the primitive runs once per
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{agent as e}from"./packem_shared/agent-C-GavfBl.mjs";import{agentChat as m}from"./packem_shared/agentChat-Bay8gA8i.mjs";import{agentState as a}from"./packem_shared/agentState-BAfa0QuC.mjs";import{agentToolEvents as x}from"./packem_shared/agentToolEvents-CBTZ_DsO.mjs";import{auth as i,authGate as u}from"./packem_shared/auth-BTEtMnGG.mjs";import{LUNORA_CLIENT as s,injectLunoraClient as c,provideLunora as l}from"./packem_shared/LUNORA_CLIENT-B0pGE0Tv.mjs";import{connectionStatus as L}from"./packem_shared/connectionStatus-C53UhkPi.mjs";import{flag as v,flags as y}from"./packem_shared/flag-BYFWoQTg.mjs";import{hydratePreloaded as Q}from"./packem_shared/hydratePreloaded-BKHgpXzQ.mjs";import{liveQuery as A}from"./packem_shared/liveQuery-DEIqmTPj.mjs";import{mutate as I}from"./packem_shared/mutate-DR8Uo8Hs.mjs";import{mutator as P}from"./packem_shared/mutator-Cw6jpG06.mjs";import{infiniteQuery as b,paginatedQuery as j}from"./packem_shared/infiniteQuery-
|
|
1
|
+
import{agent as e}from"./packem_shared/agent-C-GavfBl.mjs";import{agentChat as m}from"./packem_shared/agentChat-Bay8gA8i.mjs";import{agentState as a}from"./packem_shared/agentState-BAfa0QuC.mjs";import{agentToolEvents as x}from"./packem_shared/agentToolEvents-CBTZ_DsO.mjs";import{auth as i,authGate as u}from"./packem_shared/auth-BTEtMnGG.mjs";import{LUNORA_CLIENT as s,injectLunoraClient as c,provideLunora as l}from"./packem_shared/LUNORA_CLIENT-B0pGE0Tv.mjs";import{connectionStatus as L}from"./packem_shared/connectionStatus-C53UhkPi.mjs";import{flag as v,flags as y}from"./packem_shared/flag-BYFWoQTg.mjs";import{hydratePreloaded as Q}from"./packem_shared/hydratePreloaded-BKHgpXzQ.mjs";import{liveQuery as A}from"./packem_shared/liveQuery-DEIqmTPj.mjs";import{mutate as I}from"./packem_shared/mutate-DR8Uo8Hs.mjs";import{mutator as P}from"./packem_shared/mutator-Cw6jpG06.mjs";import{infiniteQuery as b,paginatedQuery as j}from"./packem_shared/infiniteQuery-DCiQIPPq.mjs";import{presence as K}from"./packem_shared/presence-BMrTlOCF.mjs";import{rateLimit as R}from"./packem_shared/rateLimit-CQazDrPJ.mjs";import{stream as _}from"./packem_shared/stream-CcvHiJf2.mjs";import{subscription as q}from"./packem_shared/subscription-DJeoGEDR.mjs";import{voiceAgent as z}from"./packem_shared/voiceAgent-CwlzrEjH.mjs";import{SKIP as D}from"@lunora/client/query";export{s as LUNORA_CLIENT,D as SKIP,e as agent,m as agentChat,a as agentState,x as agentToolEvents,i as auth,u as authGate,L as connectionStatus,v as flag,y as flags,Q as hydratePreloaded,b as infiniteQuery,c as injectLunoraClient,A as liveQuery,I as mutate,P as mutator,j as paginatedQuery,K as presence,l as provideLunora,R as rateLimit,_ as stream,q as subscription,z as voiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{computed as L,inject as Q,DestroyRef as W,signal as C}from"@angular/core";import{initialPages as q,derivePaginationStatus as J,applyLoadMore as z,rebalance as V}from"@lunora/client/pagination";import{resolveLunoraClient as G}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{s as H}from"./platform-BGZypnc9.mjs";const X=(e,r)=>e<r?-1:e>r?1:0,I=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(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>I(t)).join(",")}]`;const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const t=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${t} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const s=e,c=Object.keys(s).toSorted(X),a=[];for(const t of c){const n=s[t];n!==void 0&&a.push(`${JSON.stringify(t)}:${I(n)}`)}return`{${a.join(",")}}`},F=e=>{let r="";for(let s=0;s<e.length;s+=32768)r+=String.fromCharCode(...e.subarray(s,s+32768));return btoa(r)},u="$lunora.wire$",T=64,Y="__proto__",Z=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},v=(e,r=0)=>{if(r>T)throw new RangeError(`wire-codec: value nesting exceeds the ${T}-level limit`);if(e===void 0)return[u,"undefined"];if(e===null)return null;const s=typeof e;if(s==="bigint")return[u,"bigint",e.toString()];if(s==="number"){const t=e;return Number.isNaN(t)?[u,"nan"]:t===1/0?[u,"inf"]:t===-1/0?[u,"-inf"]:t}if(s!=="object")return e;if(e instanceof Date)return[u,"date",v(e.getTime(),r+1)];if(e instanceof Error){const t=e,n={};for(const y of Object.keys(t))t[y]!==void 0&&(n[y]=v(t[y],r+1));const l=[u,"error",t.name,t.message,n];return t.cause!==void 0&&l.push(v(t.cause,r+1)),l}if(e instanceof URL)return[u,"url",e.href];if(e instanceof Map)return[u,"map",[...e.entries()].map(([t,n])=>[v(t,r+1),v(n,r+1)])];if(e instanceof Set)return[u,"set",[...e].map(t=>v(t,r+1))];if(e instanceof ArrayBuffer)return[u,"bytes",F(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,n=t.constructor.name,l=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return n==="Uint8Array"?[u,"bytes",F(l)]:[u,"bytes",F(l),n]}if(Array.isArray(e)){const t=e.map(n=>v(n,r+1));return t.length>0&&t[0]===u?[u,"arr",t]:t}if(!Z(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const c=e,a={};for(const t of Object.keys(c)){const n=c[t];if(n===void 0)continue;const l=v(n,r+1);t===Y?Object.defineProperty(a,t,{configurable:!0,enumerable:!0,value:l,writable:!0}):a[t]=l}return a},ee=e=>I(v(e)),S=(e,r)=>`${e}::${ee(r)}`,j=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),U=(e,r,s)=>{const c=G(s.client),a=s.destroyRef===void 0,t=s.destroyRef??Q(W),{initialNumItems:n,shardKey:l}=s,y=e.__lunoraRef,g=r==="skip"?{}:r,p=C(q(n)),$=C([]),_=C("LoadingFirstPage"),O=new Map,h=new Map,A=new Set,M=()=>{const f=p().map(w=>{const o=S(y,j(w,g));return h.get(o)});$.set(f);const{status:b}=J(r==="skip",f);_.set(b)},B=(f,b)=>{const w=o=>S(y,j(o,g));for(const o of b){const d=w(o);if(h.has(d))continue;const m=f.find(i=>i.lower===o.lower);if(m){const i=h.get(w(m));i&&h.set(d,i)}}},D=f=>{const b=new Set;for(const o of f)b.add(S(y,j(o,g)));for(const[o,d]of O)b.has(d.currentKey)||(d.unsub(),O.delete(o),h.delete(d.currentKey));const w=new Set([...O.values()].map(o=>o.currentKey));for(const o of f){const d=j(o,g),m=S(y,d);if(w.has(m))continue;const i={currentKey:m,unsub:void 0};A.add(m);const k=c.subscribe(e,d,K=>{if(h.set(i.currentKey,K),A.delete(i.currentKey),M(),A.size===0){const N=p(),P=V(N,$());P&&(B(N,P),p.set(P),x(P),M())}},{onError:()=>{A.delete(i.currentKey),M()},shardKey:l});i.unsub=k,O.set(m,i),w.add(m)}};let R=!1,E=!1;const x=f=>{if(R){E=!0;return}R=!0;try{let b=f;do E=!1,D(b),b=p();while(E)}finally{R=!1}};return r!=="skip"&&H(a)&&x(p()),M(),t.onDestroy(()=>{for(const f of O.values())f.unsub();O.clear(),h.clear()}),{loadMore:f=>{if(r==="skip")return;const{nextCursor:b,status:w}=J(!1,$());if(w!=="CanLoadMore")return;const o=z(p(),b,f);if(!o)return;const d=p().at(-1),m=o.at(-2);if(d&&m){const i=S(y,j(d,g)),k=S(y,j(m,g)),K=O.get(i);if(K&&i!==k){const N=h.get(i);N&&h.set(k,N),K.unsub(),O.delete(i),h.delete(i)}}p.set(o),x(p()),M()},pageResults:$,status:_}},oe=(e,r,s)=>{const c=U(e,r,s),a=L(()=>{const t=[];for(const n of c.pageResults())n&&t.push(...n.page);return t});return{isLoading:L(()=>{const t=c.status();return t==="LoadingFirstPage"||t==="LoadingMore"}),loadMore:c.loadMore,results:a,status:c.status}},ae=(e,r,s)=>{const{initialNumItems:c}=s,a=U(e,r,s),t=L(()=>{const g=[];for(const p of a.pageResults())p&&g.push(p.page);return g}),n=L(()=>a.status()==="LoadingFirstPage"),l=L(()=>a.status()==="CanLoadMore"),y=L(()=>a.status()==="LoadingMore");return{fetchNextPage:g=>{a.loadMore(g??c)},hasNextPage:l,isFetchingNextPage:y,isLoading:n,pages:t,status:a.status}};export{ae as infiniteQuery,oe as paginatedQuery};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/angular",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.24",
|
|
4
4
|
"description": "Angular reactive adapter for Lunora — signal-based live queries and mutations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@lunora/client": "1.0.0-alpha.
|
|
53
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
52
|
+
"@lunora/client": "1.0.0-alpha.40",
|
|
53
|
+
"@lunora/ratelimit": "1.0.0-alpha.17",
|
|
54
54
|
"@visulima/storage-client": "1.0.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{computed as j,inject as W,DestroyRef as _,signal as C}from"@angular/core";import{initialPages as q,derivePaginationStatus as T,applyLoadMore as z,rebalance as V}from"@lunora/client/pagination";import{resolveLunoraClient as G}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{s as H}from"./platform-BGZypnc9.mjs";const X=(e,r)=>e<r?-1:e>r?1:0,I=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(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>I(t)).join(",")}]`;const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const t=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${t} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const n=e,c=Object.keys(n).toSorted(X),a=[];for(const t of c){const s=n[t];s!==void 0&&a.push(`${JSON.stringify(t)}:${I(s)}`)}return`{${a.join(",")}}`},F=e=>{let r="";for(let n=0;n<e.length;n+=32768)r+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(r)},u="$lunora.wire$",U=64,Y=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},v=(e,r=0)=>{if(r>U)throw new RangeError(`wire-codec: value nesting exceeds the ${U}-level limit`);if(e===void 0)return[u,"undefined"];if(e===null)return null;const n=typeof e;if(n==="bigint")return[u,"bigint",e.toString()];if(n==="number"){const t=e;return Number.isNaN(t)?[u,"nan"]:t===1/0?[u,"inf"]:t===-1/0?[u,"-inf"]:t}if(n!=="object")return e;if(e instanceof Date)return[u,"date",v(e.getTime(),r+1)];if(e instanceof Error){const t=e,s={};for(const l of Object.keys(t))t[l]!==void 0&&(s[l]=v(t[l],r+1));const h=[u,"error",t.name,t.message,s];return t.cause!==void 0&&h.push(v(t.cause,r+1)),h}if(e instanceof URL)return[u,"url",e.href];if(e instanceof Map)return[u,"map",[...e.entries()].map(([t,s])=>[v(t,r+1),v(s,r+1)])];if(e instanceof Set)return[u,"set",[...e].map(t=>v(t,r+1))];if(e instanceof ArrayBuffer)return[u,"bytes",F(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,s=t.constructor.name,h=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return s==="Uint8Array"?[u,"bytes",F(h)]:[u,"bytes",F(h),s]}if(Array.isArray(e)){const t=e.map(s=>v(s,r+1));return t.length>0&&t[0]===u?[u,"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 c=e,a={};for(const t of Object.keys(c)){const s=c[t];s!==void 0&&(a[t]=v(s,r+1))}return a},Z=e=>I(v(e)),S=(e,r)=>`${e}::${Z(r)}`,L=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),B=(e,r,n)=>{const c=G(n.client),a=n.destroyRef===void 0,t=n.destroyRef??W(_),{initialNumItems:s,shardKey:h}=n,l=e.__lunoraRef,d=r==="skip"?{}:r,y=C(q(s)),$=C([]),J=C("LoadingFirstPage"),O=new Map,m=new Map,k=new Set,M=()=>{const f=y().map(w=>{const o=S(l,L(w,d));return m.get(o)});$.set(f);const{status:g}=T(r==="skip",f);J.set(g)},D=(f,g)=>{const w=o=>S(l,L(o,d));for(const o of g){const p=w(o);if(m.has(p))continue;const b=f.find(i=>i.lower===o.lower);if(b){const i=m.get(w(b));i&&m.set(p,i)}}},Q=f=>{const g=new Set;for(const o of f)g.add(S(l,L(o,d)));for(const[o,p]of O)g.has(p.currentKey)||(p.unsub(),O.delete(o),m.delete(p.currentKey));const w=new Set([...O.values()].map(o=>o.currentKey));for(const o of f){const p=L(o,d),b=S(l,p);if(w.has(b))continue;const i={currentKey:b,unsub:void 0};k.add(b);const A=c.subscribe(e,p,K=>{if(m.set(i.currentKey,K),k.delete(i.currentKey),M(),k.size===0){const N=y(),R=V(N,$());R&&(D(N,R),y.set(R),x(R),M())}},{onError:()=>{k.delete(i.currentKey),M()},shardKey:h});i.unsub=A,O.set(b,i),w.add(b)}};let P=!1,E=!1;const x=f=>{if(P){E=!0;return}P=!0;try{let g=f;do E=!1,Q(g),g=y();while(E)}finally{P=!1}};return r!=="skip"&&H(a)&&x(y()),M(),t.onDestroy(()=>{for(const f of O.values())f.unsub();O.clear(),m.clear()}),{loadMore:f=>{if(r==="skip")return;const{nextCursor:g,status:w}=T(!1,$());if(w!=="CanLoadMore")return;const o=z(y(),g,f);if(!o)return;const p=y().at(-1),b=o.at(-2);if(p&&b){const i=S(l,L(p,d)),A=S(l,L(b,d)),K=O.get(i);if(K&&i!==A){const N=m.get(i);N&&m.set(A,N),K.unsub(),O.delete(i),m.delete(i)}}y.set(o),x(y()),M()},pageResults:$,status:J}},ne=(e,r,n)=>{const c=B(e,r,n),a=j(()=>{const t=[];for(const s of c.pageResults())s&&t.push(...s.page);return t});return{isLoading:j(()=>{const t=c.status();return t==="LoadingFirstPage"||t==="LoadingMore"}),loadMore:c.loadMore,results:a,status:c.status}},oe=(e,r,n)=>{const{initialNumItems:c}=n,a=B(e,r,n),t=j(()=>{const d=[];for(const y of a.pageResults())y&&d.push(y.page);return d}),s=j(()=>a.status()==="LoadingFirstPage"),h=j(()=>a.status()==="CanLoadMore"),l=j(()=>a.status()==="LoadingMore");return{fetchNextPage:d=>{a.loadMore(d??c)},hasNextPage:h,isFetchingNextPage:l,isLoading:s,pages:t,status:a.status}};export{oe as infiniteQuery,ne as paginatedQuery};
|