@lunora/react 0.0.0 → 1.0.0-alpha.10
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 +105 -0
- package/README.md +152 -9
- package/__assets__/package-og.svg +14 -0
- package/dist/index.d.mts +556 -0
- package/dist/index.d.ts +556 -0
- package/dist/index.mjs +19 -0
- package/dist/packem_shared/AuthLoading-DtKgZT2Z.mjs +33 -0
- package/dist/packem_shared/CheckoutButton-CVSry8U1.mjs +185 -0
- package/dist/packem_shared/LunoraProvider-D38Xp16l.mjs +80 -0
- package/dist/packem_shared/cache-CAp1fVNL.mjs +75 -0
- package/dist/packem_shared/hydratePreloaded-B6OHn0eL.mjs +46 -0
- package/dist/packem_shared/lunoraQueryOptions-Cij4KWBK.mjs +16 -0
- package/dist/packem_shared/query-key-B5eRQCbR.mjs +13 -0
- package/dist/packem_shared/query-options.d-D4okOpO8.d.mts +38 -0
- package/dist/packem_shared/query-options.d-D4okOpO8.d.ts +38 -0
- package/dist/packem_shared/stable-key-CaKZv9lp.mjs +30 -0
- package/dist/packem_shared/use-paginated-core-DP72UNWn.mjs +176 -0
- package/dist/packem_shared/useAuth-CNUKtOOp.mjs +129 -0
- package/dist/packem_shared/useAuthState-BiGhtSCs.mjs +36 -0
- package/dist/packem_shared/useConnectionStatus-DRSY9ldm.mjs +30 -0
- package/dist/packem_shared/useFlag-Bg5DpkGv.mjs +224 -0
- package/dist/packem_shared/useInfiniteQuery-BBIDFXBN.mjs +97 -0
- package/dist/packem_shared/useMutation-CrvMXRsk.mjs +67 -0
- package/dist/packem_shared/useMutator-IIrLtDiM.mjs +47 -0
- package/dist/packem_shared/usePaginatedQuery-AQO3kdp1.mjs +46 -0
- package/dist/packem_shared/usePresence-D7jLuxj0.mjs +108 -0
- package/dist/packem_shared/useQuery-EB74gtBJ.mjs +42 -0
- package/dist/packem_shared/useRateLimit-DTEffQEi.mjs +64 -0
- package/dist/packem_shared/useStream-MdYnWDL_.mjs +125 -0
- package/dist/packem_shared/useSubscription-DSJuryrU.mjs +139 -0
- package/dist/server.d.mts +51 -0
- package/dist/server.d.ts +51 -0
- package/dist/server.mjs +31 -0
- package/package.json +60 -17
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { c } from 'react/compiler-runtime';
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
|
|
5
|
+
|
|
6
|
+
const stores = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const createStore = (client) => {
|
|
8
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
9
|
+
let user = null;
|
|
10
|
+
const notify = () => {
|
|
11
|
+
for (const listener of listeners) {
|
|
12
|
+
listener();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
let generation = 0;
|
|
16
|
+
const setUser = (next) => {
|
|
17
|
+
if (user !== next) {
|
|
18
|
+
user = next;
|
|
19
|
+
notify();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const refresh = () => {
|
|
23
|
+
generation += 1;
|
|
24
|
+
const current = generation;
|
|
25
|
+
if (client.getAuthToken() === null) {
|
|
26
|
+
setUser(null);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
client.getCurrentUser().then((next) => {
|
|
30
|
+
if (current === generation) {
|
|
31
|
+
setUser(next);
|
|
32
|
+
}
|
|
33
|
+
return void 0;
|
|
34
|
+
}).catch(() => {
|
|
35
|
+
if (current === generation) {
|
|
36
|
+
setUser(null);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
let unsubscribeToken;
|
|
41
|
+
return {
|
|
42
|
+
getSnapshot: () => user,
|
|
43
|
+
subscribe: (onChange) => {
|
|
44
|
+
const firstSubscriber = listeners.size === 0;
|
|
45
|
+
listeners.add(onChange);
|
|
46
|
+
if (firstSubscriber) {
|
|
47
|
+
unsubscribeToken = client.onAuthTokenChange(refresh);
|
|
48
|
+
refresh();
|
|
49
|
+
}
|
|
50
|
+
return () => {
|
|
51
|
+
listeners.delete(onChange);
|
|
52
|
+
if (listeners.size === 0) {
|
|
53
|
+
unsubscribeToken?.();
|
|
54
|
+
unsubscribeToken = void 0;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const getStore = (client) => {
|
|
61
|
+
let store = stores.get(client);
|
|
62
|
+
if (!store) {
|
|
63
|
+
store = createStore(client);
|
|
64
|
+
stores.set(client, store);
|
|
65
|
+
}
|
|
66
|
+
return store;
|
|
67
|
+
};
|
|
68
|
+
const useAuth = () => {
|
|
69
|
+
const $ = c(12);
|
|
70
|
+
const client = useLunora();
|
|
71
|
+
let t0;
|
|
72
|
+
if ($[0] !== client) {
|
|
73
|
+
t0 = getStore(client);
|
|
74
|
+
$[0] = client;
|
|
75
|
+
$[1] = t0;
|
|
76
|
+
} else {
|
|
77
|
+
t0 = $[1];
|
|
78
|
+
}
|
|
79
|
+
const store = t0;
|
|
80
|
+
let t1;
|
|
81
|
+
let t2;
|
|
82
|
+
let t3;
|
|
83
|
+
if ($[2] !== client) {
|
|
84
|
+
t1 = (onChange) => client.onAuthTokenChange(onChange);
|
|
85
|
+
t2 = () => client.getAuthToken();
|
|
86
|
+
t3 = () => client.getAuthToken();
|
|
87
|
+
$[2] = client;
|
|
88
|
+
$[3] = t1;
|
|
89
|
+
$[4] = t2;
|
|
90
|
+
$[5] = t3;
|
|
91
|
+
} else {
|
|
92
|
+
t1 = $[3];
|
|
93
|
+
t2 = $[4];
|
|
94
|
+
t3 = $[5];
|
|
95
|
+
}
|
|
96
|
+
const token = useSyncExternalStore(t1, t2, t3);
|
|
97
|
+
const user = useSyncExternalStore(store.subscribe, store.getSnapshot, _temp);
|
|
98
|
+
let t4;
|
|
99
|
+
if ($[6] !== client) {
|
|
100
|
+
t4 = (next) => {
|
|
101
|
+
client.setAuthToken(next);
|
|
102
|
+
};
|
|
103
|
+
$[6] = client;
|
|
104
|
+
$[7] = t4;
|
|
105
|
+
} else {
|
|
106
|
+
t4 = $[7];
|
|
107
|
+
}
|
|
108
|
+
const setToken = t4;
|
|
109
|
+
let t5;
|
|
110
|
+
if ($[8] !== setToken || $[9] !== token || $[10] !== user) {
|
|
111
|
+
t5 = {
|
|
112
|
+
setToken,
|
|
113
|
+
token,
|
|
114
|
+
user
|
|
115
|
+
};
|
|
116
|
+
$[8] = setToken;
|
|
117
|
+
$[9] = token;
|
|
118
|
+
$[10] = user;
|
|
119
|
+
$[11] = t5;
|
|
120
|
+
} else {
|
|
121
|
+
t5 = $[11];
|
|
122
|
+
}
|
|
123
|
+
return t5;
|
|
124
|
+
};
|
|
125
|
+
function _temp() {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { useAuth as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { c } from 'react/compiler-runtime';
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
import useAuth from './useAuth-CNUKtOOp.mjs';
|
|
5
|
+
|
|
6
|
+
const subscribe = () => () => void 0;
|
|
7
|
+
const useAuthState = () => {
|
|
8
|
+
const $ = c(3);
|
|
9
|
+
const {
|
|
10
|
+
token
|
|
11
|
+
} = useAuth();
|
|
12
|
+
const hydrated = useSyncExternalStore(subscribe, _temp, _temp2);
|
|
13
|
+
const t0 = hydrated && token !== null;
|
|
14
|
+
const t1 = !hydrated;
|
|
15
|
+
let t2;
|
|
16
|
+
if ($[0] !== t0 || $[1] !== t1) {
|
|
17
|
+
t2 = {
|
|
18
|
+
isAuthenticated: t0,
|
|
19
|
+
isLoading: t1
|
|
20
|
+
};
|
|
21
|
+
$[0] = t0;
|
|
22
|
+
$[1] = t1;
|
|
23
|
+
$[2] = t2;
|
|
24
|
+
} else {
|
|
25
|
+
t2 = $[2];
|
|
26
|
+
}
|
|
27
|
+
return t2;
|
|
28
|
+
};
|
|
29
|
+
function _temp() {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
function _temp2() {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { useAuthState };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { c } from 'react/compiler-runtime';
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
|
|
5
|
+
|
|
6
|
+
const useConnectionStatus = () => {
|
|
7
|
+
const $ = c(4);
|
|
8
|
+
const client = useLunora();
|
|
9
|
+
let t0;
|
|
10
|
+
let t1;
|
|
11
|
+
let t2;
|
|
12
|
+
if ($[0] !== client) {
|
|
13
|
+
t0 = (onChange) => client.onConnectionStatus(() => {
|
|
14
|
+
onChange();
|
|
15
|
+
});
|
|
16
|
+
t1 = () => client.connectionStatus();
|
|
17
|
+
t2 = () => client.connectionStatus();
|
|
18
|
+
$[0] = client;
|
|
19
|
+
$[1] = t0;
|
|
20
|
+
$[2] = t1;
|
|
21
|
+
$[3] = t2;
|
|
22
|
+
} else {
|
|
23
|
+
t0 = $[1];
|
|
24
|
+
t1 = $[2];
|
|
25
|
+
t2 = $[3];
|
|
26
|
+
}
|
|
27
|
+
return useSyncExternalStore(t0, t1, t2);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { useConnectionStatus as default };
|
|
@@ -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-D38Xp16l.mjs';
|
|
5
|
+
import { s as stableStringify } from './stable-key-CaKZv9lp.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 };
|
|
@@ -0,0 +1,97 @@
|
|
|
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-DP72UNWn.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 };
|
|
@@ -0,0 +1,67 @@
|
|
|
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-D38Xp16l.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 };
|
|
@@ -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 };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { c } from 'react/compiler-runtime';
|
|
3
|
+
import { u as usePaginatedCore } from './use-paginated-core-DP72UNWn.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 };
|