houdini-react 1.2.0-react.1 → 1.2.6

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.
Files changed (127) hide show
  1. package/README.md +1 -1
  2. package/build/plugin/codegen/entries.d.ts +6 -0
  3. package/build/plugin/codegen/index.d.ts +14 -0
  4. package/build/plugin/codegen/manifest.d.ts +42 -0
  5. package/build/plugin/codegen/render.d.ts +2 -0
  6. package/build/plugin/codegen/router.d.ts +8 -0
  7. package/build/plugin/codegen/typeRoot.d.ts +6 -0
  8. package/build/plugin/config.d.ts +1 -0
  9. package/build/plugin/conventions.d.ts +24 -0
  10. package/build/plugin/dedent.d.ts +1 -0
  11. package/build/plugin/extract.d.ts +1 -1
  12. package/build/plugin/index.d.ts +4 -2
  13. package/build/plugin/vite.d.ts +19 -0
  14. package/build/plugin-cjs/index.js +32672 -1115
  15. package/build/plugin-esm/index.js +32666 -1111
  16. package/build/runtime/client.d.ts +3 -0
  17. package/build/runtime/clientPlugin.d.ts +3 -0
  18. package/build/runtime/hooks/useDocumentHandle.d.ts +4 -4
  19. package/build/runtime/hooks/useDocumentStore.d.ts +6 -5
  20. package/build/runtime/hooks/useDocumentSubscription.d.ts +4 -3
  21. package/build/runtime/hooks/useFragment.d.ts +3 -2
  22. package/build/runtime/hooks/useFragmentHandle.d.ts +2 -3
  23. package/build/runtime/hooks/useMutation.d.ts +2 -2
  24. package/build/runtime/hooks/useQuery.d.ts +3 -3
  25. package/build/runtime/hooks/useQueryHandle.d.ts +3 -3
  26. package/build/runtime/hooks/useSubscription.d.ts +2 -2
  27. package/build/runtime/hooks/useSubscriptionHandle.d.ts +3 -3
  28. package/build/runtime/index.d.ts +29 -1
  29. package/build/runtime/manifest.d.ts +3 -0
  30. package/build/runtime/routing/components/Link.d.ts +5 -0
  31. package/build/runtime/routing/components/Router.d.ts +52 -0
  32. package/build/runtime/routing/components/index.d.ts +2 -0
  33. package/build/runtime/routing/index.d.ts +3 -0
  34. package/build/runtime/routing/lib/cache.d.ts +7 -0
  35. package/build/runtime/routing/lib/match.d.ts +38 -0
  36. package/build/runtime/routing/lib/types.d.ts +24 -0
  37. package/build/runtime-cjs/client.d.ts +3 -0
  38. package/build/runtime-cjs/client.js +26 -0
  39. package/build/runtime-cjs/clientPlugin.d.ts +3 -0
  40. package/build/{next-cjs/index.js → runtime-cjs/clientPlugin.js} +15 -26
  41. package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +4 -4
  42. package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -1
  43. package/build/runtime-cjs/hooks/useDocumentStore.d.ts +6 -5
  44. package/build/runtime-cjs/hooks/useDocumentStore.js +9 -4
  45. package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +4 -3
  46. package/build/runtime-cjs/hooks/useDocumentSubscription.js +13 -8
  47. package/build/runtime-cjs/hooks/useFragment.d.ts +3 -2
  48. package/build/runtime-cjs/hooks/useFragment.js +9 -7
  49. package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +2 -3
  50. package/build/runtime-cjs/hooks/useMutation.d.ts +2 -2
  51. package/build/runtime-cjs/hooks/useQuery.d.ts +3 -3
  52. package/build/runtime-cjs/hooks/useQueryHandle.d.ts +3 -3
  53. package/build/runtime-cjs/hooks/useQueryHandle.js +4 -4
  54. package/build/runtime-cjs/hooks/useSubscription.d.ts +2 -2
  55. package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +3 -3
  56. package/build/runtime-cjs/index.d.ts +29 -1
  57. package/build/runtime-cjs/index.js +87 -3
  58. package/build/runtime-cjs/manifest.d.ts +3 -0
  59. package/build/runtime-cjs/manifest.js +27 -0
  60. package/build/runtime-cjs/routing/components/Link.d.ts +5 -0
  61. package/build/runtime-cjs/{hooks/useHoudiniClient.js → routing/components/Link.js} +22 -13
  62. package/build/runtime-cjs/routing/components/Router.d.ts +52 -0
  63. package/build/runtime-cjs/routing/components/Router.js +267 -0
  64. package/build/runtime-cjs/routing/components/index.d.ts +2 -0
  65. package/build/runtime-cjs/{context.js → routing/components/index.js} +13 -19
  66. package/build/runtime-cjs/routing/index.d.ts +3 -0
  67. package/build/runtime-cjs/routing/index.js +30 -0
  68. package/build/runtime-cjs/routing/lib/cache.d.ts +7 -0
  69. package/build/runtime-cjs/{lib → routing/lib}/cache.js +23 -40
  70. package/build/runtime-cjs/routing/lib/match.d.ts +38 -0
  71. package/build/runtime-cjs/routing/lib/match.js +149 -0
  72. package/build/runtime-cjs/routing/lib/types.d.ts +24 -0
  73. package/build/runtime-cjs/routing/lib/types.js +16 -0
  74. package/build/runtime-esm/client.d.ts +3 -0
  75. package/build/runtime-esm/client.js +4 -0
  76. package/build/runtime-esm/clientPlugin.d.ts +3 -0
  77. package/build/runtime-esm/clientPlugin.js +17 -0
  78. package/build/runtime-esm/hooks/useDocumentHandle.d.ts +4 -4
  79. package/build/runtime-esm/hooks/useDocumentHandle.js +1 -4
  80. package/build/runtime-esm/hooks/useDocumentStore.d.ts +6 -5
  81. package/build/runtime-esm/hooks/useDocumentStore.js +9 -4
  82. package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +4 -3
  83. package/build/runtime-esm/hooks/useDocumentSubscription.js +13 -8
  84. package/build/runtime-esm/hooks/useFragment.d.ts +3 -2
  85. package/build/runtime-esm/hooks/useFragment.js +9 -7
  86. package/build/runtime-esm/hooks/useFragmentHandle.d.ts +2 -3
  87. package/build/runtime-esm/hooks/useMutation.d.ts +2 -2
  88. package/build/runtime-esm/hooks/useQuery.d.ts +3 -3
  89. package/build/runtime-esm/hooks/useQueryHandle.d.ts +3 -3
  90. package/build/runtime-esm/hooks/useQueryHandle.js +4 -4
  91. package/build/runtime-esm/hooks/useSubscription.d.ts +2 -2
  92. package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +3 -3
  93. package/build/runtime-esm/index.d.ts +29 -1
  94. package/build/runtime-esm/index.js +79 -2
  95. package/build/runtime-esm/manifest.d.ts +3 -0
  96. package/build/runtime-esm/manifest.js +5 -0
  97. package/build/runtime-esm/routing/components/Link.d.ts +5 -0
  98. package/build/runtime-esm/routing/components/Link.js +21 -0
  99. package/build/runtime-esm/routing/components/Router.d.ts +52 -0
  100. package/build/runtime-esm/routing/components/Router.js +230 -0
  101. package/build/runtime-esm/routing/components/index.d.ts +2 -0
  102. package/build/runtime-esm/routing/components/index.js +8 -0
  103. package/build/runtime-esm/routing/index.d.ts +3 -0
  104. package/build/runtime-esm/routing/index.js +5 -0
  105. package/build/runtime-esm/routing/lib/cache.d.ts +7 -0
  106. package/build/runtime-esm/routing/lib/cache.js +29 -0
  107. package/build/runtime-esm/routing/lib/match.d.ts +38 -0
  108. package/build/runtime-esm/routing/lib/match.js +122 -0
  109. package/build/runtime-esm/routing/lib/types.d.ts +24 -0
  110. package/build/runtime-esm/routing/lib/types.js +0 -0
  111. package/package.json +7 -11
  112. package/build/next/index.d.ts +0 -2
  113. package/build/next-cjs/package.json +0 -1
  114. package/build/next-esm/index.js +0 -26
  115. package/build/next-esm/package.json +0 -1
  116. package/build/runtime/context.d.ts +0 -7
  117. package/build/runtime/hooks/useHoudiniClient.d.ts +0 -2
  118. package/build/runtime/lib/cache.d.ts +0 -62
  119. package/build/runtime-cjs/context.d.ts +0 -7
  120. package/build/runtime-cjs/hooks/useHoudiniClient.d.ts +0 -2
  121. package/build/runtime-cjs/lib/cache.d.ts +0 -62
  122. package/build/runtime-esm/context.d.ts +0 -7
  123. package/build/runtime-esm/context.js +0 -10
  124. package/build/runtime-esm/hooks/useHoudiniClient.d.ts +0 -2
  125. package/build/runtime-esm/hooks/useHoudiniClient.js +0 -12
  126. package/build/runtime-esm/lib/cache.d.ts +0 -62
  127. package/build/runtime-esm/lib/cache.js +0 -47
@@ -1,10 +1,10 @@
1
- import type { MutationArtifact, GraphQLObject, QueryResult } from '$houdini/runtime/lib/types';
1
+ import type { MutationArtifact, GraphQLObject, QueryResult, GraphQLVariables } from '$houdini/runtime/lib/types';
2
2
  export type MutationHandler<_Result, _Input, _Optimistic extends GraphQLObject> = (args: {
3
3
  variables: _Input;
4
4
  metadata?: App.Metadata;
5
5
  fetch?: typeof globalThis.fetch;
6
6
  optimisticResponse?: _Optimistic;
7
7
  }) => Promise<QueryResult<_Result, _Input>>;
8
- export declare function useMutation<_Result extends GraphQLObject, _Input extends {}, _Optimistic extends GraphQLObject>({ artifact, }: {
8
+ export declare function useMutation<_Result extends GraphQLObject, _Input extends GraphQLVariables, _Optimistic extends GraphQLObject>({ artifact, }: {
9
9
  artifact: MutationArtifact;
10
10
  }): [boolean, MutationHandler<_Result, _Input, _Optimistic>];
@@ -1,5 +1,5 @@
1
- import { type QueryArtifact, GraphQLObject } from '$houdini/runtime/lib/types';
2
- import { UseQueryConfig } from './useQueryHandle';
3
- export declare function useQuery<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends {} = []>(document: {
1
+ import type { GraphQLVariables, GraphQLObject, QueryArtifact } from '$houdini/runtime/lib/types';
2
+ import type { UseQueryConfig } from './useQueryHandle';
3
+ export declare function useQuery<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables>(document: {
4
4
  artifact: QueryArtifact;
5
5
  }, variables?: any, config?: UseQueryConfig): _Data;
@@ -1,6 +1,6 @@
1
- import { type QueryArtifact, GraphQLObject, CachePolicies } from '$houdini/runtime/lib/types';
2
- import { DocumentHandle } from './useDocumentHandle';
3
- export declare function useQueryHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends {} = []>({ artifact }: {
1
+ import type { GraphQLObject, CachePolicies, QueryArtifact, GraphQLVariables } from '$houdini/runtime/lib/types';
2
+ import type { DocumentHandle } from './useDocumentHandle';
3
+ export declare function useQueryHandle<_Artifact extends QueryArtifact, _Data extends GraphQLObject = GraphQLObject, _Input extends GraphQLVariables = GraphQLVariables>({ artifact }: {
4
4
  artifact: QueryArtifact;
5
5
  }, variables?: any, config?: UseQueryConfig): DocumentHandle<_Artifact, _Data, _Input>;
6
6
  export type UseQueryConfig = {
@@ -1,13 +1,13 @@
1
+ import { createLRUCache } from "$houdini/runtime/lib/lru";
1
2
  import React from "react";
2
- import { createCache } from "../lib/cache";
3
+ import { useClient } from "../routing";
3
4
  import { useDocumentHandle } from "./useDocumentHandle";
4
- import { useHoudiniClient } from "./useHoudiniClient";
5
5
  import { useIsMountedRef } from "./useIsMounted";
6
- const promiseCache = createCache();
6
+ const promiseCache = createLRUCache();
7
7
  function useQueryHandle({ artifact }, variables = null, config = {}) {
8
8
  const identifier = queryIdentifier({ artifact, variables, config });
9
9
  const suspenseValue = promiseCache.get(identifier);
10
- const client = useHoudiniClient();
10
+ const client = useClient();
11
11
  const isMountedRef = useIsMountedRef();
12
12
  let [observer] = React.useState(
13
13
  client.observe({
@@ -1,4 +1,4 @@
1
- import { SubscriptionArtifact, GraphQLObject } from '$houdini/runtime/lib/types';
2
- export declare function useSubscription<_Result extends GraphQLObject, _Input extends {}>(document: {
1
+ import type { SubscriptionArtifact, GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
2
+ export declare function useSubscription<_Result extends GraphQLObject, _Input extends GraphQLVariables>(document: {
3
3
  artifact: SubscriptionArtifact;
4
4
  }, variables: _Input): import("houdini").GraphQLObject | null;
@@ -1,5 +1,5 @@
1
- import { SubscriptionArtifact, GraphQLObject } from '$houdini/runtime/lib/types';
2
- export type SubscriptionHandle<_Result extends GraphQLObject, _Input extends {} | null> = {
1
+ import type { SubscriptionArtifact, GraphQLObject, GraphQLVariables } from '$houdini/runtime/lib/types';
2
+ export type SubscriptionHandle<_Result extends GraphQLObject, _Input extends GraphQLVariables> = {
3
3
  data: _Result | null;
4
4
  errors: {
5
5
  message: string;
@@ -11,7 +11,7 @@ export type SubscriptionHandle<_Result extends GraphQLObject, _Input extends {}
11
11
  unlisten: () => void;
12
12
  fetching: boolean;
13
13
  };
14
- export declare function useSubscriptionHandle<_Result extends GraphQLObject, _Input extends {}>({ artifact }: {
14
+ export declare function useSubscriptionHandle<_Result extends GraphQLObject, _Input extends GraphQLVariables>({ artifact }: {
15
15
  artifact: SubscriptionArtifact;
16
16
  }, variables: _Input): {
17
17
  data: import("houdini").GraphQLObject | null;
@@ -1,2 +1,30 @@
1
+ import type { Cache } from '$houdini/runtime/cache/cache';
2
+ import { DocumentStore } from '$houdini/runtime/client';
3
+ import { LRUCache } from '$houdini/runtime/lib/lru';
4
+ import { GraphQLObject, GraphQLVariables, QueryArtifact } from '$houdini/runtime/lib/types';
5
+ import React from 'react';
6
+ import { PendingCache } from './routing/components/Router';
7
+ import { SuspenseCache } from './routing/lib/cache';
1
8
  export * from './hooks';
2
- export { HoudiniProvider } from './context';
9
+ export * from './routing';
10
+ export declare function Router({ cache, intialURL, artifact_cache, component_cache, data_cache, pending_cache, last_variables, loaded_queries, loaded_artifacts, }: {
11
+ intialURL: string;
12
+ cache: Cache;
13
+ loaded_queries?: Record<string, {
14
+ data: GraphQLObject;
15
+ variables: GraphQLVariables;
16
+ }>;
17
+ loaded_artifacts?: Record<string, QueryArtifact>;
18
+ } & RouterCache): JSX.Element;
19
+ type RouterCache = {
20
+ artifact_cache: SuspenseCache<QueryArtifact>;
21
+ component_cache: SuspenseCache<(props: any) => React.ReactElement>;
22
+ data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
23
+ last_variables: LRUCache<GraphQLVariables>;
24
+ pending_cache: PendingCache;
25
+ };
26
+ export declare function router_cache({ pending_queries, artifacts, components, }?: {
27
+ pending_queries?: string[];
28
+ artifacts?: Record<string, QueryArtifact>;
29
+ components?: Record<string, (props: any) => React.ReactElement>;
30
+ }): RouterCache;
@@ -1,5 +1,82 @@
1
+ import React from "react";
2
+ import client from "./client";
3
+ import manifest from "./manifest";
4
+ import { Router as RouterImpl, RouterContextProvider } from "./routing";
5
+ import { suspense_cache } from "./routing/lib/cache";
1
6
  export * from "./hooks";
2
- import { HoudiniProvider } from "./context";
7
+ export * from "./routing";
8
+ function Router({
9
+ cache,
10
+ intialURL,
11
+ artifact_cache,
12
+ component_cache,
13
+ data_cache,
14
+ pending_cache,
15
+ last_variables,
16
+ loaded_queries,
17
+ loaded_artifacts
18
+ }) {
19
+ return /* @__PURE__ */ React.createElement(
20
+ RouterContextProvider,
21
+ {
22
+ client,
23
+ cache,
24
+ artifact_cache,
25
+ component_cache,
26
+ data_cache,
27
+ pending_cache,
28
+ last_variables
29
+ },
30
+ /* @__PURE__ */ React.createElement(
31
+ RouterImpl,
32
+ {
33
+ intialURL,
34
+ manifest,
35
+ loaded_queries,
36
+ loaded_artifacts
37
+ }
38
+ )
39
+ );
40
+ }
41
+ function router_cache({
42
+ pending_queries = [],
43
+ artifacts = {},
44
+ components = {}
45
+ } = {}) {
46
+ const result = {
47
+ artifact_cache: suspense_cache(),
48
+ component_cache: suspense_cache(),
49
+ data_cache: suspense_cache(),
50
+ pending_cache: suspense_cache(),
51
+ last_variables: suspense_cache()
52
+ };
53
+ for (const query of pending_queries) {
54
+ result.pending_cache.set(query, signal_promise());
55
+ }
56
+ for (const [name, artifact] of Object.entries(artifacts)) {
57
+ result.artifact_cache.set(name, artifact);
58
+ }
59
+ for (const [name, component] of Object.entries(components)) {
60
+ result.component_cache.set(name, component);
61
+ }
62
+ return result;
63
+ }
64
+ function signal_promise() {
65
+ let resolve = () => {
66
+ };
67
+ let reject = () => {
68
+ };
69
+ const promise = new Promise((res, rej) => {
70
+ resolve = res;
71
+ reject = rej;
72
+ });
73
+ return {
74
+ ...promise,
75
+ resolve,
76
+ reject
77
+ };
78
+ }
3
79
  export {
4
- HoudiniProvider
80
+ Router,
81
+ router_cache
5
82
  };
@@ -0,0 +1,3 @@
1
+ import type { RouterManifest } from './routing';
2
+ declare const manifest: RouterManifest;
3
+ export default manifest;
@@ -0,0 +1,5 @@
1
+ const manifest = {};
2
+ var manifest_default = manifest;
3
+ export {
4
+ manifest_default as default
5
+ };
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare function Link({ href, children, style, ...props }: {
3
+ href: string;
4
+ children: React.ReactNode;
5
+ } & React.AnchorHTMLAttributes<HTMLAnchorElement>): JSX.Element;
@@ -0,0 +1,21 @@
1
+ import React, { useTransition } from "react";
2
+ import { useNavigationContext } from "./Router";
3
+ function Link({
4
+ href,
5
+ children,
6
+ style,
7
+ ...props
8
+ }) {
9
+ const { goto } = useNavigationContext();
10
+ const [pending, startTransition] = useTransition();
11
+ const click = (e) => {
12
+ e.preventDefault();
13
+ startTransition(() => {
14
+ goto(href);
15
+ });
16
+ };
17
+ return /* @__PURE__ */ React.createElement("a", { href, onClick: click, style, ...props }, children);
18
+ }
19
+ export {
20
+ Link
21
+ };
@@ -0,0 +1,52 @@
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 React from 'react';
7
+ import { SuspenseCache } from '../lib/cache';
8
+ import type { NavigationContext, RouterManifest } from '../lib/types';
9
+ /**
10
+ * Router is the top level entry point for the filesystem-based router.
11
+ * It is responsible for loading various page sources (including API fetches) and
12
+ * then rendering when appropriate.
13
+ */
14
+ export declare function Router({ manifest, intialURL, loaded_queries, loaded_artifacts, }: {
15
+ manifest: RouterManifest;
16
+ intialURL?: string;
17
+ loaded_queries?: Record<string, {
18
+ data: GraphQLObject;
19
+ variables: GraphQLVariables;
20
+ }>;
21
+ loaded_artifacts?: Record<string, QueryArtifact>;
22
+ }): JSX.Element;
23
+ export declare function useNavigationContext(): NavigationContext;
24
+ export declare function RouterContextProvider({ children, client, cache, artifact_cache, component_cache, data_cache, pending_cache, last_variables, }: {
25
+ children: React.ReactElement;
26
+ client: HoudiniClient;
27
+ cache: Cache;
28
+ artifact_cache: SuspenseCache<QueryArtifact>;
29
+ component_cache: SuspenseCache<(props: any) => React.ReactElement>;
30
+ data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
31
+ pending_cache: PendingCache;
32
+ last_variables: LRUCache<GraphQLVariables>;
33
+ }): JSX.Element;
34
+ type RouterContext = {
35
+ client: HoudiniClient;
36
+ cache: Cache;
37
+ artifact_cache: SuspenseCache<QueryArtifact>;
38
+ component_cache: SuspenseCache<(props: any) => React.ReactElement>;
39
+ data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
40
+ pending_cache: PendingCache;
41
+ last_variables: LRUCache<GraphQLVariables>;
42
+ };
43
+ export type PendingCache = SuspenseCache<Promise<void> & {
44
+ resolve: () => void;
45
+ reject: () => void;
46
+ }>;
47
+ export declare const useRouterContext: () => RouterContext;
48
+ export declare function useClient(): HoudiniClient;
49
+ export declare function useCache(): Cache;
50
+ export declare function useCurrentVariables(): GraphQLVariables;
51
+ export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
52
+ export {};
@@ -0,0 +1,230 @@
1
+ import { deepEquals } from "$houdini/runtime/lib/deepEquals";
2
+ import React from "react";
3
+ import { useStream } from "react-streaming";
4
+ import { useDocumentStore } from "../../hooks/useDocumentStore";
5
+ import { find_match } from "../lib/match";
6
+ const NavContext = React.createContext({
7
+ currentRoute: "/",
8
+ goto: () => {
9
+ throw new Error("NOT FOUND");
10
+ }
11
+ });
12
+ function Router({
13
+ manifest,
14
+ intialURL,
15
+ loaded_queries,
16
+ loaded_artifacts
17
+ }) {
18
+ const [current, setCurrent] = React.useState(() => {
19
+ return intialURL || window.location.pathname;
20
+ });
21
+ const [page, variables] = find_match(manifest, current);
22
+ useLoadPage({ page, variables, loaded_queries, loaded_artifacts });
23
+ const { component_cache } = useRouterContext();
24
+ const PageComponent = component_cache.get(page.id);
25
+ React.useEffect(() => {
26
+ if (window.location.pathname !== current) {
27
+ window.history.pushState({}, "", current);
28
+ }
29
+ }, [current]);
30
+ React.useEffect(() => {
31
+ const onChange = (evt) => {
32
+ setCurrent(window.location.pathname);
33
+ };
34
+ window.addEventListener("popstate", onChange);
35
+ return () => {
36
+ window.removeEventListener("popstate", onChange);
37
+ };
38
+ }, []);
39
+ return /* @__PURE__ */ React.createElement(
40
+ NavContext.Provider,
41
+ {
42
+ value: {
43
+ currentRoute: current,
44
+ goto: setCurrent
45
+ }
46
+ },
47
+ /* @__PURE__ */ React.createElement(VariableContext.Provider, { value: variables }, /* @__PURE__ */ React.createElement(PageComponent, { url: current }))
48
+ );
49
+ }
50
+ function useLoadPage({
51
+ page,
52
+ variables,
53
+ loaded_queries,
54
+ loaded_artifacts
55
+ }) {
56
+ const {
57
+ client,
58
+ cache,
59
+ data_cache,
60
+ component_cache,
61
+ artifact_cache,
62
+ pending_cache,
63
+ last_variables
64
+ } = useRouterContext();
65
+ const stream = useStream();
66
+ function load_query({ id, artifact }) {
67
+ last_variables.set(page.id, variables);
68
+ if (pending_cache.has(id)) {
69
+ return pending_cache.get(id);
70
+ }
71
+ const observer = client.observe({ artifact, cache });
72
+ let resolve = () => {
73
+ };
74
+ let reject = () => {
75
+ };
76
+ const promise = new Promise((res, rej) => {
77
+ resolve = res;
78
+ reject = rej;
79
+ observer.send({
80
+ variables,
81
+ cacheParams: { disableSubscriptions: true }
82
+ }).then(() => {
83
+ data_cache.set(id, observer);
84
+ if (loaded_queries) {
85
+ loaded_queries[artifact.name] = {
86
+ data: observer.state.data,
87
+ variables
88
+ };
89
+ }
90
+ stream?.injectToStream(`
91
+ <script>
92
+ window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
93
+
94
+ if (window.__houdini__nav_caches__?.pending_cache.has("${artifact.name}")) {
95
+ // before we resolve the pending signals,
96
+ // fill the data cache with values we got on the server
97
+ const new_store = window.__houdini__client__.observe({
98
+ artifact: window.__houdini__nav_caches__.artifact_cache.get("${artifact.name}"),
99
+ cache: window.__houdini__cache__,
100
+ initialValue: ${JSON.stringify(observer.state.data)}
101
+ })
102
+
103
+ window.__houdini__nav_caches__.data_cache.set("${artifact.name}", new_store)
104
+
105
+ // we're pushing this store onto the client, it should be initialized
106
+ new_store.send({
107
+ setup: true,
108
+ variables: ${JSON.stringify(variables)}
109
+ })
110
+
111
+ // notify anyone waiting on the pending cache
112
+ window.__houdini__nav_caches__.pending_cache.get("${artifact.name}").resolve()
113
+ window.__houdini__nav_caches__.pending_cache.delete("${artifact.name}")
114
+ }
115
+ <\/script>
116
+ `);
117
+ resolve();
118
+ }).catch(reject).finally(() => {
119
+ pending_cache.delete(id);
120
+ });
121
+ });
122
+ pending_cache.set(id, { ...promise, resolve, reject });
123
+ return pending_cache.get(id);
124
+ }
125
+ if (last_variables.has(page.id) && !deepEquals(last_variables.get(page.id), variables)) {
126
+ data_cache.clear();
127
+ }
128
+ const missing_artifacts = [];
129
+ const found_artifacts = {};
130
+ for (const key of Object.keys(page.documents)) {
131
+ if (artifact_cache.has(key)) {
132
+ found_artifacts[key] = artifact_cache.get(key);
133
+ } else {
134
+ missing_artifacts.push(key);
135
+ }
136
+ }
137
+ for (const artifact_id of missing_artifacts) {
138
+ page.documents[artifact_id].artifact().then((mod) => {
139
+ const artifact = mod.default;
140
+ artifact_cache.set(artifact_id, artifact);
141
+ if (loaded_artifacts) {
142
+ loaded_artifacts[artifact.name] = artifact;
143
+ }
144
+ stream?.injectToStream(`
145
+ <script type="module" src="@@houdini/artifact/${artifact.name}.js" async=""><\/script>
146
+ `);
147
+ load_query({ id: artifact.name, artifact });
148
+ }).catch((err) => {
149
+ console.log(err);
150
+ });
151
+ }
152
+ for (const artifact of Object.values(found_artifacts)) {
153
+ if (!data_cache.has(artifact.name)) {
154
+ load_query({ id: artifact.name, artifact });
155
+ }
156
+ }
157
+ if (!component_cache.has(page.id)) {
158
+ throw new Promise((resolve, reject) => {
159
+ page.component().then((mod) => {
160
+ component_cache.set(page.id, mod.default);
161
+ resolve();
162
+ }).catch(reject);
163
+ });
164
+ }
165
+ }
166
+ function useNavigationContext() {
167
+ return React.useContext(NavContext);
168
+ }
169
+ function RouterContextProvider({
170
+ children,
171
+ client,
172
+ cache,
173
+ artifact_cache,
174
+ component_cache,
175
+ data_cache,
176
+ pending_cache,
177
+ last_variables
178
+ }) {
179
+ return /* @__PURE__ */ React.createElement(
180
+ Context.Provider,
181
+ {
182
+ value: {
183
+ client,
184
+ cache,
185
+ artifact_cache,
186
+ component_cache,
187
+ data_cache,
188
+ pending_cache,
189
+ last_variables
190
+ }
191
+ },
192
+ children
193
+ );
194
+ }
195
+ const Context = React.createContext(null);
196
+ const useRouterContext = () => {
197
+ const ctx = React.useContext(Context);
198
+ if (!ctx) {
199
+ throw new Error("Could not find router context");
200
+ }
201
+ return ctx;
202
+ };
203
+ function useClient() {
204
+ return useRouterContext().client;
205
+ }
206
+ function useCache() {
207
+ return useRouterContext().cache;
208
+ }
209
+ function useCurrentVariables() {
210
+ return React.useContext(VariableContext);
211
+ }
212
+ const VariableContext = React.createContext(null);
213
+ function useQueryResult(name) {
214
+ const store_ref = useRouterContext().data_cache.get(name);
215
+ const [{ data }, observer] = useDocumentStore({
216
+ artifact: store_ref.artifact,
217
+ observer: store_ref
218
+ });
219
+ return [data, observer];
220
+ }
221
+ export {
222
+ Router,
223
+ RouterContextProvider,
224
+ useCache,
225
+ useClient,
226
+ useCurrentVariables,
227
+ useNavigationContext,
228
+ useQueryResult,
229
+ useRouterContext
230
+ };
@@ -0,0 +1,2 @@
1
+ export { Link } from './Link';
2
+ export { Router, RouterContextProvider, useClient } from './Router';
@@ -0,0 +1,8 @@
1
+ import { Link } from "./Link";
2
+ import { Router, RouterContextProvider, useClient } from "./Router";
3
+ export {
4
+ Link,
5
+ Router,
6
+ RouterContextProvider,
7
+ useClient
8
+ };
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export { suspense_cache } from './lib/cache';
3
+ export type { RouterManifest, RouterPageManifest } from './lib/types';
@@ -0,0 +1,5 @@
1
+ export * from "./components";
2
+ import { suspense_cache } from "./lib/cache";
3
+ export {
4
+ suspense_cache
5
+ };
@@ -0,0 +1,7 @@
1
+ import { LRUCache } from '$houdini/runtime/lib/lru';
2
+ export declare function suspense_cache<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
+ }
@@ -0,0 +1,29 @@
1
+ import { LRUCache } from "$houdini/runtime/lib/lru";
2
+ function suspense_cache() {
3
+ return new SuspenseCache();
4
+ }
5
+ class SuspenseCache extends LRUCache {
6
+ #callbacks = /* @__PURE__ */ new Map();
7
+ get(key) {
8
+ if (super.has(key)) {
9
+ return super.get(key);
10
+ }
11
+ throw new Promise((resolve, reject) => {
12
+ this.#subscribe(key, resolve, reject);
13
+ });
14
+ }
15
+ set(key, value) {
16
+ super.set(key, value);
17
+ if (this.#callbacks.has(key)) {
18
+ this.#callbacks.get(key)?.forEach(({ resolve }) => resolve());
19
+ this.#callbacks.delete(key);
20
+ }
21
+ }
22
+ #subscribe(key, resolve, reject) {
23
+ this.#callbacks.set(key, [...this.#callbacks.get(key) || [], { resolve, reject }]);
24
+ }
25
+ }
26
+ export {
27
+ SuspenseCache,
28
+ suspense_cache
29
+ };
@@ -0,0 +1,38 @@
1
+ import type { GraphQLVariables } from '$houdini/runtime/lib/types';
2
+ import type { RouterManifest, RouterPageManifest } from './types';
3
+ export type RouteParam = {
4
+ name: string;
5
+ matcher: string;
6
+ optional: boolean;
7
+ rest: boolean;
8
+ chained: boolean;
9
+ };
10
+ export interface ParamMatcher {
11
+ (param: string): boolean;
12
+ }
13
+ export declare function find_match(manifest: RouterManifest, current: string, allowNull: true): [RouterPageManifest | null, GraphQLVariables];
14
+ export declare function find_match(manifest: RouterManifest, current: string, allowNull?: false): [RouterPageManifest, GraphQLVariables];
15
+ /**
16
+ * Creates the regex pattern, extracts parameter names, and generates types for a route
17
+ */
18
+ export declare function parse_page_pattern(id: string): {
19
+ pattern: RegExp;
20
+ params: RouteParam[];
21
+ page_id: string;
22
+ };
23
+ /**
24
+ * Splits a route id into its segments, removing segments that
25
+ * don't affect the path (i.e. groups). The root route is represented by `/`
26
+ * and will be returned as `['']`.
27
+ */
28
+ export declare function get_route_segments(route: string): string[];
29
+ export declare function exec(match: RegExpMatchArray, params: RouteParam[]): Record<string, string> | undefined;
30
+ /**
31
+ Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38
+ */