@torpor/build 1.10.0 → 1.11.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.
- package/README.md +1 -1
- package/dist/{SessionHelper-MaodMaLU.d.mts → CacheOptions-C4-ebVt9.d.mts} +58 -8
- package/dist/CacheOptions-C4-ebVt9.d.mts.map +1 -0
- package/dist/{MiddlewareFunction-7rIvFkjl.d.mts → MiddlewareFunction-DMYxjzF4.d.mts} +25 -2
- package/dist/MiddlewareFunction-DMYxjzF4.d.mts.map +1 -0
- package/dist/{Router-Bxm7K20d.d.mts → Router-DyK3DTWQ.d.mts} +2 -2
- package/dist/{Router-Bxm7K20d.d.mts.map → Router-DyK3DTWQ.d.mts.map} +1 -1
- package/dist/{Server-Djd9-NkU.mjs → Server-BCijhgZp.mjs} +3 -3
- package/dist/{Server-Djd9-NkU.mjs.map → Server-BCijhgZp.mjs.map} +1 -1
- package/dist/{Server-hwbZ7P2g.d.mts → Server-ClwvuilS.d.mts} +2 -2
- package/dist/{Server-hwbZ7P2g.d.mts.map → Server-ClwvuilS.d.mts.map} +1 -1
- package/dist/{ServerEvent-L0rT_mBJ.mjs → ServerEvent-BBRkd4Ya.mjs} +127 -31
- package/dist/ServerEvent-BBRkd4Ya.mjs.map +1 -0
- package/dist/{ServerHook-CyVEr5OL.d.mts → ServerHook-DY-NSG6n.d.mts} +2 -2
- package/dist/{ServerHook-CyVEr5OL.d.mts.map → ServerHook-DY-NSG6n.d.mts.map} +1 -1
- package/dist/{ServerLoadEvent-F60w1TZt.d.mts → ServerLoadEvent-CpcgsKCU.d.mts} +19 -5
- package/dist/ServerLoadEvent-CpcgsKCU.d.mts.map +1 -0
- package/dist/{Site-CAeAqjkk.d.mts → Site-BEMQW1_y.d.mts} +31 -11
- package/dist/Site-BEMQW1_y.d.mts.map +1 -0
- package/dist/{basePath-DQnbHc7o.mjs → basePath-B6hmOMl4.mjs} +89 -4
- package/dist/basePath-B6hmOMl4.mjs.map +1 -0
- package/dist/bin/index.js +1 -1
- package/dist/clientEntry.mjs +10 -5
- package/dist/clientEntry.mjs.map +1 -1
- package/dist/dev.d.mts +2 -2
- package/dist/dev.mjs +2 -2
- package/dist/{devPlugin-D9b5uhzm.mjs → devPlugin-BGrTpcC2.mjs} +3 -3
- package/dist/{devPlugin-D9b5uhzm.mjs.map → devPlugin-BGrTpcC2.mjs.map} +1 -1
- package/dist/discovery.d.mts +1 -1
- package/dist/discovery.mjs +1 -1
- package/dist/index.d.mts +22 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -1
- package/dist/{load-BODDzmH0.mjs → load-Dw187nJ_.mjs} +95 -52
- package/dist/load-Dw187nJ_.mjs.map +1 -0
- package/dist/nav.d.mts +2 -1
- package/dist/nav.d.mts.map +1 -1
- package/dist/nav.mjs +3 -3
- package/dist/nodeDev.d.mts +1 -1
- package/dist/nodeDev.mjs +1 -1
- package/dist/openapi.d.mts +2 -2
- package/dist/{read-DxMVAh5Y.mjs → read-CPW2iPum.mjs} +21 -2
- package/dist/read-CPW2iPum.mjs.map +1 -0
- package/dist/{response-C5EZsszY.mjs → response-B4UoOJvv.mjs} +3 -24
- package/dist/response-B4UoOJvv.mjs.map +1 -0
- package/dist/response.mjs +2 -2
- package/dist/run.d.mts +1 -1
- package/dist/run.d.mts.map +1 -1
- package/dist/run.mjs +1 -1
- package/dist/{runHooks-D5p1Rh7i.mjs → runHooks-C7kt7SEo.mjs} +36 -2
- package/dist/runHooks-C7kt7SEo.mjs.map +1 -0
- package/dist/{runOpenApi-BZ314IiI.mjs → runOpenApi-DK-QnYEr.mjs} +239 -18
- package/dist/runOpenApi-DK-QnYEr.mjs.map +1 -0
- package/dist/server/Server.d.mts +1 -1
- package/dist/server/Server.mjs +1 -1
- package/dist/server.d.mts +30 -6
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +47 -3
- package/dist/server.mjs.map +1 -1
- package/dist/{serverEntry-Da1PFlIU.d.mts → serverEntry-BFad1k1C.d.mts} +3 -3
- package/dist/serverEntry-BFad1k1C.d.mts.map +1 -0
- package/dist/{serverEntry-8YnfpKTj.mjs → serverEntry-DAT7o7o2.mjs} +3 -5
- package/dist/serverEntry-DAT7o7o2.mjs.map +1 -0
- package/dist/serverEntry.d.mts +1 -1
- package/dist/serverEntry.mjs +1 -1
- package/dist/{serverHandlers-Ba_35jpO.mjs → serverHandlers-B1L8I72-.mjs} +398 -192
- package/dist/serverHandlers-B1L8I72-.mjs.map +1 -0
- package/dist/{sitemap-CnIYTLhu.d.mts → sitemap-CKmagPyL.d.mts} +2 -2
- package/dist/{sitemap-CnIYTLhu.d.mts.map → sitemap-CKmagPyL.d.mts.map} +1 -1
- package/dist/{sitemap-4imxJVrG.mjs → sitemap-DdzFjGlo.mjs} +2 -2
- package/dist/{sitemap-4imxJVrG.mjs.map → sitemap-DdzFjGlo.mjs.map} +1 -1
- package/dist/state.d.mts +1 -4
- package/dist/state.d.mts.map +1 -1
- package/dist/state.mjs +1 -1
- package/dist/test.d.mts +2 -2
- package/dist/test.mjs +2 -2
- package/dist/{unprocessable-DwAG44Rh.mjs → unprocessable-BZXwyN0n.mjs} +23 -2
- package/dist/unprocessable-BZXwyN0n.mjs.map +1 -0
- package/package.json +3 -3
- package/src/types/manifest.d.ts +3 -0
- package/dist/MiddlewareFunction-7rIvFkjl.d.mts.map +0 -1
- package/dist/ServerEvent-L0rT_mBJ.mjs.map +0 -1
- package/dist/ServerLoadEvent-F60w1TZt.d.mts.map +0 -1
- package/dist/SessionHelper-MaodMaLU.d.mts.map +0 -1
- package/dist/Site-CAeAqjkk.d.mts.map +0 -1
- package/dist/_page-CW6SLuT4.mjs +0 -14
- package/dist/_page-CW6SLuT4.mjs.map +0 -1
- package/dist/basePath-DQnbHc7o.mjs.map +0 -1
- package/dist/load-BODDzmH0.mjs.map +0 -1
- package/dist/read-DxMVAh5Y.mjs.map +0 -1
- package/dist/response-C5EZsszY.mjs.map +0 -1
- package/dist/runHooks-D5p1Rh7i.mjs.map +0 -1
- package/dist/runOpenApi-BZ314IiI.mjs.map +0 -1
- package/dist/serverEntry-8YnfpKTj.mjs.map +0 -1
- package/dist/serverEntry-Da1PFlIU.d.mts.map +0 -1
- package/dist/serverHandlers-Ba_35jpO.mjs.map +0 -1
- package/dist/unprocessable-DwAG44Rh.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-Dw187nJ_.mjs","names":[],"sources":["../src/state/$page.ts","../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 { $watch } from \"@torpor/view\";\nimport type PageState from \"../types/PageState\";\n\nconst PAGE_SYMBOL: unique symbol = Symbol.for(\"torp.Page\");\n\n/**\n * The client's page state, which client navigation keeps up to date and\n * passes to the page's components as `$context.$page`. (On the server, each\n * request has its own page state; see `site/requestPage.ts`.)\n */\nconst $page: PageState =\n\t// @ts-ignore\n\t(globalThis[PAGE_SYMBOL] ??= $watch(\n\t\t{\n\t\t\tstatus: 404,\n\t\t\turl: new URL(\"http://localhost\"),\n\t\t\tform: undefined,\n\t\t\tflash: undefined,\n\t\t\terror: {\n\t\t\t\tmessage: \"\",\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tshallow: true,\n\t\t},\n\t));\n\nexport default $page;\n","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\tprefetchedServerData: {},\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. Returns whether\n * the page was rendered in place (see `load`).\n */\nexport default async function reload(): Promise<boolean> {\n\tconst url = new URL(document.location.href);\n\treturn (await navigate(url)).type === \"rendered\";\n}\n","import $page from \"../state/$page\";\nimport load from \"./load\";\nimport reload from \"./reload\";\n\n/**\n * The detail of the `torpor:submit-failed` window event.\n */\nexport type SubmitFailureDetail = {\n\t/** The url the form was submitted to. */\n\taction: string;\n\t/** The failure that stopped the submit. */\n\terror?: unknown;\n};\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 | null;\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: button ? new FormData(form, button) : 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\tlet response: Response;\n\ttry {\n\t\tresponse = await fetch(\n\t\t\taction,\n\t\t\t// @ts-ignore -- don't know what it's complaining about here\n\t\t\toptions,\n\t\t);\n\t} catch (error) {\n\t\t// A rejected fetch is a failed submission -- offline, or the server\n\t\t// couldn't be reached. Nothing navigates and the form keeps what the\n\t\t// user typed, so the app can show its own notice and let them retry.\n\t\tconsole.error(\"The form submit failed\", error);\n\t\thandleSubmitFailure(form, action, error);\n\t\treturn;\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} else if (response.status >= 500) {\n\t\t// A server error: like a no-javascript submit, the response is the\n\t\t// error page rendered at this url with the error status. Swap the\n\t\t// document for it -- the url stays, so a transient failure can be\n\t\t// retried with a refresh. Without an error page, reload, which will\n\t\t// show the raw error response instead\n\t\tif (response.headers.get(\"Content-Type\")?.includes(\"text/html\")) {\n\t\t\tconst html = await response.text();\n\t\t\tdocument.open();\n\t\t\tdocument.write(html);\n\t\t\tdocument.close();\n\t\t} else {\n\t\t\twindow.location.reload();\n\t\t}\n\t}\n}\n\n/**\n * Tells the app that a client form submission failed (offline, or the server\n * couldn't be reached), so it can show its own notice. The form keeps the\n * values the user typed, ready for the app to retry.\n *\n * Dispatched on `window` as a cancelable `torpor:submit-failed` `CustomEvent`.\n * An app that cancels it asks for a native form submission after all, e.g. a\n * service worker serves the POST, or the browser's own offline handling is\n * preferred.\n */\nfunction handleSubmitFailure(form: HTMLFormElement, action: string, error: unknown): void {\n\tconst event = new CustomEvent<SubmitFailureDetail>(\"torpor:submit-failed\", {\n\t\tcancelable: true,\n\t\tdetail: { action, error },\n\t});\n\t// `dispatchEvent` returns false when a handler cancelled it\n\tif (!window.dispatchEvent(event)) {\n\t\t// The prototype call, because a field named \"submit\" shadows `form.submit`\n\t\tHTMLFormElement.prototype.submit.call(form);\n\t\treturn;\n\t}\n\n\tconsole.warn(\n\t\t`The form submission to ${action} failed; staying on the current page. ` +\n\t\t\t\"Listen for torpor:submit-failed to show your own notice.\",\n\t);\n}\n","import { type DeferredMeta, setAtPath } from \"../deferred.ts\";\nimport { DATA_REUSE_HEADER, DATA_REQUEST_HEADER } from \"../dataRequest.ts\";\nimport { readResponseBody } from \"../response/read.ts\";\nimport { getBasePath } from \"../site/basePath\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport type RouteHandler from \"../types/RouteHandler\";\nimport client from \"../state/client\";\n\n/**\n * The result of loading a route's data. `error` is set when a load function\n * returned an error response (redirects excluded) -- the caller renders the\n * error page instead of the route.\n */\nexport type LoadDataResult = {\n\tdata: Record<string, any>;\n\terror?: {\n\t\tstatus: number;\n\t\tmessage: string;\n\t};\n};\n\n/**\n * Loads a route's data for a client-side navigation.\n *\n * One request (`GET <page url>/~server` with the data header) returns the\n * server data for the page and all of its layouts, with hooks running once\n * against the page url. The client then runs its own load functions (layout\n * by layout, then the page), merging each route's fresh server data in the\n * same order the server render does.\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\tprefetch = false,\n\tsignal?: AbortSignal,\n): Promise<LoadDataResult | void> {\n\tlet data = {};\n\n\t// Work out up front which layouts are already rendered (their data is\n\t// reused), so the data request can skip loading them. A prefetch also skips\n\t// their server loads (they're already in the client stack) but must not\n\t// adopt their live slot regions: it may never be followed by a navigation\n\tconst layoutStack = client.layoutStack;\n\tconst layouts = (handler.layouts ?? []).map((layout, index) => {\n\t\tconst layoutPath = resolveLayoutPath(layout.path, params);\n\t\tconst previous = layoutStack.at(index);\n\t\tconst rendered = previous?.path === layoutPath;\n\t\tconst reuse = !prefetch && rendered;\n\t\treturn { layout, index, layoutPath, previous, rendered, reuse };\n\t});\n\n\t// A page can opt out of the data request when it has no server load of its\n\t// own and every layout is already rendered (e.g. a tab switch under a\n\t// session hook that doesn't gate access). Its client load still runs.\n\tconst skipServerData =\n\t\tclientEndPoint?.serverData === false &&\n\t\t!handler.serverEndPoint &&\n\t\tlayouts.every((layout) => layout.rendered);\n\n\t// One request for all the (non-reused) server data\n\tconst server = skipServerData\n\t\t? {}\n\t\t: await loadServerData(\n\t\t\t\thandler,\n\t\t\t\tpath,\n\t\t\t\tquery,\n\t\t\t\tlayouts.filter((l) => l.rendered).map((l) => l.layoutPath),\n\t\t\t\tprefetch,\n\t\t\t\tsignal,\n\t\t\t);\n\tif (server === undefined) {\n\t\t// A load redirected: the client can't follow it through fetch, so the\n\t\t// caller falls back to a full page load\n\t\treturn;\n\t}\n\tif (\"error\" in server) {\n\t\treturn { data, error: server.error };\n\t}\n\n\tfor (const { layout, index, layoutPath, previous, rendered, reuse } of layouts) {\n\t\tconst stackLayout: LayoutPath = {\n\t\t\tpath: layoutPath,\n\t\t\tdata: {},\n\t\t\treuse,\n\t\t\tslotRegion: null,\n\t\t};\n\n\t\tif (rendered && previous) {\n\t\t\t// The layout is already rendered: keep its data. Only a real\n\t\t\t// navigation reuses its slot region; a prefetch must leave it alone\n\t\t\t// (and not run its client load again). The context the layout\n\t\t\t// passed to its slot is kept too, so refilling the slot after reuse\n\t\t\t// still sees the layout's `$context` additions\n\t\t\tif (reuse) {\n\t\t\t\tstackLayout.slotRegion = previous.slotRegion;\n\t\t\t\tstackLayout.context = previous.context;\n\t\t\t}\n\t\t\tObject.assign(stackLayout.data, previous.data);\n\t\t} else {\n\t\t\t// A new layout: run its client load (its server data already\n\t\t\t// arrived in the single request)\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;\n\t\t\tconst loaded = await runClientLoad(\n\t\t\t\tlayoutEndPoint,\n\t\t\t\tclientLocation(layoutPath),\n\t\t\t\tquery,\n\t\t\t\tparams,\n\t\t\t\tstackLayout.data,\n\t\t\t\tprefetch,\n\t\t\t);\n\t\t\tif (loaded?.redirect) return;\n\t\t\tif (loaded?.error) return { data, error: loaded.error };\n\t\t\tconst serverData = server.loads?.[index];\n\t\t\tif (serverData) Object.assign(stackLayout.data, serverData);\n\t\t}\n\n\t\tObject.assign(data, stackLayout.data);\n\t\tnewLayoutStack.push(stackLayout);\n\t}\n\n\t// The page's client load, then its server data\n\tconst loaded = await runClientLoad(\n\t\tclientEndPoint,\n\t\tclientLocation(path),\n\t\tquery,\n\t\tparams,\n\t\tdata,\n\t\tprefetch,\n\t);\n\tif (loaded?.redirect) return;\n\tif (loaded?.error) return { data, error: loaded.error };\n\tconst pageServerData = server.loads?.[handler.layouts?.length ?? 0];\n\tif (pageServerData) Object.assign(data, pageServerData);\n\n\treturn { data };\n}\n\n/** The path of a layout with its `[param]` segments substituted. */\nfunction resolveLayoutPath(path: string, params: Record<string, string>): string {\n\tfor (let key in params) {\n\t\tpath = path.replace(`[${key}]`, params[key]);\n\t}\n\treturn path;\n}\n\n/**\n * Builds the layout stack for an error page whose own loads can't run (offline,\n * or the server is down): layouts already on screen keep their data and slot\n * regions, so the error renders over the shell instead of the shell being\n * replaced by a document load that would fail too. Layouts that aren't on\n * screen render with no data.\n */\nexport function errorLayoutStack(\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n): LayoutPath[] {\n\tconst stack: LayoutPath[] = [];\n\t(handler.layouts ?? []).forEach((layout, index) => {\n\t\tconst path = resolveLayoutPath(layout.path, params);\n\t\tconst previous = client.layoutStack.at(index);\n\t\tconst rendered = previous?.path === path;\n\t\tstack.push({\n\t\t\tpath,\n\t\t\tdata: rendered && previous ? { ...previous.data } : {},\n\t\t\treuse: rendered,\n\t\t\tslotRegion: rendered && previous ? previous.slotRegion : null,\n\t\t\tcontext: rendered && previous ? previous.context : undefined,\n\t\t});\n\t});\n\treturn stack;\n}\n\ntype ServerData = {\n\tloads?: (Record<string, any> | null)[];\n\t/** Promise-valued properties streamed after the critical loads. */\n\tdeferred?: DeferredMeta[];\n};\n\ntype ServerDataFrame = {\n\ttype?: string;\n\tid?: string;\n\tvalue?: unknown;\n\tmessage?: string;\n} & ServerData;\n\n/**\n * A request-local registry of deferred promises. Values arrive after the first\n * frame (client navigation) or in inline scripts (initial hydration), and\n * resolve the promises already placed in the page's `data`.\n */\nclass DeferredStore {\n\t#entries = new Map<\n\t\tstring,\n\t\t{\n\t\t\tpromise: Promise<unknown>;\n\t\t\tresolve: (value: unknown) => void;\n\t\t\treject: (error: unknown) => void;\n\t\t}\n\t>();\n\n\tget(id: string): Promise<unknown> {\n\t\tlet entry = this.#entries.get(id);\n\t\tif (!entry) {\n\t\t\tlet resolve!: (value: unknown) => void;\n\t\t\tlet reject!: (error: unknown) => void;\n\t\t\tconst promise = new Promise<unknown>((res, rej) => {\n\t\t\t\tresolve = res;\n\t\t\t\treject = rej;\n\t\t\t});\n\t\t\t// A prefetch (or a navigation the user leaves) may never read the\n\t\t\t// promise; don't let its rejection surface as unhandled\n\t\t\tpromise.catch(() => {});\n\t\t\tentry = { promise, resolve, reject };\n\t\t\tthis.#entries.set(id, entry);\n\t\t}\n\t\treturn entry.promise;\n\t}\n\n\tresolve(id: string, value: unknown): void {\n\t\tconst entry = this.#entries.get(id);\n\t\tif (!entry) return;\n\t\tthis.#entries.delete(id);\n\t\tentry.resolve(value);\n\t}\n\n\treject(id: string, error: unknown): void {\n\t\tconst entry = this.#entries.get(id);\n\t\tif (!entry) return;\n\t\tthis.#entries.delete(id);\n\t\tentry.reject(error instanceof Error ? error : new Error(String(error)));\n\t}\n\n\trejectAll(error: unknown): void {\n\t\tfor (const id of this.#entries.keys()) {\n\t\t\tthis.reject(id, error);\n\t\t}\n\t}\n\n\t/** Places a promise for each deferred entry into the load that owns it. */\n\tattach(server: ServerData, get: (id: string) => Promise<unknown>): ServerData {\n\t\tfor (const entry of server.deferred ?? []) {\n\t\t\tconst load = server.loads?.[entry.index];\n\t\t\tif (!load) continue;\n\t\t\tsetAtPath(load, entry.path, get(entry.id));\n\t\t}\n\t\treturn server;\n\t}\n}\n\n/**\n * Fetches the page's combined server data for a navigation, reusing a prefetch\n * when there is one.\n *\n * A prefetch warms this request for the navigation that follows, and a\n * navigation consumes it (once). So a hover costs one request, a click that\n * lands while the prefetch is still in flight awaits the same promise instead\n * of issuing a second one, and a prefetched response is never served to more\n * than the one navigation it was loaded for (no stale data on later visits).\n */\nasync function loadServerData(\n\thandler: RouteHandler,\n\tpath: string,\n\tquery: URLSearchParams,\n\treusedLayouts: string[],\n\tprefetch: boolean,\n\tsignal?: AbortSignal,\n): Promise<ServerData | { error: { status: number; message: string } } | undefined> {\n\t// The server embeds the first render's data in the HTML (see the render\n\t// path in site/serverHandlers.ts), so the initial hydration can read it\n\t// instead of making a round trip. The element is consumed once, so later\n\t// navigations use the fetch below\n\tconst embedded = takeEmbeddedServerData();\n\tif (embedded !== undefined) {\n\t\treturn attachEmbeddedDeferred(embedded);\n\t}\n\n\tif (!hasServerData(handler)) {\n\t\treturn {};\n\t}\n\n\tconst key = serverDataKey(path, query);\n\n\tif (prefetch) {\n\t\tconst cached = client.prefetchedServerData[key];\n\t\tif (cached) return cached;\n\n\t\tconst pending = requestServerData(path, query, reusedLayouts);\n\t\tclient.prefetchedServerData[key] = pending;\n\t\t// A failed prefetch mustn't poison the navigation that follows it: drop\n\t\t// the entry so that navigation retries. One that is already awaiting\n\t\t// this promise still sees the failure and renders the error page.\n\t\tvoid pending.then(\n\t\t\t(result) => {\n\t\t\t\tif (isLoadError(result)) dropPrefetch(client.prefetchedServerData, key, pending);\n\t\t\t},\n\t\t\t() => dropPrefetch(client.prefetchedServerData, key, pending),\n\t\t);\n\t\treturn pending;\n\t}\n\n\tconst prefetched = client.prefetchedServerData[key];\n\tif (prefetched) {\n\t\tdelete client.prefetchedServerData[key];\n\t\treturn prefetched;\n\t}\n\n\treturn requestServerData(path, query, reusedLayouts, signal);\n}\n\n/** The `/~server` request cache key: the page path and its query. */\nfunction serverDataKey(path: string, query: URLSearchParams): string {\n\treturn path + (query.size > 0 ? `?${query}` : \"\");\n}\n\n/** Whether a load resolved to an error result (as opposed to data/nothing). */\nfunction isLoadError(value: unknown): value is { error: { status: number; message: string } } {\n\treturn typeof value === \"object\" && value !== null && \"error\" in value;\n}\n\n/** Removes a failed prefetch, unless the navigation has already consumed it. */\nfunction dropPrefetch(prefetches: Record<string, any>, key: string, pending: unknown): void {\n\tif (prefetches[key] === pending) {\n\t\tdelete prefetches[key];\n\t}\n}\n\n/**\n * The posted data request: `GET <page url>/~server` carrying the data header,\n * which the server answers with the page's and its layouts' server data as one\n * JSON body.\n */\nasync function requestServerData(\n\tpath: string,\n\tquery: URLSearchParams,\n\treusedLayouts: string[],\n\tsignal?: AbortSignal,\n): Promise<ServerData | { error: { status: number; message: string } } | undefined> {\n\tconst url = new URL(\n\t\tdocument.location.origin + getBasePath() + path.replace(/\\/$/, \"\") + \"/~server\",\n\t);\n\tfor (let [name, value] of query) {\n\t\turl.searchParams.append(name, value);\n\t}\n\n\tconst headers: Record<string, string> = { [DATA_REQUEST_HEADER]: \"1\" };\n\tif (reusedLayouts.length > 0) {\n\t\theaders[DATA_REUSE_HEADER] = JSON.stringify(reusedLayouts);\n\t}\n\n\t// A rejected fetch is the common offline failure (as is a body that fails\n\t// mid-read, e.g. the connection drops while streaming). Render it as an\n\t// error in place rather than throwing away the shell with a document load\n\t// that would fail too.\n\ttry {\n\t\tconst response = await fetch(url, {\n\t\t\tredirect: \"manual\",\n\t\t\theaders,\n\t\t\tsignal,\n\t\t});\n\t\tif (isRedirect(response)) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (!response.ok) {\n\t\t\treturn { error: await errorOf(response) };\n\t\t}\n\t\t// A site without a server (e.g. a static host) responds with the page's\n\t\t// html rather than json; there's nothing to merge\n\t\tconst type = response.headers.get(\"Content-Type\");\n\t\tif (type?.includes(\"application/x-ndjson\")) {\n\t\t\treturn await readServerDataStream(response);\n\t\t}\n\t\tif (!type?.includes(\"application/json\")) {\n\t\t\treturn {};\n\t\t}\n\t\treturn (await response.json()) as ServerData;\n\t} catch (error) {\n\t\t// A navigation the user superseded aborted this request; let it settle\n\t\t// as superseded rather than painting an offline error over the page\n\t\tif (signal?.aborted) throw error;\n\t\tconsole.error(\"The server data request failed\", error);\n\t\treturn { error: unreachableError() };\n\t}\n}\n\n/** The error rendered when the server can't be reached at all. */\nfunction unreachableError(): { status: number; message: string } {\n\treturn {\n\t\tstatus: 503,\n\t\tmessage: navigator.onLine === false ? \"You're offline.\" : \"Could not reach the server.\",\n\t};\n}\n\n/**\n * Reads a streamed data response: the first frame carries the critical loads\n * and the list of deferred paths, later frames resolve those promises. The\n * function returns as soon as the first frame is read, so a navigation mounts\n * before slow values arrive.\n */\nasync function readServerDataStream(response: Response): Promise<ServerData> {\n\tconst reader = response.body?.getReader();\n\tif (!reader) return {};\n\n\tconst decoder = new TextDecoder();\n\tlet buffer = \"\";\n\tconst readFrame = async (): Promise<ServerDataFrame | undefined> => {\n\t\twhile (true) {\n\t\t\tconst newline = buffer.indexOf(\"\\n\");\n\t\t\tif (newline >= 0) {\n\t\t\t\tconst line = buffer.slice(0, newline).trim();\n\t\t\t\tbuffer = buffer.slice(newline + 1);\n\t\t\t\tif (line) return JSON.parse(line) as ServerDataFrame;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) {\n\t\t\t\tconst line = buffer.trim();\n\t\t\t\tbuffer = \"\";\n\t\t\t\treturn line ? (JSON.parse(line) as ServerDataFrame) : undefined;\n\t\t\t}\n\t\t\tbuffer += decoder.decode(value, { stream: true });\n\t\t}\n\t};\n\n\tconst first = await readFrame();\n\tif (!first) return {};\n\tif (first.loads === undefined) return {};\n\tconst store = new DeferredStore();\n\tconst server = store.attach(first, (id) => store.get(id));\n\n\t// Keep reading in the background. The view is already mounted; values\n\t// resolve their promises as the frames arrive.\n\tvoid (async () => {\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst frame = await readFrame();\n\t\t\t\tif (!frame) break;\n\t\t\t\tif (frame.type === \"value\" && frame.id !== undefined) {\n\t\t\t\t\tstore.resolve(frame.id, frame.value);\n\t\t\t\t} else if (frame.type === \"error\" && frame.id !== undefined) {\n\t\t\t\t\tstore.reject(frame.id, frame.message ?? \"Deferred data failed\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tstore.rejectAll(new Error(\"The deferred data stream ended before a value arrived\"));\n\t\t} catch (error) {\n\t\t\tstore.rejectAll(error);\n\t\t}\n\t})();\n\n\treturn server;\n}\n\n/**\n * Recreates the promises for a page's embedded server data. The server emits\n * a bootstrap store before the inline resolve scripts, so by the time this\n * runs a value may already be resolved (or still be in flight).\n */\nfunction attachEmbeddedDeferred(server: ServerData): ServerData {\n\tif (!server.deferred?.length) return server;\n\tconst globalStore = (\n\t\tglobalThis as {\n\t\t\t__torporDeferred?: { get(id: string): Promise<unknown> };\n\t\t}\n\t).__torporDeferred;\n\t// The bootstrap is only emitted with a deferred payload; fall back to\n\t// never-resolving promises rather than throwing if it is missing\n\tconst store = new DeferredStore();\n\tconst get = globalStore ? (id: string) => globalStore.get(id) : (id: string) => store.get(id);\n\treturn store.attach(server, get);\n}\n\n/**\n * Reads and removes the server data the initial render embedded in the HTML\n * (a `t-server-data` script tag), or `undefined` when there is none (a later\n * navigation, or a page with no server data).\n */\nfunction takeEmbeddedServerData(): ServerData | undefined {\n\tconst element = document.getElementById(\"t-server-data\");\n\tif (element === null) {\n\t\treturn undefined;\n\t}\n\telement.remove();\n\ttry {\n\t\treturn JSON.parse(element.textContent ?? \"\") as ServerData;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Whether the route has any server-side code to run (a page or layout server\n * load, or a folder hook). Without any, there's no data request to make.\n */\nfunction hasServerData(handler: RouteHandler): boolean {\n\tif (handler.serverHooks && handler.serverHooks.length > 0) return true;\n\tif (handler.serverEndPoint) return true;\n\treturn (handler.layouts ?? []).some((layout) => !!layout.serverEndPoint);\n}\n\n/**\n * The result of running a route's client load: the json it returned (if any),\n * a redirect the client can't follow, or an error to render in place. Cached\n * as a whole when a prefetch warms it, because a Response body can only be\n * read once.\n */\ntype ClientLoadResult = {\n\t/** The json the load returned, if any. */\n\tdata?: Record<string, any>;\n\t/** The load redirected: only a document load can follow it. */\n\tredirect?: true;\n\t/** The load failed: render the nearest error page. */\n\terror?: { status: number; message: string };\n};\n\n/**\n * Runs a route's client-side load, merging its json data into `data` and\n * returning the redirect or error for the caller to handle.\n *\n * A prefetch caches the in-flight promise, not its resolved value, so a\n * navigation that lands while the load is still running continues the same\n * request instead of running it a second time. The navigation that follows\n * consumes (and clears) the entry; a failed prefetch is dropped so the\n * navigation retries.\n */\nasync function runClientLoad(\n\tendPoint: PageEndPoint | undefined,\n\tlocation: string,\n\tquery: URLSearchParams,\n\tparams: Record<string, string>,\n\tdata: Record<string, any>,\n\tprefetch: boolean,\n): Promise<ClientLoadResult | undefined> {\n\tif (!endPoint?.load) return;\n\n\tconst clientKey = location + (query.size > 0 ? `?${query}` : \"\");\n\tconst prefetchedData = client.prefetchedData;\n\tlet pending = prefetchedData[clientKey] as Promise<ClientLoadResult> | undefined;\n\n\tif (!pending) {\n\t\t// Only a prefetch warms the cache. A navigation runs its own load\n\t\t// directly, so a result is never left behind for a later visit.\n\t\tif (!prefetch) {\n\t\t\tconst result = await loadClientResponse(endPoint.load, query, params, data);\n\t\t\treturn mergeClientLoad(result, data);\n\t\t}\n\n\t\tconst promise = loadClientResponse(endPoint.load, query, params, data);\n\t\tprefetchedData[clientKey] = promise;\n\t\tpending = promise;\n\t\t// A failed prefetch mustn't poison the navigation that follows it\n\t\tvoid promise.then(\n\t\t\t(result) => {\n\t\t\t\tif (result.error) dropPrefetch(prefetchedData, clientKey, promise);\n\t\t\t},\n\t\t\t() => dropPrefetch(prefetchedData, clientKey, promise),\n\t\t);\n\t} else if (!prefetch) {\n\t\t// The navigation consumes the warm entry\n\t\tdelete prefetchedData[clientKey];\n\t}\n\n\treturn mergeClientLoad(await pending, data);\n}\n\nasync function loadClientResponse(\n\tload: NonNullable<PageEndPoint[\"load\"]>,\n\tquery: URLSearchParams,\n\tparams: Record<string, string>,\n\tdata: Record<string, any>,\n): Promise<ClientLoadResult> {\n\tconst clientUrl = new URL(document.location.href);\n\tfor (let [name, value] of query) {\n\t\tclientUrl.searchParams.append(name, value);\n\t}\n\ttry {\n\t\tconst response = await load({ url: clientUrl, params, data });\n\t\tif (!response) return {};\n\t\tif (isRedirect(response)) return { redirect: true };\n\t\tif (!response.ok) return { error: await errorOf(response) };\n\t\tconst body = await readResponseBody(response);\n\t\treturn body ? { data: body } : {};\n\t} catch (error) {\n\t\t// A throwing load (or a body that fails mid-read) is a page error, not\n\t\t// a navigation failure: render the error page over the shell rather\n\t\t// than blanking it with a document load that would run the same load\n\t\t// again\n\t\tconsole.error(\"The client load failed\", error);\n\t\treturn { error: { status: 500, message: \"Internal error\" } };\n\t}\n}\n\nfunction mergeClientLoad(result: ClientLoadResult, data: Record<string, any>): ClientLoadResult {\n\tif (result.data) Object.assign(data, result.data);\n\treturn result;\n}\n\nfunction clientLocation(path: string): string {\n\treturn document.location.origin + getBasePath() + path;\n}\n\nfunction isRedirect(response: Response): boolean {\n\t// A `redirect: \"manual\"` fetch surfaces a cross-navigation redirect as an\n\t// opaque (\"opaqueredirect\") response in browsers, with status 0\n\treturn (response.status >= 300 && response.status < 400) || response.type === \"opaqueredirect\";\n}\n\n/**\n * The status and message of a failed load response. The body only becomes\n * the message when it's a `message`-carrying json body or plain text -- an\n * html body is a whole page (e.g. a static host's 404), not a message.\n */\nasync function errorOf(response: Response): Promise<{ status: number; message: string }> {\n\tlet message = \"\";\n\tconst type = response.headers.get(\"Content-Type\");\n\tif (type?.includes(\"application/json\")) {\n\t\ttry {\n\t\t\tconst data = await response.json();\n\t\t\tif (typeof data.message === \"string\") {\n\t\t\t\tmessage = data.message;\n\t\t\t}\n\t\t} catch {\n\t\t\t// Not actually json\n\t\t}\n\t} else if (type?.includes(\"text/plain\")) {\n\t\tmessage = await response.text();\n\t}\n\treturn { status: response.status, message: message || response.statusText };\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 findErrorRoute from \"../site/findErrorRoute\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport parseErrorStatus from \"../utils/parseErrorStatus\";\nimport formSubmit from \"./formSubmit\";\nimport loadData, { errorLayoutStack } from \"./loadData\";\n\n/**\n * What a navigation did, so its caller knows whether the page is rendered or\n * the document has to take over.\n *\n * - `rendered`: the route (or its nearest error page) is in place.\n * - `server-only`: the route has no client component (e.g. a `+server` route),\n * so only a document load can handle it.\n * - `redirect`: a load redirected, which a fetch can't follow.\n * - `failed`: nothing rendered; the caller keeps the current page and decides\n * between a document load and telling the app (see `handleNavigationFailure`).\n * - `superseded`: a newer navigation started before this one finished and owns\n * the result, so the caller should do nothing (in particular, it must not\n * push a history entry or fall back to a document load).\n */\nexport type NavigationResult =\n\t| { type: \"rendered\" }\n\t| { type: \"server-only\" }\n\t| { type: \"redirect\" }\n\t| { type: \"failed\"; error?: unknown }\n\t| { type: \"superseded\" };\n\n/**\n * The newest navigation's id. Each `navigate` bumps it; anything older is\n * superseded and must not commit `$page`, `client.layoutStack` or the DOM.\n */\nlet latestNavigation = 0;\n\n/**\n * Aborts the newest navigation's in-flight data request when a newer one\n * starts. That's what keeps a slow (or hung) `/~server` request from delaying\n * the navigation that follows it.\n */\nlet activeController: AbortController | undefined;\n\nexport default function navigate(rawUrl: URL, withHydration = false): Promise<NavigationResult> {\n\tconst id = ++latestNavigation;\n\n\t// The newest navigation wins: abort the previous one's data request and\n\t// let its commit checks drop it when it settles. Loading is no longer\n\t// serialized, so the navigation that follows doesn't wait for a slow\n\t// request; only the commit is (it runs synchronously after the checks).\n\tactiveController?.abort();\n\tconst controller = new AbortController();\n\tactiveController = controller;\n\n\tconst result = navigateNow(rawUrl, withHydration, id, controller.signal);\n\tconst clearController = () => {\n\t\tif (activeController === controller) activeController = undefined;\n\t};\n\t// Clear the controller only if a newer navigation hasn't replaced it\n\tvoid result.then(clearController, clearController);\n\treturn result;\n}\n\nfunction isSuperseded(id: number, signal: AbortSignal): boolean {\n\treturn id !== latestNavigation || signal.aborted;\n}\n\nconst SUPERSEDED: NavigationResult = { type: \"superseded\" };\n\nasync function navigateNow(\n\trawUrl: URL,\n\twithHydration: boolean,\n\tid: number,\n\tsignal: AbortSignal,\n): Promise<NavigationResult> {\n\t// A failed route-module import (e.g. a stale dev dep hash), a throwing\n\t// load or a failed render must not reject the click handler's promise: the\n\t// caller's fallback would never run and the link would appear dead.\n\tconst previousUrl = $page.url;\n\tconst previousStatus = $page.status;\n\tconst previousError = $page.error;\n\tlet result: NavigationResult;\n\ttry {\n\t\tresult = await renderNavigation(rawUrl, withHydration, id, signal);\n\t} catch (error) {\n\t\t// An aborted request (or a failure that lands after a newer navigation\n\t\t// started) belongs to the newer navigation, not this one\n\t\tif (isSuperseded(id, signal)) return SUPERSEDED;\n\t\tconsole.error(error);\n\t\tresult = { type: \"failed\", error };\n\t}\n\tif (result.type === \"superseded\") return result;\n\tif (result.type === \"failed\" && !withHydration && !isSuperseded(id, signal)) {\n\t\t// Nothing is on screen for this url: point the reactive state back at\n\t\t// the page that is still there, in case the caller keeps it (e.g. a\n\t\t// failed navigation while offline). The initial hydration already has\n\t\t// its server-rendered page on screen, so there is nothing to restore.\n\t\t$page.url = previousUrl;\n\t\t$page.status = previousStatus;\n\t\t$page.error = previousError;\n\t}\n\treturn result;\n}\n\nasync function renderNavigation(\n\trawUrl: URL,\n\twithHydration: boolean,\n\tid: number,\n\tsignal: AbortSignal,\n): Promise<NavigationResult> {\n\t// Another navigation started before this one got to run\n\tif (isSuperseded(id, signal)) return SUPERSEDED;\n\n\tlet parent = document.getElementById(\"app\");\n\tif (!parent) {\n\t\t// TODO: 500\n\t\tconsole.log(\"500\");\n\t\treturn { type: \"failed\" };\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\tlet route = client.router.match(path, query);\n\n\t// Update $page before building the components\n\t$page.url = url;\n\tif (route) {\n\t\tif (path.endsWith(\"/_error\")) {\n\t\t\t// A direct visit to the error page (e.g. a bookmark of the url it\n\t\t\t// used to be redirected to). Make it look a bit classier by\n\t\t\t// stripping the query, which carries the status and message\n\t\t\t$page.status = parseErrorStatus(query.get(\"status\"));\n\t\t\t$page.error = { message: query.get(\"message\") ?? \"\" };\n\t\t\twindow.history.replaceState({}, \"\", rawUrl.toString().split(\"?\")[0]);\n\t\t} else {\n\t\t\t$page.status = 200;\n\t\t\t$page.error = { message: \"\" };\n\t\t}\n\t} else {\n\t\t// There's no page at this url -- render the nearest error page at it,\n\t\t// so the address bar keeps the url the user asked for: a transient\n\t\t// failure can be refreshed, and a typo can be seen and fixed\n\t\tconst errorPath = findErrorRoute(client.router, path);\n\t\tconst errorRoute = errorPath && client.router.match(errorPath, query);\n\t\tif (!errorRoute) {\n\t\t\t// Leave the current page alone; the caller falls back to a full\n\t\t\t// page load, and the server renders the error page (or passes the\n\t\t\t// raw response through, when it has no error page)\n\t\t\treturn { type: \"failed\" };\n\t\t}\n\t\troute = errorRoute;\n\t\t$page.status = 404;\n\t\t$page.error = { message: \"Not found\" };\n\t}\n\tlet handler = route.handler;\n\tlet params = route.params || {};\n\n\t// There must be a client endpoint with a component. Routes with no client\n\t// component (a pure `+server` route like `/logout`) can't be rendered\n\t// client-side, so report `server-only` and let the caller do a full page\n\t// load\n\tlet clientEndPoint: PageEndPoint | undefined = handler.endPoint\n\t\t? (await handler.endPoint())?.default\n\t\t: undefined;\n\tif (isSuperseded(id, signal)) return SUPERSEDED;\n\tif (!clientEndPoint?.component) {\n\t\treturn { type: \"server-only\" };\n\t}\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 result = await loadData(\n\t\thandler,\n\t\tparams,\n\t\tpath,\n\t\tquery,\n\t\tnewLayoutStack,\n\t\tclientEndPoint,\n\t\tfalse,\n\t\tsignal,\n\t);\n\tif (isSuperseded(id, signal)) return SUPERSEDED;\n\tif (result === undefined) {\n\t\t// A load redirected: the client can't follow it through fetch, so the\n\t\t// caller falls back to a full page load, which does\n\t\treturn { type: \"redirect\" };\n\t}\n\tlet data = result.data;\n\tif (result.error) {\n\t\tif (withHydration) {\n\t\t\t// The server rendered this page fine moments ago -- keep its\n\t\t\t// markup rather than hydrating an error page over it\n\t\t\treturn { type: \"failed\" };\n\t\t}\n\t\t// The load failed -- render the nearest error page at this url, so\n\t\t// the address bar keeps the url the user asked for: a transient\n\t\t// failure (a random db hiccup, say) can be retried with a refresh\n\t\tconst errorPath = findErrorRoute(client.router, path);\n\t\tconst errorRoute = errorPath && client.router.match(errorPath, query);\n\t\tif (!errorRoute) {\n\t\t\t// No error page -- the caller falls back to a full page load,\n\t\t\t// where the server passes the error response through\n\t\t\treturn { type: \"failed\" };\n\t\t}\n\t\troute = errorRoute;\n\t\thandler = errorRoute.handler;\n\t\tparams = errorRoute.params || {};\n\t\tclientEndPoint = handler.endPoint ? (await handler.endPoint())?.default : undefined;\n\t\tif (isSuperseded(id, signal)) return SUPERSEDED;\n\t\tif (!clientEndPoint?.component) {\n\t\t\treturn { type: \"failed\" };\n\t\t}\n\n\t\t$page.status = result.error.status;\n\t\t$page.error = { message: result.error.message };\n\n\t\t// The error page starts fresh: drop the layouts collected for the\n\t\t// route that failed (the error route's own layouts are loaded into\n\t\t// the empty stack, reusing whatever the current page shares)\n\t\tnewLayoutStack = [];\n\t\tconst errorResult = await loadData(\n\t\t\thandler,\n\t\t\tparams,\n\t\t\tpath,\n\t\t\tquery,\n\t\t\tnewLayoutStack,\n\t\t\tclientEndPoint,\n\t\t\tfalse,\n\t\t\tsignal,\n\t\t);\n\t\tif (isSuperseded(id, signal)) return SUPERSEDED;\n\t\tif (errorResult === undefined) {\n\t\t\t// The error page's own load redirected: only a document load can\n\t\t\t// follow it\n\t\t\treturn { type: \"redirect\" };\n\t\t}\n\t\tif (errorResult.error) {\n\t\t\t// The error page's own data can't load either (offline, or the\n\t\t\t// server is down). Render it over the shell with the layouts and\n\t\t\t// data that are already on screen rather than blanking the page\n\t\t\t// with a document load that would fail too.\n\t\t\tnewLayoutStack = errorLayoutStack(handler, params);\n\t\t\tdata = {};\n\t\t} else {\n\t\t\tdata = errorResult.data;\n\t\t}\n\t}\n\t// From here on there are no awaits until the synchronous commit, so a\n\t// newer navigation can no longer interleave. Drop out if one started\n\t// while a module/load was in flight.\n\tif (isSuperseded(id, signal)) return SUPERSEDED;\n\n\t// We may have form data from a no-JS form action re-render, in a JSON\n\t// script (or, in a page rendered by an older server, a hidden input)\n\tlet formElement = document.getElementById(\"t-form-data\");\n\tlet form: Record<string, string> | undefined;\n\tif (formElement) {\n\t\tform = JSON.parse(\n\t\t\tformElement instanceof HTMLInputElement ? formElement.value : (formElement.textContent ?? \"\"),\n\t\t);\n\t\t$page.form = form;\n\t\tformElement.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// The root context: the page state, read in components as\n\t// `$context.$page`, and some special context for submitting Forms\n\t// client-side\n\tconst $context = {\n\t\t$page,\n\t\tTorporBuildContext: { onformsubmit: formSubmit },\n\t};\n\n\t// The layout stack is assigned at commit time (inside `render`) so an\n\t// in-flight navigation the user supersedes can't disturb the stack the\n\t// newest navigation is reading\n\tlet layoutStack = newLayoutStack;\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\t// The index of the innermost layout that can actually be reused. It must\n\t// be on the same path (loadData marked it) *and* its slot region must still\n\t// be live: a released region has no `startNode`, and one whose window was\n\t// left pointing at a removed node has a detached `startNode`. A reactive\n\t// update inside the layout during this navigation — e.g. an @if branch\n\t// before the <slot> being cleared because $page.url changed — can cascade\n\t// through `clearRegion` and release the slot region; a post-hydration\n\t// re-render can remove the node it starts at. Reusing either throws on\n\t// `slotRegion.startNode!.parentNode`, so treat such layouts as new instead:\n\t// keep the nearest live ancestor layout, or fully re-render the chain below.\n\tlet reusedIndex = -1;\n\tfor (let i = layoutStack.length - 1; i >= 0; i--) {\n\t\tconst stackLayout = layoutStack[i];\n\t\tif (stackLayout.reuse && stackLayout.slotRegion?.startNode?.parentNode != null) {\n\t\t\treusedIndex = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\tlet reused = 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(\n\t\t\tparent,\n\t\t\tanchor,\n\t\t\t_,\n\t\t\tslotContext,\n\t\t) {\n\t\t\tlet i = layoutStack.length - 1;\n\t\t\t// Keep the context the innermost layout passed to its slot, for a\n\t\t\t// later refill that reuses that layout\n\t\t\tlayoutStack[i].context = slotContext;\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\tslotContext,\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 (i === reusedIndex) {\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\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, _, slotContext) {\n\t\t\t\t\t\t// This slot belongs to layout i-1: keep the context it\n\t\t\t\t\t\t// passed down so a later refill can replay it\n\t\t\t\t\t\tlayoutStack[i - 1].context = slotContext;\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\tslotContext,\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 newer navigation may have started while a layout module was imported\n\tif (isSuperseded(id, signal)) return SUPERSEDED;\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\t// The view-transition callback runs after a tick, so a newer navigation\n\t\t// can have claimed the page in the meantime\n\t\tif (isSuperseded(id, signal)) return;\n\n\t\t// Commit the layout stack and the DOM together: no newer navigation can\n\t\t// interleave with this synchronous section, and an older one never gets\n\t\t// here (its superseded check failed above).\n\t\tclient.layoutStack = layoutStack;\n\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\tif (\n\t\t\t\t\tslotRegion === null ||\n\t\t\t\t\tslotRegion.startNode === null ||\n\t\t\t\t\tslotRegion.startNode.parentNode === null\n\t\t\t\t) {\n\t\t\t\t\t// The region died after we planned to reuse it (a layout\n\t\t\t\t\t// update ran while an endpoint was being imported). Don't\n\t\t\t\t\t// paint an error over the current page — reload so the\n\t\t\t\t\t// server renders the requested page.\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\"The layout slot was cleared during navigation; falling back to a full page load\",\n\t\t\t\t\t);\n\t\t\t\t\twindow.location.reload();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tapp = slotRegion.startNode.parentNode as HTMLElement;\n\t\t\t\tclearLayoutSlot(slotRegion);\n\t\t\t\t// The layout itself isn't re-run, so replay the context it\n\t\t\t\t// passed to its slot (kept with the stack entry); otherwise its\n\t\t\t\t// `$context` additions would be missing from the new page\n\t\t\t\tcomponent(app, null, undefined, layoutStack[reusedIndex].context ?? $context);\n\t\t\t} else if (withHydration) {\n\t\t\t\thydrate(app, component, $props, slots, $context);\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, $context);\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// The navigation is committing: prefetches were for links that led\n\t\t\t// here, so drop them. (Do this here, not when scheduling a view\n\t\t\t// transition, so a superseded navigation doesn't clear the newer\n\t\t\t// one's prefetches.)\n\t\t\tclient.prefetchedData = {};\n\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\treturn { type: \"rendered\" };\n}\n","import navigate from \"./navigate\";\n\n/**\n * Loads and renders the page at the supplied path. Returns whether the page\n * was rendered in place: `false` when the document has to take over (a\n * `+server` route, a redirect, or a failed navigation), or when a newer\n * navigation superseded this one before it committed.\n */\nexport default async function load(path: string): Promise<boolean> {\n\tconst url = new URL(path, document.location.href);\n\treturn (await navigate(url)).type === \"rend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c;EAErB,IAAI;GACH,IAAI,QAAQ;IAOX,MAAM,aAAa,YAAY,YAAY,CAAC;IAC5C,IACC,eAAe,QACf,WAAW,cAAc,QACzB,WAAW,UAAU,eAAe,MACnC;KAKD,QAAQ,MACP,iFACD;KACA,OAAO,SAAS,OAAO;KACvB;IACD;IACA,MAAM,WAAW,UAAU;IAC3B,gBAAgB,UAAU;IAI1B,UAAU,KAAK,MAAM,KAAA,GAAW,YAAY,YAAY,CAAC,WAAW,QAAQ;GAC7E,OAAO,IAAI,eACV,QAAQ,KAAK,WAAW,QAAQ,OAAO,QAAQ;QACzC;IAON,QAAQ,GAAG;IACX,MAAM,KAAK,WAAW,QAAQ,OAAO,QAAQ;GAC9C;EACD,SAAS,OAAO;GAEf,IAAI,YAAY,6DAA2D,QAAQ;GACnF,QAAQ,IAAI,KAAK;EAClB;EAEA,IAAI,CAAC,eAAe;GAKnB,OAAO,iBAAiB,CAAC;GAMzB,IADgB,iBAAiB,IAAI,IAAI,SAAS,SAAS,IAAI,GAAG,YAAY,CAAC,CAAC,EAAE,aAClE,MACf,OAAO,SAAS,GAAG,CAAC;EAEtB;CACD;CAEA,IACC,CAAC,iBACD,OAAO,mBACP,OAAO,SAAS,wBAAwB,YAExC,SAAS,oBAAoB,MAAM;MAEnC,OAAO;CAGR,OAAO,EAAE,MAAM,WAAW;AAC3B;;;;;;;;;AC7cA,eAA8B,KAAK,MAAgC;CAElE,QAAQ,MAAM,SAAS,IADP,IAAI,MAAM,SAAS,SAAS,IACrB,CAAG,EAAA,CAAG,SAAS;AACvC"}
|
package/dist/nav.d.mts
CHANGED
|
@@ -67,7 +67,8 @@ declare function makeApi<Route extends string, Endpoint extends object, Params e
|
|
|
67
67
|
/**
|
|
68
68
|
* Loads and renders the page at the supplied path. Returns whether the page
|
|
69
69
|
* was rendered in place: `false` when the document has to take over (a
|
|
70
|
-
* `+server` route, a redirect, or a failed navigation)
|
|
70
|
+
* `+server` route, a redirect, or a failed navigation), or when a newer
|
|
71
|
+
* navigation superseded this one before it committed.
|
|
71
72
|
*/
|
|
72
73
|
declare function load(path: string): Promise<boolean>;
|
|
73
74
|
//#endregion
|
package/dist/nav.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nav.d.mts","names":[],"sources":["../src/nav/api.ts","../src/nav/load.ts","../src/nav/reload.ts","../src/nav/route.ts","../src/nav/formSubmit.ts","../src/nav/navigationFailure.ts","../src/dataRequest.ts","../src/nav.ts"],"mappings":";;;;;KAMK;;KAGO,qDAAqD;;KAGrD,WAAW,eAAe,yBAAyB;;;;;;KAO1D,UAAU,WAAW,kBAAiB,sBACxC,QAAQ,WAAW,kBAAkB,oBAAoB,QACxD,OAAO;;;;;;KASN,eAAe,WAAW,kBAAiB,aAAa,iBAC1D;EAAgB,YAAY,cAAc;oBACzB,OACf,oBACA,OACD,oBACD;;;;;;KAOE,gBAAgB,2BAA2B,aAC9C;EAAqB,eAAe;KAAa;;;;;;KAQ9C,YAAY,yBAAyB,0BACzC,gBAAgB,6BAEd,WACA,gBAAgB,yBAAwB,WACvC,gBAAgB,0BACf,qBAAqB,UACpB,QAAQ,gBAAgB,mBACvB,iBAAiB,YAAY,QAAQ,WACrC,WACD,WACD,WACD;;KAGQ,WAAW,8BAErB,yBAAyB,YAAY,YAAY,SAAS,mBAAkB,sBACzE,iBAED,eAAe,eAEf,QAAQ,YAAY,UAAU,SAC9B,OAAO,gBACH,QAAQ,UAAU,YAAY,SAAS,cAE3C,OAAO,eAAe,YAAY,SAAS,WAC3C,OAAO,gBACH,QAAQ,UAAU,YAAY,SAAS;;;;;;;;;;;;;;;;;;;;;;;;iBA4BvB,QACvB,sBACA,yBACA,eAAe,iBAAiB,SAAS,iBAAiB,QAE1D,MAAM,UAGH,qBAAqB,SACpB,SAAS,gCACJ,iBAAiB,6BAErB,QAAQ,SAAS,iBAAiB,QAAQ,iBAAiB,WAC9D,WAAW
|
|
1
|
+
{"version":3,"file":"nav.d.mts","names":[],"sources":["../src/nav/api.ts","../src/nav/load.ts","../src/nav/reload.ts","../src/nav/route.ts","../src/nav/formSubmit.ts","../src/nav/navigationFailure.ts","../src/dataRequest.ts","../src/nav.ts"],"mappings":";;;;;KAMK;;KAGO,qDAAqD;;KAGrD,WAAW,eAAe,yBAAyB;;;;;;KAO1D,UAAU,WAAW,kBAAiB,sBACxC,QAAQ,WAAW,kBAAkB,oBAAoB,QACxD,OAAO;;;;;;KASN,eAAe,WAAW,kBAAiB,aAAa,iBAC1D;EAAgB,YAAY,cAAc;oBACzB,OACf,oBACA,OACD,oBACD;;;;;;KAOE,gBAAgB,2BAA2B,aAC9C;EAAqB,eAAe;KAAa;;;;;;KAQ9C,YAAY,yBAAyB,0BACzC,gBAAgB,6BAEd,WACA,gBAAgB,yBAAwB,WACvC,gBAAgB,0BACf,qBAAqB,UACpB,QAAQ,gBAAgB,mBACvB,iBAAiB,YAAY,QAAQ,WACrC,WACD,WACD,WACD;;KAGQ,WAAW,8BAErB,yBAAyB,YAAY,YAAY,SAAS,mBAAkB,sBACzE,iBAED,eAAe,eAEf,QAAQ,YAAY,UAAU,SAC9B,OAAO,gBACH,QAAQ,UAAU,YAAY,SAAS,cAE3C,OAAO,eAAe,YAAY,SAAS,WAC3C,OAAO,gBACH,QAAQ,UAAU,YAAY,SAAS;;;;;;;;;;;;;;;;;;;;;;;;iBA4BvB,QACvB,sBACA,yBACA,eAAe,iBAAiB,SAAS,iBAAiB,QAE1D,MAAM,UAGH,qBAAqB,SACpB,SAAS,gCACJ,iBAAiB,6BAErB,QAAQ,SAAS,iBAAiB,QAAQ,iBAAiB,WAC9D,WAAW;;;;;;;;;iBCjHgB,KAAK,eAAe;;;;;;;iBCFpB,UAAU;;;;;;;;;;;;;;iBCQhB,MACvB,sBACA,eAAe,iBAAiB,SAAS,iBAAiB,QAE1D,MAAM,UACH,qBAAqB,SACpB,SAAS,gCACJ,iBAAiB,6BAErB,QAAQ,SAAS,iBAAiB,QAAQ,iBAAiB;;;;;;KChBrD;;EAEX;;EAEA;;;;;;;KCNW;;EAEX;;EAEA;;EAEA;;;;;;;;;;;;;;;;;;;qBCIY;;;;;;qBAOA;;;QCdE;YACJ;IACT,4BAA4B,YAAY;IACxC,wBAAwB,YAAY"}
|
package/dist/nav.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as getBasePath, t as addBaseToPath } from "./basePath-
|
|
2
|
-
import { i as reload, t as load } from "./load-
|
|
3
|
-
import { n as DATA_REQUEST_HEADER, r as DATA_REUSE_HEADER } from "./read-
|
|
1
|
+
import { n as getBasePath, t as addBaseToPath } from "./basePath-B6hmOMl4.mjs";
|
|
2
|
+
import { i as reload, t as load } from "./load-Dw187nJ_.mjs";
|
|
3
|
+
import { n as DATA_REQUEST_HEADER, r as DATA_REUSE_HEADER } from "./read-CPW2iPum.mjs";
|
|
4
4
|
//#region src/nav/route.ts
|
|
5
5
|
/**
|
|
6
6
|
* Builds a route path in a type-safe manner, filling in dynamic segments, e.g.
|
package/dist/nodeDev.d.mts
CHANGED
package/dist/nodeDev.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as nodeDev } from "./devPlugin-
|
|
1
|
+
export { t as nodeDev } from "./devPlugin-BGrTpcC2.mjs";
|
package/dist/openapi.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as ServerLoadEvent } from "./ServerLoadEvent-
|
|
2
|
-
import {
|
|
1
|
+
import { r as ServerLoadEvent } from "./ServerLoadEvent-CpcgsKCU.mjs";
|
|
2
|
+
import { D as SitePlugin, _ as OpenApiRouteEntry, d as OpenApiEndpointOverrides, f as OpenApiExtend, g as OpenApiPluginOptions, h as OpenApiOperation, l as JsonSchema, m as OpenApiMethod, p as OpenApiLoader, u as OpenApiEndPoint, v as ResolvedOpenApiOptions, y as ToJsonSchema } from "./Site-BEMQW1_y.mjs";
|
|
3
3
|
//#region src/openapi/document.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Builds an OpenAPI 3.1 document from a list of +server endpoints.
|
|
@@ -22,6 +22,25 @@ function findErrorRoute(router, path) {
|
|
|
22
22
|
return best?.path;
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
|
+
//#region src/utils/parseErrorStatus.ts
|
|
26
|
+
/**
|
|
27
|
+
* Parses the `status` query parameter the `/_error` page reads, accepting
|
|
28
|
+
* only a complete 4xx/5xx code. Anything else — missing, non-numeric, out of
|
|
29
|
+
* range, or a 2xx/3xx code — falls back to 404.
|
|
30
|
+
*
|
|
31
|
+
* The query string is user-controlled, so it must not decide the response
|
|
32
|
+
* status unfiltered: `?status=abc` made the response throw, `?status=200`
|
|
33
|
+
* served the error page as a success, and `?status=302` returned a redirect
|
|
34
|
+
* with no `Location`.
|
|
35
|
+
*
|
|
36
|
+
* @param value The raw `status` query value, or null when absent
|
|
37
|
+
* @returns A valid 4xx/5xx status, or 404
|
|
38
|
+
*/
|
|
39
|
+
function parseErrorStatus(value) {
|
|
40
|
+
if (value === null || !/^[45]\d{2}$/.test(value)) return 404;
|
|
41
|
+
return Number(value);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
25
44
|
//#region src/dataRequest.ts
|
|
26
45
|
/**
|
|
27
46
|
* The request header a client data request sets.
|
|
@@ -67,6 +86,6 @@ async function readResponseBody(response) {
|
|
|
67
86
|
if (response.headers.get("Content-Type")?.includes("application/json")) return await response.json();
|
|
68
87
|
}
|
|
69
88
|
//#endregion
|
|
70
|
-
export { findErrorRoute as i, DATA_REQUEST_HEADER as n, DATA_REUSE_HEADER as r, readResponseBody as t };
|
|
89
|
+
export { findErrorRoute as a, parseErrorStatus as i, DATA_REQUEST_HEADER as n, DATA_REUSE_HEADER as r, readResponseBody as t };
|
|
71
90
|
|
|
72
|
-
//# sourceMappingURL=read-
|
|
91
|
+
//# sourceMappingURL=read-CPW2iPum.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-CPW2iPum.mjs","names":[],"sources":["../src/site/findErrorRoute.ts","../src/utils/parseErrorStatus.ts","../src/dataRequest.ts","../src/response/read.ts"],"sourcesContent":["import { ERROR_ROUTE } from \"../types/RouteType\";\nimport type Router from \"./Router\";\n\n/**\n * Finds the path of the nearest error route for a request path: the error\n * route whose base (its path with the `/_error` suffix stripped) is the\n * longest prefix of the request path. E.g. an error route added with\n * `addRoute(\"/admin\", { error })` handles `/admin/nope`, while everything\n * else falls back to the root `/_error`.\n *\n * Returns undefined when the site has no matching error route.\n */\nexport default function findErrorRoute(router: Router, path: string): string | undefined {\n\tlet best: { path: string; length: number } | undefined = undefined;\n\tfor (const route of router.routes) {\n\t\tif (route.handler.type !== ERROR_ROUTE) continue;\n\t\tconst base = route.handler.path.replace(/\\/_error$/, \"\");\n\t\tconst matches = base === \"\" || path === base || path.startsWith(base + \"/\");\n\t\tif (matches && (best === undefined || base.length > best.length)) {\n\t\t\tbest = { path: route.handler.path, length: base.length };\n\t\t}\n\t}\n\treturn best?.path;\n}\n","/**\n * Parses the `status` query parameter the `/_error` page reads, accepting\n * only a complete 4xx/5xx code. Anything else — missing, non-numeric, out of\n * range, or a 2xx/3xx code — falls back to 404.\n *\n * The query string is user-controlled, so it must not decide the response\n * status unfiltered: `?status=abc` made the response throw, `?status=200`\n * served the error page as a success, and `?status=302` returned a redirect\n * with no `Location`.\n *\n * @param value The raw `status` query value, or null when absent\n * @returns A valid 4xx/5xx status, or 404\n */\nexport default function parseErrorStatus(value: string | null): number {\n\tif (value === null || !/^[45]\\d{2}$/.test(value)) return 404;\n\treturn Number(value);\n}\n","/**\n * The request header a client data request sets.\n *\n * A GET to `<page url>/~server` carrying this header is handled specially:\n * the server runs the folder hooks once against the page's url and returns the\n * server data for the page and all of its layouts in a single JSON response\n * (`{ loads: [...] }`). This mirrors the server render, where hooks run once\n * with the page url and every layout and the page load in the same request --\n * fetching each `~server` separately would run hooks with internal paths like\n * `/_layout`.\n *\n * The response's `loads` array lines up with the page's layouts (root to leaf)\n * followed by the page itself, so the client can merge each layout's cached\n * client data with its fresh server data.\n */\nexport const DATA_REQUEST_HEADER = \"X-Torpor-Data\";\n\n/**\n * A JSON array of the layout paths a data request is reusing. Reused layouts\n * keep their already-loaded data, so the server skips their loads (their slot\n * in `loads` is `null`), avoiding redundant work and repeated side effects.\n */\nexport const DATA_REUSE_HEADER = \"X-Torpor-Reuse\";\n","import { INTERNAL_RESPONSE_BODY } from \"./internal\";\n\n/**\n * The object an endpoint passed to `response()`/`ok()`, including any\n * promise-valued properties, or `undefined` for a direct `Response.json` (or\n * a non-object body).\n */\nexport function rawResponseBody(response: Response): Record<string, any> | undefined {\n\tconst body = (response as Response & { [INTERNAL_RESPONSE_BODY]?: unknown })[\n\t\tINTERNAL_RESPONSE_BODY\n\t];\n\treturn body !== null && typeof body === \"object\" ? (body as Record<string, any>) : undefined;\n}\n\n/**\n * Reads a load response's data: the original object when the endpoint used\n * `ok()`/`response()` (so deferred promises survive), otherwise its JSON body.\n */\nexport async function readResponseBody(\n\tresponse: Response | undefined,\n): Promise<Record<string, any> | undefined> {\n\tif (!response) return undefined;\n\tconst raw = rawResponseBody(response);\n\tif (raw !== undefined) return raw;\n\tif (response.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\treturn (await response.json()) as Record<string, any>;\n\t}\n\treturn undefined;\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAwB,eAAe,QAAgB,MAAkC;CACxF,IAAI,OAAqD,KAAA;CACzD,KAAK,MAAM,SAAS,OAAO,QAAQ;EAClC,IAAI,MAAM,QAAQ,SAAA,GAAsB;EACxC,MAAM,OAAO,MAAM,QAAQ,KAAK,QAAQ,aAAa,EAAE;EAEvD,KADgB,SAAS,MAAM,SAAS,QAAQ,KAAK,WAAW,OAAO,GAAG,OAC1D,SAAS,KAAA,KAAa,KAAK,SAAS,KAAK,SACxD,OAAO;GAAE,MAAM,MAAM,QAAQ;GAAM,QAAQ,KAAK;EAAO;CAEzD;CACA,OAAO,MAAM;AACd;;;;;;;;;;;;;;;;ACVA,SAAwB,iBAAiB,OAA8B;CACtE,IAAI,UAAU,QAAQ,CAAC,cAAc,KAAK,KAAK,GAAG,OAAO;CACzD,OAAO,OAAO,KAAK;AACpB;;;;;;;;;;;;;;;;;;ACDA,MAAa,sBAAsB;;;;;;AAOnC,MAAa,oBAAoB;;;;;;;;ACfjC,SAAgB,gBAAgB,UAAqD;CACpF,MAAM,OAAQ,SACb;CAED,OAAO,SAAS,QAAQ,OAAO,SAAS,WAAY,OAA+B,KAAA;AACpF;;;;;AAMA,eAAsB,iBACrB,UAC2C;CAC3C,IAAI,CAAC,UAAU,OAAO,KAAA;CACtB,MAAM,MAAM,gBAAgB,QAAQ;CACpC,IAAI,QAAQ,KAAA,GAAW,OAAO;CAC9B,IAAI,SAAS,QAAQ,IAAI,cAAc,CAAC,EAAE,SAAS,kBAAkB,GACpE,OAAQ,MAAM,SAAS,KAAK;AAG9B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as response } from "./unprocessable-BZXwyN0n.mjs";
|
|
2
2
|
//#region src/response/badRequest.ts
|
|
3
3
|
/**
|
|
4
4
|
* 400 Bad Request
|
|
@@ -45,27 +45,6 @@ function created(body) {
|
|
|
45
45
|
return response(201, body);
|
|
46
46
|
}
|
|
47
47
|
//#endregion
|
|
48
|
-
//#region src/response/forbidden.ts
|
|
49
|
-
/**
|
|
50
|
-
* 403 Forbidden
|
|
51
|
-
*
|
|
52
|
-
* The HTTP 403 Forbidden client error response status code indicates that the
|
|
53
|
-
* server understood the request but refused to process it. This status is
|
|
54
|
-
* similar to 401, except that for 403 Forbidden responses, authenticating or
|
|
55
|
-
* re-authenticating makes no difference. The request failure is tied to
|
|
56
|
-
* application logic, such as insufficient permissions to a resource or action.
|
|
57
|
-
*
|
|
58
|
-
* Clients that receive a 403 response should expect that repeating the request
|
|
59
|
-
* without modification will fail with the same error. Server owners may decide
|
|
60
|
-
* to send a 404 response instead of a 403 if acknowledging the existence of a
|
|
61
|
-
* resource to clients with insufficient privileges is not desired.
|
|
62
|
-
*
|
|
63
|
-
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403
|
|
64
|
-
*/
|
|
65
|
-
function forbidden(body) {
|
|
66
|
-
return response(403, body ?? "Forbidden");
|
|
67
|
-
}
|
|
68
|
-
//#endregion
|
|
69
48
|
//#region src/response/transfer.ts
|
|
70
49
|
/**
|
|
71
50
|
* Creates a redirect response with the supplied status code.
|
|
@@ -309,6 +288,6 @@ function unauthorized(body) {
|
|
|
309
288
|
return response(401, body ?? "Unauthorized");
|
|
310
289
|
}
|
|
311
290
|
//#endregion
|
|
312
|
-
export { permanentRedirect as a, methodNotAllowed as c,
|
|
291
|
+
export { permanentRedirect as a, methodNotAllowed as c, created as d, badRequest as f, seeOther as i, found as l, temporaryRedirect as n, notModified as o, serverError as r, movedPermanently as s, unauthorized as t, transfer as u };
|
|
313
292
|
|
|
314
|
-
//# sourceMappingURL=response-
|
|
293
|
+
//# sourceMappingURL=response-B4UoOJvv.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-B4UoOJvv.mjs","names":[],"sources":["../src/response/badRequest.ts","../src/response/created.ts","../src/response/transfer.ts","../src/response/found.ts","../src/response/methodNotAllowed.ts","../src/response/movedPermanently.ts","../src/response/notModified.ts","../src/response/permanentRedirect.ts","../src/response/seeOther.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","/**\n * Creates a redirect response with the supplied status code.\n */\nexport default function transfer(\n\tstatus: 300 | 301 | 302 | 303 | 304 | 307 | 308,\n\tlocation: string,\n): Response {\n\treturn new Response(null, {\n\t\tstatus,\n\t\theaders: {\n\t\t\tlocation,\n\t\t},\n\t});\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 transfer from \"./transfer\";\n\n/**\n * 303 See Other\n *\n * The HTTP 303 See Other redirection response status code indicates that the\n * browser should redirect to the URL in the Location header instead of\n * rendering the requested resource.\n *\n * This response code is often sent back as a result of PUT or POST methods so\n * the client may retrieve a confirmation, or view a representation of a\n * real-world object (see HTTP range-14). The method to retrieve the redirected\n * resource is always GET.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/303\n */\nexport default function seeOther(location: string): Response {\n\treturn transfer(303, 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;;;;;;AC3BA,SAAwB,SACvB,QACA,UACW;CACX,OAAO,IAAI,SAAS,MAAM;EACzB;EACA,SAAS,EACR,SACD;CACD,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACcA,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;;;;;;;;;;;;;;;;;ACbA,SAAwB,SAAS,UAA4B;CAC5D,OAAO,SAAS,KAAK,QAAQ;AAC9B;;;;;;;;;;;;;;;;;;;;;;ACGA,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"}
|
package/dist/response.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as permanentRedirect, c as methodNotAllowed, d as
|
|
1
|
+
import { a as response, i as forbidden, n as ok, r as notFound, t as unprocessable } from "./unprocessable-BZXwyN0n.mjs";
|
|
2
|
+
import { a as permanentRedirect, c as methodNotAllowed, d as created, f as badRequest, i as seeOther, l as found, n as temporaryRedirect, o as notModified, r as serverError, s as movedPermanently, t as unauthorized, u as transfer } from "./response-B4UoOJvv.mjs";
|
|
3
3
|
export { badRequest, created, forbidden, found, methodNotAllowed, movedPermanently, notFound, notModified, ok, permanentRedirect, response, seeOther, serverError, temporaryRedirect, transfer, unauthorized, unprocessable };
|
package/dist/run.d.mts
CHANGED
package/dist/run.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.mts","names":[],"sources":["../src/run/run.ts","../src/run/runBuild.ts","../src/run/runDev.ts","../src/run/runOpenApi.ts","../src/run/runPreview.ts"],"mappings":";;;iBAO8B,IAC7B,gBACA,oCACE;;;
|
|
1
|
+
{"version":3,"file":"run.d.mts","names":[],"sources":["../src/run/run.ts","../src/run/runBuild.ts","../src/run/runDev.ts","../src/run/runOpenApi.ts","../src/run/runPreview.ts"],"mappings":";;;iBAO8B,IAC7B,gBACA,oCACE;;;iBCW2B,SAAS,MAAM,OAAO;;;;;;;;;iBCiBtB,OAAO,MAAM,MAAM,aAAa,gBAAgB;;;;;;;;iBCxBhD,WAC7B,MAAM,MACN,MAAM,eACN,mBACE;;;iBCP2B,WAAW,MAAM,OAAO"}
|
package/dist/run.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as run, o as runBuild, i as runDev, t as runOpenApi, r as runPreview } from "./runOpenApi-
|
|
1
|
+
export { n as run, o as runBuild, i as runDev, t as runOpenApi, r as runPreview } from "./runOpenApi-DK-QnYEr.mjs";
|
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
//#region src/site/requestBase.ts
|
|
2
|
+
/**
|
|
3
|
+
* The base path of the site handling a request.
|
|
4
|
+
*
|
|
5
|
+
* Unlike the client runtime (one site per page), a server process can host
|
|
6
|
+
* several sites with different base paths (tests, multi-tenant servers), so
|
|
7
|
+
* the server must not read the module-global `getBasePath()`. The site's
|
|
8
|
+
* `createServerLoad` handler tags each event with its base here, and response
|
|
9
|
+
* finalization (`ServerEvent.addHeaders`) reads it back.
|
|
10
|
+
*
|
|
11
|
+
* Keyed weakly by the event, so no cleanup is needed when a request ends.
|
|
12
|
+
*/
|
|
13
|
+
const bases = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
/** Records the base path of the site handling `ev`. */
|
|
15
|
+
function setRequestBase(ev, base) {
|
|
16
|
+
bases.set(ev, base);
|
|
17
|
+
}
|
|
18
|
+
/** The base path of the site handling `ev` ("" when unset). */
|
|
19
|
+
function requestBase(ev) {
|
|
20
|
+
return bases.get(ev) ?? "";
|
|
21
|
+
}
|
|
22
|
+
const preloads = /* @__PURE__ */ new WeakMap();
|
|
23
|
+
/**
|
|
24
|
+
* Records the client chunks of the site handling `ev`, which page renders
|
|
25
|
+
* preload (kept per request for the same reason as the base path).
|
|
26
|
+
*/
|
|
27
|
+
function setRequestPreloads(ev, value) {
|
|
28
|
+
if (value) preloads.set(ev, value);
|
|
29
|
+
}
|
|
30
|
+
/** The client chunks of the site handling `ev`, if it was built with them. */
|
|
31
|
+
function requestPreloads(ev) {
|
|
32
|
+
return preloads.get(ev);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
1
35
|
//#region src/server/runHooks.ts
|
|
2
36
|
/**
|
|
3
37
|
* Runs hooks around a request handler — the shared implementation of the
|
|
@@ -56,6 +90,6 @@ async function runHooks(phases, handler, options) {
|
|
|
56
90
|
};
|
|
57
91
|
}
|
|
58
92
|
//#endregion
|
|
59
|
-
export { runHooks as t };
|
|
93
|
+
export { setRequestPreloads as a, setRequestBase as i, requestBase as n, requestPreloads as r, runHooks as t };
|
|
60
94
|
|
|
61
|
-
//# sourceMappingURL=runHooks-
|
|
95
|
+
//# sourceMappingURL=runHooks-C7kt7SEo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runHooks-C7kt7SEo.mjs","names":[],"sources":["../src/site/requestBase.ts","../src/server/runHooks.ts"],"sourcesContent":["import type ServerEvent from \"../server/ServerEvent\";\nimport type ModulePreloads from \"../types/ModulePreloads\";\n\n/**\n * The base path of the site handling a request.\n *\n * Unlike the client runtime (one site per page), a server process can host\n * several sites with different base paths (tests, multi-tenant servers), so\n * the server must not read the module-global `getBasePath()`. The site's\n * `createServerLoad` handler tags each event with its base here, and response\n * finalization (`ServerEvent.addHeaders`) reads it back.\n *\n * Keyed weakly by the event, so no cleanup is needed when a request ends.\n */\nconst bases = new WeakMap<ServerEvent, string>();\n\n/** Records the base path of the site handling `ev`. */\nexport function setRequestBase(ev: ServerEvent, base: string): void {\n\tbases.set(ev, base);\n}\n\n/** The base path of the site handling `ev` (\"\" when unset). */\nexport function requestBase(ev: ServerEvent): string {\n\treturn bases.get(ev) ?? \"\";\n}\n\nconst preloads = new WeakMap<ServerEvent, ModulePreloads>();\n\n/**\n * Records the client chunks of the site handling `ev`, which page renders\n * preload (kept per request for the same reason as the base path).\n */\nexport function setRequestPreloads(ev: ServerEvent, value: ModulePreloads | undefined): void {\n\tif (value) preloads.set(ev, value);\n}\n\n/** The client chunks of the site handling `ev`, if it was built with them. */\nexport function requestPreloads(ev: ServerEvent): ModulePreloads | undefined {\n\treturn preloads.get(ev);\n}\n","import type ServerEvent from \"./ServerEvent\";\n\n/**\n * One entry in a hook list: middleware (`MiddlewareFunction`) and server hooks\n * (`ServerHook`) are structurally identical — an optional enter and exit.\n */\ninterface Hook {\n\tenter?: (arg: any) => any;\n\texit?: (arg: any) => any;\n}\n\n/**\n * A phase of hooks around a request: a hook list plus the argument its\n * enter/exit functions take (a ServerEvent for middleware, a ServerLoadEvent\n * for server hooks). Multiple phases run their enters in order; exits run in\n * the exact reverse of entry order, across phases too.\n */\nexport interface HookPhase {\n\thooks: Hook[];\n\targ: any;\n}\n\n/**\n * Runs hooks around a request handler — the shared implementation of the\n * enter/exit machine for both middleware (site.middleware, endpoint\n * middleware) and server hooks (_hook.server.ts):\n *\n * - enter hooks run in phase order, then list order, until one returns a\n * Response (short-circuit: the handler and remaining enters are skipped)\n * - the handler runs only if no enter hook responded\n * - exit hooks run in reverse entry order — for the hooks that were entered,\n * even when the handler or an enter hook threw\n *\n * Errors are captured (and set on `options.event.error`) rather than thrown,\n * so `options.onError` can render an error response before the exit hooks run\n * (exits inspect `ev.error` to handle it). Callers rethrow `error` when the\n * result carries no response.\n *\n * With `options.event` (the middleware flavor), `ev.response` is kept in sync\n * with the running response, and an exit hook's returned Response replaces\n * it — per the `MiddlewareFunction` contract. The server-hook flavor passes\n * no event, and its exits return void.\n */\nexport default async function runHooks(\n\tphases: HookPhase[],\n\thandler: () => Promise<Response | undefined>,\n\toptions?: {\n\t\tevent?: ServerEvent;\n\t\tonError?: (ev: ServerEvent, error: unknown) => Promise<Response | undefined>;\n\t},\n): Promise<{ response: Response | undefined; error: unknown }> {\n\tconst flat = phases.flatMap((phase) => phase.hooks.map((hook) => ({ hook, arg: phase.arg })));\n\tlet entered = 0;\n\tlet response: Response | undefined = undefined;\n\tlet error: unknown = undefined;\n\tconst ev = options?.event;\n\ttry {\n\t\tfor (; entered < flat.length && !response; entered++) {\n\t\t\t// A hook returns a Response to short-circuit the request\n\t\t\tconst result = await flat[entered].hook.enter?.(flat[entered].arg);\n\t\t\tif (result) {\n\t\t\t\tresponse = result;\n\t\t\t}\n\t\t}\n\t\tif (!response) {\n\t\t\tresponse = await handler();\n\t\t}\n\t} catch (e) {\n\t\t// Exits can handle the error by returning a Response (via\n\t\t// `onError`/the caller); if none does, the caller rethrows it\n\t\terror = e;\n\t\tif (ev) {\n\t\t\tev.error = e;\n\t\t}\n\t\tif (options?.onError) {\n\t\t\tresponse = await options.onError(ev!, e);\n\t\t}\n\t} finally {\n\t\tif (ev && response) {\n\t\t\tev.response = response;\n\t\t}\n\t\t// Run exit hooks in reverse order for the hooks that were entered.\n\t\t// An exit hook can return a Response to replace the response, or to\n\t\t// handle ev.error\n\t\twhile (entered > 0) {\n\t\t\tentered--;\n\t\t\tconst result = await flat[entered].hook.exit?.(flat[entered].arg);\n\t\t\tif (result && ev) {\n\t\t\t\tresponse = result;\n\t\t\t\tev.response = result;\n\t\t\t}\n\t\t}\n\t}\n\treturn { response, error };\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,wBAAQ,IAAI,QAA6B;;AAG/C,SAAgB,eAAe,IAAiB,MAAoB;CACnE,MAAM,IAAI,IAAI,IAAI;AACnB;;AAGA,SAAgB,YAAY,IAAyB;CACpD,OAAO,MAAM,IAAI,EAAE,KAAK;AACzB;AAEA,MAAM,2BAAW,IAAI,QAAqC;;;;;AAM1D,SAAgB,mBAAmB,IAAiB,OAAyC;CAC5F,IAAI,OAAO,SAAS,IAAI,IAAI,KAAK;AAClC;;AAGA,SAAgB,gBAAgB,IAA6C;CAC5E,OAAO,SAAS,IAAI,EAAE;AACvB;;;;;;;;;;;;;;;;;;;;;;;;ACIA,eAA8B,SAC7B,QACA,SACA,SAI8D;CAC9D,MAAM,OAAO,OAAO,SAAS,UAAU,MAAM,MAAM,KAAK,UAAU;EAAE;EAAM,KAAK,MAAM;CAAI,EAAE,CAAC;CAC5F,IAAI,UAAU;CACd,IAAI,WAAiC,KAAA;CACrC,IAAI,QAAiB,K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