houdini-react 1.2.0-react.1 → 1.2.7

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 (134) 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 +2 -1
  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 +16 -3
  13. package/build/plugin/vite.d.ts +19 -0
  14. package/build/plugin-cjs/index.js +132171 -43771
  15. package/build/plugin-esm/index.js +132162 -43765
  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 +30 -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 +56 -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 +23 -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 +11 -7
  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 +15 -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/useMutation.js +3 -1
  52. package/build/runtime-cjs/hooks/useQuery.d.ts +3 -3
  53. package/build/runtime-cjs/hooks/useQueryHandle.d.ts +3 -3
  54. package/build/runtime-cjs/hooks/useQueryHandle.js +4 -4
  55. package/build/runtime-cjs/hooks/useSubscription.d.ts +2 -2
  56. package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +3 -3
  57. package/build/runtime-cjs/index.d.ts +30 -1
  58. package/build/runtime-cjs/index.js +89 -3
  59. package/build/runtime-cjs/manifest.d.ts +3 -0
  60. package/build/runtime-cjs/manifest.js +27 -0
  61. package/build/runtime-cjs/routing/components/Link.d.ts +5 -0
  62. package/build/runtime-cjs/{hooks/useHoudiniClient.js → routing/components/Link.js} +22 -13
  63. package/build/runtime-cjs/routing/components/Router.d.ts +56 -0
  64. package/build/runtime-cjs/routing/components/Router.js +296 -0
  65. package/build/runtime-cjs/routing/components/index.d.ts +2 -0
  66. package/build/runtime-cjs/{context.js → routing/components/index.js} +15 -19
  67. package/build/runtime-cjs/routing/index.d.ts +3 -0
  68. package/build/runtime-cjs/routing/index.js +30 -0
  69. package/build/runtime-cjs/routing/lib/cache.d.ts +7 -0
  70. package/build/runtime-cjs/{lib → routing/lib}/cache.js +23 -40
  71. package/build/runtime-cjs/routing/lib/match.d.ts +38 -0
  72. package/build/runtime-cjs/routing/lib/match.js +149 -0
  73. package/build/runtime-cjs/routing/lib/types.d.ts +23 -0
  74. package/build/runtime-cjs/routing/lib/types.js +16 -0
  75. package/build/runtime-esm/client.d.ts +3 -0
  76. package/build/runtime-esm/client.js +4 -0
  77. package/build/runtime-esm/clientPlugin.d.ts +3 -0
  78. package/build/runtime-esm/clientPlugin.js +17 -0
  79. package/build/runtime-esm/hooks/useDocumentHandle.d.ts +4 -4
  80. package/build/runtime-esm/hooks/useDocumentHandle.js +12 -10
  81. package/build/runtime-esm/hooks/useDocumentStore.d.ts +6 -5
  82. package/build/runtime-esm/hooks/useDocumentStore.js +9 -4
  83. package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +4 -3
  84. package/build/runtime-esm/hooks/useDocumentSubscription.js +15 -8
  85. package/build/runtime-esm/hooks/useFragment.d.ts +3 -2
  86. package/build/runtime-esm/hooks/useFragment.js +9 -7
  87. package/build/runtime-esm/hooks/useFragmentHandle.d.ts +2 -3
  88. package/build/runtime-esm/hooks/useMutation.d.ts +2 -2
  89. package/build/runtime-esm/hooks/useMutation.js +3 -1
  90. package/build/runtime-esm/hooks/useQuery.d.ts +3 -3
  91. package/build/runtime-esm/hooks/useQueryHandle.d.ts +3 -3
  92. package/build/runtime-esm/hooks/useQueryHandle.js +4 -4
  93. package/build/runtime-esm/hooks/useSubscription.d.ts +2 -2
  94. package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +3 -3
  95. package/build/runtime-esm/index.d.ts +30 -1
  96. package/build/runtime-esm/index.js +81 -2
  97. package/build/runtime-esm/manifest.d.ts +3 -0
  98. package/build/runtime-esm/manifest.js +5 -0
  99. package/build/runtime-esm/routing/components/Link.d.ts +5 -0
  100. package/build/runtime-esm/routing/components/Link.js +21 -0
  101. package/build/runtime-esm/routing/components/Router.d.ts +56 -0
  102. package/build/runtime-esm/routing/components/Router.js +257 -0
  103. package/build/runtime-esm/routing/components/index.d.ts +2 -0
  104. package/build/runtime-esm/routing/components/index.js +9 -0
  105. package/build/runtime-esm/routing/index.d.ts +3 -0
  106. package/build/runtime-esm/routing/index.js +5 -0
  107. package/build/runtime-esm/routing/lib/cache.d.ts +7 -0
  108. package/build/runtime-esm/routing/lib/cache.js +29 -0
  109. package/build/runtime-esm/routing/lib/match.d.ts +38 -0
  110. package/build/runtime-esm/routing/lib/match.js +122 -0
  111. package/build/runtime-esm/routing/lib/types.d.ts +23 -0
  112. package/build/runtime-esm/routing/lib/types.js +0 -0
  113. package/build/server/compat.d.ts +7 -0
  114. package/build/server/index.d.ts +17 -0
  115. package/build/server/session.d.ts +3 -0
  116. package/build/server-cjs/index.js +166712 -0
  117. package/build/server-esm/index.js +166703 -0
  118. package/package.json +21 -10
  119. package/build/next/index.d.ts +0 -2
  120. package/build/next-esm/index.js +0 -26
  121. package/build/runtime/context.d.ts +0 -7
  122. package/build/runtime/hooks/useHoudiniClient.d.ts +0 -2
  123. package/build/runtime/lib/cache.d.ts +0 -62
  124. package/build/runtime-cjs/context.d.ts +0 -7
  125. package/build/runtime-cjs/hooks/useHoudiniClient.d.ts +0 -2
  126. package/build/runtime-cjs/lib/cache.d.ts +0 -62
  127. package/build/runtime-esm/context.d.ts +0 -7
  128. package/build/runtime-esm/context.js +0 -10
  129. package/build/runtime-esm/hooks/useHoudiniClient.d.ts +0 -2
  130. package/build/runtime-esm/hooks/useHoudiniClient.js +0 -12
  131. package/build/runtime-esm/lib/cache.d.ts +0 -62
  132. package/build/runtime-esm/lib/cache.js +0 -47
  133. /package/build/{next-cjs → server-cjs}/package.json +0 -0
  134. /package/build/{next-esm → server-esm}/package.json +0 -0
@@ -0,0 +1,56 @@
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, session: ssrSession, }: {
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
+ session?: App.Session;
34
+ }): JSX.Element;
35
+ type RouterContext = {
36
+ client: HoudiniClient;
37
+ cache: Cache;
38
+ artifact_cache: SuspenseCache<QueryArtifact>;
39
+ component_cache: SuspenseCache<(props: any) => React.ReactElement>;
40
+ data_cache: SuspenseCache<DocumentStore<GraphQLObject, GraphQLVariables>>;
41
+ pending_cache: PendingCache;
42
+ last_variables: LRUCache<GraphQLVariables>;
43
+ session: App.Session;
44
+ };
45
+ export type PendingCache = SuspenseCache<Promise<void> & {
46
+ resolve: () => void;
47
+ reject: () => void;
48
+ }>;
49
+ export declare const useRouterContext: () => RouterContext;
50
+ export declare function useClient(): HoudiniClient;
51
+ export declare function useCache(): Cache;
52
+ export declare function updateLocalSession(session: App.Session): void;
53
+ export declare function useSession(): App.Session;
54
+ export declare function useCurrentVariables(): GraphQLVariables;
55
+ export declare function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(name: string): [_Data | null, DocumentStore<_Data, _Input>];
56
+ export {};
@@ -0,0 +1,257 @@
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
+ const session = useSession();
67
+ function load_query({ id, artifact }) {
68
+ last_variables.set(page.id, variables);
69
+ if (pending_cache.has(id)) {
70
+ return pending_cache.get(id);
71
+ }
72
+ const observer = client.observe({ artifact, cache });
73
+ let resolve = () => {
74
+ };
75
+ let reject = () => {
76
+ };
77
+ const promise = new Promise((res, rej) => {
78
+ resolve = res;
79
+ reject = rej;
80
+ observer.send({
81
+ variables,
82
+ cacheParams: { disableSubscriptions: true },
83
+ session
84
+ }).then(() => {
85
+ data_cache.set(id, observer);
86
+ if (loaded_queries) {
87
+ loaded_queries[artifact.name] = {
88
+ data: observer.state.data,
89
+ variables
90
+ };
91
+ }
92
+ stream?.injectToStream(`
93
+ <script>
94
+ window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
95
+
96
+ if (window.__houdini__nav_caches__?.pending_cache.has("${artifact.name}")) {
97
+ // before we resolve the pending signals,
98
+ // fill the data cache with values we got on the server
99
+ const new_store = window.__houdini__client__.observe({
100
+ artifact: window.__houdini__nav_caches__.artifact_cache.get("${artifact.name}"),
101
+ cache: window.__houdini__cache__,
102
+ initialValue: ${JSON.stringify(observer.state.data)}
103
+ })
104
+
105
+ window.__houdini__nav_caches__.data_cache.set("${artifact.name}", new_store)
106
+
107
+ // we're pushing this store onto the client, it should be initialized
108
+ new_store.send({
109
+ setup: true,
110
+ variables: ${JSON.stringify(variables)}
111
+ })
112
+
113
+ // notify anyone waiting on the pending cache
114
+ window.__houdini__nav_caches__.pending_cache.get("${artifact.name}").resolve()
115
+ window.__houdini__nav_caches__.pending_cache.delete("${artifact.name}")
116
+ }
117
+ <\/script>
118
+ `);
119
+ resolve();
120
+ }).catch(reject).finally(() => {
121
+ pending_cache.delete(id);
122
+ });
123
+ });
124
+ pending_cache.set(id, { ...promise, resolve, reject });
125
+ return pending_cache.get(id);
126
+ }
127
+ if (last_variables.has(page.id) && !deepEquals(last_variables.get(page.id), variables)) {
128
+ data_cache.clear();
129
+ }
130
+ const missing_artifacts = [];
131
+ const found_artifacts = {};
132
+ for (const key of Object.keys(page.documents)) {
133
+ if (artifact_cache.has(key)) {
134
+ found_artifacts[key] = artifact_cache.get(key);
135
+ } else {
136
+ missing_artifacts.push(key);
137
+ }
138
+ }
139
+ for (const artifact_id of missing_artifacts) {
140
+ page.documents[artifact_id].artifact().then((mod) => {
141
+ const artifact = mod.default;
142
+ artifact_cache.set(artifact_id, artifact);
143
+ if (loaded_artifacts) {
144
+ loaded_artifacts[artifact.name] = artifact;
145
+ }
146
+ stream?.injectToStream(`
147
+ <script type="module" src="@@houdini/artifact/${artifact.name}.js" async=""><\/script>
148
+ `);
149
+ load_query({ id: artifact.name, artifact });
150
+ }).catch((err) => {
151
+ console.log(err);
152
+ });
153
+ }
154
+ for (const artifact of Object.values(found_artifacts)) {
155
+ if (!data_cache.has(artifact.name)) {
156
+ load_query({ id: artifact.name, artifact });
157
+ }
158
+ }
159
+ if (!component_cache.has(page.id)) {
160
+ throw new Promise((resolve, reject) => {
161
+ page.component().then((mod) => {
162
+ component_cache.set(page.id, mod.default);
163
+ resolve();
164
+ }).catch(reject);
165
+ });
166
+ }
167
+ }
168
+ function useNavigationContext() {
169
+ return React.useContext(NavContext);
170
+ }
171
+ function RouterContextProvider({
172
+ children,
173
+ client,
174
+ cache,
175
+ artifact_cache,
176
+ component_cache,
177
+ data_cache,
178
+ pending_cache,
179
+ last_variables,
180
+ session: ssrSession = {}
181
+ }) {
182
+ const [session, setSession] = React.useState(ssrSession);
183
+ const handleNewSession = React.useCallback((event) => {
184
+ setSession(event.detail);
185
+ }, []);
186
+ React.useEffect(() => {
187
+ window.addEventListener("_houdini_session_", handleNewSession);
188
+ return () => {
189
+ window.removeEventListener("_houdini_session_", handleNewSession);
190
+ };
191
+ }, []);
192
+ return /* @__PURE__ */ React.createElement(
193
+ Context.Provider,
194
+ {
195
+ value: {
196
+ client,
197
+ cache,
198
+ artifact_cache,
199
+ component_cache,
200
+ data_cache,
201
+ pending_cache,
202
+ last_variables,
203
+ session
204
+ }
205
+ },
206
+ children
207
+ );
208
+ }
209
+ const Context = React.createContext(null);
210
+ const useRouterContext = () => {
211
+ const ctx = React.useContext(Context);
212
+ if (!ctx) {
213
+ throw new Error("Could not find router context");
214
+ }
215
+ return ctx;
216
+ };
217
+ function useClient() {
218
+ return useRouterContext().client;
219
+ }
220
+ function useCache() {
221
+ return useRouterContext().cache;
222
+ }
223
+ function updateLocalSession(session) {
224
+ window.dispatchEvent(
225
+ new CustomEvent("_houdini_session_", {
226
+ bubbles: true,
227
+ detail: session
228
+ })
229
+ );
230
+ }
231
+ function useSession() {
232
+ return useRouterContext().session;
233
+ }
234
+ function useCurrentVariables() {
235
+ return React.useContext(VariableContext);
236
+ }
237
+ const VariableContext = React.createContext(null);
238
+ function useQueryResult(name) {
239
+ const store_ref = useRouterContext().data_cache.get(name);
240
+ const [{ data }, observer] = useDocumentStore({
241
+ artifact: store_ref.artifact,
242
+ observer: store_ref
243
+ });
244
+ return [data, observer];
245
+ }
246
+ export {
247
+ Router,
248
+ RouterContextProvider,
249
+ updateLocalSession,
250
+ useCache,
251
+ useClient,
252
+ useCurrentVariables,
253
+ useNavigationContext,
254
+ useQueryResult,
255
+ useRouterContext,
256
+ useSession
257
+ };
@@ -0,0 +1,2 @@
1
+ export { Link } from './Link';
2
+ export { Router, RouterContextProvider, useClient, updateLocalSession } from './Router';
@@ -0,0 +1,9 @@
1
+ import { Link } from "./Link";
2
+ import { Router, RouterContextProvider, useClient, updateLocalSession } from "./Router";
3
+ export {
4
+ Link,
5
+ Router,
6
+ RouterContextProvider,
7
+ updateLocalSession,
8
+ useClient
9
+ };
@@ -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
+ */
@@ -0,0 +1,122 @@
1
+ const param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
2
+ function find_match(manifest, current, allowNull) {
3
+ let match = null;
4
+ let matchVariables = null;
5
+ for (const page of Object.values(manifest.pages)) {
6
+ const urlMatch = current.match(page.pattern);
7
+ if (!urlMatch) {
8
+ continue;
9
+ }
10
+ match = page;
11
+ matchVariables = exec(urlMatch, page.params) || {};
12
+ break;
13
+ }
14
+ if (!match && !allowNull) {
15
+ throw new Error("404");
16
+ }
17
+ return [match, matchVariables];
18
+ }
19
+ function parse_page_pattern(id) {
20
+ const params = [];
21
+ const pattern = id === "/" ? /^\/$/ : new RegExp(
22
+ `^${get_route_segments(id).map((segment) => {
23
+ const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
24
+ if (rest_match) {
25
+ params.push({
26
+ name: rest_match[1],
27
+ matcher: rest_match[2],
28
+ optional: false,
29
+ rest: true,
30
+ chained: true
31
+ });
32
+ return "(?:/(.*))?";
33
+ }
34
+ const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
35
+ if (optional_match) {
36
+ params.push({
37
+ name: optional_match[1],
38
+ matcher: optional_match[2],
39
+ optional: true,
40
+ rest: false,
41
+ chained: true
42
+ });
43
+ return "(?:/([^/]+))?";
44
+ }
45
+ if (!segment) {
46
+ return;
47
+ }
48
+ const parts = segment.split(/\[(.+?)\](?!\])/);
49
+ const result = parts.map((content, i) => {
50
+ if (i % 2) {
51
+ if (content.startsWith("x+")) {
52
+ return escape(
53
+ String.fromCharCode(parseInt(content.slice(2), 16))
54
+ );
55
+ }
56
+ if (content.startsWith("u+")) {
57
+ return escape(
58
+ String.fromCharCode(
59
+ ...content.slice(2).split("-").map((code) => parseInt(code, 16))
60
+ )
61
+ );
62
+ }
63
+ const match = param_pattern.exec(content);
64
+ if (!match) {
65
+ throw new Error(
66
+ `Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
67
+ );
68
+ }
69
+ const [, is_optional, is_rest, name, matcher] = match;
70
+ params.push({
71
+ name,
72
+ matcher,
73
+ optional: !!is_optional,
74
+ rest: !!is_rest,
75
+ chained: is_rest ? i === 1 && parts[0] === "" : false
76
+ });
77
+ return is_rest ? "(.*?)" : is_optional ? "([^/]*)?" : "([^/]+?)";
78
+ }
79
+ return escape(content);
80
+ }).join("");
81
+ return "/" + result;
82
+ }).join("")}/?$`
83
+ );
84
+ return { pattern, params, page_id: id };
85
+ }
86
+ function affects_path(segment) {
87
+ return !/^\([^)]+\)$/.test(segment);
88
+ }
89
+ function get_route_segments(route) {
90
+ return route.slice(1).split("/").filter(affects_path);
91
+ }
92
+ function exec(match, params) {
93
+ const result = {};
94
+ const values = match.slice(1);
95
+ let buffered = "";
96
+ for (let i = 0; i < params.length; i += 1) {
97
+ const param = params[i];
98
+ let value = values[i];
99
+ if (param.chained && param.rest && buffered) {
100
+ value = value ? buffered + "/" + value : buffered;
101
+ }
102
+ buffered = "";
103
+ if (value === void 0) {
104
+ if (param.rest)
105
+ result[param.name] = "";
106
+ } else {
107
+ result[param.name] = value;
108
+ }
109
+ }
110
+ if (buffered)
111
+ return;
112
+ return result;
113
+ }
114
+ function escape(str) {
115
+ return str.normalize().replace(/[[\]]/g, "\\$&").replace(/%/g, "%25").replace(/\//g, "%2[Ff]").replace(/\?/g, "%3[Ff]").replace(/#/g, "%23").replace(/[.*+?^${}()|\\]/g, "\\$&");
116
+ }
117
+ export {
118
+ exec,
119
+ find_match,
120
+ get_route_segments,
121
+ parse_page_pattern
122
+ };
@@ -0,0 +1,23 @@
1
+ import type { QueryArtifact } from '$houdini/runtime/lib/types';
2
+ import type { RouteParam } from './match';
3
+ export type RouterManifest = {
4
+ pages: Record<string, RouterPageManifest>;
5
+ };
6
+ export type RouterPageManifest = {
7
+ id: string;
8
+ pattern: RegExp;
9
+ params: RouteParam[];
10
+ documents: Record<string, {
11
+ artifact: () => Promise<{
12
+ default: QueryArtifact;
13
+ }>;
14
+ loading: boolean;
15
+ }>;
16
+ component: () => Promise<{
17
+ default: (props: any) => React.ReactElement;
18
+ }>;
19
+ };
20
+ export type NavigationContext = {
21
+ currentRoute: string;
22
+ goto: (route: string) => void;
23
+ };
File without changes
@@ -0,0 +1,7 @@
1
+ import type { Config } from 'houdini';
2
+ import type { Connect } from 'vite';
3
+ import type { Server } from '.';
4
+ export declare function dev_server({ server, config }: {
5
+ server: Connect.Server;
6
+ config: Config;
7
+ }): Server;
@@ -0,0 +1,17 @@
1
+ import type { Config } from 'houdini';
2
+ export declare function configure_server({ server, config }: {
3
+ server: Server;
4
+ config: Config;
5
+ }): void;
6
+ export type Server = {
7
+ use(fn: ServerMiddleware): void;
8
+ };
9
+ export type ServerMiddleware = (req: IncomingRequest, res: ServerResponse, next: () => void) => void;
10
+ export type IncomingRequest = {
11
+ url?: string;
12
+ headers: Headers;
13
+ };
14
+ export type ServerResponse = {
15
+ redirect(url: string, status?: number): void;
16
+ set_header(name: string, value: string): void;
17
+ };
@@ -0,0 +1,3 @@
1
+ import type { ServerResponse } from '.';
2
+ export declare function set_session(res: ServerResponse, value: App.Session): void;
3
+ export declare function get_session(req: Headers, secrets: string[]): App.Session;