@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":"serverHandlers-B1L8I72-.mjs","names":[],"sources":["../src/form/formDataToRecord.ts","../src/utils/searchParamsToRecord.ts","../src/validation/endpoint.ts","../src/site/layoutSlots.ts","../src/site/mergeHead.ts","../src/site/requestPage.ts","../src/site/responseCaching.ts","../src/site/serverHandlers.ts"],"sourcesContent":["import type { FormDataRecord } from \"../types/ServerLoadEvent\";\n\n/**\n * Converts the submitted fields of a form request into a plain record: one\n * value per field, or an array when a field was submitted with multiple\n * values (e.g. a multi select). File inputs pass through as `File` values;\n * coercing them is left to the schema or the action.\n *\n * @param request The request (or FormData directly)\n * @returns The field values\n */\nexport default async function formDataToRecord(\n\trequest: Request | FormData,\n): Promise<FormDataRecord> {\n\tconst formData = request instanceof FormData ? request : await request.formData();\n\t// A null-prototype record so field names like `__proto__`, `constructor`\n\t// or `toString` are stored as data (and `__proto__` can't pollute the\n\t// prototype) instead of being skipped by an inherited-property check\n\tconst result = Object.create(null) as FormDataRecord;\n\tfor (const key of formData.keys()) {\n\t\tif (Object.hasOwn(result, key)) continue;\n\t\tconst values = formData.getAll(key);\n\t\tresult[key] = values.length > 1 ? values : values[0];\n\t}\n\treturn result;\n}\n","import type { QueryRecord } from \"../types/ServerLoadEvent\";\n\n/**\n * Converts a URL's query string into a plain record: one string per param,\n * or an array when a param was repeated.\n *\n * @param searchParams The URL's search params\n * @returns The param values\n */\nexport default function searchParamsToRecord(searchParams: URLSearchParams): QueryRecord {\n\t// A null-prototype record so param names like `__proto__`, `constructor`\n\t// or `toString` are stored as data (and `__proto__` can't pollute the\n\t// prototype) instead of being skipped by an inherited-property check\n\tconst result = Object.create(null) as QueryRecord;\n\tfor (const key of searchParams.keys()) {\n\t\tif (Object.hasOwn(result, key)) continue;\n\t\tconst values = searchParams.getAll(key);\n\t\tresult[key] = values.length > 1 ? values : values[0];\n\t}\n\treturn result;\n}\n","import type PageServerEndPoint from \"../types/PageServerEndPoint\";\nimport type ServerEndPoint from \"../types/ServerEndPoint\";\nimport type { StandardSchemaV1 } from \"../types/StandardSchema\";\nimport type ServerEvent from \"../server/ServerEvent\";\nimport searchParamsToRecord from \"../utils/searchParamsToRecord\";\nimport unprocessable from \"../response/unprocessable\";\nimport ValidationError from \"./ValidationError\";\nimport validate from \"./validate\";\n\n/**\n * Loose views of an endpoint's schema map, keyed by handler/action name (plus\n * the reserved `params` key). The type-level constraint differs per endpoint\n * type, but the runtime treats them the same.\n */\ntype Schemas = Record<string, StandardSchemaV1 | undefined>;\n\ntype EndPoint = ServerEndPoint | PageServerEndPoint;\n\n/**\n * Gets the standard schema declared for a handler or action, if any. The\n * schemas map is keyed by name; the runtime treats it as a loose record.\n *\n * Only own keys are considered: a plain read would resolve names like\n * `toString` or `constructor` to members of `Object.prototype`, handing that\n * function to `validate()` as though it were a schema.\n */\nexport function endpointSchema(endPoint: EndPoint, name: string): StandardSchemaV1 | undefined {\n\tconst schemas = endPoint.schema as Schemas | undefined;\n\tif (schemas === undefined || !Object.hasOwn(schemas, name)) return undefined;\n\treturn schemas[name];\n}\n\n/**\n * Validates the route params against the endpoint's `params` schema, if it\n * declares one, returning the coerced params. Throws a ValidationError when\n * they don't match, which callers turn into a 404 (params come from the URL,\n * so a failed validation means the resource doesn't exist).\n *\n * @param endPoint The endpoint declaring the (optional) `params` schema\n * @param params The route params from the matched route\n * @returns The validated params\n */\nexport async function validateEndpointParams(\n\tendPoint: EndPoint,\n\tparams: Record<string, any>,\n): Promise<Record<string, any>> {\n\tconst schema = endpointSchema(endPoint, \"params\");\n\treturn schema ? ((await validate(schema, params)) as Record<string, any>) : params;\n}\n\n/**\n * Validates a handler's input against its schema: get/head handlers and load\n * functions validate the URL's query string, other handlers validate the JSON\n * request body. Returns the validated values (an empty object when no schema\n * is declared), which callers pass through to the handler's event.\n *\n * @param schema The handler's (optional) schema\n * @param functionName The handler name (`get`, `post`, `load`, etc)\n * @param url The request URL, for the query string\n * @param ev The server event, for the request body\n * @returns The validated values\n */\nexport async function validateHandlerInput(\n\tschema: StandardSchemaV1 | undefined,\n\tfunctionName: string,\n\turl: URL,\n\tev: ServerEvent,\n): Promise<{ json?: unknown; form?: unknown; query?: unknown }> {\n\tif (!schema) return {};\n\tif (functionName === \"get\" || functionName === \"head\" || functionName === \"load\") {\n\t\treturn { query: await validate(schema, searchParamsToRecord(url.searchParams)) };\n\t}\n\treturn { json: await validate(schema, await ev.json()) };\n}\n\n/**\n * Turns a ValidationError thrown during endpoint validation into a 422\n * response with the schema's issues. Returns undefined for any other error,\n * which callers should rethrow.\n *\n * @param error The error thrown by a handler or validation\n * @returns A 422 response, or undefined when the error isn't a validation failure\n */\nexport function validationErrorResponse(error: unknown): Response | undefined {\n\tif (error instanceof ValidationError) {\n\t\treturn unprocessable({ message: error.message, issues: error.issues });\n\t}\n\treturn undefined;\n}\n","/**\n * Layouts are composed by the layout engine passing each layout (and finally\n * the page) as the default slot of its parent — so every `_layout` component\n * must render `<slot />`, or pass the default slot down to a child component\n * it renders. A layout that doesn't drops its entire content: the server\n * renders the layout's own markup with an empty content area (no error), and\n * the first client-side navigation that reuses the layout crashes on a null\n * slot region.\n *\n * The static `checkLayoutSlots` check catches this at build/dev time; these\n * helpers report it at request time for the cases static analysis can't see\n * (e.g. a `<slot />` rendered conditionally inside `@if`). They are\n * server-side only — nothing here is imported into the client bundle.\n */\n\n/**\n * Returns the path of the outermost layout that never rendered its\n * `<slot />`, or undefined when every level rendered.\n *\n * Slot level j (1-based) is the slot render that layout j - 1 receives: the\n * root layout (layouts[0]) renders level 1, layout i renders level i + 1,\n * and level layouts.length renders the page. A broken level makes every\n * deeper level unreachable, so the first level that never ran identifies\n * the offending layout.\n */\nexport function findMissingSlotLayout(\n\tlayouts: readonly { path: string }[],\n\tinvokedLevels: ReadonlySet<number>,\n): string | undefined {\n\tfor (let level = 1; level <= layouts.length; level++) {\n\t\tif (!invokedLevels.has(level)) {\n\t\t\treturn layouts[level - 1].path;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nconst warnedLayouts = new Set<string>();\n\n/**\n * Reports a layout that dropped its slot content. The condition is a genuine\n * rendering bug (the page content is missing from the output), so it is not\n * dev-gated — but it warns only once per layout path to avoid per-request\n * noise.\n */ export function warnMissingSlotContent(layoutPath: string): void {\n\tif (warnedLayouts.has(layoutPath)) return;\n\twarnedLayouts.add(layoutPath);\n\tconsole.warn(\n\t\t`[torpor] The layout at \"${layoutPath}\" never rendered <slot />, so the page content ` +\n\t\t\t`was not included in the render. Every _layout component must render <slot /> (or ` +\n\t\t\t`pass the default slot down to a child component it renders).`,\n\t);\n}\n","const TITLE_REGEX = /<title(?:\\s[^>]*)?>[\\s\\S]*?<\\/title>/g;\nconst FIRST_TITLE_REGEX = /<title(?:\\s[^>]*)?>[\\s\\S]*?<\\/title>/;\n\n/**\n * Merges the head string rendered by a page (and its layouts) into the site\n * template. The first <title> in the head string -- the page's, since pages\n * render before the layouts around them -- wins, overriding both any later\n * component title (e.g. from a child component) and a static <title> in the\n * template itself. All other head content (styles, meta elements, etc) is\n * appended where %COMPONENT_HEAD% sits in the template, before </head>.\n */\nexport default function mergeHead(template: string, head: string): string {\n\tconst titles = head.match(TITLE_REGEX);\n\tlet html = template;\n\tlet headHtml = head;\n\tif (titles?.length) {\n\t\theadHtml = head.replace(TITLE_REGEX, \"\");\n\t\thtml = html.replace(FIRST_TITLE_REGEX, \"\");\n\t\theadHtml = titles[0] + headHtml;\n\t}\n\treturn html.replace(\"%COMPONENT_HEAD%\", headHtml);\n}\n","import type ServerEvent from \"../server/ServerEvent\";\nimport type PageState from \"../types/PageState\";\n\n// Each request's page state, keyed by its event so that concurrent requests\n// (which interleave at every `await`) can't see each other's url, status,\n// flash message or form result. Weak, so a state goes when its request does\nconst pages = new WeakMap<ServerEvent, PageState>();\n\n/**\n * Gets the page state of the request `ev`, creating it on first use. Page\n * renders pass it to their components as `$context.$page`.\n */\nexport default function pageOf(ev: ServerEvent): PageState {\n\tlet page = pages.get(ev);\n\tif (!page) {\n\t\tpage = {\n\t\t\tstatus: 404,\n\t\t\turl: ev.url,\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\tpages.set(ev, page);\n\t}\n\treturn page;\n}\n","import type ServerEvent from \"../server/ServerEvent\";\nimport type CacheOptions from \"../server/types/CacheOptions\";\nimport { DATA_REQUEST_HEADER } from \"../dataRequest\";\n\n/** The default for responses that read or set cookies. */\nconst PRIVATE_DEFAULT = \"private, no-cache\";\n\nlet warnedPublicCookies = false;\n\n/**\n * A weak ETag for a response body, from a hash of its content. Content-based,\n * so it changes whenever the body does: a matching `If-None-Match` only ever\n * saves sending the same bytes again.\n */\nexport async function etagOf(body: string): Promise<string> {\n\tconst digest = await crypto.subtle.digest(\"SHA-1\", new TextEncoder().encode(body));\n\tlet binary = \"\";\n\tfor (const byte of new Uint8Array(digest)) binary += String.fromCharCode(byte);\n\tconst hash = btoa(binary).replace(/=+$/, \"\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\");\n\treturn `W/\"${hash}\"`;\n}\n\n/** Builds a `Cache-Control` value from merged cache options. */\nexport function cacheControlOf(options: CacheOptions): string {\n\tif (options.noStore) return \"no-store\";\n\tconst parts: string[] = [options.private ? \"private\" : \"public\"];\n\tif (options.maxAge !== undefined) parts.push(`max-age=${options.maxAge}`);\n\telse parts.push(\"no-cache\");\n\tif (options.sMaxAge !== undefined && !options.private) parts.push(`s-maxage=${options.sMaxAge}`);\n\tif (options.staleWhileRevalidate !== undefined) {\n\t\tparts.push(`stale-while-revalidate=${options.staleWhileRevalidate}`);\n\t}\n\treturn parts.join(\", \");\n}\n\n/**\n * Applies the request's caching to its response, as the last step of\n * handling it:\n *\n * - A response that read or set a cookie (the session, a flash message) is\n * `private` unless the code that handled it explicitly said otherwise,\n * so a CDN can't serve one user's page to another\n * - The `event.cache()` settings become `Cache-Control` and `Vary` on 2xx\n * GET responses, unless the response set its own `Cache-Control`\n * - A response whose ETag matches the request's `If-None-Match` becomes a\n * 304 without a body\n */\nexport function finishCaching(ev: ServerEvent, response: Response, dev: boolean): Response {\n\tconst method = ev.request.method;\n\tif (method !== \"GET\" && method !== \"HEAD\") return response;\n\n\tconst usesCookies = ev.cookies.read || ev.cookies.cookies.size > 0;\n\tconst options = ev.cacheOptions;\n\tconst ok = response.status >= 200 && response.status < 300;\n\tconst hasOwn = response.headers.has(\"Cache-Control\") || hasHeader(ev, \"Cache-Control\");\n\n\tlet cacheControl: string | undefined;\n\tlet vary: string[] = [];\n\tif (!hasOwn) {\n\t\tif (ok && options) {\n\t\t\tconst merged = { ...options };\n\t\t\tif (usesCookies && merged.private === undefined) {\n\t\t\t\tmerged.private = true;\n\t\t\t} else if (usesCookies && merged.private === false && dev && !warnedPublicCookies) {\n\t\t\t\twarnedPublicCookies = true;\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[torpor] ${ev.url.pathname} read or set a cookie but is cached with ` +\n\t\t\t\t\t\t\"`private: false`, so shared caches (CDNs) may serve it to other users. \" +\n\t\t\t\t\t\t\"Only do this if its content doesn't depend on the cookie.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcacheControl = cacheControlOf(merged);\n\t\t\tvary = options.vary ?? [];\n\t\t} else if (usesCookies) {\n\t\t\tcacheControl = PRIVATE_DEFAULT;\n\t\t} else if (ok && ev.request.headers.has(DATA_REQUEST_HEADER)) {\n\t\t\t// Client data responses are always revalidated, so the browser\n\t\t\t// keeps them for their ETag but never serves them unchecked\n\t\t\tcacheControl = \"no-cache\";\n\t\t}\n\t}\n\n\tif (cacheControl || vary.length > 0) {\n\t\tresponse = mutable(response);\n\t\tif (cacheControl) response.headers.set(\"Cache-Control\", cacheControl);\n\t\tfor (const name of vary) response.headers.append(\"Vary\", name);\n\t}\n\n\tconst etag = response.headers.get(\"ETag\");\n\tif (etag && response.status === 200 && matches(ev.request.headers.get(\"If-None-Match\"), etag)) {\n\t\tconst headers = new Headers();\n\t\tfor (const name of [\"Cache-Control\", \"ETag\", \"Vary\", \"Content-Location\", \"Expires\"]) {\n\t\t\tconst value = response.headers.get(name);\n\t\t\tif (value) headers.set(name, value);\n\t\t}\n\t\treturn new Response(null, { status: 304, headers });\n\t}\n\n\treturn response;\n}\n\n/** Whether a header was set through `event.headers`. */\nfunction hasHeader(ev: ServerEvent, name: string): boolean {\n\tconst lower = name.toLowerCase();\n\tfor (const key of ev.headers.headers.keys()) {\n\t\tif (key.toLowerCase() === lower) return true;\n\t}\n\treturn false;\n}\n\n/** Whether an `If-None-Match` value matches an ETag (weak comparison). */\nfunction matches(ifNoneMatch: string | null, etag: string): boolean {\n\tif (!ifNoneMatch) return false;\n\tif (ifNoneMatch.trim() === \"*\") return true;\n\tconst opaque = (tag: string) => tag.trim().replace(/^W\\//, \"\");\n\treturn ifNoneMatch.split(\",\").some((tag) => opaque(tag) === opaque(etag));\n}\n\n/** The response, or a copy whose headers can be changed. */\nfunction mutable(response: Response): Response {\n\ttry {\n\t\tresponse.headers.set(\"X-Torpor-Probe\", \"1\");\n\t\tresponse.headers.delete(\"X-Torpor-Probe\");\n\t\treturn response;\n\t} catch {\n\t\t// A fetched Response's headers are immutable\n\t\treturn new Response(response.body, response);\n\t}\n}\n","import { type ServerComponent, type ServerSlotRender } from \"@torpor/view/ssr\";\nimport { DATA_REUSE_HEADER, DATA_REQUEST_HEADER } from \"../dataRequest.ts\";\nimport { type DeferredMeta, jsonForScript, splitDeferred } from \"../deferred.ts\";\nimport formDataToRecord from \"../form/formDataToRecord.ts\";\nimport forbidden from \"../response/forbidden.ts\";\nimport notFound from \"../response/notFound.ts\";\nimport ok from \"../response/ok.ts\";\nimport { readResponseBody } from \"../response/read.ts\";\nimport ServerEvent from \"../server/ServerEvent.ts\";\nimport runHooks from \"../server/runHooks.ts\";\nimport type MiddlewareFunction from \"../server/types/MiddlewareFunction\";\nimport type PageEndPoint from \"../types/PageEndPoint.ts\";\nimport type { HeadElement } from \"../types/PageEndPoint.ts\";\nimport type PageLoadEvent from \"../types/PageLoadEvent.ts\";\nimport type LayoutServerEndPoint from \"../types/LayoutServerEndPoint.ts\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint.ts\";\nimport type RouteLayoutHandler from \"../types/RouteLayoutHandler.ts\";\nimport type RouteHandler from \"../types/RouteHandler.ts\";\nimport type ServerRequest from \"../types/ServerRequest.ts\";\nimport {\n\tERROR_ROUTE,\n\tHOOK_ROUTE,\n\tHOOK_SERVER_ROUTE,\n\tLAYOUT_ROUTE,\n\tLAYOUT_SERVER_ROUTE,\n\tPAGE_ROUTE,\n\tPAGE_SERVER_ROUTE,\n\tSERVER_ROUTE,\n} from \"../types/RouteType\";\nimport type ServerEndPoint from \"../types/ServerEndPoint.ts\";\nimport type ModulePreloads from \"../types/ModulePreloads.ts\";\nimport type ServerHook from \"../types/ServerHook.ts\";\nimport type ServerLoadEvent from \"../types/ServerLoadEvent.ts\";\nimport searchParamsToRecord from \"../utils/searchParamsToRecord.ts\";\nimport parseErrorStatus from \"../utils/parseErrorStatus.ts\";\nimport validate from \"../validation/validate.ts\";\nimport ValidationError from \"../validation/ValidationError.ts\";\nimport {\n\tendpointSchema,\n\tvalidateEndpointParams,\n\tvalidationErrorResponse,\n} from \"../validation/endpoint.ts\";\nimport { findMissingSlotLayout, warnMissingSlotContent } from \"./layoutSlots.ts\";\nimport { rewriteBaseInHtml, stripBaseFromUrl } from \"./basePath.ts\";\nimport findErrorRoute from \"./findErrorRoute.ts\";\nimport mergeHead from \"./mergeHead.ts\";\nimport pageOf from \"./requestPage.ts\";\nimport { etagOf, finishCaching } from \"./responseCaching.ts\";\nimport { requestBase, requestPreloads, setRequestBase, setRequestPreloads } from \"./requestBase.ts\";\nimport type Router from \"./Router.ts\";\n\n/**\n * The site's request handler, as created by `createServerLoad`.\n */\nexport type ServerLoad = (ev: ServerEvent, template?: string) => Promise<Response>;\n\n/** Whether the site is running under `tb --dev` (set by `createServerLoad`). */\nlet devMode = false;\n\n/** Route paths already reminded about embedded-data caching, so it warns once. */\nconst warnedEmbedRoutes = new Set<string>();\n\n/**\n * Dev-only reminder for a page that embeds its server data in the HTML (so a\n * shared cache could serve one user's data to another) without an explicit\n * `Cache-Control`. Setting any `Cache-Control` — `private`/`no-store` for\n * user-specific data, `public` for pages that are safe to share — silences it.\n * Warns once per route path.\n */\nfunction warnUncachedEmbeddedData(ev: ServerEvent, path: string): void {\n\tif (!devMode || warnedEmbedRoutes.has(path)) return;\n\t// Only an explicitly-set response header counts; header names are\n\t// case-insensitive, so scan rather than a single map lookup\n\tfor (const name of ev.headers.headers.keys()) {\n\t\tif (name.toLowerCase() === \"cache-control\") return;\n\t}\n\twarnedEmbedRoutes.add(path);\n\tconsole.warn(\n\t\t`[torpor] The page at \"${path}\" embeds its server load data in the HTML but sets no ` +\n\t\t\t`Cache-Control, so a shared cache could serve one user's data to another. Set it on ` +\n\t\t\t`the response from a load or hook — \"private, no-cache\" (or \"no-store\") for ` +\n\t\t\t`user-specific data, or \"public\" if the page is safe to share.`,\n\t);\n}\n\n/**\n * Creates the site's request handler for the given router. This is kept\n * separate from serverEntry, which imports the virtual\n * `@torpor/build/manifest` module (it only exists when a site runs or\n * builds), so that tests can exercise the handlers with their own routes.\n *\n * @param router The router, built from the site's routes\n * @param basePath The site's base path, stripped from incoming URLs before\n * routing (see basePath.ts)\n * @param middleware Global middleware (from `site.middleware`), run for\n * every request before routing -- including requests that won't match a\n * route\n * @returns The request handler, which takes the site template\n */\nexport function createServerLoad(\n\trouter: Router,\n\tbasePath = \"\",\n\tmiddleware: MiddlewareFunction[] = [],\n\tdev = false,\n\t// The client chunks each page needs, from the build (see clientPreloads)\n\tpreloads?: ModulePreloads,\n): ServerLoad {\n\t// The base path is carried by this handler's closure (and tagged onto each\n\t// request for response finalization), not module state: several sites\n\t// with different bases can share one process\n\tdevMode = dev;\n\n\t/**\n\t * Finalizes the response of a load or action. Successful responses and\n\t * redirects pass through; an error response gets the site's error page\n\t * rendered at the requested url, with the error's status code -- the\n\t * address bar keeps the url the user asked for, so a transient failure\n\t * (a random db hiccup, say) can be refreshed, and a typo in the path can\n\t * be seen and fixed.\n\t */\n\tasync function handleResponse(\n\t\tev: ServerEvent,\n\t\turl: URL,\n\t\ttemplate: string | undefined,\n\t\tresponse: Response,\n\t\tfromForm = false,\n\t): Promise<Response> {\n\t\t// Success codes and redirect codes are acceptable\n\t\tif (response.status >= 200 && response.status <= 399) {\n\t\t\treturn response;\n\t\t}\n\n\t\t// 4xx error codes are acceptable from form actions\n\t\tif (fromForm && response.status >= 400 && response.status <= 499) {\n\t\t\treturn response;\n\t\t}\n\n\t\t// Read a clone, not the response itself: when the error page can't\n\t\t// render (e.g. its own load redirects), the original response is\n\t\t// returned below and its body must still be readable\n\t\tlet message = await response.clone().text();\n\t\tif (response.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\ttry {\n\t\t\t\tconst data = JSON.parse(message);\n\t\t\t\tmessage = data.message ?? message;\n\t\t\t} catch {\n\t\t\t\t// Not actually json, so show the raw body\n\t\t\t}\n\t\t}\n\t\tconst rendered = await renderErrorPage(ev, url, template, router, response.status, message);\n\t\t// No error page (or rendering it failed), so the response is passed\n\t\t// through as-is\n\t\treturn rendered ?? response;\n\t}\n\n\tconst handle = async (ev: ServerEvent, template?: string): Promise<Response> => {\n\t\t// Tag the request with this site's base, so response finalization\n\t\t// (`ServerEvent.addHeaders`) adds the right prefix even when another\n\t\t// site's handler exists in the same process\n\t\tsetRequestBase(ev, basePath);\n\t\tsetRequestPreloads(ev, preloads);\n\n\t\t// The base is stripped before routing, so that everything below (route\n\t\t// matching, params, user code reading `event.url`) is base-free.\n\t\t// Requests that don't carry the base aren't ours\n\t\tconst url = stripBaseFromUrl(ev.url, basePath);\n\t\tif (!url) {\n\t\t\t// Like any other error, the error page is rendered at the\n\t\t\t// requested url rather than redirecting into the site\n\t\t\tpageOf(ev).url = ev.url;\n\t\t\tconst response = await renderErrorPage(ev, ev.url, template, router, 404, \"Not found\");\n\t\t\treturn response ?? notFound();\n\t\t}\n\t\tconst path = url.pathname;\n\t\tconst query = url.searchParams;\n\t\t// A HEAD request is routed like a GET, so it gets the same status and\n\t\t// headers; `load` drops the body\n\t\tconst method = ev.request.method === \"HEAD\" ? \"GET\" : ev.request.method;\n\n\t\t// A client data request: one GET to `<page url>/~server` returns the\n\t\t// server data for the page and all of its layouts, with hooks running\n\t\t// once against the page url. It doesn't need a registered `~server`\n\t\t// route (a page may have no `+page.server.ts` but still have layouts\n\t\t// with server loads)\n\t\tif (\n\t\t\tmethod === \"GET\" &&\n\t\t\tev.request.headers.has(DATA_REQUEST_HEADER) &&\n\t\t\tpath.endsWith(\"/~server\")\n\t\t) {\n\t\t\tconst pagePath = path.slice(0, -\"/~server\".length) || \"/\";\n\t\t\tconst pageUrl = new URL(pagePath + url.search, url);\n\t\t\tconst pageRoute = router.match(pagePath, query);\n\t\t\tif (pageRoute) {\n\t\t\t\tpageOf(ev).url = pageUrl;\n\t\t\t\treturn await loadPageData(\n\t\t\t\t\tev,\n\t\t\t\t\tpageUrl,\n\t\t\t\t\tpageRoute.handler,\n\t\t\t\t\tpageRoute.params ?? {},\n\t\t\t\t\treusedLayoutPaths(ev),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t//console.log(`handling ${ev.request.method} for '${path}'${query.size ? ` with ${query}` : \"\"}`);\n\n\t\t// Update the page state before routing, so that a request that doesn't match\n\t\t// any route (and gets the error page) still sees this url\n\t\tconst page = pageOf(ev);\n\t\tpage.url = url;\n\t\tif (path.endsWith(\"/_error\")) {\n\t\t\tpage.status = parseErrorStatus(query.get(\"status\"));\n\t\t\tpage.error = { message: query.get(\"message\") ?? \"\" };\n\t\t} else {\n\t\t\tpage.status = 200;\n\t\t\tpage.error = { message: \"\" };\n\t\t}\n\n\t\tlet route = router.match(path, query);\n\t\tif (!route) {\n\t\t\t// If the route wasn't found, the user may be posting a form to a\n\t\t\t// +page.server.ts route that doesn't have a corresponding +page.ts\n\t\t\t// route, which is allowed, so check for that as well\n\t\t\tif (ev.request.method === \"POST\" && !path.endsWith(\"/~server\")) {\n\t\t\t\tconst serverPath =\n\t\t\t\t\t(path.endsWith(\"/\") ? path.substring(0, path.length - 1) : path) + \"/~server\";\n\t\t\t\troute = router.match(serverPath, query);\n\t\t\t}\n\t\t}\n\t\tif (!route) {\n\t\t\treturn handleResponse(ev, url, template, notFound());\n\t\t}\n\t\tconst handler = route.handler;\n\t\tconst params = route.params || {};\n\t\t// Route middleware, declared on the route's server endpoint\n\t\t// (+page.server.ts / +server.ts). Runs after the global middleware and\n\t\t// the folder hooks, so a guard can see what the hooks loaded (e.g. the\n\t\t// user, in `ev.appData`) and still skip data loading entirely\n\t\tconst routeMiddleware: MiddlewareFunction[] = [];\n\t\tconst endPointModule = handler.serverEndPoint\n\t\t\t? (await resolveServerModule(handler))?.default\n\t\t\t: handler.type === PAGE_SERVER_ROUTE || handler.type === SERVER_ROUTE\n\t\t\t\t? (await resolveModule(handler))?.default\n\t\t\t\t: undefined;\n\t\tif (Array.isArray(endPointModule?.middleware)) {\n\t\t\trouteMiddleware.push(...endPointModule.middleware);\n\t\t}\n\n\t\t// Folder hooks (_hook.server.ts), from the root down, then the route's\n\t\t// middleware, run around the handler: enter hooks in order (a Response\n\t\t// short-circuits the request), exit hooks in reverse. Hooks see the\n\t\t// request's raw params and inputs; the handler validates them after\n\t\tconst serverHooks = await loadServerHooks(handler);\n\t\tconst { response: routeResponse, error } = await runHooks(\n\t\t\t[\n\t\t\t\t{ hooks: serverHooks, arg: buildServerParams(ev, url, params) },\n\t\t\t\t{ hooks: routeMiddleware, arg: ev },\n\t\t\t],\n\t\t\tasync () => {\n\t\t\t\tswitch (handler.type) {\n\t\t\t\t\tcase PAGE_ROUTE:\n\t\t\t\t\tcase LAYOUT_ROUTE: {\n\t\t\t\t\t\t// It's a /+page.ts or /_layout.ts endpoint\n\t\t\t\t\t\tif (method === \"GET\") {\n\t\t\t\t\t\t\treturn handleResponse(\n\t\t\t\t\t\t\t\tev,\n\t\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t\ttemplate,\n\t\t\t\t\t\t\t\tawait loadView(ev, url, handler, params, template),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if (ev.request.method === \"POST\") {\n\t\t\t\t\t\t\t// The server end point comes from the sibling /+page.server.ts, if applicable\n\t\t\t\t\t\t\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\t\t\t\t\t\t\thandler.serverEndPoint && (await resolveServerModule(handler)).default;\n\t\t\t\t\t\t\treturn handleResponse(\n\t\t\t\t\t\t\t\tev,\n\t\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t\ttemplate,\n\t\t\t\t\t\t\t\tawait runAction(ev, url, handler, serverEndPoint, params, query, template),\n\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase PAGE_SERVER_ROUTE:\n\t\t\t\t\tcase LAYOUT_SERVER_ROUTE: {\n\t\t\t\t\t\t// It's a /+page.server.ts or /_layout.server.ts endpoint\n\t\t\t\t\t\tif (method === \"GET\") {\n\t\t\t\t\t\t\treturn await loadData(ev, url, handler, \"load\", params);\n\t\t\t\t\t\t} else if (ev.request.method === \"POST\") {\n\t\t\t\t\t\t\tconst serverEndPoint: PageServerEndPoint | undefined = (await resolveModule(handler))\n\t\t\t\t\t\t\t\t.default;\n\t\t\t\t\t\t\treturn handleResponse(\n\t\t\t\t\t\t\t\tev,\n\t\t\t\t\t\t\t\turl,\n\t\t\t\t\t\t\t\ttemplate,\n\t\t\t\t\t\t\t\tawait runAction(ev, url, handler, serverEndPoint, params, query, template),\n\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase SERVER_ROUTE: {\n\t\t\t\t\t\t// It's a /+server.ts endpoint\n\t\t\t\t\t\tlet functionName = ev.request.method.toLowerCase().replace(\"delete\", \"del\");\n\t\t\t\t\t\t// An endpoint without its own head handler answers HEAD\n\t\t\t\t\t\t// with get, minus the body\n\t\t\t\t\t\tif (functionName === \"head\" && typeof endPointModule?.head !== \"function\") {\n\t\t\t\t\t\t\tfunctionName = \"get\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn await loadData(ev, url, handler, functionName, params);\n\t\t\t\t\t}\n\t\t\t\t\tcase HOOK_ROUTE:\n\t\t\t\t\tcase HOOK_SERVER_ROUTE: {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase ERROR_ROUTE: {\n\t\t\t\t\t\t// A direct request for the error page (e.g. a bookmark of\n\t\t\t\t\t\t// the url it used to be redirected to, or the prerender\n\t\t\t\t\t\t// writing 404.html). It responds with the requested status\n\t\t\t\t\t\t// rather than 200\n\t\t\t\t\t\treturn await loadView(ev, url, handler, params, template, page.status);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn undefined;\n\t\t\t},\n\t\t\t{ event: ev },\n\t\t);\n\t\tif (error) {\n\t\t\tthrow error;\n\t\t}\n\n\t\treturn routeResponse ?? notFound();\n\t};\n\n\treturn async function load(ev: ServerEvent, template?: string): Promise<Response> {\n\t\t// Global middleware, from `site.middleware`: runs for every request\n\t\t// before routing, including ones that won't match a route\n\t\t// (maintenance mode, legacy url redirects, etc)\n\t\tconst { response, error } = await runHooks(\n\t\t\t[{ hooks: middleware, arg: ev }],\n\t\t\tasync () => {\n\t\t\t\treturn await handle(ev, template);\n\t\t\t},\n\t\t\t{\n\t\t\t\tevent: ev,\n\t\t\t\tonError: async (ev, error) => {\n\t\t\t\t\t// A thrown exception (a load or component crashing, say) gets the\n\t\t\t\t\t// error page rendered at the requested url, like an error response\n\t\t\t\t\t// would -- unless the request was for an api endpoint (json in,\n\t\t\t\t\t// json out), or there is no error page, or rendering it failed, in\n\t\t\t\t\t// which case the error is rethrown for the server adapters\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst url = stripBaseFromUrl(ev.url, basePath) ?? ev.url;\n\t\t\t\t\t\tconst match = router.match(url.pathname, url.searchParams);\n\t\t\t\t\t\tif (match?.handler.type !== SERVER_ROUTE) {\n\t\t\t\t\t\t\tpageOf(ev).url = url;\n\t\t\t\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\t\t\t\treturn await renderErrorPage(ev, url, template, router, 500, message);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall through to the rethrow\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t\tif (error && !response) {\n\t\t\tthrow error;\n\t\t}\n\t\t// handle() always returns a Response (notFound() on a fall-through)\n\t\tconst finished = finishCaching(ev, response as Response, devMode);\n\t\treturn ev.request.method === \"HEAD\" ? withoutBody(finished) : finished;\n\t};\n}\n\n/**\n * The head tags for the page's client files and component styles.\n *\n * - `<link rel=\"modulepreload\">` for the client chunks the page needs: the\n * client entry's, then each layout's from the root down, then the page's.\n * Without them the browser only finds the page's chunks after the entry\n * script (at the end of the HTML) has downloaded and run.\n * - `<link rel=\"stylesheet\">` for the stylesheets those chunks import, which\n * hold the components' scoped styles. The client loads the same files when\n * it hydrates (through Vite's preload helper, which skips a stylesheet\n * that's already linked), so linking them here means each component's\n * styles arrive once -- the inline `<style>` copies the components rendered\n * are left out for every style a linked stylesheet contains. Head\n * stylesheets block rendering, so there's no flash of unstyled content.\n *\n * In dev there's no build manifest: the inline styles stay, tagged with\n * their Vite module id, so the dev client adopts them instead of adding\n * another copy.\n *\n * @param styles The head content the components rendered (their styles)\n */\nfunction pageAssets(ev: ServerEvent, handler: RouteHandler, styles: string): string {\n\tconst preloads = requestPreloads(ev);\n\tif (!preloads) {\n\t\treturn devMode\n\t\t\t? styles.replace(INLINE_STYLE_RE, (tag, hash: string) =>\n\t\t\t\t\ttag.replace(`<style id='${hash}'`, `<style id='${hash}' data-vite-dev-id='${hash}.css'`),\n\t\t\t\t)\n\t\t\t: styles;\n\t}\n\n\tconst routes = [...(handler.layouts ?? []).map((layout) => layout.path), handler.path];\n\tconst scripts = new Set(preloads.entry);\n\tconst stylesheets = new Set(preloads.styles.entry);\n\tfor (const route of routes) {\n\t\tfor (const file of preloads.routes[route] ?? []) scripts.add(file);\n\t\tfor (const file of preloads.styles.routes[route] ?? []) stylesheets.add(file);\n\t}\n\n\tconst linked = new Set<string>();\n\tlet links = \"\";\n\tfor (const file of stylesheets) {\n\t\tlinks += `<link rel=\"stylesheet\" href=\"${file}\">`;\n\t\tfor (const hash of preloads.styles.hashes[file] ?? []) linked.add(hash);\n\t}\n\tfor (const file of scripts) {\n\t\tlinks += `<link rel=\"modulepreload\" href=\"${file}\">`;\n\t}\n\n\t// A style no linked stylesheet contains (e.g. one from a component that\n\t// isn't in the client build) stays inline\n\treturn (\n\t\tlinks + styles.replace(INLINE_STYLE_RE, (tag, hash: string) => (linked.has(hash) ? \"\" : tag))\n\t);\n}\n\n/** A component's inline scoped style, as rendered by the server build. */\nconst INLINE_STYLE_RE = /<style id='([a-z0-9]+)'>[\\s\\S]*?<\\/style>/g;\n\n/**\n * The response to a HEAD request: the same status and headers, with the body\n * dropped (and cancelled, so a streamed body stops producing).\n */\nfunction withoutBody(response: Response): Response {\n\tif (response.body === null) return response;\n\tvoid response.body.cancel().catch(() => {\n\t\t// Already closed or errored\n\t});\n\treturn new Response(null, {\n\t\tstatus: response.status,\n\t\tstatusText: response.statusText,\n\t\theaders: response.headers,\n\t});\n}\n\n/**\n * Resolves the route's endpoint module, caching the module on the handler so\n * warm requests don't pay for the loader. The loader promise itself is never\n * cached: a request that ends before it settles leaves it permanently\n * unsettled on workerd (promises can't resolve across requests), and every\n * later request for the route would fail on it. Two cold requests may each\n * call the loader; `import()` is module-cached, so that costs an extra\n * promise at most.\n */\nasync function resolveModule(handler: RouteHandler): Promise<any> {\n\t// In dev the loaders go through Vite's module runner, which re-imports a\n\t// module when its file is edited -- caching here would serve stale code\n\t// until restart, so dev resolves fresh on every request\n\tif (devMode) return await handler.endPoint();\n\tif (handler.resolvedModule === undefined) {\n\t\thandler.resolvedModule = await handler.endPoint();\n\t}\n\treturn handler.resolvedModule;\n}\n\n/**\n * Resolves the route's sibling server endpoint module (`+page.server.ts`),\n * caching the module value like `resolveModule` does. The direct\n * `serverEndPoint()` calls (route middleware, page actions, data requests,\n * view loads) go through here so a warm route doesn't re-import per request.\n */\nasync function resolveServerModule(handler: RouteHandler): Promise<any> {\n\tif (!handler.serverEndPoint) return undefined;\n\tif (devMode) return await handler.serverEndPoint();\n\tif (handler.resolvedServerModule === undefined) {\n\t\thandler.resolvedServerModule = await handler.serverEndPoint();\n\t}\n\treturn handler.resolvedServerModule;\n}\n\n/**\n * Resolves the route's folder hooks, caching the hook list on the handler as\n * a value (never the promise -- see `resolveModule`).\n */\n/**\n * Loads a layout's server endpoint (_layout.server.ts), if it has one.\n * Layouts can't declare `middleware`: it would run for the pages below the\n * layout but not for the endpoints in the same folders, so a guard there\n * would leave those open. Rather than ignore it, this throws.\n */\nasync function loadLayoutServerEndPoint(\n\tlayout: RouteLayoutHandler,\n): Promise<LayoutServerEndPoint | undefined> {\n\tconst endPoint: LayoutServerEndPoint | undefined =\n\t\tlayout.serverEndPoint && (await layout.serverEndPoint())?.default;\n\tif (endPoint && \"middleware\" in endPoint && endPoint.middleware !== undefined) {\n\t\tthrow new Error(\n\t\t\t`The layout server endpoint for \"${layout.path}\" declares \\`middleware\\`, which isn't ` +\n\t\t\t\t\"supported on layouts: it wouldn't guard the API endpoints in its folder. \" +\n\t\t\t\t\"Move it into a _hook.server.ts in the same folder, which runs for every request below it.\",\n\t\t);\n\t}\n\treturn endPoint;\n}\n\nasync function loadServerHooks(handler: RouteHandler): Promise<ServerHook[]> {\n\tif (!handler.serverHooks) return [];\n\tif (devMode) {\n\t\treturn await Promise.all(handler.serverHooks.map(async (load) => (await load()).default));\n\t}\n\tif (handler.resolvedHooks === undefined) {\n\t\thandler.resolvedHooks = await Promise.all(\n\t\t\thandler.serverHooks.map(async (load) => (await load()).default),\n\t\t);\n\t}\n\treturn handler.resolvedHooks;\n}\n\n/**\n * Renders the site's nearest error page for a url, with the given status\n * code and message, at the url itself. Returns undefined when the site has\n * no matching error route, or when rendering the error page failed -- the\n * caller passes the original response or error through instead.\n *\n * The error page runs through the normal view pipeline, so it is rendered\n * inside the layouts of its route (e.g. the root `/_error` gets the root\n * `_layout`).\n */\nasync function renderErrorPage(\n\tev: ServerEvent,\n\turl: URL,\n\ttemplate: string | undefined,\n\trouter: Router,\n\tstatus: number,\n\tmessage: string,\n): Promise<Response | undefined> {\n\tconst errorPath = findErrorRoute(router, url.pathname);\n\tif (!errorPath) {\n\t\treturn undefined;\n\t}\n\t// Matched (rather than picked off `router.routes`) so that the error\n\t// route's layouts, server endpoint and hooks get loaded\n\tconst errorRoute = router.match(errorPath, new URLSearchParams());\n\tif (!errorRoute) {\n\t\treturn undefined;\n\t}\n\n\tconst page = pageOf(ev);\n\tpage.status = status;\n\tpage.error = { message };\n\n\ttry {\n\t\t// The error route's folder hooks run around its render, as they would\n\t\t// for any page (a root auth hook may load the user for the header)\n\t\tconst serverHooks = await loadServerHooks(errorRoute.handler);\n\t\tconst { response: hooked, error } = await runHooks(\n\t\t\t[{ hooks: serverHooks, arg: buildServerParams(ev, url, {}) }],\n\t\t\t() => loadView(ev, url, errorRoute.handler, {}, template, status),\n\t\t);\n\t\tif (error) {\n\t\t\tthrow error;\n\t\t}\n\t\tconst response = hooked as Response;\n\t\t// A load or layout of the error page can itself fail -- loadView\n\t\t// returns its response, which (unlike a rendered error page) won't\n\t\t// be html. The caller passes the original response through instead\n\t\tif (response.headers.get(\"Content-Type\")?.includes(\"text/html\")) {\n\t\t\treturn response;\n\t\t}\n\t\treturn undefined;\n\t} catch (error) {\n\t\t// The error page itself blew up; the caller's original response or\n\t\t// error is the better fallback\n\t\tconsole.log(error);\n\t\treturn undefined;\n\t}\n}\n\nasync function loadData(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tfunctionName: string,\n\tparams: Record<string, any>,\n) {\n\tconst mod = await resolveModule(handler);\n\tconst serverEndPoint: ServerEndPoint | undefined = mod?.default;\n\t// `functionName` is computed from the request method, so the handlers are\n\t// accessed through a loose record\n\tconst handlerFn = (\n\t\tserverEndPoint as unknown as Record<string, ServerRequest | undefined> | undefined\n\t)?.[functionName];\n\tif (!serverEndPoint || !handlerFn) {\n\t\treturn notFound();\n\t}\n\n\t// Route params come from the URL, so a failed validation means the\n\t// resource doesn't exist. Only endpoints declaring a params schema pay\n\t// for validation\n\tconst paramsSchema = endpointSchema(serverEndPoint, \"params\");\n\tif (paramsSchema) {\n\t\ttry {\n\t\t\tparams = (await validate(paramsSchema, params)) as Record<string, any>;\n\t\t} catch (error) {\n\t\t\tif (error instanceof ValidationError) return notFound();\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\ttry {\n\t\t// If the endpoint declares a schema for this handler, validate its\n\t\t// input up front and reject with 422 if it fails. get/head/load\n\t\t// schemas validate the query string; other schemas validate the json\n\t\t// body. Endpoints without a schema skip straight to the handler\n\t\tconst schema = endpointSchema(serverEndPoint, functionName);\n\t\tconst values = schema\n\t\t\t? functionName === \"get\" || functionName === \"head\" || functionName === \"load\"\n\t\t\t\t? { query: await validate(schema, searchParamsToRecord(url.searchParams)) }\n\t\t\t\t: { json: await validate(schema, await ev.json()) }\n\t\t\t: {};\n\n\t\tconst serverParams = buildServerParams(ev, url, params, values);\n\n\t\t// If there was no response returned from the handler (such as errors\n\t\t// or a redirect), send an ok response\n\t\treturn (await handlerFn(serverParams)) || ok();\n\t} catch (error) {\n\t\tconst response = validationErrorResponse(error);\n\t\tif (response) return response;\n\t\tthrow error;\n\t}\n}\n\n/**\n * Handles a client data request (see `DATA_REQUEST_HEADER`). Runs the folder\n * hooks once against the page url, then loads the server data for each layout\n * (root to leaf) and the page, returning `{ loads: [...] }` -- one entry per\n * layout plus the page, in the same order as `handler.layouts`. The client\n * runs its own load functions and merges the server entries in.\n *\n * A load that redirects or fails short-circuits the whole request, so the\n * client can fall back to a full page load (redirect) or render the error\n * page (failure), exactly as it would with a single page load.\n */\nasync function loadPageData(\n\tev: ServerEvent,\n\tpageUrl: URL,\n\thandler: RouteHandler,\n\tparams: Record<string, any>,\n\treusedLayouts: Set<string>,\n): Promise<Response> {\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await resolveServerModule(handler))?.default;\n\n\tconst serverHooks = await loadServerHooks(handler);\n\t// Route middleware, declared on the page's server endpoint\n\tconst routeMiddleware = Array.isArray(serverEndPoint?.middleware)\n\t\t? serverEndPoint.middleware\n\t\t: [];\n\n\t// One entry per layout (root to leaf) followed by the page itself\n\tconst loads: (Record<string, any> | null)[] = [];\n\n\tconst { response, error } = await runHooks(\n\t\t[\n\t\t\t// Hooks run from the root down; a hook's enter can return a Response\n\t\t\t// to short-circuit the request (e.g. an auth redirect)\n\t\t\t{ hooks: serverHooks, arg: buildServerParams(ev, pageUrl, params) },\n\t\t\t// Then the route middleware, like it does for a normal request\n\t\t\t{ hooks: routeMiddleware, arg: ev },\n\t\t],\n\t\tasync () => {\n\t\t\t// Validate params and the load query against the page's server\n\t\t\t// endpoint schemas, mirroring a normal page render. Params come\n\t\t\t// from the url, so a failed params validation means the resource\n\t\t\t// doesn't exist\n\t\t\tlet query: unknown;\n\t\t\tif (serverEndPoint) {\n\t\t\t\ttry {\n\t\t\t\t\tparams = await validateEndpointParams(serverEndPoint, params);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof ValidationError) return notFound();\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tconst loadSchema = endpointSchema(serverEndPoint, \"load\");\n\t\t\t\tif (loadSchema) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tquery = await validate(loadSchema, searchParamsToRecord(pageUrl.searchParams));\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst response = validationErrorResponse(error);\n\t\t\t\t\t\tif (response) return response;\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst serverParams = buildServerParams(ev, pageUrl, params, query ? { query } : {});\n\n\t\t\tfor (const layout of handler.layouts ?? []) {\n\t\t\t\t// A reused layout keeps its cached data on the client, so skip its\n\t\t\t\t// load (and any side effects) but keep the slot aligned\n\t\t\t\t// Loaded even when reused, so that a misplaced guard is reported\n\t\t\t\tconst layoutServerEndPoint = await loadLayoutServerEndPoint(layout);\n\t\t\t\tif (reusedLayouts.has(layout.path)) {\n\t\t\t\t\tloads.push(null);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst result = await loadRouteServerData(layoutServerEndPoint, serverParams);\n\t\t\t\tif (result instanceof Response) return result;\n\t\t\t\tloads.push(result);\n\t\t\t}\n\n\t\t\tconst pageResult = await loadRouteServerData(serverEndPoint, serverParams);\n\t\t\tif (pageResult instanceof Response) return pageResult;\n\t\t\tloads.push(pageResult);\n\n\t\t\treturn await serverDataResponse(loads);\n\t\t},\n\t\t{ event: ev },\n\t);\n\tif (error) {\n\t\tthrow error;\n\t}\n\treturn response as Response;\n}\n\ntype LoadDeferredEntry = {\n\tid: string;\n\tmeta: DeferredMeta;\n\tpromise: PromiseLike<unknown>;\n};\n\n/**\n * Splits each route's server data into critical values and deferred entries,\n * assigning ids in response order. Both the streaming data response and the\n * SSR-embedded payload use this so their ids/paths line up.\n */\nfunction splitLoads(loads: (Record<string, any> | null)[]): {\n\tcriticalLoads: (Record<string, any> | null)[];\n\tentries: LoadDeferredEntry[];\n} {\n\tconst entries: LoadDeferredEntry[] = [];\n\tconst criticalLoads = loads.map((load, index) => {\n\t\tif (load === null) return null;\n\t\tconst { critical, entries: splitEntries } = splitDeferred(load);\n\t\tfor (const entry of splitEntries) {\n\t\t\tconst id = `d${entries.length}`;\n\t\t\tentries.push({\n\t\t\t\tid,\n\t\t\t\tmeta: { id, index, path: entry.path },\n\t\t\t\tpromise: entry.promise,\n\t\t\t});\n\t\t}\n\t\treturn critical as Record<string, any>;\n\t});\n\treturn { criticalLoads, entries };\n}\n\n/**\n * Serializes a data request's loads. Critical (non-promise) values go in the\n * first frame as one JSON object per route; promise-valued properties are\n * announced in the same frame and then streamed as NDJSON frames, so a\n * navigation can mount as soon as the critical data arrives.\n */\nasync function serverDataResponse(loads: (Record<string, any> | null)[]): Promise<Response> {\n\tconst { criticalLoads, entries } = splitLoads(loads);\n\n\t// The payload depends on these request headers as well as the url (the\n\t// same url without them is the page's plain server endpoint)\n\tconst vary = `${DATA_REQUEST_HEADER}, ${DATA_REUSE_HEADER}`;\n\n\tif (entries.length === 0) {\n\t\tconst body = JSON.stringify({ loads: criticalLoads });\n\t\treturn new Response(body, {\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t// From the content, so the loads always run but an unchanged\n\t\t\t\t// payload isn't sent again (the browser revalidates with it)\n\t\t\t\tETag: await etagOf(body),\n\t\t\t\tVary: vary,\n\t\t\t},\n\t\t});\n\t}\n\n\tconst first = {\n\t\ttype: \"data\",\n\t\tloads: criticalLoads,\n\t\tdeferred: entries.map((entry) => entry.meta),\n\t};\n\tconst encoder = new TextEncoder();\n\tlet cancelled = false;\n\tconst stream = new ReadableStream<Uint8Array>({\n\t\tstart(controller) {\n\t\t\tconst write = (frame: object) => {\n\t\t\t\tif (cancelled) return;\n\t\t\t\ttry {\n\t\t\t\t\tcontroller.enqueue(encoder.encode(JSON.stringify(frame) + \"\\n\"));\n\t\t\t\t} catch {\n\t\t\t\t\t// The client went away; the promise handlers below finish\n\t\t\t\t\t// without anything left to write to\n\t\t\t\t}\n\t\t\t};\n\t\t\twrite(first);\n\t\t\tvoid Promise.all(\n\t\t\t\tentries.map(async (entry) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\twrite({ type: \"value\", id: entry.id, value: await entry.promise });\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\twrite({ type: \"error\", id: entry.id, message: errorMessage(error) });\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t).finally(() => {\n\t\t\t\tif (cancelled) return;\n\t\t\t\ttry {\n\t\t\t\t\tcontroller.close();\n\t\t\t\t} catch {\n\t\t\t\t\t// Already closed by an aborted stream\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tcancel() {\n\t\t\tcancelled = true;\n\t\t},\n\t});\n\treturn new Response(stream, {\n\t\theaders: { \"Content-Type\": \"application/x-ndjson\", Vary: vary },\n\t});\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\n/**\n * Runs a single route's server load (if any) as part of a data request.\n * Returns the loaded data, `null` when the route has no load, or the raw\n * Response when the load redirected or failed.\n */\nasync function loadRouteServerData(\n\tserverEndPoint: PageServerEndPoint | undefined,\n\tserverParams: ServerLoadEvent,\n): Promise<Record<string, any> | null | Response> {\n\tif (!serverEndPoint?.load) return null;\n\tconst response = await serverEndPoint.load(serverParams);\n\tif (!response) return null;\n\tif (!response.ok) return response;\n\treturn (await readResponseBody(response)) ?? null;\n}\n\nasync function loadView(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tparams: Record<string, any>,\n\ttemplate: string | undefined,\n\t// The status to respond with: a form action's result status, or an\n\t// error page's status (404, 500, ...). Defaults to 200\n\tstatus?: number,\n\tform?: Record<string, string | number>,\n\tfromForm?: boolean,\n) {\n\t// There must be a client endpoint with a component\n\tconst clientEndPoint: PageEndPoint | undefined = (await resolveModule(handler)).default;\n\tif (!clientEndPoint?.component) {\n\t\treturn notFound();\n\t}\n\n\t// Consume the flash message when a page is rendered (but not for API\n\t// requests), so that the following page -- and only that page -- can show\n\t// it. For a form action that re-renders instead of redirecting, the\n\t// message is set and read within this request\n\tpageOf(ev).flash = ev.flash.get();\n\n\t// The template comes from site.html, which endpoints-only sites don't have\n\tif (!template) {\n\t\tthrow new Error(\n\t\t\t\"Page routes require a src/site.html file, which was not found; add it, or remove page/layout routes to serve endpoints only\",\n\t\t);\n\t}\n\n\t// There may be a server endpoint\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await resolveServerModule(handler))?.default;\n\n\t// Validate the route params and the load query against the server\n\t// endpoint's schemas, if it declares any. Params come from the URL, so a\n\t// failed validation means the resource doesn't exist; a failed query goes\n\t// to the error page like any other load failure\n\tlet query: unknown;\n\tif (serverEndPoint) {\n\t\ttry {\n\t\t\tparams = await validateEndpointParams(serverEndPoint, params);\n\t\t} catch (error) {\n\t\t\tif (error instanceof ValidationError) return notFound();\n\t\t\tthrow error;\n\t\t}\n\t\tconst loadSchema = endpointSchema(serverEndPoint, \"load\");\n\t\tif (loadSchema) {\n\t\t\tconst queryRecord = searchParamsToRecord(url.searchParams);\n\t\t\ttry {\n\t\t\t\tquery = await validate(loadSchema, queryRecord);\n\t\t\t} catch (error) {\n\t\t\t\t// A form re-render's url is the POST's, and a form action can\n\t\t\t\t// drop query params that the load schema requires, so failing\n\t\t\t\t// validation here would lose the form errors. Fall back to the\n\t\t\t\t// raw query values instead and let the load make of them what\n\t\t\t\t// it can\n\t\t\t\tif (fromForm) {\n\t\t\t\t\tquery = queryRecord;\n\t\t\t\t} else {\n\t\t\t\t\tconst response = validationErrorResponse(error);\n\t\t\t\t\tif (response) return response;\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// The folder hooks already ran around this render (see `handle`, and\n\t// `renderErrorPage`), and their appData is on the event\n\tconst serverParams = buildServerParams(ev, url, params, query ? { query } : {});\n\t// Promise-valued server data, streamed to the client after the critical\n\t// data (see the embedding block below)\n\tlet deferredEntries: LoadDeferredEntry[] = [];\n\n\t// Pass the data into $props\n\t// TODO: Promise.all\n\t// NOTE: We're loading data from top to bottom, overriding as we go, and I'm\n\t// not sure if this is the best way to go\n\tlet data = {};\n\t// Each route's server-only data (root layout to page), embedded into\n\t// the HTML so the first hydration doesn't refetch it (nav/loadData.ts)\n\tconst loads: (Record<string, any> | null)[] = [];\n\tif (handler.layouts) {\n\t\tfor (let layout of handler.layouts) {\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;\n\t\t\tconst layoutServerEndPoint = await loadLayoutServerEndPoint(layout);\n\t\t\tconst layoutResponse = await loadClientAndServerData(\n\t\t\t\turl,\n\t\t\t\tparams,\n\t\t\t\tserverParams,\n\t\t\t\tdata,\n\t\t\t\tlayoutEndPoint,\n\t\t\t\tlayoutServerEndPoint,\n\t\t\t\tloads,\n\t\t\t);\n\t\t\tif (layoutResponse?.ok === false) {\n\t\t\t\treturn layoutResponse;\n\t\t\t}\n\t\t}\n\t}\n\tlet endPointResponse = await loadClientAndServerData(\n\t\turl,\n\t\tparams,\n\t\tserverParams,\n\t\tdata,\n\t\tclientEndPoint,\n\t\tserverEndPoint,\n\t\tloads,\n\t);\n\tif (endPointResponse?.ok === false) {\n\t\treturn endPointResponse;\n\t}\n\tlet $props: Record<string, any> = { data, form };\n\n\tlet styles = \"\";\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: Also handle layout server data\n\t// TODO: There's probably a nicer way to do this with reducers or something\n\tlet component = clientEndPoint.component as ServerComponent;\n\tlet slots: Record<string, ServerSlotRender> | undefined = undefined;\n\t// Which slot levels actually ran during the render below, so a layout\n\t// that never rendered its <slot /> (silently dropping the page\n\t// content) can be reported (see findMissingSlotLayout)\n\tconst invokedLevels = new Set<number>();\n\tconst trackSlot = (level: number, slot: ServerSlotRender): ServerSlotRender => {\n\t\treturn ($slot, $context) => {\n\t\t\tinvokedLevels.add(level);\n\t\t\treturn slot($slot, $context);\n\t\t};\n\t};\n\tif (handler.layouts) {\n\t\tlet slotFunctions: ServerSlotRender[] = [];\n\t\t// The last slot function will render the client component\n\t\tslotFunctions[handler.layouts.length] = trackSlot(\n\t\t\thandler.layouts.length,\n\t\t\tasync (_, $context) => {\n\t\t\t\tlet { body, head } = await (clientEndPoint.component as ServerComponent)($props, $context);\n\t\t\t\tstyles += head;\n\t\t\t\treturn body;\n\t\t\t},\n\t\t);\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 === 0) {\n\t\t\t\t\tcomponent = layoutEndPoint.component as ServerComponent;\n\t\t\t\t\tslots = { _: slotFunctions[i + 1] };\n\t\t\t\t} else {\n\t\t\t\t\tslotFunctions[i] = trackSlot(i, async (_, $context) => {\n\t\t\t\t\t\tlet { body, head } = await (layoutEndPoint.component as ServerComponent)(\n\t\t\t\t\t\t\t$props,\n\t\t\t\t\t\t\t$context,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t_: slotFunctions[i + 1],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t\tstyles += head;\n\t\t\t\t\t\treturn body;\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet html;\n\ttry {\n\t\t// Each request has its own page state, which reaches every\n\t\t// component through the root context, as `$context.$page`\n\t\tlet { body, head } = await component($props, { $page: pageOf(ev) }, slots);\n\n\t\t// Render the page's (and its layouts') head element data, if the\n\t\t// endpoint declared any. Layouts lose to the page (the nearest\n\t\t// endpoint wins, as with @head content), and everything loses to\n\t\t// the first title in the compiled head -- which mergeHead keeps\n\t\tlet headData = \"\";\n\t\tconst event = { url, params, data } as PageLoadEvent;\n\t\tconst layoutEndPoints = await Promise.all(\n\t\t\t(handler.layouts ?? []).map(async (layout) => await layout.endPoint()),\n\t\t);\n\t\tconst headPoints = [clientEndPoint, ...layoutEndPoints].reverse();\n\t\tfor (const endPoint of headPoints) {\n\t\t\tconst headElements =\n\t\t\t\ttypeof endPoint.head === \"function\" ? await endPoint.head(event) : endPoint.head;\n\t\t\tif (headElements) {\n\t\t\t\theadData += headElements.map((element: HeadElement) => markupOf(element)).join(\"\");\n\t\t\t}\n\t\t}\n\n\t\t// Put the form info in a JSON script so that it can be accessed on\n\t\t// the client. Form results often echo the submitted values back,\n\t\t// so they go through `jsonForScript` (like the server data\n\t\t// payload) rather than into an attribute\n\t\tif (form) {\n\t\t\tbody += `\\n<script type=\"application/json\" id=\"t-form-data\">${jsonForScript(form)}</script>`;\n\t\t}\n\n\t\t// Embed the routes' server-only data as json so the client's first\n\t\t// hydration reads it instead of making a `/~server` round trip\n\t\t// (nav/loadData.ts consumes it once and removes it). The condition\n\t\t// mirrors the client's `hasServerData`, so a route with only hooks or\n\t\t// actions still ships an all-null array that saves the refetch.\n\t\t// Promise values are left out and streamed as small scripts after\n\t\t// the page, so the render doesn't wait for them.\n\t\tif (routeHasServerData(handler)) {\n\t\t\tconst { criticalLoads, entries } = splitLoads(loads);\n\t\t\tdeferredEntries = entries;\n\t\t\tconst payload: {\n\t\t\t\tloads: (Record<string, any> | null)[];\n\t\t\t\tdeferred?: DeferredMeta[];\n\t\t\t} = { loads: criticalLoads };\n\t\t\tif (entries.length > 0) {\n\t\t\t\tpayload.deferred = entries.map((entry) => entry.meta);\n\t\t\t}\n\t\t\tconst json = JSON.stringify(payload).replaceAll(\"<\", \"\\\\u003c\");\n\t\t\tbody += `\\n<script type=\"application/json\" id=\"t-server-data\">${json}</script>`;\n\t\t\t// Nudge towards an explicit cache policy only when real data\n\t\t\t// was embedded (a payload of only nulls carries nothing)\n\t\t\tif (loads.some((load) => load !== null)) {\n\t\t\t\twarnUncachedEmbeddedData(ev, handler.path);\n\t\t\t}\n\t\t}\n\n\t\tstyles += head;\n\t\thtml = rewriteBaseInHtml(\n\t\t\tmergeHead(template, pageAssets(ev, handler, styles) + headData).replace(\n\t\t\t\t\"%COMPONENT_BODY%\",\n\t\t\t\tbody,\n\t\t\t),\n\t\t\trequestBase(ev),\n\t\t);\n\t} catch (error) {\n\t\t// TODO: Show a proper Error component\n\t\thtml = '<span style=\"color: red\">Script syntax error</span><p>' + error + \"</p>\";\n\t\tdeferredEntries = [];\n\t\tconsole.log(error);\n\t}\n\n\t// A layout that never rendered <slot /> silently drops the whole page\n\t// content from the output; find and report the outermost one\n\tif (handler.layouts) {\n\t\tconst missingLayout = findMissingSlotLayout(handler.layouts, invokedLevels);\n\t\tif (missingLayout !== undefined) {\n\t\t\twarnMissingSlotContent(missingLayout);\n\t\t}\n\t}\n\n\tif (deferredEntries.length > 0) {\n\t\treturn streamHtmlResponse(html, status ?? 200, deferredEntries);\n\t}\n\n\treturn new Response(html, {\n\t\tstatus: status ?? 200,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"text/html\",\n\t\t\t// From the content, so a reload of an unchanged page can get a 304\n\t\t\tETag: await etagOf(html),\n\t\t},\n\t});\n}\n\n/**\n * Streams a rendered page whose server data contained deferred values. The\n * page HTML (with skeletons/`with` branches) is sent immediately, then each\n * deferred value arrives as a tiny script that resolves its promise in the\n * client's hydration store. This is not component streaming: the SSR markup\n * for deferred values comes from the client's `$async`/`@await` boundaries.\n */\nfunction streamHtmlResponse(html: string, status: number, entries: LoadDeferredEntry[]): Response {\n\tconst encoder = new TextEncoder();\n\tconst bodyEnd = html.lastIndexOf(\"</body>\");\n\tconst before = bodyEnd === -1 ? html : html.slice(0, bodyEnd);\n\tconst after = bodyEnd === -1 ? \"\" : html.slice(bodyEnd);\n\tlet cancelled = false;\n\tconst stream = new ReadableStream<Uint8Array>({\n\t\tstart(controller) {\n\t\t\tconst write = (text: string) => {\n\t\t\t\tif (cancelled) return;\n\t\t\t\ttry {\n\t\t\t\t\tcontroller.enqueue(encoder.encode(text));\n\t\t\t\t} catch {\n\t\t\t\t\t// Client disconnected\n\t\t\t\t}\n\t\t\t};\n\t\t\twrite(before + deferredBootstrapScript());\n\t\t\tvoid Promise.all(\n\t\t\t\tentries.map(async (entry) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\twrite(deferredScript(entry.id, await entry.promise, false));\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\twrite(deferredScript(entry.id, errorMessage(error), true));\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t).finally(() => {\n\t\t\t\twrite(after);\n\t\t\t\tif (cancelled) return;\n\t\t\t\ttry {\n\t\t\t\t\tcontroller.close();\n\t\t\t\t} catch {\n\t\t\t\t\t// Already closed\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tcancel() {\n\t\t\tcancelled = true;\n\t\t},\n\t});\n\treturn new Response(stream, {\n\t\tstatus,\n\t\theaders: { \"Content-Type\": \"text/html\" },\n\t});\n}\n\n/**\n * Creates the client-side deferred store before the inline resolve scripts\n * run. Guarded so a page with multiple deferred payloads doesn't replace a\n * store that still holds pending promises.\n */\nfunction deferredBootstrapScript(): string {\n\treturn (\n\t\t\"<script>(()=>{const g=globalThis;if(g.__torporDeferred)return;\" +\n\t\t\"const e=new Map();const get=id=>{let x=e.get(id);if(!x){let resolve,reject;\" +\n\t\t\"const promise=new Promise((res,rej)=>{resolve=res;reject=rej});promise.catch(()=>{});\" +\n\t\t\"x={promise,resolve,reject};e.set(id,x)}return x};\" +\n\t\t\"g.__torporDeferred={get,resolve:(id,v)=>get(id).resolve(v),\" +\n\t\t\"reject:(id,m)=>get(id).reject(m instanceof Error?m:new Error(String(m)))}})()</script>\"\n\t);\n}\n\n/** A script that settles one deferred entry in the hydration store. */\nfunction deferredScript(id: string, value: unknown, rejected: boolean): string {\n\t// Both payloads go through `jsonForScript`: a rejection message can\n\t// contain `</script>` (e.g. one built from user input) just as a value can\n\tconst payload = jsonForScript(rejected ? String(value) : value);\n\treturn `<script>__torporDeferred.${rejected ? \"reject\" : \"resolve\"}(${jsonForScript(id)},${payload})</script>`;\n}\n\nasync function runAction(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tserverEndPoint: PageServerEndPoint | undefined,\n\tparams: Record<string, any>,\n\tquery: URLSearchParams,\n\ttemplate: string | undefined,\n) {\n\t// The action name rides in the query, so look for a `?/name` key rather\n\t// than taking the first key -- the url may carry ordinary load query\n\t// params as well (e.g. `?page=3&/like`, or a default action posted to a\n\t// url that already has a query). A key that names a declared action also\n\t// matches (e.g. `?set`), and a form without an action attribute calls the\n\t// `default` action\n\tconst actions = serverEndPoint?.actions;\n\t// Own keys only: names like `toString`, `constructor` or `__proto__` are\n\t// on Object.prototype, so a plain property read would resolve them and\n\t// invoke (or crash on) a prototype member instead of returning 404.\n\tconst hasAction = (name: string): boolean =>\n\t\tactions !== undefined && Object.hasOwn(actions, name);\n\tconst queryKeys = Array.from(query.keys());\n\tconst actionKey =\n\t\tqueryKeys.find((key) => key.startsWith(\"/\")) ??\n\t\tqueryKeys.find((key) => hasAction(key.replace(/^\\//, \"\")));\n\tconst actionName = (actionKey ?? \"default\").replace(/^\\//, \"\");\n\tif (serverEndPoint !== undefined && actions !== undefined && Object.hasOwn(actions, actionName)) {\n\t\tconst action = actions[actionName];\n\t\tif (action) {\n\t\t\t// CSRF defense in depth: form actions are state-changing POSTs, so\n\t\t\t// reject a browser-sent Origin that doesn't match this site. A\n\t\t\t// missing Origin (non-browser clients, some privacy modes) is\n\t\t\t// allowed, like SvelteKit's checkOrigin.\n\t\t\tconst origin = ev.request.headers.get(\"Origin\");\n\t\t\tif (origin !== null) {\n\t\t\t\tlet sameOrigin = false;\n\t\t\t\ttry {\n\t\t\t\t\tsameOrigin = new URL(origin).origin === url.origin;\n\t\t\t\t} catch {\n\t\t\t\t\t// A malformed Origin can't be trusted\n\t\t\t\t}\n\t\t\t\tif (!sameOrigin) {\n\t\t\t\t\treturn forbidden(\"Cross-site form submissions are forbidden\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (actionName === \"load\" || actionName === \"params\") {\n\t\t\t\t// These names are reserved in the endpoint's schema map: `load`\n\t\t\t\t// validates the query string and `params` the route params, so\n\t\t\t\t// an action with one of these names would get the wrong schema\n\t\t\t\t// applied to its form data\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`The action name \"${actionName}\" is reserved. ` +\n\t\t\t\t\t\t`Rename the action (and its schema key, if any), e.g. to \"save\".`,\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Route params come from the URL, so a failed validation means the\n\t\t\t// resource doesn't exist\n\t\t\ttry {\n\t\t\t\tparams = await validateEndpointParams(serverEndPoint, params);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof ValidationError) return notFound();\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\t// The folder hooks already ran around the action (see `handle`), so\n\t\t\t// an auth hook can reject an unauthenticated request before it gets\n\t\t\t// schema errors back\n\t\t\tlet result: Response | undefined | void;\n\t\t\ttry {\n\t\t\t\t// If the endpoint declares a schema for this action, validate the\n\t\t\t\t// submitted form data and reject with 422 if it fails. The form\n\t\t\t\t// data is parsed on the event, so the action's `event.form()` /\n\t\t\t\t// `event.formData()` share this read of the body\n\t\t\t\tconst values: { form?: unknown } = {};\n\t\t\t\tconst schema = endpointSchema(serverEndPoint, actionName);\n\t\t\t\tif (schema) {\n\t\t\t\t\tvalues.form = await validate(schema, await formDataToRecord(await ev.formData()));\n\t\t\t\t}\n\t\t\t\tresult = await action(buildServerParams(ev, url, params, values));\n\t\t\t} catch (error) {\n\t\t\t\tconst response = validationErrorResponse(error);\n\t\t\t\tif (response) return response;\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tif (ev.request.headers.has(\"X-Torpor-Form-Submit\")) {\n\t\t\t\t// If the form was submitted from javascript, just return the\n\t\t\t\t// response and it will be handled on the client\n\t\t\t\t// TODO: Should we make the user return a response??\n\t\t\t\tresult ??= ok();\n\n\t\t\t\t// If it's a redirect, we need to stop the browser handling it\n\t\t\t\tif (result.status >= 300 && result.status <= 399) {\n\t\t\t\t\tconst location = result.headers.get(\"Location\") ?? \"\";\n\t\t\t\t\tresult = ok();\n\t\t\t\t\tresult.headers.set(\"X-Torpor-Form-Redirect\", \"\");\n\t\t\t\t\tresult.headers.set(\"Location\", location);\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t} else if (\n\t\t\t\t!result ||\n\t\t\t\t(result.status >= 200 && result.status <= 299) ||\n\t\t\t\t(result.status >= 400 && result.status <= 499)\n\t\t\t) {\n\t\t\t\t// If the form was submitted without javascript, and there was\n\t\t\t\t// no result, an ok result, or a 4xx error, re-render the view\n\t\t\t\t// with the form result. The server hooks ran around the action\n\t\t\t\t// and this re-render, so loads guarding on their appData (e.g. an\n\t\t\t\t// auth hook's user) see the same data as the action did\n\t\t\t\t// Keep the query string, so that loads validating the query see\n\t\t\t\t// the same values as the original GET. If the form action\n\t\t\t\t// dropped params that the load schema requires, loadView falls\n\t\t\t\t// back to the raw query instead of failing validation\n\t\t\t\tconst newUrl = new URL(url.pathname + url.search, url);\n\t\t\t\tconst formStatus = result?.status;\n\t\t\t\tlet formMessage = await result?.text();\n\t\t\t\tconst page = pageOf(ev);\n\t\t\t\tif (formMessage && result?.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\tpage.form = JSON.parse(formMessage);\n\t\t\t\t\tformMessage = undefined;\n\t\t\t\t} else {\n\t\t\t\t\tpage.form = {};\n\t\t\t\t}\n\t\t\t\t// Set status and message if they haven't already been set,\n\t\t\t\t// which means that you can just return e.g. forbidden() or\n\t\t\t\t// forbidden(\"no!\") and there will be something you can work\n\t\t\t\t// with in your component, or you can set a completely custom\n\t\t\t\t// object with whatever info you need\n\t\t\t\tpage.form!.status ??= formStatus ?? 0;\n\t\t\t\tpage.form!.message ??= formMessage ?? \"\";\n\t\t\t\treturn await loadView(ev, newUrl, handler, params, template, formStatus, page.form, true);\n\t\t\t} else {\n\t\t\t\t// If the form was submitted without javascript and there was a\n\t\t\t\t// redirect or server error, just return the result to handle it\n\t\t\t\t// as normal\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn notFound();\n}\n\n/**\n * Whether the route has any server-side code to run (a page or layout server\n * endpoint, or a folder hook) — the same condition the client uses to decide\n * whether to make a `/~server` request (nav/loadData.ts's `hasServerData`).\n * When it holds, the render embeds a server-data payload so the first\n * hydration skips that request.\n */\nfunction routeHasServerData(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\nasync function loadClientAndServerData(\n\turl: URL,\n\tparams: Record<string, any>,\n\tserverParams: ServerLoadEvent,\n\tdata: Record<string, any>,\n\tclientEndPoint?: PageEndPoint,\n\tserverEndPoint?: PageServerEndPoint,\n\tloads?: (Record<string, any> | null)[],\n) {\n\tif (clientEndPoint?.load) {\n\t\tconst clientParams = buildClientParams(url, params, data);\n\t\tconst clientResponse = await clientEndPoint.load(clientParams);\n\t\tif (clientResponse) {\n\t\t\tif (clientResponse.ok) {\n\t\t\t\tconst clientData = await readResponseBody(clientResponse);\n\t\t\t\tif (clientData) Object.assign(data, clientData);\n\t\t\t} else {\n\t\t\t\treturn clientResponse;\n\t\t\t}\n\t\t}\n\t}\n\tlet serverData: Record<string, any> | null = null;\n\tif (serverEndPoint?.load) {\n\t\tconst serverResponse = await serverEndPoint.load(serverParams);\n\t\tif (serverResponse) {\n\t\t\tif (serverResponse.ok) {\n\t\t\t\tserverData = (await readResponseBody(serverResponse)) ?? null;\n\t\t\t\tif (serverData) Object.assign(data, serverData);\n\t\t\t} else {\n\t\t\t\treturn serverResponse;\n\t\t\t}\n\t\t}\n\t}\n\t// Record this route's server-only data, aligned with the page and its\n\t// layouts (root to leaf), so the render can embed it for hydration\n\tloads?.push(serverData);\n}\n\nfunction buildClientParams(url: URL, params: Record<string, any>, data: Record<string, any>) {\n\treturn {\n\t\turl,\n\t\tparams,\n\t\tdata,\n\t};\n}\n\n/**\n * The layout paths a data request asked to reuse, from the `X-Torpor-Reuse`\n * header (a JSON array). A malformed header is ignored rather than failing the\n * request -- the client just gets the layouts loaded again.\n */\nfunction reusedLayoutPaths(ev: ServerEvent): Set<string> {\n\tconst header = ev.request.headers.get(DATA_REUSE_HEADER);\n\tif (!header) return new Set();\n\ttry {\n\t\tconst paths = JSON.parse(header) as unknown;\n\t\tif (Array.isArray(paths)) {\n\t\t\treturn new Set(paths.filter((p): p is string => typeof p === \"string\"));\n\t\t}\n\t} catch {\n\t\t// Not valid json\n\t}\n\treturn new Set();\n}\n\n/**\n * The url user code (hooks, loads, actions, `@head`) should see. Client-side\n * data fetches append `/~server` to the page url, but that suffix is an\n * internal detail: without stripping it, `event.url.pathname` would differ\n * between the server-rendered page and its `~server` request, so a hook\n * guarding on the path (e.g. `path !== \"/setup\"`) would misfire.\n */\nfunction requestUrl(url: URL): URL {\n\tif (!url.pathname.endsWith(\"/~server\")) return url;\n\tconst path = url.pathname.slice(0, -\"/~server\".length) || \"/\";\n\treturn new URL(path + url.search, url);\n}\n\nfunction buildServerParams(\n\tev: ServerEvent,\n\turl: URL,\n\tparams: Record<string, any>,\n\tvalues: { json?: unknown; form?: unknown; query?: unknown } = {},\n): ServerLoadEvent {\n\tconst logicalUrl = requestUrl(url);\n\treturn {\n\t\turl: logicalUrl,\n\t\tparams,\n\t\t// Shared by the whole request, so that hooks, middleware, loads and\n\t\t// actions all see the same data\n\t\tappData: ev.appData,\n\t\trequest: ev.request,\n\t\t// The inputs may have been validated already, in which case the request\n\t\t// body has been consumed and the parsed values are returned instead.\n\t\t// Their types come from the endpoint's schemas, so they are loosely\n\t\t// typed here\n\t\tjson: (): Promise<any> =>\n\t\t\tvalues.json !== undefined ? Promise.resolve(values.json) : ev.json(),\n\t\tform: async (): Promise<any> =>\n\t\t\tvalues.form !== undefined\n\t\t\t\t? Promise.resolve(values.form)\n\t\t\t\t: formDataToRecord(await ev.formData()),\n\t\tformData: (): Promise<FormData> => ev.formData(),\n\t\tquery: (): Promise<any> =>\n\t\t\tvalues.query !== undefined\n\t\t\t\t? Promise.resolve(values.query)\n\t\t\t\t: Promise.resolve(searchParamsToRecord(logicalUrl.searchParams)),\n\t\tcookies: ev.cookies,\n\t\theaders: ev.headers,\n\t\tsession: ev.session,\n\t\tflash: ev.flash,\n\t\tcache: (options) => ev.cache(options),\n\t\twaitUntil: (promise) => ev.waitUntil(promise),\n\t\tadapter: ev.adapter,\n\t};\n}\n\n/**\n * Renders a head element as markup. Attribute values are escaped, since\n * they can come from user data (e.g. a post title passed to `seo()`).\n */\nfunction markupOf(element: HeadElement): string {\n\tif (\"title\" in element) {\n\t\treturn `<title>${escapeHtml(element.title)}</title>`;\n\t}\n\tif (\"name\" in element) {\n\t\treturn `<meta name=\"${escapeHtml(element.name)}\" content=\"${escapeHtml(element.content)}\" />`;\n\t}\n\treturn `<meta property=\"${escapeHtml(element.property)}\" content=\"${escapeHtml(element.content)}\" />`;\n}\n\nfunction escapeHtml(value: string): string {\n\treturn value\n\t\t.replaceAll(\"&\", \"&\")\n\t\t.replaceAll(\"<\", \"<\")\n\t\t.replaceAll(\">\", \">\")\n\t\t.replaceAll('\"', \""\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,eAA8B,iBAC7B,SAC0B;CAC1B,MAAM,WAAW,mBAAmB,WAAW,UAAU,MAAM,QAAQ,SAAS;CAIhF,MAAM,SAAS,OAAO,OAAO,IAAI;CACjC,KAAK,MAAM,OAAO,SAAS,KAAK,GAAG;EAClC,IAAI,OAAO,OAAO,QAAQ,GAAG,GAAG;EAChC,MAAM,SAAS,SAAS,OAAO,GAAG;EAClC,OAAO,OAAO,OAAO,SAAS,IAAI,SAAS,OAAO;CACnD;CACA,OAAO;AACR;;;;;;;;;;AChBA,SAAwB,qBAAqB,cAA4C;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;EAKZ,YACC,OAAO,SAAS,KAAA,IAAY,QAAQ,QAAQ,OAAO,IAAI,IAAI,GAAG,KAAK;EACpE,MAAM,YACL,OAAO,SAAS,KAAA,IACb,QAAQ,QAAQ,OAAO,IAAI,IAC3B,iBAAiB,MAAM,GAAG,SAAS,CAAC;EACxC,gBAAmC,GAAG,SAAS;EAC/C,aACC,OAAO,UAAU,KAAA,IACd,QAAQ,QAAQ,OAAO,KAAK,IAC5B,QAAQ,QAAQ,qBAAqB,WAAW,YAAY,CAAC;EACjE,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,SAAS,GAAG;EACZ,OAAO,GAAG;EACV,QAAQ,YAAY,GAAG,MAAM,OAAO;EACpC,YAAY,YAAY,GAAG,UAAU,OAAO;EAC5C,SAAS,GAAG;CACb;AACD;;;;;AAMA,SAAS,SAAS,SAA8B;CAC/C,IAAI,WAAW,SACd,OAAO,UAAU,WAAW,QAAQ,KAAK,EAAE;CAE5C,IAAI,UAAU,SACb,OAAO,eAAe,WAAW,QAAQ,IAAI,EAAE,aAAa,WAAW,QAAQ,OAAO,EAAE;CAEzF,OAAO,mBAAmB,WAAW,QAAQ,QAAQ,EAAE,aAAa,WAAW,QAAQ,OAAO,EAAE;AACjG;AAEA,SAAS,WAAW,OAAuB;CAC1C,OAAO,MACL,WAAW,KAAK,OAAO,CAAC,CACxB,WAAW,KAAK,MAAM,CAAC,CACvB,WAAW,KAAK,MAAM,CAAC,CACvB,WAAW,MAAK,QAAQ;AAC3B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as RouteParamsOf, n as ParseRouteParams, t as ExactRouteParams } from "./ParseRouteParams-BtC0eH3z.mjs";
|
|
2
|
-
import { r as ServerLoadEvent } from "./ServerLoadEvent-
|
|
2
|
+
import { r as ServerLoadEvent } from "./ServerLoadEvent-CpcgsKCU.mjs";
|
|
3
3
|
import { n as UntypedResponse, t as TypedResponse } from "./TypedResponse-6lznqN4U.mjs";
|
|
4
4
|
import { Component } from "@torpor/view";
|
|
5
5
|
//#region src/types/PageLoadEvent.d.ts
|
|
@@ -121,4 +121,4 @@ type SitemapOptions = {
|
|
|
121
121
|
declare function sitemapResponse(options: SitemapOptions, basePath: string, event: ServerLoadEvent): Promise<Response>;
|
|
122
122
|
//#endregion
|
|
123
123
|
export { PageLoadReturn as a, PageEndPoint as i, sitemapResponse as n, PageLoadEvent as o, HeadElement as r, SitemapOptions as t };
|
|
124
|
-
//# sourceMappingURL=sitemap-
|
|
124
|
+
//# sourceMappingURL=sitemap-CKmagPyL.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sitemap-
|
|
1
|
+
{"version":3,"file":"sitemap-CKmagPyL.d.mts","names":[],"sources":["../src/types/PageLoadEvent.ts","../src/types/PageLoadReturn.ts","../src/types/PageEndPoint.ts","../src/discovery/sitemap.ts"],"mappings":";;;;;;;;;;;UAQyB,cACxB,8CACA,OAAO;;;;EAKP,KAAK;;;;EAIL,QAAQ,cAAc;;;;;EAKtB,MAAM;;;;;;;;;;;;;;KCXK,eAAe,QACxB,cAAc,QAAQ,SACtB;;;;;;;;UCLsB,aACxB,8CACA,OAAO;;;;;;;;EASP,SAAS,eAAe,cAAc,WAClC,MAAM,sCACS,SACb,SAAS,gCACJ,iBAAiB,6BAErB,QAAQ,SAAS,iBAAiB,QAAQ,iBAAiB,YAC7D,SAAS;;;;;;;EAQd;;;;EAIA,QAAQ,OAAO,cAAc,WAAW,eAAe,QAAQ,QAAQ,eAAe;;;;;;;;EAQtF;IAAwB,QAAQ;;;;;EAIhC,YAAY;;;;EAKZ,OAAO,kBAAkB,OAAO,cAAc,WAAW;;KAGrD,cAAc,eAAe,cAAc;UAEtC;EACT;;UAGS;EACT;EACA;;;;;;UAOS;EACT;EACA;;;;;;;;KCtEW;;EAEX;;EAEA;;EAEA,MAAM,OAAO,+BAA+B;;;;;;;iBAQvB,gBACrB,SAAS,gBACT,kBACA,OAAO,kBACL,QAAQ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as addBaseToPath } from "./basePath-
|
|
1
|
+
import { t as addBaseToPath } from "./basePath-B6hmOMl4.mjs";
|
|
2
2
|
//#region src/discovery/sitemap.ts
|
|
3
3
|
/**
|
|
4
4
|
* Serves the sitemap content for a runtime config: the urls returned by
|
|
@@ -27,4 +27,4 @@ function escapeXml(value) {
|
|
|
27
27
|
//#endregion
|
|
28
28
|
export { sitemapXml as n, sitemapResponse as t };
|
|
29
29
|
|
|
30
|
-
//# sourceMappingURL=sitemap-
|
|
30
|
+
//# sourceMappingURL=sitemap-DdzFjGlo.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sitemap-
|
|
1
|
+
{"version":3,"file":"sitemap-DdzFjGlo.mjs","names":[],"sources":["../src/discovery/sitemap.ts"],"sourcesContent":["import type ServerLoadEvent from \"../types/ServerLoadEvent\";\nimport { addBaseToPath } from \"../site/basePath\";\n\n/**\n * A runtime sitemap config, set on `site.sitemap`: the endpoint reads urls\n * from `get` (the database, typically) and serves the XML on each request.\n */\nexport type SitemapOptions = {\n\t/** The path to serve, e.g. \"/sitemap.xml\" */\n\tpath?: string;\n\t/** The site origin, e.g. \"https://example.com\". Overrides `site.origin`. */\n\torigin?: string;\n\t/** Returns base-free paths for the pages to list, e.g. [\"/posts/a\"] */\n\tget: (event: ServerLoadEvent) => string[] | Promise<string[]>;\n};\n\n/**\n * Serves the sitemap content for a runtime config: the urls returned by\n * `get`, prefixed with the site origin (and the base path, when the site\n * is mounted under a subpath).\n */\nexport async function sitemapResponse(\n\toptions: SitemapOptions,\n\tbasePath: string,\n\tevent: ServerLoadEvent,\n): Promise<Response> {\n\tconst paths = await options.get(event);\n\tconst xml = sitemapXml(options.origin ?? \"\", basePath, paths);\n\treturn new Response(xml, {\n\t\theaders: { \"Content-Type\": \"application/xml\" },\n\t});\n}\n\n/**\n * Builds the sitemap content: one `<url>` per page, with the loc values\n * being the origin (plus the base path, when the site is mounted under a\n * subpath) plus the route path. Values are escaped.\n */\nexport function sitemapXml(origin: string, base: string, paths: string[]): string {\n\tconst locs = paths.map((routePath) => {\n\t\tconst path = routePath === \"/\" ? base || \"/\" : addBaseToPath(routePath, base);\n\t\treturn `<loc>${escapeXml(origin)}${escapeXml(path)}</loc>`;\n\t});\n\treturn (\n\t\t`<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n` +\n\t\t`<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\\n` +\n\t\tlocs.map((loc) => ` <url>\\n ${loc}\\n </url>`).join(\"\\n\") +\n\t\t`\\n</urlset>`\n\t);\n}\n\nfunction escapeXml(value: string): string {\n\treturn value\n\t\t.replaceAll(\"&\", \"&\")\n\t\t.replaceAll(\"<\", \"<\")\n\t\t.replaceAll(\">\", \">\")\n\t\t.replaceAll('\"', \""\");\n}\n"],"mappings":";;;;;;;AAqBA,eAAsB,gBACrB,SACA,UACA,OACoB;CACpB,MAAM,QAAQ,MAAM,QAAQ,IAAI,KAAK;CACrC,MAAM,MAAM,WAAW,QAAQ,UAAU,IAAI,UAAU,KAAK;CAC5D,OAAO,IAAI,SAAS,KAAK,EACxB,SAAS,EAAE,gBAAgB,kBAAkB,EAC9C,CAAC;AACF;;;;;;AAOA,SAAgB,WAAW,QAAgB,MAAc,OAAyB;CAKjF,OACC,iHALY,MAAM,KAAK,cAAc;EACrC,MAAM,OAAO,cAAc,MAAM,QAAQ,MAAM,cAAc,WAAW,IAAI;EAC5E,OAAO,QAAQ,UAAU,MAAM,IAAI,UAAU,IAAI,EAAE;CACpD,CAII,CAAC,CAAC,KAAK,QAAQ,gBAAgB,IAAI,WAAW,CAAC,CAAC,KAAK,IAAI,IAC5D;AAEF;AAEA,SAAS,UAAU,OAAuB;CACzC,OAAO,MACL,WAAW,KAAK,OAAO,CAAC,CACxB,WAAW,KAAK,MAAM,CAAC,CACvB,WAAW,KAAK,MAAM,CAAC,CACvB,WAAW,MAAK,QAAQ;AAC3B"}
|
package/dist/state.d.mts
CHANGED
package/dist/state.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.mts","names":[],"sources":["../src/types/PageState.ts"
|
|
1
|
+
{"version":3,"file":"state.d.mts","names":[],"sources":["../src/types/PageState.ts"],"mappings":";UAAyB;EACxB;EACA,KAAK;EACL,OAAO;EACP;IACC;;;;;;;EAOD,QAAQ"}
|
package/dist/state.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/test.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as ServerEvent } from "./MiddlewareFunction-
|
|
2
|
-
import { t as Site } from "./Site-
|
|
1
|
+
import { n as ServerEvent } from "./MiddlewareFunction-DMYxjzF4.mjs";
|
|
2
|
+
import { t as Site } from "./Site-BEMQW1_y.mjs";
|
|
3
3
|
//#region src/test/runTest.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Runs a site route in test mode
|
package/dist/test.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as Router } from "./Router-C4ADUfhv.mjs";
|
|
2
|
-
import { t as ServerEvent } from "./ServerEvent-
|
|
3
|
-
import { t as createServerLoad } from "./serverHandlers-
|
|
2
|
+
import { t as ServerEvent } from "./ServerEvent-BBRkd4Ya.mjs";
|
|
3
|
+
import { t as createServerLoad } from "./serverHandlers-B1L8I72-.mjs";
|
|
4
4
|
import fpath from "node:path";
|
|
5
5
|
//#region src/test/runTest.ts
|
|
6
6
|
/**
|
|
@@ -31,6 +31,27 @@ function response(status, body) {
|
|
|
31
31
|
return result;
|
|
32
32
|
}
|
|
33
33
|
//#endregion
|
|
34
|
+
//#region src/response/forbidden.ts
|
|
35
|
+
/**
|
|
36
|
+
* 403 Forbidden
|
|
37
|
+
*
|
|
38
|
+
* The HTTP 403 Forbidden client error response status code indicates that the
|
|
39
|
+
* server understood the request but refused to process it. This status is
|
|
40
|
+
* similar to 401, except that for 403 Forbidden responses, authenticating or
|
|
41
|
+
* re-authenticating makes no difference. The request failure is tied to
|
|
42
|
+
* application logic, such as insufficient permissions to a resource or action.
|
|
43
|
+
*
|
|
44
|
+
* Clients that receive a 403 response should expect that repeating the request
|
|
45
|
+
* without modification will fail with the same error. Server owners may decide
|
|
46
|
+
* to send a 404 response instead of a 403 if acknowledging the existence of a
|
|
47
|
+
* resource to clients with insufficient privileges is not desired.
|
|
48
|
+
*
|
|
49
|
+
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403
|
|
50
|
+
*/
|
|
51
|
+
function forbidden(body) {
|
|
52
|
+
return response(403, body ?? "Forbidden");
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
34
55
|
//#region src/response/notFound.ts
|
|
35
56
|
/**
|
|
36
57
|
* 404 Not Found
|
|
@@ -109,6 +130,6 @@ function unprocessable(body) {
|
|
|
109
130
|
return response(422, body ?? "Unprocessable");
|
|
110
131
|
}
|
|
111
132
|
//#endregion
|
|
112
|
-
export { response as i, ok as n, notFound as r, unprocessable as t };
|
|
133
|
+
export { response as a, forbidden as i, ok as n, notFound as r, unprocessable as t };
|
|
113
134
|
|
|
114
|
-
//# sourceMappingURL=unprocessable-
|
|
135
|
+
//# sourceMappingURL=unprocessable-BZXwyN0n.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unprocessable-BZXwyN0n.mjs","names":[],"sources":["../src/response/response.ts","../src/response/forbidden.ts","../src/response/notFound.ts","../src/response/ok.ts","../src/response/unprocessable.ts"],"sourcesContent":["import { type DeferredEntry, splitDeferred } from \"../deferred\";\nimport { INTERNAL_RESPONSE_BODY, INTERNAL_RESPONSE_DEFERRED } from \"./internal\";\n\n/**\n * Creates a response with the supplied status code and optional body.\n *\n * If the body is an object, it will be converted to JSON and the Content-Type\n * header set to \"application/json\". Promise-valued properties are left out of\n * the JSON and kept on the Response (see `deferred.ts`), so a load can stream\n * them after the critical data. Otherwise, if the body is a string, the\n * Content-Type header will be set to \"text/plain\".\n */\nexport default function response(status: number, body?: object | string): Response {\n\tlet headers: Record<string, string> | undefined = undefined;\n\tlet originalBody: object | undefined;\n\tlet deferred: DeferredEntry[] | undefined;\n\tif (body) {\n\t\tif (typeof body === \"object\") {\n\t\t\tconst split = splitDeferred(body);\n\t\t\toriginalBody = body;\n\t\t\tdeferred = split.entries;\n\t\t\theaders = { \"Content-Type\": \"application/json\" };\n\t\t\tbody = JSON.stringify(split.critical);\n\t\t} else {\n\t\t\theaders = { \"Content-Type\": \"text/plain\" };\n\t\t}\n\t}\n\tconst result = new Response(body, {\n\t\tstatus,\n\t\theaders,\n\t}) as Response & {\n\t\t[INTERNAL_RESPONSE_BODY]?: object;\n\t\t[INTERNAL_RESPONSE_DEFERRED]?: DeferredEntry[];\n\t};\n\tif (originalBody !== undefined) {\n\t\tresult[INTERNAL_RESPONSE_BODY] = originalBody;\n\t}\n\tif (deferred && deferred.length > 0) {\n\t\tresult[INTERNAL_RESPONSE_DEFERRED] = deferred;\n\t}\n\treturn result;\n}\n","import response from \"./response\";\n\n/**\n * 403 Forbidden\n *\n * The HTTP 403 Forbidden client error response status code indicates that the\n * server understood the request but refused to process it. This status is\n * similar to 401, except that for 403 Forbidden responses, authenticating or\n * re-authenticating makes no difference. The request failure is tied to\n * application logic, such as insufficient permissions to a resource or action.\n *\n * Clients that receive a 403 response should expect that repeating the request\n * without modification will fail with the same error. Server owners may decide\n * to send a 404 response instead of a 403 if acknowledging the existence of a\n * resource to clients with insufficient privileges is not desired.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/403\n */\nexport default function forbidden(body?: object | string): Response {\n\treturn response(403, body ?? \"Forbidden\");\n}\n","import response from \"./response\";\n\n/**\n * 404 Not Found\n *\n * The HTTP 404 Not Found client error response status code indicates that the\n * server cannot find the requested resource. Links that lead to a 404 page are\n * often called broken or dead links and can be subject to link rot.\n *\n * A 404 status code only indicates that the resource is missing without\n * indicating if this is temporary or permanent. If a resource is permanently\n * removed, servers should send the 410 Gone status instead.\n *\n * 404 errors on a website can lead to a poor user experience for your visitors,\n * so the number of broken links (internal and external) should be minimized to\n * prevent frustration for readers. Common causes of 404 responses are mistyped\n * URLs or pages that are moved or deleted without redirection. For more\n * information, see the Redirections in HTTP guide.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/404\n */\nexport default function notFound(body?: object | string): Response {\n\treturn response(404, body ?? \"Not found\");\n}\n","import type { Jsonify } from \"../types/Jsonify\";\nimport type TypedResponse from \"./TypedResponse\";\nimport response from \"./response\";\n\ntype OkResponse<T extends object | string | undefined> = T extends object\n\t? TypedResponse<Jsonify<T>>\n\t: Response;\n\n/**\n * 200 OK\n *\n * The HTTP 200 OK successful response status code indicates that a request has\n * succeeded. A 200 OK response is cacheable by default.\n *\n * A 200 OK response has a different meaning and format depending on the HTTP\n * request method. Here's how they vary for different methods:\n *\n * - GET: A resource was retrieved by the server and included in the response\n * body.\n * - POST: An action succeeded; the response has a message body describing the\n * result.\n * - HEAD: Identical to GET, except there is no message body.\n * - TRACE: The response has a message body containing the request as received\n * by the server.\n *\n * Although possible, successful PUT or DELETE requests often do not result in\n * a 200 OK response. It is more common to see 201 Created if the resource is\n * uploaded or created for the first time, or 204 No Content upon successful\n * deletion of a resource.\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/200\n */\nexport default function ok<T extends object | string | undefined>(body?: T): OkResponse<T> {\n\treturn response(200, body) as OkResponse<T>;\n}\n","import response from \"./response\";\nimport type { Jsonify } from \"../types/Jsonify\";\nimport type TypedResponse from \"./TypedResponse\";\n\ntype UnprocessableResponse<T extends object | string | undefined> = T extends object\n\t? TypedResponse<Jsonify<T>>\n\t: Response;\n\n/**\n * 422 Unprocessable Content\n *\n * The HTTP 422 Unprocessable Content client error response status code\n * indicates that the server understood the content type of the request content,\n * and the syntax of the request content was correct, but it was unable to\n * process the contained instructions.\n *\n * Clients that receive a 422 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/422\n */\nexport default function unprocessable<T extends object | string | undefined>(\n\tbody?: T,\n): UnprocessableResponse<T> {\n\treturn response(422, body ?? \"Unprocessable\") as UnprocessableResponse<T>;\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAwB,SAAS,QAAgB,MAAkC;CAClF,IAAI,UAA8C,KAAA;CAClD,IAAI;CACJ,IAAI;CACJ,IAAI,MAAM;EACT,IAAI,OAAO,SAAS,UAAU;GAC7B,MAAM,QAAQ,cAAc,IAAI;GAChC,eAAe;GACf,WAAW,MAAM;GACjB,UAAU,EAAE,gBAAgB,mBAAmB;GAC/C,OAAO,KAAK,UAAU,MAAM,QAAQ;EACrC,OACC,UAAU,EAAE,gBAAgB,aAAa;CAE3C;CACA,MAAM,SAAS,IAAI,SAAS,MAAM;EACjC;EACA;CACD,CAAC;CAID,IAAI,iBAAiB,KAAA,GACpB,OAAO,0BAA0B;CAElC,IAAI,YAAY,SAAS,SAAS,GACjC,OAAO,8BAA8B;CAEtC,OAAO;AACR;;;;;;;;;;;;;;;;;;;ACvBA,SAAwB,UAAU,MAAkC;CACnE,OAAO,SAAS,KAAK,QAAQ,WAAW;AACzC;;;;;;;;;;;;;;;;;;;;;;ACCA,SAAwB,SAAS,MAAkC;CAClE,OAAO,SAAS,KAAK,QAAQ,WAAW;AACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACYA,SAAwB,GAA0C,MAAyB;CAC1F,OAAO,SAAS,KAAK,IAAI;AAC1B;;;;;;;;;;;;;;;;;;;;ACZA,SAAwB,cACvB,MAC2B;CAC3B,OAAO,SAAS,KAAK,QAAQ,eAAe;AAC7C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/build",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "A framework for building sites and apps with Torpor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"author": "",
|
|
81
81
|
"license": "ISC",
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@torpor/unplugin": "^1.2.
|
|
84
|
-
"@torpor/view": "^1.
|
|
83
|
+
"@torpor/unplugin": "^1.2.14",
|
|
84
|
+
"@torpor/view": "^1.4.0",
|
|
85
85
|
"cookie": "^2.0.1",
|
|
86
86
|
"dotenv": "^18.0.8"
|
|
87
87
|
},
|
package/src/types/manifest.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type MiddlewareFunction from "../server/types/MiddlewareFunction";
|
|
2
2
|
import type ManifestRoute from "./ManifestRoute";
|
|
3
|
+
import type ModulePreloads from "./ModulePreloads";
|
|
3
4
|
|
|
4
5
|
declare const manifest: {
|
|
5
6
|
base: string;
|
|
6
7
|
viewTransitions?: boolean;
|
|
7
8
|
middleware?: MiddlewareFunction[];
|
|
8
9
|
routes: ManifestRoute[];
|
|
10
|
+
/** The client chunks each page needs (production server builds only). */
|
|
11
|
+
preloads?: ModulePreloads;
|
|
9
12
|
/** True when running under the dev server (`tb --dev`). */
|
|
10
13
|
dev?: boolean;
|
|
11
14
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MiddlewareFunction-7rIvFkjl.d.mts","names":[],"sources":["../src/server/ServerEvent.ts","../src/server/types/MiddlewareFunction.ts"],"mappings":";;cAMqB;;EACpB,SAAS;EACT,UAAU;;;;;;EAMV;EAEA,SAAS;EAET;EAEA,SAAS;EACT,SAAS;EACT,SAAS;EACT,OAAO;;MAYH,OAAO;EAIX,YAAY,SAAS,SAAS,SAAS,wBAAwB,MAAM;EAcrE;;;;EA4CA,QAAQ;;;;;;EASR,YAAY,QAAQ;;;;KCxGhB;;;;;;EAMJ,SAAS,IAAI,gBAAgB,kBAAkB,QAAQ;;;;;;;;;;EAUvD,QAAQ,IAAI,gBAAgB,kBAAkB,QAAQ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServerEvent-L0rT_mBJ.mjs","names":["COOKIE_NAME"],"sources":["../src/server/CookieHelper.ts","../src/server/FlashHelper.ts","../src/server/HeaderHelper.ts","../src/server/SessionHelper.ts","../src/server/ServerEvent.ts"],"sourcesContent":["import { type SerializeOptions, parseCookie, stringifySetCookie } from \"cookie\";\n\nexport default class CookieHelper {\n\trequest: Request;\n\tcookies: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the value from the map\n\t\tif (this.cookies.has(name)) {\n\t\t\t// The stored value is a serialized Set-Cookie header; pull the\n\t\t\t// \"name=value\" prefix off and re-parse to get just the value\n\t\t\treturn parseCookie(this.cookies.get(name)!)[name];\n\t\t}\n\n\t\t// Otherwise, return the value from the `cookie` header\n\t\tconst header = this.request.headers.get(\"Cookie\");\n\t\treturn parseCookie(header ?? \"\")[name];\n\t}\n\n\tset(name: string, value: string, options?: SerializeOptions): void {\n\t\t// Set a cookie header with some default values for security\n\t\toptions ??= {};\n\t\toptions.httpOnly ??= true;\n\t\toptions.secure ??= true;\n\t\toptions.sameSite ??= \"lax\";\n\n\t\tthis.cookies.set(name, stringifySetCookie({ name, value, ...options }));\n\t}\n\n\tdelete(name: string, options?: SerializeOptions): void {\n\t\t// Set a cookie header with an empty value and an immediate expiry date.\n\t\t// Apply the same secure defaults as `set` so a previously-set Secure\n\t\t// cookie is actually overridden by the deletion.\n\t\toptions ??= {};\n\t\toptions.httpOnly ??= true;\n\t\toptions.secure ??= true;\n\t\toptions.sameSite ??= \"lax\";\n\t\toptions.expires = new Date(0);\n\n\t\tthis.cookies.set(name, stringifySetCookie({ name, value: \"\", ...options }));\n\t}\n}\n","import CookieHelper from \"./CookieHelper\";\n\nconst COOKIE_NAME = \"torpor-flash\";\n\n/**\n * A one-time values store set in a form action and shown on the next page\n * render, which survives the redirect. Available as `event.flash`; the\n * framework reads it into `$page.flash` when a page is rendered, so\n * components display it reactively:\n *\n * ```ts\n * actions: {\n * \tsave: async (event) => {\n * \t\t// ...save...\n * \t\tevent.flash.set(\"Project saved\"); // { message: \"Project saved\" }\n * \t\tevent.flash.set({ error: \"Import failed\", retryable: true });\n * \t\treturn seeOther(`/projects/${id}`);\n * \t},\n * }\n * ```\n *\n * ```torp\n * @if ($page.flash?.message) {\n * \t<p class=\"flash\">{$page.flash.message}</p>\n * }\n * ```\n *\n * The values ride in a (session-lifetime) cookie that is deleted when it is\n * read, so a page refresh shows them once. No signing: the only person who\n * can fake a flash is the one seeing it, and values are rendered as text.\n * They must be JSON-safe and small enough to fit in the cookie (~4KB). A\n * common shape for a styled banner is `{ type, message }`, for use e.g.\n * with the Notification component -- but the framework only requires the\n * values to be an object. Without cookies the message is simply lost --\n * the action itself still completes.\n */\nexport default class FlashHelper {\n\t#cookies: CookieHelper;\n\n\tconstructor(cookies: CookieHelper) {\n\t\tthis.#cookies = cookies;\n\t}\n\n\t/**\n\t * Reads the flash values, if any, and clears them: the same response\n\t * deletes the cookie, so the message shows exactly once. (When the\n\t * message was set during this same request, e.g. a form action that\n\t * re-renders instead of redirecting, the cookie is consumed without it\n\t * ever reaching the browser.)\n\t */\n\tget(): Record<string, unknown> | undefined {\n\t\tconst cookie = this.#cookies.get(COOKIE_NAME);\n\t\tif (!cookie) return undefined;\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\n\t\ttry {\n\t\t\tconst decoded = JSON.parse(decodeURIComponent(cookie));\n\t\t\tif (typeof decoded !== \"object\" || decoded === null || Array.isArray(decoded)) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\treturn decoded as Record<string, unknown>;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Sets the flash values. A string is stored as `{ message: value }`, an\n\t * object as-is, e.g. `flash.set({ error: \"Import failed\" })`.\n\t */\n\tset(value: string | Record<string, unknown>): void {\n\t\tconst data = typeof value === \"string\" ? { message: value } : value;\n\t\tthis.#cookies.set(COOKIE_NAME, encodeURIComponent(JSON.stringify(data)), { path: \"/\" });\n\t}\n\n\t/**\n\t * Clears an unread flash message, e.g. so it isn't shown on a later\n\t * re-render of the same page.\n\t */\n\tclear(): void {\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\n\t}\n}\n","export default class HeaderHelper {\n\trequest: Request;\n\theaders: Map<string, string> = new Map();\n\n\tconstructor(request: Request) {\n\t\tthis.request = request;\n\t}\n\n\tget(name: string): string | undefined {\n\t\t// If it's been set, return the updated value\n\t\tif (this.headers.has(name)) {\n\t\t\treturn this.headers.get(name);\n\t\t}\n\t\t// Otherwise, return the value from the header\n\t\treturn this.request.headers.get(name) ?? undefined;\n\t}\n\n\tset(name: string, value: string): void {\n\t\tthis.headers.set(name, value);\n\t}\n\n\tdelete(name: string): void {\n\t\tthis.headers.delete(name);\n\t}\n}\n","import env from \"../env\";\nimport CookieHelper from \"./CookieHelper\";\n\nconst COOKIE_NAME = \"torpor-session\";\nconst DEFAULT_MAX_AGE = 30 * 24 * 60 * 60; // 30 days, in seconds\n\n/**\n * The data stored in the session. Must be JSON-safe, and small enough to\n * fit in a cookie (4KB) along with the id, expiry and signature.\n */\ntype SessionData = Record<string, unknown>;\n\ntype SessionPayload = {\n\tid: string;\n\tdata: SessionData;\n\t/** Expiry, as a Unix epoch in milliseconds */\n\texp: number;\n};\n\n// The imported signing key, cached per secret so repeated calls (per\n// request) don't re-import\nconst keys = new Map<string, Promise<CryptoKey>>();\n\n/**\n * A helper for reading and writing the signed session cookie, available as\n * `event.session` in load functions, actions, +server endpoints and hooks.\n *\n * The value is signed with HMAC-SHA256 using `TORPOR_SESSION_SECRET` from\n * the environment, so it can't be forged or tampered with -- but it is\n * still client-side storage: everything rides in the cookie, it can't be\n * revoked individually, and it is limited to ~4KB. When you need\n * revocation, store `session.id` in your database, check it on each\n * authed request (e.g. in a `_hook.server.ts`), and delete the row to\n * revoke.\n *\n * ```ts\n * // Login action\n * const user = await checkPassword(event.form());\n * await event.session.regenerate({ userId: user.id });\n *\n * // Root hook\n * const session = await event.session.get();\n * if (session) {\n * \tevent.appData.user = await getUser(session.userId);\n * }\n * ```\n */\nexport default class SessionHelper {\n\t#cookies: CookieHelper;\n\t#id: string | undefined;\n\n\tconstructor(cookies: CookieHelper) {\n\t\tthis.#cookies = cookies;\n\t}\n\n\t/**\n\t * The id embedded in the current session cookie, or undefined when\n\t * there is no valid session. Stable across `set` calls, so it can be\n\t * used as a database key; `regenerate` mints a new one.\n\t */\n\tget id(): string | undefined {\n\t\treturn this.#id;\n\t}\n\n\t/**\n\t * Reads and verifies the session, returning its data, or undefined when\n\t * there is no cookie, the signature doesn't match, or the session has\n\t * expired.\n\t */\n\tasync get(): Promise<SessionData | undefined> {\n\t\tconst value = this.#cookies.get(COOKIE_NAME);\n\t\tif (!value) return undefined;\n\t\tconst payload = await verifyValue(value);\n\t\tif (!payload) return undefined;\n\t\tthis.#id = payload.id;\n\t\treturn payload.data;\n\t}\n\n\t/**\n\t * Writes the session, signing the data and setting the cookie. Keeps\n\t * the current session id, minting one when there isn't a valid session\n\t * yet. Call `regenerate` instead when the session's identity should\n\t * change (e.g. at login, to prevent session fixation).\n\t */\n\tasync set(data: SessionData, options?: { maxAge?: number }): Promise<void> {\n\t\tconst id = this.#id ?? crypto.randomUUID();\n\t\tthis.#id = id;\n\t\tawait this.#write(id, data, options);\n\t}\n\n\t/**\n\t * Writes the session with a fresh id, replacing any existing one. Use\n\t * it when a session's privilege level changes (login, permission\n\t * upgrade), so a cookie that was set before the change can't be reused.\n\t */\n\tasync regenerate(data: SessionData = {}, options?: { maxAge?: number }): Promise<void> {\n\t\tconst id = crypto.randomUUID();\n\t\tthis.#id = id;\n\t\tawait this.#write(id, data, options);\n\t}\n\n\t/**\n\t * Deletes the session cookie. Note that a server-side record (if you\n\t * keep one) must be deleted or revoked separately.\n\t */\n\tasync destroy(): Promise<void> {\n\t\tthis.#id = undefined;\n\t\tthis.#cookies.delete(COOKIE_NAME, { path: \"/\" });\n\t}\n\n\tasync #write(\n\t\tid: string,\n\t\tdata: SessionData,\n\t\toptions: { maxAge?: number } | undefined,\n\t): Promise<void> {\n\t\tconst maxAge = options?.maxAge ?? DEFAULT_MAX_AGE;\n\t\tconst payload: SessionPayload = { id, data, exp: Date.now() + maxAge * 1000 };\n\t\tconst encoded = encodeBase64Url(new TextEncoder().encode(JSON.stringify(payload)));\n\t\tconst signature = await sign(encoded);\n\t\tthis.#cookies.set(COOKIE_NAME, `${encoded}.${signature}`, { path: \"/\", maxAge });\n\t}\n}\n\nfunction secret(): string {\n\tconst value = env().TORPOR_SESSION_SECRET;\n\tif (!value) {\n\t\tthrow new Error(\n\t\t\t\"TORPOR_SESSION_SECRET is not set. Add it to the environment (or to a .env \" +\n\t\t\t\t\"file in dev and preview) to use sessions.\",\n\t\t);\n\t}\n\treturn value;\n}\n\nfunction signingKey(): Promise<CryptoKey> {\n\tconst value = secret();\n\tlet key = keys.get(value);\n\tif (!key) {\n\t\tkey = crypto.subtle.importKey(\n\t\t\t\"raw\",\n\t\t\tnew TextEncoder().encode(value),\n\t\t\t{ name: \"HMAC\", hash: \"SHA-256\" },\n\t\t\tfalse,\n\t\t\t[\"sign\", \"verify\"],\n\t\t);\n\t\tkeys.set(value, key);\n\t}\n\treturn key;\n}\n\nasync function sign(payload: string): Promise<string> {\n\tconst signature = await crypto.subtle.sign(\n\t\t\"HMAC\",\n\t\tawait signingKey(),\n\t\tnew TextEncoder().encode(payload),\n\t);\n\treturn encodeBase64Url(new Uint8Array(signature));\n}\n\nasync function verifyValue(value: string): Promise<SessionPayload | undefined> {\n\tconst dot = value.lastIndexOf(\".\");\n\tif (dot === -1) return undefined;\n\tconst encoded = value.slice(0, dot);\n\tconst valid = await crypto.subtle.verify(\n\t\t\"HMAC\",\n\t\tawait signingKey(),\n\t\tdecodeBase64Url(value.slice(dot + 1)),\n\t\tnew TextEncoder().encode(encoded),\n\t);\n\tif (!valid) return undefined;\n\n\tlet payload: SessionPayload;\n\ttry {\n\t\tpayload = JSON.parse(new TextDecoder().decode(decodeBase64Url(encoded)));\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (\n\t\ttypeof payload?.id !== \"string\" ||\n\t\ttypeof payload?.exp !== \"number\" ||\n\t\ttypeof payload?.data !== \"object\" ||\n\t\tpayload.data === null ||\n\t\tpayload.exp < Date.now()\n\t) {\n\t\treturn undefined;\n\t}\n\treturn payload;\n}\n\nfunction encodeBase64Url(bytes: Uint8Array): string {\n\t// btoa can't take raw bytes, and long argument lists overflow, so\n\t// convert in chunks\n\tlet binary = \"\";\n\tfor (let i = 0; i < bytes.length; i += 0x1000) {\n\t\tbinary += String.fromCharCode(...bytes.subarray(i, i + 0x1000));\n\t}\n\treturn btoa(binary).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replaceAll(\"=\", \"\");\n}\n\nfunction decodeBase64Url(value: string): Uint8Array<ArrayBuffer> {\n\tconst binary = atob(value.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\"));\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) {\n\t\tbytes[i] = binary.charCodeAt(i);\n\t}\n\treturn bytes;\n}\n","import { addBaseToPath, getBasePath } from \"../site/basePath\";\nimport CookieHelper from \"./CookieHelper\";\nimport FlashHelper from \"./FlashHelper\";\nimport HeaderHelper from \"./HeaderHelper\";\nimport SessionHelper from \"./SessionHelper\";\n\nexport default class ServerEvent {\n\trequest: Request;\n\tresponse: Response | undefined | void;\n\t/**\n\t * Set when the route handler (or a middleware enter hook) threw an\n\t * error. Exit hooks can return a Response to handle it; if none does,\n\t * the error is rethrown to the caller.\n\t */\n\terror: unknown;\n\t// TODO: Should we cast types??\n\tparams?: Record<string, string>;\n\n\tadapter: any;\n\n\tcookies: CookieHelper;\n\theaders: HeaderHelper;\n\tsession: SessionHelper;\n\tflash: FlashHelper;\n\n\t// Parsed once per request; Server.fetch passes the URL it already needed\n\t// for matching so it isn't parsed twice\n\t#url: URL | undefined;\n\n\t// The request's form body, parsed at most once per request: the schema\n\t// validation and the event's `form()`/`formData()` accessors share a\n\t// single read, since a request body can't be read twice\n\t#formData: Promise<FormData> | undefined;\n\n\t/** The request URL, parsed lazily. */\n\tget url(): URL {\n\t\treturn (this.#url ??= new URL(this.request.url));\n\t}\n\n\tconstructor(request: Request, params?: Record<string, string>, url?: URL) {\n\t\tthis.request = request;\n\t\tthis.params = params;\n\t\tthis.#url = url;\n\t\tthis.cookies = new CookieHelper(request);\n\t\tthis.headers = new HeaderHelper(request);\n\t\tthis.session = new SessionHelper(this.cookies);\n\t\tthis.flash = new FlashHelper(this.cookies);\n\n\t\t// Adapters may have added the `adapter` property to globalThis\n\t\t// @ts-ignore\n\t\tthis.adapter = globalThis.adapter;\n\t}\n\n\taddHeaders(): void {\n\t\tif (!this.response) {\n\t\t\tthrow new Error(\"Response not created yet\");\n\t\t}\n\n\t\ttry {\n\t\t\tthis.#addHeaders();\n\t\t} catch (e) {\n\t\t\t// The headers of a Response obtained from `fetch()` are immutable,\n\t\t\t// so an endpoint that returns a fetched Response directly would\n\t\t\t// otherwise kill the whole request (and process) -- swap in a\n\t\t\t// mutable clone and write the headers to that instead\n\t\t\tif (!(e instanceof TypeError)) throw e;\n\t\t\tthis.response = new Response(this.response.body, this.response);\n\t\t\tthis.#addHeaders();\n\t\t}\n\t}\n\n\t#addHeaders(): void {\n\t\tfor (let cookie of this.cookies.cookies.values()) {\n\t\t\tthis.response!.headers.append(\"set-cookie\", cookie);\n\t\t}\n\n\t\tfor (let header of this.headers.headers.entries()) {\n\t\t\tthis.response!.headers.append(header[0], header[1]);\n\t\t}\n\n\t\t// Redirect locations are written base-free, so that user code isn't\n\t\t// aware of the base path\n\t\tconst base = getBasePath();\n\t\tif (base) {\n\t\t\tconst location = this.response!.headers.get(\"Location\");\n\t\t\tif (location) {\n\t\t\t\tconst rewritten = addBaseToPath(location, base);\n\t\t\t\tif (rewritten !== location) {\n\t\t\t\t\tthis.response!.headers.set(\"Location\", rewritten);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Reads the request body as JSON.\n\t */\n\tjson(): Promise<unknown> {\n\t\treturn this.request.json();\n\t}\n\n\t/**\n\t * Reads the request body as the web standard FormData object. The body is\n\t * parsed at most once per request, so that everything that reads the form\n\t * (schema validation, `event.form()`, `event.formData()`) shares the read.\n\t */\n\tformData(): Promise<FormData> {\n\t\treturn (this.#formData ??= this.request.formData());\n\t}\n}\n"],"mappings":";;;;AAEA,IAAqB,eAArB,MAAkC;CACjC;CACA,0BAA+B,IAAI,IAAI;CAEvC,YAAY,SAAkB;EAC7B,KAAK,UAAU;CAChB;CAEA,IAAI,MAAkC;EAErC,IAAI,KAAK,QAAQ,IAAI,IAAI,GAGxB,OAAO,YAAY,KAAK,QAAQ,IAAI,IAAI,CAAE,CAAC,CAAC;EAI7C,MAAM,SAAS,KAAK,QAAQ,QAAQ,IAAI,QAAQ;EAChD,OAAO,YAAY,UAAU,EAAE,CAAC,CAAC;CAClC;CAEA,IAAI,MAAc,OAAe,SAAkC;EAElE,YAAY,CAAC;EACb,QAAQ,aAAa;EACrB,QAAQ,WAAW;EACnB,QAAQ,aAAa;EAErB,KAAK,QAAQ,IAAI,MAAM,mBAAmB;GAAE;GAAM;GAAO,GAAG;EAAQ,CAAC,CAAC;CACvE;CAEA,OAAO,MAAc,SAAkC;EAItD,YAAY,CAAC;EACb,QAAQ,aAAa;EACrB,QAAQ,WAAW;EACnB,QAAQ,aAAa;EACrB,QAAQ,0BAAU,IAAI,KAAK,CAAC;EAE5B,KAAK,QAAQ,IAAI,MAAM,mBAAmB;GAAE;GAAM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SAAU,QAAQ,OAAO,cAAc,MAAM;EAGnD,KAAK,IAAI,UAAU,KAAK,QAAQ,QAAQ,QAAQ,GAC/C,KAAK,SAAU,QAAQ,OAAO,OAAO,IAAI,OAAO,EAAE;EAKnD,MAAM,OAAO,YAAY;EACzB,IAAI,MAAM;GACT,MAAM,WAAW,KAAK,SAAU,QAAQ,IAAI,UAAU;GACtD,IAAI,UAAU;IACb,MAAM,YAAY,cAAc,UAAU,IAAI;IAC9C,IAAI,cAAc,UACjB,KAAK,SAAU,QAAQ,IAAI,YAAY,SAAS;GAElD;EACD;CACD;;;;CAKA,OAAyB;EACxB,OAAO,KAAK,QAAQ,KAAK;CAC1B;;;;;;CAOA,WAA8B;EAC7B,OAAQ,KAAK,cAAc,KAAK,QAAQ,SAAS;CAClD;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ServerLoadEvent-F60w1TZt.d.mts","names":[],"sources":["../src/types/ServerLoadEvent.ts"],"mappings":";;;;;;;KAUY,iBAAiB,eAAe,qBAAqB;;;;;KAMrD,cAAc;;;;;;;;UASD,gBACxB,8CACA,gBACA,WAAW,gBACX,YAAY,aACZ,SAAS,cAAc;;;;EAKvB,KAAK;;;;;;EAML,QAAQ;;;;;EAOR,SAAS;;;;EAIT,SAAS;;;;EAKT,YAAY,QAAQ;;;;;;;;;EASpB,YAAY,QAAQ;;;;;;;EAOpB,gBAAgB,QAAQ;;;;;;;EAOxB,aAAa,QAAQ;;;;EAIrB,SAAS;;;;;EAKT,SAAS;;;;;EAKT,OAAO;;;;EAIP,SAAS;;;;EAIT,SAAS,OAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SessionHelper-MaodMaLU.d.mts","names":[],"sources":["../src/server/CookieHelper.ts","../src/server/FlashHelper.ts","../src/server/HeaderHelper.ts","../src/server/SessionHelper.ts"],"mappings":";;cAEqB;EACpB,SAAS;EACT,SAAS;EAET,YAAY,SAAS;EAIrB,IAAI;EAaJ,IAAI,cAAc,eAAe,UAAU;EAU3C,OAAO,cAAc,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCGX;;EAGpB,YAAY,SAAS;;;;;;;;EAWrB,OAAO;;;;;EAmBP,IAAI,gBAAgB;;;;;EASpB;;;;cC9EoB;EACpB,SAAS;EACT,SAAS;EAET,YAAY,SAAS;EAIrB,IAAI;EASJ,IAAI,cAAc;EAIlB,OAAO;;;;;;;;KCXH,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;cAqCE;;EAIpB,YAAY,SAAS;;;;;;MASjB;;;;;;EASJ,OAAa,QAAQ;;;;;;;EAerB,IAAU,MAAM,aAAa;IAAY;MAAoB;;;;;;EAW7D,WAAiB,OAAM,aAAkB;IAAY;MAAoB;;;;;EAUzE,WAAiB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Site-CAeAqjkk.d.mts","names":[],"sources":["../src/types/Adapter.ts","../src/types/SitePlugin.ts","../src/types/PageServerAction.ts","../src/types/PageServerLoad.ts","../src/types/PageServerEndPoint.ts","../src/openapi/types.ts","../src/types/ServerRequest.ts","../src/types/ServerEndPoint.ts","../src/types/RouteType.ts","../src/types/Route.ts","../src/site/Site.ts"],"mappings":";;;;;;;;;UAIyB;EACxB,YAAY,MAAM,SAAS;EAC3B,aAAa,MAAM,SAAS;;;;;;;EAO5B,OAAO,MAAM,SAAS,SAAS;;;;;EAK/B,QAAQ,QAAQ,QAAQ,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;KCG1C,cAAc,MAAM,gBAAgB;;;KCjBpC,iBACJ,8CACA,WAAW,gBACX,SAAS,cAAc,WAEvB,OAAO,gBAAgB,gBAAgB,UAAU,aAAa,YAC1D,8BAA8B,QAAQ;;;KCLtC,eACJ,8CACA,OAAO,qBACP,YAAY,aACZ,SAAS,cAAc,WAEvB,OAAO,gBAAgB,gBAAgB,gBAAgB,WAAW,YAC9D,eAAe,QAAQ,QAAQ,e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D;EACxB;;;;;EAKA;;;;;;EAMA,WAAW;EACX,MAAM;EACN;;;;;;;;cCOoB;;EACpB;;;;;;;;;;EAUA;EACA,QAAQ;;;;;;EAMR;IAAgB;IAAgB;;;;;;;;EAOhC,SAAS;;;;EAIT,aAAa;;;;;;;;;;EAUb,SAAS;;;;;;EAMT;;;;;;;EAOA,aAAa;;;;;EAKb;;;;;;;;;;;;;;;;EAgBA,aAAa,IAAI;;;;;;;EAOjB;;;;;;;EAOA;;;;;;;;;EASA,sBAAsB;;;;;;EAMtB;;;;;;;;;;;;EAYA,YAAY;;;;;;;;;;;EAWZ,UAAU;;;;;;;;;EASV,MAAM,0BAA0B;;;;;EAKhC,iBAAiB,eAAe;EAEhC;;MAKI;;;;;;;;;EAYJ,eAAqB,gBAAgB,qBAAqB;;;;;;;;;;;;EA0C1D,gBAAgB,OAAO;;;;;;;;EAwBvB,aACC,cACA,cACA,kHASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+HD,SACC,cACA;IACC;IACA,sBAAsB;IACtB,kBAAkB;IAClB;IACA,wBAAwB;IACxB,sBAAsB;IACtB;KAED"}
|
package/dist/_page-CW6SLuT4.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { $watch } from "@torpor/view";
|
|
2
|
-
//#region src/state/$page.ts
|
|
3
|
-
const PAGE_SYMBOL = Symbol.for("torp.Page");
|
|
4
|
-
const $page = globalThis[PAGE_SYMBOL] ??= $watch({
|
|
5
|
-
status: 404,
|
|
6
|
-
url: new URL("http://localhost"),
|
|
7
|
-
form: void 0,
|
|
8
|
-
flash: void 0,
|
|
9
|
-
error: { message: "" }
|
|
10
|
-
}, { shallow: true });
|
|
11
|
-
//#endregion
|
|
12
|
-
export { $page as t };
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=_page-CW6SLuT4.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_page-CW6SLuT4.mjs","names":[],"sources":["../src/state/$page.ts"],"sourcesContent":["import { $watch } from \"@torpor/view\";\nimport type PageState from \"../types/PageState\";\n\nconst PAGE_SYMBOL: unique symbol = Symbol.for(\"torp.Page\");\n\nconst $page: PageState =\n\t// @ts-ignore\n\t(globalThis[PAGE_SYMBOL] ??=\n\t\t// The server request path uses `state/$serverPage`, which stores the\n\t\t// same state (same `globalThis` slot) without a reactive proxy\n\t\t$watch(\n\t\t\t{\n\t\t\t\tstatus: 404,\n\t\t\t\turl: new URL(\"http://localhost\"),\n\t\t\t\tform: undefined,\n\t\t\t\tflash: undefined,\n\t\t\t\terror: {\n\t\t\t\t\tmessage: \"\",\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tshallow: true,\n\t\t\t},\n\t\t));\n\nexport default $page;\n"],"mappings":";;AAGA,MAAM,cAA6B,OAAO,IAAI,WAAW;AAEzD,MAAM,QAEJ,WAAW,iBAGX,OACC;CACC,QAAQ;CACR,KAAK,IAAI,IAAI,kBAAkB;CAC/B,MAAM,KAAA;CACN,OAAO,KAAA;CACP,OAAO,EACN,SAAS,GACV;AACD,GACA,EACC,SAAS,KACV,CACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"basePath-DQnbHc7o.mjs","names":[],"sources":["../src/site/basePath.ts"],"sourcesContent":["/**\n * The site's base path, e.g. \"/app\" when the site is mounted under a\n * subpath. Inherited from `site.basePath` through the manifest at startup\n * (see serverEntry and clientEntry); default \"\" when the site is served\n * from the root.\n *\n * Server code and user markup are written base-free: the server strips the\n * base from incoming URLs before routing (requests that don't carry it get\n * a 404), and adds it back to generated HTML attributes, redirect\n * locations and paths built with `route()`. The client router does the\n * mirror image: strips for matching, adds for data fetches.\n */\nlet basePath = \"\";\n\n/**\n * Validates and sets the site's base path: must be \"\", start with \"/\" and\n * not end with \"/\" (a trailing slash is stripped, \"/\" is normalized to \"\")\n */\nexport function setBasePath(value: string | undefined): void {\n\tbasePath = normalizeBasePath(value);\n}\n\nexport function getBasePath(): string {\n\treturn basePath;\n}\n\n/**\n * Normalizes a base path value, throwing a descriptive error when it\n * can't be one. Trailing slashes are stripped and \"/\" is normalized to \"\".\n */\nexport function normalizeBasePath(value: string | undefined): string {\n\tconst trimmed = (value ?? \"\").trim();\n\tif (trimmed === \"\" || trimmed === \"/\") return \"\";\n\tif (!trimmed.startsWith(\"/\") || /\\s/.test(trimmed)) {\n\t\tthrow new Error(\n\t\t\t`The base path must be an absolute path without spaces (e.g. \"/app\"), ` + `got \"${value}\"`,\n\t\t);\n\t}\n\treturn trimmed.replace(/\\/+$/, \"\");\n}\n\n/**\n * Normalizes a site origin value, throwing a descriptive error when it\n * isn't an absolute http(s) origin without a path or spaces.\n */\nexport function normalizeOrigin(value: string | undefined): string {\n\tconst trimmed = (value ?? \"\").trim();\n\tif (trimmed === \"\") {\n\t\tthrow new Error(`The site origin is empty (e.g. \"https://example.com\")`);\n\t}\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(trimmed);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t`The site origin must be an absolute url (e.g. \"https://example.com\"), got \"${value}\"`,\n\t\t);\n\t}\n\tif (\n\t\t(url.protocol !== \"https:\" && url.protocol !== \"http:\") ||\n\t\turl.pathname !== \"/\" ||\n\t\t/\\s/.test(trimmed)\n\t) {\n\t\tthrow new Error(\n\t\t\t`The site origin must be an http(s) url without spaces or a path ` +\n\t\t\t\t`(e.g. \"https://example.com\"), got \"${value}\"`,\n\t\t);\n\t}\n\t// A trailing slash is allowed\n\treturn url.origin;\n}\n\n/**\n * Strips the base from a URL's pathname, copying the URL so it can be used\n * for routing without disturbing the request. Returns undefined when there\n * is a base and the URL doesn't carry it -- the caller should then return\n * a not-found response, since the site only serves requests under its\n * mount point.\n */\nexport function stripBaseFromUrl(url: URL, base: string): URL | undefined {\n\tconst stripped = new URL(url);\n\tif (!base) return stripped;\n\tif (stripped.pathname === base) {\n\t\tstripped.pathname = \"/\";\n\t\treturn stripped;\n\t}\n\tif (stripped.pathname.startsWith(base + \"/\")) {\n\t\tstripped.pathname = stripped.pathname.slice(base.length) || \"/\";\n\t\treturn stripped;\n\t}\n\treturn undefined;\n}\n\n/**\n * Adds the base to an absolute path, idempotent for paths that already\n * carry it. Relative paths (\"other/page\"), protocol-relative (\"//...\") and\n * full URLs are left alone.\n */\nexport function addBaseToPath(path: string, base: string): string {\n\tif (!base || !path.startsWith(\"/\") || path.startsWith(\"//\")) return path;\n\tif (path === \"/\") return base + \"/\";\n\tif (path === base || path.startsWith(base + \"/\")) return path;\n\treturn base + path;\n}\n\n/**\n * Rewrites absolute-path `href`, `action` and `src` attribute values in\n * rendered HTML, so that markup can be written base-free. Values that\n * aren't absolute paths (relative, \"//...\", \"http://...\", \"mailto:...\")\n * are left alone, as are ones that already carry the base.\n */\nexport function rewriteBaseInHtml(html: string, base: string): string {\n\tif (!base) return html;\n\treturn html.replace(\n\t\t/\\s(href|action|src)\\s*=\\s*(\"([^\"]*)\"|'([^']*)')/g,\n\t\t(match, name: string, _quoted: string, double: string, single: string) => {\n\t\t\tconst value = double ?? single ?? \"\";\n\t\t\tconst rewritten = addBaseToPath(value, base);\n\t\t\tif (rewritten === value) return match;\n\t\t\treturn ` ${name}=\"${rewritten}\"`;\n\t\t},\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,IAAI,WAAW;;;;;AAMf,SAAgB,YAAY,OAAiC;CAC5D,WAAW,kBAAkB,KAAK;AACnC;AAEA,SAAgB,cAAsB;CACrC,OAAO;AACR;;;;;AAMA,SAAgB,kBAAkB,OAAmC;CACpE,MAAM,WAAW,SAAS,GAAA,CAAI,KAAK;CACnC,IAAI,YAAY,MAAM,YAAY,KAAK,OAAO;CAC9C,IAAI,CAAC,QAAQ,WAAW,GAAG,KAAK,KAAK,KAAK,OAAO,GAChD,MAAM,IAAI,MACT,6EAAkF,MAAM,EACzF;CAED,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AAClC;;;;;AAMA,SAAgB,gBA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