@lunora/client 1.0.0-alpha.29 → 1.0.0-alpha.290

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.
Files changed (109) hide show
  1. package/LICENSE.md +201 -104
  2. package/README.md +22 -7
  3. package/dist/admin/index.d.mts +687 -0
  4. package/dist/admin/index.d.ts +687 -0
  5. package/dist/admin/index.mjs +1 -0
  6. package/dist/auth/index.d.mts +138 -5
  7. package/dist/auth/index.d.ts +138 -5
  8. package/dist/auth/index.mjs +1 -1
  9. package/dist/index.d.mts +757 -187
  10. package/dist/index.d.ts +757 -187
  11. package/dist/index.mjs +1 -1
  12. package/dist/packem_shared/ADMIN_AUTH_DEFAULT_PAGE_SIZE-V9c3bHU1.mjs +1 -0
  13. package/dist/packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs +1 -0
  14. package/dist/packem_shared/DEFAULT_MAX_BUFFER-Bd-_iyiV.mjs +1 -0
  15. package/dist/packem_shared/LunoraAdminClient-aBcOpYpI.mjs +1 -0
  16. package/dist/packem_shared/LunoraClient--R-NfrXm.mjs +1 -0
  17. package/dist/packem_shared/OfflineQueue-Ba2qgZK1.mjs +1 -0
  18. package/dist/packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs +1 -0
  19. package/dist/packem_shared/SKIP-d7LeP-sY.mjs +1 -0
  20. package/dist/packem_shared/SubscriptionRegistry-_FfLskdB.mjs +1 -0
  21. package/dist/packem_shared/TabCoordinator-IUCwjnqX.mjs +1 -0
  22. package/dist/packem_shared/applyDelta-CaudNj2C.mjs +1 -0
  23. package/dist/packem_shared/base64-849R7V-V.mjs +1 -0
  24. package/dist/packem_shared/client-tuning-C10B2KCO.mjs +1 -0
  25. package/dist/packem_shared/client-urls-BHLUjjcG.mjs +1 -0
  26. package/dist/packem_shared/connectLiveStream-BdjsWP1-.mjs +1 -0
  27. package/dist/packem_shared/createAsyncStoragePersistence-BgfdvLwe.mjs +1 -0
  28. package/dist/packem_shared/createAsyncStorageQueryCache-6Y94ocbQ.mjs +1 -0
  29. package/dist/packem_shared/createCallRunner-Bwcrfh76.mjs +1 -0
  30. package/dist/packem_shared/createClientQuery-B8Nfj-7o.mjs +1 -0
  31. package/dist/packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs +1 -0
  32. package/dist/packem_shared/createInMemoryPersistence-C-IzNVbg.mjs +1 -0
  33. package/dist/packem_shared/createInMemoryQueryCache-DR6AorA2.mjs +1 -0
  34. package/dist/packem_shared/createLocalStore-CDCtdy5O.mjs +1 -0
  35. package/dist/packem_shared/createMutatorRunner-CuMRJpUx.mjs +1 -0
  36. package/dist/packem_shared/createReconnect-CjTmjJDH.mjs +1 -0
  37. package/dist/packem_shared/createServerClient-DEvfqFbl.mjs +1 -0
  38. package/dist/packem_shared/createSnapshotPrecondition-BXP1NPBW.mjs +1 -0
  39. package/dist/packem_shared/delta-merge-C6OqMEPH.mjs +1 -0
  40. package/dist/packem_shared/deserializePreloaded-DxozvweR.mjs +1 -0
  41. package/dist/packem_shared/frame-hint-D-NK691z.mjs +1 -0
  42. package/dist/packem_shared/function-reference.d-Br_hsKje.d.mts +45 -0
  43. package/dist/packem_shared/function-reference.d-Br_hsKje.d.ts +45 -0
  44. package/dist/packem_shared/getServerSession-BaOoo1p6.mjs +1 -0
  45. package/dist/packem_shared/httpStream-DN3D9WqW.mjs +7 -0
  46. package/dist/packem_shared/idb-utility-BS7xvou1.mjs +1 -0
  47. package/dist/packem_shared/live-stream-DBKgZlnb.mjs +10 -0
  48. package/dist/packem_shared/liveTopicSubscription-DQtKMFKw.mjs +1 -0
  49. package/dist/packem_shared/lunora-client-joBzs47U.mjs +1 -0
  50. package/dist/packem_shared/lunora-client.d-DKfDdnjJ.d.ts +4999 -0
  51. package/dist/packem_shared/lunora-client.d-Ezp1eG81.d.mts +4999 -0
  52. package/dist/packem_shared/lunoraQueryKey-CucWmxnx.mjs +1 -0
  53. package/dist/packem_shared/offline-queue-BEqCPDmw.mjs +1 -0
  54. package/dist/packem_shared/optimistic-layers-D-7D3yeJ.mjs +1 -0
  55. package/dist/packem_shared/{preload.d-DGGRMWB5.d.ts → preload.d-qnL9TXVr.d.mts} +2 -1
  56. package/dist/packem_shared/{preload.d-BmztUzzG.d.mts → preload.d-wJ_ggZsg.d.ts} +2 -1
  57. package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
  58. package/dist/packem_shared/setAuthTokenProvider-DhBppDiZ.mjs +1 -0
  59. package/dist/packem_shared/single-blob-store-DeaYPBSS.mjs +1 -0
  60. package/dist/packem_shared/snapshot-precondition-BEtcSbWr.mjs +1 -0
  61. package/dist/packem_shared/stream-idle-C7CsIT_m.mjs +1 -0
  62. package/dist/packem_shared/wire-errors-BDckSTKZ.mjs +1 -0
  63. package/dist/pagination/index.d.mts +30 -1
  64. package/dist/pagination/index.d.ts +30 -1
  65. package/dist/pagination/index.mjs +1 -1
  66. package/dist/query/index.d.mts +143 -4
  67. package/dist/query/index.d.ts +143 -4
  68. package/dist/query/index.mjs +1 -1
  69. package/dist/service.d.mts +49 -0
  70. package/dist/service.d.ts +49 -0
  71. package/dist/service.mjs +1 -0
  72. package/dist/ssr/index.d.mts +45 -16
  73. package/dist/ssr/index.d.ts +45 -16
  74. package/dist/ssr/index.mjs +1 -1
  75. package/dist/upload.d.mts +14 -0
  76. package/dist/upload.d.ts +14 -0
  77. package/dist/upload.mjs +1 -1
  78. package/package.json +16 -4
  79. package/dist/packem_shared/CONFLICT_ERROR_CODE-B2SU0CaJ.mjs +0 -1
  80. package/dist/packem_shared/ClientServiceWorker-CRQ5yl7-.mjs +0 -1
  81. package/dist/packem_shared/DEFAULT_MAX_BUFFER-TBn2s7Rz.mjs +0 -1
  82. package/dist/packem_shared/LunoraClient-DDEoZdgP.mjs +0 -1
  83. package/dist/packem_shared/OfflineQueue-B603_q8m.mjs +0 -1
  84. package/dist/packem_shared/SKIP-CArzT3Vl.mjs +0 -1
  85. package/dist/packem_shared/SubscriptionRegistry-CdrOD7sZ.mjs +0 -1
  86. package/dist/packem_shared/TabCoordinator-ijLic02x.mjs +0 -1
  87. package/dist/packem_shared/applyDelta-DXqQORbM.mjs +0 -1
  88. package/dist/packem_shared/createAsyncStoragePersistence-BRLqeXsC.mjs +0 -1
  89. package/dist/packem_shared/createClientQuery-CrdRoicO.mjs +0 -1
  90. package/dist/packem_shared/createInMemoryBookmarkStorage-DCd5Ej-t.mjs +0 -1
  91. package/dist/packem_shared/createInMemoryPersistence-CQYXy8UP.mjs +0 -1
  92. package/dist/packem_shared/createInMemoryQueryCache-DjCKrLjk.mjs +0 -1
  93. package/dist/packem_shared/createLocalStore-B3Tw_Tw1.mjs +0 -1
  94. package/dist/packem_shared/createMutationRunner-lQXH8Amk.mjs +0 -1
  95. package/dist/packem_shared/createMutatorRunner-BVzo0FBZ.mjs +0 -1
  96. package/dist/packem_shared/createReconnect-CFT7YRSR.mjs +0 -1
  97. package/dist/packem_shared/createReply-DF0jRsv-.mjs +0 -1
  98. package/dist/packem_shared/createServerClient-B7KqO8tv.mjs +0 -1
  99. package/dist/packem_shared/createSnapshotPrecondition-DOKRAJ4b.mjs +0 -1
  100. package/dist/packem_shared/deserializePreloaded-CHfOFpka.mjs +0 -1
  101. package/dist/packem_shared/getServerSession-CGjgRBAE.mjs +0 -1
  102. package/dist/packem_shared/httpStream-Cz4_QyjV.mjs +0 -11
  103. package/dist/packem_shared/idb-utility-C-DR8nG1.mjs +0 -1
  104. package/dist/packem_shared/local-store-C53xDvEr.mjs +0 -1
  105. package/dist/packem_shared/lunora-client.d-Bt65hm_E.d.mts +0 -2979
  106. package/dist/packem_shared/lunora-client.d-Bt65hm_E.d.ts +0 -2979
  107. package/dist/packem_shared/offline-queue-D73Dq95V.mjs +0 -1
  108. package/dist/packem_shared/preloadQuery-DjwSjFwt.mjs +0 -1
  109. package/dist/packem_shared/wire-key-D_zOxXK4.mjs +0 -1
@@ -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 { F as FunctionReference, L as LunoraClient, A as ArgsOf, R as ReturnOf, P as Preloaded } from "./lunora-client.d-Bt65hm_E.js";
1
+ import { L as LunoraClient, P as Preloaded } from "./lunora-client.d-Ezp1eG81.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 { F as FunctionReference, L as LunoraClient, A as ArgsOf, R as ReturnOf, P as Preloaded } from "./lunora-client.d-Bt65hm_E.mjs";
1
+ import { L as LunoraClient, P as Preloaded } from "./lunora-client.d-DKfDdnjJ.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};
@@ -29,6 +29,11 @@ interface PaginationResult<T = unknown> {
29
29
  * adjacent ranges. Absent on legacy (open-ended) pages.
30
30
  */
31
31
  splitCursor?: null | string;
32
+ /**
33
+ * Reactive-pagination only: the server's read cut this bounded page short, so it holds only the
34
+ * first rows of its range. Split at `splitCursor` whatever the page's size.
35
+ */
36
+ splitRequired?: boolean;
32
37
  }
33
38
  /**
34
39
  * Lifecycle of a `usePaginatedQuery` feed.
@@ -46,6 +51,8 @@ interface PaginatedCoreResult<T> {
46
51
  pageResults: (PaginationResult<T> | undefined)[];
47
52
  status: PaginationStatus;
48
53
  }
54
+ /** The feed's head page: one open-ended range from the start of the feed. */
55
+ declare const headPage: (numberItems: number) => Page;
49
56
  /** First-page seed: a single open-ended range starting at the feed head. */
50
57
  declare const initialPages: (numberItems: number) => Page[];
51
58
  /**
@@ -79,4 +86,26 @@ declare const derivePaginationStatus: <T>(skipped: boolean, pageResults: (Pagina
79
86
  * valid (null or undefined — caller should no-op).
80
87
  */
81
88
  declare const applyLoadMore: (pages: Page[], cursor: null | string | undefined, numberItems: number) => Page[] | undefined;
82
- export { JOIN_FACTOR, type Page, type PaginatedCoreResult, type PaginationResult, type PaginationStatus, SPLIT_FACTOR, applyLoadMore, derivePaginationStatus, initialPages, rebalance };
89
+ /**
90
+ * What a feed does with one page's failure.
91
+ *
92
+ * - `surface` — report it (the `error` value and `onError`), as before.
93
+ * - `restart` — reload the feed from its first page, silently: the page's cursor no longer decodes.
94
+ * - `ignore` — drop it: a page the feed no longer holds, still reporting from before a restart.
95
+ */
96
+ type PageFailure = "ignore" | "restart" | "surface";
97
+ /** The feed's first page before any `loadMore`: `(null, null]`, the one page that carries no cursor. */
98
+ declare const isHeadPage: (page: Page) => boolean;
99
+ /**
100
+ * Classify a page failure. Only `INVALID_CURSOR` changes the answer: the server refuses a cursor
101
+ * minted by an older build (a deploy changed the query's order or the engine's cursor encoding), and
102
+ * every bounded page the feed holds carries one, so the only way forward is page one.
103
+ *
104
+ * Two cases surface it instead. The head page has no cursor to be stale. And `restartedSinceLoad`
105
+ * (the feed restarted, and no page past the head has had a frame since) means the server is refusing
106
+ * the cursors it mints now, which a second restart would only repeat on every `loadMore`.
107
+ */
108
+ declare const classifyPageFailure: (pages: Page[], isFailedPage: (page: Page) => boolean, error: {
109
+ code?: string;
110
+ }, restartedSinceLoad: boolean) => PageFailure;
111
+ export { JOIN_FACTOR, type Page, type PageFailure, type PaginatedCoreResult, type PaginationResult, type PaginationStatus, SPLIT_FACTOR, applyLoadMore, classifyPageFailure, derivePaginationStatus, headPage, initialPages, isHeadPage, rebalance };
@@ -29,6 +29,11 @@ interface PaginationResult<T = unknown> {
29
29
  * adjacent ranges. Absent on legacy (open-ended) pages.
30
30
  */
31
31
  splitCursor?: null | string;
32
+ /**
33
+ * Reactive-pagination only: the server's read cut this bounded page short, so it holds only the
34
+ * first rows of its range. Split at `splitCursor` whatever the page's size.
35
+ */
36
+ splitRequired?: boolean;
32
37
  }
33
38
  /**
34
39
  * Lifecycle of a `usePaginatedQuery` feed.
@@ -46,6 +51,8 @@ interface PaginatedCoreResult<T> {
46
51
  pageResults: (PaginationResult<T> | undefined)[];
47
52
  status: PaginationStatus;
48
53
  }
54
+ /** The feed's head page: one open-ended range from the start of the feed. */
55
+ declare const headPage: (numberItems: number) => Page;
49
56
  /** First-page seed: a single open-ended range starting at the feed head. */
50
57
  declare const initialPages: (numberItems: number) => Page[];
51
58
  /**
@@ -79,4 +86,26 @@ declare const derivePaginationStatus: <T>(skipped: boolean, pageResults: (Pagina
79
86
  * valid (null or undefined — caller should no-op).
80
87
  */
81
88
  declare const applyLoadMore: (pages: Page[], cursor: null | string | undefined, numberItems: number) => Page[] | undefined;
82
- export { JOIN_FACTOR, type Page, type PaginatedCoreResult, type PaginationResult, type PaginationStatus, SPLIT_FACTOR, applyLoadMore, derivePaginationStatus, initialPages, rebalance };
89
+ /**
90
+ * What a feed does with one page's failure.
91
+ *
92
+ * - `surface` — report it (the `error` value and `onError`), as before.
93
+ * - `restart` — reload the feed from its first page, silently: the page's cursor no longer decodes.
94
+ * - `ignore` — drop it: a page the feed no longer holds, still reporting from before a restart.
95
+ */
96
+ type PageFailure = "ignore" | "restart" | "surface";
97
+ /** The feed's first page before any `loadMore`: `(null, null]`, the one page that carries no cursor. */
98
+ declare const isHeadPage: (page: Page) => boolean;
99
+ /**
100
+ * Classify a page failure. Only `INVALID_CURSOR` changes the answer: the server refuses a cursor
101
+ * minted by an older build (a deploy changed the query's order or the engine's cursor encoding), and
102
+ * every bounded page the feed holds carries one, so the only way forward is page one.
103
+ *
104
+ * Two cases surface it instead. The head page has no cursor to be stale. And `restartedSinceLoad`
105
+ * (the feed restarted, and no page past the head has had a frame since) means the server is refusing
106
+ * the cursors it mints now, which a second restart would only repeat on every `loadMore`.
107
+ */
108
+ declare const classifyPageFailure: (pages: Page[], isFailedPage: (page: Page) => boolean, error: {
109
+ code?: string;
110
+ }, restartedSinceLoad: boolean) => PageFailure;
111
+ export { JOIN_FACTOR, type Page, type PageFailure, type PaginatedCoreResult, type PaginationResult, type PaginationStatus, SPLIT_FACTOR, applyLoadMore, classifyPageFailure, derivePaginationStatus, headPage, initialPages, isHeadPage, rebalance };
@@ -1 +1 @@
1
- const l=2,a=.5,p=r=>[{lower:null,numItems:r,upper:null}],m=(r,s)=>{for(const[n,e]of r.entries()){if(e.upper===null)continue;const t=s[n];if(!t)continue;const i=t.page.length;if(i>2*e.numItems&&t.splitCursor){const u=t.splitCursor,o=[...r];return o.splice(n,1,{lower:e.lower,numItems:e.numItems,upper:u},{lower:u,numItems:e.numItems,upper:e.upper}),o}if(i<.5*e.numItems&&n+1<r.length){const u=r[n+1];if(!u)continue;const o=[...r];return o.splice(n,2,{lower:e.lower,numItems:e.numItems,upper:u.upper}),o}}},c=(r,s)=>{if(r||!s[0])return{nextCursor:void 0,status:"LoadingFirstPage"};const n=s.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=(r,s,n)=>{if(s==null)return;const e=[...r],t=e.at(-1);return t&&(e[e.length-1]={lower:t.lower,numItems:t.numItems,upper:s}),e.push({lower:s,numItems:n,upper:null}),e};export{a as JOIN_FACTOR,l as SPLIT_FACTOR,I as applyLoadMore,c as derivePaginationStatus,p as initialPages,m as rebalance};
1
+ const c=2,p=.5,l=e=>({lower:null,numItems:e,upper:null}),m=e=>[l(e)],d=(e,r)=>{for(const[n,t]of e.entries()){if(t.upper===null)continue;const u=r[n];if(!u)continue;const i=u.page.length;if((i>2*t.numItems||u.splitRequired===!0)&&u.splitCursor){const o=u.splitCursor,s=[...e];return s.splice(n,1,{lower:t.lower,numItems:t.numItems,upper:o},{lower:o,numItems:t.numItems,upper:t.upper}),s}if(i<.5*t.numItems&&n+1<e.length&&r[n+1]?.splitRequired!==!0){const o=e[n+1];if(!o)continue;const s=[...e];return s.splice(n,2,{lower:t.lower,numItems:t.numItems,upper:o.upper}),s}}},f=(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],u=t.at(-1);return u&&(t[t.length-1]={lower:u.lower,numItems:u.numItems,upper:r}),t.push({lower:r,numItems:n,upper:null}),t},a=e=>e.lower===null&&e.upper===null,C=(e,r,n,t)=>{if(n.code!=="INVALID_CURSOR")return"surface";const u=e.find(i=>r(i));return u===void 0?"ignore":a(u)||t?"surface":"restart"};export{p as JOIN_FACTOR,c as SPLIT_FACTOR,I as applyLoadMore,C as classifyPageFailure,f as derivePaginationStatus,l as headPage,m as initialPages,a as isHeadPage,d as rebalance};
@@ -1,6 +1,70 @@
1
- import { S as SubscriptionError, F as FunctionReference, A as ArgsOf, R as ReturnOf, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-Bt65hm_E.mjs";
2
- export type { b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-Bt65hm_E.mjs";
3
- import '@lunora/runtime';
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-Ezp1eG81.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-Ezp1eG81.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 { type ArgsOf, type FunctionReference, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs, type ReturnOf, SKIP, type SubscriptionError, type Unsubscribe, createQuerySubscription, toSubscriptionError };
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 };
@@ -1,6 +1,70 @@
1
- import { S as SubscriptionError, F as FunctionReference, A as ArgsOf, R as ReturnOf, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-Bt65hm_E.js";
2
- export type { b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-Bt65hm_E.js";
3
- import '@lunora/runtime';
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-DKfDdnjJ.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-DKfDdnjJ.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 { type ArgsOf, type FunctionReference, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs, type ReturnOf, SKIP, type SubscriptionError, type Unsubscribe, createQuerySubscription, toSubscriptionError };
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 };
@@ -1 +1 @@
1
- import{SKIP as t,createQuerySubscription as e,toSubscriptionError as i}from"../packem_shared/SKIP-CArzT3Vl.mjs";export{t as SKIP,e as createQuerySubscription,i as toSubscriptionError};
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 };
@@ -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};