brumate 0.1.0 → 0.2.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/dist/{boot-DN1ZU8Hg.d.ts → boot-D-IdPy7B.d.ts} +24 -2
- package/dist/cli.js +2 -2
- package/dist/client-C0UCNL3J.js +1643 -0
- package/dist/client-C0UCNL3J.js.map +1 -0
- package/dist/{client-DwJInP_a.d.ts → client-MD0ZmcFR.d.ts} +101 -26
- package/dist/{client-routes-DakuM32C.js → client-routes-JTbGtukf.js} +28 -15
- package/dist/client-routes-JTbGtukf.js.map +1 -0
- package/dist/context-CTiSzQRc.js +27 -0
- package/dist/context-CTiSzQRc.js.map +1 -0
- package/dist/context-btHuB01Z.d.ts +42 -0
- package/dist/defer-D0bo1Gqx.js +52 -0
- package/dist/defer-D0bo1Gqx.js.map +1 -0
- package/dist/{devtools-BKjnHrnv.js → devtools-C50VH8gZ.js} +2 -2
- package/dist/devtools-C50VH8gZ.js.map +1 -0
- package/dist/{devtools-panel-AWOn0VK2.js → devtools-panel-AYjfwPhj.js} +4 -3
- package/dist/devtools-panel-AYjfwPhj.js.map +1 -0
- package/dist/events-BKWRqtMg.js +52 -0
- package/dist/events-BKWRqtMg.js.map +1 -0
- package/dist/{files-BBLPU9JR.js → files-Bnn1JqHx.js} +18 -3
- package/dist/files-Bnn1JqHx.js.map +1 -0
- package/dist/{html-DEeoepg3.js → html-bHZbkK-h.js} +26 -8
- package/dist/html-bHZbkK-h.js.map +1 -0
- package/dist/{html-Du8jY2Cc.d.ts → html-y1q7-t7D.d.ts} +12 -5
- package/dist/index.d.ts +79 -29
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/{inspect-CRZlO11T.js → inspect-BJtACnQp.js} +928 -91
- package/dist/inspect-BJtACnQp.js.map +1 -0
- package/dist/{loader-Dc9OwY5I.js → loader-B18i3_-T.js} +46 -11
- package/dist/loader-B18i3_-T.js.map +1 -0
- package/dist/{navigate-CzLjnoPH.js → navigate-BwuZveDF.js} +71 -12
- package/dist/navigate-BwuZveDF.js.map +1 -0
- package/dist/{produce-BRGHP7e0.js → produce-CWfJ4byV.js} +43 -2
- package/dist/produce-CWfJ4byV.js.map +1 -0
- package/dist/{produce-CtZ32UGG.d.ts → produce-D4K7qpaL.d.ts} +23 -11
- package/dist/routes-BZNt7DSZ.d.ts +38 -0
- package/dist/{rpc-9fSqL_YK.js → rpc-B-Zkn6Ch.js} +24 -18
- package/dist/rpc-B-Zkn6Ch.js.map +1 -0
- package/dist/runtime/batch.d.ts +23 -0
- package/dist/runtime/batch.js +69 -0
- package/dist/runtime/batch.js.map +1 -0
- package/dist/runtime/client.d.ts +5 -5
- package/dist/runtime/client.js +5 -1345
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.js +1 -1
- package/dist/runtime/devtools.d.ts +5 -4
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/env.d.ts +44 -0
- package/dist/runtime/env.js +61 -0
- package/dist/runtime/env.js.map +1 -0
- package/dist/runtime/events.d.ts +27 -0
- package/dist/runtime/events.js +1 -0
- package/dist/runtime/hot.d.ts +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.d.ts +2 -21
- package/dist/runtime/routes.js +31 -1
- package/dist/runtime/routes.js.map +1 -1
- package/dist/runtime/server.d.ts +6 -5
- package/dist/runtime/server.js +5 -6
- package/dist/runtime/signals.d.ts +22 -1
- package/dist/runtime/signals.js +29 -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 +46 -5
- package/dist/runtime/testing.js +240 -33
- package/dist/runtime/testing.js.map +1 -1
- package/dist/secrets-BxagsJxJ.js +23 -0
- package/dist/secrets-BxagsJxJ.js.map +1 -0
- package/dist/{server-BxqjLUnV.d.ts → server-BA9SJ2Vm.d.ts} +544 -106
- package/dist/server-BqfM95r1.js +2762 -0
- package/dist/server-BqfM95r1.js.map +1 -0
- package/dist/skew-FRmAy9iy.js +49 -0
- package/dist/skew-FRmAy9iy.js.map +1 -0
- package/dist/standard-schema-BNY82yX3.d.ts +63 -0
- package/dist/{static-loader-BcFh4ebX.d.ts → static-loader-BzE9SRaj.d.ts} +2 -2
- package/dist/{static-loader-ClNkHZGn.js → static-loader-DOygOFj5.js} +52 -21
- package/dist/static-loader-DOygOFj5.js.map +1 -0
- package/dist/{stream-bgNCMcaA.js → stream-JaMHMdBD.js} +126 -61
- package/dist/stream-JaMHMdBD.js.map +1 -0
- package/dist/vite.d.ts +42 -1
- package/dist/vite.js +435 -55
- package/dist/vite.js.map +1 -1
- package/package.json +15 -2
- package/types.d.ts +9 -1
- package/dist/client-routes-DakuM32C.js.map +0 -1
- package/dist/context-BG8KCF3v.js +0 -15
- package/dist/context-BG8KCF3v.js.map +0 -1
- package/dist/context-aeo9esY9.d.ts +0 -16
- package/dist/devtools-BKjnHrnv.js.map +0 -1
- package/dist/devtools-panel-AWOn0VK2.js.map +0 -1
- package/dist/files-BBLPU9JR.js.map +0 -1
- package/dist/html-DEeoepg3.js.map +0 -1
- package/dist/inspect-CRZlO11T.js.map +0 -1
- package/dist/loader-Dc9OwY5I.js.map +0 -1
- package/dist/navigate-CzLjnoPH.js.map +0 -1
- package/dist/produce-BRGHP7e0.js.map +0 -1
- package/dist/rpc-9fSqL_YK.js.map +0 -1
- package/dist/runtime/client.js.map +0 -1
- package/dist/server-DZsgnPKS.js +0 -1615
- package/dist/server-DZsgnPKS.js.map +0 -1
- package/dist/shared-CWYOd0H3.js +0 -40
- package/dist/shared-CWYOd0H3.js.map +0 -1
- package/dist/static-loader-ClNkHZGn.js.map +0 -1
- package/dist/stream-bgNCMcaA.js.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { t as Raw } from "./html-
|
|
2
|
-
import { a as PageState, i as PackedState, n as ElementReference } from "./produce-
|
|
3
|
-
import { t as Context$1 } from "./context-
|
|
1
|
+
import { t as Raw } from "./html-y1q7-t7D.js";
|
|
2
|
+
import { a as PageState, i as PackedState, n as ElementReference, o as ScopeId, s as ScopeState } from "./produce-D4K7qpaL.js";
|
|
3
|
+
import { t as Context$1 } from "./context-btHuB01Z.js";
|
|
4
|
+
import { t as StandardSchemaV1 } from "./standard-schema-BNY82yX3.js";
|
|
4
5
|
//#region src/runtime/cookies.d.ts
|
|
5
6
|
interface CookieOptions {
|
|
6
7
|
/** Seconds until the cookie expires. Without it, the cookie lasts until the browser closes. */
|
|
@@ -68,6 +69,46 @@ declare function createSession<T>(options: SessionOptions): Session<T>;
|
|
|
68
69
|
declare function toNodeHeaders(headers: Headers): Record<string, string | string[]>;
|
|
69
70
|
//#endregion
|
|
70
71
|
//#region src/runtime/request.d.ts
|
|
72
|
+
/**
|
|
73
|
+
* What a request is for. A form post to a server function is a call, and a
|
|
74
|
+
* form post to a page with `?__action=<id>` is a page.
|
|
75
|
+
*/
|
|
76
|
+
type RequestKind = "page" | "endpoint" | "call" | "defer";
|
|
77
|
+
/**
|
|
78
|
+
* Values that middleware hands to the components, server functions and
|
|
79
|
+
* endpoints of a request, such as the user. An app adds fields to it:
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* declare module 'brumate/server' {
|
|
83
|
+
* interface Locals {
|
|
84
|
+
* user?: { id: string; name: string };
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
interface Locals {}
|
|
90
|
+
/** The server function that a request calls, with its arguments as they were read. */
|
|
91
|
+
interface RequestCall {
|
|
92
|
+
id: string;
|
|
93
|
+
args: unknown[];
|
|
94
|
+
}
|
|
95
|
+
interface RequestEventOptions {
|
|
96
|
+
kind?: RequestKind;
|
|
97
|
+
/**
|
|
98
|
+
* Keeps work going after the response ends, such as the `waitUntil` of
|
|
99
|
+
* Cloudflare Workers. Without it, the promise runs on its own and its
|
|
100
|
+
* error is logged.
|
|
101
|
+
*/
|
|
102
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
103
|
+
/**
|
|
104
|
+
* The address of the client as the server saw it, such as the remote
|
|
105
|
+
* address of the socket. `clientAddress` reads it, and looks past the
|
|
106
|
+
* trusted proxies in `X-Forwarded-For` when it is one of them.
|
|
107
|
+
*/
|
|
108
|
+
address?: string;
|
|
109
|
+
/** True while the build prerenders the page. Rate limits do not count then. */
|
|
110
|
+
prerender?: boolean;
|
|
111
|
+
}
|
|
71
112
|
/**
|
|
72
113
|
* A request that the server handles: a server function call, a form post,
|
|
73
114
|
* a page render, or a call of middleware or an endpoint. Its methods read
|
|
@@ -75,6 +116,22 @@ declare function toNodeHeaders(headers: Headers): Record<string, string | string
|
|
|
75
116
|
*/
|
|
76
117
|
declare class RequestEvent {
|
|
77
118
|
readonly request: Request;
|
|
119
|
+
/** What the request is for. */
|
|
120
|
+
readonly kind: RequestKind;
|
|
121
|
+
/** For a call, and a page that a form posted to, the server function and its arguments. */
|
|
122
|
+
call?: RequestCall;
|
|
123
|
+
/** Values for this request, which middleware writes and the rest of the request reads. */
|
|
124
|
+
readonly locals: Locals;
|
|
125
|
+
/** The address of the client as the server saw it, when the server passed it. */
|
|
126
|
+
readonly address?: string;
|
|
127
|
+
/** True while the build prerenders the page. */
|
|
128
|
+
readonly prerender: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* The pattern of the route files that matched the path, such as
|
|
131
|
+
* `/todos/[id]`. `handleRoute` sets it. Undefined for a path that no route
|
|
132
|
+
* matches.
|
|
133
|
+
*/
|
|
134
|
+
route?: string;
|
|
78
135
|
/** Headers to add to the response, such as `cache-control`. */
|
|
79
136
|
readonly headers: Headers;
|
|
80
137
|
/** The status that `setStatus` set. */
|
|
@@ -83,7 +140,25 @@ declare class RequestEvent {
|
|
|
83
140
|
refreshed?: Set<unknown>;
|
|
84
141
|
/** Cookies that this request set, or deleted with undefined, so later reads see them. */
|
|
85
142
|
cookies?: Map<string, string | undefined>;
|
|
86
|
-
|
|
143
|
+
private readonly controller;
|
|
144
|
+
/**
|
|
145
|
+
* Aborts when the request no longer needs an answer: the request's own
|
|
146
|
+
* signal aborts, or the reader of the response went away, such as a
|
|
147
|
+
* browser that left the page while it streamed. Pass it on, such as to
|
|
148
|
+
* `fetch(url, { signal })`, so work that nobody waits for stops.
|
|
149
|
+
*/
|
|
150
|
+
readonly signal: AbortSignal;
|
|
151
|
+
private readonly keepGoing?;
|
|
152
|
+
constructor(request: Request, options?: RequestEventOptions);
|
|
153
|
+
/** Aborts `signal`, such as when the response's reader went away. The server calls it. */
|
|
154
|
+
abort(reason?: unknown): void;
|
|
155
|
+
/**
|
|
156
|
+
* Keeps work going after the response ends, such as a log line or
|
|
157
|
+
* analytics. On a host that stops a function when its response ends, the
|
|
158
|
+
* server passes the promise to the host, through the `waitUntil` option.
|
|
159
|
+
* Elsewhere the promise runs on its own, and its error is logged.
|
|
160
|
+
*/
|
|
161
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
87
162
|
/**
|
|
88
163
|
* Sets the status of the page response, such as 404 for a page that shows
|
|
89
164
|
* that nothing was found. It works while the first render of a page runs.
|
|
@@ -134,6 +209,25 @@ declare function withEvent<T>(event: RequestEvent | undefined, callback: () => T
|
|
|
134
209
|
* ```
|
|
135
210
|
*/
|
|
136
211
|
declare function getEvent(): RequestEvent;
|
|
212
|
+
/**
|
|
213
|
+
* Middleware that runs for every request of the app: pages, endpoints,
|
|
214
|
+
* server function calls, form posts and the requests for `#defer` bodies.
|
|
215
|
+
* It answers the request itself, or calls `next` for the answer and returns
|
|
216
|
+
* it, changed or not. `event.kind` says what the request is for.
|
|
217
|
+
*/
|
|
218
|
+
type EntryMiddleware = (event: RequestEvent, next: () => Promise<Response>) => Response | Promise<Response>;
|
|
219
|
+
/**
|
|
220
|
+
* Types the middleware of the entry file, `src/middleware.ts`, which the
|
|
221
|
+
* Vite plugin runs for every request:
|
|
222
|
+
*
|
|
223
|
+
* ```ts
|
|
224
|
+
* export default defineMiddleware(async (event, next) => {
|
|
225
|
+
* event.locals.user = await readUser(event);
|
|
226
|
+
* return next();
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
declare function defineMiddleware(middleware: EntryMiddleware): EntryMiddleware;
|
|
137
231
|
/**
|
|
138
232
|
* Wraps a server function, so its calls while a page renders share a result
|
|
139
233
|
* when their arguments are the same. Calls from the browser, which are
|
|
@@ -233,6 +327,8 @@ interface RouteView {
|
|
|
233
327
|
interface RouteMatch {
|
|
234
328
|
view: RouteView;
|
|
235
329
|
params: Record<string, string>;
|
|
330
|
+
/** The pattern of the route files that matched, such as `/todos/[id]`, or `/` for the root. */
|
|
331
|
+
route: string;
|
|
236
332
|
/** The endpoint at the path, if the folder has one. */
|
|
237
333
|
endpoint?: EndpointLoader;
|
|
238
334
|
/** The middleware of the folders on the path, from the outside in. */
|
|
@@ -246,67 +342,6 @@ interface RouteMatch {
|
|
|
246
342
|
/** Finds the route for a path. A path with a malformed escape, such as `/%E0`, matches none. */
|
|
247
343
|
declare function matchRoute(tree: RouteNode, pathname: string): RouteMatch | undefined;
|
|
248
344
|
//#endregion
|
|
249
|
-
//#region src/runtime/standard-schema.d.ts
|
|
250
|
-
/** The Standard Schema interface. */
|
|
251
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
252
|
-
/** The Standard Schema properties. */
|
|
253
|
-
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
254
|
-
}
|
|
255
|
-
declare namespace StandardSchemaV1 {
|
|
256
|
-
/** The Standard Schema properties interface. */
|
|
257
|
-
export interface Props<Input = unknown, Output = Input> {
|
|
258
|
-
/** The version number of the standard. */
|
|
259
|
-
readonly version: 1;
|
|
260
|
-
/** The vendor name of the schema library. */
|
|
261
|
-
readonly vendor: string;
|
|
262
|
-
/** Validates unknown input values. */
|
|
263
|
-
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
264
|
-
/** Inferred types associated with the schema. */
|
|
265
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
266
|
-
}
|
|
267
|
-
/** The result interface of the validate function. */
|
|
268
|
-
export type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
269
|
-
/** The result interface if validation succeeds. */
|
|
270
|
-
export interface SuccessResult<Output> {
|
|
271
|
-
/** The typed output value. */
|
|
272
|
-
readonly value: Output;
|
|
273
|
-
/** A falsy value for `issues` indicates success. */
|
|
274
|
-
readonly issues?: undefined;
|
|
275
|
-
}
|
|
276
|
-
export interface Options {
|
|
277
|
-
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
278
|
-
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
279
|
-
}
|
|
280
|
-
/** The result interface if validation fails. */
|
|
281
|
-
export interface FailureResult {
|
|
282
|
-
/** The issues of failed validation. */
|
|
283
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
284
|
-
}
|
|
285
|
-
/** The issue interface of the failure output. */
|
|
286
|
-
export interface Issue {
|
|
287
|
-
/** The error message of the issue. */
|
|
288
|
-
readonly message: string;
|
|
289
|
-
/** The path of the issue, if any. */
|
|
290
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
291
|
-
}
|
|
292
|
-
/** The path segment interface of the issue. */
|
|
293
|
-
export interface PathSegment {
|
|
294
|
-
/** The key representing a path segment. */
|
|
295
|
-
readonly key: PropertyKey;
|
|
296
|
-
}
|
|
297
|
-
/** The Standard Schema types interface. */
|
|
298
|
-
export interface Types<Input = unknown, Output = Input> {
|
|
299
|
-
/** The input type of the schema. */
|
|
300
|
-
readonly input: Input;
|
|
301
|
-
/** The output type of the schema. */
|
|
302
|
-
readonly output: Output;
|
|
303
|
-
}
|
|
304
|
-
/** Infers the input type of a Standard Schema. */
|
|
305
|
-
export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
306
|
-
/** Infers the output type of a Standard Schema. */
|
|
307
|
-
export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
308
|
-
}
|
|
309
|
-
//#endregion
|
|
310
345
|
//#region src/runtime/validate.d.ts
|
|
311
346
|
/**
|
|
312
347
|
* A problem that a schema found, as plain data that the server can send to
|
|
@@ -378,12 +413,124 @@ declare function parseForm<S extends StandardSchemaV1>(schema: S, form: FormData
|
|
|
378
413
|
*/
|
|
379
414
|
declare function fieldErrors(issues: readonly (StandardSchemaV1.Issue | ValidationIssue)[]): Record<string, string[]>;
|
|
380
415
|
//#endregion
|
|
416
|
+
//#region src/runtime/rate-limit.d.ts
|
|
417
|
+
/**
|
|
418
|
+
* Where a limit keeps its counts. The default counts in memory, per
|
|
419
|
+
* process. An app with more than one server passes a store on Redis or a
|
|
420
|
+
* platform store, whose `increment` is one atomic command, such as `INCR`
|
|
421
|
+
* with `EXPIRE`. A limit decides on the count that `increment` returns, so
|
|
422
|
+
* requests at the same time cannot all read one count and all pass.
|
|
423
|
+
*/
|
|
424
|
+
interface RateLimitStore {
|
|
425
|
+
/**
|
|
426
|
+
* Adds one to the count of a key, which expires after `ttl` milliseconds,
|
|
427
|
+
* and returns the new count, in one atomic step.
|
|
428
|
+
*/
|
|
429
|
+
increment(key: string, ttl: number): number | Promise<number>;
|
|
430
|
+
/** The count of a key, or undefined when it has none or it expired. */
|
|
431
|
+
get(key: string): number | undefined | Promise<number | undefined>;
|
|
432
|
+
}
|
|
433
|
+
/** A window as a number of milliseconds, or as text such as `'10s'`, `'1m'` or `'1h'`. */
|
|
434
|
+
type Window = number | `${number}${"ms" | "s" | "m" | "h" | "d"}`;
|
|
435
|
+
interface RateLimitOptions {
|
|
436
|
+
/** How many requests a key can make in the window. */
|
|
437
|
+
max: number;
|
|
438
|
+
/** The length of the window. */
|
|
439
|
+
window: Window;
|
|
440
|
+
/**
|
|
441
|
+
* What to count by, from the event and the arguments of the call, such as
|
|
442
|
+
* the ID of the user in `event.locals`, or the email of a sign-in form.
|
|
443
|
+
* Without a key, or when it returns undefined, the limit counts by the
|
|
444
|
+
* address of the client that the server passed. Each server function, or
|
|
445
|
+
* each route for middleware, counts on its own, whatever the key.
|
|
446
|
+
*/
|
|
447
|
+
key?: (event: RequestEvent, args: unknown[]) => string | undefined | Promise<string | undefined>;
|
|
448
|
+
/** The event of the request. Defaults to `getEvent()`. */
|
|
449
|
+
event?: RequestEvent;
|
|
450
|
+
/** The store of the counts. Defaults to the store of `configureRateLimit`, or memory. */
|
|
451
|
+
store?: RateLimitStore;
|
|
452
|
+
/** Whether the limit counts. Defaults to `configureRateLimit`, which is on. */
|
|
453
|
+
enabled?: boolean;
|
|
454
|
+
}
|
|
455
|
+
interface RateLimitConfig {
|
|
456
|
+
/** The store of every limit that names none. Defaults to memory, which counts per process. */
|
|
457
|
+
store?: RateLimitStore;
|
|
458
|
+
/**
|
|
459
|
+
* The proxies in front of the server, as addresses or CIDR ranges, such
|
|
460
|
+
* as `10.0.0.0/8`. `clientAddress` reads `X-Forwarded-For` when the
|
|
461
|
+
* address that the server saw is one of them. A range that is not an
|
|
462
|
+
* address, with or without a prefix length, throws.
|
|
463
|
+
*/
|
|
464
|
+
proxies?: string[];
|
|
465
|
+
/** Whether limits count. Defaults to true. Pages that the build prerenders never count. */
|
|
466
|
+
enabled?: boolean;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* The error of a request over its limit. Its status is 429, and
|
|
470
|
+
* `retryAfter` is how many seconds to wait. In the browser, the call rejects
|
|
471
|
+
* with it, and `retryAfter` comes from the `Retry-After` header.
|
|
472
|
+
*/
|
|
473
|
+
declare class RateLimitError extends ServerError {
|
|
474
|
+
readonly retryAfter: number;
|
|
475
|
+
constructor(retryAfter: number);
|
|
476
|
+
}
|
|
477
|
+
/** Sets the defaults of every limit: the store, the trusted proxies, and whether limits count. */
|
|
478
|
+
declare function configureRateLimit(options: RateLimitConfig): void;
|
|
479
|
+
/**
|
|
480
|
+
* Limits how often a key, such as the user or the address of the client,
|
|
481
|
+
* can call a server function. Call it first thing in the function, before
|
|
482
|
+
* its first `await`, as `getEvent()`:
|
|
483
|
+
*
|
|
484
|
+
* ```ts
|
|
485
|
+
* async function signIn(email: string, password: string) {
|
|
486
|
+
* 'use server';
|
|
487
|
+
* await rateLimit({ ...rateLimit.strict, key: () => email.toLowerCase() });
|
|
488
|
+
* // …
|
|
489
|
+
* }
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* The fourth call in 10 seconds for one email rejects with a
|
|
493
|
+
* `RateLimitError`, with status 429 and `Retry-After`, and the rest of the
|
|
494
|
+
* function does not run. Without a `key`, the limit counts by the address
|
|
495
|
+
* of the client, which the server passes to its handler as `address`. In
|
|
496
|
+
* production, a limit with neither throws. `rateLimit.middleware(options)`
|
|
497
|
+
* limits every request under a folder of routes, or of the whole app from
|
|
498
|
+
* the entry.
|
|
499
|
+
*/
|
|
500
|
+
declare const rateLimit: RateLimit;
|
|
501
|
+
/** A middleware of a folder, `(request, next)`, or of the entry, `(event, next)`. */
|
|
502
|
+
type RateLimitMiddleware = Middleware & ((event: RequestEvent, next: () => Promise<Response>) => Promise<Response>);
|
|
503
|
+
interface RateLimit {
|
|
504
|
+
(options: RateLimitOptions): Promise<void>;
|
|
505
|
+
/**
|
|
506
|
+
* A limit for every request that passes through a middleware, of a folder
|
|
507
|
+
* or of the entry. A request over the limit answers 429 with `Retry-After`.
|
|
508
|
+
* Each route counts on its own, by its pattern, such as `/api/[id]`.
|
|
509
|
+
*/
|
|
510
|
+
middleware: (options: RateLimitOptions) => RateLimitMiddleware;
|
|
511
|
+
/** A limit for functions that guess at secrets, such as a sign-in or a code check: 3 calls in 10 seconds. */
|
|
512
|
+
strict: RateLimitOptions;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* The address of the client of a request. It is the address that the server
|
|
516
|
+
* saw, which the handler of the server passes as `address`. When that
|
|
517
|
+
* address is one of the proxies that `configureRateLimit({ proxies })`
|
|
518
|
+
* names, it comes from `X-Forwarded-For`: the header is read from the right,
|
|
519
|
+
* past the trusted proxies, because a client can write anything at its
|
|
520
|
+
* left. An IPv6 address counts by its /64.
|
|
521
|
+
*
|
|
522
|
+
* Undefined when the server passed no address, whatever the headers say,
|
|
523
|
+
* since nothing then shows that the header comes from a proxy. Undefined too
|
|
524
|
+
* when the first hop past the proxies is not an address.
|
|
525
|
+
*/
|
|
526
|
+
declare function clientAddress(event: RequestEvent, proxies?: string[]): string | undefined;
|
|
527
|
+
//#endregion
|
|
381
528
|
//#region src/runtime/server.d.ts
|
|
382
529
|
/** The scope and the slot that hold the list of a list item. */
|
|
383
|
-
type ItemSource = readonly [scope:
|
|
530
|
+
type ItemSource = readonly [scope: ScopeId, slot: number];
|
|
384
531
|
/** A `#loading` body that renders after the rest of the page. */
|
|
385
532
|
interface Boundary {
|
|
386
|
-
id:
|
|
533
|
+
id: ScopeId;
|
|
387
534
|
/** Resolves to the body's markup, and its scopes in `ctx.state`. */
|
|
388
535
|
render: Promise<{
|
|
389
536
|
html: string;
|
|
@@ -391,22 +538,109 @@ interface Boundary {
|
|
|
391
538
|
}>;
|
|
392
539
|
/** True when a `#try` body around it failed, so its markers were never sent. */
|
|
393
540
|
cancelled?: boolean;
|
|
541
|
+
/** A body around the target of a request for a `#defer` body, which renders but is not sent. */
|
|
542
|
+
around?: boolean;
|
|
543
|
+
}
|
|
544
|
+
/** The `#defer` body that a render renders, for the request of the browser that asks for it. */
|
|
545
|
+
interface DeferTarget {
|
|
546
|
+
/** The boundary ID of the block. */
|
|
547
|
+
boundary: ScopeId;
|
|
548
|
+
/** The scope and the anchor of the block, as `<scope>:<anchor>`, which the render checks. */
|
|
549
|
+
at: string;
|
|
550
|
+
/**
|
|
551
|
+
* `found` once the render reaches the block at `at`. `moved` when it reaches the boundary
|
|
552
|
+
* elsewhere, such as after the data of the page changed and moved the IDs before it.
|
|
553
|
+
*/
|
|
554
|
+
status?: "found" | "moved";
|
|
394
555
|
}
|
|
395
556
|
/** A point in a render that `restore` goes back to. */
|
|
396
557
|
interface Mark {
|
|
558
|
+
/** The prefix of the IDs of the block that the render was in, and its counters then. */
|
|
559
|
+
prefix: string;
|
|
397
560
|
scope: number;
|
|
561
|
+
boundary: number;
|
|
562
|
+
/** How many blocks the render was in. */
|
|
563
|
+
depth: number;
|
|
398
564
|
undo: number;
|
|
399
|
-
owner:
|
|
565
|
+
owner: ScopeId | undefined;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Where a render takes its scope and boundary IDs from. The page takes
|
|
569
|
+
* numbers from its base. Each `#loading` body has its own, whose IDs are the
|
|
570
|
+
* ID of its boundary, a dot and a number, such as `5.0`. A body resumes when
|
|
571
|
+
* its data arrives, so with one counter for the page its IDs, and those of
|
|
572
|
+
* the markup after it, would depend on that order.
|
|
573
|
+
*
|
|
574
|
+
* A block whose shape depends on data, such as an `#if` or a `#for`, also
|
|
575
|
+
* numbers the scopes of its bodies after an ID of its own. The markup after
|
|
576
|
+
* the block then keeps its IDs, whichever branch rendered and however many
|
|
577
|
+
* items a list had, so a later request for a `#defer` body numbers the page
|
|
578
|
+
* the same way even when the user or the data before the block differs.
|
|
579
|
+
*/
|
|
580
|
+
interface IdSpace {
|
|
581
|
+
/** `''` for the page, or the ID of the boundary or block and a dot. */
|
|
582
|
+
prefix: string;
|
|
583
|
+
scope: number;
|
|
584
|
+
/** The counter of boundary IDs, which blocks take their IDs from too. */
|
|
585
|
+
boundary: number;
|
|
586
|
+
/** The number of the first scope, and the scopes from there on, so an ID finds its scope. */
|
|
587
|
+
first: number;
|
|
588
|
+
entries: (ScopeEntry | undefined)[];
|
|
589
|
+
}
|
|
590
|
+
/** A scope of a render: its record, and what the server keeps of it while the page renders. */
|
|
591
|
+
interface ScopeEntry {
|
|
592
|
+
id: ScopeId;
|
|
593
|
+
/** The prefix of the ID and the number after it, such as `'5.'` and `1`, or `''` and `3`. */
|
|
594
|
+
prefix: string;
|
|
595
|
+
n: number;
|
|
596
|
+
record: ScopeState;
|
|
597
|
+
/** The render whose state holds the record. */
|
|
598
|
+
ctx: Context | undefined;
|
|
599
|
+
/** The ID space that finds the scope by its ID, for a scope that `scope()` made. */
|
|
600
|
+
space?: IdSpace;
|
|
601
|
+
/** The scope that the contexts of this one are found in. */
|
|
602
|
+
parent?: ScopeId;
|
|
603
|
+
/** The values of contexts that this scope provides. */
|
|
604
|
+
values?: Map<string, unknown>;
|
|
605
|
+
/** The names of the slots, so an error can name a value that cannot be sent. */
|
|
606
|
+
names?: string[];
|
|
607
|
+
/** The scope and the slot that hold the list of this list item. */
|
|
608
|
+
source?: ItemSource;
|
|
400
609
|
}
|
|
401
610
|
/**
|
|
402
611
|
* Tracks the scopes of one render. A `#loading` body renders in a child
|
|
403
612
|
* context, so its scopes are written with its markup.
|
|
404
613
|
*/
|
|
405
614
|
declare class Context {
|
|
406
|
-
|
|
615
|
+
/**
|
|
616
|
+
* The scopes of this render, in the order it made them, with their
|
|
617
|
+
* records. A record that this render adds to a scope of another render,
|
|
618
|
+
* such as a link from a `#loading` body to a scope of the page, is here
|
|
619
|
+
* too, as a scope of its own.
|
|
620
|
+
*/
|
|
621
|
+
readonly scopes: ScopeEntry[];
|
|
622
|
+
/**
|
|
623
|
+
* Every ID space of the page, across the renders of `#loading` bodies, on
|
|
624
|
+
* the root context. A scope is found by its ID in the entries of its space.
|
|
625
|
+
* The spaces are put in a map by prefix only when a scope is looked up
|
|
626
|
+
* outside the blocks that are open, since a render makes many and looks
|
|
627
|
+
* up few, and each string key costs a hash.
|
|
628
|
+
*/
|
|
629
|
+
private readonly made;
|
|
630
|
+
private byPrefix;
|
|
631
|
+
private indexed;
|
|
632
|
+
/** The records that this render adds to scopes of other renders, by ID. */
|
|
633
|
+
private partials;
|
|
634
|
+
/** The scope that the render used last, since it uses one a few times in a row. */
|
|
635
|
+
private last;
|
|
407
636
|
private readonly root;
|
|
408
|
-
|
|
409
|
-
private
|
|
637
|
+
/** The ID spaces of the blocks that the render is in, from the outside in. */
|
|
638
|
+
private readonly spaces;
|
|
639
|
+
private readonly baseId;
|
|
640
|
+
/** The `#defer` body to render, in the request for it. The rest of the page renders no body. */
|
|
641
|
+
target: DeferTarget | undefined;
|
|
642
|
+
/** True in the context of the target body and the bodies inside it. */
|
|
643
|
+
private inTarget;
|
|
410
644
|
private readonly boundaries;
|
|
411
645
|
private readonly styles;
|
|
412
646
|
/** Markup of `#portal` blocks, written at the end of the page. */
|
|
@@ -414,19 +648,26 @@ declare class Context {
|
|
|
414
648
|
/** Markup of `#head` blocks. */
|
|
415
649
|
private readonly heads;
|
|
416
650
|
private pageTitle;
|
|
651
|
+
/** The titles that this render set, and whether they all came from a `<title>` in `#head`. */
|
|
652
|
+
private titles;
|
|
417
653
|
private onBoundary;
|
|
418
|
-
/** The scope tree of the whole page, for finding contexts across `#loading` bodies. */
|
|
419
|
-
private readonly tree;
|
|
420
654
|
/** The scope that renders the next component, which becomes its owner. */
|
|
421
655
|
private owner;
|
|
656
|
+
/**
|
|
657
|
+
* Children that render where they are inserted: the scope of the markup
|
|
658
|
+
* that wrote them, and the scope where they are, for their contexts.
|
|
659
|
+
*/
|
|
660
|
+
private readonly inserted;
|
|
422
661
|
/** Takes back what this context added to the page, from the newest, for `restore`. */
|
|
423
662
|
private readonly undo;
|
|
424
663
|
/** The URL prefix of server function calls. */
|
|
425
664
|
private rpcPrefix;
|
|
426
|
-
/** The
|
|
427
|
-
|
|
665
|
+
/** The ID of the build, for forms that post to server functions. See `RenderOptions`. */
|
|
666
|
+
build: string | undefined;
|
|
428
667
|
/** Results of server functions that a form posted to this page, for `$action`. */
|
|
429
668
|
actions: Map<unknown, unknown>;
|
|
669
|
+
/** The params of the route of the page, for `$route`. */
|
|
670
|
+
params: Record<string, string>;
|
|
430
671
|
/** The request of the page, when it renders with one. */
|
|
431
672
|
event: RequestEvent | undefined;
|
|
432
673
|
/** Results of server function calls in this render, so the same call runs once. */
|
|
@@ -437,31 +678,65 @@ declare class Context {
|
|
|
437
678
|
run<T>(callback: () => T): T;
|
|
438
679
|
/** The result of a server function that a form posted to this page. */
|
|
439
680
|
actionResult(fn: unknown): unknown;
|
|
440
|
-
|
|
441
|
-
|
|
681
|
+
/** `prefix` is the boundary ID and a dot, for the context of a `#loading` body. */
|
|
682
|
+
constructor(root?: Context, rpc?: string, base?: number, prefix?: string);
|
|
683
|
+
/** The base of the render, which the browser sends back to ask for a `#defer` body. */
|
|
684
|
+
base(): number;
|
|
685
|
+
/** True in a request for a `#defer` body, outside the body, once the body has started. */
|
|
686
|
+
past(): boolean;
|
|
687
|
+
/**
|
|
688
|
+
* A number above every scope and boundary ID of the page so far, so a
|
|
689
|
+
* later render can start there. The IDs inside boundaries start with one.
|
|
690
|
+
*/
|
|
442
691
|
next(): number;
|
|
692
|
+
/** The space that the next IDs come from. */
|
|
693
|
+
private get space();
|
|
694
|
+
/**
|
|
695
|
+
* Starts a block whose shape depends on data, such as an `#if` or a
|
|
696
|
+
* `#for`. The scopes of its bodies are numbered after one ID that the
|
|
697
|
+
* block takes, until `leave`. A `#loading` body that renders in place
|
|
698
|
+
* passes the ID of its boundary, so its scopes get the IDs that they
|
|
699
|
+
* would get in a stream.
|
|
700
|
+
*/
|
|
701
|
+
enter(id?: ScopeId): void;
|
|
702
|
+
/** Ends the block that `enter` started. */
|
|
703
|
+
leave(): void;
|
|
443
704
|
/** Returns the URL prefix of server function calls. */
|
|
444
705
|
rpc(): string;
|
|
706
|
+
/** Returns the ID of the build, when the render has one. */
|
|
707
|
+
buildId(): string | undefined;
|
|
445
708
|
/**
|
|
446
709
|
* Returns a new scope ID. `kind` is the scope's ID in the compiled
|
|
447
710
|
* component, `parent` is the scope that contains it, and `module` is the
|
|
448
711
|
* component ID of a component's root scope.
|
|
449
712
|
*/
|
|
450
|
-
scope(kind: number, parent?:
|
|
451
|
-
/** The
|
|
452
|
-
|
|
713
|
+
scope(kind: number, parent?: ScopeId, module?: string): ScopeId;
|
|
714
|
+
/** The scope of the page with an ID, from any render. */
|
|
715
|
+
private find;
|
|
716
|
+
/**
|
|
717
|
+
* Renders children where a component inserts them, at `at`. Their scopes
|
|
718
|
+
* keep `from`, the scope of the markup that wrote them, for their values,
|
|
719
|
+
* and find their contexts from `at`.
|
|
720
|
+
*/
|
|
721
|
+
children(from: ScopeId, at: ScopeId, renderBody: () => Promise<string>): Promise<string>;
|
|
722
|
+
/**
|
|
723
|
+
* The ID that `$id()` makes: the scope's ID and the position of the call.
|
|
724
|
+
* A dot in a scope ID inside a `#loading` body becomes `_`, so the ID also
|
|
725
|
+
* works as a CSS selector, such as `#b5_1-0`.
|
|
726
|
+
*/
|
|
727
|
+
id(scope: ScopeId, index: number): string;
|
|
453
728
|
/** Sets the owner of the next component's root scope. */
|
|
454
|
-
own(scope:
|
|
729
|
+
own(scope: ScopeId): void;
|
|
455
730
|
/** Provides a value of a context to the scopes inside `scope`. */
|
|
456
|
-
provide<T>(context: Context$1<T>, value: T, scope:
|
|
731
|
+
provide<T>(context: Context$1<T>, value: T, scope: ScopeId): void;
|
|
457
732
|
/**
|
|
458
733
|
* Reads a context from the nearest scope that provides it, starting at
|
|
459
734
|
* `scope`. With `slot`, records which slot holds it, so the client can
|
|
460
735
|
* update it when the provided value changes.
|
|
461
736
|
*/
|
|
462
|
-
consume<T>(context: Context$1<T>, scope:
|
|
737
|
+
consume<T>(context: Context$1<T>, scope: ScopeId, slot?: number): T;
|
|
463
738
|
/** The ID that the next call to `scope()` returns. */
|
|
464
|
-
peek():
|
|
739
|
+
peek(): ScopeId;
|
|
465
740
|
/** Marks the render so far, such as before a `#try` body, for `restore`. */
|
|
466
741
|
mark(): Mark;
|
|
467
742
|
/**
|
|
@@ -478,31 +753,40 @@ declare class Context {
|
|
|
478
753
|
* scopes stay.
|
|
479
754
|
*/
|
|
480
755
|
private drop;
|
|
756
|
+
/** The scope of this render with an ID, or the record that this render adds to another's. */
|
|
757
|
+
private entry;
|
|
481
758
|
private record;
|
|
482
|
-
|
|
759
|
+
/** The record of a scope in the state of this render, if it is there. */
|
|
760
|
+
ownRecord(scope: ScopeId): ScopeState | undefined;
|
|
761
|
+
/** The records of the scopes of this render, by ID, in the order the render made them. */
|
|
762
|
+
get state(): StateMap;
|
|
483
763
|
/**
|
|
484
764
|
* The list of each list item scope whose list is a slot of an enclosing
|
|
485
765
|
* scope, as `[scope, slot]`. The items of a list share one array.
|
|
486
766
|
*/
|
|
487
|
-
|
|
767
|
+
get sources(): Map<ScopeId, ItemSource>;
|
|
768
|
+
slots(scope: ScopeId, values: unknown[], names?: string[]): void;
|
|
488
769
|
/**
|
|
489
770
|
* Records the item of a list that can change on the client. `source` is
|
|
490
771
|
* the scope and slot that hold the list, when the compiler found one, so
|
|
491
772
|
* the client can take the item from there.
|
|
492
773
|
*/
|
|
493
|
-
item(scope:
|
|
774
|
+
item(scope: ScopeId, value: unknown, source?: ItemSource): void;
|
|
494
775
|
/** Records the scope of a child component at an anchor of its parent. */
|
|
495
|
-
link(scope:
|
|
776
|
+
link(scope: ScopeId, anchor: number, child: ScopeId): void;
|
|
496
777
|
/** Returns the reference that a `ref` signal holds on the server. */
|
|
497
|
-
element(scope:
|
|
778
|
+
element(scope: ScopeId, anchor: number): ElementReference;
|
|
498
779
|
/** Marks a function as a client function, so it serializes as a reference. */
|
|
499
|
-
fn<T>(value: T, ref: string, scope:
|
|
780
|
+
fn<T>(value: T, ref: string, scope: ScopeId): T;
|
|
500
781
|
/** Returns a component's stylesheet the first time the page renders the component. */
|
|
501
782
|
style(id: string, css: string): string;
|
|
502
783
|
/** Adds the markup of a `#head` block. */
|
|
503
784
|
head(html: string): void;
|
|
504
|
-
/**
|
|
505
|
-
|
|
785
|
+
/**
|
|
786
|
+
* Sets the title of the page. The last call wins. `markup` is true for a
|
|
787
|
+
* `<title>` in `#head`, which is in the head already.
|
|
788
|
+
*/
|
|
789
|
+
title(value: unknown, markup?: boolean): void;
|
|
506
790
|
/** True once the first render is done, and its head is about to be sent. */
|
|
507
791
|
private sent;
|
|
508
792
|
/** Marks the first render as done. Head markup after it streams with its `#loading` body. */
|
|
@@ -519,10 +803,24 @@ declare class Context {
|
|
|
519
803
|
headHTML(): string;
|
|
520
804
|
/** Adds the markup of a `#portal` block, which goes after the rest of the page. */
|
|
521
805
|
portal(html: string): void;
|
|
806
|
+
/** Adds the head markup and the title of a body that renders in place, to the head of the page. */
|
|
807
|
+
adoptHead(late: {
|
|
808
|
+
html: string;
|
|
809
|
+
title: string | undefined;
|
|
810
|
+
}): void;
|
|
811
|
+
/** True when the bodies of `#defer` blocks render in place, for a page that renders in order. */
|
|
812
|
+
inOrder: boolean;
|
|
522
813
|
/** Returns the ID of a new `#loading` boundary. */
|
|
523
|
-
boundary():
|
|
524
|
-
/** Renders a `#loading` body after the rest of the page, in its own context. */
|
|
525
|
-
defer(id:
|
|
814
|
+
boundary(): ScopeId;
|
|
815
|
+
/** Renders a `#loading` body after the rest of the page, in its own context and ID space. */
|
|
816
|
+
defer(id: ScopeId, renderBody: (ctx: Context) => Promise<string>): void;
|
|
817
|
+
/**
|
|
818
|
+
* Renders the body of a `#defer` block, in the request for it. `at` is
|
|
819
|
+
* the scope and the anchor of the block. A page renders only the
|
|
820
|
+
* fallback, so it does nothing then.
|
|
821
|
+
*/
|
|
822
|
+
deferBlock(id: ScopeId, at: string, renderBody: (ctx: Context) => Promise<string>): void;
|
|
823
|
+
private register;
|
|
526
824
|
/** Receives every boundary, including those registered before this call. */
|
|
527
825
|
watch(onBoundary: (boundary: Boundary) => void): void;
|
|
528
826
|
}
|
|
@@ -556,13 +854,41 @@ declare function wait(node: Memo): Promise<unknown>;
|
|
|
556
854
|
* The render then awaits only a memo that is loading.
|
|
557
855
|
*/
|
|
558
856
|
declare function ready(node: Memo): unknown;
|
|
857
|
+
/**
|
|
858
|
+
* The value of a memo for the page state: its value when it is ready, or
|
|
859
|
+
* a promise of it while it loads. A memo that fails gives a rejected
|
|
860
|
+
* promise either way, so the page renders and the failure reaches the
|
|
861
|
+
* browser as the load that failed.
|
|
862
|
+
*/
|
|
863
|
+
declare function stateValue(node: Memo): unknown;
|
|
864
|
+
/**
|
|
865
|
+
* Starts every memo of a run of declarations that the render waits for,
|
|
866
|
+
* so they load at the same time. Returns a promise that settles when all
|
|
867
|
+
* of them have, or undefined when none is loading. A memo that fails
|
|
868
|
+
* throws here, or rejects the promise.
|
|
869
|
+
*/
|
|
870
|
+
declare function waitAll(nodes: Memo[]): Promise<unknown> | undefined;
|
|
871
|
+
/**
|
|
872
|
+
* True when every memo has its value, so a `#loading` body that reads them
|
|
873
|
+
* can render in place. A memo that is not computed yet computes here, so
|
|
874
|
+
* the loads of the memos that are not ready start now, and the body that
|
|
875
|
+
* streams later finds them loading. A memo that failed counts as not ready:
|
|
876
|
+
* the body streams, and throws where it reads the memo.
|
|
877
|
+
*/
|
|
878
|
+
declare function settled(nodes: Memo[]): boolean;
|
|
559
879
|
declare const LAZY: unique symbol;
|
|
560
880
|
/** Markup that renders where it is inserted, so it can read the contexts there. */
|
|
561
881
|
interface Lazy {
|
|
562
|
-
[LAZY]: (ctx: Context, scope:
|
|
882
|
+
[LAZY]: (ctx: Context, scope: ScopeId | undefined) => Promise<string>;
|
|
563
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* The children of a component, which render where the component inserts
|
|
886
|
+
* them, so they read the contexts that the component provides. `from` is the
|
|
887
|
+
* scope of the markup that wrote them.
|
|
888
|
+
*/
|
|
889
|
+
declare function children(from: ScopeId, renderBody: (ctx: Context) => Promise<string>): Lazy;
|
|
564
890
|
/** Makes markup that renders where it is inserted, such as the children of a layout. */
|
|
565
|
-
declare function lazy(renderAt: (ctx: Context, scope:
|
|
891
|
+
declare function lazy(renderAt: (ctx: Context, scope: ScopeId | undefined) => Promise<string>): Lazy;
|
|
566
892
|
/** Renders the attributes of a form or button that posts to a server function. */
|
|
567
893
|
declare function action(ctx: Context, name: string, id: string, method?: string, result?: string): string;
|
|
568
894
|
/**
|
|
@@ -574,28 +900,30 @@ declare function actionResult(ctx: Context, fn: unknown): unknown;
|
|
|
574
900
|
* Renders a value inserted in markup. `ctx` and `scope` are where it is
|
|
575
901
|
* inserted, for markup that renders there.
|
|
576
902
|
*/
|
|
577
|
-
declare function insert(value: unknown, ctx?: Context, scope?:
|
|
903
|
+
declare function insert(value: unknown, ctx?: Context, scope?: ScopeId): string | Promise<string>;
|
|
578
904
|
type Component<P = any> = (props: P, ctx: Context) => Promise<string>;
|
|
579
905
|
/**
|
|
580
906
|
* Renders a child component. With `scope` and `anchor`, records the child's
|
|
581
907
|
* scope so the parent can update its props on the client.
|
|
582
908
|
*/
|
|
583
|
-
declare function component<P>(Child: Component<P>, props: P, ctx: Context, scope?:
|
|
909
|
+
declare function component<P>(Child: Component<P>, props: P, ctx: Context, scope?: ScopeId, anchor?: number): Promise<string>;
|
|
584
910
|
/** Renders a dynamic tag, which can be an element name or a component. */
|
|
585
|
-
declare function dynamic(tag: string | Component, attributes: Record<string, unknown>,
|
|
911
|
+
declare function dynamic(tag: string | Component, attributes: Record<string, unknown>, content: Raw | Lazy | undefined, ctx: Context, scope?: ScopeId): string | Promise<string>;
|
|
912
|
+
/** The records of the scopes of a render, by scope ID. */
|
|
913
|
+
type StateMap = Map<ScopeId, ScopeState>;
|
|
586
914
|
/**
|
|
587
915
|
* Writes the records of scopes with the same kind, parent and shape, such as
|
|
588
916
|
* the items of a list, in groups. Each one then costs its slots and the gap
|
|
589
917
|
* to the ID before it. The items of a list whose list is in `sources` and in
|
|
590
918
|
* the state are not written. See `PackedState`.
|
|
591
919
|
*/
|
|
592
|
-
declare function packState(
|
|
920
|
+
declare function packState(input: PageState | StateMap, sources?: Map<ScopeId, ItemSource>): PackedState;
|
|
593
921
|
/**
|
|
594
922
|
* Serializes the page state as the code of state records. `onRecord`
|
|
595
923
|
* receives each record as soon as it is ready. The promise resolves when
|
|
596
924
|
* every promise in the state has settled.
|
|
597
925
|
*/
|
|
598
|
-
declare function streamState(state: PageState, onRecord: (code: string, initial: boolean) => void): Promise<void>;
|
|
926
|
+
declare function streamState(state: PageState | StateMap, onRecord: (code: string, initial: boolean) => void): Promise<void>;
|
|
599
927
|
interface StateAttributes {
|
|
600
928
|
/** A number above every ID so far, on each record with scopes. */
|
|
601
929
|
next?: number;
|
|
@@ -603,10 +931,14 @@ interface StateAttributes {
|
|
|
603
931
|
define?: boolean;
|
|
604
932
|
/** The route of the page. */
|
|
605
933
|
route?: string;
|
|
606
|
-
/** The base of the render, when it is above 0. */
|
|
607
|
-
root?: number;
|
|
934
|
+
/** The base of the render, when it is above 0, or the key of a `#defer` body's records. */
|
|
935
|
+
root?: number | string;
|
|
608
936
|
/** The Content Security Policy nonce of the script. */
|
|
609
937
|
nonce?: string;
|
|
938
|
+
/** The params of the route of the page, on its first record, for `$route` in the browser. */
|
|
939
|
+
params?: Record<string, string>;
|
|
940
|
+
/** The ID of the build that rendered the page, on its first record, for skew protection. */
|
|
941
|
+
build?: string;
|
|
610
942
|
}
|
|
611
943
|
/**
|
|
612
944
|
* Returns the script of a state record. `scopes` marks a record with scopes,
|
|
@@ -637,6 +969,17 @@ interface RenderResult {
|
|
|
637
969
|
next: () => number;
|
|
638
970
|
/** Markup for the document's head: the `$title` and the `#head` blocks. */
|
|
639
971
|
head: string;
|
|
972
|
+
/**
|
|
973
|
+
* The event of the request. Its `signal` aborts when the reader of the
|
|
974
|
+
* response goes away, which `streamParts` and `renderToStream` report.
|
|
975
|
+
*/
|
|
976
|
+
event?: RequestEvent;
|
|
977
|
+
/**
|
|
978
|
+
* With the `defer` option, whether the render found the block: `found`,
|
|
979
|
+
* `moved` when the boundary is at another place, such as after the data
|
|
980
|
+
* of the page changed, or `missing`.
|
|
981
|
+
*/
|
|
982
|
+
defer?: "found" | "moved" | "missing";
|
|
640
983
|
}
|
|
641
984
|
interface RenderOptions {
|
|
642
985
|
/** The URL prefix of server function calls, for forms that post to one. Defaults to `/_brumate`. */
|
|
@@ -648,6 +991,17 @@ interface RenderOptions {
|
|
|
648
991
|
base?: number;
|
|
649
992
|
/** Names the route of the page, so the client knows which layouts it can keep. */
|
|
650
993
|
route?: string;
|
|
994
|
+
/**
|
|
995
|
+
* Renders `#loading` and `#defer` bodies in place, in the order of the
|
|
996
|
+
* page, instead of streaming them in `<template>`s that a script swaps in.
|
|
997
|
+
* The page arrives later, and complete, for readers that run no scripts,
|
|
998
|
+
* such as crawlers. The state is the same either way. `'bots'`, the
|
|
999
|
+
* default, does it for requests whose `User-Agent` is a known crawler. A
|
|
1000
|
+
* function decides for each request.
|
|
1001
|
+
*/
|
|
1002
|
+
inOrder?: boolean | "bots" | ((request: Request) => boolean);
|
|
1003
|
+
/** The params of the route of the page, for `$route`. `handleRoute` sets them. */
|
|
1004
|
+
params?: Record<string, string>;
|
|
651
1005
|
/** Results of server functions that a form posted to this page, by function, for `$action`. */
|
|
652
1006
|
actions?: Map<unknown, unknown>;
|
|
653
1007
|
/**
|
|
@@ -658,11 +1012,40 @@ interface RenderOptions {
|
|
|
658
1012
|
request?: Request;
|
|
659
1013
|
/** The event of the request, in place of `request`, such as one that middleware already set cookies on. */
|
|
660
1014
|
event?: RequestEvent;
|
|
1015
|
+
/**
|
|
1016
|
+
* Keeps work going after the response ends, for `event.waitUntil`, such
|
|
1017
|
+
* as the `waitUntil` of Cloudflare Workers. Without it, the promise runs
|
|
1018
|
+
* on its own and its error is logged.
|
|
1019
|
+
*/
|
|
1020
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
661
1021
|
/**
|
|
662
1022
|
* A Content Security Policy nonce for the inline scripts: the state
|
|
663
1023
|
* records, and the scripts that swap in `#loading` bodies.
|
|
664
1024
|
*/
|
|
665
1025
|
nonce?: string;
|
|
1026
|
+
/**
|
|
1027
|
+
* The ID of the build, for skew protection. The page state carries it,
|
|
1028
|
+
* and the browser sends it with each call. The Vite plugin sets it in
|
|
1029
|
+
* builds. See `handleRequest`.
|
|
1030
|
+
*/
|
|
1031
|
+
build?: string;
|
|
1032
|
+
/**
|
|
1033
|
+
* The address of the client as the server saw it, such as the remote
|
|
1034
|
+
* address of the socket, for `clientAddress` and rate limits.
|
|
1035
|
+
*/
|
|
1036
|
+
address?: string;
|
|
1037
|
+
/** True while the build prerenders the page. Rate limits do not count then. */
|
|
1038
|
+
prerender?: boolean;
|
|
1039
|
+
/**
|
|
1040
|
+
* Renders only the body of this `#defer` block, for the request that the
|
|
1041
|
+
* browser sends when the block's trigger fires. Pass the `base` of the
|
|
1042
|
+
* page too, so the IDs of the page come out the same. The body comes from
|
|
1043
|
+
* `pending`, and `html` and `state` are empty.
|
|
1044
|
+
*/
|
|
1045
|
+
defer?: {
|
|
1046
|
+
boundary: ScopeId;
|
|
1047
|
+
at: string;
|
|
1048
|
+
};
|
|
666
1049
|
}
|
|
667
1050
|
/**
|
|
668
1051
|
* Renders the parts of a page. It returns as soon as the markup is rendered.
|
|
@@ -672,6 +1055,13 @@ interface RenderOptions {
|
|
|
672
1055
|
* the stream starts.
|
|
673
1056
|
*/
|
|
674
1057
|
declare function render<P>(Root: Component<P>, props: P, options?: RenderOptions): Promise<RenderResult>;
|
|
1058
|
+
/**
|
|
1059
|
+
* Puts the bodies of boundaries in place of their fallbacks, with the bodies
|
|
1060
|
+
* inside them, as the swap script would in the browser. A `#defer` block
|
|
1061
|
+
* loses its `<template>` too, so the browser does not ask for a body that
|
|
1062
|
+
* is there. A boundary without a body keeps its fallback.
|
|
1063
|
+
*/
|
|
1064
|
+
declare function inlineBodies(html: string, bodies: Map<string, string>): string;
|
|
675
1065
|
interface DocumentOptions extends RenderOptions {
|
|
676
1066
|
/**
|
|
677
1067
|
* Markup before the component, for a component that does not render
|
|
@@ -705,6 +1095,31 @@ interface RequestOptions {
|
|
|
705
1095
|
* allowed.
|
|
706
1096
|
*/
|
|
707
1097
|
origins?: string[];
|
|
1098
|
+
/**
|
|
1099
|
+
* The middleware of the entry, which runs for every request before
|
|
1100
|
+
* anything else: pages, endpoints, calls, form posts and `#defer` bodies.
|
|
1101
|
+
* The Vite plugin passes the default export of `src/middleware.ts`.
|
|
1102
|
+
*/
|
|
1103
|
+
middleware?: EntryMiddleware;
|
|
1104
|
+
/**
|
|
1105
|
+
* The middleware of each `'use server'` file, by the ID of each of its
|
|
1106
|
+
* functions. It runs before the function, after the middleware of the
|
|
1107
|
+
* entry. `virtual:brumate/server` passes them.
|
|
1108
|
+
*/
|
|
1109
|
+
fileMiddleware?: Record<string, EntryMiddleware>;
|
|
1110
|
+
/** Keeps work going after the response ends, for `event.waitUntil`. See `RenderOptions`. */
|
|
1111
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
1112
|
+
/**
|
|
1113
|
+
* The ID of the build, for skew protection. A call from a page of another
|
|
1114
|
+
* build to a function that is gone answers 409 with this ID in
|
|
1115
|
+
* `x-brumate-build`, and the browser loads the page again. A call to a
|
|
1116
|
+
* function that still exists runs. The Vite plugin sets it in builds.
|
|
1117
|
+
*/
|
|
1118
|
+
build?: string;
|
|
1119
|
+
/** The address of the client as the server saw it, for `clientAddress` and rate limits. */
|
|
1120
|
+
address?: string;
|
|
1121
|
+
/** True while the build prerenders the pages. Rate limits do not count then. */
|
|
1122
|
+
prerender?: boolean;
|
|
708
1123
|
}
|
|
709
1124
|
/**
|
|
710
1125
|
* True when a request comes from a page of another site. Server function
|
|
@@ -732,6 +1147,19 @@ interface RouteOptions extends DocumentOptions, RequestOptions {
|
|
|
732
1147
|
dev?: boolean;
|
|
733
1148
|
/** The server functions, by ID, for forms that post to a page. `virtual:brumate/routes` passes them. */
|
|
734
1149
|
functions?: Record<string, (...args: any[]) => unknown>;
|
|
1150
|
+
/**
|
|
1151
|
+
* The URLs of the modules that every page loads early: the loader, and the
|
|
1152
|
+
* core that the first event loads. A page gets them as `Link` headers and
|
|
1153
|
+
* as `<link rel="modulepreload">` in its head. `virtual:brumate/routes`
|
|
1154
|
+
* passes them from the client build.
|
|
1155
|
+
*/
|
|
1156
|
+
hints?: string[];
|
|
1157
|
+
/**
|
|
1158
|
+
* Receives the `Link` values of `hints` before the page renders, so a
|
|
1159
|
+
* server can send them as `103 Early Hints`, such as with Node's
|
|
1160
|
+
* `response.writeEarlyHints({ link })`.
|
|
1161
|
+
*/
|
|
1162
|
+
earlyHints?: (links: string[]) => void;
|
|
735
1163
|
}
|
|
736
1164
|
/**
|
|
737
1165
|
* Answers a request with the route that matches its path, streamed:
|
|
@@ -748,6 +1176,16 @@ interface RouteOptions extends DocumentOptions, RequestOptions {
|
|
|
748
1176
|
* middleware. A `redirect` while the page renders answers with a redirect.
|
|
749
1177
|
*/
|
|
750
1178
|
declare function handleRoute(tree: RouteNode, request: Request, options?: RouteOptions): Promise<Response | undefined>;
|
|
1179
|
+
/**
|
|
1180
|
+
* Renders an object of attributes. A handler in it, such as an `onClick`
|
|
1181
|
+
* that a component passes on with `...rest`, goes into `on` as a `b-on`
|
|
1182
|
+
* entry: the client function that it refers to, with the scope that the
|
|
1183
|
+
* function belongs to and the modifiers of its wrappers. A function that
|
|
1184
|
+
* refers to nothing in the browser is left out.
|
|
1185
|
+
*/
|
|
1186
|
+
declare function spread(attributes: Record<string, unknown>, on?: string[]): string;
|
|
1187
|
+
/** The `b-on` attribute of an element with spreads: its own handlers, then those of its spreads. */
|
|
1188
|
+
declare function onAttribute(on: string[], own: string): string;
|
|
751
1189
|
//#endregion
|
|
752
|
-
export {
|
|
753
|
-
//# sourceMappingURL=server-
|
|
1190
|
+
export { rateLimit as $, onAttribute as A, CookieOptions as At, streamParts as B, handleRequest as C, ServerError as Ct, isCrossSite as D, isRedirect as Dt, insert as E, getEvent as Et, renderToStream as F, serializeCookie as Ft, RateLimitConfig as G, wait as H, settled as I, toNodeHeaders as It, RateLimitOptions as J, RateLimitError as K, spread as L, read as M, SessionOptions as Mt, ready as N, createSession as Nt, lazy as O, redirect as Ot, render as P, parseCookies as Pt, configureRateLimit as Q, stateScript as R, dynamic as S, RequestKind as St, inlineBodies as T, defineMiddleware as Tt, waitAll as U, streamState as V, RateLimit as W, Window as X, RateLimitStore as Y, clientAddress as Z, StreamOptions as _, Locals as _t, ItemSource as a, parseForm as at, children as b, RequestEvent as bt, Memo as c, Handler as ct, RenderResult as d, MiddlewareLoader as dt, ParseResult as et, RequestOptions as f, RouteMatch as ft, StateMap as g, EntryMiddleware as gt, StateAttributes as h, matchRoute as ht, DocumentOptions as i, parse as it, packState as j, Session as jt, memo as k, withEvent as kt, NotReady as l, Loader as lt, ScopeEntry as m, RouteView as mt, Context as n, ValidationIssue as nt, Lazy as o, safeParse as ot, RouteOptions as p, RouteNode as pt, RateLimitMiddleware as q, DeferTarget as r, fieldErrors as rt, Mark as s, EndpointLoader as st, Component as t, ValidationError as tt, RenderOptions as u, Middleware as ut, action as v, Redirect as vt, handleRoute as w, dedupe as wt, component as x, RequestEventOptions as xt, actionResult as y, RequestCall as yt, stateValue as z };
|
|
1191
|
+
//# sourceMappingURL=server-BA9SJ2Vm.d.ts.map
|