@lunora/react 1.0.0-alpha.6 → 1.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { LunoraClient, OptimisticUpdate, User, ConnectionStatus, ReturnOf, ArgsOf, FunctionReference, Preloaded } from '@lunora/client';
3
- export type { ArgsOf, FunctionReference, LunoraClient, OptimisticLocalStore, OptimisticUpdate, Preloaded, ReturnOf, User } from '@lunora/client';
2
+ import { LunoraClient, OptimisticUpdate, User, ConnectionStatus, ReturnOf, ArgsOf, FunctionReference, MutatorHandle, Preloaded } from '@lunora/client';
3
+ export type { ArgsOf, FunctionReference, LunoraClient, MutatorHandle, MutatorTransaction, OptimisticLocalStore, OptimisticUpdate, Preloaded, ReturnOf, User } from '@lunora/client';
4
4
  import { QueryClient } from '@tanstack/react-query';
5
5
  export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-D4okOpO8.mjs";
6
6
  import { PaginationStatus } from '@lunora/client/pagination';
@@ -354,6 +354,31 @@ interface MutationHook<F extends FunctionReference> {
354
354
  * through TanStack's `onMutate`.
355
355
  */
356
356
  declare const useMutation: <F extends FunctionReference>(function_: F) => MutationHook<F>;
357
+ interface MutatorHook<TArgs> {
358
+ /** The latest invocation's error, or `undefined`. */
359
+ error: Error | undefined;
360
+ /** `true` when the latest invocation rejected. */
361
+ isError: boolean;
362
+ /** Run the mutator; resolves once the write is persisted, rejects on failure. */
363
+ mutate: (args: TArgs) => Promise<void>;
364
+ /** `true` while ANY invocation from this hook is in flight (ref-counted, so overlapping calls compose). */
365
+ pending: boolean;
366
+ /** Clear the latest `error` back to idle. */
367
+ reset: () => void;
368
+ }
369
+ /**
370
+ * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
371
+ * custom-mutator handle from `@lunora/db`'s `bindMutators`. The optimistic
372
+ * overlay and server-authoritative push are owned by the bound handle (and
373
+ * TanStack DB's optimistic-transaction layer rebases pending overlays on every
374
+ * sync tick) — this hook only surfaces React state for the in-flight/error
375
+ * lifecycle. Reads stay on the existing `useLiveQuery`; no new query hook is
376
+ * needed.
377
+ *
378
+ * `pending` is ref-counted across overlapping invocations of THIS hook instance,
379
+ * so it clears only once every concurrent call has settled.
380
+ */
381
+ declare const useMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHook<TArgs>;
357
382
  /**
358
383
  * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
359
384
  * during SSR, then keep it live.
@@ -528,4 +553,4 @@ declare const useStream: <F extends FunctionReference<"stream">>(function_: F, a
528
553
  * the server pushes over the WS.
529
554
  */
530
555
  declare const useSubscription: <F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: UseQueryOptions) => UseSubscriptionResult<ReturnOf<F>>;
531
- export { AuthLoading, type AuthState, Authenticated, CheckoutButton, type CheckoutButtonProps, CustomerPortalButton, type CustomerPortalButtonProps, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type PageItemOf, type PaginatedArgs, type RedirectTarget, type RedirectTrigger, type Subscription, Unauthenticated, type UseAuthResult, type UseCheckoutResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMutationCallOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, hydratePreloaded, useAuth, useAuthState, useCheckout, useConnectionStatus, useFlag, useFlags, useInfiniteQuery, useLunora, useMutation, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useStream, useSubscription };
556
+ export { AuthLoading, type AuthState, Authenticated, CheckoutButton, type CheckoutButtonProps, CustomerPortalButton, type CustomerPortalButtonProps, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type MutatorHook, type PageItemOf, type PaginatedArgs, type RedirectTarget, type RedirectTrigger, type Subscription, Unauthenticated, type UseAuthResult, type UseCheckoutResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMutationCallOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, hydratePreloaded, useAuth, useAuthState, useCheckout, useConnectionStatus, useFlag, useFlags, useInfiniteQuery, useLunora, useMutation, useMutator, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useStream, useSubscription };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { LunoraClient, OptimisticUpdate, User, ConnectionStatus, ReturnOf, ArgsOf, FunctionReference, Preloaded } from '@lunora/client';
3
- export type { ArgsOf, FunctionReference, LunoraClient, OptimisticLocalStore, OptimisticUpdate, Preloaded, ReturnOf, User } from '@lunora/client';
2
+ import { LunoraClient, OptimisticUpdate, User, ConnectionStatus, ReturnOf, ArgsOf, FunctionReference, MutatorHandle, Preloaded } from '@lunora/client';
3
+ export type { ArgsOf, FunctionReference, LunoraClient, MutatorHandle, MutatorTransaction, OptimisticLocalStore, OptimisticUpdate, Preloaded, ReturnOf, User } from '@lunora/client';
4
4
  import { QueryClient } from '@tanstack/react-query';
5
5
  export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-D4okOpO8.js";
6
6
  import { PaginationStatus } from '@lunora/client/pagination';
@@ -354,6 +354,31 @@ interface MutationHook<F extends FunctionReference> {
354
354
  * through TanStack's `onMutate`.
355
355
  */
356
356
  declare const useMutation: <F extends FunctionReference>(function_: F) => MutationHook<F>;
357
+ interface MutatorHook<TArgs> {
358
+ /** The latest invocation's error, or `undefined`. */
359
+ error: Error | undefined;
360
+ /** `true` when the latest invocation rejected. */
361
+ isError: boolean;
362
+ /** Run the mutator; resolves once the write is persisted, rejects on failure. */
363
+ mutate: (args: TArgs) => Promise<void>;
364
+ /** `true` while ANY invocation from this hook is in flight (ref-counted, so overlapping calls compose). */
365
+ pending: boolean;
366
+ /** Clear the latest `error` back to idle. */
367
+ reset: () => void;
368
+ }
369
+ /**
370
+ * Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
371
+ * custom-mutator handle from `@lunora/db`'s `bindMutators`. The optimistic
372
+ * overlay and server-authoritative push are owned by the bound handle (and
373
+ * TanStack DB's optimistic-transaction layer rebases pending overlays on every
374
+ * sync tick) — this hook only surfaces React state for the in-flight/error
375
+ * lifecycle. Reads stay on the existing `useLiveQuery`; no new query hook is
376
+ * needed.
377
+ *
378
+ * `pending` is ref-counted across overlapping invocations of THIS hook instance,
379
+ * so it clears only once every concurrent call has settled.
380
+ */
381
+ declare const useMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHook<TArgs>;
357
382
  /**
358
383
  * Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
359
384
  * during SSR, then keep it live.
@@ -528,4 +553,4 @@ declare const useStream: <F extends FunctionReference<"stream">>(function_: F, a
528
553
  * the server pushes over the WS.
529
554
  */
530
555
  declare const useSubscription: <F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: UseQueryOptions) => UseSubscriptionResult<ReturnOf<F>>;
531
- export { AuthLoading, type AuthState, Authenticated, CheckoutButton, type CheckoutButtonProps, CustomerPortalButton, type CustomerPortalButtonProps, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type PageItemOf, type PaginatedArgs, type RedirectTarget, type RedirectTrigger, type Subscription, Unauthenticated, type UseAuthResult, type UseCheckoutResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMutationCallOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, hydratePreloaded, useAuth, useAuthState, useCheckout, useConnectionStatus, useFlag, useFlags, useInfiniteQuery, useLunora, useMutation, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useStream, useSubscription };
556
+ export { AuthLoading, type AuthState, Authenticated, CheckoutButton, type CheckoutButtonProps, CustomerPortalButton, type CustomerPortalButtonProps, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type MutatorHook, type PageItemOf, type PaginatedArgs, type RedirectTarget, type RedirectTrigger, type Subscription, Unauthenticated, type UseAuthResult, type UseCheckoutResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMutationCallOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, hydratePreloaded, useAuth, useAuthState, useCheckout, useConnectionStatus, useFlag, useFlags, useInfiniteQuery, useLunora, useMutation, useMutator, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useStream, useSubscription };
package/dist/index.mjs CHANGED
@@ -7,9 +7,10 @@ export { lunoraQueryOptions } from './packem_shared/lunoraQueryOptions-Cij4KWBK.
7
7
  export { default as useAuth } from './packem_shared/useAuth-CNUKtOOp.mjs';
8
8
  export { default as useConnectionStatus } from './packem_shared/useConnectionStatus-DRSY9ldm.mjs';
9
9
  export { useFlag, useFlags } from './packem_shared/useFlag-Bg5DpkGv.mjs';
10
- export { default as useInfiniteQuery } from './packem_shared/useInfiniteQuery-HjOCDd3R.mjs';
10
+ export { default as useInfiniteQuery } from './packem_shared/useInfiniteQuery-BBIDFXBN.mjs';
11
11
  export { useMutation } from './packem_shared/useMutation-CrvMXRsk.mjs';
12
- export { usePaginatedQuery } from './packem_shared/usePaginatedQuery-BGYvICZU.mjs';
12
+ export { useMutator } from './packem_shared/useMutator-IIrLtDiM.mjs';
13
+ export { usePaginatedQuery } from './packem_shared/usePaginatedQuery-AQO3kdp1.mjs';
13
14
  export { hydratePreloaded, default as usePreloadedQuery } from './packem_shared/hydratePreloaded-B6OHn0eL.mjs';
14
15
  export { usePresence } from './packem_shared/usePresence-D7jLuxj0.mjs';
15
16
  export { default as useQuery } from './packem_shared/useQuery-EB74gtBJ.mjs';
@@ -49,12 +49,14 @@ const usePaginatedCore = function(function_, args, options) {
49
49
  key: key_0
50
50
  }) => serializeQueryKey(key_0)).join("|");
51
51
  const desiredRef = useRef({
52
+ baseArgs,
52
53
  entries: [],
53
54
  fn: function_,
54
55
  shardKey
55
56
  });
56
57
  useEffect(() => {
57
58
  desiredRef.current = {
59
+ baseArgs,
58
60
  entries: pageEntries,
59
61
  fn: function_,
60
62
  shardKey
@@ -140,17 +142,30 @@ const usePaginatedCore = function(function_, args, options) {
140
142
  }
141
143
  });
142
144
  const {
143
- nextCursor,
144
145
  status
145
146
  } = derivePaginationStatus(skipped, pageResults);
146
- const nextCursorRef = useRef(void 0);
147
- useEffect(() => {
148
- nextCursorRef.current = status === "CanLoadMore" ? nextCursor : void 0;
149
- });
150
147
  const loadMore = useCallback((numberItems) => {
151
- const cursor = nextCursorRef.current;
152
- setPages((current) => applyLoadMore(current, cursor, numberItems) ?? current);
153
- }, []);
148
+ setPages((current) => {
149
+ const desired_0 = desiredRef.current;
150
+ const results = current.map((page_0) => {
151
+ const pageArgs_0 = {
152
+ ...desired_0.baseArgs,
153
+ paginationOpts: {
154
+ cursor: page_0.lower,
155
+ endCursor: page_0.upper,
156
+ numItems: page_0.numItems
157
+ }
158
+ };
159
+ return queryClient.getQueryData(lunoraQueryKey(desired_0.fn, pageArgs_0, desired_0.shardKey));
160
+ });
161
+ const {
162
+ nextCursor,
163
+ status: liveStatus
164
+ } = derivePaginationStatus(false, results);
165
+ const cursor = liveStatus === "CanLoadMore" ? nextCursor : void 0;
166
+ return applyLoadMore(current, cursor, numberItems) ?? current;
167
+ });
168
+ }, [queryClient]);
154
169
  return {
155
170
  loadMore,
156
171
  pageResults,
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { c } from 'react/compiler-runtime';
3
3
  import { useRef, useEffect } from 'react';
4
- import { u as usePaginatedCore } from './use-paginated-core-DxGvzQVR.mjs';
4
+ import { u as usePaginatedCore } from './use-paginated-core-DP72UNWn.mjs';
5
5
 
6
6
  const useInfiniteQuery = (function_, args, options) => {
7
7
  const $ = c(15);
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+ import { c } from 'react/compiler-runtime';
3
+ import { createMutatorRunner } from '@lunora/client';
4
+ import { useState } from 'react';
5
+
6
+ const useMutator = function useMutator2(handle) {
7
+ const $ = c(8);
8
+ const [pending, setPending] = useState(false);
9
+ const [error, setError] = useState(void 0);
10
+ let t0;
11
+ if ($[0] !== handle) {
12
+ t0 = createMutatorRunner(handle, {
13
+ setError,
14
+ setPending
15
+ });
16
+ $[0] = handle;
17
+ $[1] = t0;
18
+ } else {
19
+ t0 = $[1];
20
+ }
21
+ const {
22
+ mutate,
23
+ reset
24
+ } = t0;
25
+ const t1 = error !== void 0;
26
+ let t2;
27
+ if ($[2] !== error || $[3] !== mutate || $[4] !== pending || $[5] !== reset || $[6] !== t1) {
28
+ t2 = {
29
+ error,
30
+ isError: t1,
31
+ mutate,
32
+ pending,
33
+ reset
34
+ };
35
+ $[2] = error;
36
+ $[3] = mutate;
37
+ $[4] = pending;
38
+ $[5] = reset;
39
+ $[6] = t1;
40
+ $[7] = t2;
41
+ } else {
42
+ t2 = $[7];
43
+ }
44
+ return t2;
45
+ };
46
+
47
+ export { useMutator };
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { c } from 'react/compiler-runtime';
3
- import { u as usePaginatedCore } from './use-paginated-core-DxGvzQVR.mjs';
3
+ import { u as usePaginatedCore } from './use-paginated-core-DP72UNWn.mjs';
4
4
 
5
5
  const usePaginatedQuery = (function_, args, options) => {
6
6
  const $ = c(7);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/react",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.7",
4
4
  "description": "React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -49,7 +49,7 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@lunora/client": "1.0.0-alpha.4",
52
+ "@lunora/client": "1.0.0-alpha.5",
53
53
  "@lunora/ratelimit": "1.0.0-alpha.3"
54
54
  },
55
55
  "peerDependencies": {