brumate 0.3.0 → 0.4.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 +2 -2
- package/check.d.ts +49 -0
- package/dist/{boot-C25Sa6vq.d.ts → boot-DLlRmD9z.d.ts} +8 -10
- package/dist/cli.js +275 -15
- package/dist/cli.js.map +1 -1
- package/dist/client-BvDsC6Qr.js +3463 -0
- package/dist/client-BvDsC6Qr.js.map +1 -0
- package/dist/{client-D0CqSxoO.d.ts → client-DBwL2wKQ.d.ts} +390 -181
- package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
- package/dist/client-routes-BtGpYCef.js.map +1 -0
- package/dist/{cookies-BzllthiF.js → cookies-Cnbf4w-S.js} +14 -7
- package/dist/cookies-Cnbf4w-S.js.map +1 -0
- package/dist/{defer-BbD7JQhj.js → defer-CKWZLv2K.js} +4 -4
- package/dist/defer-CKWZLv2K.js.map +1 -0
- package/dist/{devtools-CQgD7NPB.js → devtools-4uTPwR_v.js} +56 -82
- package/dist/devtools-4uTPwR_v.js.map +1 -0
- package/dist/{devtools-panel-BVB-W5q4.js → devtools-panel-Be9pxYgv.js} +397 -333
- package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
- package/dist/{events-CSs7OwIC.js → events-LgLdp1R7.js} +34 -5
- package/dist/events-LgLdp1R7.js.map +1 -0
- package/dist/features-CHY5Ekku.js +30 -0
- package/dist/features-CHY5Ekku.js.map +1 -0
- package/dist/files-WW4RlajL.js +506 -0
- package/dist/files-WW4RlajL.js.map +1 -0
- package/dist/{forms-Cl21hkHt.d.ts → forms-j1xPAR14.d.ts} +3 -3
- package/dist/{forms-Bg-CwGqX.js → forms-nXK7-Lv_.js} +78 -44
- package/dist/forms-nXK7-Lv_.js.map +1 -0
- package/dist/highlight.js +31 -22
- package/dist/highlight.js.map +1 -1
- package/dist/{html-mNTKzaDD.js → html-BtKRyi7g.js} +86 -22
- package/dist/html-BtKRyi7g.js.map +1 -0
- package/dist/{html-Bq1rFxX_.d.ts → html-Bw9Qwu6F.d.ts} +20 -5
- package/dist/index.d.ts +96 -10
- package/dist/index.js +639 -104
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BHpOw1LF.js → inspect-Y6y4uNZp.js} +3751 -676
- package/dist/inspect-Y6y4uNZp.js.map +1 -0
- package/dist/{loader-Dos_3NP0.js → loader-BjKGJzLN.js} +20 -14
- package/dist/loader-BjKGJzLN.js.map +1 -0
- package/dist/logo-DQ_OYhBi.js +10 -0
- package/dist/logo-DQ_OYhBi.js.map +1 -0
- package/dist/{navigate-O78d_zGN.js → navigate-CfOr-TRF.js} +94 -31
- package/dist/navigate-CfOr-TRF.js.map +1 -0
- package/dist/nesting-DA5vJw9X.js +265 -0
- package/dist/nesting-DA5vJw9X.js.map +1 -0
- package/dist/{produce-Doc91GkX.js → produce-B7X9ori9.js} +137 -9
- package/dist/produce-B7X9ori9.js.map +1 -0
- package/dist/{produce-D0V0ICkz.d.ts → produce-DIgHBVwL.d.ts} +39 -5
- package/dist/{rpc-ygMRPmN4.js → rpc-Q-XkLwFh.js} +11 -6
- package/dist/rpc-Q-XkLwFh.js.map +1 -0
- package/dist/runtime/batch.js +9 -7
- package/dist/runtime/batch.js.map +1 -1
- package/dist/runtime/client.d.ts +4 -4
- package/dist/runtime/client.js +4 -4
- package/dist/runtime/devtools.d.ts +11 -29
- package/dist/runtime/devtools.js +3 -1
- package/dist/runtime/env.js +14 -2
- package/dist/runtime/env.js.map +1 -1
- package/dist/runtime/events.d.ts +23 -1
- package/dist/runtime/events.js +1 -1
- package/dist/runtime/forms.d.ts +2 -2
- package/dist/runtime/forms.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +5 -2
- package/dist/runtime/hot.js.map +1 -1
- package/dist/runtime/html.d.ts +2 -2
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/routes.js +4 -1
- package/dist/runtime/routes.js.map +1 -1
- package/dist/runtime/server.d.ts +5 -5
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +38 -1
- package/dist/runtime/signals.js +33 -1
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.d.ts +18 -3
- package/dist/runtime/testing.js +150 -33
- package/dist/runtime/testing.js.map +1 -1
- package/dist/{server-DuFYRXrd.d.ts → server-BvPIg9pT.d.ts} +84 -22
- package/dist/{server-CxVDYE_V.js → server-DjyOVJtJ.js} +598 -164
- package/dist/server-DjyOVJtJ.js.map +1 -0
- package/dist/{static-loader-Drpr0AzI.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
- package/dist/{static-loader-nZssh66R.js → static-loader-BZR17hSw.js} +78 -99
- package/dist/static-loader-BZR17hSw.js.map +1 -0
- package/dist/{stream-DCYZO4IF.js → stream-BP5AVmg5.js} +102 -16
- package/dist/stream-BP5AVmg5.js.map +1 -0
- package/dist/vite.d.ts +13 -20
- package/dist/vite.js +1890 -548
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +951 -0
- package/forms/forms.brm.ts +3 -3
- package/package.json +12 -3
- package/skills/brumate/SKILL.md +58 -0
- package/skills/brumate/references/errors.md +2078 -0
- package/skills/brumate/references/events.md +117 -0
- package/skills/brumate/references/signals.md +61 -0
- package/skills/brumate/references/state.md +235 -0
- package/skills/brumate/references/syntax.md +250 -0
- package/types.d.ts +4 -4
- package/dist/client-BD6XT-s5.js +0 -1968
- package/dist/client-BD6XT-s5.js.map +0 -1
- package/dist/client-routes-JTbGtukf.js.map +0 -1
- package/dist/cookies-BzllthiF.js.map +0 -1
- package/dist/defer-BbD7JQhj.js.map +0 -1
- package/dist/devtools-CQgD7NPB.js.map +0 -1
- package/dist/devtools-panel-BVB-W5q4.js.map +0 -1
- package/dist/events-CSs7OwIC.js.map +0 -1
- package/dist/files-BXSSrQgc.js +0 -205
- package/dist/files-BXSSrQgc.js.map +0 -1
- package/dist/forms-Bg-CwGqX.js.map +0 -1
- package/dist/html-mNTKzaDD.js.map +0 -1
- package/dist/inspect-BHpOw1LF.js.map +0 -1
- package/dist/loader-Dos_3NP0.js.map +0 -1
- package/dist/navigate-O78d_zGN.js.map +0 -1
- package/dist/produce-Doc91GkX.js.map +0 -1
- package/dist/rpc-ygMRPmN4.js.map +0 -1
- package/dist/server-CxVDYE_V.js.map +0 -1
- package/dist/static-loader-nZssh66R.js.map +0 -1
- package/dist/stream-DCYZO4IF.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","names":[],"sources":["../../src/runtime/nodes.ts","../../src/runtime/testing.ts"],"sourcesContent":["// Finds where whole nodes end in markup that arrives in pieces.\n\nconst VOID = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'source',\n 'track',\n 'wbr',\n]);\n\n/**\n * The end of the last whole node at the top level of markup that streams in,\n * so a chunk that ends inside a tag, the text of a script or a template\n * waits for the rest. A `>` in an attribute or a script does not end a node.\n */\nexport function wholeNodes(markup: string): number {\n const tag = /<(\\/?)([a-zA-Z][\\w-]*)(?:[^>\"']|\"[^\"]*\"|'[^']*')*>/g;\n const lower = markup.toLowerCase();\n let depth = 0;\n let end = 0;\n let match: RegExpExecArray | null;\n while ((match = tag.exec(markup))) {\n const [whole, closing, name] = match;\n const element = name!.toLowerCase();\n if (!closing && element === 'script') {\n // The text of a script is not markup, and ends only at `</script`.\n const close = lower.indexOf('</script', tag.lastIndex);\n const after = close < 0 ? -1 : markup.indexOf('>', close);\n if (after < 0) {\n return end;\n }\n tag.lastIndex = after + 1;\n } else if (!VOID.has(element) && !whole.endsWith('/>')) {\n depth += closing ? -1 : 1;\n }\n if (depth === 0) {\n end = tag.lastIndex;\n }\n }\n return end;\n}\n","// Renders a component on the server and resumes it in the DOM of a test, as\n// a page does: the HTML and the state first, then the loader, which loads\n// client code when an event fires. `visit` does the same for a route, with\n// the requests of the page answered by the routes of the app.\n\nimport type { ClientModule } from './client.ts';\nimport { start } from './loader.ts';\nimport { wholeNodes } from './nodes.ts';\nimport { handleRequest, render } from './server.ts';\nimport type { Component, EntryMiddleware, RenderOptions } from './server.ts';\n\n/** The middleware of files of server functions, by function ID. */\ntype FileMiddleware = Record<string, EntryMiddleware>;\n\nexport interface TestingOptions {\n /** Imports the client module of a component, by component ID. */\n load: (id: string) => Promise<ClientModule>;\n /** The URL prefix of server function calls. */\n rpc?: string;\n}\n\n/** What a test does with the page, as a user does. */\nexport interface Actions {\n /** The first element that matches a selector. Throws if none does. */\n get: (selector: string) => HTMLElement;\n /** The text of the first element that matches a selector. */\n text: (selector: string) => string;\n /** Clicks an element. */\n click: (selector: string) => void;\n /** Types a value into a field, and fires `input`. */\n input: (selector: string, value: string) => void;\n /** Submits a form, as its submit button does. */\n submit: (selector: string) => void;\n /**\n * Retries an assertion until it passes. The first event of a test loads\n * client code, so its effects arrive a moment later.\n */\n waitFor: (assertion: () => void, timeout?: number) => Promise<void>;\n}\n\nexport interface Mounted extends Actions {\n /** The element that holds the component. */\n container: HTMLElement;\n /** Stops the loader and removes the component. */\n unmount: () => void;\n}\n\n/** The actions on the elements inside `root`. */\nfunction actions(root: ParentNode): Actions {\n const get = (selector: string): HTMLElement => {\n const element = root.querySelector<HTMLElement>(selector);\n if (!element) {\n throw new Error(`No element matches ${selector}`);\n }\n return element;\n };\n return {\n get,\n text: (selector) => get(selector).textContent ?? '',\n click: (selector) => get(selector).click(),\n input: (selector, value) => {\n const field = get(selector) as HTMLInputElement;\n field.value = value;\n field.dispatchEvent(new Event('input', { bubbles: true }));\n },\n submit: (selector) => {\n get(selector).dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));\n },\n waitFor: async (assertion, timeout = 2000) => {\n const until = Date.now() + timeout;\n for (;;) {\n try {\n assertion();\n return;\n } catch (error) {\n if (Date.now() > until) {\n throw error;\n }\n // oxlint-disable-next-line no-await-in-loop -- It waits between tries.\n await new Promise((resolve) => setTimeout(resolve, 10));\n }\n }\n },\n };\n}\n\n/**\n * Runs an inline script, as a browser does when it adds one. The DOM of a\n * test does not run scripts. The script is `document.currentScript` while it\n * runs, so a state record hands its script to the core.\n */\nfunction run(script: Element): void {\n Object.defineProperty(document, 'currentScript', { configurable: true, value: script });\n try {\n // oxlint-disable-next-line no-eval -- The script is a state record or the swap code from the server.\n (0, eval)(script.textContent!);\n } finally {\n delete (document as { currentScript?: unknown }).currentScript;\n }\n}\n\n/**\n * Appends markup that streams in later, such as a `#loading` body, and runs\n * its inline scripts in order.\n */\nfunction append(container: HTMLElement, html: string): void {\n const template = document.createElement('template');\n template.innerHTML = html;\n // A copy, because appending moves nodes out of the live list.\n // oxlint-disable-next-line unicorn/no-useless-spread\n for (const node of [...template.content.childNodes]) {\n container.append(node);\n if (node.nodeName === 'SCRIPT' && !(node as Element).hasAttribute('type')) {\n run(node as Element);\n }\n }\n}\n\n/** Renders a component on the server and resumes it in the document of a test. */\nexport type Mount = <P>(\n component: Component<P>,\n props: P,\n renderOptions?: RenderOptions,\n) => Promise<Mounted>;\n\n/** Mounts so far, so each starts its scope IDs at a number of its own. */\nlet mounts = 0;\n/** The loader that the mounts of the document share, and how many mounts use it. */\nlet loader: { stop: () => void; users: number } | undefined;\n\n/** Returns `mount`, which loads client modules with `options.load`. */\nexport function createMount(options: TestingOptions): Mount {\n /**\n * Renders a component on the server, puts it in the document with its\n * state, and starts the loader. Markup that streams in later is added as\n * it arrives.\n */\n return async function mount<P>(\n component: Component<P>,\n props: P,\n renderOptions: RenderOptions = {},\n ): Promise<Mounted> {\n // IDs of their own, so two mounts in a file do not share scopes or state references.\n const base = renderOptions.base ?? ++mounts * 1_000_000;\n const { html, state, pending } = await render(component, props, { ...renderOptions, base });\n const container = document.createElement('div');\n container.innerHTML = html + state;\n document.body.append(container);\n // The page state, which waits for the core.\n container.querySelectorAll('script[b-state]').forEach(run);\n // One loader for the document, as a page has, however many mounts are in it.\n loader ??= {\n stop: start({ load: options.load, rpc: options.rpc, navigate: false, preload: false }),\n users: 0,\n };\n loader.users++;\n let mounted = true;\n const stop = (): void => {\n if (!mounted || !loader) {\n return;\n }\n mounted = false;\n if (--loader.users === 0) {\n loader.stop();\n loader = undefined;\n }\n };\n void (async () => {\n for await (const chunk of pending) {\n append(container, chunk);\n }\n })();\n return {\n container,\n ...actions(container),\n unmount: () => {\n stop();\n container.remove();\n // The core forgets the scopes of this mount, so a refresh later does not load its memos.\n void import('./client.ts').then((core) => core.removeRoot(String(base)));\n },\n };\n };\n}\n\n/** Server functions by ID, as `functions` of `virtual:brumate/server` has them. */\n// oxlint-disable-next-line typescript/no-explicit-any -- Server functions take any arguments.\nexport type ServerFunctions = Record<string, (...args: any[]) => unknown>;\n\nexport interface AnswerOptions {\n /** The URL prefix of server function calls. Defaults to `/_brumate`. */\n rpc?: string;\n /** Called with the ID of each call, such as `issues_1a2b#toggleStar`, before it runs. */\n onCall?: (id: string) => void;\n /** The middleware of the entry, which runs before each call. `virtual:brumate/testing` passes the app's. */\n middleware?: EntryMiddleware;\n /**\n * The middleware of each `'use server'` file, by function ID, or a\n * function that imports them. `virtual:brumate/testing` passes them.\n */\n fileMiddleware?: FileMiddleware | (() => Promise<FileMiddleware>);\n}\n\n/** What `run` of `AsyncLocalStorage` looks like, the part that `answerCalls` uses. */\ninterface Storage {\n run: <T>(store: string, callback: () => T) => T;\n getStore: () => string | undefined;\n}\n\nlet storage: Promise<Storage | undefined> | undefined;\n\n/**\n * Tells the calls that a server function makes while it is answered. Node\n * has `AsyncLocalStorage`. Elsewhere, such as in a browser, there is none,\n * and nested calls are not told apart.\n */\nfunction callStorage(): Promise<Storage | undefined> {\n storage ??= import('node:async_hooks').then(\n ({ AsyncLocalStorage }) => new AsyncLocalStorage<string>() as Storage,\n () => undefined,\n );\n return storage;\n}\n\n/**\n * Answers the server function calls of the page in the test, with\n * `functions`, through the same request and answer as a server. Calls go\n * through `fetch`, so it replaces `fetch` until the returned function\n * restores it. Other requests go to the `fetch` from before.\n *\n * `functions` can be a function that returns them, so they are imported on\n * the first call. A server function that calls a server function through\n * `fetch`, as a browser stub does, throws: it would call itself without end.\n */\nexport function answerCalls(\n functions: ServerFunctions | (() => Promise<ServerFunctions>),\n options: AnswerOptions = {},\n): () => void {\n const prefix = options.rpc ?? '/_brumate';\n const original = globalThis.fetch;\n let loaded: Promise<ServerFunctions> | undefined;\n /** The error of a call that a server function made through `fetch`. */\n let failure: Error | undefined;\n const answer = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const base = globalThis.location?.href ?? 'http://localhost/';\n const url = new URL(input instanceof Request ? input.url : String(input), base);\n if (!url.pathname.startsWith(`${prefix}/`)) {\n return original(input, init);\n }\n const id = decodeURIComponent(url.pathname.slice(prefix.length + 1));\n const calls = await callStorage();\n const caller = calls?.getStore();\n if (caller !== undefined) {\n // The outer call answers with a generic error, so the error goes to its caller too.\n failure ??= new Error(\n `The server function \"${caller}\" called \"${id}\" through fetch, as a browser stub does. In a test, server code imports the server code of a 'use server' file: import components with ?brumate-server, and answer calls with the functions of virtual:brumate/server`,\n );\n throw failure;\n }\n options.onCall?.(id);\n loaded ??= Promise.resolve(typeof functions === 'function' ? functions() : functions);\n const registry = await loaded;\n const request = input instanceof Request ? new Request(input, init) : new Request(url, init);\n const guards = options.fileMiddleware;\n const fileMiddleware = typeof guards === 'function' ? await guards() : guards;\n const handle = (): Promise<Response | undefined> =>\n handleRequest(registry, request, prefix, { middleware: options.middleware, fileMiddleware });\n const response = await (calls ? calls.run(id, handle) : handle());\n if (failure) {\n const error = failure;\n failure = undefined;\n throw error;\n }\n return response ?? original(input, init);\n };\n globalThis.fetch = answer as typeof fetch;\n return () => {\n // A later `answerCalls` or stub keeps its own `fetch`.\n if (globalThis.fetch === answer) {\n globalThis.fetch = original;\n }\n };\n}\n\n/** Answers a request as the server of the app does, or undefined when nothing does. */\nexport type RequestHandler = (request: Request) => Promise<Response | undefined>;\n\nexport interface VisitorOptions extends TestingOptions {\n /** Answers the requests for pages, forms without scripts, `#defer` bodies and endpoints. */\n routes: () => Promise<RequestHandler>;\n /** Answers server function calls. */\n calls: () => Promise<RequestHandler>;\n}\n\nexport interface VisitOptions {\n /** Cookies that the browser has before the first request, by name. */\n cookies?: Record<string, string>;\n /** Headers of every request, such as `accept-language`. */\n headers?: HeadersInit;\n}\n\nexport interface Visited extends Actions {\n /** The path and the query of the page, such as `/issues?q=bug`. It changes with client navigation. */\n readonly url: string;\n /** The status of the first page. */\n status: number;\n /** The cookies that the browser has now, by name. */\n readonly cookies: Record<string, string>;\n /** Stops the loader, puts `fetch` back and empties the document. */\n close: () => void;\n}\n\n/** Visits a path of the app, as a browser that runs scripts does. */\nexport type Visit = (path: string, options?: VisitOptions) => Promise<Visited>;\n\nconst REDIRECTS = new Set([301, 302, 303, 307, 308]);\n\n/** Reads the `set-cookie` headers of a response into the cookies of the browser. */\nfunction storeCookies(jar: Map<string, string>, response: Response): void {\n for (const header of response.headers.getSetCookie()) {\n const [pair = '', ...attributes] = header.split(';');\n const equals = pair.indexOf('=');\n const name = pair.slice(0, equals).trim();\n if (equals < 1) {\n continue;\n }\n const gone = attributes.some((attribute) => {\n const [key = '', value = ''] = attribute.trim().split('=');\n const lower = key.toLowerCase();\n return (\n (lower === 'max-age' && Number(value) <= 0) ||\n (lower === 'expires' && Date.parse(value) <= Date.now())\n );\n });\n if (gone) {\n jar.delete(name);\n } else {\n jar.set(name, pair.slice(equals + 1).trim());\n }\n }\n}\n\n/** The page that a visit holds, so a new visit closes the one before. */\nlet visited: Visited | undefined;\n\n/** Returns `visit`, which answers the requests of the page with the routes of the app. */\nexport function createVisit(options: VisitorOptions): Visit {\n const prefix = options.rpc ?? '/_brumate';\n /**\n * Answers the path with the routes of the app, puts the page in the\n * document, and starts the loader with client navigation. Links, forms,\n * server function calls and `#defer` requests of the page go to the same\n * routes, without a server, with the cookies that the answers set.\n */\n return async function visit(path, visitOptions = {}) {\n visited?.close();\n const jar = new Map(Object.entries(visitOptions.cookies ?? {}));\n const original = globalThis.fetch;\n const origin = location.origin;\n history.replaceState(null, '', new URL(path, origin));\n\n // A browser follows redirects, sends its cookies, and keeps the ones that the answers set.\n const answer = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n let url = new URL(input instanceof Request ? input.url : String(input), location.href);\n if (url.origin !== origin) {\n return original(input, init);\n }\n let method = (\n init?.method ?? (input instanceof Request ? input.method : 'GET')\n ).toUpperCase();\n let body = init?.body ?? undefined;\n const extra = new Headers(input instanceof Request ? input.headers : undefined);\n new Headers(init?.headers).forEach((value, name) => extra.set(name, value));\n for (let hops = 0; ; hops++) {\n const request = new Request(url, { method, body, signal: init?.signal ?? null });\n // Set after the request is made, since a DOM environment drops these from its init.\n new Headers(visitOptions.headers).forEach((value, name) =>\n request.headers.set(name, value),\n );\n extra.forEach((value, name) => request.headers.set(name, value));\n if (jar.size > 0) {\n request.headers.set(\n 'cookie',\n [...jar].map(([name, value]) => `${name}=${value}`).join('; '),\n );\n }\n if (method !== 'GET' && method !== 'HEAD') {\n request.headers.set('origin', origin);\n }\n const handle = url.pathname.startsWith(`${prefix}/`) ? options.calls : options.routes;\n const answered = handle().then((handler) => handler(request));\n // oxlint-disable-next-line no-await-in-loop -- Each redirect is a request of its own.\n const response = (await answered) ?? new Response('Not found', { status: 404 });\n storeCookies(jar, response);\n const location = response.headers.get('location');\n if (!REDIRECTS.has(response.status) || !location || init?.redirect === 'manual') {\n Object.defineProperty(response, 'url', { value: url.href });\n return response;\n }\n if (hops === 20) {\n throw new TypeError(`Too many redirects from ${path}`);\n }\n url = new URL(location, url);\n // As in fetch: 303 asks for the page with GET, and so do 301 and 302 after a POST.\n // 307 and 308 send the request again as it was.\n if (\n (response.status === 303 && method !== 'HEAD') ||\n (method === 'POST' && (response.status === 301 || response.status === 302))\n ) {\n method = 'GET';\n body = undefined;\n extra.delete('content-type');\n }\n }\n };\n globalThis.fetch = answer as typeof fetch;\n\n // The DOM of a test does not run scripts, so the ones that the page adds run here, once each.\n const ran = new WeakSet<Element>();\n const runOnce = (script: Element): void => {\n if (!ran.has(script) && !script.hasAttribute('src') && !script.hasAttribute('type')) {\n ran.add(script);\n run(script);\n }\n };\n const scripts = new MutationObserver((records) => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeName === 'SCRIPT') {\n runOnce(node as Element);\n } else if (node instanceof Element) {\n node.querySelectorAll('script').forEach(runOnce);\n }\n }\n }\n });\n\n const response = await answer(path);\n // The page is at the URL of the last redirect.\n history.replaceState(null, '', response.url);\n const reader = response.body!.pipeThrough(new TextDecoderStream()).getReader();\n let html = '';\n let end = -1;\n let done = false;\n while (end < 0 && !done) {\n // oxlint-disable-next-line no-await-in-loop -- The page arrives in pieces.\n const chunk = await reader.read();\n done = chunk.done;\n html += chunk.value ?? '';\n end = html.search(/<\\/html>/i);\n }\n const cut = end < 0 ? html.length : end + '</html>'.length;\n const page = new DOMParser().parseFromString(html.slice(0, cut), 'text/html');\n for (const name of document.documentElement.getAttributeNames()) {\n document.documentElement.removeAttribute(name);\n }\n for (const attribute of page.documentElement.attributes) {\n document.documentElement.setAttribute(attribute.name, attribute.value);\n }\n document.head.replaceChildren(\n ...[...page.head.childNodes].map((node) => document.importNode(node, true)),\n );\n document.body.replaceChildren(\n ...[...page.body.childNodes].map((node) => document.importNode(node, true)),\n );\n document.querySelectorAll('script').forEach(runOnce);\n scripts.observe(document, { childList: true, subtree: true });\n\n const stop = start({ load: options.load, rpc: prefix, navigate: true, preload: false });\n let rest = html.slice(cut);\n let open = true;\n void (async () => {\n while (!done) {\n // oxlint-disable-next-line no-await-in-loop -- Later markup arrives in pieces.\n const chunk = await reader.read();\n done = chunk.done;\n rest += chunk.value ?? '';\n // A chunk can end inside a tag, a script or a template, so only whole nodes move in.\n const last = done ? rest.length : wholeNodes(rest);\n if (last > 0 && open) {\n // The observer runs its scripts.\n const template = document.createElement('template');\n template.innerHTML = rest.slice(0, last);\n document.body.append(template.content);\n rest = rest.slice(last);\n }\n }\n })();\n\n const current: Visited = {\n ...actions(document),\n get url() {\n return location.pathname + location.search;\n },\n status: response.status,\n get cookies() {\n return Object.fromEntries(jar);\n },\n close: () => {\n if (!open) {\n return;\n }\n open = false;\n visited = undefined;\n stop();\n scripts.disconnect();\n reader.cancel().catch(() => {});\n if (globalThis.fetch === answer) {\n globalThis.fetch = original;\n }\n // The core forgets the page, so the next visit starts its IDs again.\n void import('./client.ts').then((core) => core.leavePage());\n document.head.replaceChildren();\n document.body.replaceChildren();\n },\n };\n visited = current;\n return current;\n };\n}\n"],"mappings":";;;AAEA,MAAM,uBAAO,IAAI,IAAI;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AAOD,SAAgB,WAAW,QAAwB;CACjD,MAAM,MAAM;CACZ,MAAM,QAAQ,OAAO,YAAY;CACjC,IAAI,QAAQ;CACZ,IAAI,MAAM;CACV,IAAI;CACJ,OAAQ,QAAQ,IAAI,KAAK,MAAM,GAAI;EACjC,MAAM,CAAC,OAAO,SAAS,QAAQ;EAC/B,MAAM,UAAU,KAAM,YAAY;EAClC,IAAI,CAAC,WAAW,YAAY,UAAU;GAEpC,MAAM,QAAQ,MAAM,QAAQ,aAAY,IAAI,SAAS;GACrD,MAAM,QAAQ,QAAQ,IAAI,KAAK,OAAO,QAAQ,KAAK,KAAK;GACxD,IAAI,QAAQ,GACV,OAAO;GAET,IAAI,YAAY,QAAQ;EAC1B,OAAO,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,SAAS,IAAI,GACnD,SAAS,UAAU,KAAK;EAE1B,IAAI,UAAU,GACZ,MAAM,IAAI;CAEd;CACA,OAAO;AACT;;;;ACAA,SAAS,QAAQ,MAA2B;CAC1C,MAAM,OAAO,aAAkC;EAC7C,MAAM,UAAU,KAAK,cAA2B,QAAQ;EACx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BAAgB;IAC9B,SAAS,KAAK,gBAAgB;GAChC;EACF;EACA,UAAU;EACV,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"testing.js","names":[],"sources":["../../src/runtime/nodes.ts","../../src/runtime/testing.ts"],"sourcesContent":["// Finds where whole nodes end in markup that arrives in pieces.\n\nconst VOID = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'source',\n 'track',\n 'wbr',\n]);\n\n/**\n * The end of the last whole node at the top level of markup that streams in,\n * so a chunk that ends inside a tag, the text of a script or a template\n * waits for the rest. A `>` in an attribute or a script does not end a node.\n */\nexport function wholeNodes(markup: string): number {\n const tag = /<(\\/?)([a-zA-Z][\\w-]*)(?:[^>\"']|\"[^\"]*\"|'[^']*')*>/g;\n const lower = markup.toLowerCase();\n let depth = 0;\n let end = 0;\n let match: RegExpExecArray | null;\n while ((match = tag.exec(markup))) {\n const [whole, closing, name] = match;\n const element = name!.toLowerCase();\n if (!closing && element === 'script') {\n // The text of a script is not markup, and ends only at `</script`.\n const close = lower.indexOf('</script', tag.lastIndex);\n const after = close < 0 ? -1 : markup.indexOf('>', close);\n if (after < 0) {\n return end;\n }\n tag.lastIndex = after + 1;\n } else if (!VOID.has(element) && !whole.endsWith('/>')) {\n depth += closing ? -1 : 1;\n }\n if (depth === 0) {\n end = tag.lastIndex;\n }\n }\n return end;\n}\n","// Renders a component on the server and resumes it in the DOM of a test, as\n// a page does: the HTML and the state first, then the loader, which loads\n// client code when an event fires. `visit` does the same for a route, with\n// the requests of the page answered by the routes of the app.\n//\n// The triggers of `$client`, `#client` and `#defer` fire as follows:\n// - 'load' fires when the loader starts.\n// - 'visible' fires when the IntersectionObserver that `mount` and `visit`\n// install reports the element, which it does at once unless the test keeps\n// the element out of view.\n// - 'idle' fires as in a browser that has no requestIdleCallback, which\n// includes happy-dom: on a timer after the page starts. The loader decides\n// this, so a test needs no action for it.\n\nimport type { ClientModule } from './client.ts';\nimport { start } from './loader.ts';\nimport { wholeNodes } from './nodes.ts';\nimport { handleRequest, render } from './server.ts';\nimport type { Component, EntryMiddleware, RenderOptions } from './server.ts';\n\n/** The middleware of files of server functions, by function ID. */\ntype FileMiddleware = Record<string, EntryMiddleware>;\n\nexport interface TestingOptions {\n /** Imports the client module of a component, by component ID. */\n load: (id: string) => Promise<ClientModule>;\n /** The URL prefix of server function calls. */\n rpc?: string;\n}\n\n/** What a test does with the page, as a user does. */\nexport interface Actions {\n /** The first element that matches a selector. Throws if none does. */\n get: (selector: string) => HTMLElement;\n /** The text of the first element that matches a selector. */\n text: (selector: string) => string;\n /** Clicks an element. */\n click: (selector: string) => void;\n /** Types a value into a field, and fires `input`. */\n input: (selector: string, value: string) => void;\n /** Submits a form, as its submit button does. */\n submit: (selector: string) => void;\n /**\n * Brings the elements that match a selector into view, so what waits for\n * them with the 'visible' trigger runs. See `offscreen`.\n */\n reveal: (selector: string) => void;\n /**\n * Retries an assertion until it passes. The first event of a test loads\n * client code, so its effects arrive a moment later.\n */\n waitFor: (assertion: () => void, timeout?: number) => Promise<void>;\n}\n\nexport interface Mounted extends Actions {\n /** The element that holds the component. */\n container: HTMLElement;\n /** Stops the loader and removes the component. */\n unmount: () => void;\n}\n\n/** The elements that the test keeps out of view, and the observers that wait for them. */\ninterface View {\n /** The selectors of `offscreen`, one entry for each mount or visit. */\n hidden: Set<{ selector: string }>;\n /** The elements that the test brought into view. */\n revealed: WeakSet<Element>;\n /** Reports an element to the observers that wait for it, as visible. */\n waiting: Set<{ element: Element; report: () => void }>;\n users: number;\n original: typeof IntersectionObserver | undefined;\n}\n\nlet view: View | undefined;\n\n/** Reports an element that waits out of view, as visible. */\nfunction reveal(element: Element): void {\n view?.revealed.add(element);\n for (const entry of view?.waiting ?? []) {\n if (entry.element === element) {\n view!.waiting.delete(entry);\n entry.report();\n }\n }\n}\n\n/**\n * Replaces the IntersectionObserver of the environment with one that reports\n * each element it observes as visible, except the ones that match a selector\n * of `offscreen`. happy-dom has an observer that never reports. Returns what\n * puts the observer of the environment back.\n */\nfunction watchView(offscreen: string | undefined): () => void {\n if (!view) {\n const current: View = {\n hidden: new Set(),\n revealed: new WeakSet(),\n waiting: new Set(),\n users: 0,\n original: globalThis.IntersectionObserver,\n };\n class Reporting {\n readonly #callback: IntersectionObserverCallback;\n readonly #entries = new Set<{ element: Element; report: () => void }>();\n readonly root = null;\n readonly rootMargin = '0px';\n readonly thresholds = [0];\n constructor(callback: IntersectionObserverCallback) {\n this.#callback = callback;\n }\n observe(element: Element): void {\n const report = (): void => {\n const rect = element.getBoundingClientRect();\n this.#callback(\n [\n {\n target: element,\n isIntersecting: true,\n intersectionRatio: 1,\n boundingClientRect: rect,\n intersectionRect: rect,\n rootBounds: null,\n time: performance.now(),\n },\n ],\n this as unknown as IntersectionObserver,\n );\n };\n const entry = { element, report };\n this.#entries.add(entry);\n let isHidden = false;\n if (!current.revealed.has(element)) {\n for (const { selector } of current.hidden) {\n if (element.matches(selector)) {\n isHidden = true;\n break;\n }\n }\n }\n if (isHidden) {\n current.waiting.add(entry);\n } else {\n queueMicrotask(() => {\n if (this.#entries.has(entry)) {\n report();\n }\n });\n }\n }\n unobserve(element: Element): void {\n for (const entry of this.#entries) {\n if (entry.element === element) {\n this.#entries.delete(entry);\n current.waiting.delete(entry);\n }\n }\n }\n disconnect(): void {\n for (const entry of this.#entries) {\n current.waiting.delete(entry);\n }\n this.#entries.clear();\n }\n takeRecords(): IntersectionObserverEntry[] {\n return [];\n }\n }\n globalThis.IntersectionObserver = Reporting as unknown as typeof IntersectionObserver;\n view = current;\n }\n const current = view;\n current.users++;\n // One entry for each user, so two mounts that keep out the same selector do not clear each other.\n const hidden = { selector: offscreen ?? '' };\n if (offscreen !== undefined) {\n current.hidden.add(hidden);\n }\n let released = false;\n return () => {\n if (released) {\n return;\n }\n released = true;\n current.hidden.delete(hidden);\n if (--current.users === 0) {\n if (current.original) {\n globalThis.IntersectionObserver = current.original;\n } else {\n delete (globalThis as { IntersectionObserver?: unknown }).IntersectionObserver;\n }\n current.waiting.clear();\n view = undefined;\n }\n };\n}\n\n/** The actions on the elements inside `root`. */\nfunction actions(root: ParentNode): Actions {\n function get(selector: string): HTMLElement {\n const element = root.querySelector<HTMLElement>(selector);\n if (!element) {\n throw new Error(`No element matches ${selector}`);\n }\n return element;\n }\n return {\n get,\n text: (selector) => get(selector).textContent ?? '',\n click: (selector) => get(selector).click(),\n input: (selector, value) => {\n const field = get(selector) as HTMLInputElement;\n field.value = value;\n field.dispatchEvent(new Event('input', { bubbles: true }));\n },\n submit: (selector) => {\n get(selector).dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));\n },\n reveal: (selector) => {\n for (const element of root.querySelectorAll(selector)) {\n reveal(element);\n }\n },\n waitFor: async (assertion, timeout = 2000) => {\n const until = Date.now() + timeout;\n for (;;) {\n try {\n assertion();\n return;\n } catch (error) {\n if (Date.now() > until) {\n throw error;\n }\n // oxlint-disable-next-line no-await-in-loop -- It waits between tries.\n await new Promise((resolve) => setTimeout(resolve, 10));\n }\n }\n },\n };\n}\n\n/**\n * Runs an inline script, as a browser does when it adds one. The DOM of a\n * test does not run scripts. The script is `document.currentScript` while it\n * runs, so a state record hands its script to the core.\n */\nfunction run(script: Element): void {\n Object.defineProperty(document, 'currentScript', { configurable: true, value: script });\n try {\n // oxlint-disable-next-line no-eval -- The script is a state record or the swap code from the server.\n (0, eval)(script.textContent!);\n } finally {\n delete (document as { currentScript?: unknown }).currentScript;\n }\n}\n\n/**\n * Appends markup that streams in later, such as a `#loading` body, and runs\n * its inline scripts in order.\n */\nfunction append(container: HTMLElement, html: string): void {\n const template = document.createElement('template');\n template.innerHTML = html;\n // A copy, because appending moves nodes out of the live list.\n // oxlint-disable-next-line unicorn/no-useless-spread\n for (const node of [...template.content.childNodes]) {\n container.append(node);\n if (node.nodeName === 'SCRIPT' && !(node as Element).hasAttribute('type')) {\n run(node as Element);\n }\n }\n}\n\n/** Renders a component on the server and resumes it in the document of a test. */\nexport type Mount = <P>(\n component: Component<P>,\n props: P,\n renderOptions?: MountRenderOptions,\n) => Promise<Mounted>;\n\n/** The options of `render`, and the elements to keep out of view. */\nexport interface MountRenderOptions extends RenderOptions {\n /**\n * A selector of elements that stay out of view, for a test of what waits\n * for them with the 'visible' trigger. `reveal` brings them into view.\n */\n offscreen?: string;\n}\n\n/** Mounts so far, so each starts its scope IDs at a number of its own. */\nlet mounts = 0;\n/** The loader that the mounts of the document share, and how many mounts use it. */\nlet loader: { stop: () => void; users: number } | undefined;\n\n/** Returns `mount`, which loads client modules with `options.load`. */\nexport function createMount(options: TestingOptions): Mount {\n /**\n * Renders a component on the server, puts it in the document with its\n * state, and starts the loader. Markup that streams in later is added as\n * it arrives.\n */\n return async function mount<P>(\n component: Component<P>,\n props: P,\n { offscreen, ...renderOptions }: MountRenderOptions = {},\n ): Promise<Mounted> {\n // IDs of their own, so two mounts in a file do not share scopes or state references.\n const base = renderOptions.base ?? ++mounts * 1_000_000;\n const { html, state, pending } = await render(component, props, { ...renderOptions, base });\n const unwatch = watchView(offscreen);\n const container = document.createElement('div');\n container.innerHTML = html + state;\n document.body.append(container);\n // The page state, which waits for the core.\n for (const script of container.querySelectorAll('script[b-state]')) {\n run(script);\n }\n // One loader for the document, as a page has, however many mounts are in it.\n loader ??= {\n stop: start({ load: options.load, rpc: options.rpc, navigate: false }),\n users: 0,\n };\n loader.users++;\n let mounted = true;\n function stop(): void {\n if (!mounted || !loader) {\n return;\n }\n mounted = false;\n unwatch();\n if (--loader.users === 0) {\n loader.stop();\n loader = undefined;\n }\n }\n void (async () => {\n for await (const chunk of pending) {\n append(container, chunk);\n }\n })();\n return {\n container,\n ...actions(container),\n unmount: () => {\n stop();\n container.remove();\n // The core forgets the scopes of this mount, so a refresh later does not load its memos.\n void import('./client.ts').then((core) => core.removeRoot(String(base)));\n },\n };\n };\n}\n\n/** Server functions by ID, as `functions` of `virtual:brumate/server` has them. */\n// oxlint-disable-next-line typescript/no-explicit-any -- Server functions take any arguments.\nexport type ServerFunctions = Record<string, (...args: any[]) => unknown>;\n\nexport interface AnswerOptions {\n /** The URL prefix of server function calls. Defaults to `/_brumate`. */\n rpc?: string;\n /** Called with the ID of each call, such as `issues_1a2b#toggleStar`, before it runs. */\n onCall?: (id: string) => void;\n /** The middleware of the entry, which runs before each call. `virtual:brumate/testing` passes the app's. */\n middleware?: EntryMiddleware;\n /**\n * The middleware of each `'use server'` file, by function ID, or a\n * function that imports them. `virtual:brumate/testing` passes them.\n */\n fileMiddleware?: FileMiddleware | (() => Promise<FileMiddleware>);\n}\n\n/** What `run` of `AsyncLocalStorage` looks like, the part that `answerCalls` uses. */\ninterface Storage {\n run: <T>(store: string, callback: () => T) => T;\n getStore: () => string | undefined;\n}\n\nlet storage: Promise<Storage | undefined> | undefined;\n\n/**\n * Tells the calls that a server function makes while it is answered. Node\n * has `AsyncLocalStorage`. Elsewhere, such as in a browser, there is none,\n * and nested calls are not told apart.\n */\nfunction callStorage(): Promise<Storage | undefined> {\n storage ??= import('node:async_hooks').then(\n ({ AsyncLocalStorage }) => new AsyncLocalStorage<string>() as Storage,\n () => undefined,\n );\n return storage;\n}\n\n/**\n * Answers the server function calls of the page in the test, with\n * `functions`, through the same request and answer as a server. Calls go\n * through `fetch`, so it replaces `fetch` until the returned function\n * restores it. Other requests go to the `fetch` from before.\n *\n * `functions` can be a function that returns them, so they are imported on\n * the first call. A server function that calls a server function through\n * `fetch`, as a browser stub does, throws: it would call itself without end.\n */\nexport function answerCalls(\n functions: ServerFunctions | (() => Promise<ServerFunctions>),\n options: AnswerOptions = {},\n): () => void {\n const prefix = options.rpc ?? '/_brumate';\n const original = globalThis.fetch;\n let loaded: Promise<ServerFunctions> | undefined;\n /** The error of a call that a server function made through `fetch`. */\n let failure: Error | undefined;\n async function answer(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n const base = globalThis.location?.href ?? 'http://localhost/';\n const url = new URL(input instanceof Request ? input.url : String(input), base);\n if (!url.pathname.startsWith(`${prefix}/`)) {\n return original(input, init);\n }\n const id = decodeURIComponent(url.pathname.slice(prefix.length + 1));\n const calls = await callStorage();\n const caller = calls?.getStore();\n if (caller !== undefined) {\n // The outer call answers with a generic error, so the error goes to its caller too.\n failure ??= new Error(\n `The server function \"${caller}\" called \"${id}\" through fetch, as a browser stub does. In a test, server code imports the server code of a 'use server' file: import components with ?brumate-server, and answer calls with the functions of virtual:brumate/server`,\n );\n throw failure;\n }\n options.onCall?.(id);\n loaded ??= Promise.resolve(typeof functions === 'function' ? functions() : functions);\n const registry = await loaded;\n const request = input instanceof Request ? new Request(input, init) : new Request(url, init);\n const guards = options.fileMiddleware;\n const fileMiddleware = typeof guards === 'function' ? await guards() : guards;\n function handle(): Promise<Response | undefined> {\n return handleRequest(registry, request, prefix, {\n middleware: options.middleware,\n fileMiddleware,\n });\n }\n const response = await (calls ? calls.run(id, handle) : handle());\n if (failure) {\n const error = failure;\n failure = undefined;\n throw error;\n }\n return response ?? original(input, init);\n }\n globalThis.fetch = answer as typeof fetch;\n return () => {\n // A later `answerCalls` or stub keeps its own `fetch`.\n if (globalThis.fetch === answer) {\n globalThis.fetch = original;\n }\n };\n}\n\n/** Answers a request as the server of the app does, or undefined when nothing does. */\nexport type RequestHandler = (request: Request) => Promise<Response | undefined>;\n\nexport interface VisitorOptions extends TestingOptions {\n /** Answers the requests for pages, forms without scripts, `#defer` bodies and endpoints. */\n routes: () => Promise<RequestHandler>;\n /** Answers server function calls. */\n calls: () => Promise<RequestHandler>;\n}\n\nexport interface VisitOptions {\n /** Cookies that the browser has before the first request, by name. */\n cookies?: Record<string, string>;\n /** Headers of every request, such as `accept-language`. */\n headers?: HeadersInit;\n /** A selector of elements that stay out of view until `reveal` brings them in. */\n offscreen?: string;\n}\n\nexport interface Visited extends Actions {\n /** The path and the query of the page, such as `/issues?q=bug`. It changes with client navigation. */\n readonly url: string;\n /** The status of the first page. */\n status: number;\n /** The cookies that the browser has now, by name. */\n readonly cookies: Record<string, string>;\n /** Stops the loader, puts `fetch` back and empties the document. */\n close: () => void;\n}\n\n/** Visits a path of the app, as a browser that runs scripts does. */\nexport type Visit = (path: string, options?: VisitOptions) => Promise<Visited>;\n\nconst REDIRECTS = new Set([301, 302, 303, 307, 308]);\n\n/** Reads the `set-cookie` headers of a response into the cookies of the browser. */\nfunction storeCookies(jar: Map<string, string>, response: Response): void {\n for (const header of response.headers.getSetCookie()) {\n const [pair = '', ...attributes] = header.split(';');\n const equals = pair.indexOf('=');\n const name = pair.slice(0, equals).trim();\n if (equals < 1) {\n continue;\n }\n let gone = false;\n for (const attribute of attributes) {\n const [key = '', value = ''] = attribute.trim().split('=');\n const lower = key.toLowerCase();\n if (\n (lower === 'max-age' && Number(value) <= 0) ||\n (lower === 'expires' && Date.parse(value) <= Date.now())\n ) {\n gone = true;\n break;\n }\n }\n if (gone) {\n jar.delete(name);\n } else {\n jar.set(name, pair.slice(equals + 1).trim());\n }\n }\n}\n\n/** The page that a visit holds, so a new visit closes the one before. */\nlet visited: Visited | undefined;\n\n/** Returns `visit`, which answers the requests of the page with the routes of the app. */\nexport function createVisit(options: VisitorOptions): Visit {\n const prefix = options.rpc ?? '/_brumate';\n /**\n * Answers the path with the routes of the app, puts the page in the\n * document, and starts the loader with client navigation. Links, forms,\n * server function calls and `#defer` requests of the page go to the same\n * routes, without a server, with the cookies that the answers set.\n */\n return async function visit(path, visitOptions = {}) {\n visited?.close();\n const jar = new Map(Object.entries(visitOptions.cookies ?? {}));\n const original = globalThis.fetch;\n const origin = location.origin;\n history.replaceState(null, '', new URL(path, origin));\n\n // A browser follows redirects, sends its cookies, and keeps the ones that the answers set.\n async function answer(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {\n let url = new URL(input instanceof Request ? input.url : String(input), location.href);\n if (url.origin !== origin) {\n return original(input, init);\n }\n let method = (\n init?.method ?? (input instanceof Request ? input.method : 'GET')\n ).toUpperCase();\n let body = init?.body ?? undefined;\n const extra = new Headers(input instanceof Request ? input.headers : undefined);\n for (const [name, value] of new Headers(init?.headers)) {\n extra.set(name, value);\n }\n for (let hops = 0; ; hops++) {\n const request = new Request(url, { method, body, signal: init?.signal ?? null });\n // Set after the request is made, since a DOM environment drops these from its init.\n for (const [name, value] of new Headers(visitOptions.headers)) {\n request.headers.set(name, value);\n }\n for (const [name, value] of extra) {\n request.headers.set(name, value);\n }\n if (jar.size > 0) {\n const cookies: string[] = [];\n for (const [name, value] of jar) {\n cookies.push(`${name}=${value}`);\n }\n request.headers.set('cookie', cookies.join('; '));\n }\n if (method !== 'GET' && method !== 'HEAD') {\n request.headers.set('origin', origin);\n }\n const handle = url.pathname.startsWith(`${prefix}/`) ? options.calls : options.routes;\n const answered = handle().then((handler) => handler(request));\n // oxlint-disable-next-line no-await-in-loop -- Each redirect is a request of its own.\n const response = (await answered) ?? new Response('Not found', { status: 404 });\n storeCookies(jar, response);\n const location = response.headers.get('location');\n if (!REDIRECTS.has(response.status) || !location || init?.redirect === 'manual') {\n Object.defineProperty(response, 'url', { value: url.href });\n return response;\n }\n if (hops === 20) {\n throw new TypeError(`Too many redirects from ${path}`);\n }\n url = new URL(location, url);\n // As in fetch: 303 asks for the page with GET, and so do 301 and 302 after a POST.\n // 307 and 308 send the request again as it was.\n if (\n (response.status === 303 && method !== 'HEAD') ||\n (method === 'POST' && (response.status === 301 || response.status === 302))\n ) {\n method = 'GET';\n body = undefined;\n extra.delete('content-type');\n }\n }\n }\n globalThis.fetch = answer as typeof fetch;\n\n // The DOM of a test does not run scripts, so the ones that the page adds run here, once each.\n const ran = new WeakSet<Element>();\n function runOnce(script: Element): void {\n if (!ran.has(script) && !script.hasAttribute('src') && !script.hasAttribute('type')) {\n ran.add(script);\n run(script);\n }\n }\n const scripts = new MutationObserver((records) => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeName === 'SCRIPT') {\n runOnce(node as Element);\n } else if (node instanceof Element) {\n for (const script of node.querySelectorAll('script')) {\n runOnce(script);\n }\n }\n }\n }\n });\n\n const response = await answer(path);\n // The page is at the URL of the last redirect.\n history.replaceState(null, '', response.url);\n const reader = response.body!.pipeThrough(new TextDecoderStream()).getReader();\n let html = '';\n let end = -1;\n let done = false;\n while (end < 0 && !done) {\n // oxlint-disable-next-line no-await-in-loop -- The page arrives in pieces.\n const chunk = await reader.read();\n done = chunk.done;\n html += chunk.value ?? '';\n end = html.search(/<\\/html>/i);\n }\n const cut = end < 0 ? html.length : end + '</html>'.length;\n const page = new DOMParser().parseFromString(html.slice(0, cut), 'text/html');\n for (const name of document.documentElement.getAttributeNames()) {\n document.documentElement.removeAttribute(name);\n }\n for (const attribute of page.documentElement.attributes) {\n document.documentElement.setAttribute(attribute.name, attribute.value);\n }\n const headNodes: Node[] = [];\n for (const node of page.head.childNodes) {\n headNodes.push(document.importNode(node, true));\n }\n document.head.replaceChildren(...headNodes);\n const bodyNodes: Node[] = [];\n for (const node of page.body.childNodes) {\n bodyNodes.push(document.importNode(node, true));\n }\n document.body.replaceChildren(...bodyNodes);\n for (const script of document.querySelectorAll('script')) {\n runOnce(script);\n }\n scripts.observe(document, { childList: true, subtree: true });\n\n const unwatch = watchView(visitOptions.offscreen);\n const stop = start({ load: options.load, rpc: prefix, navigate: true });\n let rest = html.slice(cut);\n let open = true;\n void (async () => {\n while (!done) {\n // oxlint-disable-next-line no-await-in-loop -- Later markup arrives in pieces.\n const chunk = await reader.read();\n done = chunk.done;\n rest += chunk.value ?? '';\n // A chunk can end inside a tag, a script or a template, so only whole nodes move in.\n const last = done ? rest.length : wholeNodes(rest);\n if (last > 0 && open) {\n // The observer runs its scripts.\n const template = document.createElement('template');\n template.innerHTML = rest.slice(0, last);\n document.body.append(template.content);\n rest = rest.slice(last);\n }\n }\n })();\n\n const current: Visited = {\n ...actions(document),\n get url() {\n return location.pathname + location.search;\n },\n status: response.status,\n get cookies() {\n return Object.fromEntries(jar);\n },\n close: () => {\n if (!open) {\n return;\n }\n open = false;\n visited = undefined;\n stop();\n unwatch();\n scripts.disconnect();\n reader.cancel().catch(() => {});\n if (globalThis.fetch === answer) {\n globalThis.fetch = original;\n }\n // The core forgets the page, so the next visit starts its IDs again.\n void import('./client.ts').then((core) => core.leavePage());\n document.head.replaceChildren();\n document.body.replaceChildren();\n },\n };\n visited = current;\n return current;\n };\n}\n"],"mappings":";;;AAEA,MAAM,uBAAO,IAAI,IAAI;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AAOD,SAAgB,WAAW,QAAwB;CACjD,MAAM,MAAM;CACZ,MAAM,QAAQ,OAAO,YAAY;CACjC,IAAI,QAAQ;CACZ,IAAI,MAAM;CACV,IAAI;CACJ,OAAQ,QAAQ,IAAI,KAAK,MAAM,GAAI;EACjC,MAAM,CAAC,OAAO,SAAS,QAAQ;EAC/B,MAAM,UAAU,KAAM,YAAY;EAClC,IAAI,CAAC,WAAW,YAAY,UAAU;GAEpC,MAAM,QAAQ,MAAM,QAAQ,aAAY,IAAI,SAAS;GACrD,MAAM,QAAQ,QAAQ,IAAI,KAAK,OAAO,QAAQ,KAAK,KAAK;GACxD,IAAI,QAAQ,GACV,OAAO;GAET,IAAI,YAAY,QAAQ;EAC1B,OAAO,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,SAAS,IAAI,GACnD,SAAS,UAAU,KAAK;EAE1B,IAAI,UAAU,GACZ,MAAM,IAAI;CAEd;CACA,OAAO;AACT;;;ACyBA,IAAI;;AAGJ,SAAS,OAAO,SAAwB;CACtC,MAAM,SAAS,IAAI,OAAO;CAC1B,KAAK,MAAM,SAAS,MAAM,WAAW,CAAC,GACpC,IAAI,MAAM,YAAY,SAAS;EAC7B,KAAM,QAAQ,OAAO,KAAK;EAC1B,MAAM,OAAO;CACf;AAEJ;;;;;;;AAQA,SAAS,UAAU,WAA2C;CAC5D,IAAI,CAAC,MAAM;EACT,MAAM,UAAgB;GACpB,wBAAQ,IAAI,IAAI;GAChB,0BAAU,IAAI,QAAQ;GAC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,KAAK;IAChC,OAAO,MAAM;IACb,QAAQ,MAAM,SAAS;IAEvB,MAAM,OAAO,OAAO,KAAK,SAAS,WAAW,IAAI;IACjD,IAAI,OAAO,KAAK,MAAM;KAEpB,MAAM,WAAW,SAAS,cAAc,UAAU;KAClD,SAAS,YAAY,KAAK,MAAM,GAAG,IAAI;KACvC,SAAS,KAAK,OAAO,SAAS,OAAO;KACrC,OAAO,KAAK,MAAM,IAAI;IACxB;GACF;EACF,EAAA,CAAG;EAEH,MAAM,UAAmB;GACvB,GAAG,QAAQ,QAAQ;GACnB,IAAI,MAAM;IACR,OAAO,SAAS,WAAW,SAAS;GACtC;GACA,QAAQ,SAAS;GACjB,IAAI,UAAU;IACZ,OAAO,OAAO,YAAY,GAAG;GAC/B;GACA,aAAa;IACX,IAAI,CAAC,MACH;IAEF,OAAO;IACP,UAAU,KAAA;IACV,KAAK;IACL,QAAQ;IACR,QAAQ,WAAW;IACnB,OAAO,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC;IAC9B,IAAI,WAAW,UAAU,QACvB,WAAW,QAAQ;IAGrB,OAAY,cAAc,CAAC,MAAM,SAAS,KAAK,UAAU,CAAC;IAC1D,SAAS,KAAK,gBAAgB;IAC9B,SAAS,KAAK,gBAAgB;GAChC;EACF;EACA,UAAU;EACV,OAAO;CACT;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as Raw } from "./html-Bq1rFxX_.js";
|
|
2
|
-
import { a as PackedState, c as ScopeState, n as Binding, o as PageState, r as ElementReference, s as ScopeId } from "./produce-D0V0ICkz.js";
|
|
3
1
|
import { t as Context$1 } from "./context-btHuB01Z.js";
|
|
2
|
+
import { n as Raw } from "./html-Bw9Qwu6F.js";
|
|
3
|
+
import { a as PackedState, l as ScopeId, n as Binding, o as PageState, r as ElementReference, s as PropSink, u as ScopeState } from "./produce-DIgHBVwL.js";
|
|
4
4
|
import { t as StandardSchemaV1 } from "./standard-schema-BNY82yX3.js";
|
|
5
|
-
import { f as Intent, v as SubmissionResult } from "./forms-
|
|
5
|
+
import { f as Intent, v as SubmissionResult } from "./forms-j1xPAR14.js";
|
|
6
6
|
//#region src/runtime/cookies.d.ts
|
|
7
7
|
interface CookieOptions {
|
|
8
8
|
/** Seconds until the cookie expires. Without it, the cookie lasts until the browser closes. */
|
|
@@ -725,6 +725,15 @@ interface Boundary {
|
|
|
725
725
|
around?: boolean;
|
|
726
726
|
/** The `#reveal` group that orders it, when it is in one. */
|
|
727
727
|
group?: RevealGroup;
|
|
728
|
+
/** The `#try` blocks around it, from the outside in. */
|
|
729
|
+
catchers: Catcher[];
|
|
730
|
+
}
|
|
731
|
+
/** A `#try` that is rendering its body, and how to render its `#catch` body later. */
|
|
732
|
+
interface Catcher {
|
|
733
|
+
/** The marker of the block, `<scope>:<anchor>`. */
|
|
734
|
+
key: string;
|
|
735
|
+
/** Renders the `#catch` body for an error, in a context of its own. */
|
|
736
|
+
render: (ctx: Context, error: unknown) => Promise<string>;
|
|
728
737
|
}
|
|
729
738
|
/** The order of a `#reveal` block. */
|
|
730
739
|
type RevealOrder = "sequential" | "backwards" | "together" | "natural";
|
|
@@ -800,7 +809,7 @@ interface IdSpace {
|
|
|
800
809
|
entries: (ScopeEntry | undefined)[];
|
|
801
810
|
}
|
|
802
811
|
/** A scope of a render: its record, and what the server keeps of it while the page renders. */
|
|
803
|
-
interface ScopeEntry {
|
|
812
|
+
interface ScopeEntry extends PropSink {
|
|
804
813
|
id: ScopeId;
|
|
805
814
|
/** The prefix of the ID and the number after it, such as `'5.'` and `1`, or `''` and `3`. */
|
|
806
815
|
prefix: string;
|
|
@@ -863,6 +872,10 @@ declare class Context {
|
|
|
863
872
|
/** The titles that this render set, and whether they all came from a `<title>` in `#head`. */
|
|
864
873
|
private titles;
|
|
865
874
|
private onBoundary;
|
|
875
|
+
/** The `#try` blocks of the parents of this context, from the outside in. */
|
|
876
|
+
outer: Catcher[];
|
|
877
|
+
/** The `#try` blocks of this context that are rendering their bodies now. */
|
|
878
|
+
private readonly catchers;
|
|
866
879
|
/** The scope that renders the next component, which becomes its owner. */
|
|
867
880
|
private owner;
|
|
868
881
|
/**
|
|
@@ -876,6 +889,8 @@ declare class Context {
|
|
|
876
889
|
private rpcPrefix;
|
|
877
890
|
/** The ID of the build, for forms that post to server functions. See `RenderOptions`. */
|
|
878
891
|
build: string | undefined;
|
|
892
|
+
/** True in development, where a memo that failed or a `#catch` sends its error to the browser. */
|
|
893
|
+
development: boolean;
|
|
879
894
|
/** Results of server functions that a form posted to this page, for `$action`. */
|
|
880
895
|
actions: Map<unknown, unknown>;
|
|
881
896
|
/** The params of the route of the page, for `$route`. */
|
|
@@ -919,6 +934,8 @@ declare class Context {
|
|
|
919
934
|
leave(): void;
|
|
920
935
|
/** Returns the URL prefix of server function calls. */
|
|
921
936
|
rpc(): string;
|
|
937
|
+
/** True when the render is in development. */
|
|
938
|
+
isDev(): boolean;
|
|
922
939
|
/** Returns the ID of the build, when the render has one. */
|
|
923
940
|
buildId(): string | undefined;
|
|
924
941
|
/**
|
|
@@ -934,7 +951,9 @@ declare class Context {
|
|
|
934
951
|
* keep `from`, the scope of the markup that wrote them, for their values,
|
|
935
952
|
* and find their contexts from `at`.
|
|
936
953
|
*/
|
|
937
|
-
children(from: ScopeId, at: ScopeId, renderBody: () => Promise<string
|
|
954
|
+
children(from: ScopeId, at: ScopeId, renderBody: () => Promise<string>, tag?: string): Promise<string>;
|
|
955
|
+
/** The tag of the element where the children that render now are inserted, for spacers. */
|
|
956
|
+
spacerTag(): string;
|
|
938
957
|
/**
|
|
939
958
|
* The ID that `$id()` makes: the scope's ID and the position of the call.
|
|
940
959
|
* A dot in a scope ID inside a `#loading` body becomes `_`, so the ID also
|
|
@@ -946,9 +965,9 @@ declare class Context {
|
|
|
946
965
|
/** Provides a value of a context to the scopes inside `scope`. */
|
|
947
966
|
provide<T>(context: Context$1<T>, value: T, scope: ScopeId): void;
|
|
948
967
|
/**
|
|
949
|
-
* Reads a context from the nearest scope that provides it
|
|
950
|
-
*
|
|
951
|
-
*
|
|
968
|
+
* Reads a context from the nearest scope above `scope` that provides it.
|
|
969
|
+
* With `slot`, records which slot holds it, so the client can update it
|
|
970
|
+
* when the provided value changes.
|
|
952
971
|
*/
|
|
953
972
|
consume<T>(context: Context$1<T>, scope: ScopeId, slot?: number): T;
|
|
954
973
|
/** The ID that the next call to `scope()` returns. */
|
|
@@ -981,7 +1000,17 @@ declare class Context {
|
|
|
981
1000
|
* scope, as `[scope, slot]`. The items of a list share one array.
|
|
982
1001
|
*/
|
|
983
1002
|
get sources(): Map<ScopeId, ItemSource>;
|
|
1003
|
+
/** The scope that `unbind` collects the promise props of its component in. */
|
|
1004
|
+
sink(scope: ScopeId): PropSink;
|
|
984
1005
|
slots(scope: ScopeId, values: unknown[], names?: string[]): void;
|
|
1006
|
+
/** Elements that bound props of components forwarded to the slots of scopes that have no slots yet. */
|
|
1007
|
+
private forwards?;
|
|
1008
|
+
/**
|
|
1009
|
+
* Writes the element that a component forwards to a slot of a scope above it, and on through
|
|
1010
|
+
* the props that scope binds in turn. The parent records its slots after its children render,
|
|
1011
|
+
* so a write for a scope that has none waits for them.
|
|
1012
|
+
*/
|
|
1013
|
+
private forward;
|
|
985
1014
|
/**
|
|
986
1015
|
* Records the props that a parent bound with `$bind`, among the props that
|
|
987
1016
|
* the component writes: `slots` has the slot of each, by its name. Its
|
|
@@ -996,6 +1025,11 @@ declare class Context {
|
|
|
996
1025
|
item(scope: ScopeId, value: unknown, source?: ItemSource): void;
|
|
997
1026
|
/** Records the scope of a child component at an anchor of its parent. */
|
|
998
1027
|
link(scope: ScopeId, anchor: number, child: ScopeId): void;
|
|
1028
|
+
/**
|
|
1029
|
+
* A `ref` that the rest props of a component hold is a binding of a signal above. The element
|
|
1030
|
+
* that spreads them goes to that signal, as when the component names `ref` itself.
|
|
1031
|
+
*/
|
|
1032
|
+
restRef<T extends Record<string, unknown>>(attributes: T, scope: ScopeId, anchor: number, tag?: unknown): T;
|
|
999
1033
|
/** Returns the reference that a `ref` signal holds on the server. */
|
|
1000
1034
|
element(scope: ScopeId, anchor: number): ElementReference;
|
|
1001
1035
|
/**
|
|
@@ -1051,6 +1085,11 @@ declare class Context {
|
|
|
1051
1085
|
fallbackStart(id: ScopeId): string;
|
|
1052
1086
|
/** Ends the fallback that `fallbackStart` started. */
|
|
1053
1087
|
fallbackEnd(id: ScopeId): string;
|
|
1088
|
+
/**
|
|
1089
|
+
* Starts a `#try` body. A `#loading` body inside it that fails renders the `#catch` body with
|
|
1090
|
+
* `draw`, after the page is sent. The returned function ends the `#try` body.
|
|
1091
|
+
*/
|
|
1092
|
+
catcher(key: string, draw: Catcher["render"]): () => void;
|
|
1054
1093
|
/** Returns the ID of a new `#loading` boundary. */
|
|
1055
1094
|
boundary(): ScopeId;
|
|
1056
1095
|
/** Renders a `#loading` body after the rest of the page, in its own context and ID space. */
|
|
@@ -1099,9 +1138,9 @@ declare function wait(node: Memo): Promise<unknown>;
|
|
|
1099
1138
|
declare function ready(node: Memo): unknown;
|
|
1100
1139
|
/**
|
|
1101
1140
|
* The value of a memo for the page state: its value when it is ready, or
|
|
1102
|
-
* a promise of it while it loads. A memo that fails gives a
|
|
1103
|
-
*
|
|
1104
|
-
* browser
|
|
1141
|
+
* a promise of it while it loads. A memo that fails gives a `MemoError`
|
|
1142
|
+
* either way, so the page renders, the stream goes on, and a read in the
|
|
1143
|
+
* browser throws the error as a memo that failed there.
|
|
1105
1144
|
*/
|
|
1106
1145
|
declare function stateValue(node: Memo): unknown;
|
|
1107
1146
|
/**
|
|
@@ -1122,14 +1161,19 @@ declare function settled(nodes: Memo[]): boolean;
|
|
|
1122
1161
|
declare const LAZY: unique symbol;
|
|
1123
1162
|
/** Markup that renders where it is inserted, so it can read the contexts there. */
|
|
1124
1163
|
interface Lazy {
|
|
1125
|
-
[LAZY]: (ctx: Context, scope: ScopeId | undefined) => Promise<string>;
|
|
1164
|
+
[LAZY]: (ctx: Context, scope: ScopeId | undefined, tag?: string, anchor?: number) => Promise<string>;
|
|
1126
1165
|
}
|
|
1127
1166
|
/**
|
|
1128
1167
|
* The children of a component, which render where the component inserts
|
|
1129
1168
|
* them, so they read the contexts that the component provides. `from` is the
|
|
1130
1169
|
* scope of the markup that wrote them.
|
|
1131
1170
|
*/
|
|
1132
|
-
declare function children(from: ScopeId, renderBody: (ctx: Context) => Promise<string
|
|
1171
|
+
declare function children(from: ScopeId, renderBody: (ctx: Context) => Promise<string>, ref?: string): Lazy;
|
|
1172
|
+
/**
|
|
1173
|
+
* The tag of the spacers of a windowed list in children: a row in a table body, an item in a
|
|
1174
|
+
* list, as the element where the children are inserted says, or else a `div`.
|
|
1175
|
+
*/
|
|
1176
|
+
declare function spacerTag(ctx: Context): string;
|
|
1133
1177
|
/** Makes markup that renders where it is inserted, such as the children of a layout. */
|
|
1134
1178
|
declare function lazy(renderAt: (ctx: Context, scope: ScopeId | undefined) => Promise<string>): Lazy;
|
|
1135
1179
|
/** Renders the attributes of a form or button that posts to a server function. */
|
|
@@ -1140,18 +1184,18 @@ declare function action(ctx: Context, name: string, id: string, method?: string,
|
|
|
1140
1184
|
*/
|
|
1141
1185
|
declare function actionResult(ctx: Context, fn: unknown): unknown;
|
|
1142
1186
|
/**
|
|
1143
|
-
* Renders a value inserted in markup. `ctx` and `
|
|
1144
|
-
* inserted, for markup that renders there.
|
|
1187
|
+
* Renders a value inserted in markup. `ctx`, `scope` and `anchor` are where it
|
|
1188
|
+
* is inserted, for markup that renders there.
|
|
1145
1189
|
*/
|
|
1146
|
-
declare function insert(value: unknown, ctx?: Context, scope?: ScopeId): string | Promise<string>;
|
|
1147
|
-
type Component<P = any> = (props: P, ctx: Context) => Promise<string>;
|
|
1190
|
+
declare function insert(value: unknown, ctx?: Context, scope?: ScopeId, tag?: string, anchor?: number): string | Promise<string>;
|
|
1191
|
+
type Component<P = any> = (props: P, ctx: Context) => Promise<string | object>;
|
|
1148
1192
|
/**
|
|
1149
1193
|
* Renders a child component. With `scope` and `anchor`, records the child's
|
|
1150
1194
|
* scope so the parent can update its props on the client.
|
|
1151
1195
|
*/
|
|
1152
|
-
declare function component<P>(Child: Component<P>, props: P, ctx: Context, scope?: ScopeId, anchor?: number): Promise<string>;
|
|
1196
|
+
declare function component<P>(Child: Component<P>, props: P, ctx: Context, scope?: ScopeId, anchor?: number, paragraph?: string): Promise<string>;
|
|
1153
1197
|
/** Renders a dynamic tag, which can be an element name or a component. */
|
|
1154
|
-
declare function dynamic(tag: string | Component, attributes: Record<string, unknown>, content: Raw | Lazy | undefined, ctx: Context, scope?: ScopeId): string | Promise<string>;
|
|
1198
|
+
declare function dynamic(tag: string | Component, attributes: Record<string, unknown>, content: Raw | Lazy | undefined, ctx: Context, scope?: ScopeId, ref?: unknown): string | Promise<string>;
|
|
1155
1199
|
/** The records of the scopes of a render, by scope ID. */
|
|
1156
1200
|
type StateMap = Map<ScopeId, ScopeState>;
|
|
1157
1201
|
/**
|
|
@@ -1182,6 +1226,10 @@ interface StateAttributes {
|
|
|
1182
1226
|
params?: Record<string, string>;
|
|
1183
1227
|
/** The ID of the build that rendered the page, on its first record, for skew protection. */
|
|
1184
1228
|
build?: string;
|
|
1229
|
+
/** The ID of a `#loading` boundary whose body failed. The record is the error. */
|
|
1230
|
+
fail?: ScopeId;
|
|
1231
|
+
/** The marker of a `#try` whose `#catch` body replaces its body, from the template `b-c`. */
|
|
1232
|
+
catches?: string;
|
|
1185
1233
|
}
|
|
1186
1234
|
/**
|
|
1187
1235
|
* Returns the script of a state record. `scopes` marks a record with scopes,
|
|
@@ -1333,6 +1381,14 @@ type StreamOptions = DocumentOptions;
|
|
|
1333
1381
|
declare function renderToStream<P>(Root: Component<P>, props: P, options?: DocumentOptions): ReadableStream<string>;
|
|
1334
1382
|
/** Streams the parts of a page from `render`: the first render whole, then what resolves later. */
|
|
1335
1383
|
declare function streamParts(parts: RenderResult, options?: DocumentOptions): ReadableStream<string>;
|
|
1384
|
+
/**
|
|
1385
|
+
* The error that a `#catch` body gets on the server, which the page state carries to the
|
|
1386
|
+
* browser. In development it is the error itself, for debugging. In production it is a plain
|
|
1387
|
+
* `Error` with the message of a `ServerError`, or a generic message, and the real error is
|
|
1388
|
+
* logged, as for a server function that fails. The body renders with this value too, so the
|
|
1389
|
+
* HTML cannot print what the state does not carry.
|
|
1390
|
+
*/
|
|
1391
|
+
declare function caught(error: unknown, ctx: Context): unknown;
|
|
1336
1392
|
interface RequestOptions {
|
|
1337
1393
|
/**
|
|
1338
1394
|
* Other origins that may call server functions and post forms to them,
|
|
@@ -1425,6 +1481,12 @@ interface RouteOptions extends DocumentOptions, RequestOptions {
|
|
|
1425
1481
|
* passes them from the client build.
|
|
1426
1482
|
*/
|
|
1427
1483
|
hints?: string[];
|
|
1484
|
+
/**
|
|
1485
|
+
* The URLs of the bundle of each root component, such as a route or a layout, by component ID:
|
|
1486
|
+
* its chunk and the chunks that it imports. A page adds those of its views to `hints`, so the
|
|
1487
|
+
* code of the page loads with the HTML. `virtual:brumate/routes` passes them.
|
|
1488
|
+
*/
|
|
1489
|
+
bundleHints?: Record<string, string[]>;
|
|
1428
1490
|
/**
|
|
1429
1491
|
* Receives the `Link` values of `hints` before the page renders, so a
|
|
1430
1492
|
* server can send them as `103 Early Hints`, such as with Node's
|
|
@@ -1454,7 +1516,7 @@ declare function handleRoute(tree: RouteNode, request: Request, options?: RouteO
|
|
|
1454
1516
|
* function belongs to and the modifiers of its wrappers. A function that
|
|
1455
1517
|
* refers to nothing in the browser is left out.
|
|
1456
1518
|
*/
|
|
1457
|
-
declare function spread(attributes: Record<string, unknown>, on?: string[]): string;
|
|
1519
|
+
declare function spread(attributes: Record<string, unknown>, on?: string[], names?: boolean): string;
|
|
1458
1520
|
//#endregion
|
|
1459
|
-
export {
|
|
1460
|
-
//# sourceMappingURL=server-
|
|
1521
|
+
export { memoryStore as $, createSession as $t, insert as A, Middleware as At, spacerTag as B, RequestEvent as Bt, caught as C, fieldErrors as Ct, handleRequest as D, EndpointLoader as Dt, dynamic as E, safeParse as Et, read as F, matchRoute as Ft, streamState as G, defineMiddleware as Gt, stateScript as H, RequestKind as Ht, ready as I, EntryMiddleware as It, IdempotentOptions as J, redirect as Jt, wait as K, getEvent as Kt, render as L, Locals as Lt, lazy as M, RouteMatch as Mt, memo as N, RouteNode as Nt, handleRoute as O, Handler as Ot, packState as P, RouteView as Pt, cached as Q, SessionOptions as Qt, renderToStream as R, Redirect as Rt, binding as S, ValidationIssue as St, component as T, parseForm as Tt, stateValue as U, ServerError as Ut, spread as V, RequestEventOptions as Vt, streamParts as W, dedupe as Wt, CacheStore as X, CookieOptions as Xt, idempotent as Y, withEvent as Yt, CachedOptions as Z, Session as Zt, StateAttributes as _, SubmissionOptions as _t, ItemSource as a, RateLimitError as at, action as b, ParseResult as bt, Memo as c, RateLimitStore as ct, RenderOptions as d, configureRateLimit as dt, parseCookies as en, revalidate as et, RenderResult as f, rateLimit as ft, ScopeEntry as g, Submission as gt, RouteOptions as h, ReplyOptions as ht, DocumentOptions as i, RateLimitConfig as it, isCrossSite as j, MiddlewareLoader as jt, inlineBodies as k, Loader as kt, NotReady as l, Window as lt, RevealOrder as m, IntentSubmission as mt, Context as n, toNodeHeaders as nn, storageStore as nt, Lazy as o, RateLimitMiddleware as ot, RequestOptions as p, FailedSubmission as pt, waitAll as q, isRedirect as qt, DeferTarget as r, RateLimit as rt, Mark as s, RateLimitOptions as st, Component as t, serializeCookie as tn, setCacheStore as tt, PageCache as u, clientAddress as ut, StateMap as v, SuccessfulSubmission as vt, children as w, parse as wt, actionResult as x, ValidationError as xt, StreamOptions as y, parseSubmission as yt, settled as z, RequestCall as zt };
|
|
1522
|
+
//# sourceMappingURL=server-BvPIg9pT.d.ts.map
|