@lunora/react 1.0.0-alpha.27 → 1.0.0-alpha.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5,11 +5,11 @@ export { LunoraProvider, useLunora } from './packem_shared/LunoraProvider-BsuiW4
5
5
  export { CheckoutButton, CustomerPortalButton, useCheckout } from './packem_shared/CheckoutButton-DUite8jJ.mjs';
6
6
  export { lunoraQueryOptions } from './packem_shared/lunoraQueryOptions-CefbPBId.mjs';
7
7
  export { useAgent } from './packem_shared/useAgent-BNLlIYHz.mjs';
8
- export { useAgentChat } from './packem_shared/useAgentChat-CSjKniMO.mjs';
8
+ export { useAgentChat } from './packem_shared/useAgentChat-0cebQe7-.mjs';
9
9
  export { useAgentState } from './packem_shared/useAgentState-Cqyd3Dfy.mjs';
10
10
  export { useAgentToolEvents } from './packem_shared/useAgentToolEvents-gF7U4_KY.mjs';
11
11
  export { default as useAuth } from './packem_shared/useAuth-BSutjJaa.mjs';
12
- export { default as useClientQuery } from './packem_shared/useClientQuery-CN1sC3cP.mjs';
12
+ export { default as useClientQuery } from './packem_shared/useClientQuery-DIkNT4QA.mjs';
13
13
  export { default as useConnectionStatus } from './packem_shared/useConnectionStatus-PJ7vyCHy.mjs';
14
14
  export { useFlag, useFlags } from './packem_shared/useFlag-Beyeiq2b.mjs';
15
15
  export { useHttpStream } from './packem_shared/useHttpStream-oc4s1pMy.mjs';
@@ -23,5 +23,5 @@ export { default as useQuery } from './packem_shared/useQuery-CE8_QUgh.mjs';
23
23
  export { useRateLimit } from './packem_shared/useRateLimit-DTEffQEi.mjs';
24
24
  export { useStream } from './packem_shared/useStream-GYNgc9J5.mjs';
25
25
  export { default as useSubscription } from './packem_shared/useSubscription-DcDlvVuI.mjs';
26
- export { useVoiceAgent } from './packem_shared/useVoiceAgent-sC5_ADB8.mjs';
26
+ export { useVoiceAgent } from './packem_shared/useVoiceAgent-w7fzAMSB.mjs';
27
27
  export { createClientQuery, getErrorCode, getRetryAfterMs, isConflictError, isForbiddenError, isRateLimitedError, isUnauthorizedError } from '@lunora/client';
@@ -0,0 +1,38 @@
1
+ import { FunctionReference, ReturnOf, LunoraClient, ArgsOf } from '@lunora/client';
2
+ import { QueryKey } from '@tanstack/react-query';
3
+ /**
4
+ * Pure, transport-free adapter between a Lunora function reference and a
5
+ * TanStack Query options object. No `"use client"` directive and only a
6
+ * type-level `@lunora/client` import, so it is safe to use on either side of an
7
+ * RSC boundary (the runtime transport is the `LunoraClient` you pass in).
8
+ *
9
+ * Use it when you want to drive a Lunora query through TanStack's own hooks —
10
+ * `useSuspenseQuery`, `useQueries`, or the server-side
11
+ * `queryClient.ensureQueryData` / `prefetchQuery` — rather than the first-class
12
+ * `useQuery` from `@lunora/react`.
13
+ */
14
+ /** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
15
+ interface LunoraQueryOptions<F extends FunctionReference> {
16
+ queryFn: () => Promise<ReturnOf<F>>;
17
+ queryKey: QueryKey;
18
+ staleTime: number;
19
+ }
20
+ /**
21
+ * Build a TanStack Query options object for a Lunora query, keyed identically
22
+ * to the first-class hooks (see `lunoraQueryKey`) so a value fetched through
23
+ * this adapter shares cache identity with anything `useQuery` /
24
+ * `prefetchQuery` reads or writes for the same `(fn, args, shardKey)` triple.
25
+ *
26
+ * ```ts
27
+ * const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
28
+ * ```
29
+ *
30
+ * This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
31
+ * TanStack never refetches on its own. It does not open a WebSocket — for live
32
+ * updates that re-render on every server push, use `useQuery` from
33
+ * `@lunora/react`, which attaches a shared subscription to the same cache key.
34
+ */
35
+ declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
36
+ shardKey?: string;
37
+ }) => LunoraQueryOptions<F>;
38
+ export { LunoraQueryOptions as L, lunoraQueryOptions as l };
@@ -0,0 +1,38 @@
1
+ import { FunctionReference, ReturnOf, LunoraClient, ArgsOf } from '@lunora/client';
2
+ import { QueryKey } from '@tanstack/react-query';
3
+ /**
4
+ * Pure, transport-free adapter between a Lunora function reference and a
5
+ * TanStack Query options object. No `"use client"` directive and only a
6
+ * type-level `@lunora/client` import, so it is safe to use on either side of an
7
+ * RSC boundary (the runtime transport is the `LunoraClient` you pass in).
8
+ *
9
+ * Use it when you want to drive a Lunora query through TanStack's own hooks —
10
+ * `useSuspenseQuery`, `useQueries`, or the server-side
11
+ * `queryClient.ensureQueryData` / `prefetchQuery` — rather than the first-class
12
+ * `useQuery` from `@lunora/react`.
13
+ */
14
+ /** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
15
+ interface LunoraQueryOptions<F extends FunctionReference> {
16
+ queryFn: () => Promise<ReturnOf<F>>;
17
+ queryKey: QueryKey;
18
+ staleTime: number;
19
+ }
20
+ /**
21
+ * Build a TanStack Query options object for a Lunora query, keyed identically
22
+ * to the first-class hooks (see `lunoraQueryKey`) so a value fetched through
23
+ * this adapter shares cache identity with anything `useQuery` /
24
+ * `prefetchQuery` reads or writes for the same `(fn, args, shardKey)` triple.
25
+ *
26
+ * ```ts
27
+ * const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
28
+ * ```
29
+ *
30
+ * This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
31
+ * TanStack never refetches on its own. It does not open a WebSocket — for live
32
+ * updates that re-render on every server push, use `useQuery` from
33
+ * `@lunora/react`, which attaches a shared subscription to the same cache key.
34
+ */
35
+ declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
36
+ shardKey?: string;
37
+ }) => LunoraQueryOptions<F>;
38
+ export { LunoraQueryOptions as L, lunoraQueryOptions as l };
@@ -13,18 +13,21 @@ const NO_STREAM_REF = {
13
13
  };
14
14
  const EMPTY_MESSAGES = [];
15
15
  const reconcileOptimistic = (optimistic, durable) => {
16
- const pool = durable.filter((message) => message.role === "user").map((message) => message.content);
16
+ const durableUserRows = durable.filter((message) => message.role === "user");
17
+ const consumed = /* @__PURE__ */ new Set();
17
18
  return optimistic.filter((pending) => {
18
- const index = pool.indexOf(pending.content);
19
- if (index !== -1) {
20
- pool.splice(index, 1);
21
- return false;
19
+ for (let index = pending.durableUserCountAtSend; index < durableUserRows.length; index += 1) {
20
+ const row = durableUserRows[index];
21
+ if (row !== void 0 && !consumed.has(index) && row.content === pending.content) {
22
+ consumed.add(index);
23
+ return false;
24
+ }
22
25
  }
23
26
  return true;
24
27
  });
25
28
  };
26
29
  const useAgentChat = (options) => {
27
- const $ = c(47);
30
+ const $ = c(49);
28
31
  const {
29
32
  api,
30
33
  cancel: cancelReference,
@@ -99,11 +102,24 @@ const useAgentChat = (options) => {
99
102
  let t4;
100
103
  if ($[9] !== durable || $[10] !== optimistic) {
101
104
  const visibleOptimistic = reconcileOptimistic(optimistic, durable);
105
+ let maxDurableSeq;
106
+ if ($[12] !== durable) {
107
+ maxDurableSeq = -1;
108
+ for (const message of durable) {
109
+ if (message.seq > maxDurableSeq) {
110
+ maxDurableSeq = message.seq;
111
+ }
112
+ }
113
+ $[12] = durable;
114
+ $[13] = maxDurableSeq;
115
+ } else {
116
+ maxDurableSeq = $[13];
117
+ }
102
118
  t4 = visibleOptimistic.length === 0 ? durable : [...durable, ...visibleOptimistic.map((pending, index) => ({
103
119
  content: pending.content,
104
120
  optimistic: true,
105
121
  role: "user",
106
- seq: durable.length + index
122
+ seq: maxDurableSeq + 1 + index
107
123
  }))];
108
124
  $[9] = durable;
109
125
  $[10] = optimistic;
@@ -113,32 +129,32 @@ const useAgentChat = (options) => {
113
129
  }
114
130
  const messages = t4;
115
131
  let t5;
116
- if ($[12] !== durable) {
132
+ if ($[14] !== durable) {
117
133
  t5 = durable.filter(_temp);
118
- $[12] = durable;
119
- $[13] = t5;
134
+ $[14] = durable;
135
+ $[15] = t5;
120
136
  } else {
121
- t5 = $[13];
137
+ t5 = $[15];
122
138
  }
123
139
  const assistantCount = t5.length;
124
140
  let t6;
125
- if ($[14] !== assistantCount || $[15] !== chunks || $[16] !== threadKey) {
141
+ if ($[16] !== assistantCount || $[17] !== chunks || $[18] !== threadKey) {
126
142
  let t72;
127
- if ($[18] !== assistantCount || $[19] !== threadKey) {
143
+ if ($[20] !== assistantCount || $[21] !== threadKey) {
128
144
  t72 = (event) => event.kind !== "progress" && event.threadKey === threadKey && event.turn >= assistantCount;
129
- $[18] = assistantCount;
130
- $[19] = threadKey;
131
- $[20] = t72;
145
+ $[20] = assistantCount;
146
+ $[21] = threadKey;
147
+ $[22] = t72;
132
148
  } else {
133
- t72 = $[20];
149
+ t72 = $[22];
134
150
  }
135
151
  t6 = chunks.filter(t72).map(_temp2).join("");
136
- $[14] = assistantCount;
137
- $[15] = chunks;
138
- $[16] = threadKey;
139
- $[17] = t6;
152
+ $[16] = assistantCount;
153
+ $[17] = chunks;
154
+ $[18] = threadKey;
155
+ $[19] = t6;
140
156
  } else {
141
- t6 = $[17];
157
+ t6 = $[19];
142
158
  }
143
159
  const streamingText = t6;
144
160
  const {
@@ -151,12 +167,14 @@ const useAgentChat = (options) => {
151
167
  mutate: resolveMutate
152
168
  } = approvalMutation;
153
169
  let t7;
154
- if ($[21] !== durable || $[22] !== sendArgs || $[23] !== sendMutate || $[24] !== threadKey) {
170
+ if ($[23] !== durable || $[24] !== sendArgs || $[25] !== sendMutate || $[26] !== threadKey) {
155
171
  t7 = async (input, args) => {
156
172
  const id = nextIdRef.current;
157
173
  nextIdRef.current = nextIdRef.current + 1;
174
+ const durableUserCountAtSend = durable.filter(_temp3).length;
158
175
  setOptimistic((previous) => [...reconcileOptimistic(previous, durable), {
159
176
  content: input,
177
+ durableUserCountAtSend,
160
178
  id
161
179
  }]);
162
180
  try {
@@ -172,17 +190,17 @@ const useAgentChat = (options) => {
172
190
  throw error;
173
191
  }
174
192
  };
175
- $[21] = durable;
176
- $[22] = sendArgs;
177
- $[23] = sendMutate;
178
- $[24] = threadKey;
179
- $[25] = t7;
193
+ $[23] = durable;
194
+ $[24] = sendArgs;
195
+ $[25] = sendMutate;
196
+ $[26] = threadKey;
197
+ $[27] = t7;
180
198
  } else {
181
- t7 = $[25];
199
+ t7 = $[27];
182
200
  }
183
201
  const send = t7;
184
202
  let t8;
185
- if ($[26] !== instanceId || $[27] !== resolveMutate || $[28] !== threadKey) {
203
+ if ($[28] !== instanceId || $[29] !== resolveMutate || $[30] !== threadKey) {
186
204
  t8 = async (toolCallId, note) => {
187
205
  if (instanceId === void 0) {
188
206
  throw new Error("useAgentChat: cannot approve — no in-flight run (thread has no instanceId)");
@@ -197,16 +215,16 @@ const useAgentChat = (options) => {
197
215
  }
198
216
  });
199
217
  };
200
- $[26] = instanceId;
201
- $[27] = resolveMutate;
202
- $[28] = threadKey;
203
- $[29] = t8;
218
+ $[28] = instanceId;
219
+ $[29] = resolveMutate;
220
+ $[30] = threadKey;
221
+ $[31] = t8;
204
222
  } else {
205
- t8 = $[29];
223
+ t8 = $[31];
206
224
  }
207
225
  const approve = t8;
208
226
  let t9;
209
- if ($[30] !== instanceId || $[31] !== resolveMutate || $[32] !== threadKey) {
227
+ if ($[32] !== instanceId || $[33] !== resolveMutate || $[34] !== threadKey) {
210
228
  t9 = async (toolCallId_0, note_0) => {
211
229
  if (instanceId === void 0) {
212
230
  throw new Error("useAgentChat: cannot reject — no in-flight run (thread has no instanceId)");
@@ -221,16 +239,16 @@ const useAgentChat = (options) => {
221
239
  }
222
240
  });
223
241
  };
224
- $[30] = instanceId;
225
- $[31] = resolveMutate;
226
- $[32] = threadKey;
227
- $[33] = t9;
242
+ $[32] = instanceId;
243
+ $[33] = resolveMutate;
244
+ $[34] = threadKey;
245
+ $[35] = t9;
228
246
  } else {
229
- t9 = $[33];
247
+ t9 = $[35];
230
248
  }
231
249
  const reject = t9;
232
250
  let t10;
233
- if ($[34] !== cancelMutate || $[35] !== cancelReference || $[36] !== instanceId || $[37] !== threadKey) {
251
+ if ($[36] !== cancelMutate || $[37] !== cancelReference || $[38] !== instanceId || $[39] !== threadKey) {
234
252
  t10 = async () => {
235
253
  if (cancelReference === void 0 || instanceId === void 0) {
236
254
  return;
@@ -240,17 +258,17 @@ const useAgentChat = (options) => {
240
258
  threadKey
241
259
  });
242
260
  };
243
- $[34] = cancelMutate;
244
- $[35] = cancelReference;
245
- $[36] = instanceId;
246
- $[37] = threadKey;
247
- $[38] = t10;
261
+ $[36] = cancelMutate;
262
+ $[37] = cancelReference;
263
+ $[38] = instanceId;
264
+ $[39] = threadKey;
265
+ $[40] = t10;
248
266
  } else {
249
- t10 = $[38];
267
+ t10 = $[40];
250
268
  }
251
269
  const cancel = t10;
252
270
  let t11;
253
- if ($[39] !== approve || $[40] !== cancel || $[41] !== messages || $[42] !== reject || $[43] !== send || $[44] !== status || $[45] !== streamingText) {
271
+ if ($[41] !== approve || $[42] !== cancel || $[43] !== messages || $[44] !== reject || $[45] !== send || $[46] !== status || $[47] !== streamingText) {
254
272
  t11 = {
255
273
  approve,
256
274
  cancel,
@@ -260,24 +278,27 @@ const useAgentChat = (options) => {
260
278
  status,
261
279
  streamingText
262
280
  };
263
- $[39] = approve;
264
- $[40] = cancel;
265
- $[41] = messages;
266
- $[42] = reject;
267
- $[43] = send;
268
- $[44] = status;
269
- $[45] = streamingText;
270
- $[46] = t11;
281
+ $[41] = approve;
282
+ $[42] = cancel;
283
+ $[43] = messages;
284
+ $[44] = reject;
285
+ $[45] = send;
286
+ $[46] = status;
287
+ $[47] = streamingText;
288
+ $[48] = t11;
271
289
  } else {
272
- t11 = $[46];
290
+ t11 = $[48];
273
291
  }
274
292
  return t11;
275
293
  };
276
- function _temp(message) {
277
- return message.role === "assistant";
294
+ function _temp(message_0) {
295
+ return message_0.role === "assistant";
278
296
  }
279
297
  function _temp2(delta) {
280
298
  return delta.text;
281
299
  }
300
+ function _temp3(message_1) {
301
+ return message_1.role === "user";
302
+ }
282
303
 
283
304
  export { useAgentChat };
@@ -0,0 +1,17 @@
1
+ 'use client';
2
+ import { useCallback, useSyncExternalStore } from 'react';
3
+ import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
4
+
5
+ const useClientQuery = (ref) => {
6
+ const client = useLunora();
7
+ const subscribe = useCallback((onStoreChange) => client.subscribeClientQuery(ref, () => {
8
+ onStoreChange();
9
+ }), [client, ref.key]);
10
+ const value = useSyncExternalStore(subscribe, () => client.getClientQuery(ref), () => client.getClientQuery(ref));
11
+ const setter = useCallback((next) => {
12
+ client.setClientQuery(ref, next);
13
+ }, [client, ref]);
14
+ return [value, setter];
15
+ };
16
+
17
+ export { useClientQuery as default };
@@ -309,7 +309,13 @@ const useVoiceAgent = (options) => {
309
309
  setInterimTranscript("");
310
310
  try {
311
311
  const url = voiceSocketUrl(client.url, agentNameFromReference(voice), threadKey);
312
- const openSocket = createSocket ?? ((target) => new globalThis.WebSocket(target));
312
+ const openSocket = createSocket ?? ((target) => {
313
+ const WebSocketImpl = client.getWebSocketImpl();
314
+ if (!WebSocketImpl) {
315
+ throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");
316
+ }
317
+ return new WebSocketImpl(target);
318
+ });
313
319
  const socket_0 = openSocket(url);
314
320
  socket_0.binaryType = "arraybuffer";
315
321
  const connection_2 = {
package/dist/server.d.mts CHANGED
@@ -4,20 +4,20 @@ import { ServerClientOptions } from '@lunora/client/ssr';
4
4
  export { type AuthLike, type HeadersSource, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, serializePreloaded } from '@lunora/client/ssr';
5
5
  import { QueryClient } from '@tanstack/react-query';
6
6
  export { HydrationBoundary, dehydrate } from '@tanstack/react-query';
7
- export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-D4okOpO8.mjs";
7
+ export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-CdgGQ9s4.mjs";
8
8
  /**
9
- * Run a query on the server and seed `queryClient` with the result under the
10
- * same key the client hooks use (see `lunoraQueryKey`), so a later
11
- * `useQuery(fn, args)` reads it straight from the hydrated cache — no loading
12
- * flash, no duplicate fetch on the client.
13
- *
14
- * Pair it with TanStack's `dehydrate` + `HydrationBoundary` (both re-exported
15
- * from this module): prefetch into a fresh `QueryClient`, `dehydrate` it, wrap
16
- * the client subtree in `HydrationBoundary`, and the client hooks pick the value
17
- * up from cache. Errors propagate — wrap the call if you'd rather render a
18
- * fallback than fail the server render. Drop the `await` for fire-and-forget
19
- * prefetch when you don't need the data present on the very first paint.
20
- */
9
+ * Run a query on the server and seed `queryClient` with the result under the
10
+ * same key the client hooks use (see `lunoraQueryKey`), so a later
11
+ * `useQuery(fn, args)` reads it straight from the hydrated cache — no loading
12
+ * flash, no duplicate fetch on the client.
13
+ *
14
+ * Pair it with TanStack's `dehydrate` + `HydrationBoundary` (both re-exported
15
+ * from this module): prefetch into a fresh `QueryClient`, `dehydrate` it, wrap
16
+ * the client subtree in `HydrationBoundary`, and the client hooks pick the value
17
+ * up from cache. Errors propagate — wrap the call if you'd rather render a
18
+ * fallback than fail the server render. Drop the `await` for fire-and-forget
19
+ * prefetch when you don't need the data present on the very first paint.
20
+ */
21
21
  declare const prefetchQuery: <F extends FunctionReference>(queryClient: QueryClient, client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
22
22
  shardKey?: string;
23
23
  }) => Promise<void>;
@@ -27,25 +27,25 @@ interface ServerCallOptions {
27
27
  shardKey?: string;
28
28
  }
29
29
  /**
30
- * Run a query once on the server and return its result — the standalone
31
- * counterpart to `prefetchQuery`/`preloadQuery` for when you just want the data
32
- * inline in a Server Component (e.g. to compute metadata or branch on a value)
33
- * rather than seed a cache or hand a `Preloaded` to the client.
34
- *
35
- * Builds a fresh request-scoped client per call (see `createServerClient`), so
36
- * pass `token` to run as the signed-in user. For several reads in one request,
37
- * prefer holding one `createServerClient` and calling `.query()` yourself to
38
- * avoid rebuilding the transport each time. Errors propagate.
39
- */
30
+ * Run a query once on the server and return its result — the standalone
31
+ * counterpart to `prefetchQuery`/`preloadQuery` for when you just want the data
32
+ * inline in a Server Component (e.g. to compute metadata or branch on a value)
33
+ * rather than seed a cache or hand a `Preloaded` to the client.
34
+ *
35
+ * Builds a fresh request-scoped client per call (see `createServerClient`), so
36
+ * pass `token` to run as the signed-in user. For several reads in one request,
37
+ * prefer holding one `createServerClient` and calling `.query()` yourself to
38
+ * avoid rebuilding the transport each time. Errors propagate.
39
+ */
40
40
  declare const fetchQuery: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
41
41
  /**
42
- * Run a mutation once on the server and return its result. Server-side calls go
43
- * straight over HTTP RPC — the offline queue and optimistic-update machinery are
44
- * client-only and never engage here. Errors propagate.
45
- */
42
+ * Run a mutation once on the server and return its result. Server-side calls go
43
+ * straight over HTTP RPC — the offline queue and optimistic-update machinery are
44
+ * client-only and never engage here. Errors propagate.
45
+ */
46
46
  declare const fetchMutation: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
47
47
  /**
48
- * Run an action once on the server and return its result. Errors propagate.
49
- */
48
+ * Run an action once on the server and return its result. Errors propagate.
49
+ */
50
50
  declare const fetchAction: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
51
51
  export { ServerCallOptions, fetchAction, fetchMutation, fetchQuery, prefetchQuery };
package/dist/server.d.ts CHANGED
@@ -4,20 +4,20 @@ import { ServerClientOptions } from '@lunora/client/ssr';
4
4
  export { type AuthLike, type HeadersSource, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, serializePreloaded } from '@lunora/client/ssr';
5
5
  import { QueryClient } from '@tanstack/react-query';
6
6
  export { HydrationBoundary, dehydrate } from '@tanstack/react-query';
7
- export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-D4okOpO8.js";
7
+ export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-CdgGQ9s4.js";
8
8
  /**
9
- * Run a query on the server and seed `queryClient` with the result under the
10
- * same key the client hooks use (see `lunoraQueryKey`), so a later
11
- * `useQuery(fn, args)` reads it straight from the hydrated cache — no loading
12
- * flash, no duplicate fetch on the client.
13
- *
14
- * Pair it with TanStack's `dehydrate` + `HydrationBoundary` (both re-exported
15
- * from this module): prefetch into a fresh `QueryClient`, `dehydrate` it, wrap
16
- * the client subtree in `HydrationBoundary`, and the client hooks pick the value
17
- * up from cache. Errors propagate — wrap the call if you'd rather render a
18
- * fallback than fail the server render. Drop the `await` for fire-and-forget
19
- * prefetch when you don't need the data present on the very first paint.
20
- */
9
+ * Run a query on the server and seed `queryClient` with the result under the
10
+ * same key the client hooks use (see `lunoraQueryKey`), so a later
11
+ * `useQuery(fn, args)` reads it straight from the hydrated cache — no loading
12
+ * flash, no duplicate fetch on the client.
13
+ *
14
+ * Pair it with TanStack's `dehydrate` + `HydrationBoundary` (both re-exported
15
+ * from this module): prefetch into a fresh `QueryClient`, `dehydrate` it, wrap
16
+ * the client subtree in `HydrationBoundary`, and the client hooks pick the value
17
+ * up from cache. Errors propagate — wrap the call if you'd rather render a
18
+ * fallback than fail the server render. Drop the `await` for fire-and-forget
19
+ * prefetch when you don't need the data present on the very first paint.
20
+ */
21
21
  declare const prefetchQuery: <F extends FunctionReference>(queryClient: QueryClient, client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
22
22
  shardKey?: string;
23
23
  }) => Promise<void>;
@@ -27,25 +27,25 @@ interface ServerCallOptions {
27
27
  shardKey?: string;
28
28
  }
29
29
  /**
30
- * Run a query once on the server and return its result — the standalone
31
- * counterpart to `prefetchQuery`/`preloadQuery` for when you just want the data
32
- * inline in a Server Component (e.g. to compute metadata or branch on a value)
33
- * rather than seed a cache or hand a `Preloaded` to the client.
34
- *
35
- * Builds a fresh request-scoped client per call (see `createServerClient`), so
36
- * pass `token` to run as the signed-in user. For several reads in one request,
37
- * prefer holding one `createServerClient` and calling `.query()` yourself to
38
- * avoid rebuilding the transport each time. Errors propagate.
39
- */
30
+ * Run a query once on the server and return its result — the standalone
31
+ * counterpart to `prefetchQuery`/`preloadQuery` for when you just want the data
32
+ * inline in a Server Component (e.g. to compute metadata or branch on a value)
33
+ * rather than seed a cache or hand a `Preloaded` to the client.
34
+ *
35
+ * Builds a fresh request-scoped client per call (see `createServerClient`), so
36
+ * pass `token` to run as the signed-in user. For several reads in one request,
37
+ * prefer holding one `createServerClient` and calling `.query()` yourself to
38
+ * avoid rebuilding the transport each time. Errors propagate.
39
+ */
40
40
  declare const fetchQuery: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
41
41
  /**
42
- * Run a mutation once on the server and return its result. Server-side calls go
43
- * straight over HTTP RPC — the offline queue and optimistic-update machinery are
44
- * client-only and never engage here. Errors propagate.
45
- */
42
+ * Run a mutation once on the server and return its result. Server-side calls go
43
+ * straight over HTTP RPC — the offline queue and optimistic-update machinery are
44
+ * client-only and never engage here. Errors propagate.
45
+ */
46
46
  declare const fetchMutation: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
47
47
  /**
48
- * Run an action once on the server and return its result. Errors propagate.
49
- */
48
+ * Run an action once on the server and return its result. Errors propagate.
49
+ */
50
50
  declare const fetchAction: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
51
51
  export { ServerCallOptions, fetchAction, fetchMutation, fetchQuery, prefetchQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/react",
3
- "version": "1.0.0-alpha.27",
3
+ "version": "1.0.0-alpha.29",
4
4
  "description": "React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -49,9 +49,9 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@lunora/client": "1.0.0-alpha.23",
53
- "@lunora/errors": "1.0.0-alpha.5",
54
- "@lunora/ratelimit": "1.0.0-alpha.8"
52
+ "@lunora/client": "1.0.0-alpha.25",
53
+ "@lunora/errors": "1.0.0-alpha.6",
54
+ "@lunora/ratelimit": "1.0.0-alpha.9"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "@tanstack/react-query": "^5.101.0",
@@ -1,38 +0,0 @@
1
- import { FunctionReference, ReturnOf, LunoraClient, ArgsOf } from '@lunora/client';
2
- import { QueryKey } from '@tanstack/react-query';
3
- /**
4
- * Pure, transport-free adapter between a Lunora function reference and a
5
- * TanStack Query options object. No `"use client"` directive and only a
6
- * type-level `@lunora/client` import, so it is safe to use on either side of an
7
- * RSC boundary (the runtime transport is the `LunoraClient` you pass in).
8
- *
9
- * Use it when you want to drive a Lunora query through TanStack's own hooks —
10
- * `useSuspenseQuery`, `useQueries`, or the server-side
11
- * `queryClient.ensureQueryData` / `prefetchQuery` — rather than the first-class
12
- * `useQuery` from `@lunora/react`.
13
- */
14
- /** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
15
- interface LunoraQueryOptions<F extends FunctionReference> {
16
- queryFn: () => Promise<ReturnOf<F>>;
17
- queryKey: QueryKey;
18
- staleTime: number;
19
- }
20
- /**
21
- * Build a TanStack Query options object for a Lunora query, keyed identically
22
- * to the first-class hooks (see `lunoraQueryKey`) so a value fetched through
23
- * this adapter shares cache identity with anything `useQuery` /
24
- * `prefetchQuery` reads or writes for the same `(fn, args, shardKey)` triple.
25
- *
26
- * ```ts
27
- * const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
28
- * ```
29
- *
30
- * This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
31
- * TanStack never refetches on its own. It does not open a WebSocket — for live
32
- * updates that re-render on every server push, use `useQuery` from
33
- * `@lunora/react`, which attaches a shared subscription to the same cache key.
34
- */
35
- declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
36
- shardKey?: string;
37
- }) => LunoraQueryOptions<F>;
38
- export { LunoraQueryOptions as L, lunoraQueryOptions as l };
@@ -1,38 +0,0 @@
1
- import { FunctionReference, ReturnOf, LunoraClient, ArgsOf } from '@lunora/client';
2
- import { QueryKey } from '@tanstack/react-query';
3
- /**
4
- * Pure, transport-free adapter between a Lunora function reference and a
5
- * TanStack Query options object. No `"use client"` directive and only a
6
- * type-level `@lunora/client` import, so it is safe to use on either side of an
7
- * RSC boundary (the runtime transport is the `LunoraClient` you pass in).
8
- *
9
- * Use it when you want to drive a Lunora query through TanStack's own hooks —
10
- * `useSuspenseQuery`, `useQueries`, or the server-side
11
- * `queryClient.ensureQueryData` / `prefetchQuery` — rather than the first-class
12
- * `useQuery` from `@lunora/react`.
13
- */
14
- /** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
15
- interface LunoraQueryOptions<F extends FunctionReference> {
16
- queryFn: () => Promise<ReturnOf<F>>;
17
- queryKey: QueryKey;
18
- staleTime: number;
19
- }
20
- /**
21
- * Build a TanStack Query options object for a Lunora query, keyed identically
22
- * to the first-class hooks (see `lunoraQueryKey`) so a value fetched through
23
- * this adapter shares cache identity with anything `useQuery` /
24
- * `prefetchQuery` reads or writes for the same `(fn, args, shardKey)` triple.
25
- *
26
- * ```ts
27
- * const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
28
- * ```
29
- *
30
- * This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
31
- * TanStack never refetches on its own. It does not open a WebSocket — for live
32
- * updates that re-render on every server push, use `useQuery` from
33
- * `@lunora/react`, which attaches a shared subscription to the same cache key.
34
- */
35
- declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
36
- shardKey?: string;
37
- }) => LunoraQueryOptions<F>;
38
- export { LunoraQueryOptions as L, lunoraQueryOptions as l };