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.
- package/dist/{boot-DN1ZU8Hg.d.ts → boot-C25Sa6vq.d.ts} +27 -2
- package/dist/cli.js +2 -2
- package/dist/client-BD6XT-s5.js +1968 -0
- package/dist/client-BD6XT-s5.js.map +1 -0
- package/dist/{client-DwJInP_a.d.ts → client-D0CqSxoO.d.ts} +211 -30
- 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/{cookies-Av5WFmcf.js → cookies-BzllthiF.js} +2 -1
- package/dist/cookies-BzllthiF.js.map +1 -0
- package/dist/defer-BbD7JQhj.js +56 -0
- package/dist/defer-BbD7JQhj.js.map +1 -0
- package/dist/devtools-CQgD7NPB.js +623 -0
- package/dist/devtools-CQgD7NPB.js.map +1 -0
- package/dist/devtools-panel-BVB-W5q4.js +1930 -0
- package/dist/devtools-panel-BVB-W5q4.js.map +1 -0
- package/dist/events-CSs7OwIC.js +85 -0
- package/dist/events-CSs7OwIC.js.map +1 -0
- package/dist/{files-DdT84mPy.js → files-BXSSrQgc.js} +34 -6
- package/dist/files-BXSSrQgc.js.map +1 -0
- package/dist/forms-Bg-CwGqX.js +406 -0
- package/dist/forms-Bg-CwGqX.js.map +1 -0
- package/dist/forms-Cl21hkHt.d.ts +281 -0
- package/dist/highlight.d.ts +17 -0
- package/dist/highlight.js +269 -0
- package/dist/highlight.js.map +1 -0
- package/dist/html-Bq1rFxX_.d.ts +92 -0
- package/dist/html-mNTKzaDD.js +241 -0
- package/dist/html-mNTKzaDD.js.map +1 -0
- package/dist/index.d.ts +123 -30
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BPchdWbU.js → inspect-BHpOw1LF.js} +1400 -121
- package/dist/inspect-BHpOw1LF.js.map +1 -0
- package/dist/{loader-Dc9OwY5I.js → loader-Dos_3NP0.js} +47 -11
- package/dist/loader-Dos_3NP0.js.map +1 -0
- package/dist/{navigate-CzLjnoPH.js → navigate-O78d_zGN.js} +115 -13
- package/dist/navigate-O78d_zGN.js.map +1 -0
- package/dist/produce-D0V0ICkz.d.ts +114 -0
- package/dist/produce-Doc91GkX.js +274 -0
- package/dist/produce-Doc91GkX.js.map +1 -0
- package/dist/routes-BZNt7DSZ.d.ts +38 -0
- package/dist/{rpc-9fSqL_YK.js → rpc-ygMRPmN4.js} +39 -23
- package/dist/rpc-ygMRPmN4.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 +191 -5
- 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 +42 -0
- package/dist/runtime/events.js +1 -0
- package/dist/runtime/forms.d.ts +2 -0
- package/dist/runtime/forms.js +1 -0
- package/dist/runtime/gather.d.ts +25 -0
- package/dist/runtime/gather.js +33 -0
- package/dist/runtime/gather.js.map +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 +7 -5
- package/dist/runtime/server.js +6 -7
- package/dist/runtime/signals.d.ts +60 -3
- package/dist/runtime/signals.js +40 -2
- 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/runtime/values.d.ts +2 -0
- package/dist/runtime/values.js +24 -0
- package/dist/runtime/values.js.map +1 -0
- package/dist/secrets-BxagsJxJ.js +23 -0
- package/dist/secrets-BxagsJxJ.js.map +1 -0
- package/dist/server-CxVDYE_V.js +3417 -0
- package/dist/server-CxVDYE_V.js.map +1 -0
- package/dist/server-DuFYRXrd.d.ts +1460 -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-Drpr0AzI.d.ts} +2 -2
- package/dist/static-loader-nZssh66R.js +333 -0
- package/dist/static-loader-nZssh66R.js.map +1 -0
- package/dist/stream-DCYZO4IF.js +424 -0
- package/dist/stream-DCYZO4IF.js.map +1 -0
- package/dist/values-B8C7CLvG.d.ts +63 -0
- package/dist/vite.d.ts +49 -1
- package/dist/vite.js +598 -68
- package/dist/vite.js.map +1 -1
- package/forms/forms.brm.ts +141 -0
- package/package.json +45 -3
- 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/cookies-Av5WFmcf.js.map +0 -1
- package/dist/devtools-BKjnHrnv.js +0 -113
- package/dist/devtools-BKjnHrnv.js.map +0 -1
- package/dist/devtools-panel-AWOn0VK2.js +0 -434
- package/dist/devtools-panel-AWOn0VK2.js.map +0 -1
- package/dist/files-DdT84mPy.js.map +0 -1
- package/dist/html-DEeoepg3.js +0 -152
- package/dist/html-DEeoepg3.js.map +0 -1
- package/dist/html-Du8jY2Cc.d.ts +0 -53
- package/dist/inspect-BPchdWbU.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 +0 -126
- package/dist/produce-BRGHP7e0.js.map +0 -1
- package/dist/produce-CtZ32UGG.d.ts +0 -60
- package/dist/rpc-9fSqL_YK.js.map +0 -1
- package/dist/runtime/client.js.map +0 -1
- package/dist/server-BxqjLUnV.d.ts +0 -753
- 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 +0 -185
- package/dist/static-loader-ClNkHZGn.js.map +0 -1
- package/dist/stream-bgNCMcaA.js +0 -280
- package/dist/stream-bgNCMcaA.js.map +0 -1
package/dist/runtime/server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { A as
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export { Context, ElementReference, FunctionReference, NotReady, RequestEvent, ServerError, ValidationError, action, actionResult, affix, attribute, classAttribute, component, createContext, createSession, dedupe, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, insert, isCrossSite, isRedirect, lazy, matchRoute, memo, packState, parse, parseCookies, parseForm, produce, raw, read, ready, redirect, render, renderToStream, safeParse, serializeCookie, spread, stateScript, streamParts, streamState, toNodeHeaders, vars, wait, withEvent };
|
|
1
|
+
import { g as raw, h as onAttribute, i as attribute, l as escape, m as mergeAttributes, r as affix, s as classAttribute, u as escapeAttribute, x as vars } from "../html-mNTKzaDD.js";
|
|
2
|
+
import { a as serializeCookie, i as parseCookies, s as toNodeHeaders, t as createSession } from "../cookies-BzllthiF.js";
|
|
3
|
+
import { i as FunctionReference, m as useSerialEntry, p as unbind, r as ElementReference, t as produce } from "../produce-Doc91GkX.js";
|
|
4
|
+
import { $ as withEvent, A as RateLimitError, B as matchRoute, C as stateScript, D as wait, E as streamState, F as ValidationError, G as storageStore, H as memoryStore, I as fieldErrors, J as dedupe, K as RequestEvent, L as parse, M as configureRateLimit, N as rateLimit, O as waitAll, P as parseSubmission, Q as redirect, R as parseForm, S as spread, T as streamParts, U as revalidate, V as cached, W as setCacheStore, X as getEvent, Y as defineMiddleware, Z as isRedirect, _ as read, a as binding, b as renderToStream, c as dynamic, d as inlineBodies, f as insert, g as packState, h as memo, i as actionResult, j as clientAddress, k as idempotent, l as handleRequest, m as lazy, n as NotReady, o as children, p as isCrossSite, q as ServerError, r as action, s as component, t as Context, u as handleRoute, v as ready, w as stateValue, x as settled, y as render, z as safeParse } from "../server-CxVDYE_V.js";
|
|
5
|
+
import { a as routeContext, i as navigationContext, r as createContext } from "../context-CTiSzQRc.js";
|
|
6
|
+
export { Context, ElementReference, FunctionReference, NotReady, RateLimitError, RequestEvent, ServerError, ValidationError, action, actionResult, affix, attribute, binding, cached, children, classAttribute, clientAddress, component, configureRateLimit, createContext, createSession, dedupe, defineMiddleware, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, idempotent, inlineBodies, insert, isCrossSite, isRedirect, lazy, matchRoute, memo, memoryStore, mergeAttributes, navigationContext, onAttribute, packState, parse, parseCookies, parseForm, parseSubmission, produce, rateLimit, raw, read, ready, redirect, render, renderToStream, revalidate, routeContext, safeParse, serializeCookie, setCacheStore, settled, spread, stateScript, stateValue, storageStore, streamParts, streamState, toNodeHeaders, unbind, useSerialEntry, vars, wait, waitAll, withEvent };
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import { t as Context } from "../context-
|
|
1
|
+
import { a as Route, r as NavigationState, t as Context } from "../context-btHuB01Z.js";
|
|
2
|
+
import { n as RouteParams, r as RoutePath } from "../routes-BZNt7DSZ.js";
|
|
2
3
|
//#region src/runtime/signals.d.ts
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
declare const BINDABLE: unique symbol;
|
|
5
|
+
/** The mark of a prop that a parent can bind. It has no value at runtime. */
|
|
6
|
+
export interface BindableMark<T> {
|
|
7
|
+
readonly [BINDABLE]: T;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Marks a prop that a parent can bind with `$bind`, such as
|
|
11
|
+
* `open?: Bindable<boolean>`. The parent passes `T` or `$bind(name)`.
|
|
12
|
+
* Inside the component, `$props<T>()` gives `T`.
|
|
13
|
+
*/
|
|
14
|
+
export type Bindable<T> = T | BindableMark<T>;
|
|
15
|
+
/** The props as the component reads them, with `Bindable<T>` as `T`. */
|
|
16
|
+
export type Unbound<T> = { [K in keyof T]: Exclude<T[K], BindableMark<unknown>>; };
|
|
17
|
+
/**
|
|
18
|
+
* Returns the props of the component. Destructure the call to keep each prop
|
|
19
|
+
* reactive. Destructure it with `let` to write props, such as
|
|
20
|
+
* `let { open = false } = $props()`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function $props<T = Record<string, any>>(): Unbound<T>;
|
|
5
23
|
/** Declares writable state. The variable reads and writes the signal. */
|
|
6
24
|
export declare function $signal<T>(value: T): T;
|
|
7
25
|
export declare function $signal<T>(): T | undefined;
|
|
@@ -12,6 +30,18 @@ export type MemoValue<T> = Awaited<T> extends AsyncIterable<infer U> ? U : Await
|
|
|
12
30
|
* is read. An async iterable gives each of its values in turn.
|
|
13
31
|
*/
|
|
14
32
|
export declare function $memo<T>(_value: T): MemoValue<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Declares a memo that takes the value once it stops changing for `ms`
|
|
35
|
+
* milliseconds, such as a search query while the user types. On the server,
|
|
36
|
+
* and until the value first changes, it is the value.
|
|
37
|
+
*/
|
|
38
|
+
export declare function $debounced<T>(_value: T, _ms: number): MemoValue<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Declares a memo that takes the value at most once every `ms`
|
|
41
|
+
* milliseconds, and the last value after the wait, such as a position while
|
|
42
|
+
* the pointer moves. On the server, and until the value first changes, it is the value.
|
|
43
|
+
*/
|
|
44
|
+
export declare function $throttled<T>(_value: T, _ms: number): MemoValue<T>;
|
|
15
45
|
/**
|
|
16
46
|
* Declares a value that follows a memo, and that handlers can write. A write
|
|
17
47
|
* shows a guess, such as a new item while the form that adds it posts. The
|
|
@@ -33,6 +63,14 @@ export declare function $id(): string;
|
|
|
33
63
|
export declare function $setContext<T>(_context: Context<T>, _value: T): void;
|
|
34
64
|
/** Reads a context from the nearest component above that provides it, or its default value. */
|
|
35
65
|
export declare function $getContext<T>(_context: Context<T>): T;
|
|
66
|
+
/**
|
|
67
|
+
* The route of the page: its URL, its query string and its params, typed
|
|
68
|
+
* from the route files as `href` is. The server reads the request, and the
|
|
69
|
+
* browser reads `location`. It changes when navigation changes the URL.
|
|
70
|
+
*/
|
|
71
|
+
export declare function $route<P extends RoutePath = RoutePath>(_path?: P): Route<RouteParams<P>>;
|
|
72
|
+
/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */
|
|
73
|
+
export declare function $navigation(): NavigationState;
|
|
36
74
|
/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */
|
|
37
75
|
export declare function $produce<T>(_signal: T, _recipe: (draft: T) => T | void): void;
|
|
38
76
|
/** Sets the title of the page. The last component that sets it wins. */
|
|
@@ -42,5 +80,24 @@ export declare function $title(_value: unknown): void;
|
|
|
42
80
|
* to, or undefined before the first post. Pending while the form sends.
|
|
43
81
|
*/
|
|
44
82
|
export declare function $action<F extends (...args: never[]) => unknown>(_fn: F): Awaited<ReturnType<F>> | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Passes a child a signal, or a prop that the component writes, so a write
|
|
85
|
+
* of the prop in the child writes it. The child destructures the prop with
|
|
86
|
+
* `let`. Pass it as the value of a prop: `<Dialog open=$bind(open) />`.
|
|
87
|
+
*
|
|
88
|
+
* - Only a prop of type `Bindable<T>` takes it.
|
|
89
|
+
* - With `set`, a write calls `set(next)` in place of writing the signal.
|
|
90
|
+
*/
|
|
91
|
+
export declare function $bind<T>(signal: T, set?: (next: T) => unknown): BindableMark<T>;
|
|
92
|
+
/**
|
|
93
|
+
* Marks a function that a script makes as an event handler, so a spread can
|
|
94
|
+
* pass it on, as it passes on a handler that a caller writes in markup.
|
|
95
|
+
* `args` are JSON values that go with the handler, and it runs as
|
|
96
|
+
* `fn(...args, event)`.
|
|
97
|
+
*/
|
|
98
|
+
export declare function $handler<A extends unknown[], E = Event>(fn: (...args: [...A, E]) => unknown, ...args: A): (event: E) => unknown;
|
|
99
|
+
/** A function that does not read the event. */
|
|
100
|
+
export declare function $handler<A extends unknown[]>(fn: (...args: A) => unknown, ...args: A): (event: Event) => unknown;
|
|
45
101
|
//#endregion
|
|
102
|
+
export {};
|
|
46
103
|
//# sourceMappingURL=signals.d.ts.map
|
package/dist/runtime/signals.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
function compileTimeOnly(name) {
|
|
3
3
|
throw new Error(`${name} works only in .brm files, which the brumate compiler compiles`);
|
|
4
4
|
}
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Returns the props of the component. Destructure the call to keep each prop
|
|
7
|
+
* reactive. Destructure it with `let` to write props, such as
|
|
8
|
+
* `let { open = false } = $props()`.
|
|
9
|
+
*/
|
|
6
10
|
function $props() {
|
|
7
11
|
return compileTimeOnly("$props");
|
|
8
12
|
}
|
|
@@ -17,6 +21,22 @@ function $memo(_value) {
|
|
|
17
21
|
return compileTimeOnly("$memo");
|
|
18
22
|
}
|
|
19
23
|
/**
|
|
24
|
+
* Declares a memo that takes the value once it stops changing for `ms`
|
|
25
|
+
* milliseconds, such as a search query while the user types. On the server,
|
|
26
|
+
* and until the value first changes, it is the value.
|
|
27
|
+
*/
|
|
28
|
+
function $debounced(_value, _ms) {
|
|
29
|
+
return compileTimeOnly("$debounced");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Declares a memo that takes the value at most once every `ms`
|
|
33
|
+
* milliseconds, and the last value after the wait, such as a position while
|
|
34
|
+
* the pointer moves. On the server, and until the value first changes, it is the value.
|
|
35
|
+
*/
|
|
36
|
+
function $throttled(_value, _ms) {
|
|
37
|
+
return compileTimeOnly("$throttled");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
20
40
|
* Declares a value that follows a memo, and that handlers can write. A write
|
|
21
41
|
* shows a guess, such as a new item while the form that adds it posts. The
|
|
22
42
|
* value goes back to the memo when the memo changes, or when the server
|
|
@@ -53,6 +73,18 @@ function $setContext(_context, _value) {
|
|
|
53
73
|
function $getContext(_context) {
|
|
54
74
|
return compileTimeOnly("$getContext");
|
|
55
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The route of the page: its URL, its query string and its params, typed
|
|
78
|
+
* from the route files as `href` is. The server reads the request, and the
|
|
79
|
+
* browser reads `location`. It changes when navigation changes the URL.
|
|
80
|
+
*/
|
|
81
|
+
function $route(_path) {
|
|
82
|
+
return compileTimeOnly("$route");
|
|
83
|
+
}
|
|
84
|
+
/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */
|
|
85
|
+
function $navigation() {
|
|
86
|
+
return compileTimeOnly("$navigation");
|
|
87
|
+
}
|
|
56
88
|
/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */
|
|
57
89
|
function $produce(_signal, _recipe) {
|
|
58
90
|
compileTimeOnly("$produce");
|
|
@@ -68,7 +100,13 @@ function $title(_value) {
|
|
|
68
100
|
function $action(_fn) {
|
|
69
101
|
return compileTimeOnly("$action");
|
|
70
102
|
}
|
|
103
|
+
function $bind() {
|
|
104
|
+
return compileTimeOnly("$bind");
|
|
105
|
+
}
|
|
106
|
+
function $handler() {
|
|
107
|
+
return compileTimeOnly("$handler");
|
|
108
|
+
}
|
|
71
109
|
//#endregion
|
|
72
|
-
export { $action, $client, $effect, $getContext, $id, $isPending, $memo, $optimistic, $produce, $props, $setContext, $signal, $title, $untrack };
|
|
110
|
+
export { $action, $bind, $client, $debounced, $effect, $getContext, $handler, $id, $isPending, $memo, $navigation, $optimistic, $produce, $props, $route, $setContext, $signal, $throttled, $title, $untrack };
|
|
73
111
|
|
|
74
112
|
//# sourceMappingURL=signals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.js","names":[],"sources":["../../src/runtime/signals.ts"],"sourcesContent":["// The compile-time functions of `.brm` files. The compiler replaces every\n// call and removes the import, so this module only gives them their types.\n// A call outside a `.brm` file throws.\n\nimport type { Context } from './context.ts';\n\nfunction compileTimeOnly(name: string): never {\n throw new Error(`${name} works only in .brm files, which the brumate compiler compiles`);\n}\n\n/** Returns the props of the component. Destructure the call to keep each prop reactive. */\n// oxlint-disable-next-line typescript/no-explicit-any -- Props are any object unless typed.\nexport function $props<T = Record<string, any>>(): T {\n return compileTimeOnly('$props');\n}\n\n/** Declares writable state. The variable reads and writes the signal. */\nexport function $signal<T>(value: T): T;\nexport function $signal<T>(): T | undefined;\nexport function $signal(): never {\n return compileTimeOnly('$signal');\n}\n\n/** The value of a memo: what a promise settles to, or the latest value of an async iterable. */\nexport type MemoValue<T> = Awaited<T> extends AsyncIterable<infer U> ? U : Awaited<T>;\n\n/**\n * Declares a value computed from other values. A promise is awaited where it\n * is read. An async iterable gives each of its values in turn.\n */\nexport function $memo<T>(_value: T): MemoValue<T> {\n return compileTimeOnly('$memo');\n}\n\n/**\n * Declares a value that follows a memo, and that handlers can write. A write\n * shows a guess, such as a new item while the form that adds it posts. The\n * value goes back to the memo when the memo changes, or when the server\n * calls of the page finish, such as after a failed post.\n */\nexport function $optimistic<T>(_source: T): T {\n return compileTimeOnly('$optimistic');\n}\n\n/** Runs a callback when the values it reads change, after the page resumes. Never on load. */\nexport function $effect(_callback: () => void | (() => void)): void {\n compileTimeOnly('$effect');\n}\n\n/** Runs a callback in the browser when a trigger fires. */\nexport function $client(\n _callback: () => void | (() => void),\n _trigger?: 'visible' | 'idle' | 'load',\n): void {\n compileTimeOnly('$client');\n}\n\n/** Reads a value without depending on it. */\nexport function $untrack<T>(_value: T): T {\n return compileTimeOnly('$untrack');\n}\n\n/** True while a new value of a memo, or of a memo it reads, loads on the client. Always false on the server. */\nexport function $isPending(_memo: unknown): boolean {\n return compileTimeOnly('$isPending');\n}\n\n/** Returns an ID that is unique in the page and the same on the server and the client. */\nexport function $id(): string {\n return compileTimeOnly('$id');\n}\n\n/** Provides a value of a context to the components inside this one. */\nexport function $setContext<T>(_context: Context<T>, _value: T): void {\n compileTimeOnly('$setContext');\n}\n\n/** Reads a context from the nearest component above that provides it, or its default value. */\nexport function $getContext<T>(_context: Context<T>): T {\n return compileTimeOnly('$getContext');\n}\n\n/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */\nexport function $produce<T>(_signal: T, _recipe: (draft: T) => T | void): void {\n compileTimeOnly('$produce');\n}\n\n/** Sets the title of the page. The last component that sets it wins. */\nexport function $title(_value: unknown): void {\n compileTimeOnly('$title');\n}\n\n/**\n * The latest result of a server function that a form of this component posts\n * to, or undefined before the first post. Pending while the form sends.\n */\nexport function $action<F extends (...args: never[]) => unknown>(\n _fn: F,\n): Awaited<ReturnType<F>> | undefined {\n return compileTimeOnly('$action');\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"signals.js","names":[],"sources":["../../src/runtime/signals.ts"],"sourcesContent":["// The compile-time functions of `.brm` files. The compiler replaces every\n// call and removes the import, so this module only gives them their types.\n// A call outside a `.brm` file throws.\n\nimport type { Context, NavigationState, Route } from './context.ts';\nimport type { RoutePath, RouteParams } from './routes.ts';\n\nfunction compileTimeOnly(name: string): never {\n throw new Error(`${name} works only in .brm files, which the brumate compiler compiles`);\n}\n\ndeclare const BINDABLE: unique symbol;\n\n/** The mark of a prop that a parent can bind. It has no value at runtime. */\nexport interface BindableMark<T> {\n readonly [BINDABLE]: T;\n}\n\n/**\n * Marks a prop that a parent can bind with `$bind`, such as\n * `open?: Bindable<boolean>`. The parent passes `T` or `$bind(name)`.\n * Inside the component, `$props<T>()` gives `T`.\n */\nexport type Bindable<T> = T | BindableMark<T>;\n\n/** The props as the component reads them, with `Bindable<T>` as `T`. */\nexport type Unbound<T> = { [K in keyof T]: Exclude<T[K], BindableMark<unknown>> };\n\n/**\n * Returns the props of the component. Destructure the call to keep each prop\n * reactive. Destructure it with `let` to write props, such as\n * `let { open = false } = $props()`.\n */\n// oxlint-disable-next-line typescript/no-explicit-any -- Props are any object unless typed.\nexport function $props<T = Record<string, any>>(): Unbound<T> {\n return compileTimeOnly('$props');\n}\n\n/** Declares writable state. The variable reads and writes the signal. */\nexport function $signal<T>(value: T): T;\nexport function $signal<T>(): T | undefined;\nexport function $signal(): never {\n return compileTimeOnly('$signal');\n}\n\n/** The value of a memo: what a promise settles to, or the latest value of an async iterable. */\nexport type MemoValue<T> = Awaited<T> extends AsyncIterable<infer U> ? U : Awaited<T>;\n\n/**\n * Declares a value computed from other values. A promise is awaited where it\n * is read. An async iterable gives each of its values in turn.\n */\nexport function $memo<T>(_value: T): MemoValue<T> {\n return compileTimeOnly('$memo');\n}\n\n/**\n * Declares a memo that takes the value once it stops changing for `ms`\n * milliseconds, such as a search query while the user types. On the server,\n * and until the value first changes, it is the value.\n */\nexport function $debounced<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$debounced');\n}\n\n/**\n * Declares a memo that takes the value at most once every `ms`\n * milliseconds, and the last value after the wait, such as a position while\n * the pointer moves. On the server, and until the value first changes, it is the value.\n */\nexport function $throttled<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$throttled');\n}\n\n/**\n * Declares a value that follows a memo, and that handlers can write. A write\n * shows a guess, such as a new item while the form that adds it posts. The\n * value goes back to the memo when the memo changes, or when the server\n * calls of the page finish, such as after a failed post.\n */\nexport function $optimistic<T>(_source: T): T {\n return compileTimeOnly('$optimistic');\n}\n\n/** Runs a callback when the values it reads change, after the page resumes. Never on load. */\nexport function $effect(_callback: () => void | (() => void)): void {\n compileTimeOnly('$effect');\n}\n\n/** Runs a callback in the browser when a trigger fires. */\nexport function $client(\n _callback: () => void | (() => void),\n _trigger?: 'visible' | 'idle' | 'load',\n): void {\n compileTimeOnly('$client');\n}\n\n/** Reads a value without depending on it. */\nexport function $untrack<T>(_value: T): T {\n return compileTimeOnly('$untrack');\n}\n\n/** True while a new value of a memo, or of a memo it reads, loads on the client. Always false on the server. */\nexport function $isPending(_memo: unknown): boolean {\n return compileTimeOnly('$isPending');\n}\n\n/** Returns an ID that is unique in the page and the same on the server and the client. */\nexport function $id(): string {\n return compileTimeOnly('$id');\n}\n\n/** Provides a value of a context to the components inside this one. */\nexport function $setContext<T>(_context: Context<T>, _value: T): void {\n compileTimeOnly('$setContext');\n}\n\n/** Reads a context from the nearest component above that provides it, or its default value. */\nexport function $getContext<T>(_context: Context<T>): T {\n return compileTimeOnly('$getContext');\n}\n\n/**\n * The route of the page: its URL, its query string and its params, typed\n * from the route files as `href` is. The server reads the request, and the\n * browser reads `location`. It changes when navigation changes the URL.\n */\nexport function $route<P extends RoutePath = RoutePath>(_path?: P): Route<RouteParams<P>> {\n return compileTimeOnly('$route');\n}\n\n/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */\nexport function $navigation(): NavigationState {\n return compileTimeOnly('$navigation');\n}\n\n/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */\nexport function $produce<T>(_signal: T, _recipe: (draft: T) => T | void): void {\n compileTimeOnly('$produce');\n}\n\n/** Sets the title of the page. The last component that sets it wins. */\nexport function $title(_value: unknown): void {\n compileTimeOnly('$title');\n}\n\n/**\n * The latest result of a server function that a form of this component posts\n * to, or undefined before the first post. Pending while the form sends.\n */\nexport function $action<F extends (...args: never[]) => unknown>(\n _fn: F,\n): Awaited<ReturnType<F>> | undefined {\n return compileTimeOnly('$action');\n}\n\n/**\n * Passes a child a signal, or a prop that the component writes, so a write\n * of the prop in the child writes it. The child destructures the prop with\n * `let`. Pass it as the value of a prop: `<Dialog open=$bind(open) />`.\n *\n * - Only a prop of type `Bindable<T>` takes it.\n * - With `set`, a write calls `set(next)` in place of writing the signal.\n */\nexport function $bind<T>(signal: T, set?: (next: T) => unknown): BindableMark<T>;\nexport function $bind(): never {\n return compileTimeOnly('$bind');\n}\n\n/**\n * Marks a function that a script makes as an event handler, so a spread can\n * pass it on, as it passes on a handler that a caller writes in markup.\n * `args` are JSON values that go with the handler, and it runs as\n * `fn(...args, event)`.\n */\nexport function $handler<A extends unknown[], E = Event>(\n fn: (...args: [...A, E]) => unknown,\n ...args: A\n): (event: E) => unknown;\n/** A function that does not read the event. */\nexport function $handler<A extends unknown[]>(\n fn: (...args: A) => unknown,\n ...args: A\n): (event: Event) => unknown;\nexport function $handler(): never {\n return compileTimeOnly('$handler');\n}\n"],"mappings":";AAOA,SAAS,gBAAgB,MAAqB;CAC5C,MAAM,IAAI,MAAM,GAAG,KAAK,+DAA+D;AACzF;;;;;;AAyBA,SAAgB,SAA8C;CAC5D,OAAO,gBAAgB,QAAQ;AACjC;AAKA,SAAgB,UAAiB;CAC/B,OAAO,gBAAgB,SAAS;AAClC;;;;;AASA,SAAgB,MAAS,QAAyB;CAChD,OAAO,gBAAgB,OAAO;AAChC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;;AAQA,SAAgB,YAAe,SAAe;CAC5C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,QAAQ,WAA4C;CAClE,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,QACd,WACA,UACM;CACN,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,SAAY,QAAc;CACxC,OAAO,gBAAgB,UAAU;AACnC;;AAGA,SAAgB,WAAW,OAAyB;CAClD,OAAO,gBAAgB,YAAY;AACrC;;AAGA,SAAgB,MAAc;CAC5B,OAAO,gBAAgB,KAAK;AAC9B;;AAGA,SAAgB,YAAe,UAAsB,QAAiB;CACpE,gBAAgB,aAAa;AAC/B;;AAGA,SAAgB,YAAe,UAAyB;CACtD,OAAO,gBAAgB,aAAa;AACtC;;;;;;AAOA,SAAgB,OAAwC,OAAkC;CACxF,OAAO,gBAAgB,QAAQ;AACjC;;AAGA,SAAgB,cAA+B;CAC7C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,SAAY,SAAY,SAAuC;CAC7E,gBAAgB,UAAU;AAC5B;;AAGA,SAAgB,OAAO,QAAuB;CAC5C,gBAAgB,QAAQ;AAC1B;;;;;AAMA,SAAgB,QACd,KACoC;CACpC,OAAO,gBAAgB,SAAS;AAClC;AAWA,SAAgB,QAAe;CAC7B,OAAO,gBAAgB,OAAO;AAChC;AAiBA,SAAgB,WAAkB;CAChC,OAAO,gBAAgB,UAAU;AACnC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as LoaderOptions } from "../boot-
|
|
2
|
-
import { t as startWithoutNavigation } from "../static-loader-
|
|
1
|
+
import { t as LoaderOptions } from "../boot-C25Sa6vq.js";
|
|
2
|
+
import { t as startWithoutNavigation } from "../static-loader-Drpr0AzI.js";
|
|
3
3
|
export { type LoaderOptions, startWithoutNavigation };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as startWithoutNavigation } from "../static-loader-
|
|
1
|
+
export { t as startWithoutNavigation } from "../static-loader-nZssh66R.js";
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { t as ClientModule } from "../client-
|
|
2
|
-
import {
|
|
1
|
+
import { t as ClientModule } from "../client-D0CqSxoO.js";
|
|
2
|
+
import { Pt as EntryMiddleware, d as RenderOptions, t as Component } from "../server-DuFYRXrd.js";
|
|
3
3
|
//#region src/runtime/testing.d.ts
|
|
4
|
+
/** The middleware of files of server functions, by function ID. */
|
|
5
|
+
type FileMiddleware = Record<string, EntryMiddleware>;
|
|
4
6
|
export interface TestingOptions {
|
|
5
7
|
/** Imports the client module of a component, by component ID. */
|
|
6
8
|
load: (id: string) => Promise<ClientModule>;
|
|
7
9
|
/** The URL prefix of server function calls. */
|
|
8
10
|
rpc?: string;
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
container: HTMLElement;
|
|
12
|
+
/** What a test does with the page, as a user does. */
|
|
13
|
+
export interface Actions {
|
|
13
14
|
/** The first element that matches a selector. Throws if none does. */
|
|
14
15
|
get: (selector: string) => HTMLElement;
|
|
15
16
|
/** The text of the first element that matches a selector. */
|
|
@@ -25,6 +26,10 @@ export interface Mounted {
|
|
|
25
26
|
* client code, so its effects arrive a moment later.
|
|
26
27
|
*/
|
|
27
28
|
waitFor: (assertion: () => void, timeout?: number) => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export interface Mounted extends Actions {
|
|
31
|
+
/** The element that holds the component. */
|
|
32
|
+
container: HTMLElement;
|
|
28
33
|
/** Stops the loader and removes the component. */
|
|
29
34
|
unmount: () => void;
|
|
30
35
|
}
|
|
@@ -39,6 +44,13 @@ export interface AnswerOptions {
|
|
|
39
44
|
rpc?: string;
|
|
40
45
|
/** Called with the ID of each call, such as `issues_1a2b#toggleStar`, before it runs. */
|
|
41
46
|
onCall?: (id: string) => void;
|
|
47
|
+
/** The middleware of the entry, which runs before each call. `virtual:brumate/testing` passes the app's. */
|
|
48
|
+
middleware?: EntryMiddleware;
|
|
49
|
+
/**
|
|
50
|
+
* The middleware of each `'use server'` file, by function ID, or a
|
|
51
|
+
* function that imports them. `virtual:brumate/testing` passes them.
|
|
52
|
+
*/
|
|
53
|
+
fileMiddleware?: FileMiddleware | (() => Promise<FileMiddleware>);
|
|
42
54
|
}
|
|
43
55
|
/**
|
|
44
56
|
* Answers the server function calls of the page in the test, with
|
|
@@ -51,5 +63,34 @@ export interface AnswerOptions {
|
|
|
51
63
|
* `fetch`, as a browser stub does, throws: it would call itself without end.
|
|
52
64
|
*/
|
|
53
65
|
export declare function answerCalls(functions: ServerFunctions | (() => Promise<ServerFunctions>), options?: AnswerOptions): () => void;
|
|
66
|
+
/** Answers a request as the server of the app does, or undefined when nothing does. */
|
|
67
|
+
export type RequestHandler = (request: Request) => Promise<Response | undefined>;
|
|
68
|
+
export interface VisitorOptions extends TestingOptions {
|
|
69
|
+
/** Answers the requests for pages, forms without scripts, `#defer` bodies and endpoints. */
|
|
70
|
+
routes: () => Promise<RequestHandler>;
|
|
71
|
+
/** Answers server function calls. */
|
|
72
|
+
calls: () => Promise<RequestHandler>;
|
|
73
|
+
}
|
|
74
|
+
export interface VisitOptions {
|
|
75
|
+
/** Cookies that the browser has before the first request, by name. */
|
|
76
|
+
cookies?: Record<string, string>;
|
|
77
|
+
/** Headers of every request, such as `accept-language`. */
|
|
78
|
+
headers?: HeadersInit;
|
|
79
|
+
}
|
|
80
|
+
export interface Visited extends Actions {
|
|
81
|
+
/** The path and the query of the page, such as `/issues?q=bug`. It changes with client navigation. */
|
|
82
|
+
readonly url: string;
|
|
83
|
+
/** The status of the first page. */
|
|
84
|
+
status: number;
|
|
85
|
+
/** The cookies that the browser has now, by name. */
|
|
86
|
+
readonly cookies: Record<string, string>;
|
|
87
|
+
/** Stops the loader, puts `fetch` back and empties the document. */
|
|
88
|
+
close: () => void;
|
|
89
|
+
}
|
|
90
|
+
/** Visits a path of the app, as a browser that runs scripts does. */
|
|
91
|
+
export type Visit = (path: string, options?: VisitOptions) => Promise<Visited>;
|
|
92
|
+
/** Returns `visit`, which answers the requests of the page with the routes of the app. */
|
|
93
|
+
export declare function createVisit(options: VisitorOptions): Visit;
|
|
54
94
|
//#endregion
|
|
95
|
+
export {};
|
|
55
96
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/runtime/testing.js
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as start } from "../loader-
|
|
1
|
+
import { l as handleRequest, y as render } from "../server-CxVDYE_V.js";
|
|
2
|
+
import { t as start } from "../loader-Dos_3NP0.js";
|
|
3
|
+
//#region src/runtime/nodes.ts
|
|
4
|
+
const VOID = /* @__PURE__ */ new Set([
|
|
5
|
+
"area",
|
|
6
|
+
"base",
|
|
7
|
+
"br",
|
|
8
|
+
"col",
|
|
9
|
+
"embed",
|
|
10
|
+
"hr",
|
|
11
|
+
"img",
|
|
12
|
+
"input",
|
|
13
|
+
"link",
|
|
14
|
+
"meta",
|
|
15
|
+
"source",
|
|
16
|
+
"track",
|
|
17
|
+
"wbr"
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* The end of the last whole node at the top level of markup that streams in,
|
|
21
|
+
* so a chunk that ends inside a tag, the text of a script or a template
|
|
22
|
+
* waits for the rest. A `>` in an attribute or a script does not end a node.
|
|
23
|
+
*/
|
|
24
|
+
function wholeNodes(markup) {
|
|
25
|
+
const tag = /<(\/?)([a-zA-Z][\w-]*)(?:[^>"']|"[^"]*"|'[^']*')*>/g;
|
|
26
|
+
const lower = markup.toLowerCase();
|
|
27
|
+
let depth = 0;
|
|
28
|
+
let end = 0;
|
|
29
|
+
let match;
|
|
30
|
+
while (match = tag.exec(markup)) {
|
|
31
|
+
const [whole, closing, name] = match;
|
|
32
|
+
const element = name.toLowerCase();
|
|
33
|
+
if (!closing && element === "script") {
|
|
34
|
+
const close = lower.indexOf("<\/script", tag.lastIndex);
|
|
35
|
+
const after = close < 0 ? -1 : markup.indexOf(">", close);
|
|
36
|
+
if (after < 0) return end;
|
|
37
|
+
tag.lastIndex = after + 1;
|
|
38
|
+
} else if (!VOID.has(element) && !whole.endsWith("/>")) depth += closing ? -1 : 1;
|
|
39
|
+
if (depth === 0) end = tag.lastIndex;
|
|
40
|
+
}
|
|
41
|
+
return end;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
3
44
|
//#region src/runtime/testing.ts
|
|
45
|
+
/** The actions on the elements inside `root`. */
|
|
46
|
+
function actions(root) {
|
|
47
|
+
const get = (selector) => {
|
|
48
|
+
const element = root.querySelector(selector);
|
|
49
|
+
if (!element) throw new Error(`No element matches ${selector}`);
|
|
50
|
+
return element;
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
get,
|
|
54
|
+
text: (selector) => get(selector).textContent ?? "",
|
|
55
|
+
click: (selector) => get(selector).click(),
|
|
56
|
+
input: (selector, value) => {
|
|
57
|
+
const field = get(selector);
|
|
58
|
+
field.value = value;
|
|
59
|
+
field.dispatchEvent(new Event("input", { bubbles: true }));
|
|
60
|
+
},
|
|
61
|
+
submit: (selector) => {
|
|
62
|
+
get(selector).dispatchEvent(new Event("submit", {
|
|
63
|
+
bubbles: true,
|
|
64
|
+
cancelable: true
|
|
65
|
+
}));
|
|
66
|
+
},
|
|
67
|
+
waitFor: async (assertion, timeout = 2e3) => {
|
|
68
|
+
const until = Date.now() + timeout;
|
|
69
|
+
for (;;) try {
|
|
70
|
+
assertion();
|
|
71
|
+
return;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (Date.now() > until) throw error;
|
|
74
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
4
79
|
/**
|
|
5
80
|
* Runs an inline script, as a browser does when it adds one. The DOM of a
|
|
6
81
|
* test does not run scripts. The script is `document.currentScript` while it
|
|
@@ -72,37 +147,9 @@ function createMount(options) {
|
|
|
72
147
|
(async () => {
|
|
73
148
|
for await (const chunk of pending) append(container, chunk);
|
|
74
149
|
})();
|
|
75
|
-
const get = (selector) => {
|
|
76
|
-
const element = container.querySelector(selector);
|
|
77
|
-
if (!element) throw new Error(`No element matches ${selector}`);
|
|
78
|
-
return element;
|
|
79
|
-
};
|
|
80
150
|
return {
|
|
81
151
|
container,
|
|
82
|
-
|
|
83
|
-
text: (selector) => get(selector).textContent ?? "",
|
|
84
|
-
click: (selector) => get(selector).click(),
|
|
85
|
-
input: (selector, value) => {
|
|
86
|
-
const field = get(selector);
|
|
87
|
-
field.value = value;
|
|
88
|
-
field.dispatchEvent(new Event("input", { bubbles: true }));
|
|
89
|
-
},
|
|
90
|
-
submit: (selector) => {
|
|
91
|
-
get(selector).dispatchEvent(new Event("submit", {
|
|
92
|
-
bubbles: true,
|
|
93
|
-
cancelable: true
|
|
94
|
-
}));
|
|
95
|
-
},
|
|
96
|
-
waitFor: async (assertion, timeout = 2e3) => {
|
|
97
|
-
const until = Date.now() + timeout;
|
|
98
|
-
for (;;) try {
|
|
99
|
-
assertion();
|
|
100
|
-
return;
|
|
101
|
-
} catch (error) {
|
|
102
|
-
if (Date.now() > until) throw error;
|
|
103
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
104
|
-
}
|
|
105
|
-
},
|
|
152
|
+
...actions(container),
|
|
106
153
|
unmount: () => {
|
|
107
154
|
stop();
|
|
108
155
|
container.remove();
|
|
@@ -152,7 +199,12 @@ function answerCalls(functions, options = {}) {
|
|
|
152
199
|
loaded ??= Promise.resolve(typeof functions === "function" ? functions() : functions);
|
|
153
200
|
const registry = await loaded;
|
|
154
201
|
const request = input instanceof Request ? new Request(input, init) : new Request(url, init);
|
|
155
|
-
const
|
|
202
|
+
const guards = options.fileMiddleware;
|
|
203
|
+
const fileMiddleware = typeof guards === "function" ? await guards() : guards;
|
|
204
|
+
const handle = () => handleRequest(registry, request, prefix, {
|
|
205
|
+
middleware: options.middleware,
|
|
206
|
+
fileMiddleware
|
|
207
|
+
});
|
|
156
208
|
const response = await (calls ? calls.run(id, handle) : handle());
|
|
157
209
|
if (failure) {
|
|
158
210
|
const error = failure;
|
|
@@ -166,7 +218,162 @@ function answerCalls(functions, options = {}) {
|
|
|
166
218
|
if (globalThis.fetch === answer) globalThis.fetch = original;
|
|
167
219
|
};
|
|
168
220
|
}
|
|
221
|
+
const REDIRECTS = /* @__PURE__ */ new Set([
|
|
222
|
+
301,
|
|
223
|
+
302,
|
|
224
|
+
303,
|
|
225
|
+
307,
|
|
226
|
+
308
|
|
227
|
+
]);
|
|
228
|
+
/** Reads the `set-cookie` headers of a response into the cookies of the browser. */
|
|
229
|
+
function storeCookies(jar, response) {
|
|
230
|
+
for (const header of response.headers.getSetCookie()) {
|
|
231
|
+
const [pair = "", ...attributes] = header.split(";");
|
|
232
|
+
const equals = pair.indexOf("=");
|
|
233
|
+
const name = pair.slice(0, equals).trim();
|
|
234
|
+
if (equals < 1) continue;
|
|
235
|
+
if (attributes.some((attribute) => {
|
|
236
|
+
const [key = "", value = ""] = attribute.trim().split("=");
|
|
237
|
+
const lower = key.toLowerCase();
|
|
238
|
+
return lower === "max-age" && Number(value) <= 0 || lower === "expires" && Date.parse(value) <= Date.now();
|
|
239
|
+
})) jar.delete(name);
|
|
240
|
+
else jar.set(name, pair.slice(equals + 1).trim());
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/** The page that a visit holds, so a new visit closes the one before. */
|
|
244
|
+
let visited;
|
|
245
|
+
/** Returns `visit`, which answers the requests of the page with the routes of the app. */
|
|
246
|
+
function createVisit(options) {
|
|
247
|
+
const prefix = options.rpc ?? "/_brumate";
|
|
248
|
+
/**
|
|
249
|
+
* Answers the path with the routes of the app, puts the page in the
|
|
250
|
+
* document, and starts the loader with client navigation. Links, forms,
|
|
251
|
+
* server function calls and `#defer` requests of the page go to the same
|
|
252
|
+
* routes, without a server, with the cookies that the answers set.
|
|
253
|
+
*/
|
|
254
|
+
return async function visit(path, visitOptions = {}) {
|
|
255
|
+
visited?.close();
|
|
256
|
+
const jar = new Map(Object.entries(visitOptions.cookies ?? {}));
|
|
257
|
+
const original = globalThis.fetch;
|
|
258
|
+
const origin = location.origin;
|
|
259
|
+
history.replaceState(null, "", new URL(path, origin));
|
|
260
|
+
const answer = async (input, init) => {
|
|
261
|
+
let url = new URL(input instanceof Request ? input.url : String(input), location.href);
|
|
262
|
+
if (url.origin !== origin) return original(input, init);
|
|
263
|
+
let method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
264
|
+
let body = init?.body ?? void 0;
|
|
265
|
+
const extra = new Headers(input instanceof Request ? input.headers : void 0);
|
|
266
|
+
new Headers(init?.headers).forEach((value, name) => extra.set(name, value));
|
|
267
|
+
for (let hops = 0;; hops++) {
|
|
268
|
+
const request = new Request(url, {
|
|
269
|
+
method,
|
|
270
|
+
body,
|
|
271
|
+
signal: init?.signal ?? null
|
|
272
|
+
});
|
|
273
|
+
new Headers(visitOptions.headers).forEach((value, name) => request.headers.set(name, value));
|
|
274
|
+
extra.forEach((value, name) => request.headers.set(name, value));
|
|
275
|
+
if (jar.size > 0) request.headers.set("cookie", [...jar].map(([name, value]) => `${name}=${value}`).join("; "));
|
|
276
|
+
if (method !== "GET" && method !== "HEAD") request.headers.set("origin", origin);
|
|
277
|
+
const response = await (url.pathname.startsWith(`${prefix}/`) ? options.calls : options.routes)().then((handler) => handler(request)) ?? new Response("Not found", { status: 404 });
|
|
278
|
+
storeCookies(jar, response);
|
|
279
|
+
const location = response.headers.get("location");
|
|
280
|
+
if (!REDIRECTS.has(response.status) || !location || init?.redirect === "manual") {
|
|
281
|
+
Object.defineProperty(response, "url", { value: url.href });
|
|
282
|
+
return response;
|
|
283
|
+
}
|
|
284
|
+
if (hops === 20) throw new TypeError(`Too many redirects from ${path}`);
|
|
285
|
+
url = new URL(location, url);
|
|
286
|
+
if (response.status === 303 && method !== "HEAD" || method === "POST" && (response.status === 301 || response.status === 302)) {
|
|
287
|
+
method = "GET";
|
|
288
|
+
body = void 0;
|
|
289
|
+
extra.delete("content-type");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
globalThis.fetch = answer;
|
|
294
|
+
const ran = /* @__PURE__ */ new WeakSet();
|
|
295
|
+
const runOnce = (script) => {
|
|
296
|
+
if (!ran.has(script) && !script.hasAttribute("src") && !script.hasAttribute("type")) {
|
|
297
|
+
ran.add(script);
|
|
298
|
+
run(script);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
const scripts = new MutationObserver((records) => {
|
|
302
|
+
for (const record of records) for (const node of record.addedNodes) if (node.nodeName === "SCRIPT") runOnce(node);
|
|
303
|
+
else if (node instanceof Element) node.querySelectorAll("script").forEach(runOnce);
|
|
304
|
+
});
|
|
305
|
+
const response = await answer(path);
|
|
306
|
+
history.replaceState(null, "", response.url);
|
|
307
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
308
|
+
let html = "";
|
|
309
|
+
let end = -1;
|
|
310
|
+
let done = false;
|
|
311
|
+
while (end < 0 && !done) {
|
|
312
|
+
const chunk = await reader.read();
|
|
313
|
+
done = chunk.done;
|
|
314
|
+
html += chunk.value ?? "";
|
|
315
|
+
end = html.search(/<\/html>/i);
|
|
316
|
+
}
|
|
317
|
+
const cut = end < 0 ? html.length : end + 7;
|
|
318
|
+
const page = new DOMParser().parseFromString(html.slice(0, cut), "text/html");
|
|
319
|
+
for (const name of document.documentElement.getAttributeNames()) document.documentElement.removeAttribute(name);
|
|
320
|
+
for (const attribute of page.documentElement.attributes) document.documentElement.setAttribute(attribute.name, attribute.value);
|
|
321
|
+
document.head.replaceChildren(...[...page.head.childNodes].map((node) => document.importNode(node, true)));
|
|
322
|
+
document.body.replaceChildren(...[...page.body.childNodes].map((node) => document.importNode(node, true)));
|
|
323
|
+
document.querySelectorAll("script").forEach(runOnce);
|
|
324
|
+
scripts.observe(document, {
|
|
325
|
+
childList: true,
|
|
326
|
+
subtree: true
|
|
327
|
+
});
|
|
328
|
+
const stop = start({
|
|
329
|
+
load: options.load,
|
|
330
|
+
rpc: prefix,
|
|
331
|
+
navigate: true,
|
|
332
|
+
preload: false
|
|
333
|
+
});
|
|
334
|
+
let rest = html.slice(cut);
|
|
335
|
+
let open = true;
|
|
336
|
+
(async () => {
|
|
337
|
+
while (!done) {
|
|
338
|
+
const chunk = await reader.read();
|
|
339
|
+
done = chunk.done;
|
|
340
|
+
rest += chunk.value ?? "";
|
|
341
|
+
const last = done ? rest.length : wholeNodes(rest);
|
|
342
|
+
if (last > 0 && open) {
|
|
343
|
+
const template = document.createElement("template");
|
|
344
|
+
template.innerHTML = rest.slice(0, last);
|
|
345
|
+
document.body.append(template.content);
|
|
346
|
+
rest = rest.slice(last);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
})();
|
|
350
|
+
const current = {
|
|
351
|
+
...actions(document),
|
|
352
|
+
get url() {
|
|
353
|
+
return location.pathname + location.search;
|
|
354
|
+
},
|
|
355
|
+
status: response.status,
|
|
356
|
+
get cookies() {
|
|
357
|
+
return Object.fromEntries(jar);
|
|
358
|
+
},
|
|
359
|
+
close: () => {
|
|
360
|
+
if (!open) return;
|
|
361
|
+
open = false;
|
|
362
|
+
visited = void 0;
|
|
363
|
+
stop();
|
|
364
|
+
scripts.disconnect();
|
|
365
|
+
reader.cancel().catch(() => {});
|
|
366
|
+
if (globalThis.fetch === answer) globalThis.fetch = original;
|
|
367
|
+
import("./client.js").then((core) => core.leavePage());
|
|
368
|
+
document.head.replaceChildren();
|
|
369
|
+
document.body.replaceChildren();
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
visited = current;
|
|
373
|
+
return current;
|
|
374
|
+
};
|
|
375
|
+
}
|
|
169
376
|
//#endregion
|
|
170
|
-
export { answerCalls, createMount };
|
|
377
|
+
export { answerCalls, createMount, createVisit };
|
|
171
378
|
|
|
172
379
|
//# sourceMappingURL=testing.js.map
|