@torpor/build 1.4.5 → 1.5.0

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 (45) hide show
  1. package/README.md +3 -2
  2. package/dist/{Site-CQ29Opvm.d.mts → Site-Blz32JRD.d.mts} +4 -3
  3. package/dist/{Site-CQ29Opvm.d.mts.map → Site-Blz32JRD.d.mts.map} +1 -1
  4. package/dist/bin/index.js +1 -1
  5. package/dist/clientEntry.mjs +4 -4
  6. package/dist/clientEntry.mjs.map +1 -1
  7. package/dist/dataRequest-JosDB_ig.mjs +50 -0
  8. package/dist/dataRequest-JosDB_ig.mjs.map +1 -0
  9. package/dist/dev.mjs +1 -1
  10. package/dist/devPlugin-V689J6l6.mjs +144 -0
  11. package/dist/devPlugin-V689J6l6.mjs.map +1 -0
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +3 -2
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/load-LWQoFWh-.mjs +349 -0
  16. package/dist/load-LWQoFWh-.mjs.map +1 -0
  17. package/dist/nav.mjs +1 -1
  18. package/dist/nodeDev.d.mts +16 -0
  19. package/dist/nodeDev.d.mts.map +1 -0
  20. package/dist/nodeDev.mjs +2 -0
  21. package/dist/openapi.d.mts +1 -1
  22. package/dist/{response-CuNPcxsY.mjs → response-sth6FQsj.mjs} +33 -3
  23. package/dist/response-sth6FQsj.mjs.map +1 -0
  24. package/dist/response.mjs +2 -2
  25. package/dist/run.d.mts +1 -1
  26. package/dist/run.mjs +1 -1
  27. package/dist/{runOpenApi-CbbrPi4E.mjs → runOpenApi-tnflDjZV.mjs} +10 -143
  28. package/dist/runOpenApi-tnflDjZV.mjs.map +1 -0
  29. package/dist/serverEntry-fj0XfTs4.d.mts.map +1 -1
  30. package/dist/{serverEntry-D3uwudkX.mjs → serverEntry-o6kk_-Wo.mjs} +2 -2
  31. package/dist/{serverEntry-D3uwudkX.mjs.map → serverEntry-o6kk_-Wo.mjs.map} +1 -1
  32. package/dist/serverEntry.mjs +1 -1
  33. package/dist/{serverHandlers-C8qzOSX-.mjs → serverHandlers-F1gJ1lrj.mjs} +194 -30
  34. package/dist/serverHandlers-F1gJ1lrj.mjs.map +1 -0
  35. package/dist/test.d.mts +1 -1
  36. package/dist/test.mjs +1 -1
  37. package/dist/{unprocessable-D6RcYLh6.mjs → unprocessable-CoMN2zFa.mjs} +2 -32
  38. package/dist/unprocessable-CoMN2zFa.mjs.map +1 -0
  39. package/package.json +8 -3
  40. package/dist/load-Uyj9I60p.mjs +0 -246
  41. package/dist/load-Uyj9I60p.mjs.map +0 -1
  42. package/dist/response-CuNPcxsY.mjs.map +0 -1
  43. package/dist/runOpenApi-CbbrPi4E.mjs.map +0 -1
  44. package/dist/serverHandlers-C8qzOSX-.mjs.map +0 -1
  45. package/dist/unprocessable-D6RcYLh6.mjs.map +0 -1
@@ -1,246 +0,0 @@
1
- import { n as getBasePath, s as stripBaseFromUrl } from "./basePath-DQnbHc7o.mjs";
2
- import { t as $page } from "./_page-CW6SLuT4.mjs";
3
- import { clearLayoutSlot, fillLayoutSlot, hydrate, mount, unmount } from "@torpor/view";
4
- //#region src/state/client.ts
5
- const CLIENT_SYMBOL = Symbol.for("torp.Client");
6
- const client = globalThis[CLIENT_SYMBOL] ??= {
7
- router: null,
8
- layoutStack: [],
9
- prefetchedData: {},
10
- viewTransitions: false
11
- };
12
- //#endregion
13
- //#region src/nav/reload.ts
14
- /**
15
- * Reloads data for the currently loaded page and rerenders it.
16
- */
17
- async function reload() {
18
- return await navigate(new URL(document.location.href));
19
- }
20
- //#endregion
21
- //#region src/nav/formSubmit.ts
22
- async function formSubmit(e) {
23
- e.preventDefault();
24
- $page.form = void 0;
25
- const form = e.target;
26
- const button = e.submitter;
27
- let action = form.action || document.URL;
28
- if (button && button.formAction && button.formAction !== document.URL) action = button.formAction;
29
- const options = {
30
- body: new FormData(form),
31
- method: "POST",
32
- mode: "cors",
33
- credentials: "same-origin",
34
- headers: { "X-Torpor-Form-Submit": "" }
35
- };
36
- const response = await fetch(action, options);
37
- if (response.status === 200 && response.headers.has("Content-Disposition") && /attachment;\s*filename="(.+?)"/.test(response.headers.get("Content-Disposition"))) {
38
- const downloadFileName = response.headers.get("Content-Disposition")?.match(/attachment;\s*filename="(.+?)"/)[1] ?? "file";
39
- const downloadLink = document.createElement("a");
40
- downloadLink.href = window.URL.createObjectURL(await response.blob());
41
- downloadLink.download = downloadFileName;
42
- downloadLink.click();
43
- } else if (response.status === 200 && response.headers.has("X-Torpor-Form-Redirect")) {
44
- const redirect = response.headers.get("Location");
45
- await load(redirect);
46
- window.location.href = redirect;
47
- } else if (response.status >= 200 && response.status <= 299 || response.status >= 400 && response.status <= 499) {
48
- if (response.headers.get("Content-Type") === "application/json") $page.form = await response.json();
49
- await reload();
50
- }
51
- }
52
- //#endregion
53
- //#region src/nav/loadData.ts
54
- async function loadData(handler, params, path, query, newLayoutStack, clientEndPoint, serverEndPoint, prefetch = false) {
55
- let data = {};
56
- if (handler.layouts) {
57
- let layoutStack = client.layoutStack;
58
- for (let [i, layout] of handler.layouts.entries()) {
59
- let layoutPath = layout.path;
60
- for (let key in params) layoutPath = layoutPath.replace(`[${key}]`, params[key]);
61
- if (layoutStack.at(i)?.path === layoutPath) {
62
- if (!prefetch) layoutStack[i].reuse = true;
63
- newLayoutStack[i] = layoutStack[i];
64
- Object.assign(data, layoutStack[i].data);
65
- } else {
66
- const stackLayout = {
67
- path: layoutPath,
68
- data: {},
69
- reuse: false,
70
- slotRegion: null
71
- };
72
- const layoutEndPoint = (await layout.endPoint())?.default;
73
- const layoutServerEndPoint = layout.serverEndPoint && (await layout.serverEndPoint())?.default;
74
- if ((await loadClientAndServerData(stackLayout.data, document.location.origin + getBasePath() + layoutPath, query, params, layoutEndPoint, layoutServerEndPoint))?.ok === false) return;
75
- Object.assign(data, stackLayout.data);
76
- newLayoutStack.push(stackLayout);
77
- }
78
- }
79
- }
80
- if ((await loadClientAndServerData(data, document.location.origin + getBasePath() + path, query, params, clientEndPoint, serverEndPoint))?.ok === false) return;
81
- return data;
82
- }
83
- async function loadClientAndServerData(data, location, query, params, clientEndPoint, serverEndPoint) {
84
- let prefetchedData = client.prefetchedData;
85
- if (clientEndPoint?.load) {
86
- const clientKey = location + (query.size > 0 ? `?${query}` : "");
87
- if (prefetchedData[clientKey]) Object.assign(data, prefetchedData[clientKey]);
88
- else {
89
- const clientUrl = new URL(document.location.href);
90
- for (let [name, value] of query) clientUrl.searchParams.append(name, value);
91
- const clientParams = buildClientParams(clientUrl, params, data);
92
- const clientResponse = await clientEndPoint.load(clientParams);
93
- if (clientResponse) {
94
- if (clientResponse.ok) {
95
- if (clientResponse.headers.get("Content-Type")?.includes("application/json")) {
96
- const clientData = await clientResponse.json();
97
- Object.assign(data, clientData);
98
- prefetchedData[clientKey] = clientData;
99
- }
100
- } else return clientResponse;
101
- }
102
- }
103
- }
104
- if (serverEndPoint?.load) {
105
- const serverLocation = location.replace(/\/$/, "") + "/~server";
106
- const serverKey = serverLocation + (query.size > 0 ? `?${query}` : "");
107
- if (prefetchedData[serverKey]) Object.assign(data, prefetchedData[serverKey]);
108
- else {
109
- const serverUrl = new URL(serverLocation);
110
- for (let [name, value] of query) serverUrl.searchParams.append(name, value);
111
- const serverResponse = await fetch(serverUrl);
112
- if (serverResponse) {
113
- if (serverResponse.ok) {
114
- if (serverResponse.headers.get("Content-Type")?.includes("application/json")) {
115
- const serverData = await serverResponse.json();
116
- Object.assign(data, serverData);
117
- prefetchedData[serverKey] = serverData;
118
- }
119
- } else return serverResponse;
120
- }
121
- }
122
- }
123
- }
124
- function buildClientParams(url, params, data) {
125
- return {
126
- url,
127
- params,
128
- data
129
- };
130
- }
131
- //#endregion
132
- //#region src/nav/navigate.ts
133
- async function navigate(rawUrl, withHydration = false) {
134
- let parent = document.getElementById("app");
135
- if (!parent) {
136
- console.log("500");
137
- return false;
138
- }
139
- const url = stripBaseFromUrl(rawUrl, getBasePath()) ?? rawUrl;
140
- const path = url.pathname;
141
- const query = url.searchParams;
142
- const route = client.router.match(path, query);
143
- if (!route) {
144
- console.log("404");
145
- return false;
146
- }
147
- $page.url = url;
148
- if (path.endsWith("/_error")) {
149
- $page.status = parseInt(query.get("status") ?? "404");
150
- $page.error = { message: query.get("message") ?? "" };
151
- window.history.replaceState({}, "", rawUrl.toString().split("?")[0]);
152
- } else $page.status = 200;
153
- const handler = route.handler;
154
- const params = route.params || {};
155
- const clientEndPoint = (await handler.endPoint()).default;
156
- if (!clientEndPoint?.component) {
157
- console.log("404");
158
- return false;
159
- }
160
- const serverEndPoint = handler.serverEndPoint && (await handler.serverEndPoint())?.default;
161
- let newLayoutStack = [];
162
- const data = await loadData(handler, params, path, query, newLayoutStack, clientEndPoint, serverEndPoint);
163
- if (data === void 0) return false;
164
- let formInput = document.getElementById("t-form-data");
165
- let form;
166
- if (formInput) {
167
- form = JSON.parse(formInput.value);
168
- $page.form = form;
169
- formInput.remove();
170
- }
171
- let $props = { data };
172
- $props.form = $page.form;
173
- const $context = { TorporBuildContext: { onformsubmit: formSubmit } };
174
- client.layoutStack.push({
175
- path: route.handler.path,
176
- data: {},
177
- reuse: false,
178
- slotRegion: null
179
- });
180
- client.layoutStack = newLayoutStack;
181
- let layoutStack = client.layoutStack;
182
- let component = clientEndPoint.component;
183
- let slots = void 0;
184
- let reused = false;
185
- let reusedIndex = -1;
186
- if (handler.layouts) {
187
- let slotFunctions = [];
188
- slotFunctions[handler.layouts.length] = function clientComponent(parent, anchor) {
189
- let i = layoutStack.length - 1;
190
- layoutStack[i].slotRegion = fillLayoutSlot(clientEndPoint.component, slotFunctions[i + 1], parent, anchor, $props, $context);
191
- };
192
- for (let i = handler.layouts.length - 1; i >= 0; i--) {
193
- const layoutEndPoint = (await handler.layouts[i].endPoint())?.default;
194
- if (layoutEndPoint?.component) {
195
- if (layoutStack[i].reuse) {
196
- component = slotFunctions[i + 1];
197
- reusedIndex = i;
198
- reused = true;
199
- break;
200
- } else if (i === 0) {
201
- component = layoutEndPoint.component;
202
- slots = { _: slotFunctions[i + 1] };
203
- } else slotFunctions[i] = function layoutComponent(parent, anchor, _, $context) {
204
- layoutStack[i - 1].slotRegion = fillLayoutSlot(layoutEndPoint.component, slotFunctions[i + 1], parent, anchor, $props, $context);
205
- };
206
- }
207
- }
208
- }
209
- let app = parent;
210
- const render = () => {
211
- try {
212
- if (reused) {
213
- const slotRegion = layoutStack[reusedIndex].slotRegion;
214
- app = slotRegion.startNode.parentNode;
215
- clearLayoutSlot(slotRegion);
216
- component(app, null);
217
- } else if (withHydration) hydrate(app, component, $props, slots);
218
- else {
219
- unmount(app);
220
- mount(app, component, $props, slots);
221
- }
222
- } catch (error) {
223
- app.innerHTML = "<span style=\"color: red\">Script syntax error</span><p>" + error + "</p>";
224
- console.log(error);
225
- }
226
- if (!withHydration) {
227
- if (stripBaseFromUrl(new URL(document.location.href), getBasePath())?.pathname !== path) window.scrollTo(0, 0);
228
- }
229
- };
230
- if (!withHydration && client.viewTransitions && typeof document.startViewTransition === "function") document.startViewTransition(render);
231
- else render();
232
- client.prefetchedData = {};
233
- return true;
234
- }
235
- //#endregion
236
- //#region src/nav/load.ts
237
- /**
238
- * Loads and renders the page at the supplied path.
239
- */
240
- async function load(path) {
241
- return await navigate(new URL(path, document.location.href));
242
- }
243
- //#endregion
244
- export { client as a, reload as i, navigate as n, loadData as r, load as t };
245
-
246
- //# sourceMappingURL=load-Uyj9I60p.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-Uyj9I60p.mjs","names":[],"sources":["../src/state/client.ts","../src/nav/reload.ts","../src/nav/formSubmit.ts","../src/nav/loadData.ts","../src/nav/navigate.ts","../src/nav/load.ts"],"sourcesContent":["import type ClientState from \"../types/ClientState\";\n\nconst CLIENT_SYMBOL: unique symbol = Symbol.for(\"torp.Client\");\n\nconst client: ClientState =\n\t// @ts-ignore\n\t(globalThis[CLIENT_SYMBOL] ??= {\n\t\t// @ts-ignore This will definitely, 100% get set\n\t\trouter: null,\n\t\tlayoutStack: [],\n\t\t// TODO: Probably expire after 30 seconds or something?\n\t\tprefetchedData: {},\n\t\tviewTransitions: false,\n\t});\n\nexport default client;\n","import navigate from \"./navigate\";\n\n/**\n * Reloads data for the currently loaded page and rerenders it.\n */\nexport default async function reload(): Promise<boolean> {\n\tconst url = new URL(document.location.href);\n\treturn await navigate(url);\n}\n","import $page from \"../state/$page\";\nimport load from \"./load\";\nimport reload from \"./reload\";\n\nexport default async function formSubmit(e: SubmitEvent): Promise<void> {\n\t// We'll take it from here\n\te.preventDefault();\n\n\t// Reset $page on submit and link navigation\n\t// TODO: Should we put data in $page.data??\n\t$page.form = undefined;\n\n\t// Perform a POST fetch to the form's action location\n\tconst form = e.target as HTMLFormElement;\n\tconst button = e.submitter as HTMLButtonElement;\n\t// HACK: submit buttons have their formAction set to the current page if not\n\t// set, so we can't just check whether it's empty and fallback to form action\n\t//const action = button?.formAction ?? form.action;\n\tlet action = form.action || document.URL;\n\tif (button && button.formAction && button.formAction !== document.URL) {\n\t\taction = button.formAction;\n\t}\n\tconst options = {\n\t\tbody: new FormData(form),\n\t\tmethod: \"POST\",\n\t\tmode: \"cors\",\n\t\tcredentials: \"same-origin\",\n\t\t// Add a special header which tells the server that we want the raw\n\t\t// error response (if applicable) rather than the reloaded page that you\n\t\t// would get if submitting a page without javascript\n\t\theaders: {\n\t\t\t\"X-Torpor-Form-Submit\": \"\",\n\t\t},\n\t};\n\tconst response = await fetch(\n\t\taction,\n\t\t// @ts-ignore -- don't know what it's complaining about here\n\t\toptions,\n\t);\n\n\tif (\n\t\tresponse.status === 200 &&\n\t\tresponse.headers.has(\"Content-Disposition\") &&\n\t\t/attachment;\\s*filename=\"(.+?)\"/.test(response.headers.get(\"Content-Disposition\")!)\n\t) {\n\t\t// TODO: Is this enough to check to see if we have a file that should download?\n\t\t// Download the file by creating a dummy <a> and clicking it\n\t\tconst downloadFileName =\n\t\t\tresponse.headers.get(\"Content-Disposition\")?.match(/attachment;\\s*filename=\"(.+?)\"/)![1] ??\n\t\t\t\"file\";\n\t\tconst downloadLink = document.createElement(\"a\");\n\t\tdownloadLink.href = window.URL.createObjectURL(await response.blob());\n\t\tdownloadLink.download = downloadFileName;\n\t\tdownloadLink.click();\n\t} else if (response.status === 200 && response.headers.has(\"X-Torpor-Form-Redirect\")) {\n\t\t// TODO: Should do the correct type of redirect e.g. seeOther etc\n\t\tconst redirect = response.headers.get(\"Location\")!;\n\t\tawait load(redirect);\n\t\twindow.location.href = redirect;\n\t} else if (\n\t\t(response.status >= 200 && response.status <= 299) ||\n\t\t(response.status >= 400 && response.status <= 499)\n\t) {\n\t\t// Put the response into `$page.form`, and it will be put into `$props` in reload\n\t\tif (response.headers.get(\"Content-Type\") === \"application/json\") {\n\t\t\t$page.form = await response.json();\n\t\t}\n\t\tawait reload();\n\t}\n}\n","import client from \"../state/client\";\nimport { getBasePath } from \"../site/basePath\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport type RouteHandler from \"../types/RouteHandler\";\n\nexport default async function loadData(\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n\tpath: string,\n\tquery: URLSearchParams,\n\tnewLayoutStack: LayoutPath[],\n\tclientEndPoint: PageEndPoint | undefined,\n\tserverEndPoint: PageServerEndPoint | undefined,\n\tprefetch = false,\n): Promise<Record<string, string> | void> {\n\tlet data = {};\n\tif (handler.layouts) {\n\t\tlet layoutStack = client.layoutStack;\n\t\tfor (let [i, layout] of handler.layouts.entries()) {\n\t\t\tlet layoutPath = layout.path;\n\t\t\tfor (let key in params) {\n\t\t\t\tlayoutPath = layoutPath.replace(`[${key}]`, params[key]);\n\t\t\t}\n\t\t\tif (layoutStack.at(i)?.path === layoutPath) {\n\t\t\t\t// We've already loaded this layout, we can just re-use its data and UI\n\t\t\t\tif (!prefetch) {\n\t\t\t\t\tlayoutStack[i].reuse = true;\n\t\t\t\t}\n\t\t\t\tnewLayoutStack[i] = layoutStack[i];\n\t\t\t\tObject.assign(data, layoutStack[i].data);\n\t\t\t} else {\n\t\t\t\tconst stackLayout = { path: layoutPath, data: {}, reuse: false, slotRegion: null };\n\t\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;\n\t\t\t\tconst layoutServerEndPoint: PageServerEndPoint | undefined =\n\t\t\t\t\tlayout.serverEndPoint && (await layout.serverEndPoint())?.default;\n\t\t\t\tconst layoutResponse = await loadClientAndServerData(\n\t\t\t\t\tstackLayout.data,\n\t\t\t\t\tdocument.location.origin + getBasePath() + layoutPath,\n\t\t\t\t\tquery,\n\t\t\t\t\tparams,\n\t\t\t\t\tlayoutEndPoint,\n\t\t\t\t\tlayoutServerEndPoint,\n\t\t\t\t);\n\t\t\t\tif (layoutResponse?.ok === false) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tObject.assign(data, stackLayout.data);\n\t\t\t\tnewLayoutStack.push(stackLayout);\n\t\t\t}\n\t\t}\n\t}\n\tlet endPointResponse = await loadClientAndServerData(\n\t\tdata,\n\t\tdocument.location.origin + getBasePath() + path,\n\t\tquery,\n\t\tparams,\n\t\tclientEndPoint,\n\t\tserverEndPoint,\n\t);\n\tif (endPointResponse?.ok === false) {\n\t\treturn;\n\t}\n\treturn data;\n}\n\nasync function loadClientAndServerData(\n\tdata: Record<string, any>,\n\tlocation: string,\n\tquery: URLSearchParams,\n\tparams: Record<string, string>,\n\tclientEndPoint?: PageEndPoint,\n\tserverEndPoint?: PageServerEndPoint,\n): Promise<Response | undefined | void> {\n\tlet prefetchedData = client.prefetchedData;\n\n\tif (clientEndPoint?.load) {\n\t\tconst clientKey = location + (query.size > 0 ? `?${query}` : \"\");\n\t\tif (prefetchedData[clientKey]) {\n\t\t\tObject.assign(data, prefetchedData[clientKey]);\n\t\t} else {\n\t\t\tconst clientUrl = new URL(document.location.href);\n\t\t\tfor (let [name, value] of query) {\n\t\t\t\tclientUrl.searchParams.append(name, value);\n\t\t\t}\n\t\t\tconst clientParams = buildClientParams(clientUrl, params, data);\n\t\t\tconst clientResponse = await clientEndPoint.load(clientParams);\n\t\t\tif (clientResponse) {\n\t\t\t\tif (clientResponse.ok) {\n\t\t\t\t\tif (clientResponse.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\t\tconst clientData = await clientResponse.json();\n\t\t\t\t\t\tObject.assign(data, clientData);\n\t\t\t\t\t\tprefetchedData[clientKey] = clientData;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn clientResponse;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (serverEndPoint?.load) {\n\t\tconst serverLocation = location.replace(/\\/$/, \"\") + \"/~server\";\n\t\tconst serverKey = serverLocation + (query.size > 0 ? `?${query}` : \"\");\n\t\tif (prefetchedData[serverKey]) {\n\t\t\tObject.assign(data, prefetchedData[serverKey]);\n\t\t} else {\n\t\t\tconst serverUrl = new URL(serverLocation);\n\t\t\tfor (let [name, value] of query) {\n\t\t\t\tserverUrl.searchParams.append(name, value);\n\t\t\t}\n\t\t\tconst serverResponse = await fetch(serverUrl);\n\t\t\tif (serverResponse) {\n\t\t\t\tif (serverResponse.ok) {\n\t\t\t\t\tif (serverResponse.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\t\tconst serverData = await serverResponse.json();\n\t\t\t\t\t\tObject.assign(data, serverData);\n\t\t\t\t\t\tprefetchedData[serverKey] = serverData;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn serverResponse;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction buildClientParams(url: URL, params: Record<string, string>, data: Record<string, any>) {\n\treturn {\n\t\turl,\n\t\tparams,\n\t\tdata,\n\t};\n}\n","import { clearLayoutSlot, fillLayoutSlot, hydrate } from \"@torpor/view\";\nimport { type Component, type SlotRender } from \"@torpor/view\";\nimport { mount, unmount } from \"@torpor/view\";\nimport $page from \"../state/$page\";\nimport client from \"../state/client\";\nimport { getBasePath, stripBaseFromUrl } from \"../site/basePath\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport formSubmit from \"./formSubmit\";\nimport loadData from \"./loadData\";\n\n// @ts-ignore\nexport default async function navigate(rawUrl: URL, withHydration = false): Promise<boolean> {\n\tlet parent = document.getElementById(\"app\");\n\tif (!parent) {\n\t\t// TODO: 500\n\t\tconsole.log(\"500\");\n\t\treturn false;\n\t}\n\n\t// The base path is stripped before matching (routes are base-free), but\n\t// kept in browser state: the caller pushes the original URL. When the\n\t// url doesn't carry the base there will be no matching route anyway\n\tconst url = stripBaseFromUrl(rawUrl, getBasePath()) ?? rawUrl;\n\tconst path = url.pathname;\n\tconst query = url.searchParams;\n\n\t//console.log(`navigating to '${path}'${query.size ? ` with ${query}` : \"\"}`);\n\n\tconst route = client.router.match(path, query);\n\tif (!route) {\n\t\t// TODO: 404\n\t\tconsole.log(\"404\");\n\t\treturn false;\n\t}\n\n\t// Update $page before building the components\n\t$page.url = url;\n\tif (path.endsWith(\"/_error\")) {\n\t\t$page.status = parseInt(query.get(\"status\") ?? \"404\");\n\t\t$page.error = { message: query.get(\"message\") ?? \"\" };\n\t\t// Make it look a bit classier by removing the query -- keeping the\n\t\t// original URL, so the base path stays in the address bar\n\t\twindow.history.replaceState({}, \"\", rawUrl.toString().split(\"?\")[0]);\n\t} else {\n\t\t$page.status = 200;\n\t}\n\tconst handler = route.handler;\n\tconst params = route.params || {};\n\n\t// There must be a client endpoint with a component\n\tconst clientEndPoint: PageEndPoint | undefined = (await handler.endPoint()).default;\n\tif (!clientEndPoint?.component) {\n\t\t// TODO: 404\n\t\tconsole.log(\"404\");\n\t\treturn false;\n\t}\n\n\t// There may be a server endpoint\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await handler.serverEndPoint())?.default;\n\n\tlet newLayoutStack: LayoutPath[] = [];\n\n\t// Pass the data into $props\n\t// TODO: Don't load if this is the first time -- it should have been passed\n\t// to us, somehow...\n\tconst data = await loadData(\n\t\thandler,\n\t\tparams,\n\t\tpath,\n\t\tquery,\n\t\tnewLayoutStack,\n\t\tclientEndPoint,\n\t\tserverEndPoint,\n\t);\n\tif (data === undefined) {\n\t\t// The data couldn't be loaded -- a load function returned an error\n\t\t// response, or (on a prerendered site with no server) the ~server\n\t\t// request got a 404. Leave the current page alone; the caller\n\t\t// (e.g. the client entry) falls back to a full page load\n\t\treturn false;\n\t}\n\t// We may have form data in a hidden input -- not sure if this is the best\n\t// way to do it\n\tlet formInput = document.getElementById(\"t-form-data\") as HTMLInputElement;\n\tlet form: Record<string, string> | undefined;\n\tif (formInput) {\n\t\tform = JSON.parse(formInput.value);\n\t\t$page.form = form;\n\t\tformInput.remove();\n\t}\n\tlet $props: Record<string, any> = { data };\n\n\t// We may have form data in $page.form, either from the hidden input\n\t// (above), or added via onformsubmit (below)\n\t$props.form = $page.form;\n\n\t// Add some special context for submitting Forms client-side\n\tconst $context = {\n\t\tTorporBuildContext: { onformsubmit: formSubmit },\n\t};\n\n\tclient.layoutStack.push({ path: route.handler.path, data: {}, reuse: false, slotRegion: null });\n\tclient.layoutStack = newLayoutStack;\n\tlet layoutStack = client.layoutStack;\n\n\t// If there are layouts, work our way upwards, pushing each component into\n\t// the default slot of its parent\n\t// TODO: There's probably a nicer way to do this with reducers or something\n\tlet component = clientEndPoint.component as Component;\n\tlet slots: Record<string, SlotRender> | undefined = undefined;\n\tlet reused = false;\n\t// The index of the innermost reused layout. Its slotRegion is the region\n\t// that must be cleared and refilled (it contains the next layout's or the\n\t// page's content). This is usually the last entry of the stack, but not\n\t// when an outer layout is reused while an inner one is new — e.g.\n\t// navigating between sections that share the root layout.\n\tlet reusedIndex = -1;\n\tif (handler.layouts) {\n\t\tlet slotFunctions: SlotRender[] = [];\n\t\t// The last slot function will render the client component\n\t\tslotFunctions[handler.layouts.length] = function clientComponent(parent, anchor) {\n\t\t\tlet i = layoutStack.length - 1;\n\t\t\tlayoutStack[i].slotRegion = fillLayoutSlot(\n\t\t\t\tclientEndPoint.component!,\n\t\t\t\tslotFunctions[i + 1],\n\t\t\t\tparent,\n\t\t\t\tanchor,\n\t\t\t\t$props,\n\t\t\t\t$context,\n\t\t\t);\n\t\t};\n\n\t\t// Each earlier slot function will render a layout\n\t\tfor (let i = handler.layouts.length - 1; i >= 0; i--) {\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await handler.layouts[i].endPoint())\n\t\t\t\t?.default;\n\t\t\tif (layoutEndPoint?.component) {\n\t\t\t\tif (layoutStack[i].reuse) {\n\t\t\t\t\t// Reuse this layout — clear and refill its slot (done in\n\t\t\t\t\t// the try block below so a failure doesn't leave the slot\n\t\t\t\t\t// half-cleared)\n\t\t\t\t\tcomponent = slotFunctions[i + 1] as Component;\n\t\t\t\t\treusedIndex = i;\n\t\t\t\t\treused = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else if (i === 0) {\n\t\t\t\t\tcomponent = layoutEndPoint.component as Component;\n\t\t\t\t\tslots = { _: slotFunctions[i + 1] };\n\t\t\t\t} else {\n\t\t\t\t\tslotFunctions[i] = function layoutComponent(parent, anchor, _, $context) {\n\t\t\t\t\t\tlayoutStack[i - 1].slotRegion = fillLayoutSlot(\n\t\t\t\t\t\t\tlayoutEndPoint.component!,\n\t\t\t\t\t\t\tslotFunctions[i + 1],\n\t\t\t\t\t\t\tparent,\n\t\t\t\t\t\t\tanchor,\n\t\t\t\t\t\t\t$props,\n\t\t\t\t\t\t\t$context,\n\t\t\t\t\t\t);\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// A definite alias, so that the render closure's type checks hold\n\tlet app: HTMLElement = parent;\n\t// The DOM update, wrapped by the view transitions API when navigating\n\t// (but not on the initial hydration)\n\tconst render = () => {\n\t\ttry {\n\t\t\tif (reused) {\n\t\t\t\t// The layout is being reused — clear the old slot content, then\n\t\t\t\t// call the slot function directly to fill it with the new page.\n\t\t\t\t// We must not go through `mount` here: the slot's container still\n\t\t\t\t// holds the layout's own children (e.g. a header), which `mount`\n\t\t\t\t// refuses to mount into. Both the clear and the fill are inside\n\t\t\t\t// the try so that a failure doesn't leave the slot half-cleared.\n\t\t\t\tconst slotRegion = layoutStack[reusedIndex].slotRegion;\n\t\t\t\tapp = slotRegion.startNode!.parentNode as HTMLElement;\n\t\t\t\tclearLayoutSlot(slotRegion);\n\t\t\t\tcomponent(app, null);\n\t\t\t} else if (withHydration) {\n\t\t\t\thydrate(app, component, $props, slots);\n\t\t\t} else {\n\t\t\t\t// The layout chain changed (or there was no previous layout to\n\t\t\t\t// reuse): tear down the previous UI entirely — disposing its\n\t\t\t\t// region tree and clearing `#app` — so `mount` starts fresh.\n\t\t\t\t// Without this, `mount` throws because `#app` still holds the\n\t\t\t\t// previous render's children, and it would reuse a stale root\n\t\t\t\t// region.\n\t\t\t\tunmount(app);\n\t\t\t\tmount(app, component, $props, slots);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// TODO: Show a proper Error component\n\t\t\tapp.innerHTML = '<span style=\"color: red\">Script syntax error</span><p>' + error + \"</p>\";\n\t\t\tconsole.log(error);\n\t\t}\n\n\t\tif (!withHydration) {\n\t\t\t// Scroll back to the top when moving to a different page; keep the\n\t\t\t// scroll position for same-page navigations (query changes,\n\t\t\t// re-renders after form actions)\n\t\t\tconst current = stripBaseFromUrl(new URL(document.location.href), getBasePath())?.pathname;\n\t\t\tif (current !== path) {\n\t\t\t\twindow.scrollTo(0, 0);\n\t\t\t}\n\t\t}\n\t};\n\n\tif (\n\t\t!withHydration &&\n\t\tclient.viewTransitions &&\n\t\ttypeof document.startViewTransition === \"function\"\n\t) {\n\t\tdocument.startViewTransition(render);\n\t} else {\n\t\trender();\n\t}\n\n\t// Reset prefetched data on each navigation\n\tclient.prefetchedData = {};\n\n\treturn true;\n}\n","import navigate from \"./navigate\";\n\n/**\n * Loads and renders the page at the supplied path.\n */\nexport default async function load(path: string): Promise<boolean> {\n\tconst url = new URL(path, document.location.href);\n\treturn await navigate(url);\n}\n"],"mappings":";;;;AAEA,MAAM,gBAA+B,OAAO,IAAI,aAAa;AAE7D,MAAM,SAEJ,WAAW,mBAAmB;CAE9B,QAAQ;CACR,aAAa,CAAC;CAEd,gBAAgB,CAAC;CACjB,iBAAiB;AAClB;;;;;;ACRD,eAA8B,SAA2B;CAExD,OAAO,MAAM,SAAS,IADN,IAAI,SAAS,SAAS,IAChB,CAAG;AAC1B;;;ACJA,eAA8B,WAAW,GAA+B;CAEvE,EAAE,eAAe;CAIjB,MAAM,OAAO,KAAA;CAGb,MAAM,OAAO,EAAE;CACf,MAAM,SAAS,EAAE;CAIjB,IAAI,SAAS,KAAK,UAAU,SAAS;CACrC,IAAI,UAAU,OAAO,cAAc,OAAO,eAAe,SAAS,KACjE,SAAS,OAAO;CAEjB,MAAM,UAAU;EACf,MAAM,IAAI,SAAS,IAAI;EACvB,QAAQ;EACR,MAAM;EACN,aAAa;EAIb,SAAS,EACR,wBAAwB,GACzB;CACD;CACA,MAAM,WAAW,MAAM,MACtB,QAEA,OACD;CAEA,IACC,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,qBAAqB,KAC1C,iCAAiC,KAAK,SAAS,QAAQ,IAAI,qBAAqB,CAAE,GACjF;EAGD,MAAM,mBACL,SAAS,QAAQ,IAAI,qBAAqB,CAAC,EAAE,MAAM,gCAAgC,CAAC,CAAE,MACtF;EACD,MAAM,eAAe,SAAS,cAAc,GAAG;EAC/C,aAAa,OAAO,OAAO,IAAI,gBAAgB,MAAM,SAAS,KAAK,CAAC;EACpE,aAAa,WAAW;EACxB,aAAa,MAAM;CACpB,OAAO,IAAI,SAAS,WAAW,OAAO,SAAS,QAAQ,IAAI,wBAAwB,GAAG;EAErF,MAAM,WAAW,SAAS,QAAQ,IAAI,UAAU;EAChD,MAAM,KAAK,QAAQ;EACnB,OAAO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AM,aAAa,YAAY,YAAY,CAAC;IAC5C,MAAM,WAAW,UAAW;IAC5B,gBAAgB,UAAU;IAC1B,UAAU,KAAK,IAAI;GACpB,OAAO,IAAI,eACV,QAAQ,KAAK,WAAW,QAAQ,KAAK;QAC/B;IAON,QAAQ,GAAG;IACX,MAAM,KAAK,WAAW,QAAQ,KAAK;GACpC;EACD,SAAS,OAAO;GAEf,IAAI,YAAY,6DAA2D,QAAQ;GACnF,QAAQ,IAAI,KAAK;EAClB;EAEA,IAAI,CAAC,eAIY;OAAA,iBAAiB,IAAI,IAAI,SAAS,SAAS,IAAI,GAAG,YAAY,CAAC,CAAC,EAAE,aAClE,MACf,OAAO,SAAS,GAAG,CAAC;EAAA;CAGvB;CAEA,IACC,CAAC,iBACD,OAAO,mBACP,OAAO,SAAS,wBAAwB,YAExC,SAAS,oBAAoB,MAAM;MAEnC,OAAO;CAIR,OAAO,iBAAiB,CAAC;CAEzB,OAAO;AACR;;;;;;AC9NA,eAA8B,KAAK,MAAgC;CAElE,OAAO,MAAM,SAAS,IADN,IAAI,MAAM,SAAS,SAAS,IACtB,CAAG;AAC1B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"response-CuNPcxsY.mjs","names":[],"sources":["../src/response/badRequest.ts","../src/response/created.ts","../src/response/forbidden.ts","../src/response/found.ts","../src/response/methodNotAllowed.ts","../src/response/movedPermanently.ts","../src/response/notModified.ts","../src/response/permanentRedirect.ts","../src/response/serverError.ts","../src/response/temporaryRedirect.ts","../src/response/unauthorized.ts"],"sourcesContent":["import response from \"./response\";\nimport type { Jsonify } from \"../types/Jsonify\";\nimport type TypedResponse from \"./TypedResponse\";\n\ntype BadRequestResponse<T extends object | string | undefined> = T extends object\n\t? TypedResponse<Jsonify<T>>\n\t: Response;\n\n/**\n * 400 Bad Request\n *\n * The HTTP 400 Bad Request client error response status code indicates that the\n * server would not process the request due to something the server considered\n * to be a client error. The reason for a 400 response is typically due to\n * malformed request syntax, invalid request message framing, or deceptive\n * request routing.\n *\n * Clients that receive a 400 response should expect that repeating the request\n * without modification will fail with the same error.\n *\n * An object body is typed: it becomes the page's `$props.form` (with its JSON\n * form) after a form submit, so validation errors can be surfaced with their\n * field types via `PageForm`.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/400\n */\nexport default function badRequest<T extends object | string | undefined>(\n\tbody?: T,\n): BadRequestResponse<T> {\n\treturn response(400, body ?? \"Bad request\") as BadRequestResponse<T>;\n}\n","import type { Jsonify } from \"../types/Jsonify\";\nimport type TypedResponse from \"./TypedResponse\";\nimport response from \"./response\";\n\ntype CreatedResponse<T extends object | string | undefined> = T extends object\n\t? TypedResponse<Jsonify<T>>\n\t: Response;\n\n/**\n * 201 Created\n *\n * The HTTP 201 Created successful response status code indicates that the HTTP\n * request has led to the creation of a resource. This status code is commonly\n * sent as the result of a POST request.\n *\n * The new resource, or a description and link to the new resource, is created\n * before the response is returned. The newly-created items can be returned in\n * the body of the response message, but must be locatable by the URL of the\n * initiating request or by the URL in the value of the Location header provided\n * with the response.\n *\n * An object body is typed: the client sees its JSON form through\n * `makeApi`-created callers.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/201\n */\nexport default function created<T extends object | string | undefined>(\n\tbody?: T,\n): CreatedResponse<T> {\n\treturn response(201, body) as CreatedResponse<T>;\n}\n","import response from \"./response\";\n\n/**\n * 403 Forbidden\n *\n * The HTTP 403 Forbidden client error response status code indicates that the\n * server understood the request but refused to process it. This status is\n * similar to 401, except that for 403 Forbidden responses, authenticating or\n * re-authenticating makes no difference. The request failure is tied to\n * application logic, such as insufficient permissions to a resource or action.\n *\n * Clients that receive a 403 response should expect that repeating the request\n * without modification will fail with the same error. Server owners may decide\n * to send a 404 response instead of a 403 if acknowledging the existence of a\n * resource to clients with insufficient privileges is not desired.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403\n */\nexport default function forbidden(body?: object | string): Response {\n\treturn response(403, body ?? \"Forbidden\");\n}\n","import transfer from \"./transfer\";\n\n/**\n * 302 Found\n *\n * The HTTP 302 Found redirection response status code indicates that the\n * requested resource has been temporarily moved to the URL in the Location\n * header.\n *\n * A browser receiving this status will automatically request the resource at\n * the URL in the Location header, redirecting the user to the new page. Search\n * engines receiving this response will not attribute links to the original URL\n * to the new resource, meaning no SEO value is transferred to the new URL.\n *\n * > Note: In the Fetch Standard, when a user agent receives a 302 in response\n * > to a POST request, it uses the GET method in the subsequent redirection\n * > request, as permitted by the HTTP specification. To avoid user agents\n * > modifying the request, use 307 Temporary Redirect instead, as altering the\n * > method after a 307 response is prohibited.\n *\n * > In cases where you want any request method to be changed to GET, use 303\n * > See Other. This is useful when you want to give a response to a PUT method\n * > that is not the uploaded resource but a confirmation message such as: \"you\n * > successfully uploaded XYZ\".\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/302\n */\nexport default function found(location: string): Response {\n\treturn transfer(302, location);\n}\n","import response from \"./response\";\n\n/**\n * 405 Method Not Allowed\n *\n * The HTTP 405 Method Not Allowed client error response status code indicates\n * that the server knows the request method, but the target resource doesn't\n * support this method. The server must generate an Allow header in a 405\n * response with a list of methods that the target resource currently supports.\n *\n * Improper server-side permissions set on files or directories may cause a 405\n * response when the request would otherwise be expected to succeed.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/405\n */\nexport default function methodNotAllowed(body?: object | string): Response {\n\treturn response(405, body ?? \"Method not allowed\");\n}\n","import transfer from \"./transfer\";\n\n/**\n * 301 Moved Permanently\n *\n * The HTTP 301 Moved Permanently redirection response status code indicates\n * that the requested resource has been permanently moved to the URL in the\n * Location header.\n *\n * A browser receiving this status will automatically request the resource at\n * the URL in the Location header, redirecting the user to the new page. Search\n * engines receiving this response will attribute links to the original URL to\n * the redirected resource, passing the SEO ranking to the new URL.\n *\n * > Note: In the Fetch Standard, when a user agent receives a 301 in response\n * > to a POST request, it uses the GET method in the subsequent redirection\n * > request, as permitted by the HTTP specification. To avoid user agents\n * > modifying the request, use 308 Permanent Redirect instead, as altering the\n * > method after a 308 response is prohibited.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301\n */\nexport default function movedPermanently(location: string): Response {\n\treturn transfer(301, location);\n}\n","import transfer from \"./transfer\";\n\n/**\n * 304 Not Modified\n *\n * The HTTP 304 Not Modified redirection response status code indicates that\n * there is no need to retransmit the requested resources.\n *\n * This response code is sent when the request is a conditional GET or HEAD\n * request with an If-None-Match or an If-Modified-Since header and the\n * condition evaluates to 'false'. It confirms that the resource cached by the\n * client is still valid and that the server would have sent a 200 OK response\n * with the resource if the condition evaluated to 'true'. See HTTP caching for\n * more information.\n *\n * The response must not contain a body and must include the headers that would\n * have been sent in an equivalent 200 response, such as:\n *\n * - Cache-Control\n * - Content-Location\n * - Date\n * - ETag\n * - Expires\n * - Vary\n *\n * > Note: Many developer tools' network panels of browsers create extraneous\n * > requests leading to 304 responses, so that access to the local cache is\n * > visible to developers.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304\n */\nexport default function notModified(): Response {\n\treturn transfer(304, \"\");\n}\n","import transfer from \"./transfer\";\n\n/**\n * 308 Permanent Redirect\n *\n * The HTTP 308 Permanent Redirect redirection response status code indicates\n * that the requested resource has been permanently moved to the URL given by\n * the Location header.\n *\n * A browser receiving this status will automatically request the resource at\n * the URL in the Location header, redirecting the user to the new page. Search\n * engines receiving this response will attribute links to the original URL to\n * the redirected resource, passing the SEO ranking to the new URL.\n *\n * The request method and the body will not be modified by the client in the\n * redirected request. A 301 Moved Permanently requires the request method and\n * the body to remain unchanged when redirection is performed, but this is\n * incorrectly handled by older clients to use the GET method instead.\n *\n * > Note: Some Web applications may use the 308 Permanent Redirect in a\n * > non-standard way and for different purposes. For example, Google Drive uses\n * > a 308 Resume Incomplete response to indicate to the client when an\n * > unfinished upload has stalled. See Perform a resumable download on the\n * > Google Drive documentation for more information.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/308\n */\nexport default function permanentRedirect(location: string): Response {\n\treturn transfer(308, location);\n}\n","import response from \"./response\";\n\n/**\n * 500 Server Error\n *\n * The HTTP 500 Internal Server Error server error response status code\n * indicates that the server encountered an unexpected condition that prevented\n * it from fulfilling the request. This error is a generic \"catch-all\" response\n * to server issues, indicating that the server cannot find a more appropriate\n * 5XX error to respond with.\n *\n * If you're a visitor seeing 500 errors on a web page, these issues require\n * investigation by server owners or administrators. There are many possible\n * causes of 500 errors, including: improper server configuration, out-of-memory\n * (OOM) issues, unhandled exceptions, improper file permissions, or other\n * complex factors. Server administrators may proactively log occurrences of\n * server error responses, like the 500 status code, with details about the\n * initiating requests to improve the stability of a service in the future.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500\n */\nexport default function serverError(body?: object | string): Response {\n\treturn response(500, body ?? \"Server error\");\n}\n","import transfer from \"./transfer\";\n\n/**\n * 307 Temporary Redirect\n *\n * The HTTP 307 Temporary Redirect redirection response status code indicates\n * that the resource requested has been temporarily moved to the URL in the\n * Location header.\n *\n * A browser receiving this status will automatically request the resource at\n * the URL in the Location header, redirecting the user to the new page. Search\n * engines receiving this response will not attribute links to the original URL\n * to the new resource, meaning no SEO value is transferred to the new URL.\n *\n * The method and the body of the original request are reused to perform the\n * redirected request. In the cases where you want the request method to be\n * changed to GET, use 303 See Other instead. This is useful when you want to\n * give an answer to a successful PUT request that is not the uploaded resource,\n * but a status monitor or confirmation message like \"You have successfully\n * uploaded XYZ\".\n *\n * The difference between 307 and 302 is that 307 guarantees that the client\n * will not change the request method and body when the redirected request is\n * made. With 302, older clients incorrectly changed the method to GET. 307 and\n * 302 responses are identical when the request method is GET.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/307\n */\nexport default function temporaryRedirect(location: string): Response {\n\treturn transfer(307, location);\n}\n","import response from \"./response\";\n\n/**\n * 401 Unauthorized\n *\n * The HTTP 401 Unauthorized client error response status code indicates that a\n * request was not successful because it lacks valid authentication credentials\n * for the requested resource. This status code is sent with an HTTP\n * WWW-Authenticate response header that contains information on the\n * authentication scheme the server expects the client to include to make the\n * request successfully.\n *\n * A 401 Unauthorized is similar to the 403 Forbidden response, except that a\n * 403 is returned when a request contains valid credentials, but the client\n * does not have permissions to perform a certain action.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/401\n */\nexport default function unauthorized(body?: object | string): Response {\n\treturn response(401, body ?? \"Unauthorized\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0BA,SAAwB,WACvB,MACwB;CACxB,OAAO,SAAS,KAAK,QAAQ,aAAa;AAC3C;;;;;;;;;;;;;;;;;;;;;ACJA,SAAwB,QACvB,MACqB;CACrB,OAAO,SAAS,KAAK,IAAI;AAC1B;;;;;;;;;;;;;;;;;;;ACZA,SAAwB,UAAU,MAAkC;CACnE,OAAO,SAAS,KAAK,QAAQ,WAAW;AACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACOA,SAAwB,MAAM,UAA4B;CACzD,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;ACdA,SAAwB,iBAAiB,MAAkC;CAC1E,OAAO,SAAS,KAAK,QAAQ,oBAAoB;AAClD;;;;;;;;;;;;;;;;;;;;;;;ACKA,SAAwB,iBAAiB,UAA4B;CACpE,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACOA,SAAwB,cAAwB;CAC/C,OAAO,SAAS,KAAK,EAAE;AACxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACNA,SAAwB,kBAAkB,UAA4B;CACrE,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;;;;;;;ACRA,SAAwB,YAAY,MAAkC;CACrE,OAAO,SAAS,KAAK,QAAQ,cAAc;AAC5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACKA,SAAwB,kBAAkB,UAA4B;CACrE,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;;;;ACZA,SAAwB,aAAa,MAAkC;CACtE,OAAO,SAAS,KAAK,QAAQ,cAAc;AAC5C"}