@lunora/react 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +60 -3
- package/dist/index.d.ts +60 -3
- package/dist/index.mjs +18 -15
- package/dist/packem_shared/{Authenticated-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-BFlsXmup.mjs} +1 -1
- package/dist/packem_shared/{hydratePreloaded-BlFL9FGq.mjs → hydratePreloaded-Dsf9YuII.mjs} +22 -14
- package/dist/packem_shared/{lunoraQueryOptions-CsuWzjg1.mjs → lunoraQueryOptions-C3uwOTMW.mjs} +1 -1
- package/dist/packem_shared/query-key-BmCbgidV.mjs +13 -0
- package/dist/packem_shared/stable-key-CGp4e2Ux.mjs +38 -0
- package/dist/packem_shared/{use-paginated-core-CoOfcc-p.mjs → use-paginated-core-CWSzk1J1.mjs} +36 -17
- 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/{useConnectionStatus-DRSY9ldm.mjs → useConnectionStatus-PJ7vyCHy.mjs} +1 -1
- package/dist/packem_shared/useFlag-hhoN_xYA.mjs +224 -0
- package/dist/packem_shared/{useInfiniteQuery-MH0x4l8h.mjs → useInfiniteQuery-Dy42_srs.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-Tx-B3mAP.mjs} +1 -1
- package/dist/packem_shared/{usePresence-D7jLuxj0.mjs → usePresence-DC8VIyLB.mjs} +1 -1
- package/dist/packem_shared/useQuery-_fTR6DCQ.mjs +54 -0
- package/dist/packem_shared/{useStream-BRY9nemd.mjs → useStream-DFuryaIC.mjs} +2 -2
- package/dist/packem_shared/{useSubscription-CHMCjyQg.mjs → useSubscription-D38Jdyr8.mjs} +2 -2
- package/dist/server.mjs +2 -2
- package/package.json +5 -4
- package/dist/packem_shared/query-key-C5rufkEE.mjs +0 -21
- package/dist/packem_shared/useQuery-C5S0W-7K.mjs +0 -41
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { c } from 'react/compiler-runtime';
|
|
3
|
+
import { useState, useRef, useEffect } from 'react';
|
|
4
|
+
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
5
|
+
import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
|
|
6
|
+
|
|
7
|
+
const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
|
|
8
|
+
const flagKind = (value) => {
|
|
9
|
+
const kind = typeof value;
|
|
10
|
+
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
11
|
+
return kind;
|
|
12
|
+
}
|
|
13
|
+
return "object";
|
|
14
|
+
};
|
|
15
|
+
const flagsReference = {
|
|
16
|
+
__lunoraRef: FLAGS_EVAL_PATH
|
|
17
|
+
};
|
|
18
|
+
const useFlag = (key, defaultValue, context) => {
|
|
19
|
+
const $ = c(19);
|
|
20
|
+
const client = useLunora();
|
|
21
|
+
const [value, setValue] = useState(defaultValue);
|
|
22
|
+
let t0;
|
|
23
|
+
if ($[0] !== defaultValue) {
|
|
24
|
+
t0 = flagKind(defaultValue);
|
|
25
|
+
$[0] = defaultValue;
|
|
26
|
+
$[1] = t0;
|
|
27
|
+
} else {
|
|
28
|
+
t0 = $[1];
|
|
29
|
+
}
|
|
30
|
+
const type = t0;
|
|
31
|
+
let t1;
|
|
32
|
+
if ($[2] !== context) {
|
|
33
|
+
t1 = context === void 0 ? "" : stableStringify(context);
|
|
34
|
+
$[2] = context;
|
|
35
|
+
$[3] = t1;
|
|
36
|
+
} else {
|
|
37
|
+
t1 = $[3];
|
|
38
|
+
}
|
|
39
|
+
const serializedContext = t1;
|
|
40
|
+
let t2;
|
|
41
|
+
if ($[4] !== context || $[5] !== defaultValue) {
|
|
42
|
+
t2 = {
|
|
43
|
+
context,
|
|
44
|
+
defaultValue
|
|
45
|
+
};
|
|
46
|
+
$[4] = context;
|
|
47
|
+
$[5] = defaultValue;
|
|
48
|
+
$[6] = t2;
|
|
49
|
+
} else {
|
|
50
|
+
t2 = $[6];
|
|
51
|
+
}
|
|
52
|
+
const latest = useRef(t2);
|
|
53
|
+
let t3;
|
|
54
|
+
if ($[7] !== context || $[8] !== defaultValue) {
|
|
55
|
+
t3 = () => {
|
|
56
|
+
latest.current = {
|
|
57
|
+
context,
|
|
58
|
+
defaultValue
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
$[7] = context;
|
|
62
|
+
$[8] = defaultValue;
|
|
63
|
+
$[9] = t3;
|
|
64
|
+
} else {
|
|
65
|
+
t3 = $[9];
|
|
66
|
+
}
|
|
67
|
+
useEffect(t3);
|
|
68
|
+
let t4;
|
|
69
|
+
if ($[10] !== client || $[11] !== key || $[12] !== type) {
|
|
70
|
+
t4 = () => {
|
|
71
|
+
let cancelled = false;
|
|
72
|
+
const {
|
|
73
|
+
context: currentContext,
|
|
74
|
+
defaultValue: currentDefault
|
|
75
|
+
} = latest.current;
|
|
76
|
+
setValue(currentDefault);
|
|
77
|
+
let unsubscribe;
|
|
78
|
+
try {
|
|
79
|
+
unsubscribe = client.subscribe(flagsReference, {
|
|
80
|
+
context: currentContext,
|
|
81
|
+
default: currentDefault,
|
|
82
|
+
key,
|
|
83
|
+
type
|
|
84
|
+
}, (next) => {
|
|
85
|
+
if (!cancelled) {
|
|
86
|
+
setValue(next);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} catch {
|
|
90
|
+
return () => {
|
|
91
|
+
cancelled = true;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return () => {
|
|
95
|
+
cancelled = true;
|
|
96
|
+
unsubscribe();
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
$[10] = client;
|
|
100
|
+
$[11] = key;
|
|
101
|
+
$[12] = type;
|
|
102
|
+
$[13] = t4;
|
|
103
|
+
} else {
|
|
104
|
+
t4 = $[13];
|
|
105
|
+
}
|
|
106
|
+
let t5;
|
|
107
|
+
if ($[14] !== client || $[15] !== key || $[16] !== serializedContext || $[17] !== type) {
|
|
108
|
+
t5 = [client, key, type, serializedContext];
|
|
109
|
+
$[14] = client;
|
|
110
|
+
$[15] = key;
|
|
111
|
+
$[16] = serializedContext;
|
|
112
|
+
$[17] = type;
|
|
113
|
+
$[18] = t5;
|
|
114
|
+
} else {
|
|
115
|
+
t5 = $[18];
|
|
116
|
+
}
|
|
117
|
+
useEffect(t4, t5);
|
|
118
|
+
return value;
|
|
119
|
+
};
|
|
120
|
+
const useFlags = (flags, context) => {
|
|
121
|
+
const $ = c(16);
|
|
122
|
+
const client = useLunora();
|
|
123
|
+
const [values, setValues] = useState(flags);
|
|
124
|
+
let t0;
|
|
125
|
+
if ($[0] !== flags) {
|
|
126
|
+
t0 = stableStringify(flags);
|
|
127
|
+
$[0] = flags;
|
|
128
|
+
$[1] = t0;
|
|
129
|
+
} else {
|
|
130
|
+
t0 = $[1];
|
|
131
|
+
}
|
|
132
|
+
const spec = t0;
|
|
133
|
+
let t1;
|
|
134
|
+
if ($[2] !== context) {
|
|
135
|
+
t1 = context === void 0 ? "" : stableStringify(context);
|
|
136
|
+
$[2] = context;
|
|
137
|
+
$[3] = t1;
|
|
138
|
+
} else {
|
|
139
|
+
t1 = $[3];
|
|
140
|
+
}
|
|
141
|
+
const serializedContext = t1;
|
|
142
|
+
let t2;
|
|
143
|
+
if ($[4] !== context || $[5] !== flags) {
|
|
144
|
+
t2 = {
|
|
145
|
+
context,
|
|
146
|
+
flags
|
|
147
|
+
};
|
|
148
|
+
$[4] = context;
|
|
149
|
+
$[5] = flags;
|
|
150
|
+
$[6] = t2;
|
|
151
|
+
} else {
|
|
152
|
+
t2 = $[6];
|
|
153
|
+
}
|
|
154
|
+
const latest = useRef(t2);
|
|
155
|
+
let t3;
|
|
156
|
+
if ($[7] !== context || $[8] !== flags) {
|
|
157
|
+
t3 = () => {
|
|
158
|
+
latest.current = {
|
|
159
|
+
context,
|
|
160
|
+
flags
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
$[7] = context;
|
|
164
|
+
$[8] = flags;
|
|
165
|
+
$[9] = t3;
|
|
166
|
+
} else {
|
|
167
|
+
t3 = $[9];
|
|
168
|
+
}
|
|
169
|
+
useEffect(t3);
|
|
170
|
+
let t4;
|
|
171
|
+
if ($[10] !== client) {
|
|
172
|
+
t4 = () => {
|
|
173
|
+
let cancelled = false;
|
|
174
|
+
const {
|
|
175
|
+
context: currentContext,
|
|
176
|
+
flags: currentFlags
|
|
177
|
+
} = latest.current;
|
|
178
|
+
setValues(currentFlags);
|
|
179
|
+
const unsubscribes = [];
|
|
180
|
+
for (const [key, defaultValue] of Object.entries(currentFlags)) {
|
|
181
|
+
try {
|
|
182
|
+
unsubscribes.push(client.subscribe(flagsReference, {
|
|
183
|
+
context: currentContext,
|
|
184
|
+
default: defaultValue,
|
|
185
|
+
key,
|
|
186
|
+
type: flagKind(defaultValue)
|
|
187
|
+
}, (next) => {
|
|
188
|
+
if (!cancelled) {
|
|
189
|
+
setValues((previous) => ({
|
|
190
|
+
...previous,
|
|
191
|
+
[key]: next
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
}));
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return () => {
|
|
199
|
+
cancelled = true;
|
|
200
|
+
for (const unsubscribe of unsubscribes) {
|
|
201
|
+
unsubscribe();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
$[10] = client;
|
|
206
|
+
$[11] = t4;
|
|
207
|
+
} else {
|
|
208
|
+
t4 = $[11];
|
|
209
|
+
}
|
|
210
|
+
let t5;
|
|
211
|
+
if ($[12] !== client || $[13] !== serializedContext || $[14] !== spec) {
|
|
212
|
+
t5 = [client, spec, serializedContext];
|
|
213
|
+
$[12] = client;
|
|
214
|
+
$[13] = serializedContext;
|
|
215
|
+
$[14] = spec;
|
|
216
|
+
$[15] = t5;
|
|
217
|
+
} else {
|
|
218
|
+
t5 = $[15];
|
|
219
|
+
}
|
|
220
|
+
useEffect(t4, t5);
|
|
221
|
+
return values;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export { useFlag, useFlags };
|
|
@@ -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-
|
|
4
|
+
import { u as usePaginatedCore } from './use-paginated-core-CWSzk1J1.mjs';
|
|
5
5
|
|
|
6
6
|
const useInfiniteQuery = (function_, args, options) => {
|
|
7
7
|
const $ = c(15);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useMutation as useMutation$1 } from '@tanstack/react-query';
|
|
3
3
|
import { useRef, useState, useCallback } from 'react';
|
|
4
|
-
import { useLunora } from './LunoraProvider-
|
|
4
|
+
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
5
5
|
|
|
6
6
|
const useMutation = (function_) => {
|
|
7
7
|
const client = useLunora();
|
|
@@ -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 };
|
package/dist/packem_shared/{usePaginatedQuery-D3PTDRGS.mjs → usePaginatedQuery-Tx-B3mAP.mjs}
RENAMED
|
@@ -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-
|
|
3
|
+
import { u as usePaginatedCore } from './use-paginated-core-CWSzk1J1.mjs';
|
|
4
4
|
|
|
5
5
|
const usePaginatedQuery = (function_, args, options) => {
|
|
6
6
|
const $ = c(7);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
-
import { useLunora } from './LunoraProvider-
|
|
3
|
+
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
4
4
|
|
|
5
5
|
const makeSessionId = () => {
|
|
6
6
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { c } from 'react/compiler-runtime';
|
|
3
|
+
import { useQueryClient, useQuery as useQuery$1 } from '@tanstack/react-query';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { g as getSubscriptionRegistry } from './cache-BFlsXmup.mjs';
|
|
6
|
+
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
7
|
+
import { s as serializeQueryKey, l as lunoraQueryKey } from './query-key-BmCbgidV.mjs';
|
|
8
|
+
|
|
9
|
+
const useQuery = (function_, args, t0) => {
|
|
10
|
+
const $ = c(5);
|
|
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 {
|
|
21
|
+
data
|
|
22
|
+
} = useQuery$1({
|
|
23
|
+
enabled: !skipped,
|
|
24
|
+
queryFn: () => client.query(function_, argsRecord, {
|
|
25
|
+
shardKey
|
|
26
|
+
}),
|
|
27
|
+
queryKey,
|
|
28
|
+
staleTime: Number.POSITIVE_INFINITY
|
|
29
|
+
});
|
|
30
|
+
const t1 = serializeQueryKey(queryKey);
|
|
31
|
+
let t2;
|
|
32
|
+
if ($[0] !== client || $[1] !== queryClient || $[2] !== skipped || $[3] !== t1) {
|
|
33
|
+
t2 = [client, queryClient, t1, skipped];
|
|
34
|
+
$[0] = client;
|
|
35
|
+
$[1] = queryClient;
|
|
36
|
+
$[2] = skipped;
|
|
37
|
+
$[3] = t1;
|
|
38
|
+
$[4] = t2;
|
|
39
|
+
} else {
|
|
40
|
+
t2 = $[4];
|
|
41
|
+
}
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (skipped) {
|
|
44
|
+
return _temp;
|
|
45
|
+
}
|
|
46
|
+
const registry = getSubscriptionRegistry(client);
|
|
47
|
+
return registry.attach(queryClient, queryKey, function_, argsRecord, shardKey);
|
|
48
|
+
}, t2);
|
|
49
|
+
return data;
|
|
50
|
+
};
|
|
51
|
+
function _temp() {
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { useQuery as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useReducer, useRef, useEffect } from 'react';
|
|
3
|
-
import { useLunora } from './LunoraProvider-
|
|
4
|
-
import {
|
|
3
|
+
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
4
|
+
import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
|
|
5
5
|
|
|
6
6
|
const reducer = function(state, action) {
|
|
7
7
|
switch (action.type) {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { c } from 'react/compiler-runtime';
|
|
3
3
|
import { createQuerySubscription } from '@lunora/client/query';
|
|
4
4
|
import { useState, useRef, useEffect } from 'react';
|
|
5
|
-
import { useLunora } from './LunoraProvider-
|
|
6
|
-
import {
|
|
5
|
+
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
6
|
+
import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
|
|
7
7
|
|
|
8
8
|
const useSubscription = (function_, args, t0) => {
|
|
9
9
|
const $ = c(22);
|
package/dist/server.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createServerClient } from '@lunora/client/ssr';
|
|
2
2
|
export { createServerClient, deserializePreloaded, getServerSession, serializePreloaded } from '@lunora/client/ssr';
|
|
3
|
-
import { l as lunoraQueryKey } from './packem_shared/query-key-
|
|
4
|
-
export { lunoraQueryOptions } from './packem_shared/lunoraQueryOptions-
|
|
3
|
+
import { l as lunoraQueryKey } from './packem_shared/query-key-BmCbgidV.mjs';
|
|
4
|
+
export { lunoraQueryOptions } from './packem_shared/lunoraQueryOptions-C3uwOTMW.mjs';
|
|
5
5
|
export { preloadQuery, preloadedQueryResult } from '@lunora/client';
|
|
6
6
|
export { HydrationBoundary, dehydrate } from '@tanstack/react-query';
|
|
7
7
|
|
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.21",
|
|
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.19",
|
|
53
|
+
"@lunora/errors": "1.0.0-alpha.2",
|
|
54
|
+
"@lunora/ratelimit": "1.0.0-alpha.5"
|
|
54
55
|
},
|
|
55
56
|
"peerDependencies": {
|
|
56
57
|
"@tanstack/react-query": "^5.101.0",
|
|
@@ -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,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 };
|