brumate 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/{boot-DN1ZU8Hg.d.ts → boot-C25Sa6vq.d.ts} +27 -2
  2. package/dist/cli.js +2 -2
  3. package/dist/client-BD6XT-s5.js +1968 -0
  4. package/dist/client-BD6XT-s5.js.map +1 -0
  5. package/dist/{client-DwJInP_a.d.ts → client-D0CqSxoO.d.ts} +211 -30
  6. package/dist/{client-routes-DakuM32C.js → client-routes-JTbGtukf.js} +28 -15
  7. package/dist/client-routes-JTbGtukf.js.map +1 -0
  8. package/dist/context-CTiSzQRc.js +27 -0
  9. package/dist/context-CTiSzQRc.js.map +1 -0
  10. package/dist/context-btHuB01Z.d.ts +42 -0
  11. package/dist/{cookies-Av5WFmcf.js → cookies-BzllthiF.js} +2 -1
  12. package/dist/cookies-BzllthiF.js.map +1 -0
  13. package/dist/defer-BbD7JQhj.js +56 -0
  14. package/dist/defer-BbD7JQhj.js.map +1 -0
  15. package/dist/devtools-CQgD7NPB.js +623 -0
  16. package/dist/devtools-CQgD7NPB.js.map +1 -0
  17. package/dist/devtools-panel-BVB-W5q4.js +1930 -0
  18. package/dist/devtools-panel-BVB-W5q4.js.map +1 -0
  19. package/dist/events-CSs7OwIC.js +85 -0
  20. package/dist/events-CSs7OwIC.js.map +1 -0
  21. package/dist/{files-DdT84mPy.js → files-BXSSrQgc.js} +34 -6
  22. package/dist/files-BXSSrQgc.js.map +1 -0
  23. package/dist/forms-Bg-CwGqX.js +406 -0
  24. package/dist/forms-Bg-CwGqX.js.map +1 -0
  25. package/dist/forms-Cl21hkHt.d.ts +281 -0
  26. package/dist/highlight.d.ts +17 -0
  27. package/dist/highlight.js +269 -0
  28. package/dist/highlight.js.map +1 -0
  29. package/dist/html-Bq1rFxX_.d.ts +92 -0
  30. package/dist/html-mNTKzaDD.js +241 -0
  31. package/dist/html-mNTKzaDD.js.map +1 -0
  32. package/dist/index.d.ts +123 -30
  33. package/dist/index.js +14 -6
  34. package/dist/index.js.map +1 -1
  35. package/dist/{inspect-BPchdWbU.js → inspect-BHpOw1LF.js} +1400 -121
  36. package/dist/inspect-BHpOw1LF.js.map +1 -0
  37. package/dist/{loader-Dc9OwY5I.js → loader-Dos_3NP0.js} +47 -11
  38. package/dist/loader-Dos_3NP0.js.map +1 -0
  39. package/dist/{navigate-CzLjnoPH.js → navigate-O78d_zGN.js} +115 -13
  40. package/dist/navigate-O78d_zGN.js.map +1 -0
  41. package/dist/produce-D0V0ICkz.d.ts +114 -0
  42. package/dist/produce-Doc91GkX.js +274 -0
  43. package/dist/produce-Doc91GkX.js.map +1 -0
  44. package/dist/routes-BZNt7DSZ.d.ts +38 -0
  45. package/dist/{rpc-9fSqL_YK.js → rpc-ygMRPmN4.js} +39 -23
  46. package/dist/rpc-ygMRPmN4.js.map +1 -0
  47. package/dist/runtime/batch.d.ts +23 -0
  48. package/dist/runtime/batch.js +69 -0
  49. package/dist/runtime/batch.js.map +1 -0
  50. package/dist/runtime/client.d.ts +5 -5
  51. package/dist/runtime/client.js +5 -1345
  52. package/dist/runtime/context.d.ts +2 -2
  53. package/dist/runtime/context.js +1 -1
  54. package/dist/runtime/devtools.d.ts +191 -5
  55. package/dist/runtime/devtools.js +1 -1
  56. package/dist/runtime/env.d.ts +44 -0
  57. package/dist/runtime/env.js +61 -0
  58. package/dist/runtime/env.js.map +1 -0
  59. package/dist/runtime/events.d.ts +42 -0
  60. package/dist/runtime/events.js +1 -0
  61. package/dist/runtime/forms.d.ts +2 -0
  62. package/dist/runtime/forms.js +1 -0
  63. package/dist/runtime/gather.d.ts +25 -0
  64. package/dist/runtime/gather.js +33 -0
  65. package/dist/runtime/gather.js.map +1 -0
  66. package/dist/runtime/hot.d.ts +1 -1
  67. package/dist/runtime/html.d.ts +2 -2
  68. package/dist/runtime/html.js +1 -1
  69. package/dist/runtime/loader.d.ts +2 -2
  70. package/dist/runtime/loader.js +2 -2
  71. package/dist/runtime/routes.d.ts +2 -21
  72. package/dist/runtime/routes.js +31 -1
  73. package/dist/runtime/routes.js.map +1 -1
  74. package/dist/runtime/server.d.ts +7 -5
  75. package/dist/runtime/server.js +6 -7
  76. package/dist/runtime/signals.d.ts +60 -3
  77. package/dist/runtime/signals.js +40 -2
  78. package/dist/runtime/signals.js.map +1 -1
  79. package/dist/runtime/static-loader.d.ts +2 -2
  80. package/dist/runtime/static-loader.js +1 -1
  81. package/dist/runtime/testing.d.ts +46 -5
  82. package/dist/runtime/testing.js +240 -33
  83. package/dist/runtime/testing.js.map +1 -1
  84. package/dist/runtime/values.d.ts +2 -0
  85. package/dist/runtime/values.js +24 -0
  86. package/dist/runtime/values.js.map +1 -0
  87. package/dist/secrets-BxagsJxJ.js +23 -0
  88. package/dist/secrets-BxagsJxJ.js.map +1 -0
  89. package/dist/server-CxVDYE_V.js +3417 -0
  90. package/dist/server-CxVDYE_V.js.map +1 -0
  91. package/dist/server-DuFYRXrd.d.ts +1460 -0
  92. package/dist/skew-FRmAy9iy.js +49 -0
  93. package/dist/skew-FRmAy9iy.js.map +1 -0
  94. package/dist/standard-schema-BNY82yX3.d.ts +63 -0
  95. package/dist/{static-loader-BcFh4ebX.d.ts → static-loader-Drpr0AzI.d.ts} +2 -2
  96. package/dist/static-loader-nZssh66R.js +333 -0
  97. package/dist/static-loader-nZssh66R.js.map +1 -0
  98. package/dist/stream-DCYZO4IF.js +424 -0
  99. package/dist/stream-DCYZO4IF.js.map +1 -0
  100. package/dist/values-B8C7CLvG.d.ts +63 -0
  101. package/dist/vite.d.ts +49 -1
  102. package/dist/vite.js +598 -68
  103. package/dist/vite.js.map +1 -1
  104. package/forms/forms.brm.ts +141 -0
  105. package/package.json +45 -3
  106. package/types.d.ts +9 -1
  107. package/dist/client-routes-DakuM32C.js.map +0 -1
  108. package/dist/context-BG8KCF3v.js +0 -15
  109. package/dist/context-BG8KCF3v.js.map +0 -1
  110. package/dist/context-aeo9esY9.d.ts +0 -16
  111. package/dist/cookies-Av5WFmcf.js.map +0 -1
  112. package/dist/devtools-BKjnHrnv.js +0 -113
  113. package/dist/devtools-BKjnHrnv.js.map +0 -1
  114. package/dist/devtools-panel-AWOn0VK2.js +0 -434
  115. package/dist/devtools-panel-AWOn0VK2.js.map +0 -1
  116. package/dist/files-DdT84mPy.js.map +0 -1
  117. package/dist/html-DEeoepg3.js +0 -152
  118. package/dist/html-DEeoepg3.js.map +0 -1
  119. package/dist/html-Du8jY2Cc.d.ts +0 -53
  120. package/dist/inspect-BPchdWbU.js.map +0 -1
  121. package/dist/loader-Dc9OwY5I.js.map +0 -1
  122. package/dist/navigate-CzLjnoPH.js.map +0 -1
  123. package/dist/produce-BRGHP7e0.js +0 -126
  124. package/dist/produce-BRGHP7e0.js.map +0 -1
  125. package/dist/produce-CtZ32UGG.d.ts +0 -60
  126. package/dist/rpc-9fSqL_YK.js.map +0 -1
  127. package/dist/runtime/client.js.map +0 -1
  128. package/dist/server-BxqjLUnV.d.ts +0 -753
  129. package/dist/server-DZsgnPKS.js +0 -1615
  130. package/dist/server-DZsgnPKS.js.map +0 -1
  131. package/dist/shared-CWYOd0H3.js +0 -40
  132. package/dist/shared-CWYOd0H3.js.map +0 -1
  133. package/dist/static-loader-ClNkHZGn.js +0 -185
  134. package/dist/static-loader-ClNkHZGn.js.map +0 -1
  135. package/dist/stream-bgNCMcaA.js +0 -280
  136. package/dist/stream-bgNCMcaA.js.map +0 -1
@@ -0,0 +1,1460 @@
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
+ import { t as Context$1 } from "./context-btHuB01Z.js";
4
+ import { t as StandardSchemaV1 } from "./standard-schema-BNY82yX3.js";
5
+ import { f as Intent, v as SubmissionResult } from "./forms-Cl21hkHt.js";
6
+ //#region src/runtime/cookies.d.ts
7
+ interface CookieOptions {
8
+ /** Seconds until the cookie expires. Without it, the cookie lasts until the browser closes. */
9
+ maxAge?: number;
10
+ expires?: Date;
11
+ /** Defaults to `/`. */
12
+ path?: string;
13
+ domain?: string;
14
+ /** Defaults to true when the request is HTTPS. */
15
+ secure?: boolean;
16
+ /** Keeps the cookie from browser code. Defaults to true. */
17
+ httpOnly?: boolean;
18
+ /** Defaults to `lax`. */
19
+ sameSite?: "strict" | "lax" | "none";
20
+ }
21
+ /** Reads the cookies of a `cookie` header. */
22
+ declare function parseCookies(header: string | null): Record<string, string>;
23
+ /** Writes a `set-cookie` header value. */
24
+ declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
25
+ interface SessionOptions {
26
+ /**
27
+ * Signs the cookie, so a browser cannot change it. Use a random string of
28
+ * at least 32 characters, kept out of the code, such as in an environment
29
+ * variable. A list signs with the first and accepts all, for changing it.
30
+ */
31
+ secret: string | string[];
32
+ /** The name of the cookie. Defaults to `session`. */
33
+ name?: string;
34
+ /** Seconds until the session expires. Defaults to 7 days. */
35
+ maxAge?: number;
36
+ /** Other options of the cookie. */
37
+ cookie?: Omit<CookieOptions, "maxAge" | "expires">;
38
+ }
39
+ interface Session<T> {
40
+ /** The data of the session, or undefined when there is none, it expired, or its signature does not match. */
41
+ get(event: RequestEvent): Promise<T | undefined>;
42
+ /** Replaces the data of the session, and starts its time again. */
43
+ set(event: RequestEvent, data: T): Promise<void>;
44
+ /** Changes some fields of the data, and returns the new data. */
45
+ update(event: RequestEvent, change: Partial<T>): Promise<T>;
46
+ /** Ends the session. */
47
+ clear(event: RequestEvent): void;
48
+ }
49
+ /**
50
+ * A session in a signed cookie. The browser can read the data, but cannot
51
+ * change it, so keep secrets out of it: store an ID, and look the rest up
52
+ * on the server.
53
+ *
54
+ * ```ts
55
+ * export const session = createSession<{ userId: string }>({ secret: process.env.SESSION_SECRET! });
56
+ *
57
+ * async function login(form: FormData) {
58
+ * 'use server';
59
+ * const event = getEvent();
60
+ * await session.set(event, { userId: await checkPassword(form) });
61
+ * }
62
+ * ```
63
+ */
64
+ declare function createSession<T>(options: SessionOptions): Session<T>;
65
+ /**
66
+ * The headers of a response for Node's `writeHead`, with each `set-cookie`
67
+ * apart. `Object.fromEntries(headers)` joins them into one, which browsers
68
+ * read as a single cookie.
69
+ */
70
+ declare function toNodeHeaders(headers: Headers): Record<string, string | string[]>;
71
+ //#endregion
72
+ //#region src/runtime/request.d.ts
73
+ /**
74
+ * What a request is for. A form post to a server function is a call, and a
75
+ * form post to a page with `?__action=<id>` is a page.
76
+ */
77
+ type RequestKind = "page" | "endpoint" | "call" | "defer";
78
+ /**
79
+ * Values that middleware hands to the components, server functions and
80
+ * endpoints of a request, such as the user. An app adds fields to it:
81
+ *
82
+ * ```ts
83
+ * declare module 'brumate/server' {
84
+ * interface Locals {
85
+ * user?: { id: string; name: string };
86
+ * }
87
+ * }
88
+ * ```
89
+ */
90
+ interface Locals {}
91
+ /** The server function that a request calls, with its arguments as they were read. */
92
+ interface RequestCall {
93
+ id: string;
94
+ args: unknown[];
95
+ }
96
+ interface RequestEventOptions {
97
+ kind?: RequestKind;
98
+ /**
99
+ * Keeps work going after the response ends, such as the `waitUntil` of
100
+ * Cloudflare Workers. Without it, the promise runs on its own and its
101
+ * error is logged.
102
+ */
103
+ waitUntil?: (promise: Promise<unknown>) => void;
104
+ /**
105
+ * The address of the client as the server saw it, such as the remote
106
+ * address of the socket. `clientAddress` reads it, and looks past the
107
+ * trusted proxies in `X-Forwarded-For` when it is one of them.
108
+ */
109
+ address?: string;
110
+ /** True while the build prerenders the page. Rate limits do not count then. */
111
+ prerender?: boolean;
112
+ }
113
+ /**
114
+ * A request that the server handles: a server function call, a form post,
115
+ * a page render, or a call of middleware or an endpoint. Its methods read
116
+ * the request and change the response. Get it with `getEvent()`.
117
+ */
118
+ /** A step of the render of a page, for the Server tab of the devtools. */
119
+ interface TraceEntry {
120
+ kind: "render" | "stream" | "memo" | "call" | "body";
121
+ label: string;
122
+ start: number;
123
+ /** Undefined while it runs. */
124
+ end?: number;
125
+ failed?: boolean;
126
+ }
127
+ declare class RequestEvent {
128
+ readonly request: Request;
129
+ /** What the request is for. */
130
+ readonly kind: RequestKind;
131
+ /** For a call, and a page that a form posted to, the server function and its arguments. */
132
+ call?: RequestCall;
133
+ /** Values for this request, which middleware writes and the rest of the request reads. */
134
+ readonly locals: Locals;
135
+ /** The address of the client as the server saw it, when the server passed it. */
136
+ readonly address?: string;
137
+ /** True while the build prerenders the page. */
138
+ readonly prerender: boolean;
139
+ /**
140
+ * The pattern of the route files that matched the path, such as
141
+ * `/todos/[id]`. `handleRoute` sets it. Undefined for a path that no route
142
+ * matches.
143
+ */
144
+ route?: string;
145
+ /** Headers to add to the response, such as `cache-control`. */
146
+ readonly headers: Headers;
147
+ /** The status that `setStatus` set. */
148
+ status?: number;
149
+ /** Server functions that `refresh` named, whose memos the client loads again. */
150
+ refreshed?: Set<unknown>;
151
+ /** Cookies that this request set, or deleted with undefined, so later reads see them. */
152
+ cookies?: Map<string, string | undefined>;
153
+ /**
154
+ * True once the request read its cookies or its `authorization` header, or
155
+ * set a cookie, such as for a session. The answer then depends on the user,
156
+ * so a page with `cache` is not cached for everyone.
157
+ */
158
+ personal: boolean;
159
+ /**
160
+ * In development, what the render of the page did and when, in
161
+ * milliseconds from its start, for the Server tab of the devtools.
162
+ */
163
+ trace?: TraceEntry[];
164
+ /** When the trace started, by `performance.now()`. */
165
+ traceStart: number;
166
+ /** Starts an entry of the trace, when there is one, and returns what ends it. */
167
+ traced(kind: TraceEntry["kind"], label: string): (failed?: boolean) => void;
168
+ /**
169
+ * The tags of the `cached` functions that the request called, with the
170
+ * version that each had then, so `revalidate` drops the page that it renders.
171
+ */
172
+ readonly cacheTags: Map<string, string | undefined>;
173
+ private readonly controller;
174
+ /**
175
+ * Aborts when the request no longer needs an answer: the request's own
176
+ * signal aborts, or the reader of the response went away, such as a
177
+ * browser that left the page while it streamed. Pass it on, such as to
178
+ * `fetch(url, { signal })`, so work that nobody waits for stops.
179
+ */
180
+ readonly signal: AbortSignal;
181
+ private readonly keepGoing?;
182
+ constructor(request: Request, options?: RequestEventOptions);
183
+ /** Aborts `signal`, such as when the response's reader went away. The server calls it. */
184
+ abort(reason?: unknown): void;
185
+ /**
186
+ * Keeps work going after the response ends, such as a log line or
187
+ * analytics. On a host that stops a function when its response ends, the
188
+ * server passes the promise to the host, through the `waitUntil` option.
189
+ * Elsewhere the promise runs on its own, and its error is logged.
190
+ */
191
+ waitUntil(promise: Promise<unknown>): void;
192
+ /**
193
+ * Sets the status of the page response, such as 404 for a page that shows
194
+ * that nothing was found. It works while the first render of a page runs.
195
+ * Markup that streams later, such as a `#loading` body, cannot change it,
196
+ * because the response has started by then.
197
+ */
198
+ setStatus(status: number): void;
199
+ /**
200
+ * Asks the client to load again the memos that call a server function, such
201
+ * as a list after a server function adds to it. The compiler gives those
202
+ * memos client code, so they can load.
203
+ */
204
+ refresh(fn: (...args: never[]) => unknown): void;
205
+ /** The cookies of the request, with the ones that this request set or deleted. */
206
+ getCookies(): Record<string, string>;
207
+ /** A cookie of the request, or the value that this request set. */
208
+ getCookie(name: string): string | undefined;
209
+ /**
210
+ * Sets a cookie on the response. It is `HttpOnly`, `SameSite=Lax` and on
211
+ * the path `/` unless the options say otherwise, and `Secure` on HTTPS.
212
+ * Markup that streams later, such as a `#loading` body, cannot set cookies,
213
+ * because the response has started.
214
+ */
215
+ setCookie(name: string, value: string, options?: CookieOptions): void;
216
+ /** Deletes a cookie. Pass the `path` and `domain` that it was set with, if they were not the defaults. */
217
+ deleteCookie(name: string, options?: Pick<CookieOptions, "path" | "domain">): void;
218
+ }
219
+ /**
220
+ * Runs a callback with an event, so `getEvent()` in its code before its first
221
+ * `await` returns it. Returns what the callback returns, such as its promise.
222
+ * `calls`, while a page renders, lets calls with the same arguments share a result.
223
+ */
224
+ declare function withEvent<T>(event: RequestEvent | undefined, callback: () => T, calls?: Map<string, unknown>): T;
225
+ /**
226
+ * Returns the event of the request that the server handles: in a server
227
+ * function, middleware or an endpoint, or while a component renders.
228
+ *
229
+ * Call it before the first `await` of the function, and keep it in a
230
+ * variable. After an `await`, other requests may have run, so it throws.
231
+ *
232
+ * ```ts
233
+ * async function save(todo: Todo) {
234
+ * 'use server';
235
+ * const event = getEvent();
236
+ * await db.save(todo);
237
+ * event.setCookie('saved', todo.id);
238
+ * }
239
+ * ```
240
+ */
241
+ declare function getEvent(): RequestEvent;
242
+ /**
243
+ * Middleware that runs for every request of the app: pages, endpoints,
244
+ * server function calls, form posts and the requests for `#defer` bodies.
245
+ * It answers the request itself, or calls `next` for the answer and returns
246
+ * it, changed or not. `event.kind` says what the request is for.
247
+ */
248
+ type EntryMiddleware = (event: RequestEvent, next: () => Promise<Response>) => Response | Promise<Response>;
249
+ /**
250
+ * Types the middleware of the entry file, `src/middleware.ts`, which the
251
+ * Vite plugin runs for every request:
252
+ *
253
+ * ```ts
254
+ * export default defineMiddleware(async (event, next) => {
255
+ * event.locals.user = await readUser(event);
256
+ * return next();
257
+ * });
258
+ * ```
259
+ */
260
+ declare function defineMiddleware(middleware: EntryMiddleware): EntryMiddleware;
261
+ declare function dedupe<F extends (...args: any[]) => unknown>(fn: F, id: string): F;
262
+ /**
263
+ * An error whose message reaches the client. A server function call that
264
+ * throws it rejects with the message, and the response has its status.
265
+ * Other errors reach the client as a generic message, so server details stay
266
+ * on the server.
267
+ */
268
+ declare class ServerError extends Error {
269
+ readonly status: number;
270
+ constructor(message: string, options?: {
271
+ status?: number;
272
+ });
273
+ }
274
+ /** Thrown by `redirect`. */
275
+ declare class Redirect extends Error {
276
+ readonly location: string;
277
+ readonly status: number;
278
+ constructor(location: string, status: number);
279
+ }
280
+ /**
281
+ * Stops a server function and sends the browser to another page. While a
282
+ * page renders, the error reaches the caller of `render`, which can
283
+ * answer with a redirect.
284
+ */
285
+ declare function redirect(location: string, status?: number): never;
286
+ declare function isRedirect(error: unknown): error is Redirect;
287
+ //#endregion
288
+ //#region src/runtime/router.d.ts
289
+ /** Imports the module of a route file. */
290
+ type Loader = () => Promise<{
291
+ default: Component;
292
+ }>;
293
+ /** Answers a request at the path of an endpoint, for one method. */
294
+ type Handler = (request: Request, params: Record<string, string>) => Response | Promise<Response>;
295
+ /**
296
+ * Runs before the routes of a folder. It answers the request itself, or
297
+ * calls `next` for the answer of the route and returns it, changed or not.
298
+ */
299
+ type Middleware = (request: Request, next: () => Promise<Response>) => Response | Promise<Response>;
300
+ /** Imports `_middleware.ts`. */
301
+ type MiddlewareLoader = () => Promise<{
302
+ middleware: Middleware;
303
+ }>;
304
+ /** Imports an endpoint: a module that exports a handler for each method, such as `GET`. */
305
+ type EndpointLoader = () => Promise<Partial<Record<string, Handler>>>;
306
+ /** A folder of routes, as `virtual:brumate/routes` describes it. */
307
+ interface RouteNode {
308
+ /** `_layout.brm`. */
309
+ layout?: Loader;
310
+ /** `index.brm`, or the file of a segment, such as `about.brm`. */
311
+ page?: Loader;
312
+ /** `_default.brm`: what a slot renders when its routes do not match. */
313
+ fallback?: Loader;
314
+ /** `_error.brm`: renders when a route of the folder throws, or when no route matches. */
315
+ error?: Loader;
316
+ /** `_loading.brm`: shows while a route of the folder streams in. */
317
+ loading?: Loader;
318
+ /** `_middleware.ts`: runs before the routes of the folder. */
319
+ middleware?: MiddlewareLoader;
320
+ /** A `.ts` file at this path, such as `api/todos.ts`. */
321
+ endpoint?: EndpointLoader;
322
+ /** Folders and files with a fixed segment. */
323
+ static?: Record<string, RouteNode>;
324
+ /** `[name]`: one segment, read as `params.name`. */
325
+ dynamic?: {
326
+ name: string;
327
+ node: RouteNode;
328
+ };
329
+ /** `[...name]`: the rest of the path, read as `params.name`. */
330
+ rest?: {
331
+ name: string;
332
+ node: RouteNode;
333
+ };
334
+ /** `@name` folders: routes that render in the `name` slot of the layout. */
335
+ slots?: Record<string, RouteNode>;
336
+ }
337
+ /** A matched route: the component to render, and what renders in its slots. */
338
+ interface RouteView {
339
+ load: Loader;
340
+ /**
341
+ * The file and the params that the view depends on, such as
342
+ * `/todos/[id]/_layout {"id":"3"}`. Two pages with the same key for a
343
+ * layout render the same layout, so the client can keep it.
344
+ */
345
+ key: string;
346
+ /** `children` and the named slots of a layout. */
347
+ slots: Record<string, RouteView>;
348
+ /** `_loading.brm` of the folder: the view streams in, and this shows until then. */
349
+ loading?: Loader;
350
+ }
351
+ interface RouteMatch {
352
+ view: RouteView;
353
+ params: Record<string, string>;
354
+ /** The pattern of the route files that matched, such as `/todos/[id]`, or `/` for the root. */
355
+ route: string;
356
+ /** The endpoint at the path, if the folder has one. */
357
+ endpoint?: EndpointLoader;
358
+ /** The middleware of the folders on the path, from the outside in. */
359
+ middleware: MiddlewareLoader[];
360
+ /**
361
+ * Views that show an error in place of the route, from the innermost
362
+ * `_error.brm` to the outermost. Each renders inside the layouts above it.
363
+ */
364
+ errors: RouteView[];
365
+ }
366
+ /** Finds the route for a path. A path with a malformed escape, such as `/%E0`, matches none. */
367
+ declare function matchRoute(tree: RouteNode, pathname: string): RouteMatch | undefined;
368
+ //#endregion
369
+ //#region src/runtime/validate.d.ts
370
+ /**
371
+ * A problem that a schema found, as plain data that the server can send to
372
+ * the browser. A path segment is a string or a number.
373
+ */
374
+ interface ValidationIssue {
375
+ message: string;
376
+ path?: (string | number)[];
377
+ }
378
+ /** The output of a schema, or the issues that it found. */
379
+ type ParseResult<T> = {
380
+ value: T;
381
+ issues?: undefined;
382
+ } | {
383
+ value?: undefined;
384
+ issues: ValidationIssue[];
385
+ };
386
+ /**
387
+ * The error that `parse` throws when the value does not match. It answers
388
+ * with status 400 and its message, as any `ServerError` does. Its `issues`
389
+ * stay on the server.
390
+ */
391
+ declare class ValidationError extends ServerError {
392
+ readonly issues: ValidationIssue[];
393
+ constructor(issues: ValidationIssue[]);
394
+ }
395
+ /**
396
+ * Validates a value with a Standard Schema. Returns `{ value }` with the
397
+ * output of the schema, or `{ issues }` as plain data. It does not throw for
398
+ * a value that does not match.
399
+ */
400
+ declare function safeParse<S extends StandardSchemaV1>(schema: S, value: unknown): Promise<ParseResult<StandardSchemaV1.InferOutput<S>>>;
401
+ /**
402
+ * Validates a value with a Standard Schema, and returns the output of the
403
+ * schema. A value that does not match throws a `ValidationError`, which
404
+ * answers with status 400 and a message built from the first issue.
405
+ *
406
+ * ```ts
407
+ * async function save(input: unknown) {
408
+ * 'use server';
409
+ * const todo = await parse(Todo, input);
410
+ * await db.todos.save(todo);
411
+ * }
412
+ * ```
413
+ */
414
+ declare function parse<S extends StandardSchemaV1>(schema: S, value: unknown): Promise<StandardSchemaV1.InferOutput<S>>;
415
+ /**
416
+ * Validates the data of a form with a Standard Schema. The entries become a
417
+ * plain object first. Returns `{ value }` or `{ issues }`, and does not throw
418
+ * for data that does not match, so a function of `$action` can return the
419
+ * issues for the page to show.
420
+ *
421
+ * ```ts
422
+ * async function signUp(form: FormData) {
423
+ * 'use server';
424
+ * const result = await parseForm(SignUp, form);
425
+ * if (result.issues) {
426
+ * return { errors: fieldErrors(result.issues) };
427
+ * }
428
+ * }
429
+ * ```
430
+ */
431
+ declare function parseForm<S extends StandardSchemaV1>(schema: S, form: FormData): Promise<ParseResult<StandardSchemaV1.InferOutput<S>>>;
432
+ /**
433
+ * The messages of issues by field, for a page to show next to each field.
434
+ * The key is the path joined with dots, such as `address.city`. Issues
435
+ * without a path, and a path of `__proto__`, are under the key `''`. The
436
+ * result is plain data, so a server function can return it.
437
+ */
438
+ declare function fieldErrors(issues: readonly (StandardSchemaV1.Issue | ValidationIssue)[]): Record<string, string[]>;
439
+ //#endregion
440
+ //#region src/runtime/submission.d.ts
441
+ /** What a server function adds to the reply of a submission. */
442
+ interface ReplyOptions {
443
+ /** Errors of the whole form, such as "That email is taken". */
444
+ formErrors?: string[];
445
+ /** Errors of fields, by field name, such as `{ email: ['That email is taken'] }`. */
446
+ fieldErrors?: Record<string, string[]>;
447
+ /** Sets the form back to its default values, such as after a save. */
448
+ reset?: boolean;
449
+ }
450
+ /** The options of `parseSubmission`. */
451
+ interface SubmissionOptions {
452
+ /**
453
+ * Field names whose values are never sent back, such as `password`. Files
454
+ * are never sent back either, because a file input cannot be filled.
455
+ */
456
+ hide?: string[];
457
+ }
458
+ interface SubmissionBase {
459
+ /** The posted values, after the intent, before the schema. */
460
+ payload: Record<string, unknown> | undefined;
461
+ /** The reply for `createForm`, with the errors of the submission and of `options`. */
462
+ reply(options?: ReplyOptions): SubmissionResult;
463
+ }
464
+ /** A submission whose values passed the schema. */
465
+ interface SuccessfulSubmission<T> extends SubmissionBase {
466
+ status: "success";
467
+ /** The output of the schema. */
468
+ value: T;
469
+ intent?: undefined;
470
+ }
471
+ /** A submission whose values did not pass the schema, or whose names or intent were not allowed. */
472
+ interface FailedSubmission extends SubmissionBase {
473
+ status: "error";
474
+ value?: undefined;
475
+ intent?: Intent;
476
+ issues: ValidationIssue[];
477
+ }
478
+ /** A submission of an intent button, such as "Add an item". It is not a save. */
479
+ interface IntentSubmission extends SubmissionBase {
480
+ status: "intent";
481
+ value?: undefined;
482
+ intent: Intent;
483
+ }
484
+ /** A submission of a form: a success, an error, or an intent. */
485
+ type Submission<T> = SuccessfulSubmission<T> | FailedSubmission | IntentSubmission;
486
+ /**
487
+ * Reads the data of a form that `createForm` shows. It turns the entries
488
+ * into an object, as `parseForm` does, applies the intent of the button
489
+ * that was pressed, and validates the values with a Standard Schema when
490
+ * the button was not an intent. It does not throw for data that does not
491
+ * match. `reply()` gives what the function returns, for `createForm` to show.
492
+ *
493
+ * ```ts
494
+ * async function save(form: FormData) {
495
+ * 'use server';
496
+ * const submission = await parseSubmission(Order, form);
497
+ * if (submission.status !== 'success') {
498
+ * return submission.reply();
499
+ * }
500
+ * await db.orders.save(submission.value);
501
+ * return submission.reply({ reset: true });
502
+ * }
503
+ * ```
504
+ */
505
+ declare function parseSubmission<S extends StandardSchemaV1>(schema: S, form: FormData, options?: SubmissionOptions): Promise<Submission<StandardSchemaV1.InferOutput<S>>>;
506
+ //#endregion
507
+ //#region src/runtime/rate-limit.d.ts
508
+ /**
509
+ * Where a limit keeps its counts. The default counts in memory, per
510
+ * process. An app with more than one server passes a store on Redis or a
511
+ * platform store, whose `increment` is one atomic command, such as `INCR`
512
+ * with `EXPIRE`. A limit decides on the count that `increment` returns, so
513
+ * requests at the same time cannot all read one count and all pass.
514
+ */
515
+ interface RateLimitStore {
516
+ /**
517
+ * Adds one to the count of a key, which expires after `ttl` milliseconds,
518
+ * and returns the new count, in one atomic step.
519
+ */
520
+ increment(key: string, ttl: number): number | Promise<number>;
521
+ /** The count of a key, or undefined when it has none or it expired. */
522
+ get(key: string): number | undefined | Promise<number | undefined>;
523
+ }
524
+ /** A window as a number of milliseconds, or as text such as `'10s'`, `'1m'` or `'1h'`. */
525
+ type Window = number | `${number}${"ms" | "s" | "m" | "h" | "d"}`;
526
+ interface RateLimitOptions {
527
+ /** How many requests a key can make in the window. */
528
+ max: number;
529
+ /** The length of the window. */
530
+ window: Window;
531
+ /**
532
+ * What to count by, from the event and the arguments of the call, such as
533
+ * the ID of the user in `event.locals`, or the email of a sign-in form.
534
+ * Without a key, or when it returns undefined, the limit counts by the
535
+ * address of the client that the server passed. Each server function, or
536
+ * each route for middleware, counts on its own, whatever the key.
537
+ */
538
+ key?: (event: RequestEvent, args: unknown[]) => string | undefined | Promise<string | undefined>;
539
+ /** The event of the request. Defaults to `getEvent()`. */
540
+ event?: RequestEvent;
541
+ /** The store of the counts. Defaults to the store of `configureRateLimit`, or memory. */
542
+ store?: RateLimitStore;
543
+ /** Whether the limit counts. Defaults to `configureRateLimit`, which is on. */
544
+ enabled?: boolean;
545
+ }
546
+ interface RateLimitConfig {
547
+ /** The store of every limit that names none. Defaults to memory, which counts per process. */
548
+ store?: RateLimitStore;
549
+ /**
550
+ * The proxies in front of the server, as addresses or CIDR ranges, such
551
+ * as `10.0.0.0/8`. `clientAddress` reads `X-Forwarded-For` when the
552
+ * address that the server saw is one of them. A range that is not an
553
+ * address, with or without a prefix length, throws.
554
+ */
555
+ proxies?: string[];
556
+ /** Whether limits count. Defaults to true. Pages that the build prerenders never count. */
557
+ enabled?: boolean;
558
+ }
559
+ /**
560
+ * The error of a request over its limit. Its status is 429, and
561
+ * `retryAfter` is how many seconds to wait. In the browser, the call rejects
562
+ * with it, and `retryAfter` comes from the `Retry-After` header.
563
+ */
564
+ declare class RateLimitError extends ServerError {
565
+ readonly retryAfter: number;
566
+ constructor(retryAfter: number);
567
+ }
568
+ /** Sets the defaults of every limit: the store, the trusted proxies, and whether limits count. */
569
+ declare function configureRateLimit(options: RateLimitConfig): void;
570
+ /**
571
+ * Limits how often a key, such as the user or the address of the client,
572
+ * can call a server function. Call it first thing in the function, before
573
+ * its first `await`, as `getEvent()`:
574
+ *
575
+ * ```ts
576
+ * async function signIn(email: string, password: string) {
577
+ * 'use server';
578
+ * await rateLimit({ ...rateLimit.strict, key: () => email.toLowerCase() });
579
+ * // …
580
+ * }
581
+ * ```
582
+ *
583
+ * The fourth call in 10 seconds for one email rejects with a
584
+ * `RateLimitError`, with status 429 and `Retry-After`, and the rest of the
585
+ * function does not run. Without a `key`, the limit counts by the address
586
+ * of the client, which the server passes to its handler as `address`. In
587
+ * production, a limit with neither throws. `rateLimit.middleware(options)`
588
+ * limits every request under a folder of routes, or of the whole app from
589
+ * the entry.
590
+ */
591
+ declare const rateLimit: RateLimit;
592
+ /** A middleware of a folder, `(request, next)`, or of the entry, `(event, next)`. */
593
+ type RateLimitMiddleware = Middleware & ((event: RequestEvent, next: () => Promise<Response>) => Promise<Response>);
594
+ interface RateLimit {
595
+ (options: RateLimitOptions): Promise<void>;
596
+ /**
597
+ * A limit for every request that passes through a middleware, of a folder
598
+ * or of the entry. A request over the limit answers 429 with `Retry-After`.
599
+ * Each route counts on its own, by its pattern, such as `/api/[id]`.
600
+ */
601
+ middleware: (options: RateLimitOptions) => RateLimitMiddleware;
602
+ /** A limit for functions that guess at secrets, such as a sign-in or a code check: 3 calls in 10 seconds. */
603
+ strict: RateLimitOptions;
604
+ }
605
+ /**
606
+ * The address of the client of a request. It is the address that the server
607
+ * saw, which the handler of the server passes as `address`. When that
608
+ * address is one of the proxies that `configureRateLimit({ proxies })`
609
+ * names, it comes from `X-Forwarded-For`: the header is read from the right,
610
+ * past the trusted proxies, because a client can write anything at its
611
+ * left. An IPv6 address counts by its /64.
612
+ *
613
+ * Undefined when the server passed no address, whatever the headers say,
614
+ * since nothing then shows that the header comes from a proxy. Undefined too
615
+ * when the first hop past the proxies is not an address.
616
+ */
617
+ declare function clientAddress(event: RequestEvent, proxies?: string[]): string | undefined;
618
+ //#endregion
619
+ //#region src/runtime/cache.d.ts
620
+ /**
621
+ * Where cached results live. Values are text. `maxAge` is in seconds, after
622
+ * which the store can drop the value. Each method can return a promise.
623
+ */
624
+ interface CacheStore {
625
+ get(key: string): Promise<string | null | undefined> | string | null | undefined;
626
+ set(key: string, value: string, maxAge: number): Promise<void> | void;
627
+ }
628
+ /**
629
+ * A store in the memory of the server, the default. Each process has its
630
+ * own, and it keeps at most `size` values, dropping the oldest first.
631
+ */
632
+ declare function memoryStore(size?: number): CacheStore & {
633
+ readonly memory: true;
634
+ };
635
+ /**
636
+ * Sets the store of `cached`, such as one that keeps results in Redis for
637
+ * every process of the app. Set it before the first request.
638
+ */
639
+ declare function setCacheStore(next: CacheStore): void;
640
+ /** The store of unstorage, which Nitro gives as `useStorage()`. */
641
+ interface Storage {
642
+ getItem(key: string): Promise<unknown>;
643
+ setItem(key: string, value: string, options?: {
644
+ ttl?: number;
645
+ }): Promise<void>;
646
+ getItemRaw?(key: string): Promise<unknown>;
647
+ setItemRaw?(key: string, value: string, options?: {
648
+ ttl?: number;
649
+ }): Promise<void>;
650
+ }
651
+ /**
652
+ * A store of `cached` from an unstorage storage, such as Nitro's
653
+ * `useStorage('cache')`. It reads and writes the values as they are, since
654
+ * `getItem` would parse text that looks like JSON.
655
+ */
656
+ declare function storageStore(storage: Storage): CacheStore;
657
+ interface CachedOptions<A extends unknown[]> {
658
+ /** Seconds that a result is used for the same arguments. */
659
+ maxAge: number;
660
+ /** What a result depends on, for `revalidate`. A function gets the arguments. */
661
+ tags?: string[] | ((...args: A) => string[]);
662
+ /**
663
+ * The name of the results in the store. A store that other processes
664
+ * share, such as Redis, needs one, so each process finds the same results.
665
+ */
666
+ name?: string;
667
+ }
668
+ /**
669
+ * Makes a function that keeps its results for `maxAge` seconds, by its
670
+ * arguments, and returns a kept result in place of running again. Use it for
671
+ * data that every user sees the same, such as a list of products.
672
+ *
673
+ * - The function runs without the request: `getEvent()` throws in it, so a
674
+ * result never holds one user's data. Pass what it needs as arguments.
675
+ * - Arguments and results are values that brumate can send, such as plain
676
+ * objects, arrays, dates and maps.
677
+ * - Calls with the same arguments while one runs share that run.
678
+ * - `revalidate(tag)` drops the results of a tag.
679
+ */
680
+ declare function cached<A extends unknown[], R>(fn: (...args: A) => Promise<R> | R, options: CachedOptions<A>): (...args: A) => Promise<Awaited<R>>;
681
+ /**
682
+ * Drops the results of `cached` functions with these tags, such as after a
683
+ * server function changes the data. The next call runs the function again.
684
+ * To show the new data on the page, call `refresh` too.
685
+ */
686
+ declare function revalidate(...tags: string[]): Promise<void>;
687
+ //#endregion
688
+ //#region src/runtime/idempotent.d.ts
689
+ interface IdempotentOptions {
690
+ /** Seconds that the result of a key is kept. Defaults to 600. */
691
+ maxAge?: number;
692
+ }
693
+ /**
694
+ * Makes a server function that runs once for each form that the server
695
+ * renders for it. A second post of the same form, such as a double click
696
+ * before the page loaded or a post again after a reload, gets the result of
697
+ * the first, or the same redirect, without running the function again.
698
+ *
699
+ * - It works for the exported functions of a `'use server'` file, used as the
700
+ * `action` of a form.
701
+ * - The key is in the URL of the form, so a page with such a form is not
702
+ * cached for everyone. Each render has a new key.
703
+ * - With scripts, the form gets a new key after each answer, so a post that
704
+ * the user means again runs again.
705
+ * - A call without a key, such as from a handler, runs as usual.
706
+ */
707
+ declare function idempotent<F extends (...args: any[]) => unknown>(fn: F, options?: IdempotentOptions): F;
708
+ //#endregion
709
+ //#region src/runtime/server.d.ts
710
+ /** What `$bind(name)` passes a child: the value of the name, and the scope and slot it writes. */
711
+ declare function binding<T>(value: T, scope: ScopeId, slot: number, set?: unknown): Binding<T>;
712
+ /** The scope and the slot that hold the list of a list item. */
713
+ type ItemSource = readonly [scope: ScopeId, slot: number];
714
+ /** A `#loading` body that renders after the rest of the page. */
715
+ interface Boundary {
716
+ id: ScopeId;
717
+ /** Resolves to the body's markup, and its scopes in `ctx.state`. */
718
+ render: Promise<{
719
+ html: string;
720
+ ctx: Context;
721
+ }>;
722
+ /** True when a `#try` body around it failed, so its markers were never sent. */
723
+ cancelled?: boolean;
724
+ /** A body around the target of a request for a `#defer` body, which renders but is not sent. */
725
+ around?: boolean;
726
+ /** The `#reveal` group that orders it, when it is in one. */
727
+ group?: RevealGroup;
728
+ }
729
+ /** The order of a `#reveal` block. */
730
+ type RevealOrder = "sequential" | "backwards" | "together" | "natural";
731
+ /**
732
+ * The `#loading` bodies of a `#reveal` block, in the order of the markup.
733
+ * When a body is ready, the stream asks the group, which sends the bodies
734
+ * that its order lets show. The data of every body still loads at once.
735
+ */
736
+ declare class RevealGroup {
737
+ readonly order: RevealOrder;
738
+ readonly collapsed: boolean;
739
+ /** The bodies that stream, each with how to send it once it is ready. */
740
+ private readonly members;
741
+ /** The fallbacks that `collapsed` hides until the body before them shows. */
742
+ readonly hidden: Set<ScopeId>;
743
+ private closed;
744
+ constructor(order: RevealOrder, collapsed: boolean);
745
+ /** True when a body that is ready can render in place, before the bodies that stream. */
746
+ mayShow(): boolean;
747
+ /** True when the fallback of the next body that streams waits, for `collapsed`. */
748
+ hides(): boolean;
749
+ add(id: ScopeId): void;
750
+ /** The body is ready, or failed with nothing to send. `send` writes it, and runs `after` with it. */
751
+ ready(id: ScopeId, send: (after: string) => void): void;
752
+ /** The block ended, so the group knows its last body. */
753
+ close(): void;
754
+ private flush;
755
+ }
756
+ /** The `#defer` body that a render renders, for the request of the browser that asks for it. */
757
+ interface DeferTarget {
758
+ /** The boundary ID of the block. */
759
+ boundary: ScopeId;
760
+ /** The scope and the anchor of the block, as `<scope>:<anchor>`, which the render checks. */
761
+ at: string;
762
+ /**
763
+ * `found` once the render reaches the block at `at`. `moved` when it reaches the boundary
764
+ * elsewhere, such as after the data of the page changed and moved the IDs before it.
765
+ */
766
+ status?: "found" | "moved";
767
+ }
768
+ /** A point in a render that `restore` goes back to. */
769
+ interface Mark {
770
+ /** The prefix of the IDs of the block that the render was in, and its counters then. */
771
+ prefix: string;
772
+ scope: number;
773
+ boundary: number;
774
+ /** How many blocks the render was in. */
775
+ depth: number;
776
+ undo: number;
777
+ owner: ScopeId | undefined;
778
+ }
779
+ /**
780
+ * Where a render takes its scope and boundary IDs from. The page takes
781
+ * numbers from its base. Each `#loading` body has its own, whose IDs are the
782
+ * ID of its boundary, a dot and a number, such as `5.0`. A body resumes when
783
+ * its data arrives, so with one counter for the page its IDs, and those of
784
+ * the markup after it, would depend on that order.
785
+ *
786
+ * A block whose shape depends on data, such as an `#if` or a `#for`, also
787
+ * numbers the scopes of its bodies after an ID of its own. The markup after
788
+ * the block then keeps its IDs, whichever branch rendered and however many
789
+ * items a list had, so a later request for a `#defer` body numbers the page
790
+ * the same way even when the user or the data before the block differs.
791
+ */
792
+ interface IdSpace {
793
+ /** `''` for the page, or the ID of the boundary or block and a dot. */
794
+ prefix: string;
795
+ scope: number;
796
+ /** The counter of boundary IDs, which blocks take their IDs from too. */
797
+ boundary: number;
798
+ /** The number of the first scope, and the scopes from there on, so an ID finds its scope. */
799
+ first: number;
800
+ entries: (ScopeEntry | undefined)[];
801
+ }
802
+ /** A scope of a render: its record, and what the server keeps of it while the page renders. */
803
+ interface ScopeEntry {
804
+ id: ScopeId;
805
+ /** The prefix of the ID and the number after it, such as `'5.'` and `1`, or `''` and `3`. */
806
+ prefix: string;
807
+ n: number;
808
+ record: ScopeState;
809
+ /** The render whose state holds the record. */
810
+ ctx: Context | undefined;
811
+ /** The ID space that finds the scope by its ID, for a scope that `scope()` made. */
812
+ space?: IdSpace;
813
+ /** The scope that the contexts of this one are found in. */
814
+ parent?: ScopeId;
815
+ /** The values of contexts that this scope provides. */
816
+ values?: Map<string, unknown>;
817
+ /** The names of the slots, so an error can name a value that cannot be sent. */
818
+ names?: string[];
819
+ /** The scope and the slot that hold the list of this list item. */
820
+ source?: ItemSource;
821
+ }
822
+ /**
823
+ * Tracks the scopes of one render. A `#loading` body renders in a child
824
+ * context, so its scopes are written with its markup.
825
+ */
826
+ declare class Context {
827
+ /**
828
+ * The scopes of this render, in the order it made them, with their
829
+ * records. A record that this render adds to a scope of another render,
830
+ * such as a link from a `#loading` body to a scope of the page, is here
831
+ * too, as a scope of its own.
832
+ */
833
+ readonly scopes: ScopeEntry[];
834
+ /**
835
+ * Every ID space of the page, across the renders of `#loading` bodies, on
836
+ * the root context. A scope is found by its ID in the entries of its space.
837
+ * The spaces are put in a map by prefix only when a scope is looked up
838
+ * outside the blocks that are open, since a render makes many and looks
839
+ * up few, and each string key costs a hash.
840
+ */
841
+ private readonly made;
842
+ private byPrefix;
843
+ private indexed;
844
+ /** The records that this render adds to scopes of other renders, by ID. */
845
+ private partials;
846
+ /** The scope that the render used last, since it uses one a few times in a row. */
847
+ private last;
848
+ private readonly root;
849
+ /** The ID spaces of the blocks that the render is in, from the outside in. */
850
+ private readonly spaces;
851
+ private readonly baseId;
852
+ /** The `#defer` body to render, in the request for it. The rest of the page renders no body. */
853
+ target: DeferTarget | undefined;
854
+ /** True in the context of the target body and the bodies inside it. */
855
+ private inTarget;
856
+ private readonly boundaries;
857
+ private readonly styles;
858
+ /** Markup of `#portal` blocks, written at the end of the page. */
859
+ readonly portals: string[];
860
+ /** Markup of `#head` blocks. */
861
+ private readonly heads;
862
+ private pageTitle;
863
+ /** The titles that this render set, and whether they all came from a `<title>` in `#head`. */
864
+ private titles;
865
+ private onBoundary;
866
+ /** The scope that renders the next component, which becomes its owner. */
867
+ private owner;
868
+ /**
869
+ * Children that render where they are inserted: the scope of the markup
870
+ * that wrote them, and the scope where they are, for their contexts.
871
+ */
872
+ private readonly inserted;
873
+ /** Takes back what this context added to the page, from the newest, for `restore`. */
874
+ private readonly undo;
875
+ /** The URL prefix of server function calls. */
876
+ private rpcPrefix;
877
+ /** The ID of the build, for forms that post to server functions. See `RenderOptions`. */
878
+ build: string | undefined;
879
+ /** Results of server functions that a form posted to this page, for `$action`. */
880
+ actions: Map<unknown, unknown>;
881
+ /** The params of the route of the page, for `$route`. */
882
+ params: Record<string, string>;
883
+ /** The request of the page, when it renders with one. */
884
+ event: RequestEvent | undefined;
885
+ /** Results of server function calls in this render, so the same call runs once. */
886
+ readonly calls: Map<string, unknown>;
887
+ /** The event of the page, for `getEvent()` in a component, which the compiler rewrites to this. */
888
+ getEvent(): RequestEvent;
889
+ /** Starts an entry of the trace of the request, in development. */
890
+ traced(kind: TraceEntry["kind"], label: string): ((failed?: boolean) => void) | undefined;
891
+ /** Marks the request of the page as one that depends on the user, so the page is not cached for everyone. */
892
+ personal(): void;
893
+ /** Runs code of the render with its event and its call results, such as a memo's compute. */
894
+ run<T>(callback: () => T): T;
895
+ /** The result of a server function that a form posted to this page. */
896
+ actionResult(fn: unknown): unknown;
897
+ /** `prefix` is the boundary ID and a dot, for the context of a `#loading` body. */
898
+ constructor(root?: Context, rpc?: string, base?: number, prefix?: string);
899
+ /** The base of the render, which the browser sends back to ask for a `#defer` body. */
900
+ base(): number;
901
+ /** True in a request for a `#defer` body, outside the body, once the body has started. */
902
+ past(): boolean;
903
+ /**
904
+ * A number above every scope and boundary ID of the page so far, so a
905
+ * later render can start there. The IDs inside boundaries start with one.
906
+ */
907
+ next(): number;
908
+ /** The space that the next IDs come from. */
909
+ private get space();
910
+ /**
911
+ * Starts a block whose shape depends on data, such as an `#if` or a
912
+ * `#for`. The scopes of its bodies are numbered after one ID that the
913
+ * block takes, until `leave`. A `#loading` body that renders in place
914
+ * passes the ID of its boundary, so its scopes get the IDs that they
915
+ * would get in a stream.
916
+ */
917
+ enter(id?: ScopeId): void;
918
+ /** Ends the block that `enter` started. */
919
+ leave(): void;
920
+ /** Returns the URL prefix of server function calls. */
921
+ rpc(): string;
922
+ /** Returns the ID of the build, when the render has one. */
923
+ buildId(): string | undefined;
924
+ /**
925
+ * Returns a new scope ID. `kind` is the scope's ID in the compiled
926
+ * component, `parent` is the scope that contains it, and `module` is the
927
+ * component ID of a component's root scope.
928
+ */
929
+ scope(kind: number, parent?: ScopeId, module?: string): ScopeId;
930
+ /** The scope of the page with an ID, from any render. */
931
+ private find;
932
+ /**
933
+ * Renders children where a component inserts them, at `at`. Their scopes
934
+ * keep `from`, the scope of the markup that wrote them, for their values,
935
+ * and find their contexts from `at`.
936
+ */
937
+ children(from: ScopeId, at: ScopeId, renderBody: () => Promise<string>): Promise<string>;
938
+ /**
939
+ * The ID that `$id()` makes: the scope's ID and the position of the call.
940
+ * A dot in a scope ID inside a `#loading` body becomes `_`, so the ID also
941
+ * works as a CSS selector, such as `#b5_1-0`.
942
+ */
943
+ id(scope: ScopeId, index: number): string;
944
+ /** Sets the owner of the next component's root scope. */
945
+ own(scope: ScopeId): void;
946
+ /** Provides a value of a context to the scopes inside `scope`. */
947
+ provide<T>(context: Context$1<T>, value: T, scope: ScopeId): void;
948
+ /**
949
+ * Reads a context from the nearest scope that provides it, starting at
950
+ * `scope`. With `slot`, records which slot holds it, so the client can
951
+ * update it when the provided value changes.
952
+ */
953
+ consume<T>(context: Context$1<T>, scope: ScopeId, slot?: number): T;
954
+ /** The ID that the next call to `scope()` returns. */
955
+ peek(): ScopeId;
956
+ /** Marks the render so far, such as before a `#try` body, for `restore`. */
957
+ mark(): Mark;
958
+ /**
959
+ * Takes back what the render added to the page since `mark`, such as a
960
+ * `#try` body that threw, whose markup is not sent: its scopes, the
961
+ * stylesheets it counted as sent, its `#portal` and `#head` markup, its
962
+ * title, its `#loading` bodies, and its links to child components.
963
+ */
964
+ restore(mark: Mark): void;
965
+ /**
966
+ * Forgets the scopes of this render from `from` on, such as those of a
967
+ * `#try` body that threw, so the client does not resume markup that was
968
+ * never sent. `#loading` bodies render in contexts of their own, so their
969
+ * scopes stay.
970
+ */
971
+ private drop;
972
+ /** The scope of this render with an ID, or the record that this render adds to another's. */
973
+ private entry;
974
+ private record;
975
+ /** The record of a scope in the state of this render, if it is there. */
976
+ ownRecord(scope: ScopeId): ScopeState | undefined;
977
+ /** The records of the scopes of this render, by ID, in the order the render made them. */
978
+ get state(): StateMap;
979
+ /**
980
+ * The list of each list item scope whose list is a slot of an enclosing
981
+ * scope, as `[scope, slot]`. The items of a list share one array.
982
+ */
983
+ get sources(): Map<ScopeId, ItemSource>;
984
+ slots(scope: ScopeId, values: unknown[], names?: string[]): void;
985
+ /**
986
+ * Records the props that a parent bound with `$bind`, among the props that
987
+ * the component writes: `slots` has the slot of each, by its name. Its
988
+ * writes in the browser go to the parent's slots.
989
+ */
990
+ bindings(scope: ScopeId, props: Record<string, unknown>, slots: Record<string, number>): void;
991
+ /**
992
+ * Records the item of a list that can change on the client. `source` is
993
+ * the scope and slot that hold the list, when the compiler found one, so
994
+ * the client can take the item from there.
995
+ */
996
+ item(scope: ScopeId, value: unknown, source?: ItemSource): void;
997
+ /** Records the scope of a child component at an anchor of its parent. */
998
+ link(scope: ScopeId, anchor: number, child: ScopeId): void;
999
+ /** Returns the reference that a `ref` signal holds on the server. */
1000
+ element(scope: ScopeId, anchor: number): ElementReference;
1001
+ /**
1002
+ * Marks a function as a client function, so it serializes as a reference.
1003
+ * `args` are the arguments of a handler that `$handler` made, which go
1004
+ * with the reference. Each call makes a new reference, so a function that
1005
+ * `$handler` marks gets a copy for its arguments.
1006
+ */
1007
+ fn<T>(value: T, ref: string, scope: ScopeId, args?: unknown[]): T;
1008
+ /** Returns a component's stylesheet the first time the page renders the component. */
1009
+ style(id: string, css: string): string;
1010
+ /** Adds the markup of a `#head` block. */
1011
+ head(html: string): void;
1012
+ /**
1013
+ * Sets the title of the page. The last call wins. `markup` is true for a
1014
+ * `<title>` in `#head`, which is in the head already.
1015
+ */
1016
+ title(value: unknown, markup?: boolean): void;
1017
+ /** True once the first render is done, and its head is about to be sent. */
1018
+ private sent;
1019
+ /** Marks the first render as done. Head markup after it streams with its `#loading` body. */
1020
+ send(): void;
1021
+ /**
1022
+ * The head markup and the title that a `#loading` body set, after the
1023
+ * head was sent. The title is undefined if the body set none.
1024
+ */
1025
+ lateHead(): {
1026
+ html: string;
1027
+ title: string | undefined;
1028
+ };
1029
+ /** The markup for the document's head: the title and the `#head` blocks. */
1030
+ headHTML(): string;
1031
+ /** Adds the markup of a `#portal` block, which goes after the rest of the page. */
1032
+ portal(html: string): void;
1033
+ /** Adds the head markup and the title of a body that renders in place, to the head of the page. */
1034
+ adoptHead(late: {
1035
+ html: string;
1036
+ title: string | undefined;
1037
+ }): void;
1038
+ /** True when the bodies of `#defer` blocks render in place, for a page that renders in order. */
1039
+ inOrder: boolean;
1040
+ /** The `#reveal` blocks that are open in this context, the innermost last. */
1041
+ private readonly reveals;
1042
+ /** Starts a `#reveal` block: the `#loading` bodies until `revealEnd` show in its order. */
1043
+ revealStart(order: RevealOrder, collapsed: boolean): void;
1044
+ /** Ends the `#reveal` block that `revealStart` started. */
1045
+ revealEnd(): void;
1046
+ /** The group of the `#reveal` block around the next body, when the stream orders it. */
1047
+ private get reveal();
1048
+ /** True when a `#loading` body that is ready can render in place, as its `#reveal` allows. */
1049
+ mayShow(): boolean;
1050
+ /** Starts the fallback of a `#loading` body, which `collapsed` hides in a template. */
1051
+ fallbackStart(id: ScopeId): string;
1052
+ /** Ends the fallback that `fallbackStart` started. */
1053
+ fallbackEnd(id: ScopeId): string;
1054
+ /** Returns the ID of a new `#loading` boundary. */
1055
+ boundary(): ScopeId;
1056
+ /** Renders a `#loading` body after the rest of the page, in its own context and ID space. */
1057
+ defer(id: ScopeId, renderBody: (ctx: Context) => Promise<string>): void;
1058
+ /**
1059
+ * Renders the body of a `#defer` block, in the request for it. `at` is
1060
+ * the scope and the anchor of the block. A page renders only the
1061
+ * fallback, so it does nothing then.
1062
+ */
1063
+ deferBlock(id: ScopeId, at: string, renderBody: (ctx: Context) => Promise<string>): void;
1064
+ private register;
1065
+ /** Receives every boundary, including those registered before this call. */
1066
+ watch(onBoundary: (boundary: Boundary) => void): void;
1067
+ }
1068
+ /** Thrown when code reads a memo whose value is still loading. It carries the load. */
1069
+ declare class NotReady extends Error {
1070
+ readonly source: Promise<unknown>;
1071
+ constructor(source: Promise<unknown>);
1072
+ }
1073
+ /** A memo on the server. It computes on its first read, so nothing waits for a memo that nothing reads. */
1074
+ interface Memo<T = unknown> {
1075
+ compute: () => T;
1076
+ /** The render, whose event server functions that the compute calls read. */
1077
+ ctx?: Context;
1078
+ state: "idle" | "pending" | "done" | "failed";
1079
+ value?: unknown;
1080
+ error?: unknown;
1081
+ load?: Promise<unknown>;
1082
+ /** The name of the memo, for the trace of the devtools. */
1083
+ name?: string;
1084
+ }
1085
+ /** Declares a memo. Its value is computed when it is first read. */
1086
+ declare function memo<T>(compute: () => T, ctx?: Context, name?: string): Memo<T>;
1087
+ /**
1088
+ * Reads a memo. A value that is still loading throws `NotReady` with its
1089
+ * load, and a memo that read such a value stays unread, so it computes
1090
+ * again when it is read after the load settles.
1091
+ */
1092
+ declare function read(node: Memo): any;
1093
+ /** Waits for the value of a memo, through every load it reads. */
1094
+ declare function wait(node: Memo): Promise<unknown>;
1095
+ /**
1096
+ * The value of a memo when it is ready, or a promise of it while it loads.
1097
+ * The render then awaits only a memo that is loading.
1098
+ */
1099
+ declare function ready(node: Memo): unknown;
1100
+ /**
1101
+ * 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 rejected
1103
+ * promise either way, so the page renders and the failure reaches the
1104
+ * browser as the load that failed.
1105
+ */
1106
+ declare function stateValue(node: Memo): unknown;
1107
+ /**
1108
+ * Starts every memo of a run of declarations that the render waits for,
1109
+ * so they load at the same time. Returns a promise that settles when all
1110
+ * of them have, or undefined when none is loading. A memo that fails
1111
+ * throws here, or rejects the promise.
1112
+ */
1113
+ declare function waitAll(nodes: Memo[]): Promise<unknown> | undefined;
1114
+ /**
1115
+ * True when every memo has its value, so a `#loading` body that reads them
1116
+ * can render in place. A memo that is not computed yet computes here, so
1117
+ * the loads of the memos that are not ready start now, and the body that
1118
+ * streams later finds them loading. A memo that failed counts as not ready:
1119
+ * the body streams, and throws where it reads the memo.
1120
+ */
1121
+ declare function settled(nodes: Memo[]): boolean;
1122
+ declare const LAZY: unique symbol;
1123
+ /** Markup that renders where it is inserted, so it can read the contexts there. */
1124
+ interface Lazy {
1125
+ [LAZY]: (ctx: Context, scope: ScopeId | undefined) => Promise<string>;
1126
+ }
1127
+ /**
1128
+ * The children of a component, which render where the component inserts
1129
+ * them, so they read the contexts that the component provides. `from` is the
1130
+ * scope of the markup that wrote them.
1131
+ */
1132
+ declare function children(from: ScopeId, renderBody: (ctx: Context) => Promise<string>): Lazy;
1133
+ /** Makes markup that renders where it is inserted, such as the children of a layout. */
1134
+ declare function lazy(renderAt: (ctx: Context, scope: ScopeId | undefined) => Promise<string>): Lazy;
1135
+ /** Renders the attributes of a form or button that posts to a server function. */
1136
+ declare function action(ctx: Context, name: string, id: string, method?: string, result?: string): string;
1137
+ /**
1138
+ * The result of a server function that a form posted to this page, for
1139
+ * `$action`, or undefined when the page was not rendered for a post.
1140
+ */
1141
+ declare function actionResult(ctx: Context, fn: unknown): unknown;
1142
+ /**
1143
+ * Renders a value inserted in markup. `ctx` and `scope` are where it is
1144
+ * inserted, for markup that renders there.
1145
+ */
1146
+ declare function insert(value: unknown, ctx?: Context, scope?: ScopeId): string | Promise<string>;
1147
+ type Component<P = any> = (props: P, ctx: Context) => Promise<string>;
1148
+ /**
1149
+ * Renders a child component. With `scope` and `anchor`, records the child's
1150
+ * scope so the parent can update its props on the client.
1151
+ */
1152
+ declare function component<P>(Child: Component<P>, props: P, ctx: Context, scope?: ScopeId, anchor?: number): Promise<string>;
1153
+ /** 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>;
1155
+ /** The records of the scopes of a render, by scope ID. */
1156
+ type StateMap = Map<ScopeId, ScopeState>;
1157
+ /**
1158
+ * Writes the records of scopes with the same kind, parent and shape, such as
1159
+ * the items of a list, in groups. Each one then costs its slots and the gap
1160
+ * to the ID before it. The items of a list whose list is in `sources` and in
1161
+ * the state are not written. See `PackedState`.
1162
+ */
1163
+ declare function packState(input: PageState | StateMap, sources?: Map<ScopeId, ItemSource>): PackedState;
1164
+ /**
1165
+ * Serializes the page state as the code of state records. `onRecord`
1166
+ * receives each record as soon as it is ready. The promise resolves when
1167
+ * every promise in the state has settled.
1168
+ */
1169
+ declare function streamState(state: PageState | StateMap, onRecord: (code: string, initial: boolean) => void): Promise<void>;
1170
+ interface StateAttributes {
1171
+ /** A number above every ID so far, on each record with scopes. */
1172
+ next?: number;
1173
+ /** The first record of a render defines `$bR`. Later ones call it. */
1174
+ define?: boolean;
1175
+ /** The route of the page. */
1176
+ route?: string;
1177
+ /** The base of the render, when it is above 0, or the key of a `#defer` body's records. */
1178
+ root?: number | string;
1179
+ /** The Content Security Policy nonce of the script. */
1180
+ nonce?: string;
1181
+ /** The params of the route of the page, on its first record, for `$route` in the browser. */
1182
+ params?: Record<string, string>;
1183
+ /** The ID of the build that rendered the page, on its first record, for skew protection. */
1184
+ build?: string;
1185
+ }
1186
+ /**
1187
+ * Returns the script of a state record. `scopes` marks a record with scopes,
1188
+ * as opposed to one that settles a promise. The record is code that seroval
1189
+ * wrote, as a function of the references of its render, `$R`, and of the
1190
+ * functions that make brumate's values, `$b`. seroval escapes every `<` in
1191
+ * the strings in it.
1192
+ */
1193
+ declare function stateScript(code: string, scopes?: boolean, attributes?: StateAttributes): string;
1194
+ interface RenderResult {
1195
+ /** The markup. A `#loading` body that is not ready shows its fallback. */
1196
+ html: string;
1197
+ /** The script that holds the page state. */
1198
+ state: string;
1199
+ /**
1200
+ * Markup to write after the page, as it is ready: the bodies of
1201
+ * `#loading` blocks, and the state records that settle promises.
1202
+ */
1203
+ pending: AsyncIterable<string>;
1204
+ /** Headers that the page set while it rendered, such as cookies. */
1205
+ headers: Headers;
1206
+ /** The status that `setStatus` set while the page rendered, or 200. */
1207
+ status: number;
1208
+ /**
1209
+ * A number above every ID of this render, once its `#loading` bodies have
1210
+ * rendered. Another root on the same page passes it as `base`.
1211
+ */
1212
+ next: () => number;
1213
+ /** Markup for the document's head: the `$title` and the `#head` blocks. */
1214
+ head: string;
1215
+ /**
1216
+ * The event of the request. Its `signal` aborts when the reader of the
1217
+ * response goes away, which `streamParts` and `renderToStream` report.
1218
+ */
1219
+ event?: RequestEvent;
1220
+ /**
1221
+ * With the `defer` option, whether the render found the block: `found`,
1222
+ * `moved` when the boundary is at another place, such as after the data
1223
+ * of the page changed, or `missing`.
1224
+ */
1225
+ defer?: "found" | "moved" | "missing";
1226
+ }
1227
+ interface RenderOptions {
1228
+ /** The URL prefix of server function calls, for forms that post to one. Defaults to `/_brumate`. */
1229
+ rpc?: string;
1230
+ /** In development: the swaps of `#loading` bodies keep their fallbacks, for the devtools. */
1231
+ dev?: boolean;
1232
+ /**
1233
+ * The first scope and boundary ID. A page that the client loads in place
1234
+ * of another starts above the IDs of the page it keeps parts of.
1235
+ */
1236
+ base?: number;
1237
+ /** Names the route of the page, so the client knows which layouts it can keep. */
1238
+ route?: string;
1239
+ /**
1240
+ * Renders `#loading` and `#defer` bodies in place, in the order of the
1241
+ * page, instead of streaming them in `<template>`s that a script swaps in.
1242
+ * The page arrives later, and complete, for readers that run no scripts,
1243
+ * such as crawlers. The state is the same either way. `'bots'`, the
1244
+ * default, does it for requests whose `User-Agent` is a known crawler. A
1245
+ * function decides for each request.
1246
+ */
1247
+ inOrder?: boolean | "bots" | ((request: Request) => boolean);
1248
+ /** The params of the route of the page, for `$route`. `handleRoute` sets them. */
1249
+ params?: Record<string, string>;
1250
+ /** Results of server functions that a form posted to this page, by function, for `$action`. */
1251
+ actions?: Map<unknown, unknown>;
1252
+ /**
1253
+ * The request of the page. Components and the server functions that their
1254
+ * memos call read it with `getEvent()`. Headers and cookies that they set
1255
+ * are in the `headers` that `render` returns.
1256
+ */
1257
+ request?: Request;
1258
+ /** The event of the request, in place of `request`, such as one that middleware already set cookies on. */
1259
+ event?: RequestEvent;
1260
+ /**
1261
+ * Keeps work going after the response ends, for `event.waitUntil`, such
1262
+ * as the `waitUntil` of Cloudflare Workers. Without it, the promise runs
1263
+ * on its own and its error is logged.
1264
+ */
1265
+ waitUntil?: (promise: Promise<unknown>) => void;
1266
+ /**
1267
+ * A Content Security Policy nonce for the inline scripts: the state
1268
+ * records, and the scripts that swap in `#loading` bodies.
1269
+ */
1270
+ nonce?: string;
1271
+ /**
1272
+ * The ID of the build, for skew protection. The page state carries it,
1273
+ * and the browser sends it with each call. The Vite plugin sets it in
1274
+ * builds. See `handleRequest`.
1275
+ */
1276
+ build?: string;
1277
+ /**
1278
+ * The address of the client as the server saw it, such as the remote
1279
+ * address of the socket, for `clientAddress` and rate limits.
1280
+ */
1281
+ address?: string;
1282
+ /** True while the build prerenders the page. Rate limits do not count then. */
1283
+ prerender?: boolean;
1284
+ /**
1285
+ * Renders only the body of this `#defer` block, for the request that the
1286
+ * browser sends when the block's trigger fires. Pass the `base` of the
1287
+ * page too, so the IDs of the page come out the same. The body comes from
1288
+ * `pending`, and `html` and `state` are empty.
1289
+ */
1290
+ defer?: {
1291
+ boundary: ScopeId;
1292
+ at: string;
1293
+ };
1294
+ }
1295
+ /**
1296
+ * Renders the parts of a page. It returns as soon as the markup is rendered.
1297
+ * `#loading` bodies and promises in the state do not hold it up: they come
1298
+ * later, from `pending`. `renderToStream` puts the parts together. Use this
1299
+ * directly to send the response headers that server functions set before
1300
+ * the stream starts.
1301
+ */
1302
+ declare function render<P>(Root: Component<P>, props: P, options?: RenderOptions): Promise<RenderResult>;
1303
+ /**
1304
+ * Puts the bodies of boundaries in place of their fallbacks, with the bodies
1305
+ * inside them, as the swap script would in the browser. A `#defer` block
1306
+ * loses its `<template>` too, so the browser does not ask for a body that
1307
+ * is there. A boundary without a body keeps its fallback.
1308
+ */
1309
+ declare function inlineBodies(html: string, bodies: Map<string, string>): string;
1310
+ interface DocumentOptions extends RenderOptions {
1311
+ /**
1312
+ * Markup before the component, for a component that does not render
1313
+ * `<html>`. A function receives the markup for the document's head.
1314
+ */
1315
+ start?: string | ((head: string) => string);
1316
+ /** Markup for the head, before the head of the components, such as the `<link>` of a CSS file. */
1317
+ head?: string;
1318
+ /**
1319
+ * Markup right after the page state, such as the client entry. Make
1320
+ * module scripts `async`, so they run before the stream ends.
1321
+ */
1322
+ scripts?: string;
1323
+ /** Markup after the first render, for a component that does not render `<html>`. */
1324
+ end?: string;
1325
+ }
1326
+ type StreamOptions = DocumentOptions;
1327
+ /**
1328
+ * Renders a component as a stream. The first chunk is the whole first
1329
+ * render, sent as soon as it is ready. Each `#loading` body and each state
1330
+ * record that settles a promise follows it as it resolves. A component that
1331
+ * renders `<html>` gets the doctype and its head.
1332
+ */
1333
+ declare function renderToStream<P>(Root: Component<P>, props: P, options?: DocumentOptions): ReadableStream<string>;
1334
+ /** Streams the parts of a page from `render`: the first render whole, then what resolves later. */
1335
+ declare function streamParts(parts: RenderResult, options?: DocumentOptions): ReadableStream<string>;
1336
+ interface RequestOptions {
1337
+ /**
1338
+ * Other origins that may call server functions and post forms to them,
1339
+ * such as `https://app.example.com`. The origin of the request is always
1340
+ * allowed.
1341
+ */
1342
+ origins?: string[];
1343
+ /**
1344
+ * The middleware of the entry, which runs for every request before
1345
+ * anything else: pages, endpoints, calls, form posts and `#defer` bodies.
1346
+ * The Vite plugin passes the default export of `src/middleware.ts`.
1347
+ */
1348
+ middleware?: EntryMiddleware;
1349
+ /**
1350
+ * The middleware of each `'use server'` file, by the ID of each of its
1351
+ * functions. It runs before the function, after the middleware of the
1352
+ * entry. `virtual:brumate/server` passes them.
1353
+ */
1354
+ fileMiddleware?: Record<string, EntryMiddleware>;
1355
+ /** Keeps work going after the response ends, for `event.waitUntil`. See `RenderOptions`. */
1356
+ waitUntil?: (promise: Promise<unknown>) => void;
1357
+ /**
1358
+ * The ID of the build, for skew protection. A call from a page of another
1359
+ * build to a function that is gone answers 409 with this ID in
1360
+ * `x-brumate-build`, and the browser loads the page again. A call to a
1361
+ * function that still exists runs. The Vite plugin sets it in builds.
1362
+ */
1363
+ build?: string;
1364
+ /** The address of the client as the server saw it, for `clientAddress` and rate limits. */
1365
+ address?: string;
1366
+ /** True while the build prerenders the pages. Rate limits do not count then. */
1367
+ prerender?: boolean;
1368
+ }
1369
+ /**
1370
+ * True when a request comes from a page of another site. Server function
1371
+ * calls and form posts send the cookies of the user, so another site must
1372
+ * not be able to make them.
1373
+ *
1374
+ * The browser sends `Origin` with every call and post. Without it, an older
1375
+ * browser's `Sec-Fetch-Site` decides. A request with neither does not come
1376
+ * from a page in a browser, so it is allowed.
1377
+ */
1378
+ declare function isCrossSite(request: Request, options?: RequestOptions): boolean;
1379
+ /**
1380
+ * Answers a server function call from `brumate/client`. Returns undefined
1381
+ * when the request is not a call, so other handlers can answer it. Server
1382
+ * functions read the request with `getEvent()`. A call from a page of
1383
+ * another site answers 403. See `isCrossSite`.
1384
+ */
1385
+ declare function handleRequest(functions: Record<string, (...args: any[]) => unknown>, request: Request, prefix?: string, options?: RequestOptions): Promise<Response | undefined>;
1386
+ /**
1387
+ * How long a page can be cached for everyone, as a route exports it from
1388
+ * its module script: `export const cache = { maxAge: 60 }`. A layout's
1389
+ * applies to the pages below it, and the nearest one wins.
1390
+ */
1391
+ interface PageCache {
1392
+ /** Seconds that a cache can serve the page without asking again. */
1393
+ maxAge: number;
1394
+ /** Seconds after `maxAge` that a cache can serve the old page while it gets a new one. */
1395
+ staleWhileRevalidate?: number;
1396
+ }
1397
+ interface RouteOptions extends DocumentOptions, RequestOptions {
1398
+ /**
1399
+ * The HTML that the build prerendered for the path, for a server that has
1400
+ * the file. The server sends it at once, then renders the `#defer` blocks
1401
+ * with the `load` or `idle` trigger in the same response, in place of a
1402
+ * request for each. Requests for a `#defer` body and client navigation
1403
+ * render the route as usual.
1404
+ */
1405
+ shell?: string;
1406
+ /**
1407
+ * Keeps the pages that `cache` makes public in the store of `cached`, and
1408
+ * answers the next request for the same URL from it until `maxAge` ends or
1409
+ * `revalidate` drops a tag that the page used. Defaults to true. A CDN in
1410
+ * front of the server can keep them instead.
1411
+ */
1412
+ pageCache?: boolean;
1413
+ /**
1414
+ * Throws errors that are not a `ServerError` instead of rendering
1415
+ * `_error.brm`, so a dev server can show them, such as with `errorPage`
1416
+ * from `brumate/vite`. The Vite plugin sets it in development.
1417
+ */
1418
+ dev?: boolean;
1419
+ /** The server functions, by ID, for forms that post to a page. `virtual:brumate/routes` passes them. */
1420
+ functions?: Record<string, (...args: any[]) => unknown>;
1421
+ /**
1422
+ * The URLs of the modules that every page loads early: the loader, and the
1423
+ * core that the first event loads. A page gets them as `Link` headers and
1424
+ * as `<link rel="modulepreload">` in its head. `virtual:brumate/routes`
1425
+ * passes them from the client build.
1426
+ */
1427
+ hints?: string[];
1428
+ /**
1429
+ * Receives the `Link` values of `hints` before the page renders, so a
1430
+ * server can send them as `103 Early Hints`, such as with Node's
1431
+ * `response.writeEarlyHints({ link })`.
1432
+ */
1433
+ earlyHints?: (links: string[]) => void;
1434
+ }
1435
+ /**
1436
+ * Answers a request with the route that matches its path, streamed:
1437
+ *
1438
+ * - The `_middleware.ts` of each folder on the path runs first, from the outside in.
1439
+ * - An endpoint at the path answers the methods that it exports.
1440
+ * - A form without scripts that posts to the page with `?__action=<id>`
1441
+ * runs that server function first, and the page renders with its result
1442
+ * for `$action`.
1443
+ * - A route that throws renders the nearest `_error.brm`, and a path that
1444
+ * no route matches renders the `_error.brm` of the root with status 404.
1445
+ *
1446
+ * Returns undefined when no route matches and the root has no error file or
1447
+ * middleware. A `redirect` while the page renders answers with a redirect.
1448
+ */
1449
+ declare function handleRoute(tree: RouteNode, request: Request, options?: RouteOptions): Promise<Response | undefined>;
1450
+ /**
1451
+ * Renders an object of attributes. A handler in it, such as an `onClick`
1452
+ * that a component passes on with `...rest`, goes into `on` as a `b-on`
1453
+ * entry: the client function that it refers to, with the scope that the
1454
+ * function belongs to and the modifiers of its wrappers. A function that
1455
+ * refers to nothing in the browser is left out.
1456
+ */
1457
+ declare function spread(attributes: Record<string, unknown>, on?: string[]): string;
1458
+ //#endregion
1459
+ export { setCacheStore as $, serializeCookie as $t, isCrossSite as A, RouteMatch as At, stateScript as B, RequestKind as Bt, children as C, parseForm as Ct, handleRoute as D, Loader as Dt, handleRequest as E, Handler as Et, ready as F, Locals as Ft, waitAll as G, isRedirect as Gt, streamParts as H, dedupe as Ht, render as I, Redirect as It, CacheStore as J, CookieOptions as Jt, IdempotentOptions as K, redirect as Kt, renderToStream as L, RequestCall as Lt, memo as M, RouteView as Mt, packState as N, matchRoute as Nt, inlineBodies as O, Middleware as Ot, read as P, EntryMiddleware as Pt, revalidate as Q, parseCookies as Qt, settled as R, RequestEvent as Rt, binding as S, parse as St, dynamic as T, EndpointLoader as Tt, streamState as U, defineMiddleware as Ut, stateValue as V, ServerError as Vt, wait as W, getEvent as Wt, cached as X, SessionOptions as Xt, CachedOptions as Y, Session as Yt, memoryStore as Z, createSession as Zt, StateAttributes as _, parseSubmission as _t, ItemSource as a, RateLimitOptions as at, action as b, ValidationIssue as bt, Memo as c, clientAddress as ct, RenderOptions as d, FailedSubmission as dt, toNodeHeaders as en, storageStore as et, RenderResult as f, IntentSubmission as ft, ScopeEntry as g, SuccessfulSubmission as gt, RouteOptions as h, SubmissionOptions as ht, DocumentOptions as i, RateLimitMiddleware as it, lazy as j, RouteNode as jt, insert as k, MiddlewareLoader as kt, NotReady as l, configureRateLimit as lt, RevealOrder as m, Submission as mt, Context as n, RateLimitConfig as nt, Lazy as o, RateLimitStore as ot, RequestOptions as p, ReplyOptions as pt, idempotent as q, withEvent as qt, DeferTarget as r, RateLimitError as rt, Mark as s, Window as st, Component as t, RateLimit as tt, PageCache as u, rateLimit as ut, StateMap as v, ParseResult as vt, component as w, safeParse as wt, actionResult as x, fieldErrors as xt, StreamOptions as y, ValidationError as yt, spread as z, RequestEventOptions as zt };
1460
+ //# sourceMappingURL=server-DuFYRXrd.d.ts.map