@lunora/react 1.0.0-alpha.9 → 1.0.0-alpha.91
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 +25 -18
- package/dist/index.d.mts +1157 -355
- package/dist/index.d.ts +1157 -355
- package/dist/index.mjs +1 -18
- package/dist/packem_shared/AuthLoading-dC08yqew.mjs +2 -0
- package/dist/packem_shared/LunoraProvider-DC06S-p1.mjs +2 -0
- package/dist/packem_shared/cache-C2UbTWee.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-DYvzkKqH.mjs +2 -0
- package/dist/packem_shared/lunoraQueryOptions-BVgQsR9d.mjs +1 -0
- package/dist/packem_shared/query-key-By_ZIdza.mjs +1 -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-B_BlboiY.mjs +1 -0
- package/dist/packem_shared/stream-state-abygFxmy.mjs +1 -0
- package/dist/packem_shared/use-paginated-core-BZaJ5Xam.mjs +2 -0
- package/dist/packem_shared/useAction-CUSJu4yq.mjs +2 -0
- package/dist/packem_shared/useAgent-DtQfMu4S.mjs +2 -0
- package/dist/packem_shared/useAgentChat-g4ZNMq1B.mjs +2 -0
- package/dist/packem_shared/useAgentState-BuMYPWb2.mjs +2 -0
- package/dist/packem_shared/useAgentToolEvents-B1ItKmZi.mjs +2 -0
- package/dist/packem_shared/useAuth-x4boOoAR.mjs +2 -0
- package/dist/packem_shared/useAuthSessions-gBDeNFnd.mjs +2 -0
- package/dist/packem_shared/useAuthState-CoOG9XdT.mjs +2 -0
- package/dist/packem_shared/useClientQuery-DFs7trEf.mjs +2 -0
- package/dist/packem_shared/useConnectionStatus-XYsYGiT6.mjs +2 -0
- package/dist/packem_shared/useFlag-BDM923ke.mjs +2 -0
- package/dist/packem_shared/useHttpStream-DWtB9sAr.mjs +2 -0
- package/dist/packem_shared/useInfiniteQuery-D6zw7PwB.mjs +2 -0
- package/dist/packem_shared/useMutation-BnKec7bE.mjs +2 -0
- package/dist/packem_shared/useMutator-BtUd-xEA.mjs +2 -0
- package/dist/packem_shared/usePaginatedQuery-hCSqOGFy.mjs +2 -0
- package/dist/packem_shared/usePresence-BVjZyltT.mjs +2 -0
- package/dist/packem_shared/useQuery-DIu5vJyH.mjs +2 -0
- package/dist/packem_shared/useRateLimit-Cckxi8m9.mjs +2 -0
- package/dist/packem_shared/useStream-Cor62Cu-.mjs +2 -0
- package/dist/packem_shared/useSubscription-egFPCaGE.mjs +2 -0
- package/dist/packem_shared/useVoiceAgent-DHdUlo0G.mjs +2 -0
- package/dist/packem_shared/wire-key-p_JEwJ1j.mjs +1 -0
- package/dist/payment.d.mts +93 -0
- package/dist/payment.d.ts +93 -0
- package/dist/payment.mjs +2 -0
- package/dist/server.d.mts +47 -29
- package/dist/server.d.ts +47 -29
- package/dist/server.mjs +1 -31
- package/dist/upload.d.mts +23 -0
- package/dist/upload.d.ts +23 -0
- package/dist/upload.mjs +2 -0
- package/package.json +14 -4
- package/dist/packem_shared/AuthLoading-DtKgZT2Z.mjs +0 -33
- package/dist/packem_shared/CheckoutButton-CVSry8U1.mjs +0 -185
- package/dist/packem_shared/LunoraProvider-D38Xp16l.mjs +0 -80
- package/dist/packem_shared/cache-CAp1fVNL.mjs +0 -75
- package/dist/packem_shared/hydratePreloaded-B6OHn0eL.mjs +0 -46
- package/dist/packem_shared/lunoraQueryOptions-Cij4KWBK.mjs +0 -16
- package/dist/packem_shared/query-key-B5eRQCbR.mjs +0 -13
- 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/stable-key-CaKZv9lp.mjs +0 -30
- package/dist/packem_shared/use-paginated-core-DP72UNWn.mjs +0 -176
- package/dist/packem_shared/useAuth-CNUKtOOp.mjs +0 -129
- package/dist/packem_shared/useAuthState-BiGhtSCs.mjs +0 -36
- package/dist/packem_shared/useConnectionStatus-DRSY9ldm.mjs +0 -30
- package/dist/packem_shared/useFlag-Bg5DpkGv.mjs +0 -224
- package/dist/packem_shared/useInfiniteQuery-BBIDFXBN.mjs +0 -97
- package/dist/packem_shared/useMutation-CrvMXRsk.mjs +0 -67
- package/dist/packem_shared/useMutator-IIrLtDiM.mjs +0 -47
- package/dist/packem_shared/usePaginatedQuery-AQO3kdp1.mjs +0 -46
- package/dist/packem_shared/usePresence-D7jLuxj0.mjs +0 -108
- package/dist/packem_shared/useQuery-EB74gtBJ.mjs +0 -42
- package/dist/packem_shared/useRateLimit-DTEffQEi.mjs +0 -64
- package/dist/packem_shared/useStream-MdYnWDL_.mjs +0 -125
- package/dist/packem_shared/useSubscription-DSJuryrU.mjs +0 -139
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { k as keyHash } from './query-key-B5eRQCbR.mjs';
|
|
2
|
-
|
|
3
|
-
class LunoraSubscriptionRegistry {
|
|
4
|
-
constructor(client) {
|
|
5
|
-
this.client = client;
|
|
6
|
-
}
|
|
7
|
-
client;
|
|
8
|
-
entries = /* @__PURE__ */ new Map();
|
|
9
|
-
/**
|
|
10
|
-
* Hash a TanStack `queryKey` to the internal registry index. Exposed so a
|
|
11
|
-
* hook can look up the registry without re-implementing the hash.
|
|
12
|
-
*/
|
|
13
|
-
// eslint-disable-next-line class-methods-use-this -- instance method by design: callers reach the hash through a registry handle rather than importing the module-level helper.
|
|
14
|
-
keyOf(queryKey) {
|
|
15
|
-
return keyHash(queryKey);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Attach a consumer to the live subscription for `queryKey`. The first
|
|
19
|
-
* attach opens the underlying WS subscription; subsequent attaches reuse
|
|
20
|
-
* it (refcount-bumped). Returns the detach function — call it exactly once
|
|
21
|
-
* per attach.
|
|
22
|
-
*/
|
|
23
|
-
attach(queryClient, queryKey, function_, args, shardKey, options = {}) {
|
|
24
|
-
const key = keyHash(queryKey);
|
|
25
|
-
let entry = this.entries.get(key);
|
|
26
|
-
if (!entry) {
|
|
27
|
-
entry = {
|
|
28
|
-
pollTimer: void 0,
|
|
29
|
-
refCount: 0,
|
|
30
|
-
unsubscribe: void 0
|
|
31
|
-
};
|
|
32
|
-
this.entries.set(key, entry);
|
|
33
|
-
try {
|
|
34
|
-
entry.unsubscribe = this.client.subscribe(function_, args, (value) => {
|
|
35
|
-
queryClient.setQueryData(queryKey, value);
|
|
36
|
-
}, {
|
|
37
|
-
shardKey
|
|
38
|
-
});
|
|
39
|
-
} catch {
|
|
40
|
-
entry.pollTimer = setInterval(() => {
|
|
41
|
-
queryClient.invalidateQueries({
|
|
42
|
-
queryKey
|
|
43
|
-
}).catch(() => {
|
|
44
|
-
});
|
|
45
|
-
}, options.pollIntervalMs ?? 5e3);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
entry.refCount += 1;
|
|
49
|
-
return () => {
|
|
50
|
-
const current = this.entries.get(key);
|
|
51
|
-
if (!current) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
current.refCount -= 1;
|
|
55
|
-
if (current.refCount <= 0) {
|
|
56
|
-
current.unsubscribe?.();
|
|
57
|
-
if (current.pollTimer) {
|
|
58
|
-
clearInterval(current.pollTimer);
|
|
59
|
-
}
|
|
60
|
-
this.entries.delete(key);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const registryByClient = /* @__PURE__ */ new WeakMap();
|
|
66
|
-
const getSubscriptionRegistry = (client) => {
|
|
67
|
-
let registry = registryByClient.get(client);
|
|
68
|
-
if (!registry) {
|
|
69
|
-
registry = new LunoraSubscriptionRegistry(client);
|
|
70
|
-
registryByClient.set(client, registry);
|
|
71
|
-
}
|
|
72
|
-
return registry;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export { getSubscriptionRegistry as g };
|
|
@@ -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-CAp1fVNL.mjs';
|
|
5
|
-
import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
|
|
6
|
-
import { l as lunoraQueryKey, s as serializeQueryKey } from './query-key-B5eRQCbR.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,16 +0,0 @@
|
|
|
1
|
-
import { l as lunoraQueryKey } from './query-key-B5eRQCbR.mjs';
|
|
2
|
-
|
|
3
|
-
const lunoraQueryOptions = (client, function_, args, options = {}) => {
|
|
4
|
-
const argsRecord = args ?? {};
|
|
5
|
-
return {
|
|
6
|
-
queryFn: () => client.query(function_, argsRecord, {
|
|
7
|
-
shardKey: options.shardKey
|
|
8
|
-
}),
|
|
9
|
-
queryKey: lunoraQueryKey(function_, argsRecord, options.shardKey),
|
|
10
|
-
// Lunora is push-driven: the value never goes stale on a timer. For
|
|
11
|
-
// reactivity use `useQuery`; this adapter is a one-shot/suspense read.
|
|
12
|
-
staleTime: Number.POSITIVE_INFINITY
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export { lunoraQueryOptions };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { s as stableStringify } from './stable-key-CaKZv9lp.mjs';
|
|
2
|
-
|
|
3
|
-
const keyHash = (queryKey) => stableStringify(queryKey);
|
|
4
|
-
const lunoraQueryKey = (function_, args, shardKey) => [
|
|
5
|
-
"lunora",
|
|
6
|
-
function_.__lunoraRef,
|
|
7
|
-
args,
|
|
8
|
-
// 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.
|
|
9
|
-
shardKey ?? null
|
|
10
|
-
];
|
|
11
|
-
const serializeQueryKey = (queryKey) => keyHash(queryKey);
|
|
12
|
-
|
|
13
|
-
export { 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,30 +0,0 @@
|
|
|
1
|
-
const compareKeys = (a, b) => {
|
|
2
|
-
if (a < b) {
|
|
3
|
-
return -1;
|
|
4
|
-
}
|
|
5
|
-
return a > b ? 1 : 0;
|
|
6
|
-
};
|
|
7
|
-
const stableStringify = (value) => {
|
|
8
|
-
if (value === void 0) {
|
|
9
|
-
return "null";
|
|
10
|
-
}
|
|
11
|
-
if (value === null || typeof value !== "object") {
|
|
12
|
-
return JSON.stringify(value);
|
|
13
|
-
}
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
return `[${value.map((item) => stableStringify(item)).join(",")}]`;
|
|
16
|
-
}
|
|
17
|
-
const record = value;
|
|
18
|
-
const keys = Object.keys(record).toSorted(compareKeys);
|
|
19
|
-
const parts = [];
|
|
20
|
-
for (const key of keys) {
|
|
21
|
-
const raw = record[key];
|
|
22
|
-
if (raw === void 0) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
parts.push(`${JSON.stringify(key)}:${stableStringify(raw)}`);
|
|
26
|
-
}
|
|
27
|
-
return `{${parts.join(",")}}`;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { stableStringify as s };
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { initialPages, rebalance, derivePaginationStatus, applyLoadMore } from '@lunora/client/pagination';
|
|
3
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
-
import { useRef, useReducer, useState, useEffect, useCallback } from 'react';
|
|
5
|
-
import { g as getSubscriptionRegistry } from './cache-CAp1fVNL.mjs';
|
|
6
|
-
import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
|
|
7
|
-
import { s as serializeQueryKey, l as lunoraQueryKey } from './query-key-B5eRQCbR.mjs';
|
|
8
|
-
|
|
9
|
-
const useLazyRef = function(create) {
|
|
10
|
-
const reference = useRef(void 0);
|
|
11
|
-
reference.current ??= create();
|
|
12
|
-
return reference;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const usePaginatedCore = function(function_, args, options) {
|
|
16
|
-
const client = useLunora();
|
|
17
|
-
const queryClient = useQueryClient();
|
|
18
|
-
const {
|
|
19
|
-
initialNumItems,
|
|
20
|
-
shardKey
|
|
21
|
-
} = options;
|
|
22
|
-
const skipped = args === "skip";
|
|
23
|
-
const baseArgs = skipped ? {} : args;
|
|
24
|
-
const baseArgsKey = JSON.stringify(baseArgs);
|
|
25
|
-
const [, forceRender] = useReducer((tick) => tick + 1, 0);
|
|
26
|
-
const [pages, setPages] = useState(() => initialPages(initialNumItems));
|
|
27
|
-
const resetKey = `${function_.__lunoraRef}::${baseArgsKey}::${String(initialNumItems)}::${shardKey ?? ""}`;
|
|
28
|
-
const resetKeyRef = useRef(resetKey);
|
|
29
|
-
if (resetKeyRef.current !== resetKey) {
|
|
30
|
-
resetKeyRef.current = resetKey;
|
|
31
|
-
setPages(initialPages(initialNumItems));
|
|
32
|
-
}
|
|
33
|
-
const pageEntries = pages.map((page) => {
|
|
34
|
-
const pageArgs = {
|
|
35
|
-
...baseArgs,
|
|
36
|
-
paginationOpts: {
|
|
37
|
-
cursor: page.lower,
|
|
38
|
-
endCursor: page.upper,
|
|
39
|
-
numItems: page.numItems
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const key = lunoraQueryKey(function_, pageArgs, shardKey);
|
|
43
|
-
return {
|
|
44
|
-
args: pageArgs,
|
|
45
|
-
key
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
const pageKeysHash = pageEntries.map(({
|
|
49
|
-
key: key_0
|
|
50
|
-
}) => serializeQueryKey(key_0)).join("|");
|
|
51
|
-
const desiredRef = useRef({
|
|
52
|
-
baseArgs,
|
|
53
|
-
entries: [],
|
|
54
|
-
fn: function_,
|
|
55
|
-
shardKey
|
|
56
|
-
});
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
desiredRef.current = {
|
|
59
|
-
baseArgs,
|
|
60
|
-
entries: pageEntries,
|
|
61
|
-
fn: function_,
|
|
62
|
-
shardKey
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
const detachesRef = useLazyRef(() => /* @__PURE__ */ new Map());
|
|
66
|
-
const detachClientRef = useRef(client);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const detaches = detachesRef.current;
|
|
69
|
-
if (detachClientRef.current !== client) {
|
|
70
|
-
for (const detach of detaches.values()) {
|
|
71
|
-
detach();
|
|
72
|
-
}
|
|
73
|
-
detaches.clear();
|
|
74
|
-
detachClientRef.current = client;
|
|
75
|
-
}
|
|
76
|
-
if (skipped) {
|
|
77
|
-
for (const detach_0 of detaches.values()) {
|
|
78
|
-
detach_0();
|
|
79
|
-
}
|
|
80
|
-
detaches.clear();
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const desired = desiredRef.current;
|
|
84
|
-
const registry = getSubscriptionRegistry(client);
|
|
85
|
-
const wanted = new Set(desired.entries.map(({
|
|
86
|
-
key: key_1
|
|
87
|
-
}) => serializeQueryKey(key_1)));
|
|
88
|
-
for (const [hash, detach_1] of detaches) {
|
|
89
|
-
if (!wanted.has(hash)) {
|
|
90
|
-
detach_1();
|
|
91
|
-
detaches.delete(hash);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
for (const entry of desired.entries) {
|
|
95
|
-
const hash_0 = serializeQueryKey(entry.key);
|
|
96
|
-
if (detaches.has(hash_0)) {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
const initialFetch = queryClient.fetchQuery({
|
|
100
|
-
queryFn: () => client.query(desired.fn, entry.args, {
|
|
101
|
-
shardKey: desired.shardKey
|
|
102
|
-
}),
|
|
103
|
-
queryKey: entry.key,
|
|
104
|
-
staleTime: 0
|
|
105
|
-
});
|
|
106
|
-
initialFetch.catch(() => {
|
|
107
|
-
});
|
|
108
|
-
detaches.set(hash_0, registry.attach(queryClient, entry.key, desired.fn, entry.args, desired.shardKey));
|
|
109
|
-
}
|
|
110
|
-
}, [client, queryClient, pageKeysHash, skipped]);
|
|
111
|
-
useEffect(() => () => {
|
|
112
|
-
for (const detach_2 of detachesRef.current.values()) {
|
|
113
|
-
detach_2();
|
|
114
|
-
}
|
|
115
|
-
detachesRef.current.clear();
|
|
116
|
-
}, []);
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
const cache = queryClient.getQueryCache();
|
|
119
|
-
const unsubscribe = cache.subscribe((event) => {
|
|
120
|
-
if (event.type !== "updated") {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const hash_1 = serializeQueryKey(event.query.queryKey);
|
|
124
|
-
if (pageEntries.some(({
|
|
125
|
-
key: key_2
|
|
126
|
-
}) => serializeQueryKey(key_2) === hash_1)) {
|
|
127
|
-
forceRender();
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
return unsubscribe;
|
|
131
|
-
}, [queryClient, pageKeysHash]);
|
|
132
|
-
const pageResults = skipped ? [] : pageEntries.map(({
|
|
133
|
-
key: key_3
|
|
134
|
-
}) => queryClient.getQueryData(key_3));
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
if (skipped) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const next = rebalance(pages, pageResults);
|
|
140
|
-
if (next) {
|
|
141
|
-
setPages(next);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
const {
|
|
145
|
-
status
|
|
146
|
-
} = derivePaginationStatus(skipped, pageResults);
|
|
147
|
-
const loadMore = useCallback((numberItems) => {
|
|
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]);
|
|
169
|
-
return {
|
|
170
|
-
loadMore,
|
|
171
|
-
pageResults,
|
|
172
|
-
status
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
export { usePaginatedCore as u };
|
|
@@ -1,129 +0,0 @@
|
|
|
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 };
|
|
@@ -1,36 +0,0 @@
|
|
|
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 };
|
|
@@ -1,30 +0,0 @@
|
|
|
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 };
|