houdini-react 1.2.10 → 1.2.12
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 -12
- package/build/plugin-cjs/index.js +20364 -105926
- package/build/plugin-esm/index.js +20360 -105921
- package/build/runtime-cjs/routing/components/Router.js +111 -38
- package/build/runtime-esm/routing/components/Router.js +111 -38
- package/package.json +3 -2
- package/build/runtime/server/compat.d.ts +0 -7
- package/build/runtime/server/index.d.ts +0 -17
- package/build/runtime/server/session.d.ts +0 -3
- package/build/runtime-cjs/server/compat.d.ts +0 -7
- package/build/runtime-cjs/server/compat.js +0 -52
- package/build/runtime-cjs/server/index.d.ts +0 -17
- package/build/runtime-cjs/server/index.js +0 -54
- package/build/runtime-cjs/server/session.d.ts +0 -3
- package/build/runtime-cjs/server/session.js +0 -61
- package/build/runtime-esm/server/compat.d.ts +0 -7
- package/build/runtime-esm/server/compat.js +0 -28
- package/build/runtime-esm/server/index.d.ts +0 -17
- package/build/runtime-esm/server/index.js +0 -30
- package/build/runtime-esm/server/session.d.ts +0 -3
- package/build/runtime-esm/server/session.js +0 -30
|
@@ -41,6 +41,11 @@ var import_react = __toESM(require("react"));
|
|
|
41
41
|
var import_react_streaming = require("react-streaming");
|
|
42
42
|
var import_useDocumentStore = require("../../hooks/useDocumentStore");
|
|
43
43
|
var import_match = require("../lib/match");
|
|
44
|
+
const PreloadWhich = {
|
|
45
|
+
component: "component",
|
|
46
|
+
data: "data",
|
|
47
|
+
page: "page"
|
|
48
|
+
};
|
|
44
49
|
function Router({
|
|
45
50
|
manifest,
|
|
46
51
|
initialURL,
|
|
@@ -52,7 +57,13 @@ function Router({
|
|
|
52
57
|
return initialURL || window.location.pathname;
|
|
53
58
|
});
|
|
54
59
|
const [page, variables] = (0, import_match.find_match)(manifest, current);
|
|
55
|
-
|
|
60
|
+
const { loadData, loadComponent } = usePageData({
|
|
61
|
+
page,
|
|
62
|
+
variables,
|
|
63
|
+
loaded_queries,
|
|
64
|
+
loaded_artifacts,
|
|
65
|
+
assetPrefix
|
|
66
|
+
});
|
|
56
67
|
const { component_cache } = useRouterContext();
|
|
57
68
|
const PageComponent = component_cache.get(page.id);
|
|
58
69
|
import_react.default.useEffect(() => {
|
|
@@ -72,7 +83,18 @@ function Router({
|
|
|
72
83
|
window.removeEventListener("popstate", onChange);
|
|
73
84
|
};
|
|
74
85
|
}, []);
|
|
75
|
-
|
|
86
|
+
useLinkBehavior({
|
|
87
|
+
goto: setCurrent,
|
|
88
|
+
preload(url, which) {
|
|
89
|
+
const [page2, variables2] = (0, import_match.find_match)(manifest, url);
|
|
90
|
+
if (["both", "component"].includes(which)) {
|
|
91
|
+
loadComponent(page2);
|
|
92
|
+
}
|
|
93
|
+
if (["both", "data"].includes(which)) {
|
|
94
|
+
loadData(page2, variables2);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
76
98
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageComponent, { url: current }) });
|
|
77
99
|
}
|
|
78
100
|
function usePageData({
|
|
@@ -174,46 +196,55 @@ function usePageData({
|
|
|
174
196
|
pending_cache.set(id, { ...promise, resolve, reject });
|
|
175
197
|
return pending_cache.get(id);
|
|
176
198
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const missing_artifacts = [];
|
|
181
|
-
const found_artifacts = {};
|
|
182
|
-
for (const key of Object.keys(page.documents)) {
|
|
183
|
-
if (artifact_cache.has(key)) {
|
|
184
|
-
found_artifacts[key] = artifact_cache.get(key);
|
|
185
|
-
} else {
|
|
186
|
-
missing_artifacts.push(key);
|
|
199
|
+
function loadData(targetPage, variables2) {
|
|
200
|
+
if (last_variables.has(targetPage.id) && !(0, import_deepEquals.deepEquals)(last_variables.get(targetPage.id), variables2)) {
|
|
201
|
+
data_cache.clear();
|
|
187
202
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
203
|
+
const missing_artifacts = [];
|
|
204
|
+
const found_artifacts = {};
|
|
205
|
+
for (const key of Object.keys(targetPage.documents)) {
|
|
206
|
+
if (artifact_cache.has(key)) {
|
|
207
|
+
found_artifacts[key] = artifact_cache.get(key);
|
|
208
|
+
} else {
|
|
209
|
+
missing_artifacts.push(key);
|
|
195
210
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
211
|
+
}
|
|
212
|
+
for (const artifact_id of missing_artifacts) {
|
|
213
|
+
targetPage.documents[artifact_id].artifact().then((mod) => {
|
|
214
|
+
const artifact = mod.default;
|
|
215
|
+
artifact_cache.set(artifact_id, artifact);
|
|
216
|
+
if (loaded_artifacts) {
|
|
217
|
+
loaded_artifacts[artifact.name] = artifact;
|
|
218
|
+
}
|
|
219
|
+
stream?.injectToStream(`
|
|
220
|
+
<script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
|
|
221
|
+
`);
|
|
222
|
+
load_query({ id: artifact.name, artifact });
|
|
223
|
+
}).catch((err) => {
|
|
224
|
+
console.log(err);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
for (const artifact of Object.values(found_artifacts)) {
|
|
228
|
+
if (!data_cache.has(artifact.name)) {
|
|
229
|
+
load_query({ id: artifact.name, artifact });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
203
232
|
}
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
|
|
233
|
+
async function loadComponent(targetPage) {
|
|
234
|
+
if (component_cache.has(targetPage.id)) {
|
|
235
|
+
return;
|
|
207
236
|
}
|
|
237
|
+
const mod = await targetPage.component();
|
|
238
|
+
component_cache.set(targetPage.id, mod.default);
|
|
208
239
|
}
|
|
240
|
+
loadData(page, variables);
|
|
209
241
|
if (!component_cache.has(page.id)) {
|
|
210
|
-
throw
|
|
211
|
-
page.component().then((mod) => {
|
|
212
|
-
component_cache.set(page.id, mod.default);
|
|
213
|
-
resolve();
|
|
214
|
-
}).catch(reject);
|
|
215
|
-
});
|
|
242
|
+
throw loadComponent(page);
|
|
216
243
|
}
|
|
244
|
+
return {
|
|
245
|
+
loadData,
|
|
246
|
+
loadComponent
|
|
247
|
+
};
|
|
217
248
|
}
|
|
218
249
|
function RouterContextProvider({
|
|
219
250
|
children,
|
|
@@ -290,11 +321,20 @@ function useQueryResult(name) {
|
|
|
290
321
|
});
|
|
291
322
|
return [data, observer];
|
|
292
323
|
}
|
|
293
|
-
function
|
|
324
|
+
function useLinkBehavior({
|
|
325
|
+
goto,
|
|
326
|
+
preload
|
|
327
|
+
}) {
|
|
328
|
+
useLinkNavigation({ goto });
|
|
329
|
+
if (!globalThis.navigator?.connection?.saveData) {
|
|
330
|
+
usePreload({ preload });
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function useLinkNavigation({ goto }) {
|
|
294
334
|
const [pending, startTransition] = import_react.default.useTransition();
|
|
295
335
|
import_react.default.useEffect(() => {
|
|
296
|
-
|
|
297
|
-
|
|
336
|
+
const onClick = (e) => {
|
|
337
|
+
const link = e.target?.closest("a");
|
|
298
338
|
if (link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.defaultPrevented) {
|
|
299
339
|
const target = link.attributes.getNamedItem("href")?.value;
|
|
300
340
|
if (!target || !target.startsWith("/")) {
|
|
@@ -312,6 +352,39 @@ function useAnchorIntercept({ goto }) {
|
|
|
312
352
|
};
|
|
313
353
|
}, []);
|
|
314
354
|
}
|
|
355
|
+
function usePreload({ preload }) {
|
|
356
|
+
const timeoutRef = import_react.default.useRef(null);
|
|
357
|
+
import_react.default.useEffect(() => {
|
|
358
|
+
const mouseMove = (e) => {
|
|
359
|
+
const target = e.target;
|
|
360
|
+
if (!(target instanceof HTMLAnchorElement)) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
let preloadWhichRaw = target.attributes.getNamedItem("data-houdini-preload")?.value;
|
|
364
|
+
let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
|
|
365
|
+
if (!PreloadWhich[preloadWhich]) {
|
|
366
|
+
console.log(
|
|
367
|
+
`invalid preload value "${preloadWhich}" must be "${PreloadWhich.component}", "${PreloadWhich.data}", or "${PreloadWhich.page}"`
|
|
368
|
+
);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (timeoutRef.current) {
|
|
372
|
+
clearTimeout(timeoutRef.current);
|
|
373
|
+
}
|
|
374
|
+
timeoutRef.current = setTimeout(() => {
|
|
375
|
+
const url = target.attributes.getNamedItem("href")?.value;
|
|
376
|
+
if (!url) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
preload(url, preloadWhich);
|
|
380
|
+
}, 20);
|
|
381
|
+
};
|
|
382
|
+
document.addEventListener("mousemove", mouseMove);
|
|
383
|
+
return () => {
|
|
384
|
+
document.removeEventListener("mousemove", mouseMove);
|
|
385
|
+
};
|
|
386
|
+
}, []);
|
|
387
|
+
}
|
|
315
388
|
// Annotate the CommonJS export names for ESM import in node:
|
|
316
389
|
0 && (module.exports = {
|
|
317
390
|
Router,
|
|
@@ -4,6 +4,11 @@ import React from "react";
|
|
|
4
4
|
import { useStream } from "react-streaming";
|
|
5
5
|
import { useDocumentStore } from "../../hooks/useDocumentStore";
|
|
6
6
|
import { find_match } from "../lib/match";
|
|
7
|
+
const PreloadWhich = {
|
|
8
|
+
component: "component",
|
|
9
|
+
data: "data",
|
|
10
|
+
page: "page"
|
|
11
|
+
};
|
|
7
12
|
function Router({
|
|
8
13
|
manifest,
|
|
9
14
|
initialURL,
|
|
@@ -15,7 +20,13 @@ function Router({
|
|
|
15
20
|
return initialURL || window.location.pathname;
|
|
16
21
|
});
|
|
17
22
|
const [page, variables] = find_match(manifest, current);
|
|
18
|
-
|
|
23
|
+
const { loadData, loadComponent } = usePageData({
|
|
24
|
+
page,
|
|
25
|
+
variables,
|
|
26
|
+
loaded_queries,
|
|
27
|
+
loaded_artifacts,
|
|
28
|
+
assetPrefix
|
|
29
|
+
});
|
|
19
30
|
const { component_cache } = useRouterContext();
|
|
20
31
|
const PageComponent = component_cache.get(page.id);
|
|
21
32
|
React.useEffect(() => {
|
|
@@ -35,7 +46,18 @@ function Router({
|
|
|
35
46
|
window.removeEventListener("popstate", onChange);
|
|
36
47
|
};
|
|
37
48
|
}, []);
|
|
38
|
-
|
|
49
|
+
useLinkBehavior({
|
|
50
|
+
goto: setCurrent,
|
|
51
|
+
preload(url, which) {
|
|
52
|
+
const [page2, variables2] = find_match(manifest, url);
|
|
53
|
+
if (["both", "component"].includes(which)) {
|
|
54
|
+
loadComponent(page2);
|
|
55
|
+
}
|
|
56
|
+
if (["both", "data"].includes(which)) {
|
|
57
|
+
loadData(page2, variables2);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
39
61
|
return /* @__PURE__ */ jsx(VariableContext.Provider, { value: variables, children: /* @__PURE__ */ jsx(PageComponent, { url: current }) });
|
|
40
62
|
}
|
|
41
63
|
function usePageData({
|
|
@@ -137,46 +159,55 @@ function usePageData({
|
|
|
137
159
|
pending_cache.set(id, { ...promise, resolve, reject });
|
|
138
160
|
return pending_cache.get(id);
|
|
139
161
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const missing_artifacts = [];
|
|
144
|
-
const found_artifacts = {};
|
|
145
|
-
for (const key of Object.keys(page.documents)) {
|
|
146
|
-
if (artifact_cache.has(key)) {
|
|
147
|
-
found_artifacts[key] = artifact_cache.get(key);
|
|
148
|
-
} else {
|
|
149
|
-
missing_artifacts.push(key);
|
|
162
|
+
function loadData(targetPage, variables2) {
|
|
163
|
+
if (last_variables.has(targetPage.id) && !deepEquals(last_variables.get(targetPage.id), variables2)) {
|
|
164
|
+
data_cache.clear();
|
|
150
165
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
const missing_artifacts = [];
|
|
167
|
+
const found_artifacts = {};
|
|
168
|
+
for (const key of Object.keys(targetPage.documents)) {
|
|
169
|
+
if (artifact_cache.has(key)) {
|
|
170
|
+
found_artifacts[key] = artifact_cache.get(key);
|
|
171
|
+
} else {
|
|
172
|
+
missing_artifacts.push(key);
|
|
158
173
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
}
|
|
175
|
+
for (const artifact_id of missing_artifacts) {
|
|
176
|
+
targetPage.documents[artifact_id].artifact().then((mod) => {
|
|
177
|
+
const artifact = mod.default;
|
|
178
|
+
artifact_cache.set(artifact_id, artifact);
|
|
179
|
+
if (loaded_artifacts) {
|
|
180
|
+
loaded_artifacts[artifact.name] = artifact;
|
|
181
|
+
}
|
|
182
|
+
stream?.injectToStream(`
|
|
183
|
+
<script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""><\/script>
|
|
184
|
+
`);
|
|
185
|
+
load_query({ id: artifact.name, artifact });
|
|
186
|
+
}).catch((err) => {
|
|
187
|
+
console.log(err);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
for (const artifact of Object.values(found_artifacts)) {
|
|
191
|
+
if (!data_cache.has(artifact.name)) {
|
|
192
|
+
load_query({ id: artifact.name, artifact });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
166
195
|
}
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
196
|
+
async function loadComponent(targetPage) {
|
|
197
|
+
if (component_cache.has(targetPage.id)) {
|
|
198
|
+
return;
|
|
170
199
|
}
|
|
200
|
+
const mod = await targetPage.component();
|
|
201
|
+
component_cache.set(targetPage.id, mod.default);
|
|
171
202
|
}
|
|
203
|
+
loadData(page, variables);
|
|
172
204
|
if (!component_cache.has(page.id)) {
|
|
173
|
-
throw
|
|
174
|
-
page.component().then((mod) => {
|
|
175
|
-
component_cache.set(page.id, mod.default);
|
|
176
|
-
resolve();
|
|
177
|
-
}).catch(reject);
|
|
178
|
-
});
|
|
205
|
+
throw loadComponent(page);
|
|
179
206
|
}
|
|
207
|
+
return {
|
|
208
|
+
loadData,
|
|
209
|
+
loadComponent
|
|
210
|
+
};
|
|
180
211
|
}
|
|
181
212
|
function RouterContextProvider({
|
|
182
213
|
children,
|
|
@@ -253,11 +284,20 @@ function useQueryResult(name) {
|
|
|
253
284
|
});
|
|
254
285
|
return [data, observer];
|
|
255
286
|
}
|
|
256
|
-
function
|
|
287
|
+
function useLinkBehavior({
|
|
288
|
+
goto,
|
|
289
|
+
preload
|
|
290
|
+
}) {
|
|
291
|
+
useLinkNavigation({ goto });
|
|
292
|
+
if (!globalThis.navigator?.connection?.saveData) {
|
|
293
|
+
usePreload({ preload });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function useLinkNavigation({ goto }) {
|
|
257
297
|
const [pending, startTransition] = React.useTransition();
|
|
258
298
|
React.useEffect(() => {
|
|
259
|
-
|
|
260
|
-
|
|
299
|
+
const onClick = (e) => {
|
|
300
|
+
const link = e.target?.closest("a");
|
|
261
301
|
if (link && link instanceof HTMLAnchorElement && link.href && (!link.target || link.target === "_self") && link.origin === location.origin && !link.hasAttribute("download") && e.button === 0 && !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.defaultPrevented) {
|
|
262
302
|
const target = link.attributes.getNamedItem("href")?.value;
|
|
263
303
|
if (!target || !target.startsWith("/")) {
|
|
@@ -275,6 +315,39 @@ function useAnchorIntercept({ goto }) {
|
|
|
275
315
|
};
|
|
276
316
|
}, []);
|
|
277
317
|
}
|
|
318
|
+
function usePreload({ preload }) {
|
|
319
|
+
const timeoutRef = React.useRef(null);
|
|
320
|
+
React.useEffect(() => {
|
|
321
|
+
const mouseMove = (e) => {
|
|
322
|
+
const target = e.target;
|
|
323
|
+
if (!(target instanceof HTMLAnchorElement)) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
let preloadWhichRaw = target.attributes.getNamedItem("data-houdini-preload")?.value;
|
|
327
|
+
let preloadWhich = !preloadWhichRaw || preloadWhichRaw === "true" ? "page" : preloadWhichRaw;
|
|
328
|
+
if (!PreloadWhich[preloadWhich]) {
|
|
329
|
+
console.log(
|
|
330
|
+
`invalid preload value "${preloadWhich}" must be "${PreloadWhich.component}", "${PreloadWhich.data}", or "${PreloadWhich.page}"`
|
|
331
|
+
);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (timeoutRef.current) {
|
|
335
|
+
clearTimeout(timeoutRef.current);
|
|
336
|
+
}
|
|
337
|
+
timeoutRef.current = setTimeout(() => {
|
|
338
|
+
const url = target.attributes.getNamedItem("href")?.value;
|
|
339
|
+
if (!url) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
preload(url, preloadWhich);
|
|
343
|
+
}, 20);
|
|
344
|
+
};
|
|
345
|
+
document.addEventListener("mousemove", mouseMove);
|
|
346
|
+
return () => {
|
|
347
|
+
document.removeEventListener("mousemove", mouseMove);
|
|
348
|
+
};
|
|
349
|
+
}, []);
|
|
350
|
+
}
|
|
278
351
|
export {
|
|
279
352
|
Router,
|
|
280
353
|
RouterContextProvider,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "houdini-react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"description": "The React plugin for houdini",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -35,12 +35,13 @@
|
|
|
35
35
|
"estraverse": "^5.3.0",
|
|
36
36
|
"express": "^4.18.2",
|
|
37
37
|
"graphql": "^15.8.0",
|
|
38
|
+
"graphql-yoga": "^4.0.4",
|
|
38
39
|
"react": "^18.2.0",
|
|
39
40
|
"react-streaming": "^0.3.9",
|
|
40
41
|
"recast": "^0.23.1",
|
|
41
42
|
"rollup": "^3.7.4",
|
|
42
43
|
"use-deep-compare-effect": "^1.8.1",
|
|
43
|
-
"houdini": "^1.2.
|
|
44
|
+
"houdini": "^1.2.12"
|
|
44
45
|
},
|
|
45
46
|
"files": [
|
|
46
47
|
"build"
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var compat_exports = {};
|
|
20
|
-
__export(compat_exports, {
|
|
21
|
-
dev_server: () => dev_server
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(compat_exports);
|
|
24
|
-
function dev_server({ server, config }) {
|
|
25
|
-
return {
|
|
26
|
-
use(fn) {
|
|
27
|
-
server.use((req, res, next) => {
|
|
28
|
-
fn(
|
|
29
|
-
{
|
|
30
|
-
url: req.url,
|
|
31
|
-
headers: new Headers(req.headers)
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
...res,
|
|
35
|
-
redirect(url, status = 307) {
|
|
36
|
-
res.statusCode = status;
|
|
37
|
-
res.setHeader("location", url);
|
|
38
|
-
res.setHeader("content-length", "0");
|
|
39
|
-
return res.end();
|
|
40
|
-
},
|
|
41
|
-
set_header: res.setHeader.bind(res)
|
|
42
|
-
},
|
|
43
|
-
next
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
-
0 && (module.exports = {
|
|
51
|
-
dev_server
|
|
52
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var server_exports = {};
|
|
20
|
-
__export(server_exports, {
|
|
21
|
-
configure_server: () => configure_server
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(server_exports);
|
|
24
|
-
var import_config = require("../../plugin/config");
|
|
25
|
-
var import_session = require("./session");
|
|
26
|
-
function configure_server({ server, config }) {
|
|
27
|
-
server.use(server_handler({ config }));
|
|
28
|
-
}
|
|
29
|
-
function server_handler({ config }) {
|
|
30
|
-
const plugin_config = (0, import_config.plugin_config)(config);
|
|
31
|
-
return (req, res, next) => {
|
|
32
|
-
if (!req.url) {
|
|
33
|
-
next();
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (plugin_config.auth && "redirect" in plugin_config.auth && req.url.startsWith(plugin_config.auth.redirect)) {
|
|
37
|
-
return redirect_auth(req, res, next);
|
|
38
|
-
}
|
|
39
|
-
next();
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
const redirect_auth = (req, res, next) => {
|
|
43
|
-
const { searchParams } = new URL(req.url, `http://${req.headers.get("host")}`);
|
|
44
|
-
const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
|
|
45
|
-
(0, import_session.set_session)(res, session);
|
|
46
|
-
if (redirectTo) {
|
|
47
|
-
return res.redirect(redirectTo);
|
|
48
|
-
}
|
|
49
|
-
next();
|
|
50
|
-
};
|
|
51
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
-
0 && (module.exports = {
|
|
53
|
-
configure_server
|
|
54
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
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 session_exports = {};
|
|
26
|
-
__export(session_exports, {
|
|
27
|
-
get_session: () => get_session,
|
|
28
|
-
set_session: () => set_session
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(session_exports);
|
|
31
|
-
var import_cookie_parser = __toESM(require("cookie-parser"));
|
|
32
|
-
const session_cookie_name = "__houdini__";
|
|
33
|
-
function set_session(res, value) {
|
|
34
|
-
const today = new Date();
|
|
35
|
-
const expires = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1e3);
|
|
36
|
-
const serialized = JSON.stringify(value);
|
|
37
|
-
res.set_header(
|
|
38
|
-
"Set-Cookie",
|
|
39
|
-
`${session_cookie_name}=${serialized}; Path=/; HttpOnly; Secure; SameSite=Lax; Expires=${expires.toUTCString()} `
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
function get_session(req, secrets) {
|
|
43
|
-
const cookie = req.get("cookie");
|
|
44
|
-
if (!cookie) {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
const parsed = import_cookie_parser.default.signedCookie(cookie, secrets);
|
|
48
|
-
if (!parsed) {
|
|
49
|
-
return {};
|
|
50
|
-
}
|
|
51
|
-
const houdini_session_cookie = parsed.split(";").map((s) => s.trim().split("=")).filter((s) => s[0] === session_cookie_name);
|
|
52
|
-
if (houdini_session_cookie.length === 1) {
|
|
53
|
-
return JSON.parse(houdini_session_cookie[0][1]);
|
|
54
|
-
}
|
|
55
|
-
return {};
|
|
56
|
-
}
|
|
57
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
-
0 && (module.exports = {
|
|
59
|
-
get_session,
|
|
60
|
-
set_session
|
|
61
|
-
});
|