@lunora/client 1.0.0-alpha.28 → 1.0.0-alpha.281
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/README.md +19 -4
- package/dist/admin/index.d.mts +647 -0
- package/dist/admin/index.d.ts +647 -0
- package/dist/admin/index.mjs +1 -0
- package/dist/auth/index.d.mts +138 -5
- package/dist/auth/index.d.ts +138 -5
- package/dist/auth/index.mjs +1 -60
- package/dist/index.d.mts +756 -186
- package/dist/index.d.ts +756 -186
- package/dist/index.mjs +1 -21
- package/dist/packem_shared/ADMIN_AUTH_DEFAULT_PAGE_SIZE-V9c3bHU1.mjs +1 -0
- package/dist/packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs +1 -0
- package/dist/packem_shared/DEFAULT_MAX_BUFFER-Bd-_iyiV.mjs +1 -0
- package/dist/packem_shared/LunoraAdminClient-1KWk7JkZ.mjs +1 -0
- package/dist/packem_shared/LunoraClient-DKPUPbuv.mjs +1 -0
- package/dist/packem_shared/OfflineQueue-Ba2qgZK1.mjs +1 -0
- package/dist/packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs +1 -0
- package/dist/packem_shared/SKIP-d7LeP-sY.mjs +1 -0
- package/dist/packem_shared/SubscriptionRegistry-BKgQtuh9.mjs +1 -0
- package/dist/packem_shared/TabCoordinator-IUCwjnqX.mjs +1 -0
- package/dist/packem_shared/applyDelta-CaudNj2C.mjs +1 -0
- package/dist/packem_shared/base64-849R7V-V.mjs +1 -0
- package/dist/packem_shared/client-tuning-C10B2KCO.mjs +1 -0
- package/dist/packem_shared/client-urls-BHLUjjcG.mjs +1 -0
- package/dist/packem_shared/connectLiveStream-BdjsWP1-.mjs +1 -0
- package/dist/packem_shared/createAsyncStoragePersistence-BgfdvLwe.mjs +1 -0
- package/dist/packem_shared/createAsyncStorageQueryCache-6Y94ocbQ.mjs +1 -0
- package/dist/packem_shared/createCallRunner-Bwcrfh76.mjs +1 -0
- package/dist/packem_shared/createClientQuery-B8Nfj-7o.mjs +1 -0
- package/dist/packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs +1 -0
- package/dist/packem_shared/createInMemoryPersistence-C-IzNVbg.mjs +1 -0
- package/dist/packem_shared/createInMemoryQueryCache-DR6AorA2.mjs +1 -0
- package/dist/packem_shared/createLocalStore-D38o4O8Z.mjs +1 -0
- package/dist/packem_shared/createMutatorRunner-CuMRJpUx.mjs +1 -0
- package/dist/packem_shared/createReconnect-CjTmjJDH.mjs +1 -0
- package/dist/packem_shared/createServerClient-97d5uFpA.mjs +1 -0
- package/dist/packem_shared/createSnapshotPrecondition-BXP1NPBW.mjs +1 -0
- package/dist/packem_shared/delta-merge-C6OqMEPH.mjs +1 -0
- package/dist/packem_shared/deserializePreloaded-DxozvweR.mjs +1 -0
- package/dist/packem_shared/frame-hint-D-NK691z.mjs +1 -0
- package/dist/packem_shared/function-reference.d-Br_hsKje.d.mts +45 -0
- package/dist/packem_shared/function-reference.d-Br_hsKje.d.ts +45 -0
- package/dist/packem_shared/getServerSession-BaOoo1p6.mjs +1 -0
- package/dist/packem_shared/httpStream-DN3D9WqW.mjs +7 -0
- package/dist/packem_shared/idb-utility-BS7xvou1.mjs +1 -0
- package/dist/packem_shared/live-stream-DBKgZlnb.mjs +10 -0
- package/dist/packem_shared/liveTopicSubscription-DQtKMFKw.mjs +1 -0
- package/dist/packem_shared/lunora-client-CNUU3FU7.mjs +1 -0
- package/dist/packem_shared/lunora-client.d-C8zXKzbE.d.mts +4966 -0
- package/dist/packem_shared/lunora-client.d-CAIGiEHg.d.ts +4966 -0
- package/dist/packem_shared/lunoraQueryKey-CucWmxnx.mjs +1 -0
- package/dist/packem_shared/offline-queue-BEqCPDmw.mjs +1 -0
- package/dist/packem_shared/optimistic-layers-D-7D3yeJ.mjs +1 -0
- package/dist/packem_shared/{preload.d-Cqb4Kh2I.d.ts → preload.d-CLx5oM3f.d.mts} +2 -1
- package/dist/packem_shared/{preload.d-CLwoXl3R.d.mts → preload.d-DTHQlBVJ.d.ts} +2 -1
- package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
- package/dist/packem_shared/setAuthTokenProvider-DhBppDiZ.mjs +1 -0
- package/dist/packem_shared/single-blob-store-DeaYPBSS.mjs +1 -0
- package/dist/packem_shared/snapshot-precondition-BEtcSbWr.mjs +1 -0
- package/dist/packem_shared/stream-idle-C7CsIT_m.mjs +1 -0
- package/dist/packem_shared/wire-errors-BDckSTKZ.mjs +1 -0
- package/dist/pagination/index.mjs +1 -61
- package/dist/query/index.d.mts +143 -4
- package/dist/query/index.d.ts +143 -4
- package/dist/query/index.mjs +1 -1
- package/dist/service.d.mts +49 -0
- package/dist/service.d.ts +49 -0
- package/dist/service.mjs +1 -0
- package/dist/ssr/index.d.mts +45 -16
- package/dist/ssr/index.d.ts +45 -16
- package/dist/ssr/index.mjs +1 -4
- package/dist/upload.d.mts +14 -0
- package/dist/upload.d.ts +14 -0
- package/dist/upload.mjs +1 -24
- package/package.json +15 -3
- package/dist/packem_shared/CONFLICT_ERROR_CODE-B8gQ8tyU.mjs +0 -33
- package/dist/packem_shared/ClientServiceWorker-C3PAFwy0.mjs +0 -100
- package/dist/packem_shared/DEFAULT_MAX_BUFFER-7hFnzNk9.mjs +0 -110
- package/dist/packem_shared/LunoraClient-DKATLGHY.mjs +0 -3631
- package/dist/packem_shared/OfflineQueue-BgarnAub.mjs +0 -1
- package/dist/packem_shared/SKIP-vItZChkw.mjs +0 -50
- package/dist/packem_shared/SubscriptionRegistry-CxS_Inha.mjs +0 -31
- package/dist/packem_shared/TabCoordinator-D_5oNTTt.mjs +0 -258
- package/dist/packem_shared/applyDelta-CRKZ1PBt.mjs +0 -81
- package/dist/packem_shared/createAsyncStoragePersistence-1Z5BZ8RC.mjs +0 -45
- package/dist/packem_shared/createClientQuery-dJZg1ohm.mjs +0 -80
- package/dist/packem_shared/createInMemoryBookmarkStorage-BoN7a7TH.mjs +0 -11
- package/dist/packem_shared/createInMemoryPersistence-DZ2VHWgm.mjs +0 -79
- package/dist/packem_shared/createInMemoryQueryCache-DiaGZkA2.mjs +0 -112
- package/dist/packem_shared/createLocalStore-BtqUmOQA.mjs +0 -2
- package/dist/packem_shared/createMutationRunner-BqsavzvG.mjs +0 -21
- package/dist/packem_shared/createMutatorRunner-BETvCd0p.mjs +0 -31
- package/dist/packem_shared/createReconnect-Di_-oHH7.mjs +0 -22
- package/dist/packem_shared/createReply-lI4tVS2w.mjs +0 -36
- package/dist/packem_shared/createServerClient-Bp2r9tcB.mjs +0 -11
- package/dist/packem_shared/createSnapshotPrecondition-CxQ1T4ZP.mjs +0 -18
- package/dist/packem_shared/deserializePreloaded-C0eJTY_W.mjs +0 -4
- package/dist/packem_shared/getServerSession-8jXewqxd.mjs +0 -13
- package/dist/packem_shared/httpStream-DIdL8NEw.mjs +0 -168
- package/dist/packem_shared/idb-utility-DrSVX43Q.mjs +0 -48
- package/dist/packem_shared/local-store-DIq-UWfD.mjs +0 -106
- package/dist/packem_shared/lunora-client.d-B1iZb2Ph.d.mts +0 -2845
- package/dist/packem_shared/lunora-client.d-B1iZb2Ph.d.ts +0 -2845
- package/dist/packem_shared/offline-queue-N-1JvYb4.mjs +0 -211
- package/dist/packem_shared/preloadQuery-lobFkD2Z.mjs +0 -13
- package/dist/packem_shared/wire-key-Djie6aaR.mjs +0 -266
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{stableWireKey as a}from"@lunora/wire";const s=(e,r,y)=>["lunora",e,r,y??null],n=(e,r,y)=>s(e.__lunoraRef,a(r),y),t=(e,r,y,u={})=>{const o=y??{};return{queryFn:()=>e.query(r,o,{shardKey:u.shardKey}),queryKey:n(r,o,u.shardKey),staleTime:Number.POSITIVE_INFINITY}};export{n as lunoraQueryKey,s as lunoraQueryKeyFromArgsKey,t as lunoraQueryOptions};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let a=0;const d=()=>{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID();a+=1;const o=typeof crypto<"u"&&typeof crypto.getRandomValues=="function"?Array.from(crypto.getRandomValues(new Uint8Array(8)),e=>e.toString(16).padStart(2,"0")).join(""):Math.random().toString(16).slice(2,12);return`id_${Date.now().toString(36)}_${a.toString(36)}_${o}`},l=(o,e)=>o!==void 0&&e!==o,f=d,h=(o,e,t,i)=>{if(o)try{o({error:t,mutationId:i,operation:e});return}catch{}console.warn(`[lunora] offline-queue persistence ${e} failed`,t)};class p{queueBeforeFirstConnect;maxItems;onPersistenceError;persistence;onEvict;onSizeChange;onReplayingChange;version;items=[];replayingIds=new Set;appending=new Map;unsettled=new Map;unpersisted=new Set;constructor(e={},t={}){this.maxItems=e.maxItems??1e3,this.queueBeforeFirstConnect=e.queueBeforeFirstConnect??!1,this.onPersistenceError=e.onPersistenceError,this.persistence=t.persistence,this.onEvict=t.onEvict,this.onSizeChange=t.onSizeChange,this.onReplayingChange=t.onReplayingChange,this.version=t.version}get size(){return this.items.length}get replaying(){return this.replayingIds.size}enqueue(e){const t=e;t.id??=f();let i=this.items.length;for(;t.issueSeq!==void 0&&i>0&&(this.items[i-1]?.issueSeq??-1)>t.issueSeq;)i-=1;this.items.splice(i,0,t),this.unsettled.set(t.id,t),this.persist(this.recordOf(t,t.id)),this.evictOverflow(),this.notifySize()}discard(e){this.unsettled.delete(e),this.unpersisted.delete(e),this.replayingIds.delete(e)&&this.onReplayingChange?.();const{persistence:t}=this;t&&(this.appending.get(e)??Promise.resolve()).then(async()=>t.remove(e)).catch(i=>{h(this.onPersistenceError,"remove",i,e)})}flushUnpersisted(){for(const e of this.unpersisted){const t=this.unsettled.get(e);t&&!this.appending.has(e)&&this.persist(this.recordOf(t,e))}}async hydrate(){if(!this.persistence)return[];let e;try{e=await this.persistence.load()}catch(s){throw h(this.onPersistenceError,"load",s),s}const t=[],i=new Set(this.items.map(s=>s.id));for(const s of e)if(!i.has(s.id)){if(l(this.version,s.version)){this.persistence.remove(s.id).catch(c=>{h(this.onPersistenceError,"remove",c,s.id)});continue}i.add(s.id),t.push({args:s.args,baselineSeq:s.baselineSeq,clientId:s.clientId,functionPath:s.functionPath,id:s.id,identity:s.identity,reject:()=>{},resolve:()=>{},shardKey:s.shardKey})}this.items.unshift(...t),this.evictOverflow(),this.notifySize();const n=new Set(this.items),r=new Set;for(const s of t)n.has(s)&&r.add(s.shardKey);return[...r]}restampIdentity(e,t){for(const i of this.items){if(i.identity!==e)continue;i.identity=t;const{id:n}=i;!this.persistence||n===void 0||this.rewriteStamp(n,this.recordOf(i,n)).catch(r=>{h(this.onPersistenceError,"replace",r,n)})}}hasPending(e){return this.items.some(t=>e(t))}drain(e){if(!e){const n=[...this.items];return this.items.length=0,this.markReplaying(n),this.notifySize(),n}const t=[],i=[];for(const n of this.items)(e(n)?t:i).push(n);return this.items.length=0,this.items.push(...i),this.markReplaying(t),this.notifySize(),t}requeue(e){if(e.length!==0){for(const t of e)t.id!==void 0&&this.replayingIds.delete(t.id);this.items.unshift(...e),this.notifySize()}}drainConflict(){const e=[],t=[];for(const i of this.items){let n=!0,r;if(i.precondition!==void 0)try{n=i.precondition()}catch(s){n=!1,r=s}if(n)t.push(i);else{const s=new Error("offline mutation skipped: precondition failed before replay",r===void 0?void 0:{cause:r});s.code="OFFLINE_PRECONDITION_FAILED",i.reject(s),e.push(i)}}return e.length>0&&(this.items.length=0,this.items.push(...t),this.notifySize()),e}clear(){for(const e of new Set([...this.items,...this.unsettled.values()])){const t=new Error("CLIENT_CLOSED"),i=e.id??"",n=s=>{t.code="CLIENT_CLOSED",t.persisted=s,e.reject(t)},r=this.appending.get(i);this.replayingIds.has(i)?n(!1):r===void 0?n(this.persistence!==void 0&&!this.unpersisted.has(i)):r.catch(()=>!1).then(n).catch(()=>{})}this.items.length=0,this.replayingIds.clear(),this.unsettled.clear(),this.unpersisted.clear(),this.notifySize()}recordOf(e,t){return{args:e.args,...e.baselineSeq===void 0?{}:{baselineSeq:e.baselineSeq},clientId:e.clientId,functionPath:e.functionPath,id:t,identity:e.identity,shardKey:e.shardKey,...this.version===void 0?{}:{version:this.version}}}persist(e){const{persistence:t}=this;if(!t)return;const i=(async()=>{try{return await t.append(e),this.unpersisted.delete(e.id),!0}catch(n){return this.unsettled.has(e.id)&&this.unpersisted.add(e.id),h(this.onPersistenceError,"append",n,e.id),!1}})();this.appending.set(e.id,i),i.finally(()=>{this.appending.get(e.id)===i&&this.appending.delete(e.id)}).catch(()=>{})}async rewriteStamp(e,t){const i=this.persistence;if(i)try{await this.appending.get(e),await i.replace(t)}catch(n){h(this.onPersistenceError,"replace",n,e)}}evictOverflow(){for(;this.items.length>this.maxItems;){const e=this.items.shift();if(e){e.id&&this.discard(e.id);const t=new Error("offline queue overflow");t.code="OFFLINE_QUEUE_OVERFLOW",e.reject(t),this.onEvict?.(e,t)}}}markReplaying(e){for(const t of e)t.id!==void 0&&this.replayingIds.add(t.id)}notifySize(){this.onSizeChange?.(this.items.length)}}export{p as O,l as i,f as n,h as r};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let l=0,n;const f=(i,o)=>{for(const r of i)try{r(o)}catch{}},p=i=>{const o=[...i.callbacks],r=i.lastValue;return()=>{for(const e of o){if(i.lastValue!==r)return;i.callbacks.has(e)&&f([e],r)}}},k=i=>{n===void 0?i():n.add(i)},L=()=>l,y=(i,o)=>{let r=i;for(const e of o)try{r=e.transform(r)}catch{}return r},d=(i,o)=>{o!==i.lastValue&&(i.lastValue=o,n===void 0?f(i.callbacks,o):n.add(i))},v=(i,o=()=>!0)=>{const r=new Set;n=r;try{i()}finally{n=void 0;const e=[...r].map(c=>typeof c=="function"?c:p(c));for(const c of e){if(!o())break;try{c()}catch{}}}},m=(i,o)=>{d(i,y(o,i.optimisticLayers))},b=(i,o)=>{let r;try{r=o(i.lastValue)}catch{return}const e={id:Symbol("optimistic"),transform:o};let c=!1;i.optimisticLayers.push(e),d(i,r);const s=()=>{const t=i.optimisticLayers.findIndex(u=>u.id===e.id);return t===-1?!1:(i.optimisticLayers.splice(t,1),!0)},a=()=>{m(i,i.serverBase)};return{confirm:t=>{if(t===void 0){s();return}e.commitCursor=t,l+=1,e.acknowledgedAt=l,i.serverCursor!==void 0&&i.serverCursor>=t&&s()&&a()},rollback:()=>{c||(c=!0,s(),a())}}},h=(i,o)=>{if(o===void 0||i.optimisticLayers.length===0)return!1;const r=i.optimisticLayers.length;return i.optimisticLayers=i.optimisticLayers.filter(e=>e.commitCursor===void 0||e.commitCursor>o),i.optimisticLayers.length!==r},g=(i,o)=>{i.optimisticLayers.length!==0&&(i.optimisticLayers=i.optimisticLayers.filter(r=>r.acknowledgedAt===void 0||r.acknowledgedAt>o))},w=i=>{for(let o=i.length-1;o>=0;o-=1)i[o]?.()};export{b as a,h as b,w as c,k as d,g as e,L as f,m as r,v as w};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as LunoraClient, P as Preloaded } from "./lunora-client.d-C8zXKzbE.mjs";
|
|
2
|
+
import { F as FunctionReference, A as ArgsOf, R as ReturnOf } from "./function-reference.d-Br_hsKje.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Run a query once on the server (during SSR) and capture its result in a
|
|
4
5
|
* serializable {@link Preloaded} token. Embed the token in the rendered HTML and
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as LunoraClient, P as Preloaded } from "./lunora-client.d-CAIGiEHg.js";
|
|
2
|
+
import { F as FunctionReference, A as ArgsOf, R as ReturnOf } from "./function-reference.d-Br_hsKje.js";
|
|
2
3
|
/**
|
|
3
4
|
* Run a query once on the server (during SSR) and capture its result in a
|
|
4
5
|
* serializable {@link Preloaded} token. Embed the token in the rendered HTML and
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=async(e,r,a,u={})=>{const l=await e.query(r,a,u);return{__lunoraPreloaded:!0,args:a??{},functionPath:r.__lunoraRef,shardKey:u.shardKey,value:l}},d=e=>e.value;export{t as preloadQuery,d as preloadedQueryResult};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f}from"./base64-849R7V-V.mjs";const d=1e4,h=1e3,m=864e5,l=5e3,y=o=>{try{const t=JSON.parse(new TextDecoder().decode(f(o.split(".")[1]??""))),r=typeof t=="object"&&t!==null?t.exp:void 0;return typeof r=="number"?r*1e3:void 0}catch{return}},E=(o,t,r={})=>{let s=!1,c,n;const v=async()=>{let e;try{e=await t()}catch{return l}if(s)return;o.setAuthToken(e,e===null?void 0:r.subject);const u=e===null?void 0:y(e);if(u===void 0)return;const i=u-Date.now();return i<=0?l:Math.min(m,Math.max(h,i>d?i-d:i/2))},a=async()=>{if(n!==void 0)return;clearTimeout(c),n=v();let e;try{e=await n}finally{n=void 0}e!==void 0&&!s&&(c=setTimeout(()=>{a().catch(()=>{})},e))},p=o.onTokenExpired(()=>{a().catch(()=>{})});return a().catch(()=>{}),()=>{s=!0,clearTimeout(c),p()}};export{E as setAuthTokenProvider};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{encodeWire as s,parseWire as a}from"@lunora/wire";const c=Symbol("lunora.corrupt-blob"),m=(r,t)=>{let n=Promise.resolve();const o=e=>{const i=n.then(e,e);return n=i.then(()=>{},()=>{}),i};return{clear:()=>o(()=>r.removeItem(t)),read:async()=>{const e=await r.getItem(t);if(e!==null)try{return a(e)}catch{return c}},serialize:o,write:async e=>{await r.setItem(t,JSON.stringify(s(e)))}}};export{c as C,m as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{stableWireKey as p}from"@lunora/wire";const u=new WeakMap,i=(e,t)=>{u.set(e,t)},d=e=>e===void 0?void 0:u.get(e),h=(e,t,s,n)=>{const o=e.peekActiveQuerySnapshot(t.__lunoraRef,s,n),a=o.present&&o.answered?p(o.value):void 0,c=()=>{const r=e.peekActiveQuerySnapshot(t.__lunoraRef,s,n);return!o.present||!o.answered||!r.present||!r.answered?!0:p(r.value)===a};return a!==void 0&&i(c,{args:s,functionPath:t.__lunoraRef,shardKey:n}),c};export{h as c,i as r,d as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as v}from"@lunora/errors";import{TransportError as f}from"./CONFLICT_ERROR_CODE-B7qNZMMk.mjs";const c=t=>t.reason??Object.assign(new Error("The operation was aborted"),{name:"AbortError"}),m=async(t,r,o,i=()=>new f(`LunoraClient: request timed out after ${t.toString()}ms`))=>{if(r?.aborted)throw c(r);const n=new AbortController,e=[],u=new Promise((b,d)=>{if(t>0){const a=setTimeout(()=>{d(i()),n.abort()},t);e.push(()=>{clearTimeout(a)})}if(r){const a=()=>{n.abort(),d(c(r))};r.addEventListener("abort",a,{once:!0}),e.push(()=>{r.removeEventListener("abort",a)})}}),s=o(n.signal);s.catch(()=>{});try{return await Promise.race([s,u])}finally{for(const b of e)b()}},E=async(t,r)=>{if(r===void 0)return t;if(r.aborted)throw t.catch(()=>{}),c(r);let o=()=>{};const i=new Promise((n,e)=>{o=()=>{e(c(r))},r.addEventListener("abort",o,{once:!0})});t.catch(()=>{});try{return await Promise.race([t,i])}finally{r.removeEventListener("abort",o)}},y=async(t,r)=>!Number.isFinite(r)||r<=0?t.read():m(r,void 0,async()=>t.read(),()=>new v("STREAM_IDLE",`stream received nothing for ${r.toString()}ms`));export{E as a,c as b,y as r,m as w};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as i}from"@lunora/errors";import{decodeWire as u}from"@lunora/wire";import{TransportError as l,getRetryAfterMs as m}from"./CONFLICT_ERROR_CODE-B7qNZMMk.mjs";import{f as a}from"./frame-hint-D-NK691z.mjs";const v=t=>{if(t===null)return;const r=Number(t);if(Number.isFinite(r))return r>0?r*1e3:void 0;const e=Date.parse(t);if(Number.isNaN(e))return;const o=e-Date.now();return o>0?o:void 0},p=(t,r)=>{const e=v(r);if(!(e===void 0||m(t)!==void 0))return t.data===void 0?{retryAfterMs:e}:typeof t.data=="object"&&t.data!==null&&!Array.isArray(t.data)?{...t.data,retryAfterMs:e}:void 0},y=t=>{const r=t?.error;if(typeof r!="object"||r===null||Array.isArray(r))return;const{why:e,...o}=r;return typeof e=="string"?{...o,why:e}:o},E=()=>new l("LunoraClient: batch slot carried no error envelope"),c=(t,r)=>{const e=t.error,o=typeof e?.code=="string"?e.code:void 0,s=typeof e?.message=="string"?e.message:void 0;return{code:o,messageText:(typeof t.message=="string"?t.message:void 0)??s??r}},D=t=>{const{code:r,messageText:e}=c(t,"stream error"),o=t.error,s=o?.why,n=r===void 0?new Error(e):new i(r,e,a(o?.hint));return typeof s=="string"&&(n.why=s),n},O=t=>{const{code:r,messageText:e}=c(t,"subscription error"),o=t.error,s=typeof o?.why=="string"?{why:o.why}:{};return{message:e,...r===void 0?{}:{code:r},...a(o?.hint),...s}},h=Symbol.for("lunora.serverVerdict"),d=t=>{const r=new Error(t.message??"request failed");if(r.code=t.code,r[h]=!0,t.data!==void 0)try{r.data=u(t.data)}catch{}return t.hint!==void 0&&(r.hint=t.hint),t.docsUrl!==void 0&&(r.docsUrl=t.docsUrl),typeof t.why=="string"&&(r.why=t.why),r},b=t=>Object.freeze(Object.fromEntries([...t].filter(([r])=>r!=="set-cookie"))),w=(t,r)=>Object.defineProperty(t,"headers",{value:b(r)}),j=(t,r)=>{const e=d(t),o=p(e,r.get("retry-after"));return o!==void 0&&(e.data=o),w(e,r)},M=t=>{const r=y(t);return r===void 0?E():d(r)},f=new WeakSet,N=t=>{const r=new i("WIRE_DECODE_FAILED",`LunoraClient: the call succeeded but its result could not be decoded (a mutation has still committed) — ${t instanceof Error?t.message:String(t)}`,{cause:t});return f.add(r),r},T=t=>t instanceof Error&&f.has(t);export{v as a,j as b,D as c,O as d,y as e,E as f,T as i,d as r,M as s,N as u,w};
|
|
@@ -1,61 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
const JOIN_FACTOR = 0.5;
|
|
3
|
-
const initialPages = (numberItems) => [
|
|
4
|
-
// eslint-disable-next-line unicorn/no-null -- `lower: null` is the feed head, `upper: null` the open-ended tail — both are wire-shape cursors.
|
|
5
|
-
{ lower: null, numItems: numberItems, upper: null }
|
|
6
|
-
];
|
|
7
|
-
const rebalance = (pages, results) => {
|
|
8
|
-
for (const [index, page] of pages.entries()) {
|
|
9
|
-
if (page.upper === null) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
const result = results[index];
|
|
13
|
-
if (!result) {
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
const size = result.page.length;
|
|
17
|
-
if (size > SPLIT_FACTOR * page.numItems && result.splitCursor) {
|
|
18
|
-
const split = result.splitCursor;
|
|
19
|
-
const next = [...pages];
|
|
20
|
-
next.splice(index, 1, { lower: page.lower, numItems: page.numItems, upper: split }, { lower: split, numItems: page.numItems, upper: page.upper });
|
|
21
|
-
return next;
|
|
22
|
-
}
|
|
23
|
-
if (size < JOIN_FACTOR * page.numItems && index + 1 < pages.length) {
|
|
24
|
-
const neighbour = pages[index + 1];
|
|
25
|
-
if (!neighbour) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
const next = [...pages];
|
|
29
|
-
next.splice(index, 2, { lower: page.lower, numItems: page.numItems, upper: neighbour.upper });
|
|
30
|
-
return next;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return void 0;
|
|
34
|
-
};
|
|
35
|
-
const derivePaginationStatus = (skipped, pageResults) => {
|
|
36
|
-
if (skipped || !pageResults[0]) {
|
|
37
|
-
return { nextCursor: void 0, status: "LoadingFirstPage" };
|
|
38
|
-
}
|
|
39
|
-
const tail = pageResults.at(-1);
|
|
40
|
-
if (!tail) {
|
|
41
|
-
return { nextCursor: void 0, status: "LoadingMore" };
|
|
42
|
-
}
|
|
43
|
-
if (tail.isDone || tail.continueCursor === null) {
|
|
44
|
-
return { nextCursor: void 0, status: "Exhausted" };
|
|
45
|
-
}
|
|
46
|
-
return { nextCursor: tail.continueCursor, status: "CanLoadMore" };
|
|
47
|
-
};
|
|
48
|
-
const applyLoadMore = (pages, cursor, numberItems) => {
|
|
49
|
-
if (cursor === void 0 || cursor === null) {
|
|
50
|
-
return void 0;
|
|
51
|
-
}
|
|
52
|
-
const next = [...pages];
|
|
53
|
-
const tail = next.at(-1);
|
|
54
|
-
if (tail) {
|
|
55
|
-
next[next.length - 1] = { lower: tail.lower, numItems: tail.numItems, upper: cursor };
|
|
56
|
-
}
|
|
57
|
-
next.push({ lower: cursor, numItems: numberItems, upper: null });
|
|
58
|
-
return next;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export { JOIN_FACTOR, SPLIT_FACTOR, applyLoadMore, derivePaginationStatus, initialPages, rebalance };
|
|
1
|
+
const l=2,m=.5,p=e=>[{lower:null,numItems:e,upper:null}],c=(e,r)=>{for(const[n,t]of e.entries()){if(t.upper===null)continue;const o=r[n];if(!o)continue;const i=o.page.length;if(i>2*t.numItems&&o.splitCursor){const u=o.splitCursor,s=[...e];return s.splice(n,1,{lower:t.lower,numItems:t.numItems,upper:u},{lower:u,numItems:t.numItems,upper:t.upper}),s}if(i<.5*t.numItems&&n+1<e.length){const u=e[n+1];if(!u)continue;const s=[...e];return s.splice(n,2,{lower:t.lower,numItems:t.numItems,upper:u.upper}),s}}},a=(e,r)=>{if(e||!r[0])return{nextCursor:void 0,status:"LoadingFirstPage"};const n=r.at(-1);return n?n.isDone||n.continueCursor===null?{nextCursor:void 0,status:"Exhausted"}:{nextCursor:n.continueCursor,status:"CanLoadMore"}:{nextCursor:void 0,status:"LoadingMore"}},I=(e,r,n)=>{if(r==null)return;const t=[...e],o=t.at(-1);return o&&(t[t.length-1]={lower:o.lower,numItems:o.numItems,upper:r}),t.push({lower:r,numItems:n,upper:null}),t};export{m as JOIN_FACTOR,l as SPLIT_FACTOR,I as applyLoadMore,a as derivePaginationStatus,p as initialPages,c as rebalance};
|
package/dist/query/index.d.mts
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { F as FunctionReference, R as ReturnOf, A as ArgsOf } from "../packem_shared/function-reference.d-Br_hsKje.mjs";
|
|
2
|
+
import { L as LunoraClient, S as SubscriptionError, a as Unsubscribe } from "../packem_shared/lunora-client.d-C8zXKzbE.mjs";
|
|
3
|
+
export type {
|
|
4
|
+
/**
|
|
5
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
6
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
7
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
8
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
9
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
10
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
11
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
12
|
+
* store / signal / cache.
|
|
13
|
+
*
|
|
14
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
15
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
16
|
+
* the same way.
|
|
17
|
+
*/
|
|
18
|
+
b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-C8zXKzbE.mjs";
|
|
19
|
+
import '@lunora/errors';
|
|
20
|
+
/**
|
|
21
|
+
* The TanStack Query cache-key contract for Lunora queries. It lives here, not
|
|
22
|
+
* in an adapter, because every TanStack binding (React, Vue, Solid, Svelte,
|
|
23
|
+
* Angular Query) hashes keys the same way, and a value prefetched through one
|
|
24
|
+
* entry point must land under the exact key a hook reads back.
|
|
25
|
+
*
|
|
26
|
+
* Typed as `ReadonlyArray<unknown>` — TanStack v5's default `QueryKey` — so this
|
|
27
|
+
* module needs no TanStack dependency.
|
|
28
|
+
*/
|
|
29
|
+
type LunoraQueryKey = ReadonlyArray<unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Project a Lunora `(fn, args, shardKey)` triple into the query key TanStack
|
|
32
|
+
* hashes for dedup. The `"lunora"` literal namespaces our entries so an app's
|
|
33
|
+
* own queries can't collide with ours.
|
|
34
|
+
*
|
|
35
|
+
* `args` sits in the key already encoded by `stableWireKey`, not as the raw
|
|
36
|
+
* object. TanStack hashes keys with `JSON.stringify`, which maps `NaN` to
|
|
37
|
+
* `null`, `-0` to `0` and a `Date` to its ISO string (so distinct args shared
|
|
38
|
+
* one cache entry and served each other's rows) and throws on a `bigint`. A
|
|
39
|
+
* string slot hashes the same under any hash function, so every QueryClient
|
|
40
|
+
* agrees on it without configuration.
|
|
41
|
+
*/
|
|
42
|
+
declare const lunoraQueryKeyFromArgsKey: (ref: string, argsKey: string, shardKey: string | undefined) => LunoraQueryKey;
|
|
43
|
+
declare const lunoraQueryKey: (function_: FunctionReference, args: Record<string, unknown>, shardKey: string | undefined) => LunoraQueryKey;
|
|
44
|
+
/** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
|
|
45
|
+
interface LunoraQueryOptions<F extends FunctionReference> {
|
|
46
|
+
queryFn: () => Promise<ReturnOf<F>>;
|
|
47
|
+
queryKey: LunoraQueryKey;
|
|
48
|
+
staleTime: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build a TanStack Query options object for a Lunora query, keyed identically
|
|
52
|
+
* to the adapters' first-class hooks (see `lunoraQueryKey`), so a value fetched
|
|
53
|
+
* through it shares cache identity with anything those hooks or a server-side
|
|
54
|
+
* `prefetchQuery` read or write for the same `(fn, args, shardKey)` triple.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
|
|
61
|
+
* TanStack never refetches on its own. It opens no WebSocket and has no
|
|
62
|
+
* framework or browser dependency, so it is safe on either side of an RSC
|
|
63
|
+
* boundary — the transport is the `LunoraClient` passed in.
|
|
64
|
+
*/
|
|
65
|
+
declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
|
|
66
|
+
shardKey?: string;
|
|
67
|
+
}) => LunoraQueryOptions<F>;
|
|
4
68
|
/**
|
|
5
69
|
* The sentinel a framework adapter resolves its reactive args to when it wants
|
|
6
70
|
* to short-circuit a query — no network call, no socket.
|
|
@@ -59,4 +123,79 @@ declare const toSubscriptionError: (error: unknown) => SubscriptionError;
|
|
|
59
123
|
* in-flight push reaches the sinks.
|
|
60
124
|
*/
|
|
61
125
|
declare const createQuerySubscription: <F extends FunctionReference, T = ReturnOf<F>>(client: LunoraClient, function_: F, args: ResolvedArgs<F>, sinks: QuerySubscriptionSinks<T>, options?: QuerySubscriptionOptions) => Unsubscribe;
|
|
62
|
-
export {
|
|
126
|
+
export {
|
|
127
|
+
/**
|
|
128
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
129
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
130
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
131
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
132
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
133
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
134
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
135
|
+
* store / signal / cache.
|
|
136
|
+
*
|
|
137
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
138
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
139
|
+
* the same way.
|
|
140
|
+
*/
|
|
141
|
+
type ArgsOf,
|
|
142
|
+
/**
|
|
143
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
144
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
145
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
146
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
147
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
148
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
149
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
150
|
+
* store / signal / cache.
|
|
151
|
+
*
|
|
152
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
153
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
154
|
+
* the same way.
|
|
155
|
+
*/
|
|
156
|
+
type FunctionReference, type LunoraQueryKey, type LunoraQueryOptions, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs,
|
|
157
|
+
/**
|
|
158
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
159
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
160
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
161
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
162
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
163
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
164
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
165
|
+
* store / signal / cache.
|
|
166
|
+
*
|
|
167
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
168
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
169
|
+
* the same way.
|
|
170
|
+
*/
|
|
171
|
+
type ReturnOf, SKIP,
|
|
172
|
+
/**
|
|
173
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
174
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
175
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
176
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
177
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
178
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
179
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
180
|
+
* store / signal / cache.
|
|
181
|
+
*
|
|
182
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
183
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
184
|
+
* the same way.
|
|
185
|
+
*/
|
|
186
|
+
type SubscriptionError,
|
|
187
|
+
/**
|
|
188
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
189
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
190
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
191
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
192
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
193
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
194
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
195
|
+
* store / signal / cache.
|
|
196
|
+
*
|
|
197
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
198
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
199
|
+
* the same way.
|
|
200
|
+
*/
|
|
201
|
+
type Unsubscribe, createQuerySubscription, lunoraQueryKey, lunoraQueryKeyFromArgsKey, lunoraQueryOptions, toSubscriptionError };
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { F as FunctionReference, R as ReturnOf, A as ArgsOf } from "../packem_shared/function-reference.d-Br_hsKje.js";
|
|
2
|
+
import { L as LunoraClient, S as SubscriptionError, a as Unsubscribe } from "../packem_shared/lunora-client.d-CAIGiEHg.js";
|
|
3
|
+
export type {
|
|
4
|
+
/**
|
|
5
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
6
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
7
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
8
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
9
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
10
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
11
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
12
|
+
* store / signal / cache.
|
|
13
|
+
*
|
|
14
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
15
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
16
|
+
* the same way.
|
|
17
|
+
*/
|
|
18
|
+
b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-CAIGiEHg.js";
|
|
19
|
+
import '@lunora/errors';
|
|
20
|
+
/**
|
|
21
|
+
* The TanStack Query cache-key contract for Lunora queries. It lives here, not
|
|
22
|
+
* in an adapter, because every TanStack binding (React, Vue, Solid, Svelte,
|
|
23
|
+
* Angular Query) hashes keys the same way, and a value prefetched through one
|
|
24
|
+
* entry point must land under the exact key a hook reads back.
|
|
25
|
+
*
|
|
26
|
+
* Typed as `ReadonlyArray<unknown>` — TanStack v5's default `QueryKey` — so this
|
|
27
|
+
* module needs no TanStack dependency.
|
|
28
|
+
*/
|
|
29
|
+
type LunoraQueryKey = ReadonlyArray<unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Project a Lunora `(fn, args, shardKey)` triple into the query key TanStack
|
|
32
|
+
* hashes for dedup. The `"lunora"` literal namespaces our entries so an app's
|
|
33
|
+
* own queries can't collide with ours.
|
|
34
|
+
*
|
|
35
|
+
* `args` sits in the key already encoded by `stableWireKey`, not as the raw
|
|
36
|
+
* object. TanStack hashes keys with `JSON.stringify`, which maps `NaN` to
|
|
37
|
+
* `null`, `-0` to `0` and a `Date` to its ISO string (so distinct args shared
|
|
38
|
+
* one cache entry and served each other's rows) and throws on a `bigint`. A
|
|
39
|
+
* string slot hashes the same under any hash function, so every QueryClient
|
|
40
|
+
* agrees on it without configuration.
|
|
41
|
+
*/
|
|
42
|
+
declare const lunoraQueryKeyFromArgsKey: (ref: string, argsKey: string, shardKey: string | undefined) => LunoraQueryKey;
|
|
43
|
+
declare const lunoraQueryKey: (function_: FunctionReference, args: Record<string, unknown>, shardKey: string | undefined) => LunoraQueryKey;
|
|
44
|
+
/** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
|
|
45
|
+
interface LunoraQueryOptions<F extends FunctionReference> {
|
|
46
|
+
queryFn: () => Promise<ReturnOf<F>>;
|
|
47
|
+
queryKey: LunoraQueryKey;
|
|
48
|
+
staleTime: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build a TanStack Query options object for a Lunora query, keyed identically
|
|
52
|
+
* to the adapters' first-class hooks (see `lunoraQueryKey`), so a value fetched
|
|
53
|
+
* through it shares cache identity with anything those hooks or a server-side
|
|
54
|
+
* `prefetchQuery` read or write for the same `(fn, args, shardKey)` triple.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
|
|
61
|
+
* TanStack never refetches on its own. It opens no WebSocket and has no
|
|
62
|
+
* framework or browser dependency, so it is safe on either side of an RSC
|
|
63
|
+
* boundary — the transport is the `LunoraClient` passed in.
|
|
64
|
+
*/
|
|
65
|
+
declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
|
|
66
|
+
shardKey?: string;
|
|
67
|
+
}) => LunoraQueryOptions<F>;
|
|
4
68
|
/**
|
|
5
69
|
* The sentinel a framework adapter resolves its reactive args to when it wants
|
|
6
70
|
* to short-circuit a query — no network call, no socket.
|
|
@@ -59,4 +123,79 @@ declare const toSubscriptionError: (error: unknown) => SubscriptionError;
|
|
|
59
123
|
* in-flight push reaches the sinks.
|
|
60
124
|
*/
|
|
61
125
|
declare const createQuerySubscription: <F extends FunctionReference, T = ReturnOf<F>>(client: LunoraClient, function_: F, args: ResolvedArgs<F>, sinks: QuerySubscriptionSinks<T>, options?: QuerySubscriptionOptions) => Unsubscribe;
|
|
62
|
-
export {
|
|
126
|
+
export {
|
|
127
|
+
/**
|
|
128
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
129
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
130
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
131
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
132
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
133
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
134
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
135
|
+
* store / signal / cache.
|
|
136
|
+
*
|
|
137
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
138
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
139
|
+
* the same way.
|
|
140
|
+
*/
|
|
141
|
+
type ArgsOf,
|
|
142
|
+
/**
|
|
143
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
144
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
145
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
146
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
147
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
148
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
149
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
150
|
+
* store / signal / cache.
|
|
151
|
+
*
|
|
152
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
153
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
154
|
+
* the same way.
|
|
155
|
+
*/
|
|
156
|
+
type FunctionReference, type LunoraQueryKey, type LunoraQueryOptions, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs,
|
|
157
|
+
/**
|
|
158
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
159
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
160
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
161
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
162
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
163
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
164
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
165
|
+
* store / signal / cache.
|
|
166
|
+
*
|
|
167
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
168
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
169
|
+
* the same way.
|
|
170
|
+
*/
|
|
171
|
+
type ReturnOf, SKIP,
|
|
172
|
+
/**
|
|
173
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
174
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
175
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
176
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
177
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
178
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
179
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
180
|
+
* store / signal / cache.
|
|
181
|
+
*
|
|
182
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
183
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
184
|
+
* the same way.
|
|
185
|
+
*/
|
|
186
|
+
type SubscriptionError,
|
|
187
|
+
/**
|
|
188
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
189
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
190
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
191
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
192
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
193
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
194
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
195
|
+
* store / signal / cache.
|
|
196
|
+
*
|
|
197
|
+
* It also owns the TanStack Query key contract (`lunoraQueryKey`,
|
|
198
|
+
* `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
|
|
199
|
+
* the same way.
|
|
200
|
+
*/
|
|
201
|
+
type Unsubscribe, createQuerySubscription, lunoraQueryKey, lunoraQueryKeyFromArgsKey, lunoraQueryOptions, toSubscriptionError };
|
package/dist/query/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{lunoraQueryKey as e,lunoraQueryKeyFromArgsKey as u,lunoraQueryOptions as t}from"../packem_shared/lunoraQueryKey-CucWmxnx.mjs";import{SKIP as n,createQuerySubscription as i,toSubscriptionError as p}from"../packem_shared/SKIP-d7LeP-sY.mjs";export{n as SKIP,i as createQuerySubscription,e as lunoraQueryKey,u as lunoraQueryKeyFromArgsKey,t as lunoraQueryOptions,p as toSubscriptionError};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { F as FunctionReference, A as ArgsOf, R as ReturnOf } from "./packem_shared/function-reference.d-Br_hsKje.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* The wire endpoint every Lunora Worker serves. Matches `createWorker`'s RPC
|
|
4
|
+
* route; the envelope shape below is that route's documented contract.
|
|
5
|
+
*/
|
|
6
|
+
declare const RPC_PATH = "/_lunora/rpc";
|
|
7
|
+
/**
|
|
8
|
+
* The slice of a Cloudflare service binding this module uses.
|
|
9
|
+
*
|
|
10
|
+
* Structural on purpose: `env.BACKEND` satisfies it, and so does a one-method
|
|
11
|
+
* fake in a test. Declaring the full `Fetcher` would drag
|
|
12
|
+
* `@cloudflare/workers-types` into every consumer for a single method.
|
|
13
|
+
*/
|
|
14
|
+
interface ServiceBindingLike {
|
|
15
|
+
fetch: (request: Request) => Promise<Response>;
|
|
16
|
+
}
|
|
17
|
+
interface ServiceCallOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Route to a specific shard. Omitted, the callee routes to its default shard
|
|
20
|
+
* — the same rule the HTTP path follows, so a sharded app must pass the key
|
|
21
|
+
* it would have passed there.
|
|
22
|
+
*/
|
|
23
|
+
shardKey?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A typed caller bound to one Lunora Worker.
|
|
27
|
+
*
|
|
28
|
+
* The three methods are separate rather than one `call` so a reader can tell a
|
|
29
|
+
* read from a write at the call site, and so the reference's `Kind` is checked:
|
|
30
|
+
* passing a mutation reference to `query` is a compile error, matching how
|
|
31
|
+
* `ctx.runQuery`/`ctx.runMutation` behave inside an app.
|
|
32
|
+
*/
|
|
33
|
+
interface LunoraServiceClient {
|
|
34
|
+
action: <F extends FunctionReference<"action">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
|
|
35
|
+
mutation: <F extends FunctionReference<"mutation">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
|
|
36
|
+
query: <F extends FunctionReference<"query">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Build a typed caller for the Lunora Worker behind `binding`.
|
|
40
|
+
*
|
|
41
|
+
* Only PUBLIC functions are reachable. An `internal*` procedure is deliberately
|
|
42
|
+
* absent from the generated `api` object and rejected by the callee, because a
|
|
43
|
+
* service binding is a trust boundary between deployments, not the intra-app
|
|
44
|
+
* `ctx.run*` seam.
|
|
45
|
+
* @param binding The service binding, e.g. `env.BACKEND`.
|
|
46
|
+
* @returns a client whose methods type-check against the generated `api`.
|
|
47
|
+
*/
|
|
48
|
+
declare const createServiceClient: (binding: ServiceBindingLike) => LunoraServiceClient;
|
|
49
|
+
export { type LunoraServiceClient, RPC_PATH, type ServiceBindingLike, type ServiceCallOptions, createServiceClient };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { F as FunctionReference, A as ArgsOf, R as ReturnOf } from "./packem_shared/function-reference.d-Br_hsKje.js";
|
|
2
|
+
/**
|
|
3
|
+
* The wire endpoint every Lunora Worker serves. Matches `createWorker`'s RPC
|
|
4
|
+
* route; the envelope shape below is that route's documented contract.
|
|
5
|
+
*/
|
|
6
|
+
declare const RPC_PATH = "/_lunora/rpc";
|
|
7
|
+
/**
|
|
8
|
+
* The slice of a Cloudflare service binding this module uses.
|
|
9
|
+
*
|
|
10
|
+
* Structural on purpose: `env.BACKEND` satisfies it, and so does a one-method
|
|
11
|
+
* fake in a test. Declaring the full `Fetcher` would drag
|
|
12
|
+
* `@cloudflare/workers-types` into every consumer for a single method.
|
|
13
|
+
*/
|
|
14
|
+
interface ServiceBindingLike {
|
|
15
|
+
fetch: (request: Request) => Promise<Response>;
|
|
16
|
+
}
|
|
17
|
+
interface ServiceCallOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Route to a specific shard. Omitted, the callee routes to its default shard
|
|
20
|
+
* — the same rule the HTTP path follows, so a sharded app must pass the key
|
|
21
|
+
* it would have passed there.
|
|
22
|
+
*/
|
|
23
|
+
shardKey?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A typed caller bound to one Lunora Worker.
|
|
27
|
+
*
|
|
28
|
+
* The three methods are separate rather than one `call` so a reader can tell a
|
|
29
|
+
* read from a write at the call site, and so the reference's `Kind` is checked:
|
|
30
|
+
* passing a mutation reference to `query` is a compile error, matching how
|
|
31
|
+
* `ctx.runQuery`/`ctx.runMutation` behave inside an app.
|
|
32
|
+
*/
|
|
33
|
+
interface LunoraServiceClient {
|
|
34
|
+
action: <F extends FunctionReference<"action">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
|
|
35
|
+
mutation: <F extends FunctionReference<"mutation">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
|
|
36
|
+
query: <F extends FunctionReference<"query">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Build a typed caller for the Lunora Worker behind `binding`.
|
|
40
|
+
*
|
|
41
|
+
* Only PUBLIC functions are reachable. An `internal*` procedure is deliberately
|
|
42
|
+
* absent from the generated `api` object and rejected by the callee, because a
|
|
43
|
+
* service binding is a trust boundary between deployments, not the intra-app
|
|
44
|
+
* `ctx.run*` seam.
|
|
45
|
+
* @param binding The service binding, e.g. `env.BACKEND`.
|
|
46
|
+
* @returns a client whose methods type-check against the generated `api`.
|
|
47
|
+
*/
|
|
48
|
+
declare const createServiceClient: (binding: ServiceBindingLike) => LunoraServiceClient;
|
|
49
|
+
export { type LunoraServiceClient, RPC_PATH, type ServiceBindingLike, type ServiceCallOptions, createServiceClient };
|
package/dist/service.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as c}from"@lunora/errors";import{encodeArgsOrThrow as d,decodeWire as y}from"@lunora/wire";import{e as f,r as w}from"./packem_shared/wire-errors-BDckSTKZ.mjs";const v="/_lunora/rpc",N="https://lunora.internal",i=async(n,t,r,o,u)=>{const a=r.__lunoraRef,p=JSON.stringify({args:d("@lunora/client/service",a,o??{}),functionPath:a,...u?.shardKey===void 0?{}:{shardKey:u.shardKey}}),e=await n.fetch(new Request(`${N}${v}`,{body:p,headers:{"content-type":"application/json"},method:"POST"}));let s;try{s=await e.json()}catch{throw new c("INTERNAL",`@lunora/client/service: ${t} "${a}" got a non-JSON response (status ${e.status.toString()}). Check the service binding points at the Lunora Worker that declares this function.`,{status:e.status})}if(s===null||typeof s!="object")throw new c("INTERNAL",`@lunora/client/service: ${t} "${a}" returned a JSON body that is not an object (status ${e.status.toString()}). Check the service binding points at the Lunora Worker that declares this function.`,{status:e.status});const h=s,l=f(h);if(l!==void 0)throw w(l);if(!e.ok)throw new c("INTERNAL",`@lunora/client/service: ${t} "${a}" failed with status ${e.status.toString()} and no error envelope.`,{status:e.status});return y(h.result)},R=n=>({action:async(t,r,o)=>await i(n,"action",t,r,o),mutation:async(t,r,o)=>await i(n,"mutation",t,r,o),query:async(t,r,o)=>await i(n,"query",t,r,o)});export{v as RPC_PATH,R as createServiceClient};
|