houdini-react 0.0.0-20231008055552
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 +21 -0
- package/README.md +36 -0
- package/build/plugin/codegen/entries.d.ts +5 -0
- package/build/plugin/codegen/index.d.ts +13 -0
- package/build/plugin/codegen/manifest.d.ts +5 -0
- package/build/plugin/codegen/render.d.ts +5 -0
- package/build/plugin/codegen/router.d.ts +7 -0
- package/build/plugin/codegen/typeRoot.d.ts +6 -0
- package/build/plugin/config.d.ts +4 -0
- package/build/plugin/dedent.d.ts +1 -0
- package/build/plugin/extract.d.ts +6 -0
- package/build/plugin/index.d.ts +7 -0
- package/build/plugin/transform.d.ts +6 -0
- package/build/plugin/vite.d.ts +54 -0
- package/build/plugin-cjs/index.js +79966 -0
- package/build/plugin-cjs/package.json +1 -0
- package/build/plugin-esm/index.js +79956 -0
- package/build/plugin-esm/package.json +1 -0
- package/build/runtime/client.d.ts +3 -0
- package/build/runtime/clientPlugin.d.ts +3 -0
- package/build/runtime/hooks/index.d.ts +8 -0
- package/build/runtime/hooks/useDeepCompareEffect.d.ts +35 -0
- package/build/runtime/hooks/useDocumentHandle.d.ts +34 -0
- package/build/runtime/hooks/useDocumentStore.d.ts +12 -0
- package/build/runtime/hooks/useDocumentSubscription.d.ts +15 -0
- package/build/runtime/hooks/useFragment.d.ts +16 -0
- package/build/runtime/hooks/useFragmentHandle.d.ts +8 -0
- package/build/runtime/hooks/useIsMounted.d.ts +3 -0
- package/build/runtime/hooks/useMutation.d.ts +10 -0
- package/build/runtime/hooks/useQuery.d.ts +5 -0
- package/build/runtime/hooks/useQueryHandle.d.ts +10 -0
- package/build/runtime/hooks/useSubscription.d.ts +4 -0
- package/build/runtime/hooks/useSubscriptionHandle.d.ts +25 -0
- package/build/runtime/index.d.ts +11 -0
- package/build/runtime/manifest.d.ts +3 -0
- package/build/runtime/routing/Router.d.ts +67 -0
- package/build/runtime/routing/cache.d.ts +7 -0
- package/build/runtime/routing/index.d.ts +2 -0
- package/build/runtime/server/index.d.ts +17 -0
- package/build/runtime/server/renderToStream/createBuffer.d.ts +17 -0
- package/build/runtime/server/renderToStream/createPipeWrapper.d.ts +12 -0
- package/build/runtime/server/renderToStream/createReadableWrapper.d.ts +6 -0
- package/build/runtime/server/renderToStream/loadNodeStreamModule.d.ts +10 -0
- package/build/runtime/server/renderToStream/resolveSeoStrategy.d.ts +9 -0
- package/build/runtime/server/renderToStream.d.ts +28 -0
- package/build/runtime/server/shared/initData.d.ts +8 -0
- package/build/runtime/server/shared/key.d.ts +4 -0
- package/build/runtime/server/shared/utils.d.ts +3 -0
- package/build/runtime/server/useStream.d.ts +9 -0
- package/build/runtime/server/utils/assert.d.ts +15 -0
- package/build/runtime/server/utils/createErrorWithCleanStackTrace.d.ts +2 -0
- package/build/runtime/server/utils/debug.d.ts +14 -0
- package/build/runtime/server/utils/getGlobalVariable.d.ts +4 -0
- package/build/runtime/server/utils/isBrowser.d.ts +2 -0
- package/build/runtime/server/utils/isCallable.d.ts +2 -0
- package/build/runtime/server/utils/isClientSide.d.ts +2 -0
- package/build/runtime/server/utils/isPromise.d.ts +1 -0
- package/build/runtime/server/utils/isServerSide.d.ts +2 -0
- package/build/runtime/server/utils/objectAssign.d.ts +2 -0
- package/build/runtime/server/utils/projectInfo.d.ts +10 -0
- package/build/runtime/server/utils.d.ts +4 -0
- package/build/runtime-cjs/client.d.ts +3 -0
- package/build/runtime-cjs/client.js +27 -0
- package/build/runtime-cjs/clientPlugin.d.ts +3 -0
- package/build/runtime-cjs/clientPlugin.js +39 -0
- package/build/runtime-cjs/hooks/index.d.ts +8 -0
- package/build/runtime-cjs/hooks/index.js +45 -0
- package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +35 -0
- package/build/runtime-cjs/hooks/useDeepCompareEffect.js +72 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +34 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.js +131 -0
- package/build/runtime-cjs/hooks/useDocumentStore.d.ts +12 -0
- package/build/runtime-cjs/hooks/useDocumentStore.js +68 -0
- package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +15 -0
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +72 -0
- package/build/runtime-cjs/hooks/useFragment.d.ts +16 -0
- package/build/runtime-cjs/hooks/useFragment.js +97 -0
- package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +8 -0
- package/build/runtime-cjs/hooks/useFragmentHandle.js +47 -0
- package/build/runtime-cjs/hooks/useIsMounted.d.ts +3 -0
- package/build/runtime-cjs/hooks/useIsMounted.js +38 -0
- package/build/runtime-cjs/hooks/useMutation.d.ts +10 -0
- package/build/runtime-cjs/hooks/useMutation.js +50 -0
- package/build/runtime-cjs/hooks/useQuery.d.ts +5 -0
- package/build/runtime-cjs/hooks/useQuery.js +32 -0
- package/build/runtime-cjs/hooks/useQueryHandle.d.ts +10 -0
- package/build/runtime-cjs/hooks/useQueryHandle.js +125 -0
- package/build/runtime-cjs/hooks/useSubscription.d.ts +4 -0
- package/build/runtime-cjs/hooks/useSubscription.js +32 -0
- package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +25 -0
- package/build/runtime-cjs/hooks/useSubscriptionHandle.js +42 -0
- package/build/runtime-cjs/index.d.ts +11 -0
- package/build/runtime-cjs/index.js +77 -0
- package/build/runtime-cjs/manifest.d.ts +3 -0
- package/build/runtime-cjs/manifest.js +27 -0
- package/build/runtime-cjs/package.json +1 -0
- package/build/runtime-cjs/routing/Router.d.ts +67 -0
- package/build/runtime-cjs/routing/Router.js +429 -0
- package/build/runtime-cjs/routing/cache.d.ts +7 -0
- package/build/runtime-cjs/routing/cache.js +58 -0
- package/build/runtime-cjs/routing/index.d.ts +2 -0
- package/build/runtime-cjs/routing/index.js +30 -0
- package/build/runtime-cjs/server/index.d.ts +17 -0
- package/build/runtime-cjs/server/index.js +28 -0
- package/build/runtime-cjs/server/renderToStream/createBuffer.d.ts +17 -0
- package/build/runtime-cjs/server/renderToStream/createBuffer.js +101 -0
- package/build/runtime-cjs/server/renderToStream/createPipeWrapper.d.ts +12 -0
- package/build/runtime-cjs/server/renderToStream/createPipeWrapper.js +90 -0
- package/build/runtime-cjs/server/renderToStream/createReadableWrapper.d.ts +6 -0
- package/build/runtime-cjs/server/renderToStream/createReadableWrapper.js +85 -0
- package/build/runtime-cjs/server/renderToStream/loadNodeStreamModule.d.ts +10 -0
- package/build/runtime-cjs/server/renderToStream/loadNodeStreamModule.js +51 -0
- package/build/runtime-cjs/server/renderToStream/resolveSeoStrategy.d.ts +9 -0
- package/build/runtime-cjs/server/renderToStream/resolveSeoStrategy.js +44 -0
- package/build/runtime-cjs/server/renderToStream.d.ts +28 -0
- package/build/runtime-cjs/server/renderToStream.js +183 -0
- package/build/runtime-cjs/server/shared/initData.d.ts +8 -0
- package/build/runtime-cjs/server/shared/initData.js +28 -0
- package/build/runtime-cjs/server/shared/key.d.ts +4 -0
- package/build/runtime-cjs/server/shared/key.js +45 -0
- package/build/runtime-cjs/server/shared/utils.d.ts +3 -0
- package/build/runtime-cjs/server/shared/utils.js +20 -0
- package/build/runtime-cjs/server/useStream.d.ts +9 -0
- package/build/runtime-cjs/server/useStream.js +44 -0
- package/build/runtime-cjs/server/utils/assert.d.ts +15 -0
- package/build/runtime-cjs/server/utils/assert.js +119 -0
- package/build/runtime-cjs/server/utils/createErrorWithCleanStackTrace.d.ts +2 -0
- package/build/runtime-cjs/server/utils/createErrorWithCleanStackTrace.js +62 -0
- package/build/runtime-cjs/server/utils/debug.d.ts +14 -0
- package/build/runtime-cjs/server/utils/debug.js +112 -0
- package/build/runtime-cjs/server/utils/getGlobalVariable.d.ts +4 -0
- package/build/runtime-cjs/server/utils/getGlobalVariable.js +32 -0
- package/build/runtime-cjs/server/utils/isBrowser.d.ts +2 -0
- package/build/runtime-cjs/server/utils/isBrowser.js +30 -0
- package/build/runtime-cjs/server/utils/isCallable.d.ts +2 -0
- package/build/runtime-cjs/server/utils/isCallable.js +30 -0
- package/build/runtime-cjs/server/utils/isClientSide.d.ts +2 -0
- package/build/runtime-cjs/server/utils/isClientSide.js +30 -0
- package/build/runtime-cjs/server/utils/isPromise.d.ts +1 -0
- package/build/runtime-cjs/server/utils/isPromise.js +31 -0
- package/build/runtime-cjs/server/utils/isServerSide.d.ts +2 -0
- package/build/runtime-cjs/server/utils/isServerSide.js +31 -0
- package/build/runtime-cjs/server/utils/objectAssign.d.ts +2 -0
- package/build/runtime-cjs/server/utils/objectAssign.js +30 -0
- package/build/runtime-cjs/server/utils/projectInfo.d.ts +10 -0
- package/build/runtime-cjs/server/utils/projectInfo.js +37 -0
- package/build/runtime-cjs/server/utils.d.ts +4 -0
- package/build/runtime-cjs/server/utils.js +21 -0
- package/build/runtime-esm/client.d.ts +3 -0
- package/build/runtime-esm/client.js +5 -0
- package/build/runtime-esm/clientPlugin.d.ts +3 -0
- package/build/runtime-esm/clientPlugin.js +17 -0
- package/build/runtime-esm/hooks/index.d.ts +8 -0
- package/build/runtime-esm/hooks/index.js +16 -0
- package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +35 -0
- package/build/runtime-esm/hooks/useDeepCompareEffect.js +41 -0
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +34 -0
- package/build/runtime-esm/hooks/useDocumentHandle.js +101 -0
- package/build/runtime-esm/hooks/useDocumentStore.d.ts +12 -0
- package/build/runtime-esm/hooks/useDocumentStore.js +38 -0
- package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +15 -0
- package/build/runtime-esm/hooks/useDocumentSubscription.js +42 -0
- package/build/runtime-esm/hooks/useFragment.d.ts +16 -0
- package/build/runtime-esm/hooks/useFragment.js +66 -0
- package/build/runtime-esm/hooks/useFragmentHandle.d.ts +8 -0
- package/build/runtime-esm/hooks/useFragmentHandle.js +23 -0
- package/build/runtime-esm/hooks/useIsMounted.d.ts +3 -0
- package/build/runtime-esm/hooks/useIsMounted.js +14 -0
- package/build/runtime-esm/hooks/useMutation.d.ts +10 -0
- package/build/runtime-esm/hooks/useMutation.js +26 -0
- package/build/runtime-esm/hooks/useQuery.d.ts +5 -0
- package/build/runtime-esm/hooks/useQuery.js +8 -0
- package/build/runtime-esm/hooks/useQueryHandle.d.ts +10 -0
- package/build/runtime-esm/hooks/useQueryHandle.js +95 -0
- package/build/runtime-esm/hooks/useSubscription.d.ts +4 -0
- package/build/runtime-esm/hooks/useSubscription.js +8 -0
- package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +25 -0
- package/build/runtime-esm/hooks/useSubscriptionHandle.js +18 -0
- package/build/runtime-esm/index.d.ts +11 -0
- package/build/runtime-esm/index.js +45 -0
- package/build/runtime-esm/manifest.d.ts +3 -0
- package/build/runtime-esm/manifest.js +5 -0
- package/build/runtime-esm/package.json +1 -0
- package/build/runtime-esm/routing/Router.d.ts +67 -0
- package/build/runtime-esm/routing/Router.js +390 -0
- package/build/runtime-esm/routing/cache.d.ts +7 -0
- package/build/runtime-esm/routing/cache.js +33 -0
- package/build/runtime-esm/routing/index.d.ts +2 -0
- package/build/runtime-esm/routing/index.js +5 -0
- package/build/runtime-esm/server/index.d.ts +17 -0
- package/build/runtime-esm/server/index.js +4 -0
- package/build/runtime-esm/server/renderToStream/createBuffer.d.ts +17 -0
- package/build/runtime-esm/server/renderToStream/createBuffer.js +77 -0
- package/build/runtime-esm/server/renderToStream/createPipeWrapper.d.ts +12 -0
- package/build/runtime-esm/server/renderToStream/createPipeWrapper.js +66 -0
- package/build/runtime-esm/server/renderToStream/createReadableWrapper.d.ts +6 -0
- package/build/runtime-esm/server/renderToStream/createReadableWrapper.js +61 -0
- package/build/runtime-esm/server/renderToStream/loadNodeStreamModule.d.ts +10 -0
- package/build/runtime-esm/server/renderToStream/loadNodeStreamModule.js +20 -0
- package/build/runtime-esm/server/renderToStream/resolveSeoStrategy.d.ts +9 -0
- package/build/runtime-esm/server/renderToStream/resolveSeoStrategy.js +20 -0
- package/build/runtime-esm/server/renderToStream.d.ts +28 -0
- package/build/runtime-esm/server/renderToStream.js +152 -0
- package/build/runtime-esm/server/shared/initData.d.ts +8 -0
- package/build/runtime-esm/server/shared/initData.js +4 -0
- package/build/runtime-esm/server/shared/key.d.ts +4 -0
- package/build/runtime-esm/server/shared/key.js +20 -0
- package/build/runtime-esm/server/shared/utils.d.ts +3 -0
- package/build/runtime-esm/server/shared/utils.js +3 -0
- package/build/runtime-esm/server/useStream.d.ts +9 -0
- package/build/runtime-esm/server/useStream.js +13 -0
- package/build/runtime-esm/server/utils/assert.d.ts +15 -0
- package/build/runtime-esm/server/utils/assert.js +91 -0
- package/build/runtime-esm/server/utils/createErrorWithCleanStackTrace.d.ts +2 -0
- package/build/runtime-esm/server/utils/createErrorWithCleanStackTrace.js +38 -0
- package/build/runtime-esm/server/utils/debug.d.ts +14 -0
- package/build/runtime-esm/server/utils/debug.js +87 -0
- package/build/runtime-esm/server/utils/getGlobalVariable.d.ts +4 -0
- package/build/runtime-esm/server/utils/getGlobalVariable.js +8 -0
- package/build/runtime-esm/server/utils/isBrowser.d.ts +2 -0
- package/build/runtime-esm/server/utils/isBrowser.js +6 -0
- package/build/runtime-esm/server/utils/isCallable.d.ts +2 -0
- package/build/runtime-esm/server/utils/isCallable.js +6 -0
- package/build/runtime-esm/server/utils/isClientSide.d.ts +2 -0
- package/build/runtime-esm/server/utils/isClientSide.js +6 -0
- package/build/runtime-esm/server/utils/isPromise.d.ts +1 -0
- package/build/runtime-esm/server/utils/isPromise.js +7 -0
- package/build/runtime-esm/server/utils/isServerSide.d.ts +2 -0
- package/build/runtime-esm/server/utils/isServerSide.js +7 -0
- package/build/runtime-esm/server/utils/objectAssign.d.ts +2 -0
- package/build/runtime-esm/server/utils/objectAssign.js +6 -0
- package/build/runtime-esm/server/utils/projectInfo.d.ts +10 -0
- package/build/runtime-esm/server/utils/projectInfo.js +13 -0
- package/build/runtime-esm/server/utils.d.ts +4 -0
- package/build/runtime-esm/server/utils.js +4 -0
- package/package.json +67 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createLRUCache } from "$houdini/runtime/lib/lru";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useClient } from "../routing";
|
|
4
|
+
import { useDocumentHandle } from "./useDocumentHandle";
|
|
5
|
+
import { useIsMountedRef } from "./useIsMounted";
|
|
6
|
+
const promiseCache = createLRUCache();
|
|
7
|
+
function useQueryHandle({ artifact }, variables = null, config = {}) {
|
|
8
|
+
const identifier = queryIdentifier({ artifact, variables, config });
|
|
9
|
+
const suspenseValue = promiseCache.get(identifier);
|
|
10
|
+
const client = useClient();
|
|
11
|
+
const isMountedRef = useIsMountedRef();
|
|
12
|
+
let [observer] = React.useState(
|
|
13
|
+
client.observe({
|
|
14
|
+
artifact,
|
|
15
|
+
initialValue: suspenseValue?.resolved?.data ?? {}
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
const suspenseTracker = React.useRef(false);
|
|
19
|
+
const box = React.useRef(observer.state);
|
|
20
|
+
const subscribe = React.useCallback(
|
|
21
|
+
(fn) => {
|
|
22
|
+
return observer.subscribe((val) => {
|
|
23
|
+
box.current = val;
|
|
24
|
+
if (isMountedRef.current && !suspenseTracker.current) {
|
|
25
|
+
fn();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
[observer]
|
|
30
|
+
);
|
|
31
|
+
const storeValue = React.useSyncExternalStore(subscribe, () => box.current);
|
|
32
|
+
const handle = useDocumentHandle({
|
|
33
|
+
artifact,
|
|
34
|
+
observer,
|
|
35
|
+
storeValue
|
|
36
|
+
});
|
|
37
|
+
React.useEffect(() => {
|
|
38
|
+
return () => {
|
|
39
|
+
promiseCache.delete(identifier);
|
|
40
|
+
};
|
|
41
|
+
}, [identifier]);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
return () => {
|
|
44
|
+
observer.cleanup();
|
|
45
|
+
};
|
|
46
|
+
}, [observer]);
|
|
47
|
+
let result = storeValue.data;
|
|
48
|
+
if (!suspenseValue) {
|
|
49
|
+
let resolve = () => {
|
|
50
|
+
};
|
|
51
|
+
const loadPromise = new Promise((r) => resolve = r);
|
|
52
|
+
const suspenseUnit = {
|
|
53
|
+
then: loadPromise.then.bind(loadPromise),
|
|
54
|
+
resolve,
|
|
55
|
+
variables
|
|
56
|
+
};
|
|
57
|
+
promiseCache.set(identifier, suspenseUnit);
|
|
58
|
+
handle.fetch({
|
|
59
|
+
variables,
|
|
60
|
+
stuff: {
|
|
61
|
+
silenceLoading: true
|
|
62
|
+
}
|
|
63
|
+
}).then((value) => {
|
|
64
|
+
suspenseUnit.resolved = {
|
|
65
|
+
...handle,
|
|
66
|
+
data: value.data,
|
|
67
|
+
partia: value.partial,
|
|
68
|
+
artifact
|
|
69
|
+
};
|
|
70
|
+
suspenseUnit.resolve();
|
|
71
|
+
});
|
|
72
|
+
suspenseTracker.current = true;
|
|
73
|
+
throw suspenseUnit;
|
|
74
|
+
}
|
|
75
|
+
if (!result && suspenseValue && !suspenseValue.resolved) {
|
|
76
|
+
suspenseTracker.current = true;
|
|
77
|
+
throw suspenseValue;
|
|
78
|
+
}
|
|
79
|
+
if (!result && suspenseValue?.resolved) {
|
|
80
|
+
return suspenseValue.resolved;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
...handle,
|
|
84
|
+
variables: storeValue.variables,
|
|
85
|
+
data: result
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function queryIdentifier(args) {
|
|
89
|
+
args.fetchKey ??= 0;
|
|
90
|
+
const { artifact, variables, fetchKey } = args;
|
|
91
|
+
return [artifact.name, JSON.stringify(variables), fetchKey].join("@@");
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
useQueryHandle
|
|
95
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SubscriptionArtifact, GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
2
|
+
export declare function useSubscription<_Result extends GraphQLObject, _Input extends GraphQLVariables>(document: {
|
|
3
|
+
artifact: SubscriptionArtifact;
|
|
4
|
+
}, variables: _Input): import("houdini").GraphQLObject | null;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SubscriptionArtifact, GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
2
|
+
export type SubscriptionHandle<_Result extends GraphQLObject, _Input extends GraphQLVariables> = {
|
|
3
|
+
data: _Result | null;
|
|
4
|
+
errors: {
|
|
5
|
+
message: string;
|
|
6
|
+
}[] | null;
|
|
7
|
+
variables: _Input;
|
|
8
|
+
listen: (args: {
|
|
9
|
+
variables?: _Input;
|
|
10
|
+
}) => void;
|
|
11
|
+
unlisten: () => void;
|
|
12
|
+
fetching: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function useSubscriptionHandle<_Result extends GraphQLObject, _Input extends GraphQLVariables>({ artifact }: {
|
|
15
|
+
artifact: SubscriptionArtifact;
|
|
16
|
+
}, variables: _Input): {
|
|
17
|
+
data: import("houdini").GraphQLObject | null;
|
|
18
|
+
errors: {
|
|
19
|
+
message: string;
|
|
20
|
+
}[] | null;
|
|
21
|
+
fetching: boolean;
|
|
22
|
+
variables: _Input;
|
|
23
|
+
unlisten: () => Promise<void>;
|
|
24
|
+
listen: ({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: import("$houdini/lib").SendParams) => Promise<import("$houdini/runtime/lib/types").QueryResult<import("houdini").GraphQLObject, _Input>>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useDocumentSubscription } from "./useDocumentSubscription";
|
|
2
|
+
function useSubscriptionHandle({ artifact }, variables) {
|
|
3
|
+
const [storeValue, observer] = useDocumentSubscription({
|
|
4
|
+
artifact,
|
|
5
|
+
variables
|
|
6
|
+
});
|
|
7
|
+
return {
|
|
8
|
+
data: storeValue.data,
|
|
9
|
+
errors: storeValue.errors,
|
|
10
|
+
fetching: storeValue.fetching,
|
|
11
|
+
variables,
|
|
12
|
+
unlisten: observer.cleanup,
|
|
13
|
+
listen: observer.send
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
useSubscriptionHandle
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
|
+
import { RouterCache } from './routing';
|
|
3
|
+
export * from './hooks';
|
|
4
|
+
export { router_cache } from './routing';
|
|
5
|
+
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, session, assetPrefix, injectToStream, }: {
|
|
6
|
+
initialURL: string;
|
|
7
|
+
cache: Cache;
|
|
8
|
+
session?: App.Session;
|
|
9
|
+
assetPrefix: string;
|
|
10
|
+
injectToStream?: (chunk: string) => void;
|
|
11
|
+
} & RouterCache): JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import client from "./client";
|
|
3
|
+
import manifest from "./manifest";
|
|
4
|
+
import { Router as RouterImpl, RouterContextProvider } from "./routing";
|
|
5
|
+
export * from "./hooks";
|
|
6
|
+
import { router_cache } from "./routing";
|
|
7
|
+
function Router({
|
|
8
|
+
cache,
|
|
9
|
+
initialURL,
|
|
10
|
+
artifact_cache,
|
|
11
|
+
component_cache,
|
|
12
|
+
data_cache,
|
|
13
|
+
pending_cache,
|
|
14
|
+
last_variables,
|
|
15
|
+
session,
|
|
16
|
+
assetPrefix,
|
|
17
|
+
injectToStream
|
|
18
|
+
}) {
|
|
19
|
+
return /* @__PURE__ */ jsx(
|
|
20
|
+
RouterContextProvider,
|
|
21
|
+
{
|
|
22
|
+
client: client(),
|
|
23
|
+
cache,
|
|
24
|
+
artifact_cache,
|
|
25
|
+
component_cache,
|
|
26
|
+
data_cache,
|
|
27
|
+
pending_cache,
|
|
28
|
+
last_variables,
|
|
29
|
+
session,
|
|
30
|
+
children: /* @__PURE__ */ jsx(
|
|
31
|
+
RouterImpl,
|
|
32
|
+
{
|
|
33
|
+
initialURL,
|
|
34
|
+
manifest,
|
|
35
|
+
assetPrefix,
|
|
36
|
+
injectToStream
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
Router,
|
|
44
|
+
router_cache
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
|
+
import { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
|
|
3
|
+
import { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
5
|
+
import { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
6
|
+
import type { RouterManifest } from '$houdini/runtime/router/types';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { SuspenseCache } from './cache';
|
|
9
|
+
type ComponentType = any;
|
|
10
|
+
/**
|
|
11
|
+
* Router is the top level entry point for the filesystem-based router.
|
|
12
|
+
* It is responsible for loading various page sources (including API fetches) and
|
|
13
|
+
* then rendering when appropriate.
|
|
14
|
+
*/
|
|
15
|
+
export declare function Router({ manifest, initialURL, assetPrefix, injectToStream, }: {
|
|
16
|
+
manifest: RouterManifest<ComponentType>;
|
|
17
|
+
initialURL?: string;
|
|
18
|
+
assetPrefix: string;
|
|
19
|
+
injectToStream?: undefined | ((chunk: string) => void);
|
|
20
|
+
}): JSX.Element;
|
|
21
|
+
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, session: ssrSession, }: {
|
|
22
|
+
children: React.ReactElement;
|
|
23
|
+
client: HoudiniClient;
|
|
24
|
+
cache: Cache;
|
|
25
|
+
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
26
|
+
component_cache: SuspenseCache<(props: any) => React.ReactElement>;
|
|
27
|
+
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
28
|
+
pending_cache: PendingCache;
|
|
29
|
+
last_variables: LRUCache<GraphQLVariables>;
|
|
30
|
+
session?: App.Session;
|
|
31
|
+
}): JSX.Element;
|
|
32
|
+
type RouterContext = {
|
|
33
|
+
client: HoudiniClient;
|
|
34
|
+
cache: Cache;
|
|
35
|
+
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
36
|
+
component_cache: SuspenseCache<(props: any) => React.ReactElement>;
|
|
37
|
+
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
38
|
+
pending_cache: PendingCache;
|
|
39
|
+
last_variables: LRUCache<GraphQLVariables>;
|
|
40
|
+
session: App.Session;
|
|
41
|
+
};
|
|
42
|
+
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
43
|
+
resolve: () => void;
|
|
44
|
+
reject: () => void;
|
|
45
|
+
}>;
|
|
46
|
+
export declare const useRouterContext: () => RouterContext;
|
|
47
|
+
export declare function useClient(): HoudiniClient;
|
|
48
|
+
export declare function useCache(): Cache;
|
|
49
|
+
export declare function updateLocalSession(session: App.Session): void;
|
|
50
|
+
export declare function useSession(): App.Session;
|
|
51
|
+
export declare function useCurrentVariables(): GraphQLVariables;
|
|
52
|
+
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
|
|
53
|
+
export type RouterCache = {
|
|
54
|
+
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
55
|
+
component_cache: SuspenseCache<(props: any) => React.ReactElement>;
|
|
56
|
+
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
57
|
+
last_variables: LRUCache<GraphQLVariables>;
|
|
58
|
+
pending_cache: PendingCache;
|
|
59
|
+
};
|
|
60
|
+
export declare function router_cache({ pending_queries, artifacts, components, initialData, initialArtifacts, }?: {
|
|
61
|
+
pending_queries?: string[];
|
|
62
|
+
artifacts?: Record<string, QueryArtifact>;
|
|
63
|
+
components?: Record<string, (props: any) => React.ReactElement>;
|
|
64
|
+
initialData?: Record<string, DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
65
|
+
initialArtifacts?: Record<string, QueryArtifact>;
|
|
66
|
+
}): RouterCache;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { deepEquals } from "$houdini/runtime/lib/deepEquals";
|
|
3
|
+
import { find_match } from "$houdini/runtime/router/match";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { useDocumentStore } from "../hooks/useDocumentStore";
|
|
6
|
+
import { suspense_cache } from "./cache";
|
|
7
|
+
const PreloadWhich = {
|
|
8
|
+
component: "component",
|
|
9
|
+
data: "data",
|
|
10
|
+
page: "page"
|
|
11
|
+
};
|
|
12
|
+
function Router({
|
|
13
|
+
manifest,
|
|
14
|
+
initialURL,
|
|
15
|
+
assetPrefix,
|
|
16
|
+
injectToStream
|
|
17
|
+
}) {
|
|
18
|
+
const [current, setCurrent] = React.useState(() => {
|
|
19
|
+
return initialURL || window.location.pathname;
|
|
20
|
+
});
|
|
21
|
+
const [page, variables] = find_match(manifest, current);
|
|
22
|
+
const { loadData, loadComponent } = usePageData({
|
|
23
|
+
page,
|
|
24
|
+
variables,
|
|
25
|
+
assetPrefix,
|
|
26
|
+
injectToStream
|
|
27
|
+
});
|
|
28
|
+
const { component_cache } = useRouterContext();
|
|
29
|
+
const PageComponent = component_cache.get(page.id);
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
if (globalThis.window && window.location.pathname !== current) {
|
|
32
|
+
window.history.pushState({}, "", current);
|
|
33
|
+
}
|
|
34
|
+
}, [current]);
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
if (!globalThis.window) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const onChange = (evt) => {
|
|
40
|
+
setCurrent(window.location.pathname);
|
|
41
|
+
};
|
|
42
|
+
window.addEventListener("popstate", onChange);
|
|
43
|
+
return () => {
|
|
44
|
+
window.removeEventListener("popstate", onChange);
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
useLinkBehavior({
|
|
48
|
+
goto: setCurrent,
|
|
49
|
+
preload(url, which) {
|
|
50
|
+
const [page2, variables2] = find_match(manifest, url);
|
|
51
|
+
if (["both", "component"].includes(which)) {
|
|
52
|
+
loadComponent(page2);
|
|
53
|
+
}
|
|
54
|
+
if (["both", "data"].includes(which)) {
|
|
55
|
+
loadData(page2, variables2);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(PageComponent, { url: current }) });
|
|
60
|
+
}
|
|
61
|
+
function usePageData({
|
|
62
|
+
page,
|
|
63
|
+
variables,
|
|
64
|
+
assetPrefix,
|
|
65
|
+
injectToStream
|
|
66
|
+
}) {
|
|
67
|
+
const {
|
|
68
|
+
client,
|
|
69
|
+
cache,
|
|
70
|
+
data_cache,
|
|
71
|
+
component_cache,
|
|
72
|
+
artifact_cache,
|
|
73
|
+
pending_cache,
|
|
74
|
+
last_variables
|
|
75
|
+
} = useRouterContext();
|
|
76
|
+
const session = useSession();
|
|
77
|
+
function load_query({ id, artifact }) {
|
|
78
|
+
last_variables.set(page.id, variables);
|
|
79
|
+
if (pending_cache.has(id)) {
|
|
80
|
+
return pending_cache.get(id);
|
|
81
|
+
}
|
|
82
|
+
const observer = client.observe({ artifact, cache });
|
|
83
|
+
let resolve = () => {
|
|
84
|
+
};
|
|
85
|
+
let reject = () => {
|
|
86
|
+
};
|
|
87
|
+
const promise = new Promise((res, rej) => {
|
|
88
|
+
resolve = res;
|
|
89
|
+
reject = rej;
|
|
90
|
+
observer.send({
|
|
91
|
+
variables,
|
|
92
|
+
cacheParams: { disableSubscriptions: true },
|
|
93
|
+
session
|
|
94
|
+
}).then(() => {
|
|
95
|
+
data_cache.set(id, observer);
|
|
96
|
+
injectToStream?.(`
|
|
97
|
+
<script>
|
|
98
|
+
window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
|
|
99
|
+
|
|
100
|
+
const artifactName = "${artifact.name}"
|
|
101
|
+
const value = ${JSON.stringify(observer.state.data)}
|
|
102
|
+
|
|
103
|
+
// if the data is pending, we need to resolve it
|
|
104
|
+
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
|
|
105
|
+
// before we resolve the pending signals,
|
|
106
|
+
// fill the data cache with values we got on the server
|
|
107
|
+
const new_store = window.__houdini__client__.observe({
|
|
108
|
+
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
|
|
109
|
+
cache: window.__houdini__cache__,
|
|
110
|
+
initialValue: value
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
// if there are no data caches available we need to populate the pending one instead
|
|
118
|
+
if (!window.__houdini__nav_caches__) {
|
|
119
|
+
if (!window.__houdini__pending_data__) {
|
|
120
|
+
window.__houdini__pending_data__ = {}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!window.__houdini__pending_artifacts__) {
|
|
124
|
+
window.__houdini__pending_artifacts__ = {}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
window.__houdini__pending_data__[artifactName] = value
|
|
128
|
+
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (window.__houdini__nav_caches__?.pending_cache.has(artifactName)) {
|
|
132
|
+
// we're pushing this store onto the client, it should be initialized
|
|
133
|
+
new_store.send({
|
|
134
|
+
setup: true,
|
|
135
|
+
variables: ${JSON.stringify(variables)}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
// notify anyone waiting on the pending cache
|
|
139
|
+
window.__houdini__nav_caches__.pending_cache.get(artifactName).resolve()
|
|
140
|
+
window.__houdini__nav_caches__.pending_cache.delete(artifactName)
|
|
141
|
+
}
|
|
142
|
+
<\/script>
|
|
143
|
+
`);
|
|
144
|
+
resolve();
|
|
145
|
+
}).catch(reject).finally(() => {
|
|
146
|
+
pending_cache.delete(id);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
pending_cache.set(id, { ...promise, resolve, reject });
|
|
150
|
+
return pending_cache.get(id);
|
|
151
|
+
}
|
|
152
|
+
function loadData(targetPage, variables2) {
|
|
153
|
+
if (last_variables.has(targetPage.id) && !deepEquals(last_variables.get(targetPage.id), variables2)) {
|
|
154
|
+
data_cache.clear();
|
|
155
|
+
}
|
|
156
|
+
const missing_artifacts = [];
|
|
157
|
+
const found_artifacts = {};
|
|
158
|
+
for (const key of Object.keys(targetPage.documents)) {
|
|
159
|
+
if (artifact_cache.has(key)) {
|
|
160
|
+
found_artifacts[key] = artifact_cache.get(key);
|
|
161
|
+
} else {
|
|
162
|
+
missing_artifacts.push(key);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
for (const artifact_id of missing_artifacts) {
|
|
166
|
+
targetPage.documents[artifact_id].artifact().then((mod) => {
|
|
167
|
+
const artifact = mod.default;
|
|
168
|
+
artifact_cache.set(artifact_id, artifact);
|
|
169
|
+
injectToStream?.(`
|
|
170
|
+
<script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
|
|
171
|
+
`);
|
|
172
|
+
load_query({ id: artifact.name, artifact });
|
|
173
|
+
}).catch((err) => {
|
|
174
|
+
console.log(err);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
for (const artifact of Object.values(found_artifacts)) {
|
|
178
|
+
if (!data_cache.has(artifact.name)) {
|
|
179
|
+
load_query({ id: artifact.name, artifact });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async function loadComponent(targetPage) {
|
|
184
|
+
if (component_cache.has(targetPage.id)) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const mod = await targetPage.component();
|
|
188
|
+
component_cache.set(targetPage.id, mod.default);
|
|
189
|
+
}
|
|
190
|
+
loadData(page, variables);
|
|
191
|
+
if (!component_cache.has(page.id)) {
|
|
192
|
+
throw loadComponent(page);
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
loadData,
|
|
196
|
+
loadComponent
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function RouterContextProvider({
|
|
200
|
+
children,
|
|
201
|
+
client,
|
|
202
|
+
cache,
|
|
203
|
+
artifact_cache,
|
|
204
|
+
component_cache,
|
|
205
|
+
data_cache,
|
|
206
|
+
pending_cache,
|
|
207
|
+
last_variables,
|
|
208
|
+
session: ssrSession = {}
|
|
209
|
+
}) {
|
|
210
|
+
const [session, setSession] = React.useState(ssrSession);
|
|
211
|
+
const handleNewSession = React.useCallback((event) => {
|
|
212
|
+
setSession(event.detail);
|
|
213
|
+
}, []);
|
|
214
|
+
React.useEffect(() => {
|
|
215
|
+
window.addEventListener("_houdini_session_", handleNewSession);
|
|
216
|
+
return () => {
|
|
217
|
+
window.removeEventListener("_houdini_session_", handleNewSession);
|
|
218
|
+
};
|
|
219
|
+
}, []);
|
|
220
|
+
return /* @__PURE__ */ jsx(
|
|
221
|
+
Context.Provider,
|
|
222
|
+
{
|
|
223
|
+
value: {
|
|
224
|
+
client,
|
|
225
|
+
cache,
|
|
226
|
+
artifact_cache,
|
|
227
|
+
component_cache,
|
|
228
|
+
data_cache,
|
|
229
|
+
pending_cache,
|
|
230
|
+
last_variables,
|
|
231
|
+
session
|
|
232
|
+
},
|
|
233
|
+
children
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
const Context = React.createContext(null);
|
|
238
|
+
const useRouterContext = () => {
|
|
239
|
+
const ctx = React.useContext(Context);
|
|
240
|
+
if (!ctx) {
|
|
241
|
+
console.log(ctx);
|
|
242
|
+
throw new Error("Could not find router context");
|
|
243
|
+
}
|
|
244
|
+
return ctx;
|
|
245
|
+
};
|
|
246
|
+
function useClient() {
|
|
247
|
+
return useRouterContext().client;
|
|
248
|
+
}
|
|
249
|
+
function useCache() {
|
|
250
|
+
return useRouterContext().cache;
|
|
251
|
+
}
|
|
252
|
+
function updateLocalSession(session) {
|
|
253
|
+
window.dispatchEvent(
|
|
254
|
+
new CustomEvent("_houdini_session_", {
|
|
255
|
+
bubbles: true,
|
|
256
|
+
detail: session
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
function useSession() {
|
|
261
|
+
return useRouterContext().session;
|
|
262
|
+
}
|
|
263
|
+
function useCurrentVariables() {
|
|
264
|
+
return React.useContext(VariableContext);
|
|
265
|
+
}
|
|
266
|
+
const VariableContext = React.createContext(null);
|
|
267
|
+
function useQueryResult(name) {
|
|
268
|
+
const store_ref = useRouterContext().data_cache.get(name);
|
|
269
|
+
const [{ data }, observer] = useDocumentStore({
|
|
270
|
+
artifact: store_ref.artifact,
|
|
271
|
+
observer: store_ref
|
|
272
|
+
});
|
|
273
|
+
return [data, observer];
|
|
274
|
+
}
|
|
275
|
+
function useLinkBehavior({
|
|
276
|
+
goto,
|
|
277
|
+
preload
|
|
278
|
+
}) {
|
|
279
|
+
useLinkNavigation({ goto });
|
|
280
|
+
if (!globalThis.navigator?.connection?.saveData) {
|
|
281
|
+
usePreload({ preload });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function useLinkNavigation({ goto }) {
|
|
285
|
+
const [pending, startTransition] = React.useTransition();
|
|
286
|
+
React.useEffect(() => {
|
|
287
|
+
const onClick = (e) => {
|
|
288
|
+
const link = e.target?.closest("a");
|
|
289
|
+
if (link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.defaultPrevented) {
|
|
290
|
+
const target = link.attributes.getNamedItem("href")?.value;
|
|
291
|
+
if (!target || !target.startsWith("/")) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
e.preventDefault();
|
|
295
|
+
startTransition(() => {
|
|
296
|
+
goto(target);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
document.addEventListener("click", onClick);
|
|
301
|
+
return () => {
|
|
302
|
+
document.removeEventListener("click", onClick);
|
|
303
|
+
};
|
|
304
|
+
}, []);
|
|
305
|
+
}
|
|
306
|
+
function usePreload({ preload }) {
|
|
307
|
+
const timeoutRef = React.useRef(null);
|
|
308
|
+
React.useEffect(() => {
|
|
309
|
+
const mouseMove = (e) => {
|
|
310
|
+
const target = e.target;
|
|
311
|
+
if (!(target instanceof HTMLAnchorElement)) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
let preloadWhichRaw = target.attributes.getNamedItem("data-houdini-preload")?.value;
|
|
315
|
+
let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
|
|
316
|
+
if (!PreloadWhich[preloadWhich]) {
|
|
317
|
+
console.log(
|
|
318
|
+
`invalid preload value "${preloadWhich}" must be "${PreloadWhich.component}", "${PreloadWhich.data}", or "${PreloadWhich.page}"`
|
|
319
|
+
);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (timeoutRef.current) {
|
|
323
|
+
clearTimeout(timeoutRef.current);
|
|
324
|
+
}
|
|
325
|
+
timeoutRef.current = setTimeout(() => {
|
|
326
|
+
const url = target.attributes.getNamedItem("href")?.value;
|
|
327
|
+
if (!url) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
preload(url, preloadWhich);
|
|
331
|
+
}, 20);
|
|
332
|
+
};
|
|
333
|
+
document.addEventListener("mousemove", mouseMove);
|
|
334
|
+
return () => {
|
|
335
|
+
document.removeEventListener("mousemove", mouseMove);
|
|
336
|
+
};
|
|
337
|
+
}, []);
|
|
338
|
+
}
|
|
339
|
+
function router_cache({
|
|
340
|
+
pending_queries = [],
|
|
341
|
+
artifacts = {},
|
|
342
|
+
components = {},
|
|
343
|
+
initialData = {},
|
|
344
|
+
initialArtifacts = {}
|
|
345
|
+
} = {}) {
|
|
346
|
+
const result = {
|
|
347
|
+
artifact_cache: suspense_cache(initialArtifacts),
|
|
348
|
+
component_cache: suspense_cache(),
|
|
349
|
+
data_cache: suspense_cache(initialData),
|
|
350
|
+
pending_cache: suspense_cache(),
|
|
351
|
+
last_variables: suspense_cache()
|
|
352
|
+
};
|
|
353
|
+
for (const query of pending_queries) {
|
|
354
|
+
result.pending_cache.set(query, signal_promise());
|
|
355
|
+
}
|
|
356
|
+
for (const [name, artifact] of Object.entries(artifacts)) {
|
|
357
|
+
result.artifact_cache.set(name, artifact);
|
|
358
|
+
}
|
|
359
|
+
for (const [name, component] of Object.entries(components)) {
|
|
360
|
+
result.component_cache.set(name, component);
|
|
361
|
+
}
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
function signal_promise() {
|
|
365
|
+
let resolve = () => {
|
|
366
|
+
};
|
|
367
|
+
let reject = () => {
|
|
368
|
+
};
|
|
369
|
+
const promise = new Promise((res, rej) => {
|
|
370
|
+
resolve = res;
|
|
371
|
+
reject = rej;
|
|
372
|
+
});
|
|
373
|
+
return {
|
|
374
|
+
...promise,
|
|
375
|
+
resolve,
|
|
376
|
+
reject
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
export {
|
|
380
|
+
Router,
|
|
381
|
+
RouterContextProvider,
|
|
382
|
+
router_cache,
|
|
383
|
+
updateLocalSession,
|
|
384
|
+
useCache,
|
|
385
|
+
useClient,
|
|
386
|
+
useCurrentVariables,
|
|
387
|
+
useQueryResult,
|
|
388
|
+
useRouterContext,
|
|
389
|
+
useSession
|
|
390
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LRUCache } from '$houdini/runtime/lib/lru';
|
|
2
|
+
export declare function suspense_cache<T>(initialData?: Record<string, T>): SuspenseCache<T>;
|
|
3
|
+
export declare class SuspenseCache<_Data> extends LRUCache<_Data> {
|
|
4
|
+
#private;
|
|
5
|
+
get(key: string): _Data;
|
|
6
|
+
set(key: string, value: _Data): void;
|
|
7
|
+
}
|