houdini-react 1.3.7 → 1.3.8
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/index.d.ts +1 -3
- package/build/plugin/state.d.ts +3 -0
- package/build/plugin-cjs/index.js +238 -240
- package/build/plugin-esm/index.js +237 -237
- package/build/runtime/routing/Router.d.ts +6 -32
- package/build/runtime/routing/hooks.d.ts +40 -0
- package/build/runtime/routing/index.d.ts +1 -0
- package/build/runtime-cjs/hooks/useDocumentHandle.js +4 -4
- package/build/runtime-cjs/hooks/useDocumentStore.js +2 -2
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +2 -2
- package/build/runtime-cjs/hooks/useMutation.js +2 -2
- package/build/runtime-cjs/routing/Router.d.ts +6 -32
- package/build/runtime-cjs/routing/Router.js +11 -62
- package/build/runtime-cjs/routing/hooks.d.ts +40 -0
- package/build/runtime-cjs/routing/hooks.js +89 -0
- package/build/runtime-cjs/routing/index.d.ts +1 -0
- package/build/runtime-cjs/routing/index.js +1 -0
- package/build/runtime-esm/hooks/useDocumentHandle.js +1 -1
- package/build/runtime-esm/hooks/useDocumentStore.js +1 -1
- package/build/runtime-esm/hooks/useDocumentSubscription.js +1 -1
- package/build/runtime-esm/hooks/useMutation.js +1 -1
- package/build/runtime-esm/routing/Router.d.ts +6 -32
- package/build/runtime-esm/routing/Router.js +3 -49
- package/build/runtime-esm/routing/hooks.d.ts +40 -0
- package/build/runtime-esm/routing/hooks.js +53 -0
- package/build/runtime-esm/routing/index.d.ts +1 -0
- package/build/runtime-esm/routing/index.js +1 -0
- package/package.json +2 -2
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
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';
|
|
3
|
+
import type { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import type { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
5
|
+
import type { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
6
6
|
import type { RouterManifest } from '$houdini/runtime/router/types';
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
type PageComponent
|
|
11
|
-
url: string;
|
|
12
|
-
}>;
|
|
8
|
+
import { type SuspenseCache } from './cache';
|
|
9
|
+
import { type DocumentHandle } from '../hooks/useDocumentHandle';
|
|
10
|
+
import { type PageComponent, type PendingCache } from './hooks';
|
|
13
11
|
type ComponentType = any;
|
|
14
12
|
/**
|
|
15
13
|
* Router is the top level entry point for the filesystem-based router.
|
|
@@ -22,11 +20,6 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
22
20
|
assetPrefix: string;
|
|
23
21
|
injectToStream?: undefined | ((chunk: string) => void);
|
|
24
22
|
}): React.JSX.Element;
|
|
25
|
-
export declare const useLocation: () => {
|
|
26
|
-
pathname: string;
|
|
27
|
-
params: Record<string, any>;
|
|
28
|
-
goto: (url: string) => void;
|
|
29
|
-
};
|
|
30
23
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
31
24
|
children: React.ReactNode;
|
|
32
25
|
client: HoudiniClient;
|
|
@@ -38,26 +31,7 @@ export declare function RouterContextProvider({ children, client, cache, artifac
|
|
|
38
31
|
last_variables: LRUCache<GraphQLVariables>;
|
|
39
32
|
session?: App.Session;
|
|
40
33
|
}): React.JSX.Element;
|
|
41
|
-
type RouterContext = {
|
|
42
|
-
client: HoudiniClient;
|
|
43
|
-
cache: Cache;
|
|
44
|
-
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
45
|
-
component_cache: SuspenseCache<PageComponent>;
|
|
46
|
-
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
47
|
-
ssr_signals: PendingCache;
|
|
48
|
-
last_variables: LRUCache<GraphQLVariables>;
|
|
49
|
-
session: App.Session;
|
|
50
|
-
setSession: (newSession: Partial<App.Session>) => void;
|
|
51
|
-
};
|
|
52
|
-
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
53
|
-
resolve: () => void;
|
|
54
|
-
reject: (message: string) => void;
|
|
55
|
-
}>;
|
|
56
|
-
export declare const useRouterContext: () => RouterContext;
|
|
57
|
-
export declare function useClient(): HoudiniClient;
|
|
58
|
-
export declare function useCache(): Cache;
|
|
59
34
|
export declare function updateLocalSession(session: App.Session): void;
|
|
60
|
-
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
61
35
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
62
36
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentHandle<any, _Data, _Input>];
|
|
63
37
|
export type RouterCache = {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
|
+
import type { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
|
|
3
|
+
import type { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import type { GraphQLObject, GraphQLVariables, QueryArtifact } from '$houdini/runtime/lib/types';
|
|
5
|
+
import { default as React } from 'react';
|
|
6
|
+
import type { SuspenseCache } from './cache';
|
|
7
|
+
export type PageComponent = React.ComponentType<{
|
|
8
|
+
url: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
11
|
+
resolve: () => void;
|
|
12
|
+
reject: (message: string) => void;
|
|
13
|
+
}>;
|
|
14
|
+
type RouterContext = {
|
|
15
|
+
client: HoudiniClient;
|
|
16
|
+
cache: Cache;
|
|
17
|
+
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
18
|
+
component_cache: SuspenseCache<PageComponent>;
|
|
19
|
+
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
20
|
+
ssr_signals: PendingCache;
|
|
21
|
+
last_variables: LRUCache<GraphQLVariables>;
|
|
22
|
+
session: App.Session;
|
|
23
|
+
setSession: (newSession: Partial<App.Session>) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const Context: React.Context<RouterContext | null>;
|
|
26
|
+
export declare const LocationContext: React.Context<{
|
|
27
|
+
pathname: string;
|
|
28
|
+
params: Record<string, any>;
|
|
29
|
+
goto: (url: string) => void;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const useLocation: () => {
|
|
32
|
+
pathname: string;
|
|
33
|
+
params: Record<string, any>;
|
|
34
|
+
goto: (url: string) => void;
|
|
35
|
+
};
|
|
36
|
+
export declare const useRouterContext: () => RouterContext;
|
|
37
|
+
export declare function useClient(): HoudiniClient;
|
|
38
|
+
export declare function useCache(): Cache;
|
|
39
|
+
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
40
|
+
export {};
|
|
@@ -31,7 +31,7 @@ var import_pageInfo = require("$houdini/runtime/lib/pageInfo");
|
|
|
31
31
|
var import_pagination = require("$houdini/runtime/lib/pagination");
|
|
32
32
|
var import_types = require("$houdini/runtime/lib/types");
|
|
33
33
|
var import_react = __toESM(require("react"));
|
|
34
|
-
var
|
|
34
|
+
var import_hooks = require("../routing/hooks");
|
|
35
35
|
function useDocumentHandle({
|
|
36
36
|
artifact,
|
|
37
37
|
observer,
|
|
@@ -39,9 +39,9 @@ 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 location = (0,
|
|
43
|
-
const [session] = (0,
|
|
44
|
-
const client = (0,
|
|
42
|
+
const location = (0, import_hooks.useLocation)();
|
|
43
|
+
const [session] = (0, import_hooks.useSession)();
|
|
44
|
+
const client = (0, import_hooks.useClient)();
|
|
45
45
|
const paginationObserver = import_react.default.useMemo(() => {
|
|
46
46
|
if (!artifact.refetch?.paginated) {
|
|
47
47
|
return null;
|
|
@@ -28,14 +28,14 @@ __export(useDocumentStore_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(useDocumentStore_exports);
|
|
30
30
|
var React = __toESM(require("react"));
|
|
31
|
-
var
|
|
31
|
+
var import_hooks = require("../routing/hooks");
|
|
32
32
|
var import_useIsMounted = require("./useIsMounted");
|
|
33
33
|
function useDocumentStore({
|
|
34
34
|
artifact,
|
|
35
35
|
observer: obs,
|
|
36
36
|
...observeParams
|
|
37
37
|
}) {
|
|
38
|
-
const client = (0,
|
|
38
|
+
const client = (0, import_hooks.useClient)();
|
|
39
39
|
const isMountedRef = (0, import_useIsMounted.useIsMountedRef)();
|
|
40
40
|
let [observer, setObserver] = React.useState(
|
|
41
41
|
() => obs ?? client.observe({
|
|
@@ -27,7 +27,7 @@ __export(useDocumentSubscription_exports, {
|
|
|
27
27
|
useDocumentSubscription: () => useDocumentSubscription
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(useDocumentSubscription_exports);
|
|
30
|
-
var
|
|
30
|
+
var import_hooks = require("../routing/hooks");
|
|
31
31
|
var import_useDeepCompareEffect = __toESM(require("./useDeepCompareEffect"));
|
|
32
32
|
var import_useDocumentStore = require("./useDocumentStore");
|
|
33
33
|
function useDocumentSubscription({
|
|
@@ -41,7 +41,7 @@ function useDocumentSubscription({
|
|
|
41
41
|
artifact,
|
|
42
42
|
...observeParams
|
|
43
43
|
});
|
|
44
|
-
const [session] = (0,
|
|
44
|
+
const [session] = (0, import_hooks.useSession)();
|
|
45
45
|
(0, import_useDeepCompareEffect.default)(() => {
|
|
46
46
|
if (!disabled) {
|
|
47
47
|
observer.send({
|
|
@@ -21,14 +21,14 @@ __export(useMutation_exports, {
|
|
|
21
21
|
useMutation: () => useMutation
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(useMutation_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_hooks = require("../routing/hooks");
|
|
25
25
|
var import_useDocumentStore = require("./useDocumentStore");
|
|
26
26
|
function useMutation({
|
|
27
27
|
artifact
|
|
28
28
|
}) {
|
|
29
29
|
const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({ artifact });
|
|
30
30
|
const pending = storeValue.fetching;
|
|
31
|
-
const [session] = (0,
|
|
31
|
+
const [session] = (0, import_hooks.useSession)();
|
|
32
32
|
const mutate = ({
|
|
33
33
|
metadata,
|
|
34
34
|
fetch,
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
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';
|
|
3
|
+
import type { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import type { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
5
|
+
import type { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
6
6
|
import type { RouterManifest } from '$houdini/runtime/router/types';
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
type PageComponent
|
|
11
|
-
url: string;
|
|
12
|
-
}>;
|
|
8
|
+
import { type SuspenseCache } from './cache';
|
|
9
|
+
import { type DocumentHandle } from '../hooks/useDocumentHandle';
|
|
10
|
+
import { type PageComponent, type PendingCache } from './hooks';
|
|
13
11
|
type ComponentType = any;
|
|
14
12
|
/**
|
|
15
13
|
* Router is the top level entry point for the filesystem-based router.
|
|
@@ -22,11 +20,6 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
22
20
|
assetPrefix: string;
|
|
23
21
|
injectToStream?: undefined | ((chunk: string) => void);
|
|
24
22
|
}): React.JSX.Element;
|
|
25
|
-
export declare const useLocation: () => {
|
|
26
|
-
pathname: string;
|
|
27
|
-
params: Record<string, any>;
|
|
28
|
-
goto: (url: string) => void;
|
|
29
|
-
};
|
|
30
23
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
31
24
|
children: React.ReactNode;
|
|
32
25
|
client: HoudiniClient;
|
|
@@ -38,26 +31,7 @@ export declare function RouterContextProvider({ children, client, cache, artifac
|
|
|
38
31
|
last_variables: LRUCache<GraphQLVariables>;
|
|
39
32
|
session?: App.Session;
|
|
40
33
|
}): React.JSX.Element;
|
|
41
|
-
type RouterContext = {
|
|
42
|
-
client: HoudiniClient;
|
|
43
|
-
cache: Cache;
|
|
44
|
-
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
45
|
-
component_cache: SuspenseCache<PageComponent>;
|
|
46
|
-
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
47
|
-
ssr_signals: PendingCache;
|
|
48
|
-
last_variables: LRUCache<GraphQLVariables>;
|
|
49
|
-
session: App.Session;
|
|
50
|
-
setSession: (newSession: Partial<App.Session>) => void;
|
|
51
|
-
};
|
|
52
|
-
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
53
|
-
resolve: () => void;
|
|
54
|
-
reject: (message: string) => void;
|
|
55
|
-
}>;
|
|
56
|
-
export declare const useRouterContext: () => RouterContext;
|
|
57
|
-
export declare function useClient(): HoudiniClient;
|
|
58
|
-
export declare function useCache(): Cache;
|
|
59
34
|
export declare function updateLocalSession(session: App.Session): void;
|
|
60
|
-
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
61
35
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
62
36
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentHandle<any, _Data, _Input>];
|
|
63
37
|
export type RouterCache = {
|
|
@@ -29,14 +29,9 @@ __export(Router_exports, {
|
|
|
29
29
|
RouterContextProvider: () => RouterContextProvider,
|
|
30
30
|
router_cache: () => router_cache,
|
|
31
31
|
updateLocalSession: () => updateLocalSession,
|
|
32
|
-
useCache: () => useCache,
|
|
33
|
-
useClient: () => useClient,
|
|
34
32
|
useCurrentVariables: () => useCurrentVariables,
|
|
35
|
-
useLocation: () => useLocation,
|
|
36
33
|
useQueryResult: () => useQueryResult,
|
|
37
|
-
useRoute: () => useRoute
|
|
38
|
-
useRouterContext: () => useRouterContext,
|
|
39
|
-
useSession: () => useSession
|
|
34
|
+
useRoute: () => useRoute
|
|
40
35
|
});
|
|
41
36
|
module.exports = __toCommonJS(Router_exports);
|
|
42
37
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -46,9 +41,10 @@ var import_scalars = require("$houdini/runtime/lib/scalars");
|
|
|
46
41
|
var import_match = require("$houdini/runtime/router/match");
|
|
47
42
|
var import_react = __toESM(require("react"));
|
|
48
43
|
var import_react2 = require("react");
|
|
44
|
+
var import_cache = require("./cache");
|
|
49
45
|
var import_useDocumentHandle = require("../hooks/useDocumentHandle");
|
|
50
46
|
var import_useDocumentStore = require("../hooks/useDocumentStore");
|
|
51
|
-
var
|
|
47
|
+
var import_hooks = require("./hooks");
|
|
52
48
|
const PreloadWhich = {
|
|
53
49
|
component: "component",
|
|
54
50
|
data: "data",
|
|
@@ -73,7 +69,7 @@ function Router({
|
|
|
73
69
|
assetPrefix,
|
|
74
70
|
injectToStream
|
|
75
71
|
});
|
|
76
|
-
const { component_cache, data_cache } = useRouterContext();
|
|
72
|
+
const { component_cache, data_cache } = (0, import_hooks.useRouterContext)();
|
|
77
73
|
const PageComponent = component_cache.get(page.id);
|
|
78
74
|
import_react.default.useEffect(() => {
|
|
79
75
|
if (globalThis.window && window.location.pathname !== currentURL) {
|
|
@@ -112,7 +108,7 @@ function Router({
|
|
|
112
108
|
}
|
|
113
109
|
});
|
|
114
110
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
115
|
-
LocationContext.Provider,
|
|
111
|
+
import_hooks.LocationContext.Provider,
|
|
116
112
|
{
|
|
117
113
|
value: {
|
|
118
114
|
pathname: currentURL,
|
|
@@ -123,7 +119,6 @@ function Router({
|
|
|
123
119
|
}
|
|
124
120
|
) });
|
|
125
121
|
}
|
|
126
|
-
const useLocation = () => (0, import_react2.useContext)(LocationContext);
|
|
127
122
|
function usePageData({
|
|
128
123
|
page,
|
|
129
124
|
variables,
|
|
@@ -138,8 +133,8 @@ function usePageData({
|
|
|
138
133
|
artifact_cache,
|
|
139
134
|
ssr_signals,
|
|
140
135
|
last_variables
|
|
141
|
-
} = useRouterContext();
|
|
142
|
-
const [session] = useSession();
|
|
136
|
+
} = (0, import_hooks.useRouterContext)();
|
|
137
|
+
const [session] = (0, import_hooks.useSession)();
|
|
143
138
|
function load_query({
|
|
144
139
|
id,
|
|
145
140
|
artifact,
|
|
@@ -346,7 +341,7 @@ function RouterContextProvider({
|
|
|
346
341
|
};
|
|
347
342
|
}, []);
|
|
348
343
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
349
|
-
Context.Provider,
|
|
344
|
+
import_hooks.Context.Provider,
|
|
350
345
|
{
|
|
351
346
|
value: {
|
|
352
347
|
client,
|
|
@@ -363,20 +358,6 @@ function RouterContextProvider({
|
|
|
363
358
|
}
|
|
364
359
|
);
|
|
365
360
|
}
|
|
366
|
-
const Context = import_react.default.createContext(null);
|
|
367
|
-
const useRouterContext = () => {
|
|
368
|
-
const ctx = import_react.default.useContext(Context);
|
|
369
|
-
if (!ctx) {
|
|
370
|
-
throw new Error("Could not find router context");
|
|
371
|
-
}
|
|
372
|
-
return ctx;
|
|
373
|
-
};
|
|
374
|
-
function useClient() {
|
|
375
|
-
return useRouterContext().client;
|
|
376
|
-
}
|
|
377
|
-
function useCache() {
|
|
378
|
-
return useRouterContext().cache;
|
|
379
|
-
}
|
|
380
361
|
function updateLocalSession(session) {
|
|
381
362
|
window.dispatchEvent(
|
|
382
363
|
new CustomEvent("_houdini_session_", {
|
|
@@ -385,39 +366,12 @@ function updateLocalSession(session) {
|
|
|
385
366
|
})
|
|
386
367
|
);
|
|
387
368
|
}
|
|
388
|
-
function useSession() {
|
|
389
|
-
const ctx = useRouterContext();
|
|
390
|
-
const updateSession = (newSession) => {
|
|
391
|
-
ctx.data_cache.clear();
|
|
392
|
-
ctx.setSession(newSession);
|
|
393
|
-
const auth = import_config.default.router?.auth;
|
|
394
|
-
if (!auth) {
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
const url = "redirect" in auth ? auth.redirect : auth.url;
|
|
398
|
-
fetch(url, {
|
|
399
|
-
method: "POST",
|
|
400
|
-
body: JSON.stringify(newSession),
|
|
401
|
-
headers: {
|
|
402
|
-
"Content-Type": "application/json",
|
|
403
|
-
Accept: "application/json"
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
return [ctx.session, updateSession];
|
|
408
|
-
}
|
|
409
369
|
function useCurrentVariables() {
|
|
410
370
|
return import_react.default.useContext(VariableContext);
|
|
411
371
|
}
|
|
412
372
|
const VariableContext = import_react.default.createContext(null);
|
|
413
|
-
const LocationContext = import_react.default.createContext({
|
|
414
|
-
pathname: "",
|
|
415
|
-
params: {},
|
|
416
|
-
goto: () => {
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
373
|
function useQueryResult(name) {
|
|
420
|
-
const { data_cache, artifact_cache } = useRouterContext();
|
|
374
|
+
const { data_cache, artifact_cache } = (0, import_hooks.useRouterContext)();
|
|
421
375
|
const store_ref = data_cache.get(name);
|
|
422
376
|
const [storeValue, observer] = (0, import_useDocumentStore.useDocumentStore)({
|
|
423
377
|
artifact: store_ref.artifact,
|
|
@@ -541,7 +495,7 @@ function PageContextProvider({
|
|
|
541
495
|
keys,
|
|
542
496
|
children
|
|
543
497
|
}) {
|
|
544
|
-
const location2 = useLocation();
|
|
498
|
+
const location2 = (0, import_hooks.useLocation)();
|
|
545
499
|
const params = Object.fromEntries(
|
|
546
500
|
Object.entries(location2.params).filter(([key]) => keys.includes(key))
|
|
547
501
|
);
|
|
@@ -572,12 +526,7 @@ function signal_promise() {
|
|
|
572
526
|
RouterContextProvider,
|
|
573
527
|
router_cache,
|
|
574
528
|
updateLocalSession,
|
|
575
|
-
useCache,
|
|
576
|
-
useClient,
|
|
577
529
|
useCurrentVariables,
|
|
578
|
-
useLocation,
|
|
579
530
|
useQueryResult,
|
|
580
|
-
useRoute
|
|
581
|
-
useRouterContext,
|
|
582
|
-
useSession
|
|
531
|
+
useRoute
|
|
583
532
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
|
+
import type { DocumentStore, HoudiniClient } from '$houdini/runtime/client';
|
|
3
|
+
import type { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import type { GraphQLObject, GraphQLVariables, QueryArtifact } from '$houdini/runtime/lib/types';
|
|
5
|
+
import { default as React } from 'react';
|
|
6
|
+
import type { SuspenseCache } from './cache';
|
|
7
|
+
export type PageComponent = React.ComponentType<{
|
|
8
|
+
url: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
11
|
+
resolve: () => void;
|
|
12
|
+
reject: (message: string) => void;
|
|
13
|
+
}>;
|
|
14
|
+
type RouterContext = {
|
|
15
|
+
client: HoudiniClient;
|
|
16
|
+
cache: Cache;
|
|
17
|
+
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
18
|
+
component_cache: SuspenseCache<PageComponent>;
|
|
19
|
+
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
20
|
+
ssr_signals: PendingCache;
|
|
21
|
+
last_variables: LRUCache<GraphQLVariables>;
|
|
22
|
+
session: App.Session;
|
|
23
|
+
setSession: (newSession: Partial<App.Session>) => void;
|
|
24
|
+
};
|
|
25
|
+
export declare const Context: React.Context<RouterContext | null>;
|
|
26
|
+
export declare const LocationContext: React.Context<{
|
|
27
|
+
pathname: string;
|
|
28
|
+
params: Record<string, any>;
|
|
29
|
+
goto: (url: string) => void;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const useLocation: () => {
|
|
32
|
+
pathname: string;
|
|
33
|
+
params: Record<string, any>;
|
|
34
|
+
goto: (url: string) => void;
|
|
35
|
+
};
|
|
36
|
+
export declare const useRouterContext: () => RouterContext;
|
|
37
|
+
export declare function useClient(): HoudiniClient;
|
|
38
|
+
export declare function useCache(): Cache;
|
|
39
|
+
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var hooks_exports = {};
|
|
26
|
+
__export(hooks_exports, {
|
|
27
|
+
Context: () => Context,
|
|
28
|
+
LocationContext: () => LocationContext,
|
|
29
|
+
useCache: () => useCache,
|
|
30
|
+
useClient: () => useClient,
|
|
31
|
+
useLocation: () => useLocation,
|
|
32
|
+
useRouterContext: () => useRouterContext,
|
|
33
|
+
useSession: () => useSession
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
36
|
+
var import_config = __toESM(require("$houdini/runtime/imports/config"));
|
|
37
|
+
var import_react = __toESM(require("react"));
|
|
38
|
+
const Context = import_react.default.createContext(null);
|
|
39
|
+
const LocationContext = import_react.default.createContext({
|
|
40
|
+
pathname: "",
|
|
41
|
+
params: {},
|
|
42
|
+
goto: () => {
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const useLocation = () => (0, import_react.useContext)(LocationContext);
|
|
46
|
+
const useRouterContext = () => {
|
|
47
|
+
const ctx = import_react.default.useContext(Context);
|
|
48
|
+
if (!ctx) {
|
|
49
|
+
throw new Error("Could not find router context");
|
|
50
|
+
}
|
|
51
|
+
return ctx;
|
|
52
|
+
};
|
|
53
|
+
function useClient() {
|
|
54
|
+
return useRouterContext().client;
|
|
55
|
+
}
|
|
56
|
+
function useCache() {
|
|
57
|
+
return useRouterContext().cache;
|
|
58
|
+
}
|
|
59
|
+
function useSession() {
|
|
60
|
+
const ctx = useRouterContext();
|
|
61
|
+
const updateSession = (newSession) => {
|
|
62
|
+
ctx.data_cache.clear();
|
|
63
|
+
ctx.setSession(newSession);
|
|
64
|
+
const auth = import_config.default.router?.auth;
|
|
65
|
+
if (!auth) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const url = "redirect" in auth ? auth.redirect : auth.url;
|
|
69
|
+
fetch(url, {
|
|
70
|
+
method: "POST",
|
|
71
|
+
body: JSON.stringify(newSession),
|
|
72
|
+
headers: {
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
Accept: "application/json"
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
return [ctx.session, updateSession];
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
Context,
|
|
83
|
+
LocationContext,
|
|
84
|
+
useCache,
|
|
85
|
+
useClient,
|
|
86
|
+
useLocation,
|
|
87
|
+
useRouterContext,
|
|
88
|
+
useSession
|
|
89
|
+
});
|
|
@@ -23,6 +23,7 @@ __export(routing_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(routing_exports);
|
|
25
25
|
__reExport(routing_exports, require("./Router"), module.exports);
|
|
26
|
+
__reExport(routing_exports, require("./hooks"), module.exports);
|
|
26
27
|
var import_cache = require("./cache");
|
|
27
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
29
|
0 && (module.exports = {
|
|
@@ -2,7 +2,7 @@ import { extractPageInfo } from "$houdini/runtime/lib/pageInfo";
|
|
|
2
2
|
import { cursorHandlers, offsetHandlers } from "$houdini/runtime/lib/pagination";
|
|
3
3
|
import { ArtifactKind } from "$houdini/runtime/lib/types";
|
|
4
4
|
import React from "react";
|
|
5
|
-
import { useClient,
|
|
5
|
+
import { useClient, useSession, useLocation } from "../routing/hooks";
|
|
6
6
|
function useDocumentHandle({
|
|
7
7
|
artifact,
|
|
8
8
|
observer,
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { Cache } from '$houdini/runtime/cache/cache';
|
|
2
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';
|
|
3
|
+
import type { LRUCache } from '$houdini/runtime/lib/lru';
|
|
4
|
+
import type { GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
5
|
+
import type { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
6
6
|
import type { RouterManifest } from '$houdini/runtime/router/types';
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
type PageComponent
|
|
11
|
-
url: string;
|
|
12
|
-
}>;
|
|
8
|
+
import { type SuspenseCache } from './cache';
|
|
9
|
+
import { type DocumentHandle } from '../hooks/useDocumentHandle';
|
|
10
|
+
import { type PageComponent, type PendingCache } from './hooks';
|
|
13
11
|
type ComponentType = any;
|
|
14
12
|
/**
|
|
15
13
|
* Router is the top level entry point for the filesystem-based router.
|
|
@@ -22,11 +20,6 @@ export declare function Router({ manifest, initialURL, assetPrefix, injectToStre
|
|
|
22
20
|
assetPrefix: string;
|
|
23
21
|
injectToStream?: undefined | ((chunk: string) => void);
|
|
24
22
|
}): React.JSX.Element;
|
|
25
|
-
export declare const useLocation: () => {
|
|
26
|
-
pathname: string;
|
|
27
|
-
params: Record<string, any>;
|
|
28
|
-
goto: (url: string) => void;
|
|
29
|
-
};
|
|
30
23
|
export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, ssr_signals, last_variables, session: ssrSession, }: {
|
|
31
24
|
children: React.ReactNode;
|
|
32
25
|
client: HoudiniClient;
|
|
@@ -38,26 +31,7 @@ export declare function RouterContextProvider({ children, client, cache, artifac
|
|
|
38
31
|
last_variables: LRUCache<GraphQLVariables>;
|
|
39
32
|
session?: App.Session;
|
|
40
33
|
}): React.JSX.Element;
|
|
41
|
-
type RouterContext = {
|
|
42
|
-
client: HoudiniClient;
|
|
43
|
-
cache: Cache;
|
|
44
|
-
artifact_cache: SuspenseCache<QueryArtifact>;
|
|
45
|
-
component_cache: SuspenseCache<PageComponent>;
|
|
46
|
-
data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
|
|
47
|
-
ssr_signals: PendingCache;
|
|
48
|
-
last_variables: LRUCache<GraphQLVariables>;
|
|
49
|
-
session: App.Session;
|
|
50
|
-
setSession: (newSession: Partial<App.Session>) => void;
|
|
51
|
-
};
|
|
52
|
-
export type PendingCache = SuspenseCache<Promise<void> & {
|
|
53
|
-
resolve: () => void;
|
|
54
|
-
reject: (message: string) => void;
|
|
55
|
-
}>;
|
|
56
|
-
export declare const useRouterContext: () => RouterContext;
|
|
57
|
-
export declare function useClient(): HoudiniClient;
|
|
58
|
-
export declare function useCache(): Cache;
|
|
59
34
|
export declare function updateLocalSession(session: App.Session): void;
|
|
60
|
-
export declare function useSession(): [App.Session, (newSession: Partial<App.Session>) => void];
|
|
61
35
|
export declare function useCurrentVariables(): GraphQLVariables;
|
|
62
36
|
export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentHandle<any, _Data, _Input>];
|
|
63
37
|
export type RouterCache = {
|