@lunora/react 1.0.0-alpha.3 → 1.0.0-alpha.30
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/LICENSE.md +6 -0
- package/README.md +2 -0
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +913 -276
- package/dist/index.d.ts +913 -276
- package/dist/index.mjs +25 -15
- package/dist/packem_shared/{AuthLoading-DtKgZT2Z.mjs → AuthLoading-DezUWNB2.mjs} +1 -1
- package/dist/packem_shared/{CheckoutButton-CVSry8U1.mjs → CheckoutButton-DUite8jJ.mjs} +8 -4
- package/dist/packem_shared/{LunoraProvider-D38Xp16l.mjs → LunoraProvider-BsuiW4Lk.mjs} +3 -2
- package/dist/packem_shared/{cache-CItk3fgN.mjs → cache-JeuDAXfE.mjs} +6 -1
- package/dist/packem_shared/hydratePreloaded-2omLtadR.mjs +54 -0
- package/dist/packem_shared/{lunoraQueryOptions-CsuWzjg1.mjs → lunoraQueryOptions-CefbPBId.mjs} +1 -1
- package/dist/packem_shared/query-key-LGnArBTB.mjs +13 -0
- package/dist/packem_shared/query-options.d-CdgGQ9s4.d.mts +38 -0
- package/dist/packem_shared/query-options.d-CdgGQ9s4.d.ts +38 -0
- package/dist/packem_shared/stable-key-DePnevIy.mjs +38 -0
- package/dist/packem_shared/{use-paginated-core-CoOfcc-p.mjs → use-paginated-core-xxvd1YA0.mjs} +37 -19
- package/dist/packem_shared/useAgent-BNLlIYHz.mjs +101 -0
- package/dist/packem_shared/useAgentChat-0cebQe7-.mjs +304 -0
- package/dist/packem_shared/useAgentState-Cqyd3Dfy.mjs +37 -0
- package/dist/packem_shared/useAgentToolEvents-gF7U4_KY.mjs +129 -0
- package/dist/packem_shared/{useAuth-CNUKtOOp.mjs → useAuth-BSutjJaa.mjs} +1 -1
- package/dist/packem_shared/{useAuthState-BiGhtSCs.mjs → useAuthState-CyF35qZR.mjs} +1 -1
- package/dist/packem_shared/useClientQuery-DIkNT4QA.mjs +17 -0
- package/dist/packem_shared/{useConnectionStatus-DRSY9ldm.mjs → useConnectionStatus-PJ7vyCHy.mjs} +1 -1
- package/dist/packem_shared/useFlag-Beyeiq2b.mjs +128 -0
- package/dist/packem_shared/useHttpStream-oc4s1pMy.mjs +127 -0
- package/dist/packem_shared/{useInfiniteQuery-MH0x4l8h.mjs → useInfiniteQuery-CJNw1XaZ.mjs} +1 -1
- package/dist/packem_shared/{useMutation-CrvMXRsk.mjs → useMutation-BeqeIjTr.mjs} +1 -1
- package/dist/packem_shared/useMutator-IIrLtDiM.mjs +47 -0
- package/dist/packem_shared/{usePaginatedQuery-D3PTDRGS.mjs → usePaginatedQuery-DWzydaVR.mjs} +1 -1
- package/dist/packem_shared/{usePresence-D7jLuxj0.mjs → usePresence-Rnx1Fznc.mjs} +13 -6
- package/dist/packem_shared/useQuery-CE8_QUgh.mjs +77 -0
- package/dist/packem_shared/{useStream-BRY9nemd.mjs → useStream-GYNgc9J5.mjs} +6 -3
- package/dist/packem_shared/{useSubscription-CHMCjyQg.mjs → useSubscription-DcDlvVuI.mjs} +3 -3
- package/dist/packem_shared/useVoiceAgent-w7fzAMSB.mjs +422 -0
- package/dist/packem_shared/wire-key-Bg8BJ8YM.mjs +101 -0
- package/dist/server.d.mts +29 -29
- package/dist/server.d.ts +29 -29
- package/dist/server.mjs +2 -2
- package/package.json +6 -5
- package/dist/packem_shared/hydratePreloaded-BlFL9FGq.mjs +0 -46
- package/dist/packem_shared/query-key-C5rufkEE.mjs +0 -21
- package/dist/packem_shared/query-options.d-D4okOpO8.d.mts +0 -38
- package/dist/packem_shared/query-options.d-D4okOpO8.d.ts +0 -38
- package/dist/packem_shared/useQuery-C5S0W-7K.mjs +0 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/react",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.30",
|
|
4
4
|
"description": "React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "packages/react"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist",
|
|
28
|
+
"./dist",
|
|
29
29
|
"README.md",
|
|
30
30
|
"LICENSE.md",
|
|
31
31
|
"__assets__"
|
|
@@ -49,8 +49,9 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@lunora/client": "1.0.0-alpha.
|
|
53
|
-
"@lunora/
|
|
52
|
+
"@lunora/client": "1.0.0-alpha.26",
|
|
53
|
+
"@lunora/errors": "1.0.0-alpha.6",
|
|
54
|
+
"@lunora/ratelimit": "1.0.0-alpha.9"
|
|
54
55
|
},
|
|
55
56
|
"peerDependencies": {
|
|
56
57
|
"@tanstack/react-query": "^5.101.0",
|
|
@@ -65,7 +66,7 @@
|
|
|
65
66
|
"optional": false
|
|
66
67
|
},
|
|
67
68
|
"react-dom": {
|
|
68
|
-
"optional":
|
|
69
|
+
"optional": true
|
|
69
70
|
}
|
|
70
71
|
},
|
|
71
72
|
"engines": {
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useQueryClient, useQuery } from '@tanstack/react-query';
|
|
3
|
-
import { useMemo, useEffect } from 'react';
|
|
4
|
-
import { g as getSubscriptionRegistry } from './cache-CItk3fgN.mjs';
|
|
5
|
-
import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
|
|
6
|
-
import { l as lunoraQueryKey, s as serializeQueryKey } from './query-key-C5rufkEE.mjs';
|
|
7
|
-
|
|
8
|
-
const usePreloadedQuery = function(preloaded) {
|
|
9
|
-
const client = useLunora();
|
|
10
|
-
const queryClient = useQueryClient();
|
|
11
|
-
const {
|
|
12
|
-
args,
|
|
13
|
-
functionPath,
|
|
14
|
-
shardKey,
|
|
15
|
-
value
|
|
16
|
-
} = preloaded;
|
|
17
|
-
const functionRef = useMemo(() => {
|
|
18
|
-
return {
|
|
19
|
-
__lunoraRef: functionPath
|
|
20
|
-
};
|
|
21
|
-
}, [functionPath]);
|
|
22
|
-
const queryKey = useMemo(() => lunoraQueryKey(functionRef, args, shardKey), [functionRef.__lunoraRef, JSON.stringify(args), shardKey]);
|
|
23
|
-
const {
|
|
24
|
-
data
|
|
25
|
-
} = useQuery({
|
|
26
|
-
// Seed the cache with the server value so the first paint doesn't
|
|
27
|
-
// re-fetch. TanStack treats `initialData` as fresh — the WS push from
|
|
28
|
-
// the registry is what supplies subsequent updates.
|
|
29
|
-
initialData: value,
|
|
30
|
-
queryFn: () => client.query(functionRef, args, {
|
|
31
|
-
shardKey
|
|
32
|
-
}),
|
|
33
|
-
queryKey,
|
|
34
|
-
staleTime: Number.POSITIVE_INFINITY
|
|
35
|
-
});
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
const registry = getSubscriptionRegistry(client);
|
|
38
|
-
return registry.attach(queryClient, queryKey, functionRef, args, shardKey);
|
|
39
|
-
}, [client, queryClient, serializeQueryKey(queryKey)]);
|
|
40
|
-
return data ?? value;
|
|
41
|
-
};
|
|
42
|
-
const hydratePreloaded = function(preloaded) {
|
|
43
|
-
return usePreloadedQuery(preloaded);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export { usePreloadedQuery as default, hydratePreloaded };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const keyHash = (queryKey) => JSON.stringify(queryKey);
|
|
2
|
-
const stableStringify = (value) => {
|
|
3
|
-
if (value === null || typeof value !== "object") {
|
|
4
|
-
return JSON.stringify(value);
|
|
5
|
-
}
|
|
6
|
-
if (Array.isArray(value)) {
|
|
7
|
-
return `[${value.map((entry) => stableStringify(entry)).join(",")}]`;
|
|
8
|
-
}
|
|
9
|
-
const entries = Object.entries(value).toSorted(([a], [b]) => a.localeCompare(b));
|
|
10
|
-
return `{${entries.map(([key, value_]) => `${JSON.stringify(key)}:${stableStringify(value_)}`).join(",")}}`;
|
|
11
|
-
};
|
|
12
|
-
const lunoraQueryKey = (function_, args, shardKey) => [
|
|
13
|
-
"lunora",
|
|
14
|
-
function_.__lunoraRef,
|
|
15
|
-
args,
|
|
16
|
-
// eslint-disable-next-line unicorn/no-null -- this literal is part of the JSON-serialized query key TanStack hashes for dedup; `null` keeps a stable, distinct slot from an absent shardKey across renders.
|
|
17
|
-
shardKey ?? null
|
|
18
|
-
];
|
|
19
|
-
const serializeQueryKey = (queryKey) => keyHash(queryKey);
|
|
20
|
-
|
|
21
|
-
export { stableStringify as a, keyHash as k, lunoraQueryKey as l, serializeQueryKey as s };
|
|
@@ -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 };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useQueryClient, useQuery as useQuery$1 } from '@tanstack/react-query';
|
|
3
|
-
import { useMemo, useEffect } from 'react';
|
|
4
|
-
import { g as getSubscriptionRegistry } from './cache-CItk3fgN.mjs';
|
|
5
|
-
import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
|
|
6
|
-
import { l as lunoraQueryKey, a as stableStringify, s as serializeQueryKey } from './query-key-C5rufkEE.mjs';
|
|
7
|
-
|
|
8
|
-
const useQuery = (function_, args, options = {}) => {
|
|
9
|
-
const client = useLunora();
|
|
10
|
-
const queryClient = useQueryClient();
|
|
11
|
-
const {
|
|
12
|
-
shardKey
|
|
13
|
-
} = options;
|
|
14
|
-
const skipped = args === "skip";
|
|
15
|
-
const argsRecord = skipped ? {} : args;
|
|
16
|
-
const queryKey = useMemo(() => lunoraQueryKey(function_, argsRecord, shardKey), [function_.__lunoraRef, stableStringify(argsRecord), shardKey]);
|
|
17
|
-
const {
|
|
18
|
-
data
|
|
19
|
-
} = useQuery$1({
|
|
20
|
-
enabled: !skipped,
|
|
21
|
-
queryFn: () => client.query(function_, argsRecord, {
|
|
22
|
-
shardKey
|
|
23
|
-
}),
|
|
24
|
-
queryKey,
|
|
25
|
-
// Lunora is push-driven: once the initial fetch resolves, the WS owns
|
|
26
|
-
// freshness. Staleness only matters when the subscription is missing,
|
|
27
|
-
// and the registry handles that with a polling fallback.
|
|
28
|
-
staleTime: Number.POSITIVE_INFINITY
|
|
29
|
-
});
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
if (skipped) {
|
|
32
|
-
return () => {
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
const registry = getSubscriptionRegistry(client);
|
|
36
|
-
return registry.attach(queryClient, queryKey, function_, argsRecord, shardKey);
|
|
37
|
-
}, [client, queryClient, serializeQueryKey(queryKey), skipped]);
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { useQuery as default };
|