houdini-react 1.2.43 → 1.2.45
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/build/plugin-cjs/index.js +884 -883
- package/build/plugin-esm/index.js +884 -883
- package/build/runtime/hooks/useDocumentStore.d.ts +1 -2
- package/build/runtime/hooks/useDocumentSubscription.d.ts +3 -7
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/routing/Router.d.ts +16 -1
- package/build/runtime-cjs/hooks/useDocumentHandle.js +1 -1
- package/build/runtime-cjs/hooks/useDocumentStore.d.ts +1 -2
- package/build/runtime-cjs/hooks/useDocumentStore.js +5 -1
- package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +3 -7
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +3 -4
- package/build/runtime-cjs/hooks/useMutation.js +1 -1
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/index.js +8 -2
- package/build/runtime-cjs/routing/Router.d.ts +16 -1
- package/build/runtime-cjs/routing/Router.js +85 -13
- package/build/runtime-esm/hooks/useDocumentHandle.js +1 -1
- package/build/runtime-esm/hooks/useDocumentStore.d.ts +1 -2
- package/build/runtime-esm/hooks/useDocumentStore.js +5 -1
- package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +3 -7
- package/build/runtime-esm/hooks/useDocumentSubscription.js +3 -4
- package/build/runtime-esm/hooks/useMutation.js +1 -1
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/index.js +5 -2
- package/build/runtime-esm/routing/Router.d.ts +16 -1
- package/build/runtime-esm/routing/Router.js +82 -13
- package/package.json +2 -2
|
@@ -7,6 +7,5 @@ export type UseDocumentStoreParams<_Artifact extends DocumentArtifact, _Data ext
|
|
|
7
7
|
} & Partial<ObserveParams<_Data, DocumentArtifact, _Input>>;
|
|
8
8
|
export declare function useDocumentStore<_Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables, _Artifact extends DocumentArtifact = DocumentArtifact>({ artifact, observer: obs, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data, _Input>): [
|
|
9
9
|
QueryResult<_Data, _Input>,
|
|
10
|
-
DocumentStore<_Data, _Input
|
|
11
|
-
(store: DocumentStore<_Data, _Input>) => void
|
|
10
|
+
DocumentStore<_Data, _Input>
|
|
12
11
|
];
|
|
@@ -6,10 +6,6 @@ export declare function useDocumentSubscription<_Artifact extends DocumentArtifa
|
|
|
6
6
|
variables: _Input;
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
send?: Partial<SendParams>;
|
|
9
|
-
}): [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
DocumentStore<_Data, _Input>,
|
|
14
|
-
(store: DocumentStore<_Data, _Input>) => void
|
|
15
|
-
];
|
|
9
|
+
}): [QueryResult<_Data, _Input> & {
|
|
10
|
+
parent?: string | null;
|
|
11
|
+
}, DocumentStore<_Data, _Input>];
|
package/build/runtime/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -18,6 +18,10 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
18
18
|
assetPrefix: string;
|
|
19
19
|
injectToStream?: undefined | ((chunk: string) => void);
|
|
20
20
|
}): JSX.Element;
|
|
21
|
+
export declare const useLocation: () => {
|
|
22
|
+
pathname: string;
|
|
23
|
+
params: Record<string, any>;
|
|
24
|
+
};
|
|
21
25
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
22
26
|
children: React.ReactElement;
|
|
23
27
|
client: HoudiniClient;
|
|
@@ -38,6 +42,7 @@ type RouterContext = {
|
|
|
38
42
|
ssr_signals: PendingCache;
|
|
39
43
|
last_variables: LRUCache<GraphQLVariables>;
|
|
40
44
|
session: App.Session;
|
|
45
|
+
setSession: (newSession: Partial<App.Session>) => void;
|
|
41
46
|
};
|
|
42
47
|
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
43
48
|
resolve: () => void;
|
|
@@ -47,7 +52,7 @@ export declare const useRouterContext: () => RouterContext;
|
|
|
47
52
|
export declare function useClient(): HoudiniClient;
|
|
48
53
|
export declare function useCache(): Cache;
|
|
49
54
|
export declare function updateLocalSession(session: App.Session): void;
|
|
50
|
-
export declare function useSession(): App.Session;
|
|
55
|
+
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
51
56
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
52
57
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
|
|
53
58
|
export type RouterCache = {
|
|
@@ -65,4 +70,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
65
70
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
66
71
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
67
72
|
}): RouterCache;
|
|
73
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
74
|
+
keys: string[];
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}): JSX.Element;
|
|
77
|
+
export declare function useRoute<PageProps extends {
|
|
78
|
+
Params: {};
|
|
79
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
80
|
+
export type RouteProp<Params> = {
|
|
81
|
+
params: Params;
|
|
82
|
+
};
|
|
68
83
|
export {};
|
|
@@ -39,7 +39,7 @@ function useDocumentHandle({
|
|
|
39
39
|
}) {
|
|
40
40
|
const [forwardPending, setForwardPending] = import_react.default.useState(false);
|
|
41
41
|
const [backwardPending, setBackwardPending] = import_react.default.useState(false);
|
|
42
|
-
const session = (0, import_Router.useSession)();
|
|
42
|
+
const [session] = (0, import_Router.useSession)();
|
|
43
43
|
return import_react.default.useMemo(() => {
|
|
44
44
|
const wrapLoad = (setLoading, fn) => {
|
|
45
45
|
return async (value) => {
|
|
@@ -7,6 +7,5 @@ export type UseDocumentStoreParams<_Artifact extends DocumentArtifact, _Data ext
|
|
|
7
7
|
} & Partial<ObserveParams<_Data, DocumentArtifact, _Input>>;
|
|
8
8
|
export declare function useDocumentStore<_Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables, _Artifact extends DocumentArtifact = DocumentArtifact>({ artifact, observer: obs, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data, _Input>): [
|
|
9
9
|
QueryResult<_Data, _Input>,
|
|
10
|
-
DocumentStore<_Data, _Input
|
|
11
|
-
(store: DocumentStore<_Data, _Input>) => void
|
|
10
|
+
DocumentStore<_Data, _Input>
|
|
12
11
|
];
|
|
@@ -44,6 +44,10 @@ function useDocumentStore({
|
|
|
44
44
|
})
|
|
45
45
|
);
|
|
46
46
|
const box = React.useRef(observer.state);
|
|
47
|
+
if (obs && obs !== observer) {
|
|
48
|
+
box.current = obs.state;
|
|
49
|
+
setObserver(obs);
|
|
50
|
+
}
|
|
47
51
|
const subscribe = React.useCallback(
|
|
48
52
|
(fn) => {
|
|
49
53
|
return observer.subscribe((val) => {
|
|
@@ -60,7 +64,7 @@ function useDocumentStore({
|
|
|
60
64
|
() => box.current,
|
|
61
65
|
() => box.current
|
|
62
66
|
);
|
|
63
|
-
return [storeValue, observer
|
|
67
|
+
return [storeValue, observer];
|
|
64
68
|
}
|
|
65
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
70
|
0 && (module.exports = {
|
|
@@ -6,10 +6,6 @@ export declare function useDocumentSubscription<_Artifact extends DocumentArtifa
|
|
|
6
6
|
variables: _Input;
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
send?: Partial<SendParams>;
|
|
9
|
-
}): [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
DocumentStore<_Data, _Input>,
|
|
14
|
-
(store: DocumentStore<_Data, _Input>) => void
|
|
15
|
-
];
|
|
9
|
+
}): [QueryResult<_Data, _Input> & {
|
|
10
|
+
parent?: string | null;
|
|
11
|
+
}, DocumentStore<_Data, _Input>];
|
|
@@ -37,11 +37,11 @@ function useDocumentSubscription({
|
|
|
37
37
|
disabled,
|
|
38
38
|
...observeParams
|
|
39
39
|
}) {
|
|
40
|
-
const [storeValue, observer
|
|
40
|
+
const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({
|
|
41
41
|
artifact,
|
|
42
42
|
...observeParams
|
|
43
43
|
});
|
|
44
|
-
const session = (0, import_Router.useSession)();
|
|
44
|
+
const [session] = (0, import_Router.useSession)();
|
|
45
45
|
(0, import_useDeepCompareEffect.default)(() => {
|
|
46
46
|
if (!disabled) {
|
|
47
47
|
observer.send({
|
|
@@ -62,8 +62,7 @@ function useDocumentSubscription({
|
|
|
62
62
|
parent: send?.stuff?.parentID,
|
|
63
63
|
...storeValue
|
|
64
64
|
},
|
|
65
|
-
observer
|
|
66
|
-
setObserver
|
|
65
|
+
observer
|
|
67
66
|
];
|
|
68
67
|
}
|
|
69
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -28,7 +28,7 @@ function useMutation({
|
|
|
28
28
|
}) {
|
|
29
29
|
const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({ artifact });
|
|
30
30
|
const pending = storeValue.fetching;
|
|
31
|
-
const session = (0, import_Router.useSession)();
|
|
31
|
+
const [session] = (0, import_Router.useSession)();
|
|
32
32
|
const mutate = ({
|
|
33
33
|
metadata,
|
|
34
34
|
fetch,
|
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -26,7 +26,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
26
26
|
var runtime_exports = {};
|
|
27
27
|
__export(runtime_exports, {
|
|
28
28
|
Router: () => Router,
|
|
29
|
-
router_cache: () => import_routing2.router_cache
|
|
29
|
+
router_cache: () => import_routing2.router_cache,
|
|
30
|
+
useLocation: () => import_routing2.useLocation,
|
|
31
|
+
useRoute: () => import_routing2.useRoute,
|
|
32
|
+
useSession: () => import_routing2.useSession
|
|
30
33
|
});
|
|
31
34
|
module.exports = __toCommonJS(runtime_exports);
|
|
32
35
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -73,5 +76,8 @@ function Router({
|
|
|
73
76
|
// Annotate the CommonJS export names for ESM import in node:
|
|
74
77
|
0 && (module.exports = {
|
|
75
78
|
Router,
|
|
76
|
-
router_cache
|
|
79
|
+
router_cache,
|
|
80
|
+
useLocation,
|
|
81
|
+
useRoute,
|
|
82
|
+
useSession
|
|
77
83
|
});
|
|
@@ -18,6 +18,10 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
18
18
|
assetPrefix: string;
|
|
19
19
|
injectToStream?: undefined | ((chunk: string) => void);
|
|
20
20
|
}): JSX.Element;
|
|
21
|
+
export declare const useLocation: () => {
|
|
22
|
+
pathname: string;
|
|
23
|
+
params: Record<string, any>;
|
|
24
|
+
};
|
|
21
25
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
22
26
|
children: React.ReactElement;
|
|
23
27
|
client: HoudiniClient;
|
|
@@ -38,6 +42,7 @@ type RouterContext = {
|
|
|
38
42
|
ssr_signals: PendingCache;
|
|
39
43
|
last_variables: LRUCache<GraphQLVariables>;
|
|
40
44
|
session: App.Session;
|
|
45
|
+
setSession: (newSession: Partial<App.Session>) => void;
|
|
41
46
|
};
|
|
42
47
|
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
43
48
|
resolve: () => void;
|
|
@@ -47,7 +52,7 @@ export declare const useRouterContext: () => RouterContext;
|
|
|
47
52
|
export declare function useClient(): HoudiniClient;
|
|
48
53
|
export declare function useCache(): Cache;
|
|
49
54
|
export declare function updateLocalSession(session: App.Session): void;
|
|
50
|
-
export declare function useSession(): App.Session;
|
|
55
|
+
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
51
56
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
52
57
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
|
|
53
58
|
export type RouterCache = {
|
|
@@ -65,4 +70,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
65
70
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
66
71
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
67
72
|
}): RouterCache;
|
|
73
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
74
|
+
keys: string[];
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}): JSX.Element;
|
|
77
|
+
export declare function useRoute<PageProps extends {
|
|
78
|
+
Params: {};
|
|
79
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
80
|
+
export type RouteProp<Params> = {
|
|
81
|
+
params: Params;
|
|
82
|
+
};
|
|
68
83
|
export {};
|
|
@@ -24,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var Router_exports = {};
|
|
26
26
|
__export(Router_exports, {
|
|
27
|
+
PageContextProvider: () => PageContextProvider,
|
|
27
28
|
Router: () => Router,
|
|
28
29
|
RouterContextProvider: () => RouterContextProvider,
|
|
29
30
|
router_cache: () => router_cache,
|
|
@@ -31,15 +32,20 @@ __export(Router_exports, {
|
|
|
31
32
|
useCache: () => useCache,
|
|
32
33
|
useClient: () => useClient,
|
|
33
34
|
useCurrentVariables: () => useCurrentVariables,
|
|
35
|
+
useLocation: () => useLocation,
|
|
34
36
|
useQueryResult: () => useQueryResult,
|
|
37
|
+
useRoute: () => useRoute,
|
|
35
38
|
useRouterContext: () => useRouterContext,
|
|
36
39
|
useSession: () => useSession
|
|
37
40
|
});
|
|
38
41
|
module.exports = __toCommonJS(Router_exports);
|
|
39
42
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
+
var import_config = __toESM(require("$houdini/runtime/imports/config"));
|
|
40
44
|
var import_deepEquals = require("$houdini/runtime/lib/deepEquals");
|
|
45
|
+
var import_scalars = require("$houdini/runtime/lib/scalars");
|
|
41
46
|
var import_match = require("$houdini/runtime/router/match");
|
|
42
47
|
var import_react = __toESM(require("react"));
|
|
48
|
+
var import_react2 = require("react");
|
|
43
49
|
var import_useDocumentStore = require("../hooks/useDocumentStore");
|
|
44
50
|
var import_cache = require("./cache");
|
|
45
51
|
const PreloadWhich = {
|
|
@@ -57,6 +63,9 @@ function Router({
|
|
|
57
63
|
return initialURL || window.location.pathname;
|
|
58
64
|
});
|
|
59
65
|
const [page, variables] = (0, import_match.find_match)(manifest, currentURL);
|
|
66
|
+
if (!page) {
|
|
67
|
+
throw new Error("404");
|
|
68
|
+
}
|
|
60
69
|
const { loadData, loadComponent } = usePageData({
|
|
61
70
|
page,
|
|
62
71
|
variables,
|
|
@@ -96,8 +105,9 @@ function Router({
|
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
107
|
});
|
|
99
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: currentURL }, page.id) });
|
|
108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocationContext.Provider, { value: { pathname: currentURL, params: variables ?? {} }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: currentURL }, page.id) }) });
|
|
100
109
|
}
|
|
110
|
+
const useLocation = () => (0, import_react2.useContext)(LocationContext);
|
|
101
111
|
function usePageData({
|
|
102
112
|
page,
|
|
103
113
|
variables,
|
|
@@ -113,7 +123,7 @@ function usePageData({
|
|
|
113
123
|
ssr_signals,
|
|
114
124
|
last_variables
|
|
115
125
|
} = useRouterContext();
|
|
116
|
-
const session = useSession();
|
|
126
|
+
const [session] = useSession();
|
|
117
127
|
function load_query({ id, artifact }) {
|
|
118
128
|
for (const artifact2 of Object.keys(page.documents)) {
|
|
119
129
|
last_variables.set(artifact2, variables);
|
|
@@ -133,7 +143,7 @@ function usePageData({
|
|
|
133
143
|
variables,
|
|
134
144
|
cacheParams: { disableSubscriptions: true },
|
|
135
145
|
session
|
|
136
|
-
}).then(() => {
|
|
146
|
+
}).then(async () => {
|
|
137
147
|
data_cache.set(id, observer);
|
|
138
148
|
if (observer.state.errors && observer.state.errors.length > 0) {
|
|
139
149
|
reject(observer.state.errors.map((e) => e.message).join("\n"));
|
|
@@ -145,7 +155,12 @@ function usePageData({
|
|
|
145
155
|
window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
|
|
146
156
|
|
|
147
157
|
const artifactName = "${artifact.name}"
|
|
148
|
-
const value = ${JSON.stringify(
|
|
158
|
+
const value = ${JSON.stringify(
|
|
159
|
+
await (0, import_scalars.marshalSelection)({
|
|
160
|
+
selection: observer.artifact.selection,
|
|
161
|
+
data: observer.state.data
|
|
162
|
+
})
|
|
163
|
+
)}
|
|
149
164
|
|
|
150
165
|
// if the data is pending, we need to resolve it
|
|
151
166
|
if (window.__houdini__nav_caches__?.data_cache.has(artifactName)) {
|
|
@@ -154,7 +169,18 @@ function usePageData({
|
|
|
154
169
|
const new_store = window.__houdini__client__.observe({
|
|
155
170
|
artifact: window.__houdini__nav_caches__.artifact_cache.get(artifactName),
|
|
156
171
|
cache: window.__houdini__cache__,
|
|
157
|
-
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
// we're pushing this store onto the client, it should be initialized
|
|
175
|
+
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
176
|
+
setup: true,
|
|
177
|
+
variables: ${JSON.stringify(
|
|
178
|
+
(0, import_scalars.marshalInputs)({
|
|
179
|
+
artifact: observer.artifact,
|
|
180
|
+
input: variables,
|
|
181
|
+
config: import_config.default
|
|
182
|
+
})
|
|
183
|
+
)}
|
|
158
184
|
})
|
|
159
185
|
|
|
160
186
|
window.__houdini__nav_caches__?.data_cache.set(artifactName, new_store)
|
|
@@ -174,12 +200,12 @@ function usePageData({
|
|
|
174
200
|
if (!window.__houdini__pending_artifacts__) {
|
|
175
201
|
window.__houdini__pending_artifacts__ = {}
|
|
176
202
|
}
|
|
177
|
-
|
|
178
|
-
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(variables)}
|
|
179
|
-
window.__houdini__pending_data__[artifactName] = value
|
|
180
|
-
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
181
203
|
}
|
|
182
204
|
|
|
205
|
+
window.__houdini__pending_variables__[artifactName] = ${JSON.stringify(observer.state.variables)}
|
|
206
|
+
window.__houdini__pending_data__[artifactName] = value
|
|
207
|
+
window.__houdini__pending_artifacts__[artifactName] = ${JSON.stringify(artifact)}
|
|
208
|
+
|
|
183
209
|
// if this payload finishes off an ssr request, we need to resolve the signal
|
|
184
210
|
if (window.__houdini__nav_caches__?.ssr_signals.has(artifactName)) {
|
|
185
211
|
|
|
@@ -188,7 +214,13 @@ function usePageData({
|
|
|
188
214
|
// we're pushing this store onto the client, it should be initialized
|
|
189
215
|
window.__houdini__nav_caches__.data_cache.get(artifactName).send({
|
|
190
216
|
setup: true,
|
|
191
|
-
variables: ${JSON.stringify(
|
|
217
|
+
variables: ${JSON.stringify(
|
|
218
|
+
(0, import_scalars.marshalInputs)({
|
|
219
|
+
artifact: observer.artifact,
|
|
220
|
+
input: variables,
|
|
221
|
+
config: import_config.default
|
|
222
|
+
})
|
|
223
|
+
)}
|
|
192
224
|
})
|
|
193
225
|
}
|
|
194
226
|
|
|
@@ -218,7 +250,7 @@ function usePageData({
|
|
|
218
250
|
}
|
|
219
251
|
let last = {};
|
|
220
252
|
let usedVariables = {};
|
|
221
|
-
for (const variable of pageVariables) {
|
|
253
|
+
for (const variable of Object.keys(pageVariables)) {
|
|
222
254
|
last[variable] = last_variables.get(artifact)[variable];
|
|
223
255
|
usedVariables[variable] = (variables2 ?? {})[variable];
|
|
224
256
|
}
|
|
@@ -301,7 +333,8 @@ function RouterContextProvider({
|
|
|
301
333
|
data_cache,
|
|
302
334
|
ssr_signals,
|
|
303
335
|
last_variables,
|
|
304
|
-
session
|
|
336
|
+
session,
|
|
337
|
+
setSession: (newSession) => setSession((old) => ({ ...old, ...newSession }))
|
|
305
338
|
},
|
|
306
339
|
children
|
|
307
340
|
}
|
|
@@ -330,12 +363,34 @@ function updateLocalSession(session) {
|
|
|
330
363
|
);
|
|
331
364
|
}
|
|
332
365
|
function useSession() {
|
|
333
|
-
|
|
366
|
+
const ctx = useRouterContext();
|
|
367
|
+
const updateSession = (newSession) => {
|
|
368
|
+
ctx.data_cache.clear();
|
|
369
|
+
ctx.setSession(newSession);
|
|
370
|
+
const auth = import_config.default.router?.auth;
|
|
371
|
+
if (!auth) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const url = "redirect" in auth ? auth.redirect : auth.url;
|
|
375
|
+
fetch(url, {
|
|
376
|
+
method: "POST",
|
|
377
|
+
body: JSON.stringify(newSession),
|
|
378
|
+
headers: {
|
|
379
|
+
"Content-Type": "application/json",
|
|
380
|
+
Accept: "application/json"
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
return [ctx.session, updateSession];
|
|
334
385
|
}
|
|
335
386
|
function useCurrentVariables() {
|
|
336
387
|
return import_react.default.useContext(VariableContext);
|
|
337
388
|
}
|
|
338
389
|
const VariableContext = import_react.default.createContext(null);
|
|
390
|
+
const LocationContext = import_react.default.createContext({
|
|
391
|
+
pathname: "",
|
|
392
|
+
params: {}
|
|
393
|
+
});
|
|
339
394
|
function useQueryResult(name) {
|
|
340
395
|
const store_ref = useRouterContext().data_cache.get(name);
|
|
341
396
|
const [{ data, errors }, observer] = (0, import_useDocumentStore.useDocumentStore)({
|
|
@@ -445,6 +500,20 @@ function router_cache({
|
|
|
445
500
|
}
|
|
446
501
|
return result;
|
|
447
502
|
}
|
|
503
|
+
const PageContext = import_react.default.createContext({ params: {} });
|
|
504
|
+
function PageContextProvider({
|
|
505
|
+
keys,
|
|
506
|
+
children
|
|
507
|
+
}) {
|
|
508
|
+
const location2 = useLocation();
|
|
509
|
+
const params = Object.fromEntries(
|
|
510
|
+
Object.entries(location2.params).filter(([key]) => keys.includes(key))
|
|
511
|
+
);
|
|
512
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageContext.Provider, { value: { params }, children });
|
|
513
|
+
}
|
|
514
|
+
function useRoute() {
|
|
515
|
+
return (0, import_react2.useContext)(PageContext);
|
|
516
|
+
}
|
|
448
517
|
function signal_promise() {
|
|
449
518
|
let resolve = () => {
|
|
450
519
|
};
|
|
@@ -462,6 +531,7 @@ function signal_promise() {
|
|
|
462
531
|
}
|
|
463
532
|
// Annotate the CommonJS export names for ESM import in node:
|
|
464
533
|
0 && (module.exports = {
|
|
534
|
+
PageContextProvider,
|
|
465
535
|
Router,
|
|
466
536
|
RouterContextProvider,
|
|
467
537
|
router_cache,
|
|
@@ -469,7 +539,9 @@ function signal_promise() {
|
|
|
469
539
|
useCache,
|
|
470
540
|
useClient,
|
|
471
541
|
useCurrentVariables,
|
|
542
|
+
useLocation,
|
|
472
543
|
useQueryResult,
|
|
544
|
+
useRoute,
|
|
473
545
|
useRouterContext,
|
|
474
546
|
useSession
|
|
475
547
|
});
|
|
@@ -10,7 +10,7 @@ function useDocumentHandle({
|
|
|
10
10
|
}) {
|
|
11
11
|
const [forwardPending, setForwardPending] = React.useState(false);
|
|
12
12
|
const [backwardPending, setBackwardPending] = React.useState(false);
|
|
13
|
-
const session = useSession();
|
|
13
|
+
const [session] = useSession();
|
|
14
14
|
return React.useMemo(() => {
|
|
15
15
|
const wrapLoad = (setLoading, fn) => {
|
|
16
16
|
return async (value) => {
|
|
@@ -7,6 +7,5 @@ export type UseDocumentStoreParams<_Artifact extends DocumentArtifact, _Data ext
|
|
|
7
7
|
} & Partial<ObserveParams<_Data, DocumentArtifact, _Input>>;
|
|
8
8
|
export declare function useDocumentStore<_Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables, _Artifact extends DocumentArtifact = DocumentArtifact>({ artifact, observer: obs, ...observeParams }: UseDocumentStoreParams<_Artifact, _Data, _Input>): [
|
|
9
9
|
QueryResult<_Data, _Input>,
|
|
10
|
-
DocumentStore<_Data, _Input
|
|
11
|
-
(store: DocumentStore<_Data, _Input>) => void
|
|
10
|
+
DocumentStore<_Data, _Input>
|
|
12
11
|
];
|
|
@@ -15,6 +15,10 @@ function useDocumentStore({
|
|
|
15
15
|
})
|
|
16
16
|
);
|
|
17
17
|
const box = React.useRef(observer.state);
|
|
18
|
+
if (obs && obs !== observer) {
|
|
19
|
+
box.current = obs.state;
|
|
20
|
+
setObserver(obs);
|
|
21
|
+
}
|
|
18
22
|
const subscribe = React.useCallback(
|
|
19
23
|
(fn) => {
|
|
20
24
|
return observer.subscribe((val) => {
|
|
@@ -31,7 +35,7 @@ function useDocumentStore({
|
|
|
31
35
|
() => box.current,
|
|
32
36
|
() => box.current
|
|
33
37
|
);
|
|
34
|
-
return [storeValue, observer
|
|
38
|
+
return [storeValue, observer];
|
|
35
39
|
}
|
|
36
40
|
export {
|
|
37
41
|
useDocumentStore
|
|
@@ -6,10 +6,6 @@ export declare function useDocumentSubscription<_Artifact extends DocumentArtifa
|
|
|
6
6
|
variables: _Input;
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
send?: Partial<SendParams>;
|
|
9
|
-
}): [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
DocumentStore<_Data, _Input>,
|
|
14
|
-
(store: DocumentStore<_Data, _Input>) => void
|
|
15
|
-
];
|
|
9
|
+
}): [QueryResult<_Data, _Input> & {
|
|
10
|
+
parent?: string | null;
|
|
11
|
+
}, DocumentStore<_Data, _Input>];
|
|
@@ -8,11 +8,11 @@ function useDocumentSubscription({
|
|
|
8
8
|
disabled,
|
|
9
9
|
...observeParams
|
|
10
10
|
}) {
|
|
11
|
-
const [storeValue, observer
|
|
11
|
+
const [storeValue, observer] = useDocumentStore({
|
|
12
12
|
artifact,
|
|
13
13
|
...observeParams
|
|
14
14
|
});
|
|
15
|
-
const session = useSession();
|
|
15
|
+
const [session] = useSession();
|
|
16
16
|
useDeepCompareEffect(() => {
|
|
17
17
|
if (!disabled) {
|
|
18
18
|
observer.send({
|
|
@@ -33,8 +33,7 @@ function useDocumentSubscription({
|
|
|
33
33
|
parent: send?.stuff?.parentID,
|
|
34
34
|
...storeValue
|
|
35
35
|
},
|
|
36
|
-
observer
|
|
37
|
-
setObserver
|
|
36
|
+
observer
|
|
38
37
|
];
|
|
39
38
|
}
|
|
40
39
|
export {
|
|
@@ -2,7 +2,7 @@ import type { GraphQLObject } from '$houdini/lib/types';
|
|
|
2
2
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
3
3
|
import { RouterCache } from './routing';
|
|
4
4
|
export * from './hooks';
|
|
5
|
-
export { router_cache } from './routing';
|
|
5
|
+
export { router_cache, useSession, useLocation, useRoute } from './routing';
|
|
6
6
|
export declare function Router({ cache, initialURL, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session, assetPrefix, injectToStream, }: {
|
|
7
7
|
initialURL: string;
|
|
8
8
|
initialVariables: GraphQLObject;
|
|
@@ -3,7 +3,7 @@ import client from "./client";
|
|
|
3
3
|
import manifest from "./manifest";
|
|
4
4
|
import { Router as RouterImpl, RouterContextProvider } from "./routing";
|
|
5
5
|
export * from "./hooks";
|
|
6
|
-
import { router_cache } from "./routing";
|
|
6
|
+
import { router_cache, useSession, useLocation, useRoute } from "./routing";
|
|
7
7
|
function Router({
|
|
8
8
|
cache,
|
|
9
9
|
initialURL,
|
|
@@ -41,5 +41,8 @@ function Router({
|
|
|
41
41
|
}
|
|
42
42
|
export {
|
|
43
43
|
Router,
|
|
44
|
-
router_cache
|
|
44
|
+
router_cache,
|
|
45
|
+
useLocation,
|
|
46
|
+
useRoute,
|
|
47
|
+
useSession
|
|
45
48
|
};
|
|
@@ -18,6 +18,10 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
18
18
|
assetPrefix: string;
|
|
19
19
|
injectToStream?: undefined | ((chunk: string) => void);
|
|
20
20
|
}): JSX.Element;
|
|
21
|
+
export declare const useLocation: () => {
|
|
22
|
+
pathname: string;
|
|
23
|
+
params: Record<string, any>;
|
|
24
|
+
};
|
|
21
25
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
22
26
|
children: React.ReactElement;
|
|
23
27
|
client: HoudiniClient;
|
|
@@ -38,6 +42,7 @@ type RouterContext = {
|
|
|
38
42
|
ssr_signals: PendingCache;
|
|
39
43
|
last_variables: LRUCache<GraphQLVariables>;
|
|
40
44
|
session: App.Session;
|
|
45
|
+
setSession: (newSession: Partial<App.Session>) => void;
|
|
41
46
|
};
|
|
42
47
|
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
43
48
|
resolve: () => void;
|
|
@@ -47,7 +52,7 @@ export declare const useRouterContext: () => RouterContext;
|
|
|
47
52
|
export declare function useClient(): HoudiniClient;
|
|
48
53
|
export declare function useCache(): Cache;
|
|
49
54
|
export declare function updateLocalSession(session: App.Session): void;
|
|
50
|
-
export declare function useSession(): App.Session;
|
|
55
|
+
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
51
56
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
52
57
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
|
|
53
58
|
export type RouterCache = {
|
|
@@ -65,4 +70,14 @@ export declare function router_cache({ pending_queries, artifacts, components, i
|
|
|
65
70
|
initialVariables?: Record<string, GraphQLVariables>;
|
|
66
71
|
initialArtifacts?: Record<string, QueryArtifact>;
|
|
67
72
|
}): RouterCache;
|
|
73
|
+
export declare function PageContextProvider({ keys, children, }: {
|
|
74
|
+
keys: string[];
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}): JSX.Element;
|
|
77
|
+
export declare function useRoute<PageProps extends {
|
|
78
|
+
Params: {};
|
|
79
|
+
}>(): RouteProp<PageProps['Params']>;
|
|
80
|
+
export type RouteProp<Params> = {
|
|
81
|
+
params: Params;
|
|
82
|
+
};
|
|
68
83
|
export {};
|