@lunora/react 1.0.0-alpha.31 → 1.0.0-alpha.33

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 (64) hide show
  1. package/dist/index.mjs +1 -28
  2. package/dist/packem_shared/AuthLoading-eLWn4Z7G.mjs +2 -0
  3. package/dist/packem_shared/CheckoutButton-DS_DKgNf.mjs +2 -0
  4. package/dist/packem_shared/LunoraProvider-InsjxtOB.mjs +2 -0
  5. package/dist/packem_shared/cache-odCgnNLz.mjs +1 -0
  6. package/dist/packem_shared/hydratePreloaded-DltXxPnp.mjs +2 -0
  7. package/dist/packem_shared/lunoraQueryOptions-BhiUY9ZF.mjs +1 -0
  8. package/dist/packem_shared/query-key-Y92N0Dci.mjs +1 -0
  9. package/dist/packem_shared/stable-key-BSG0zK_E.mjs +1 -0
  10. package/dist/packem_shared/use-paginated-core-DYjRFno_.mjs +2 -0
  11. package/dist/packem_shared/useAgent-DNKxqQ9F.mjs +2 -0
  12. package/dist/packem_shared/useAgentChat-BmYXshp0.mjs +2 -0
  13. package/dist/packem_shared/useAgentState-DO0yz6OU.mjs +2 -0
  14. package/dist/packem_shared/useAgentToolEvents-DTWZCIfd.mjs +2 -0
  15. package/dist/packem_shared/useAuth-CWkJn7i9.mjs +2 -0
  16. package/dist/packem_shared/useAuthState-jnCMkIwt.mjs +2 -0
  17. package/dist/packem_shared/useClientQuery-EPo__hzu.mjs +2 -0
  18. package/dist/packem_shared/useConnectionStatus-PL5D-S7t.mjs +2 -0
  19. package/dist/packem_shared/useFlag-Dh7bXXPx.mjs +2 -0
  20. package/dist/packem_shared/useHttpStream-DFswZrRk.mjs +2 -0
  21. package/dist/packem_shared/useInfiniteQuery-DyExohf2.mjs +2 -0
  22. package/dist/packem_shared/useMutation-B4uL3Rde.mjs +2 -0
  23. package/dist/packem_shared/useMutator-D3CGrk5-.mjs +2 -0
  24. package/dist/packem_shared/usePaginatedQuery-Roo_jyC9.mjs +2 -0
  25. package/dist/packem_shared/usePresence-SJBy81um.mjs +2 -0
  26. package/dist/packem_shared/useQuery-m-trnMUV.mjs +2 -0
  27. package/dist/packem_shared/useRateLimit-DqikMrX9.mjs +2 -0
  28. package/dist/packem_shared/useStream-CGcSWvPI.mjs +2 -0
  29. package/dist/packem_shared/useSubscription-CiQk8tFR.mjs +2 -0
  30. package/dist/packem_shared/useVoiceAgent-4gj2W2jc.mjs +2 -0
  31. package/dist/packem_shared/wire-key-8Ju6XYoB.mjs +1 -0
  32. package/dist/server.mjs +1 -31
  33. package/dist/upload.mjs +1 -2
  34. package/package.json +4 -4
  35. package/dist/packem_shared/AuthLoading-DezUWNB2.mjs +0 -33
  36. package/dist/packem_shared/CheckoutButton-DUite8jJ.mjs +0 -189
  37. package/dist/packem_shared/LunoraProvider-BsuiW4Lk.mjs +0 -81
  38. package/dist/packem_shared/cache-JeuDAXfE.mjs +0 -80
  39. package/dist/packem_shared/hydratePreloaded-2omLtadR.mjs +0 -54
  40. package/dist/packem_shared/lunoraQueryOptions-CefbPBId.mjs +0 -16
  41. package/dist/packem_shared/query-key-LGnArBTB.mjs +0 -13
  42. package/dist/packem_shared/stable-key-DePnevIy.mjs +0 -38
  43. package/dist/packem_shared/use-paginated-core-xxvd1YA0.mjs +0 -179
  44. package/dist/packem_shared/useAgent-BNLlIYHz.mjs +0 -101
  45. package/dist/packem_shared/useAgentChat-0cebQe7-.mjs +0 -304
  46. package/dist/packem_shared/useAgentState-Cqyd3Dfy.mjs +0 -37
  47. package/dist/packem_shared/useAgentToolEvents-gF7U4_KY.mjs +0 -129
  48. package/dist/packem_shared/useAuth-BSutjJaa.mjs +0 -129
  49. package/dist/packem_shared/useAuthState-CyF35qZR.mjs +0 -36
  50. package/dist/packem_shared/useClientQuery-DIkNT4QA.mjs +0 -17
  51. package/dist/packem_shared/useConnectionStatus-PJ7vyCHy.mjs +0 -30
  52. package/dist/packem_shared/useFlag-Beyeiq2b.mjs +0 -128
  53. package/dist/packem_shared/useHttpStream-oc4s1pMy.mjs +0 -127
  54. package/dist/packem_shared/useInfiniteQuery-CJNw1XaZ.mjs +0 -97
  55. package/dist/packem_shared/useMutation-BeqeIjTr.mjs +0 -67
  56. package/dist/packem_shared/useMutator-IIrLtDiM.mjs +0 -47
  57. package/dist/packem_shared/usePaginatedQuery-DWzydaVR.mjs +0 -46
  58. package/dist/packem_shared/usePresence-Rnx1Fznc.mjs +0 -115
  59. package/dist/packem_shared/useQuery-CE8_QUgh.mjs +0 -77
  60. package/dist/packem_shared/useRateLimit-DTEffQEi.mjs +0 -64
  61. package/dist/packem_shared/useStream-GYNgc9J5.mjs +0 -128
  62. package/dist/packem_shared/useSubscription-DcDlvVuI.mjs +0 -139
  63. package/dist/packem_shared/useVoiceAgent-w7fzAMSB.mjs +0 -422
  64. package/dist/packem_shared/wire-key-Bg8BJ8YM.mjs +0 -101
@@ -1,128 +0,0 @@
1
- 'use client';
2
- import { useState, useRef, useEffect } from 'react';
3
- import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
4
- import { s as stableStringify } from './stable-key-DePnevIy.mjs';
5
-
6
- const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
7
- const flagKind = (value) => {
8
- const kind = typeof value;
9
- if (kind === "boolean" || kind === "number" || kind === "string") {
10
- return kind;
11
- }
12
- return "object";
13
- };
14
- const flagsReference = {
15
- __lunoraRef: FLAGS_EVAL_PATH
16
- };
17
- const useFlag = (key, defaultValue, context) => {
18
- const client = useLunora();
19
- const [value, setValue] = useState(defaultValue);
20
- const type = flagKind(defaultValue);
21
- const serializedContext = context === void 0 ? "" : stableStringify(context);
22
- const resetKey = `${key}::${type}::${serializedContext}`;
23
- const resetKeyRef = useRef(resetKey);
24
- if (resetKeyRef.current !== resetKey) {
25
- resetKeyRef.current = resetKey;
26
- setValue(defaultValue);
27
- }
28
- const latest = useRef({
29
- context,
30
- defaultValue
31
- });
32
- useEffect(() => {
33
- latest.current = {
34
- context,
35
- defaultValue
36
- };
37
- });
38
- useEffect(() => {
39
- let cancelled = false;
40
- const {
41
- context: currentContext,
42
- defaultValue: currentDefault
43
- } = latest.current;
44
- setValue(currentDefault);
45
- let unsubscribe;
46
- try {
47
- unsubscribe = client.subscribe(flagsReference, {
48
- context: currentContext,
49
- default: currentDefault,
50
- key,
51
- type
52
- }, (next) => {
53
- if (!cancelled) {
54
- setValue(next);
55
- }
56
- });
57
- } catch {
58
- return () => {
59
- cancelled = true;
60
- };
61
- }
62
- return () => {
63
- cancelled = true;
64
- unsubscribe();
65
- };
66
- }, [client, key, type, serializedContext]);
67
- return value;
68
- };
69
- const useFlags = (flags, context) => {
70
- const client = useLunora();
71
- const [values, setValues] = useState(flags);
72
- const spec = stableStringify(flags);
73
- const serializedContext = context === void 0 ? "" : stableStringify(context);
74
- const resetKey = `${spec}::${serializedContext}`;
75
- const resetKeyRef = useRef(resetKey);
76
- if (resetKeyRef.current !== resetKey) {
77
- resetKeyRef.current = resetKey;
78
- setValues(flags);
79
- }
80
- const latest = useRef({
81
- context,
82
- flags
83
- });
84
- useEffect(() => {
85
- latest.current = {
86
- context,
87
- flags
88
- };
89
- });
90
- useEffect(() => {
91
- let cancelled = false;
92
- const {
93
- context: currentContext,
94
- flags: currentFlags
95
- } = latest.current;
96
- setValues(currentFlags);
97
- const unsubscribes = [];
98
- for (const [key, defaultValue] of Object.entries(currentFlags)) {
99
- try {
100
- unsubscribes.push(client.subscribe(flagsReference, {
101
- context: currentContext,
102
- default: defaultValue,
103
- key,
104
- type: flagKind(defaultValue)
105
- }, (next) => {
106
- if (!cancelled) {
107
- setValues((previous) => {
108
- return {
109
- ...previous,
110
- [key]: next
111
- };
112
- });
113
- }
114
- }));
115
- } catch {
116
- }
117
- }
118
- return () => {
119
- cancelled = true;
120
- for (const unsubscribe of unsubscribes) {
121
- unsubscribe();
122
- }
123
- };
124
- }, [client, spec, serializedContext]);
125
- return values;
126
- };
127
-
128
- export { useFlag, useFlags };
@@ -1,127 +0,0 @@
1
- 'use client';
2
- import { useReducer, useRef, useEffect } from 'react';
3
- import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
4
- import { s as stableStringify } from './stable-key-DePnevIy.mjs';
5
-
6
- const reducer = function(state, action) {
7
- switch (action.type) {
8
- case "chunk": {
9
- return {
10
- chunks: [...state.chunks, action.chunk],
11
- error: void 0,
12
- status: "streaming"
13
- };
14
- }
15
- case "complete": {
16
- return {
17
- ...state,
18
- status: "complete"
19
- };
20
- }
21
- case "error": {
22
- return {
23
- ...state,
24
- error: action.error,
25
- status: "error"
26
- };
27
- }
28
- case "reset": {
29
- return {
30
- chunks: [],
31
- error: void 0,
32
- status: "idle"
33
- };
34
- }
35
- case "start": {
36
- return {
37
- ...state,
38
- status: "streaming"
39
- };
40
- }
41
- default: {
42
- return state;
43
- }
44
- }
45
- };
46
- const useHttpStream = (route, args, options = {}) => {
47
- const client = useLunora();
48
- const [state, dispatch] = useReducer(reducer, {
49
- chunks: [],
50
- error: void 0,
51
- status: "idle"
52
- });
53
- const skipped = args === "skip";
54
- const serialized = skipped ? "skip" : stableStringify(args);
55
- const cancelRef = useRef(void 0);
56
- useEffect(() => {
57
- if (skipped) {
58
- dispatch({
59
- type: "reset"
60
- });
61
- return () => {
62
- };
63
- }
64
- dispatch({
65
- type: "reset"
66
- });
67
- dispatch({
68
- type: "start"
69
- });
70
- let stillMounted = true;
71
- let cancelled = false;
72
- const iterable = client.httpStream(route, args, {
73
- maxBuffer: options.maxBuffer
74
- });
75
- const cancel = () => {
76
- if (cancelled) {
77
- return;
78
- }
79
- cancelled = true;
80
- iterable.cancel();
81
- };
82
- cancelRef.current = cancel;
83
- (async () => {
84
- try {
85
- for await (const chunk of iterable) {
86
- if (!stillMounted) {
87
- return;
88
- }
89
- dispatch({
90
- chunk,
91
- type: "chunk"
92
- });
93
- }
94
- if (stillMounted) {
95
- dispatch({
96
- type: "complete"
97
- });
98
- }
99
- } catch (error) {
100
- if (!stillMounted) {
101
- return;
102
- }
103
- const normalized = error instanceof Error ? error : new Error(String(error));
104
- dispatch({
105
- error: normalized,
106
- type: "error"
107
- });
108
- }
109
- })().catch(() => {
110
- });
111
- return () => {
112
- stillMounted = false;
113
- cancel();
114
- cancelRef.current = void 0;
115
- };
116
- }, [client, route.method, route.path, serialized, skipped, options.maxBuffer]);
117
- return {
118
- cancel: () => {
119
- cancelRef.current?.();
120
- },
121
- chunks: state.chunks,
122
- error: state.error,
123
- status: state.status
124
- };
125
- };
126
-
127
- export { useHttpStream };
@@ -1,97 +0,0 @@
1
- 'use client';
2
- import { c } from 'react/compiler-runtime';
3
- import { useRef, useEffect } from 'react';
4
- import { u as usePaginatedCore } from './use-paginated-core-xxvd1YA0.mjs';
5
-
6
- const useInfiniteQuery = (function_, args, options) => {
7
- const $ = c(15);
8
- const {
9
- initialNumItems
10
- } = options;
11
- const {
12
- loadMore,
13
- pageResults,
14
- status
15
- } = usePaginatedCore(function_, args === "skip" ? "skip" : args, options);
16
- const skipped = args === "skip";
17
- let resolvedPages;
18
- if ($[0] !== pageResults) {
19
- resolvedPages = [];
20
- for (const result of pageResults) {
21
- if (result) {
22
- resolvedPages.push(result.page);
23
- }
24
- }
25
- $[0] = pageResults;
26
- $[1] = resolvedPages;
27
- } else {
28
- resolvedPages = $[1];
29
- }
30
- let t0;
31
- if ($[2] !== initialNumItems || $[3] !== loadMore) {
32
- t0 = {
33
- defaultNumItems: initialNumItems,
34
- loadMore
35
- };
36
- $[2] = initialNumItems;
37
- $[3] = loadMore;
38
- $[4] = t0;
39
- } else {
40
- t0 = $[4];
41
- }
42
- const nextRef = useRef(t0);
43
- let t1;
44
- if ($[5] !== initialNumItems || $[6] !== loadMore) {
45
- t1 = () => {
46
- nextRef.current = {
47
- defaultNumItems: initialNumItems,
48
- loadMore
49
- };
50
- };
51
- $[5] = initialNumItems;
52
- $[6] = loadMore;
53
- $[7] = t1;
54
- } else {
55
- t1 = $[7];
56
- }
57
- useEffect(t1);
58
- let t2;
59
- if ($[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
60
- t2 = (numberItems) => {
61
- const {
62
- defaultNumItems,
63
- loadMore: load
64
- } = nextRef.current;
65
- load(numberItems ?? defaultNumItems);
66
- };
67
- $[8] = t2;
68
- } else {
69
- t2 = $[8];
70
- }
71
- const fetchNextPage = t2;
72
- const t3 = status === "CanLoadMore";
73
- const t4 = !skipped && status === "LoadingMore";
74
- const t5 = !skipped && status === "LoadingFirstPage";
75
- let t6;
76
- if ($[9] !== resolvedPages || $[10] !== status || $[11] !== t3 || $[12] !== t4 || $[13] !== t5) {
77
- t6 = {
78
- fetchNextPage,
79
- hasNextPage: t3,
80
- isFetchingNextPage: t4,
81
- isLoading: t5,
82
- pages: resolvedPages,
83
- status
84
- };
85
- $[9] = resolvedPages;
86
- $[10] = status;
87
- $[11] = t3;
88
- $[12] = t4;
89
- $[13] = t5;
90
- $[14] = t6;
91
- } else {
92
- t6 = $[14];
93
- }
94
- return t6;
95
- };
96
-
97
- export { useInfiniteQuery as default };
@@ -1,67 +0,0 @@
1
- 'use client';
2
- import { useMutation as useMutation$1 } from '@tanstack/react-query';
3
- import { useRef, useState, useCallback } from 'react';
4
- import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
5
-
6
- const useMutation = (function_) => {
7
- const client = useLunora();
8
- const pendingCountRef = useRef(0);
9
- const [pending, setPending] = useState(false);
10
- const mutation = useMutation$1({
11
- mutationFn: ({
12
- args,
13
- options
14
- }) => client.mutation(function_, args, options),
15
- // `onMutate` fires when a call starts, `onSettled` when it resolves or
16
- // rejects — so overlapping calls compose and `pending` only clears once
17
- // the last one settles.
18
- onMutate: () => {
19
- pendingCountRef.current += 1;
20
- setPending(true);
21
- },
22
- onSettled: () => {
23
- pendingCountRef.current -= 1;
24
- setPending(pendingCountRef.current > 0);
25
- }
26
- });
27
- const {
28
- data,
29
- error,
30
- isError,
31
- mutateAsync,
32
- reset
33
- } = mutation;
34
- const mutate = useCallback((args_0, options_0) => mutateAsync({
35
- args: args_0,
36
- options: options_0
37
- }), [mutateAsync]);
38
- const withOptimisticUpdate = useCallback((update) => {
39
- const boundMutate = (args_1, options_1) => mutateAsync({
40
- args: args_1,
41
- options: {
42
- optimisticUpdate: update,
43
- ...options_1
44
- }
45
- });
46
- return {
47
- data,
48
- error,
49
- isError,
50
- mutate: boundMutate,
51
- pending,
52
- reset,
53
- withOptimisticUpdate
54
- };
55
- }, [mutateAsync, data, error, isError, pending, reset]);
56
- return {
57
- data,
58
- error,
59
- isError,
60
- mutate,
61
- pending,
62
- reset,
63
- withOptimisticUpdate
64
- };
65
- };
66
-
67
- export { useMutation };
@@ -1,47 +0,0 @@
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,46 +0,0 @@
1
- 'use client';
2
- import { c } from 'react/compiler-runtime';
3
- import { u as usePaginatedCore } from './use-paginated-core-xxvd1YA0.mjs';
4
-
5
- const usePaginatedQuery = (function_, args, options) => {
6
- const $ = c(7);
7
- const {
8
- loadMore,
9
- pageResults,
10
- status
11
- } = usePaginatedCore(function_, args === "skip" ? "skip" : args, options);
12
- let results;
13
- if ($[0] !== pageResults) {
14
- results = [];
15
- for (const result of pageResults) {
16
- if (result) {
17
- results.push(...result.page);
18
- }
19
- }
20
- $[0] = pageResults;
21
- $[1] = results;
22
- } else {
23
- results = $[1];
24
- }
25
- const skipped = args === "skip";
26
- const t0 = !skipped && (status === "LoadingFirstPage" || status === "LoadingMore");
27
- let t1;
28
- if ($[2] !== loadMore || $[3] !== results || $[4] !== status || $[5] !== t0) {
29
- t1 = {
30
- isLoading: t0,
31
- loadMore,
32
- results,
33
- status
34
- };
35
- $[2] = loadMore;
36
- $[3] = results;
37
- $[4] = status;
38
- $[5] = t0;
39
- $[6] = t1;
40
- } else {
41
- t1 = $[6];
42
- }
43
- return t1;
44
- };
45
-
46
- export { usePaginatedQuery };
@@ -1,115 +0,0 @@
1
- 'use client';
2
- import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
3
- import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
4
-
5
- const randomSessionId = (prefix = "sess") => {
6
- if (typeof crypto !== "undefined") {
7
- if (typeof crypto.randomUUID === "function") {
8
- return crypto.randomUUID();
9
- }
10
- if (typeof crypto.getRandomValues === "function") {
11
- const bytes = crypto.getRandomValues(new Uint8Array(16));
12
- return `${prefix}-${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
13
- }
14
- }
15
- return `${prefix}-${Date.now().toString(36)}`;
16
- };
17
-
18
- const DEFAULT_INTERVAL_MS = 1e4;
19
- const usePresence = (roomId, options) => {
20
- const client = useLunora();
21
- const {
22
- heartbeat,
23
- intervalMs = DEFAULT_INTERVAL_MS,
24
- listPresent,
25
- shardKey
26
- } = options;
27
- const generatedSessionId = useMemo(() => options.sessionId ?? randomSessionId(), [options.sessionId]);
28
- const [present, setPresent] = useState(void 0);
29
- const dataRef = useRef(options.data);
30
- const inputsRef = useRef({
31
- client,
32
- heartbeat,
33
- roomId,
34
- sessionId: generatedSessionId,
35
- shardKey
36
- });
37
- useEffect(() => {
38
- inputsRef.current = {
39
- client,
40
- heartbeat,
41
- roomId,
42
- sessionId: generatedSessionId,
43
- shardKey
44
- };
45
- });
46
- const sendHeartbeat = useCallback(() => {
47
- const {
48
- client: c,
49
- heartbeat: hb,
50
- roomId: room,
51
- sessionId: sid,
52
- shardKey: sk
53
- } = inputsRef.current;
54
- const args = {
55
- roomId: room,
56
- sessionId: sid,
57
- ...dataRef.current === void 0 ? {} : {
58
- data: dataRef.current
59
- }
60
- };
61
- c.mutation(hb, args, {
62
- shardKey: sk
63
- }).catch(() => void 0);
64
- }, []);
65
- const setData = useCallback((next) => {
66
- dataRef.current = next;
67
- sendHeartbeat();
68
- }, [sendHeartbeat]);
69
- useEffect(() => {
70
- sendHeartbeat();
71
- const handle = setInterval(sendHeartbeat, intervalMs);
72
- const onVisible = () => {
73
- if (document.visibilityState === "visible") {
74
- sendHeartbeat();
75
- }
76
- };
77
- document.addEventListener("visibilitychange", onVisible);
78
- return () => {
79
- clearInterval(handle);
80
- document.removeEventListener("visibilitychange", onVisible);
81
- };
82
- }, [sendHeartbeat, intervalMs]);
83
- useEffect(() => {
84
- const release = client.acquireConnectionContext({
85
- roomId,
86
- sessionId: generatedSessionId
87
- }, {
88
- shardKey
89
- });
90
- return release;
91
- }, [client, roomId, generatedSessionId, shardKey]);
92
- useEffect(() => {
93
- let cancelled = false;
94
- const unsubscribe = client.subscribe(listPresent, {
95
- roomId
96
- }, (value) => {
97
- if (!cancelled) {
98
- setPresent(value);
99
- }
100
- }, {
101
- shardKey
102
- });
103
- return () => {
104
- cancelled = true;
105
- unsubscribe();
106
- };
107
- }, [client, listPresent.__lunoraRef, roomId, shardKey]);
108
- return {
109
- present,
110
- sessionId: generatedSessionId,
111
- setData
112
- };
113
- };
114
-
115
- export { usePresence };
@@ -1,77 +0,0 @@
1
- 'use client';
2
- import { c } from 'react/compiler-runtime';
3
- import { useQueryClient, useQuery as useQuery$1 } from '@tanstack/react-query';
4
- import { useState, useEffect } from 'react';
5
- import { g as getSubscriptionRegistry } from './cache-JeuDAXfE.mjs';
6
- import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
7
- import { s as serializeQueryKey, l as lunoraQueryKey } from './query-key-LGnArBTB.mjs';
8
-
9
- const useQuery = (function_, args, t0) => {
10
- const $ = c(9);
11
- const options = t0 === void 0 ? {} : t0;
12
- const client = useLunora();
13
- const queryClient = useQueryClient();
14
- const {
15
- shardKey
16
- } = options;
17
- const skipped = args === "skip";
18
- const argsRecord = skipped ? {} : args;
19
- const queryKey = lunoraQueryKey(function_, argsRecord, shardKey);
20
- const [hydrated, setHydrated] = useState(client.isReady);
21
- let t1;
22
- let t2;
23
- if ($[0] !== client || $[1] !== hydrated) {
24
- t1 = () => {
25
- if (!hydrated) {
26
- client.whenReady().then(() => {
27
- setHydrated(true);
28
- });
29
- }
30
- };
31
- t2 = [client, hydrated];
32
- $[0] = client;
33
- $[1] = hydrated;
34
- $[2] = t1;
35
- $[3] = t2;
36
- } else {
37
- t1 = $[2];
38
- t2 = $[3];
39
- }
40
- useEffect(t1, t2);
41
- const cachedData = skipped ? void 0 : client.peekHydratedQuery(function_.__lunoraRef, argsRecord, shardKey);
42
- const {
43
- data
44
- } = useQuery$1({
45
- enabled: !skipped && hydrated,
46
- initialData: cachedData,
47
- queryFn: () => client.query(function_, argsRecord, {
48
- shardKey
49
- }),
50
- queryKey,
51
- staleTime: Number.POSITIVE_INFINITY
52
- });
53
- const t3 = serializeQueryKey(queryKey);
54
- let t4;
55
- if ($[4] !== client || $[5] !== queryClient || $[6] !== skipped || $[7] !== t3) {
56
- t4 = [client, queryClient, t3, skipped];
57
- $[4] = client;
58
- $[5] = queryClient;
59
- $[6] = skipped;
60
- $[7] = t3;
61
- $[8] = t4;
62
- } else {
63
- t4 = $[8];
64
- }
65
- useEffect(() => {
66
- if (skipped) {
67
- return _temp;
68
- }
69
- const registry = getSubscriptionRegistry(client);
70
- return registry.attach(queryClient, queryKey, function_, argsRecord, shardKey);
71
- }, t4);
72
- return skipped ? void 0 : data;
73
- };
74
- function _temp() {
75
- }
76
-
77
- export { useQuery as default };