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
@@ -1,753 +0,0 @@
1
- import { t as Raw } from "./html-Du8jY2Cc.js";
2
- import { a as PageState, i as PackedState, n as ElementReference } from "./produce-CtZ32UGG.js";
3
- import { t as Context$1 } from "./context-aeo9esY9.js";
4
- //#region src/runtime/cookies.d.ts
5
- interface CookieOptions {
6
- /** Seconds until the cookie expires. Without it, the cookie lasts until the browser closes. */
7
- maxAge?: number;
8
- expires?: Date;
9
- /** Defaults to `/`. */
10
- path?: string;
11
- domain?: string;
12
- /** Defaults to true when the request is HTTPS. */
13
- secure?: boolean;
14
- /** Keeps the cookie from browser code. Defaults to true. */
15
- httpOnly?: boolean;
16
- /** Defaults to `lax`. */
17
- sameSite?: "strict" | "lax" | "none";
18
- }
19
- /** Reads the cookies of a `cookie` header. */
20
- declare function parseCookies(header: string | null): Record<string, string>;
21
- /** Writes a `set-cookie` header value. */
22
- declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
23
- interface SessionOptions {
24
- /**
25
- * Signs the cookie, so a browser cannot change it. Use a random string of
26
- * at least 32 characters, kept out of the code, such as in an environment
27
- * variable. A list signs with the first and accepts all, for changing it.
28
- */
29
- secret: string | string[];
30
- /** The name of the cookie. Defaults to `session`. */
31
- name?: string;
32
- /** Seconds until the session expires. Defaults to 7 days. */
33
- maxAge?: number;
34
- /** Other options of the cookie. */
35
- cookie?: Omit<CookieOptions, "maxAge" | "expires">;
36
- }
37
- interface Session<T> {
38
- /** The data of the session, or undefined when there is none, it expired, or its signature does not match. */
39
- get(event: RequestEvent): Promise<T | undefined>;
40
- /** Replaces the data of the session, and starts its time again. */
41
- set(event: RequestEvent, data: T): Promise<void>;
42
- /** Changes some fields of the data, and returns the new data. */
43
- update(event: RequestEvent, change: Partial<T>): Promise<T>;
44
- /** Ends the session. */
45
- clear(event: RequestEvent): void;
46
- }
47
- /**
48
- * A session in a signed cookie. The browser can read the data, but cannot
49
- * change it, so keep secrets out of it: store an ID, and look the rest up
50
- * on the server.
51
- *
52
- * ```ts
53
- * export const session = createSession<{ userId: string }>({ secret: process.env.SESSION_SECRET! });
54
- *
55
- * async function login(form: FormData) {
56
- * 'use server';
57
- * const event = getEvent();
58
- * await session.set(event, { userId: await checkPassword(form) });
59
- * }
60
- * ```
61
- */
62
- declare function createSession<T>(options: SessionOptions): Session<T>;
63
- /**
64
- * The headers of a response for Node's `writeHead`, with each `set-cookie`
65
- * apart. `Object.fromEntries(headers)` joins them into one, which browsers
66
- * read as a single cookie.
67
- */
68
- declare function toNodeHeaders(headers: Headers): Record<string, string | string[]>;
69
- //#endregion
70
- //#region src/runtime/request.d.ts
71
- /**
72
- * A request that the server handles: a server function call, a form post,
73
- * a page render, or a call of middleware or an endpoint. Its methods read
74
- * the request and change the response. Get it with `getEvent()`.
75
- */
76
- declare class RequestEvent {
77
- readonly request: Request;
78
- /** Headers to add to the response, such as `cache-control`. */
79
- readonly headers: Headers;
80
- /** The status that `setStatus` set. */
81
- status?: number;
82
- /** Server functions that `refresh` named, whose memos the client loads again. */
83
- refreshed?: Set<unknown>;
84
- /** Cookies that this request set, or deleted with undefined, so later reads see them. */
85
- cookies?: Map<string, string | undefined>;
86
- constructor(request: Request);
87
- /**
88
- * Sets the status of the page response, such as 404 for a page that shows
89
- * that nothing was found. It works while the first render of a page runs.
90
- * Markup that streams later, such as a `#loading` body, cannot change it,
91
- * because the response has started by then.
92
- */
93
- setStatus(status: number): void;
94
- /**
95
- * Asks the client to load again the memos that call a server function, such
96
- * as a list after a server function adds to it. The compiler gives those
97
- * memos client code, so they can load.
98
- */
99
- refresh(fn: (...args: never[]) => unknown): void;
100
- /** The cookies of the request, with the ones that this request set or deleted. */
101
- getCookies(): Record<string, string>;
102
- /** A cookie of the request, or the value that this request set. */
103
- getCookie(name: string): string | undefined;
104
- /**
105
- * Sets a cookie on the response. It is `HttpOnly`, `SameSite=Lax` and on
106
- * the path `/` unless the options say otherwise, and `Secure` on HTTPS.
107
- * Markup that streams later, such as a `#loading` body, cannot set cookies,
108
- * because the response has started.
109
- */
110
- setCookie(name: string, value: string, options?: CookieOptions): void;
111
- /** Deletes a cookie. Pass the `path` and `domain` that it was set with, if they were not the defaults. */
112
- deleteCookie(name: string, options?: Pick<CookieOptions, "path" | "domain">): void;
113
- }
114
- /**
115
- * Runs a callback with an event, so `getEvent()` in its code before its first
116
- * `await` returns it. Returns what the callback returns, such as its promise.
117
- * `calls`, while a page renders, lets calls with the same arguments share a result.
118
- */
119
- declare function withEvent<T>(event: RequestEvent | undefined, callback: () => T, calls?: Map<string, unknown>): T;
120
- /**
121
- * Returns the event of the request that the server handles: in a server
122
- * function, middleware or an endpoint, or while a component renders.
123
- *
124
- * Call it before the first `await` of the function, and keep it in a
125
- * variable. After an `await`, other requests may have run, so it throws.
126
- *
127
- * ```ts
128
- * async function save(todo: Todo) {
129
- * 'use server';
130
- * const event = getEvent();
131
- * await db.save(todo);
132
- * event.setCookie('saved', todo.id);
133
- * }
134
- * ```
135
- */
136
- declare function getEvent(): RequestEvent;
137
- /**
138
- * Wraps a server function, so its calls while a page renders share a result
139
- * when their arguments are the same. Calls from the browser, which are
140
- * requests of their own, always run, so a function that changes something
141
- * runs each time.
142
- */
143
- declare function dedupe<F extends (...args: any[]) => unknown>(fn: F, id: string): F;
144
- /**
145
- * An error whose message reaches the client. A server function call that
146
- * throws it rejects with the message, and the response has its status.
147
- * Other errors reach the client as a generic message, so server details stay
148
- * on the server.
149
- */
150
- declare class ServerError extends Error {
151
- readonly status: number;
152
- constructor(message: string, options?: {
153
- status?: number;
154
- });
155
- }
156
- /** Thrown by `redirect`. */
157
- declare class Redirect extends Error {
158
- readonly location: string;
159
- readonly status: number;
160
- constructor(location: string, status: number);
161
- }
162
- /**
163
- * Stops a server function and sends the browser to another page. While a
164
- * page renders, the error reaches the caller of `render`, which can
165
- * answer with a redirect.
166
- */
167
- declare function redirect(location: string, status?: number): never;
168
- declare function isRedirect(error: unknown): error is Redirect;
169
- //#endregion
170
- //#region src/runtime/router.d.ts
171
- /** Imports the module of a route file. */
172
- type Loader = () => Promise<{
173
- default: Component;
174
- }>;
175
- /** Answers a request at the path of an endpoint, for one method. */
176
- type Handler = (request: Request, params: Record<string, string>) => Response | Promise<Response>;
177
- /**
178
- * Runs before the routes of a folder. It answers the request itself, or
179
- * calls `next` for the answer of the route and returns it, changed or not.
180
- */
181
- type Middleware = (request: Request, next: () => Promise<Response>) => Response | Promise<Response>;
182
- /** Imports `_middleware.ts`. */
183
- type MiddlewareLoader = () => Promise<{
184
- middleware: Middleware;
185
- }>;
186
- /** Imports an endpoint: a module that exports a handler for each method, such as `GET`. */
187
- type EndpointLoader = () => Promise<Partial<Record<string, Handler>>>;
188
- /** A folder of routes, as `virtual:brumate/routes` describes it. */
189
- interface RouteNode {
190
- /** `_layout.brm`. */
191
- layout?: Loader;
192
- /** `index.brm`, or the file of a segment, such as `about.brm`. */
193
- page?: Loader;
194
- /** `_default.brm`: what a slot renders when its routes do not match. */
195
- fallback?: Loader;
196
- /** `_error.brm`: renders when a route of the folder throws, or when no route matches. */
197
- error?: Loader;
198
- /** `_loading.brm`: shows while a route of the folder streams in. */
199
- loading?: Loader;
200
- /** `_middleware.ts`: runs before the routes of the folder. */
201
- middleware?: MiddlewareLoader;
202
- /** A `.ts` file at this path, such as `api/todos.ts`. */
203
- endpoint?: EndpointLoader;
204
- /** Folders and files with a fixed segment. */
205
- static?: Record<string, RouteNode>;
206
- /** `[name]`: one segment, read as `params.name`. */
207
- dynamic?: {
208
- name: string;
209
- node: RouteNode;
210
- };
211
- /** `[...name]`: the rest of the path, read as `params.name`. */
212
- rest?: {
213
- name: string;
214
- node: RouteNode;
215
- };
216
- /** `@name` folders: routes that render in the `name` slot of the layout. */
217
- slots?: Record<string, RouteNode>;
218
- }
219
- /** A matched route: the component to render, and what renders in its slots. */
220
- interface RouteView {
221
- load: Loader;
222
- /**
223
- * The file and the params that the view depends on, such as
224
- * `/todos/[id]/_layout {"id":"3"}`. Two pages with the same key for a
225
- * layout render the same layout, so the client can keep it.
226
- */
227
- key: string;
228
- /** `children` and the named slots of a layout. */
229
- slots: Record<string, RouteView>;
230
- /** `_loading.brm` of the folder: the view streams in, and this shows until then. */
231
- loading?: Loader;
232
- }
233
- interface RouteMatch {
234
- view: RouteView;
235
- params: Record<string, string>;
236
- /** The endpoint at the path, if the folder has one. */
237
- endpoint?: EndpointLoader;
238
- /** The middleware of the folders on the path, from the outside in. */
239
- middleware: MiddlewareLoader[];
240
- /**
241
- * Views that show an error in place of the route, from the innermost
242
- * `_error.brm` to the outermost. Each renders inside the layouts above it.
243
- */
244
- errors: RouteView[];
245
- }
246
- /** Finds the route for a path. A path with a malformed escape, such as `/%E0`, matches none. */
247
- declare function matchRoute(tree: RouteNode, pathname: string): RouteMatch | undefined;
248
- //#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
- //#region src/runtime/validate.d.ts
311
- /**
312
- * A problem that a schema found, as plain data that the server can send to
313
- * the browser. A path segment is a string or a number.
314
- */
315
- interface ValidationIssue {
316
- message: string;
317
- path?: (string | number)[];
318
- }
319
- /** The output of a schema, or the issues that it found. */
320
- type ParseResult<T> = {
321
- value: T;
322
- issues?: undefined;
323
- } | {
324
- value?: undefined;
325
- issues: ValidationIssue[];
326
- };
327
- /**
328
- * The error that `parse` throws when the value does not match. It answers
329
- * with status 400 and its message, as any `ServerError` does. Its `issues`
330
- * stay on the server.
331
- */
332
- declare class ValidationError extends ServerError {
333
- readonly issues: ValidationIssue[];
334
- constructor(issues: ValidationIssue[]);
335
- }
336
- /**
337
- * Validates a value with a Standard Schema. Returns `{ value }` with the
338
- * output of the schema, or `{ issues }` as plain data. It does not throw for
339
- * a value that does not match.
340
- */
341
- declare function safeParse<S extends StandardSchemaV1>(schema: S, value: unknown): Promise<ParseResult<StandardSchemaV1.InferOutput<S>>>;
342
- /**
343
- * Validates a value with a Standard Schema, and returns the output of the
344
- * schema. A value that does not match throws a `ValidationError`, which
345
- * answers with status 400 and a message built from the first issue.
346
- *
347
- * ```ts
348
- * async function save(input: unknown) {
349
- * 'use server';
350
- * const todo = await parse(Todo, input);
351
- * await db.todos.save(todo);
352
- * }
353
- * ```
354
- */
355
- declare function parse<S extends StandardSchemaV1>(schema: S, value: unknown): Promise<StandardSchemaV1.InferOutput<S>>;
356
- /**
357
- * Validates the data of a form with a Standard Schema. The entries become a
358
- * plain object first. Returns `{ value }` or `{ issues }`, and does not throw
359
- * for data that does not match, so a function of `$action` can return the
360
- * issues for the page to show.
361
- *
362
- * ```ts
363
- * async function signUp(form: FormData) {
364
- * 'use server';
365
- * const result = await parseForm(SignUp, form);
366
- * if (result.issues) {
367
- * return { errors: fieldErrors(result.issues) };
368
- * }
369
- * }
370
- * ```
371
- */
372
- declare function parseForm<S extends StandardSchemaV1>(schema: S, form: FormData): Promise<ParseResult<StandardSchemaV1.InferOutput<S>>>;
373
- /**
374
- * The messages of issues by field, for a page to show next to each field.
375
- * The key is the path joined with dots, such as `address.city`. Issues
376
- * without a path, and a path of `__proto__`, are under the key `''`. The
377
- * result is plain data, so a server function can return it.
378
- */
379
- declare function fieldErrors(issues: readonly (StandardSchemaV1.Issue | ValidationIssue)[]): Record<string, string[]>;
380
- //#endregion
381
- //#region src/runtime/server.d.ts
382
- /** The scope and the slot that hold the list of a list item. */
383
- type ItemSource = readonly [scope: number, slot: number];
384
- /** A `#loading` body that renders after the rest of the page. */
385
- interface Boundary {
386
- id: number;
387
- /** Resolves to the body's markup, and its scopes in `ctx.state`. */
388
- render: Promise<{
389
- html: string;
390
- ctx: Context;
391
- }>;
392
- /** True when a `#try` body around it failed, so its markers were never sent. */
393
- cancelled?: boolean;
394
- }
395
- /** A point in a render that `restore` goes back to. */
396
- interface Mark {
397
- scope: number;
398
- undo: number;
399
- owner: number | undefined;
400
- }
401
- /**
402
- * Tracks the scopes of one render. A `#loading` body renders in a child
403
- * context, so its scopes are written with its markup.
404
- */
405
- declare class Context {
406
- readonly state: PageState;
407
- private readonly root;
408
- private nextScope;
409
- private nextBoundary;
410
- private readonly boundaries;
411
- private readonly styles;
412
- /** Markup of `#portal` blocks, written at the end of the page. */
413
- readonly portals: string[];
414
- /** Markup of `#head` blocks. */
415
- private readonly heads;
416
- private pageTitle;
417
- private onBoundary;
418
- /** The scope tree of the whole page, for finding contexts across `#loading` bodies. */
419
- private readonly tree;
420
- /** The scope that renders the next component, which becomes its owner. */
421
- private owner;
422
- /** Takes back what this context added to the page, from the newest, for `restore`. */
423
- private readonly undo;
424
- /** The URL prefix of server function calls. */
425
- private rpcPrefix;
426
- /** The names of the slots of each scope, so an error can name a value that cannot be sent. */
427
- readonly slotNames: Map<number, string[]>;
428
- /** Results of server functions that a form posted to this page, for `$action`. */
429
- actions: Map<unknown, unknown>;
430
- /** The request of the page, when it renders with one. */
431
- event: RequestEvent | undefined;
432
- /** Results of server function calls in this render, so the same call runs once. */
433
- readonly calls: Map<string, unknown>;
434
- /** The event of the page, for `getEvent()` in a component, which the compiler rewrites to this. */
435
- getEvent(): RequestEvent;
436
- /** Runs code of the render with its event and its call results, such as a memo's compute. */
437
- run<T>(callback: () => T): T;
438
- /** The result of a server function that a form posted to this page. */
439
- actionResult(fn: unknown): unknown;
440
- constructor(root?: Context, rpc?: string, base?: number);
441
- /** A number above every scope and boundary ID so far, so a later render can start there. */
442
- next(): number;
443
- /** Returns the URL prefix of server function calls. */
444
- rpc(): string;
445
- /**
446
- * Returns a new scope ID. `kind` is the scope's ID in the compiled
447
- * component, `parent` is the scope that contains it, and `module` is the
448
- * component ID of a component's root scope.
449
- */
450
- scope(kind: number, parent?: number, module?: string): number;
451
- /** The ID that `$id()` makes: the scope's ID and the position of the call. */
452
- id(scope: number, index: number): string;
453
- /** Sets the owner of the next component's root scope. */
454
- own(scope: number): void;
455
- /** Provides a value of a context to the scopes inside `scope`. */
456
- provide<T>(context: Context$1<T>, value: T, scope: number): void;
457
- /**
458
- * Reads a context from the nearest scope that provides it, starting at
459
- * `scope`. With `slot`, records which slot holds it, so the client can
460
- * update it when the provided value changes.
461
- */
462
- consume<T>(context: Context$1<T>, scope: number, slot?: number): T;
463
- /** The ID that the next call to `scope()` returns. */
464
- peek(): number;
465
- /** Marks the render so far, such as before a `#try` body, for `restore`. */
466
- mark(): Mark;
467
- /**
468
- * Takes back what the render added to the page since `mark`, such as a
469
- * `#try` body that threw, whose markup is not sent: its scopes, the
470
- * stylesheets it counted as sent, its `#portal` and `#head` markup, its
471
- * title, its `#loading` bodies, and its links to child components.
472
- */
473
- restore(mark: Mark): void;
474
- /**
475
- * Forgets the scopes of this render from `from` on, such as those of a
476
- * `#try` body that threw, so the client does not resume markup that was
477
- * never sent. `#loading` bodies render in contexts of their own, so their
478
- * scopes stay.
479
- */
480
- private drop;
481
- private record;
482
- slots(scope: number, values: unknown[], names?: string[]): void;
483
- /**
484
- * The list of each list item scope whose list is a slot of an enclosing
485
- * scope, as `[scope, slot]`. The items of a list share one array.
486
- */
487
- readonly sources: Map<number, ItemSource>;
488
- /**
489
- * Records the item of a list that can change on the client. `source` is
490
- * the scope and slot that hold the list, when the compiler found one, so
491
- * the client can take the item from there.
492
- */
493
- item(scope: number, value: unknown, source?: ItemSource): void;
494
- /** Records the scope of a child component at an anchor of its parent. */
495
- link(scope: number, anchor: number, child: number): void;
496
- /** Returns the reference that a `ref` signal holds on the server. */
497
- element(scope: number, anchor: number): ElementReference;
498
- /** Marks a function as a client function, so it serializes as a reference. */
499
- fn<T>(value: T, ref: string, scope: number): T;
500
- /** Returns a component's stylesheet the first time the page renders the component. */
501
- style(id: string, css: string): string;
502
- /** Adds the markup of a `#head` block. */
503
- head(html: string): void;
504
- /** Sets the title of the page. The last call wins. */
505
- title(value: unknown): void;
506
- /** True once the first render is done, and its head is about to be sent. */
507
- private sent;
508
- /** Marks the first render as done. Head markup after it streams with its `#loading` body. */
509
- send(): void;
510
- /**
511
- * The head markup and the title that a `#loading` body set, after the
512
- * head was sent. The title is undefined if the body set none.
513
- */
514
- lateHead(): {
515
- html: string;
516
- title: string | undefined;
517
- };
518
- /** The markup for the document's head: the title and the `#head` blocks. */
519
- headHTML(): string;
520
- /** Adds the markup of a `#portal` block, which goes after the rest of the page. */
521
- portal(html: string): void;
522
- /** Returns the ID of a new `#loading` boundary. */
523
- boundary(): number;
524
- /** Renders a `#loading` body after the rest of the page, in its own context. */
525
- defer(id: number, renderBody: (ctx: Context) => Promise<string>): void;
526
- /** Receives every boundary, including those registered before this call. */
527
- watch(onBoundary: (boundary: Boundary) => void): void;
528
- }
529
- /** Thrown when code reads a memo whose value is still loading. It carries the load. */
530
- declare class NotReady extends Error {
531
- readonly source: Promise<unknown>;
532
- constructor(source: Promise<unknown>);
533
- }
534
- /** A memo on the server. It computes on its first read, so nothing waits for a memo that nothing reads. */
535
- interface Memo<T = unknown> {
536
- compute: () => T;
537
- /** The render, whose event server functions that the compute calls read. */
538
- ctx?: Context;
539
- state: "idle" | "pending" | "done" | "failed";
540
- value?: unknown;
541
- error?: unknown;
542
- load?: Promise<unknown>;
543
- }
544
- /** Declares a memo. Its value is computed when it is first read. */
545
- declare function memo<T>(compute: () => T, ctx?: Context): Memo<T>;
546
- /**
547
- * Reads a memo. A value that is still loading throws `NotReady` with its
548
- * load, and a memo that read such a value stays unread, so it computes
549
- * again when it is read after the load settles.
550
- */
551
- declare function read(node: Memo): any;
552
- /** Waits for the value of a memo, through every load it reads. */
553
- declare function wait(node: Memo): Promise<unknown>;
554
- /**
555
- * The value of a memo when it is ready, or a promise of it while it loads.
556
- * The render then awaits only a memo that is loading.
557
- */
558
- declare function ready(node: Memo): unknown;
559
- declare const LAZY: unique symbol;
560
- /** Markup that renders where it is inserted, so it can read the contexts there. */
561
- interface Lazy {
562
- [LAZY]: (ctx: Context, scope: number | undefined) => Promise<string>;
563
- }
564
- /** Makes markup that renders where it is inserted, such as the children of a layout. */
565
- declare function lazy(renderAt: (ctx: Context, scope: number | undefined) => Promise<string>): Lazy;
566
- /** Renders the attributes of a form or button that posts to a server function. */
567
- declare function action(ctx: Context, name: string, id: string, method?: string, result?: string): string;
568
- /**
569
- * The result of a server function that a form posted to this page, for
570
- * `$action`, or undefined when the page was not rendered for a post.
571
- */
572
- declare function actionResult(ctx: Context, fn: unknown): unknown;
573
- /**
574
- * Renders a value inserted in markup. `ctx` and `scope` are where it is
575
- * inserted, for markup that renders there.
576
- */
577
- declare function insert(value: unknown, ctx?: Context, scope?: number): string | Promise<string>;
578
- type Component<P = any> = (props: P, ctx: Context) => Promise<string>;
579
- /**
580
- * Renders a child component. With `scope` and `anchor`, records the child's
581
- * scope so the parent can update its props on the client.
582
- */
583
- declare function component<P>(Child: Component<P>, props: P, ctx: Context, scope?: number, anchor?: number): Promise<string>;
584
- /** Renders a dynamic tag, which can be an element name or a component. */
585
- declare function dynamic(tag: string | Component, attributes: Record<string, unknown>, children: Raw | undefined, ctx: Context, scope?: number): string | Promise<string>;
586
- /**
587
- * Writes the records of scopes with the same kind, parent and shape, such as
588
- * the items of a list, in groups. Each one then costs its slots and the gap
589
- * to the ID before it. The items of a list whose list is in `sources` and in
590
- * the state are not written. See `PackedState`.
591
- */
592
- declare function packState(state: PageState, sources?: Map<number, ItemSource>): PackedState;
593
- /**
594
- * Serializes the page state as the code of state records. `onRecord`
595
- * receives each record as soon as it is ready. The promise resolves when
596
- * every promise in the state has settled.
597
- */
598
- declare function streamState(state: PageState, onRecord: (code: string, initial: boolean) => void): Promise<void>;
599
- interface StateAttributes {
600
- /** A number above every ID so far, on each record with scopes. */
601
- next?: number;
602
- /** The first record of a render defines `$bR`. Later ones call it. */
603
- define?: boolean;
604
- /** The route of the page. */
605
- route?: string;
606
- /** The base of the render, when it is above 0. */
607
- root?: number;
608
- /** The Content Security Policy nonce of the script. */
609
- nonce?: string;
610
- }
611
- /**
612
- * Returns the script of a state record. `scopes` marks a record with scopes,
613
- * as opposed to one that settles a promise. The record is code that seroval
614
- * wrote, as a function of the references of its render, `$R`, and of the
615
- * functions that make brumate's values, `$b`. seroval escapes every `<` in
616
- * the strings in it.
617
- */
618
- declare function stateScript(code: string, scopes?: boolean, attributes?: StateAttributes): string;
619
- interface RenderResult {
620
- /** The markup. A `#loading` body that is not ready shows its fallback. */
621
- html: string;
622
- /** The script that holds the page state. */
623
- state: string;
624
- /**
625
- * Markup to write after the page, as it is ready: the bodies of
626
- * `#loading` blocks, and the state records that settle promises.
627
- */
628
- pending: AsyncIterable<string>;
629
- /** Headers that the page set while it rendered, such as cookies. */
630
- headers: Headers;
631
- /** The status that `setStatus` set while the page rendered, or 200. */
632
- status: number;
633
- /**
634
- * A number above every ID of this render, once its `#loading` bodies have
635
- * rendered. Another root on the same page passes it as `base`.
636
- */
637
- next: () => number;
638
- /** Markup for the document's head: the `$title` and the `#head` blocks. */
639
- head: string;
640
- }
641
- interface RenderOptions {
642
- /** The URL prefix of server function calls, for forms that post to one. Defaults to `/_brumate`. */
643
- rpc?: string;
644
- /**
645
- * The first scope and boundary ID. A page that the client loads in place
646
- * of another starts above the IDs of the page it keeps parts of.
647
- */
648
- base?: number;
649
- /** Names the route of the page, so the client knows which layouts it can keep. */
650
- route?: string;
651
- /** Results of server functions that a form posted to this page, by function, for `$action`. */
652
- actions?: Map<unknown, unknown>;
653
- /**
654
- * The request of the page. Components and the server functions that their
655
- * memos call read it with `getEvent()`. Headers and cookies that they set
656
- * are in the `headers` that `render` returns.
657
- */
658
- request?: Request;
659
- /** The event of the request, in place of `request`, such as one that middleware already set cookies on. */
660
- event?: RequestEvent;
661
- /**
662
- * A Content Security Policy nonce for the inline scripts: the state
663
- * records, and the scripts that swap in `#loading` bodies.
664
- */
665
- nonce?: string;
666
- }
667
- /**
668
- * Renders the parts of a page. It returns as soon as the markup is rendered.
669
- * `#loading` bodies and promises in the state do not hold it up: they come
670
- * later, from `pending`. `renderToStream` puts the parts together. Use this
671
- * directly to send the response headers that server functions set before
672
- * the stream starts.
673
- */
674
- declare function render<P>(Root: Component<P>, props: P, options?: RenderOptions): Promise<RenderResult>;
675
- interface DocumentOptions extends RenderOptions {
676
- /**
677
- * Markup before the component, for a component that does not render
678
- * `<html>`. A function receives the markup for the document's head.
679
- */
680
- start?: string | ((head: string) => string);
681
- /** Markup for the head, before the head of the components, such as the `<link>` of a CSS file. */
682
- head?: string;
683
- /**
684
- * Markup right after the page state, such as the client entry. Make
685
- * module scripts `async`, so they run before the stream ends.
686
- */
687
- scripts?: string;
688
- /** Markup after the first render, for a component that does not render `<html>`. */
689
- end?: string;
690
- }
691
- type StreamOptions = DocumentOptions;
692
- /**
693
- * Renders a component as a stream. The first chunk is the whole first
694
- * render, sent as soon as it is ready. Each `#loading` body and each state
695
- * record that settles a promise follows it as it resolves. A component that
696
- * renders `<html>` gets the doctype and its head.
697
- */
698
- declare function renderToStream<P>(Root: Component<P>, props: P, options?: DocumentOptions): ReadableStream<string>;
699
- /** Streams the parts of a page from `render`: the first render whole, then what resolves later. */
700
- declare function streamParts(parts: RenderResult, options?: DocumentOptions): ReadableStream<string>;
701
- interface RequestOptions {
702
- /**
703
- * Other origins that may call server functions and post forms to them,
704
- * such as `https://app.example.com`. The origin of the request is always
705
- * allowed.
706
- */
707
- origins?: string[];
708
- }
709
- /**
710
- * True when a request comes from a page of another site. Server function
711
- * calls and form posts send the cookies of the user, so another site must
712
- * not be able to make them.
713
- *
714
- * The browser sends `Origin` with every call and post. Without it, an older
715
- * browser's `Sec-Fetch-Site` decides. A request with neither does not come
716
- * from a page in a browser, so it is allowed.
717
- */
718
- declare function isCrossSite(request: Request, options?: RequestOptions): boolean;
719
- /**
720
- * Answers a server function call from `brumate/client`. Returns undefined
721
- * when the request is not a call, so other handlers can answer it. Server
722
- * functions read the request with `getEvent()`. A call from a page of
723
- * another site answers 403. See `isCrossSite`.
724
- */
725
- declare function handleRequest(functions: Record<string, (...args: any[]) => unknown>, request: Request, prefix?: string, options?: RequestOptions): Promise<Response | undefined>;
726
- interface RouteOptions extends DocumentOptions, RequestOptions {
727
- /**
728
- * Throws errors that are not a `ServerError` instead of rendering
729
- * `_error.brm`, so a dev server can show them, such as with `errorPage`
730
- * from `brumate/vite`. The Vite plugin sets it in development.
731
- */
732
- dev?: boolean;
733
- /** The server functions, by ID, for forms that post to a page. `virtual:brumate/routes` passes them. */
734
- functions?: Record<string, (...args: any[]) => unknown>;
735
- }
736
- /**
737
- * Answers a request with the route that matches its path, streamed:
738
- *
739
- * - The `_middleware.ts` of each folder on the path runs first, from the outside in.
740
- * - An endpoint at the path answers the methods that it exports.
741
- * - A form without scripts that posts to the page with `?__action=<id>`
742
- * runs that server function first, and the page renders with its result
743
- * for `$action`.
744
- * - A route that throws renders the nearest `_error.brm`, and a path that
745
- * no route matches renders the `_error.brm` of the root with status 404.
746
- *
747
- * Returns undefined when no route matches and the root has no error file or
748
- * middleware. A `redirect` while the page renders answers with a redirect.
749
- */
750
- declare function handleRoute(tree: RouteNode, request: Request, options?: RouteOptions): Promise<Response | undefined>;
751
- //#endregion
752
- export { ServerError as $, stateScript as A, safeParse as B, lazy as C, ready as D, read as E, ValidationError as F, Middleware as G, EndpointLoader as H, ValidationIssue as I, RouteNode as J, MiddlewareLoader as K, fieldErrors as L, streamState as M, wait as N, render as O, ParseResult as P, RequestEvent as Q, parse as R, isCrossSite as S, packState as T, Handler as U, StandardSchemaV1 as V, Loader as W, matchRoute as X, RouteView as Y, Redirect as Z, component as _, Lazy as a, CookieOptions as at, handleRoute as b, NotReady as c, createSession as ct, RequestOptions as d, toNodeHeaders as dt, dedupe as et, RouteOptions as f, actionResult as g, action as h, ItemSource as i, withEvent as it, streamParts as j, renderToStream as k, RenderOptions as l, parseCookies as lt, StreamOptions as m, Context as n, isRedirect as nt, Mark as o, Session as ot, StateAttributes as p, RouteMatch as q, DocumentOptions as r, redirect as rt, Memo as s, SessionOptions as st, Component as t, getEvent as tt, RenderResult as u, serializeCookie as ut, dynamic as v, memo as w, insert as x, handleRequest as y, parseForm as z };
753
- //# sourceMappingURL=server-BxqjLUnV.d.ts.map