@torpor/build 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{SessionHelper-MaodMaLU.d.mts → CacheOptions-C4-ebVt9.d.mts} +58 -8
- package/dist/CacheOptions-C4-ebVt9.d.mts.map +1 -0
- package/dist/{MiddlewareFunction-7rIvFkjl.d.mts → MiddlewareFunction-DMYxjzF4.d.mts} +25 -2
- package/dist/MiddlewareFunction-DMYxjzF4.d.mts.map +1 -0
- package/dist/{Router-Bxm7K20d.d.mts → Router-DyK3DTWQ.d.mts} +2 -2
- package/dist/{Router-Bxm7K20d.d.mts.map → Router-DyK3DTWQ.d.mts.map} +1 -1
- package/dist/{Server-Djd9-NkU.mjs → Server-BCijhgZp.mjs} +3 -3
- package/dist/{Server-Djd9-NkU.mjs.map → Server-BCijhgZp.mjs.map} +1 -1
- package/dist/{Server-hwbZ7P2g.d.mts → Server-ClwvuilS.d.mts} +2 -2
- package/dist/{Server-hwbZ7P2g.d.mts.map → Server-ClwvuilS.d.mts.map} +1 -1
- package/dist/{ServerEvent-L0rT_mBJ.mjs → ServerEvent-BBRkd4Ya.mjs} +127 -31
- package/dist/ServerEvent-BBRkd4Ya.mjs.map +1 -0
- package/dist/{ServerHook-CyVEr5OL.d.mts → ServerHook-DY-NSG6n.d.mts} +2 -2
- package/dist/{ServerHook-CyVEr5OL.d.mts.map → ServerHook-DY-NSG6n.d.mts.map} +1 -1
- package/dist/{ServerLoadEvent-F60w1TZt.d.mts → ServerLoadEvent-CpcgsKCU.d.mts} +19 -5
- package/dist/ServerLoadEvent-CpcgsKCU.d.mts.map +1 -0
- package/dist/{Site-CAeAqjkk.d.mts → Site-BEMQW1_y.d.mts} +31 -11
- package/dist/Site-BEMQW1_y.d.mts.map +1 -0
- package/dist/{basePath-DQnbHc7o.mjs → basePath-B6hmOMl4.mjs} +89 -4
- package/dist/basePath-B6hmOMl4.mjs.map +1 -0
- package/dist/bin/index.js +1 -1
- package/dist/clientEntry.mjs +10 -5
- package/dist/clientEntry.mjs.map +1 -1
- package/dist/dev.d.mts +2 -2
- package/dist/dev.mjs +2 -2
- package/dist/{devPlugin-D9b5uhzm.mjs → devPlugin-BGrTpcC2.mjs} +3 -3
- package/dist/{devPlugin-D9b5uhzm.mjs.map → devPlugin-BGrTpcC2.mjs.map} +1 -1
- package/dist/discovery.d.mts +1 -1
- package/dist/discovery.mjs +1 -1
- package/dist/index.d.mts +22 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -1
- package/dist/{load-BODDzmH0.mjs → load-Dw187nJ_.mjs} +95 -52
- package/dist/load-Dw187nJ_.mjs.map +1 -0
- package/dist/nav.d.mts +2 -1
- package/dist/nav.d.mts.map +1 -1
- package/dist/nav.mjs +3 -3
- package/dist/nodeDev.d.mts +1 -1
- package/dist/nodeDev.mjs +1 -1
- package/dist/openapi.d.mts +2 -2
- package/dist/{read-DxMVAh5Y.mjs → read-CPW2iPum.mjs} +21 -2
- package/dist/read-CPW2iPum.mjs.map +1 -0
- package/dist/{response-C5EZsszY.mjs → response-B4UoOJvv.mjs} +3 -24
- package/dist/response-B4UoOJvv.mjs.map +1 -0
- package/dist/response.mjs +2 -2
- package/dist/run.d.mts +1 -1
- package/dist/run.d.mts.map +1 -1
- package/dist/run.mjs +1 -1
- package/dist/{runHooks-D5p1Rh7i.mjs → runHooks-C7kt7SEo.mjs} +36 -2
- package/dist/runHooks-C7kt7SEo.mjs.map +1 -0
- package/dist/{runOpenApi-BZ314IiI.mjs → runOpenApi-DK-QnYEr.mjs} +239 -18
- package/dist/runOpenApi-DK-QnYEr.mjs.map +1 -0
- package/dist/server/Server.d.mts +1 -1
- package/dist/server/Server.mjs +1 -1
- package/dist/server.d.mts +30 -6
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +47 -3
- package/dist/server.mjs.map +1 -1
- package/dist/{serverEntry-Da1PFlIU.d.mts → serverEntry-BFad1k1C.d.mts} +3 -3
- package/dist/serverEntry-BFad1k1C.d.mts.map +1 -0
- package/dist/{serverEntry-8YnfpKTj.mjs → serverEntry-DAT7o7o2.mjs} +3 -5
- package/dist/serverEntry-DAT7o7o2.mjs.map +1 -0
- package/dist/serverEntry.d.mts +1 -1
- package/dist/serverEntry.mjs +1 -1
- package/dist/{serverHandlers-Ba_35jpO.mjs → serverHandlers-B1L8I72-.mjs} +398 -192
- package/dist/serverHandlers-B1L8I72-.mjs.map +1 -0
- package/dist/{sitemap-CnIYTLhu.d.mts → sitemap-CKmagPyL.d.mts} +2 -2
- package/dist/{sitemap-CnIYTLhu.d.mts.map → sitemap-CKmagPyL.d.mts.map} +1 -1
- package/dist/{sitemap-4imxJVrG.mjs → sitemap-DdzFjGlo.mjs} +2 -2
- package/dist/{sitemap-4imxJVrG.mjs.map → sitemap-DdzFjGlo.mjs.map} +1 -1
- package/dist/state.d.mts +1 -4
- package/dist/state.d.mts.map +1 -1
- package/dist/state.mjs +1 -1
- package/dist/test.d.mts +2 -2
- package/dist/test.mjs +2 -2
- package/dist/{unprocessable-DwAG44Rh.mjs → unprocessable-BZXwyN0n.mjs} +23 -2
- package/dist/unprocessable-BZXwyN0n.mjs.map +1 -0
- package/package.json +3 -3
- package/src/types/manifest.d.ts +3 -0
- package/dist/MiddlewareFunction-7rIvFkjl.d.mts.map +0 -1
- package/dist/ServerEvent-L0rT_mBJ.mjs.map +0 -1
- package/dist/ServerLoadEvent-F60w1TZt.d.mts.map +0 -1
- package/dist/SessionHelper-MaodMaLU.d.mts.map +0 -1
- package/dist/Site-CAeAqjkk.d.mts.map +0 -1
- package/dist/_page-CW6SLuT4.mjs +0 -14
- package/dist/_page-CW6SLuT4.mjs.map +0 -1
- package/dist/basePath-DQnbHc7o.mjs.map +0 -1
- package/dist/load-BODDzmH0.mjs.map +0 -1
- package/dist/read-DxMVAh5Y.mjs.map +0 -1
- package/dist/response-C5EZsszY.mjs.map +0 -1
- package/dist/runHooks-D5p1Rh7i.mjs.map +0 -1
- package/dist/runOpenApi-BZ314IiI.mjs.map +0 -1
- package/dist/serverEntry-8YnfpKTj.mjs.map +0 -1
- package/dist/serverEntry-Da1PFlIU.d.mts.map +0 -1
- package/dist/serverHandlers-Ba_35jpO.mjs.map +0 -1
- package/dist/unprocessable-DwAG44Rh.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as CookieHelper, i as FlashHelper, n as SessionHelper, r as HeaderHelper, t as CacheOptions } from "./CacheOptions-C4-ebVt9.mjs";
|
|
2
2
|
import { a as RouteParamsOf } from "./ParseRouteParams-BtC0eH3z.mjs";
|
|
3
3
|
//#region src/types/ServerLoadEvent.d.ts
|
|
4
4
|
/**
|
|
@@ -30,8 +30,9 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
|
|
|
30
30
|
*/
|
|
31
31
|
params: Params;
|
|
32
32
|
/**
|
|
33
|
-
* Data that is available to functions in +server hooks,
|
|
34
|
-
* and pages. It flows down in that
|
|
33
|
+
* Data that is available to functions in +server hooks, route middleware
|
|
34
|
+
* (as `ev.appData`), layouts, endpoints and pages. It flows down in that
|
|
35
|
+
* order.
|
|
35
36
|
*/
|
|
36
37
|
appData: Record<string, any>;
|
|
37
38
|
/**
|
|
@@ -76,13 +77,26 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
|
|
|
76
77
|
session: SessionHelper;
|
|
77
78
|
/**
|
|
78
79
|
* A helper for setting one-time flash messages, shown on the next page
|
|
79
|
-
* render as `$page.flash = { type, message }`.
|
|
80
|
+
* render as `$context.$page.flash = { type, message }`.
|
|
80
81
|
*/
|
|
81
82
|
flash: FlashHelper;
|
|
82
83
|
/**
|
|
83
84
|
* A helper for getting and setting headers.
|
|
84
85
|
*/
|
|
85
86
|
headers: HeaderHelper;
|
|
87
|
+
/**
|
|
88
|
+
* Sets how the response may be cached (`Cache-Control` and `Vary`), e.g.
|
|
89
|
+
* `event.cache({ maxAge: 60 })`. Calls from a request's layouts and page
|
|
90
|
+
* are merged, with the most restrictive setting winning. See
|
|
91
|
+
* [Caching](/build/caching).
|
|
92
|
+
*/
|
|
93
|
+
cache: (options: CacheOptions) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Keeps background work running after the response is sent (on
|
|
96
|
+
* Cloudflare, through the worker's `ctx.waitUntil`). A rejection is
|
|
97
|
+
* logged rather than left unhandled.
|
|
98
|
+
*/
|
|
99
|
+
waitUntil: (promise: Promise<unknown>) => void;
|
|
86
100
|
/**
|
|
87
101
|
* An optional adapter object, containing adapter-specific functionality.
|
|
88
102
|
*/
|
|
@@ -90,4 +104,4 @@ interface ServerLoadEvent<Route extends string | undefined = undefined, Body = u
|
|
|
90
104
|
}
|
|
91
105
|
//#endregion
|
|
92
106
|
export { QueryRecord as n, ServerLoadEvent as r, FormDataRecord as t };
|
|
93
|
-
//# sourceMappingURL=ServerLoadEvent-
|
|
107
|
+
//# sourceMappingURL=ServerLoadEvent-CpcgsKCU.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerLoadEvent-CpcgsKCU.d.mts","names":[],"sources":["../src/types/ServerLoadEvent.ts"],"mappings":";;;;;;;KAWY,iBAAiB,eAAe,qBAAqB;;;;;KAMrD,cAAc;;;;;;;;UASD,gBACxB,8CACA,gBACA,WAAW,gBACX,YAAY,aACZ,SAAS,cAAc;;;;EAKvB,KAAK;;;;;;EAML,QAAQ;;;;;;EAQR,SAAS;;;;EAIT,SAAS;;;;EAKT,YAAY,QAAQ;;;;;;;;;EASpB,YAAY,QAAQ;;;;;;;EAOpB,gBAAgB,QAAQ;;;;;;;EAOxB,aAAa,QAAQ;;;;EAIrB,SAAS;;;;;EAKT,SAAS;;;;;EAKT,OAAO;;;;EAIP,SAAS;;;;;;;EAOT,QAAQ,SAAS;;;;;;EAMjB,YAAY,SAAS;;;;EAIrB,SAAS,OAAO"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as MiddlewareFunction } from "./MiddlewareFunction-
|
|
2
|
-
import { t as Server } from "./Server-
|
|
1
|
+
import { t as MiddlewareFunction } from "./MiddlewareFunction-DMYxjzF4.mjs";
|
|
2
|
+
import { t as Server } from "./Server-ClwvuilS.mjs";
|
|
3
3
|
import { a as RouteParamsOf } from "./ParseRouteParams-BtC0eH3z.mjs";
|
|
4
|
-
import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-
|
|
5
|
-
import { t as ServerHook } from "./ServerHook-
|
|
6
|
-
import { a as PageLoadReturn, i as PageEndPoint, t as SitemapOptions } from "./sitemap-
|
|
4
|
+
import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-CpcgsKCU.mjs";
|
|
5
|
+
import { t as ServerHook } from "./ServerHook-DY-NSG6n.mjs";
|
|
6
|
+
import { a as PageLoadReturn, i as PageEndPoint, t as SitemapOptions } from "./sitemap-CKmagPyL.mjs";
|
|
7
7
|
import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
|
|
8
8
|
import { Plugin, UserConfig } from "vite";
|
|
9
9
|
//#region src/types/Adapter.d.ts
|
|
@@ -146,7 +146,8 @@ interface PageServerEndPoint<Route extends string | undefined = undefined, Data
|
|
|
146
146
|
};
|
|
147
147
|
/**
|
|
148
148
|
* Route middleware, run for this route's loads and actions after the
|
|
149
|
-
* global middleware (see `site.middleware`) and
|
|
149
|
+
* global middleware (see `site.middleware`) and the folder hooks, so it
|
|
150
|
+
* can read what the hooks loaded from `ev.appData` (e.g. the user).
|
|
150
151
|
* `enter` may return a Response to short-circuit; `exit` hooks run in
|
|
151
152
|
* reverse. Middleware see the raw request url.
|
|
152
153
|
*/
|
|
@@ -443,9 +444,10 @@ type ServerEndPoint<Route extends string | undefined = undefined, Schemas extend
|
|
|
443
444
|
head?: ServerRequest<Route, unknown, FormDataRecord, SchemaQuery<Schemas, "head">, ParamsOf<Schemas, Route>>;
|
|
444
445
|
/**
|
|
445
446
|
* Route middleware, run for this endpoint's handlers after the global
|
|
446
|
-
* middleware (see `site.middleware`)
|
|
447
|
-
*
|
|
448
|
-
*
|
|
447
|
+
* middleware (see `site.middleware`) and the folder hooks, so it can
|
|
448
|
+
* read what the hooks loaded from `ev.appData` (e.g. the user). `enter`
|
|
449
|
+
* may return a Response to short-circuit; `exit` hooks run in reverse.
|
|
450
|
+
* Middleware see the raw request url.
|
|
449
451
|
*/
|
|
450
452
|
middleware?: MiddlewareFunction[];
|
|
451
453
|
};
|
|
@@ -486,6 +488,15 @@ interface Route {
|
|
|
486
488
|
subFolder?: string;
|
|
487
489
|
}
|
|
488
490
|
//#endregion
|
|
491
|
+
//#region src/types/Budgets.d.ts
|
|
492
|
+
/** Limits on what each page may ship (see `Site.budgets`). */
|
|
493
|
+
interface Budgets {
|
|
494
|
+
/** The most gzipped JavaScript (in bytes) a page may load before it hydrates. */
|
|
495
|
+
js?: number;
|
|
496
|
+
/** Fail the build when a page goes over, rather than warning. */
|
|
497
|
+
fail?: boolean;
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
489
500
|
//#region src/site/Site.d.ts
|
|
490
501
|
/**
|
|
491
502
|
* The Site class contains the information necessary to setup a @torpor/build
|
|
@@ -621,6 +632,15 @@ declare class Site {
|
|
|
621
632
|
* the XML live at that path (customizable with `path`).
|
|
622
633
|
*/
|
|
623
634
|
sitemap?: SitemapOptions | boolean | string;
|
|
635
|
+
/**
|
|
636
|
+
* Limits on what each page may ship, checked by `tb --build`, which
|
|
637
|
+
* also reports how much JavaScript the heaviest pages load before they
|
|
638
|
+
* hydrate. `js` is the most gzipped JavaScript (in bytes) a page may load
|
|
639
|
+
* that way, e.g. `{ js: 250_000 }`; a page over it is a warning, or a
|
|
640
|
+
* build failure with `fail: true`. Chunks loaded later through dynamic
|
|
641
|
+
* imports don't count.
|
|
642
|
+
*/
|
|
643
|
+
budgets?: Budgets;
|
|
624
644
|
/**
|
|
625
645
|
* A Standard Schema (zod, valibot, arktype, etc) used to validate (and
|
|
626
646
|
* parse) the server environment. When set, `env()` from
|
|
@@ -723,5 +743,5 @@ declare class Site {
|
|
|
723
743
|
}, subFolder?: string): void;
|
|
724
744
|
}
|
|
725
745
|
//#endregion
|
|
726
|
-
export {
|
|
727
|
-
//# sourceMappingURL=Site-
|
|
746
|
+
export { PageServerActionSchemas as C, SitePlugin as D, PageServerAction as E, Adapter as O, LoadQuery as S, PageServerLoad as T, OpenApiRouteEntry as _, SchemaQuery as a, ActionBody as b, ServerRequest as c, OpenApiEndpointOverrides as d, OpenApiExtend as f, OpenApiPluginOptions as g, OpenApiOperation as h, SchemaBody as i, JsonSchema as l, OpenApiMethod as m, Budgets as n, ServerEndPoint as o, OpenApiLoader as p, ParamsOf as r, ServerEndPointSchemas as s, Site as t, OpenApiEndPoint as u, ResolvedOpenApiOptions as v, PageServerEndPoint as w, LoadParams as x, ToJsonSchema as y };
|
|
747
|
+
//# sourceMappingURL=Site-BEMQW1_y.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Site-BEMQW1_y.d.mts","names":[],"sources":["../src/types/Adapter.ts","../src/types/SitePlugin.ts","../src/types/PageServerAction.ts","../src/types/PageServerLoad.ts","../src/types/PageServerEndPoint.ts","../src/openapi/types.ts","../src/types/ServerRequest.ts","../src/types/ServerEndPoint.ts","../src/types/RouteType.ts","../src/types/Route.ts","../src/types/Budgets.ts","../src/site/Site.ts"],"mappings":";;;;;;;;;UAIyB;EACxB,YAAY,MAAM,SAAS;EAC3B,aAAa,MAAM,SAAS;;;;;;;EAO5B,OAAO,MAAM,SAAS,SAAS;;;;;EAK/B,QAAQ,QAAQ,QAAQ,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;KCG1C,cAAc,MAAM,gBAAgB;;;KCjBpC,iBACJ,8CACA,WAAW,gBACX,SAAS,cAAc,WAEvB,OAAO,gBAAgB,gBAAgB,UAAU,aAAa,YAC1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;;;;cCtMD;cACA;cACA;cACA;cACA;cACA;cACA;cACA;KAED,mBACF,oBACA,2BACA,sBACA,sBACA,6BACA,oBACA,2BACA;;;;;;KCRE,iBAAiB,qBAAqB,iBAAiB,aAAa;;;;UAKvD;EACxB;;;;;EAKA;;;;;;EAMA,WAAW;EACX,MAAM;EACN;;;;;UC3BwB;;EAExB;;EAEA;;;;;;;;cC+BoB;;EACpB;;;;;;;;;;EAUA;EACA,QAAQ;;;;;;EAMR;IAAgB;IAAgB;;;;;;;;EAOhC,SAAS;;;;EAIT,aAAa;;;;;;;;;;EAUb,SAAS;;;;;;EAMT;;;;;;;EAOA,aAAa;;;;;EAKb;;;;;;;;;;;;;;;;EAgBA,aAAa,IAAI;;;;;;;EAOjB;;;;;;;EAOA;;;;;;;;;EASA,sBAAsB;;;;;;EAMtB;;;;;;;;;;;;EAYA,YAAY;;;;;;;;;;;EAWZ,UAAU;;;;;;;;;EASV,UAAU;;;;;;;;;EASV,MAAM,0BAA0B;;;;;EAKhC,iBAAiB,eAAe;EAEhC;;MAKI;;;;;;;;;EAYJ,eAAqB,gBAAgB,qBAAqB;;;;;;;;;;;;EA0C1D,gBAAgB,OAAO;;;;;;;;EAyBvB,aACC,cACA,cACA,kHASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+HD,SACC,cACA;IACC;IACA,sBAAsB;IACtB,kBAAkB;IAClB;IACA,wBAAwB;IACxB,sBAAsB;IACtB;KAED"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
//#region src/site/basePath.ts
|
|
2
2
|
/**
|
|
3
3
|
* The site's base path, e.g. "/app" when the site is mounted under a
|
|
4
|
-
* subpath.
|
|
5
|
-
* (see
|
|
4
|
+
* subpath. On the client it's inherited from `site.basePath` through the
|
|
5
|
+
* manifest at startup (see clientEntry); default "" when the site is served
|
|
6
6
|
* from the root.
|
|
7
7
|
*
|
|
8
|
+
* Server handlers don't use this module state: `createServerLoad` keeps its
|
|
9
|
+
* site's base in its closure and tags each request (`requestBase.ts`), so
|
|
10
|
+
* several sites with different bases can share a process.
|
|
11
|
+
*
|
|
8
12
|
* Server code and user markup are written base-free: the server strips the
|
|
9
13
|
* base from incoming URLs before routing (requests that don't carry it get
|
|
10
14
|
* a 404), and adds it back to generated HTML attributes, redirect
|
|
@@ -83,10 +87,91 @@ function addBaseToPath(path, base) {
|
|
|
83
87
|
* rendered HTML, so that markup can be written base-free. Values that
|
|
84
88
|
* aren't absolute paths (relative, "//...", "http://...", "mailto:...")
|
|
85
89
|
* are left alone, as are ones that already carry the base.
|
|
90
|
+
*
|
|
91
|
+
* Only actual tag attributes are rewritten: text nodes (so an
|
|
92
|
+
* `href="/..."` shown in a `<pre>`/`<code>` sample or in page copy stays
|
|
93
|
+
* literal), comments, and raw-text elements (`<script>`, `<style>`,
|
|
94
|
+
* `<textarea>`, `<title>`) are copied verbatim.
|
|
86
95
|
*/
|
|
87
96
|
function rewriteBaseInHtml(html, base) {
|
|
88
97
|
if (!base) return html;
|
|
89
|
-
|
|
98
|
+
let result = "";
|
|
99
|
+
let index = 0;
|
|
100
|
+
while (index < html.length) {
|
|
101
|
+
const open = html.indexOf("<", index);
|
|
102
|
+
if (open === -1) {
|
|
103
|
+
result += html.slice(index);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
result += html.slice(index, open);
|
|
107
|
+
if (html.startsWith("<!--", open)) {
|
|
108
|
+
const close = html.indexOf("-->", open + 4);
|
|
109
|
+
if (close === -1) {
|
|
110
|
+
result += html.slice(open);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
result += html.slice(open, close + 3);
|
|
114
|
+
index = close + 3;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
let cursor = open + 1;
|
|
118
|
+
const closing = html[cursor] === "/";
|
|
119
|
+
if (closing) cursor++;
|
|
120
|
+
const nameStart = cursor;
|
|
121
|
+
while (cursor < html.length && /[a-zA-Z0-9:-]/.test(html[cursor])) cursor++;
|
|
122
|
+
const tagName = html.slice(nameStart, cursor).toLowerCase();
|
|
123
|
+
if (tagName === "") {
|
|
124
|
+
result += "<";
|
|
125
|
+
index = open + 1;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const tagEnd = findTagEnd(html, open);
|
|
129
|
+
if (tagEnd === -1) {
|
|
130
|
+
result += html.slice(open);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
const tag = html.slice(open, tagEnd + 1);
|
|
134
|
+
result += closing ? tag : rewriteTagAttributes(tag, base);
|
|
135
|
+
index = tagEnd + 1;
|
|
136
|
+
if (!closing && RAW_TEXT_ELEMENTS.has(tagName) && !tag.endsWith("/>")) {
|
|
137
|
+
const close = html.toLowerCase().indexOf(`</${tagName}`, index);
|
|
138
|
+
if (close === -1) {
|
|
139
|
+
result += html.slice(index);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
const closeEnd = html.indexOf(">", close);
|
|
143
|
+
if (closeEnd === -1) {
|
|
144
|
+
result += html.slice(index);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
result += html.slice(index, closeEnd + 1);
|
|
148
|
+
index = closeEnd + 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
/** Elements whose content must not be scanned for tags or attributes. */
|
|
154
|
+
const RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set([
|
|
155
|
+
"script",
|
|
156
|
+
"style",
|
|
157
|
+
"textarea",
|
|
158
|
+
"title"
|
|
159
|
+
]);
|
|
160
|
+
/** The index of the ">" ending the tag that starts at `start`, skipping quoted values. */
|
|
161
|
+
function findTagEnd(html, start) {
|
|
162
|
+
let quote = null;
|
|
163
|
+
for (let i = start + 1; i < html.length; i++) {
|
|
164
|
+
const char = html[i];
|
|
165
|
+
if (quote !== null) {
|
|
166
|
+
if (char === quote) quote = null;
|
|
167
|
+
} else if (char === "\"" || char === "'") quote = char;
|
|
168
|
+
else if (char === ">") return i;
|
|
169
|
+
}
|
|
170
|
+
return -1;
|
|
171
|
+
}
|
|
172
|
+
/** Rewrites base-free `href`/`action`/`src` attributes within one tag. */
|
|
173
|
+
function rewriteTagAttributes(tag, base) {
|
|
174
|
+
return tag.replace(/\s(href|action|src)\s*=\s*("([^"]*)"|'([^']*)')/gi, (match, name, _quoted, double, single) => {
|
|
90
175
|
const value = double ?? single ?? "";
|
|
91
176
|
const rewritten = addBaseToPath(value, base);
|
|
92
177
|
if (rewritten === value) return match;
|
|
@@ -96,4 +181,4 @@ function rewriteBaseInHtml(html, base) {
|
|
|
96
181
|
//#endregion
|
|
97
182
|
export { rewriteBaseInHtml as a, normalizeOrigin as i, getBasePath as n, setBasePath as o, normalizeBasePath as r, stripBaseFromUrl as s, addBaseToPath as t };
|
|
98
183
|
|
|
99
|
-
//# sourceMappingURL=basePath-
|
|
184
|
+
//# sourceMappingURL=basePath-B6hmOMl4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basePath-B6hmOMl4.mjs","names":[],"sources":["../src/site/basePath.ts"],"sourcesContent":["/**\n * The site's base path, e.g. \"/app\" when the site is mounted under a\n * subpath. On the client it's inherited from `site.basePath` through the\n * manifest at startup (see clientEntry); default \"\" when the site is served\n * from the root.\n *\n * Server handlers don't use this module state: `createServerLoad` keeps its\n * site's base in its closure and tags each request (`requestBase.ts`), so\n * several sites with different bases can share a process.\n *\n * Server code and user markup are written base-free: the server strips the\n * base from incoming URLs before routing (requests that don't carry it get\n * a 404), and adds it back to generated HTML attributes, redirect\n * locations and paths built with `route()`. The client router does the\n * mirror image: strips for matching, adds for data fetches.\n */\nlet basePath = \"\";\n\n/**\n * Validates and sets the site's base path: must be \"\", start with \"/\" and\n * not end with \"/\" (a trailing slash is stripped, \"/\" is normalized to \"\")\n */\nexport function setBasePath(value: string | undefined): void {\n\tbasePath = normalizeBasePath(value);\n}\n\nexport function getBasePath(): string {\n\treturn basePath;\n}\n\n/**\n * Normalizes a base path value, throwing a descriptive error when it\n * can't be one. Trailing slashes are stripped and \"/\" is normalized to \"\".\n */\nexport function normalizeBasePath(value: string | undefined): string {\n\tconst trimmed = (value ?? \"\").trim();\n\tif (trimmed === \"\" || trimmed === \"/\") return \"\";\n\tif (!trimmed.startsWith(\"/\") || /\\s/.test(trimmed)) {\n\t\tthrow new Error(\n\t\t\t`The base path must be an absolute path without spaces (e.g. \"/app\"), ` + `got \"${value}\"`,\n\t\t);\n\t}\n\treturn trimmed.replace(/\\/+$/, \"\");\n}\n\n/**\n * Normalizes a site origin value, throwing a descriptive error when it\n * isn't an absolute http(s) origin without a path or spaces.\n */\nexport function normalizeOrigin(value: string | undefined): string {\n\tconst trimmed = (value ?? \"\").trim();\n\tif (trimmed === \"\") {\n\t\tthrow new Error(`The site origin is empty (e.g. \"https://example.com\")`);\n\t}\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(trimmed);\n\t} catch {\n\t\tthrow new Error(\n\t\t\t`The site origin must be an absolute url (e.g. \"https://example.com\"), got \"${value}\"`,\n\t\t);\n\t}\n\tif (\n\t\t(url.protocol !== \"https:\" && url.protocol !== \"http:\") ||\n\t\turl.pathname !== \"/\" ||\n\t\t/\\s/.test(trimmed)\n\t) {\n\t\tthrow new Error(\n\t\t\t`The site origin must be an http(s) url without spaces or a path ` +\n\t\t\t\t`(e.g. \"https://example.com\"), got \"${value}\"`,\n\t\t);\n\t}\n\t// A trailing slash is allowed\n\treturn url.origin;\n}\n\n/**\n * Strips the base from a URL's pathname, copying the URL so it can be used\n * for routing without disturbing the request. Returns undefined when there\n * is a base and the URL doesn't carry it -- the caller should then return\n * a not-found response, since the site only serves requests under its\n * mount point.\n */\nexport function stripBaseFromUrl(url: URL, base: string): URL | undefined {\n\tconst stripped = new URL(url);\n\tif (!base) return stripped;\n\tif (stripped.pathname === base) {\n\t\tstripped.pathname = \"/\";\n\t\treturn stripped;\n\t}\n\tif (stripped.pathname.startsWith(base + \"/\")) {\n\t\tstripped.pathname = stripped.pathname.slice(base.length) || \"/\";\n\t\treturn stripped;\n\t}\n\treturn undefined;\n}\n\n/**\n * Adds the base to an absolute path, idempotent for paths that already\n * carry it. Relative paths (\"other/page\"), protocol-relative (\"//...\") and\n * full URLs are left alone.\n */\nexport function addBaseToPath(path: string, base: string): string {\n\tif (!base || !path.startsWith(\"/\") || path.startsWith(\"//\")) return path;\n\tif (path === \"/\") return base + \"/\";\n\tif (path === base || path.startsWith(base + \"/\")) return path;\n\treturn base + path;\n}\n\n/**\n * Rewrites absolute-path `href`, `action` and `src` attribute values in\n * rendered HTML, so that markup can be written base-free. Values that\n * aren't absolute paths (relative, \"//...\", \"http://...\", \"mailto:...\")\n * are left alone, as are ones that already carry the base.\n *\n * Only actual tag attributes are rewritten: text nodes (so an\n * `href=\"/...\"` shown in a `<pre>`/`<code>` sample or in page copy stays\n * literal), comments, and raw-text elements (`<script>`, `<style>`,\n * `<textarea>`, `<title>`) are copied verbatim.\n */\nexport function rewriteBaseInHtml(html: string, base: string): string {\n\tif (!base) return html;\n\n\tlet result = \"\";\n\tlet index = 0;\n\twhile (index < html.length) {\n\t\tconst open = html.indexOf(\"<\", index);\n\n\t\t// No more tags: the rest is text, copied verbatim\n\t\tif (open === -1) {\n\t\t\tresult += html.slice(index);\n\t\t\tbreak;\n\t\t}\n\t\tresult += html.slice(index, open);\n\n\t\t// Comments are copied through unparsed\n\t\tif (html.startsWith(\"<!--\", open)) {\n\t\t\tconst close = html.indexOf(\"-->\", open + 4);\n\t\t\tif (close === -1) {\n\t\t\t\tresult += html.slice(open);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult += html.slice(open, close + 3);\n\t\t\tindex = close + 3;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Parse the tag name (if this \"<\" actually starts one; otherwise it's\n\t\t// a literal less-than in text)\n\t\tlet cursor = open + 1;\n\t\tconst closing = html[cursor] === \"/\";\n\t\tif (closing) cursor++;\n\t\tconst nameStart = cursor;\n\t\twhile (cursor < html.length && /[a-zA-Z0-9:-]/.test(html[cursor]!)) cursor++;\n\t\tconst tagName = html.slice(nameStart, cursor).toLowerCase();\n\t\tif (tagName === \"\") {\n\t\t\tresult += \"<\";\n\t\t\tindex = open + 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst tagEnd = findTagEnd(html, open);\n\t\tif (tagEnd === -1) {\n\t\t\tresult += html.slice(open);\n\t\t\tbreak;\n\t\t}\n\n\t\tconst tag = html.slice(open, tagEnd + 1);\n\t\tresult += closing ? tag : rewriteTagAttributes(tag, base);\n\t\tindex = tagEnd + 1;\n\n\t\t// Raw-text elements can hold \"<\" and attribute-looking strings (a\n\t\t// script's inline HTML template, say); copy them untouched so the\n\t\t// scanner can't mistake their text for tags\n\t\tif (!closing && RAW_TEXT_ELEMENTS.has(tagName) && !tag.endsWith(\"/>\")) {\n\t\t\tconst close = html.toLowerCase().indexOf(`</${tagName}`, index);\n\t\t\tif (close === -1) {\n\t\t\t\tresult += html.slice(index);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst closeEnd = html.indexOf(\">\", close);\n\t\t\tif (closeEnd === -1) {\n\t\t\t\tresult += html.slice(index);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult += html.slice(index, closeEnd + 1);\n\t\t\tindex = closeEnd + 1;\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/** Elements whose content must not be scanned for tags or attributes. */\nconst RAW_TEXT_ELEMENTS = new Set([\"script\", \"style\", \"textarea\", \"title\"]);\n\n/** The index of the \">\" ending the tag that starts at `start`, skipping quoted values. */\nfunction findTagEnd(html: string, start: number): number {\n\tlet quote: string | null = null;\n\tfor (let i = start + 1; i < html.length; i++) {\n\t\tconst char = html[i];\n\t\tif (quote !== null) {\n\t\t\tif (char === quote) quote = null;\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tquote = char;\n\t\t} else if (char === \">\") {\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/** Rewrites base-free `href`/`action`/`src` attributes within one tag. */\nfunction rewriteTagAttributes(tag: string, base: string): string {\n\treturn tag.replace(\n\t\t/\\s(href|action|src)\\s*=\\s*(\"([^\"]*)\"|'([^']*)')/gi,\n\t\t(match, name: string, _quoted: string, double: string, single: string) => {\n\t\t\tconst value = double ?? single ?? \"\";\n\t\t\tconst rewritten = addBaseToPath(value, base);\n\t\t\tif (rewritten === value) return match;\n\t\t\treturn ` ${name}=\"${rewritten}\"`;\n\t\t},\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,IAAI,WAAW;;;;;AAMf,SAAgB,YAAY,OAAiC;CAC5D,WAAW,kBAAkB,KAAK;AACnC;AAEA,SAAgB,cAAsB;CACrC,OAAO;AACR;;;;;AAMA,SAAgB,kBAAkB,OAAmC;CACpE,MAAM,WAAW,SAAS,GAAA,CAAI,KAAK;CACnC,IAAI,YAAY,MAAM,YAAY,KAAK,OAAO;CAC9C,IAAI,CAAC,QAAQ,WAAW,GAAG,KAAK,KAAK,KAAK,OAAO,GAChD,MAAM,IAAI,MACT,6EAAkF,MAAM,EACzF;CAED,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AAClC;;;;;AAMA,SAAgB,gBAAgB,OAAmC;CAClE,MAAM,WAAW,SAAS,GAAA,CAAI,KAAK;CACnC,IAAI,YAAY,IACf,MAAM,IAAI,MAAM,uDAAuD;CAExE,IAAI;CACJ,IAAI;EACH,MAAM,IAAI,IAAI,OAAO;CACtB,QAAQ;EACP,MAAM,IAAI,MACT,8EAA8E,MAAM,EACrF;CACD;CACA,IACE,IAAI,aAAa,YAAY,IAAI,aAAa,WAC/C,IAAI,aAAa,OACjB,KAAK,KAAK,OAAO,GAEjB,MAAM,IAAI,MACT,sGACuC,MAAM,EAC9C;CAGD,OAAO,IAAI;AACZ;;;;;;;;AASA,SAAgB,iBAAiB,KAAU,MAA+B;CACzE,MAAM,WAAW,IAAI,IAAI,GAAG;CAC5B,IAAI,CAAC,MAAM,OAA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C/B,CACD;AACD"}
|
package/dist/bin/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import { a as loadSite, n as run, t as runOpenApi } from "../runOpenApi-
|
|
2
|
+
import { a as loadSite, n as run, t as runOpenApi } from "../runOpenApi-DK-QnYEr.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fpath from "node:path";
|
|
5
5
|
//#region src/run/runCheck.ts
|
package/dist/clientEntry.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as Router } from "./Router-C4ADUfhv.mjs";
|
|
2
|
-
import { o as setBasePath } from "./basePath-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { n as getBasePath, o as setBasePath, t as addBaseToPath } from "./basePath-B6hmOMl4.mjs";
|
|
3
|
+
import { a as client, n as navigate, o as $page, r as loadData } from "./load-Dw187nJ_.mjs";
|
|
4
|
+
import { setUrlRewriter } from "@torpor/view";
|
|
5
5
|
import manifest from "@torpor/build/manifest";
|
|
6
6
|
//#region src/nav/navigationFailure.ts
|
|
7
7
|
/**
|
|
@@ -40,6 +40,8 @@ function handleNavigationFailure(href, result) {
|
|
|
40
40
|
//#endregion
|
|
41
41
|
//#region src/site/clientEntry.ts
|
|
42
42
|
setBasePath(manifest.base);
|
|
43
|
+
const base = getBasePath();
|
|
44
|
+
if (base) setUrlRewriter((url) => addBaseToPath(url, base));
|
|
43
45
|
const router = new Router();
|
|
44
46
|
router.addPages(manifest.routes);
|
|
45
47
|
client.router = router;
|
|
@@ -64,7 +66,8 @@ window.addEventListener("click", async (e) => {
|
|
|
64
66
|
if (result.type === "rendered") {
|
|
65
67
|
window.history.replaceState({ scroll: window.scrollY }, "", document.location.href);
|
|
66
68
|
window.history.pushState({ scroll: 0 }, "", url);
|
|
67
|
-
} else if (
|
|
69
|
+
} else if (result.type === "superseded") return;
|
|
70
|
+
else if (handleNavigationFailure(href, result) === "document") window.location.href = href;
|
|
68
71
|
}
|
|
69
72
|
});
|
|
70
73
|
window.addEventListener("mouseover", maybePrefetch);
|
|
@@ -103,7 +106,9 @@ function ignoreAnchorMouseEvent(link, e) {
|
|
|
103
106
|
return e.defaultPrevented || mouse.altKey || mouse.ctrlKey || mouse.metaKey || mouse.shiftKey || link.target && link.target !== "_self" || link.rel === "external" || link.hasAttribute("download") || link.isContentEditable;
|
|
104
107
|
}
|
|
105
108
|
window.addEventListener("popstate", async () => {
|
|
106
|
-
|
|
109
|
+
const result = await navigateToLocation(document.location);
|
|
110
|
+
if (result.type === "superseded") return;
|
|
111
|
+
if (result.type !== "rendered") {
|
|
107
112
|
window.location.reload();
|
|
108
113
|
return;
|
|
109
114
|
}
|
package/dist/clientEntry.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientEntry.mjs","names":[],"sources":["../src/nav/navigationFailure.ts","../src/site/clientEntry.ts"],"sourcesContent":["import type { NavigationResult } from \"./navigate.ts\";\n\n/**\n * The detail of the `torpor:navigation-failed` window event.\n */\nexport type NavigationFailureDetail = {\n\t/** The url the navigation was headed to. */\n\thref: string;\n\t/** Why the page was kept: the network is unreachable. */\n\treason: \"offline\";\n\t/** The failure that would have triggered the document fallback. */\n\terror?: unknown;\n};\n\n/** What the caller should do after a navigation rendered nothing. */\nexport type NavigationFallback = \"document\" | \"kept\";\n\n/**\n * Decides what happens after a navigation rendered nothing.\n *\n * A failed navigation while offline can't be recovered by a document load\n * either (unless a service worker has that url cached), so the current page is\n * kept — often holding an unsaved form or an optimistic edit — and the app is\n * told through the cancelable `torpor:navigation-failed` `CustomEvent` on\n * `window`. Everything else takes the document fallback: by-design server\n * navigations (`+server` routes, redirects), and online failures such as a\n * stale chunk hash, which a reload fixes by picking up the new manifest.\n *\n * `navigator.onLine` only reports that the machine has a network interface,\n * not that the server is reachable, so it is used here as a hint (it decides\n * whether to keep the page, not whether the network works). The event carries\n * the caught error so an app can tell the cases apart.\n *\n * Returns `\"document\"` when the caller should navigate the document, and\n * `\"kept\"` when the page was left in place.\n */\nexport default function handleNavigationFailure(\n\thref: string,\n\tresult: NavigationResult,\n): NavigationFallback {\n\tif (result.type !== \"failed\" || navigator.onLine !== false) {\n\t\treturn \"document\";\n\t}\n\n\tconst event = new CustomEvent<NavigationFailureDetail>(\"torpor:navigation-failed\", {\n\t\tcancelable: true,\n\t\tdetail: { href, reason: \"offline\", error: result.error },\n\t});\n\t// An app that cancels the event (e.g. its service worker caches the target\n\t// shell) asks for the document navigation after all\n\tif (!window.dispatchEvent(event)) {\n\t\treturn \"document\";\n\t}\n\n\tconsole.warn(\n\t\t`Navigation to ${href} failed while offline; staying on the current page. ` +\n\t\t\t\"Listen for torpor:navigation-failed to show your own notice.\",\n\t);\n\treturn \"kept\";\n}\n","import manifest from \"@torpor/build/manifest\";\nimport loadData from \"../nav/loadData.ts\";\nimport navigate from \"../nav/navigate.ts\";\nimport type { NavigationResult } from \"../nav/navigate.ts\";\nimport handleNavigationFailure from \"../nav/navigationFailure.ts\";\nimport $page from \"../state/$page.ts\";\nimport client from \"../state/client\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport Router from \"./Router.ts\";\nimport { setBasePath } from \"./basePath.ts\";\n\nsetBasePath(manifest.base);\n\n// Build the router from the Site object created by the user\nconst router = new Router();\nrouter.addPages(manifest.routes);\n\n// Put it in client state so that it can be accessed from navigate. We can't\n// just import it to navigate because that gets built by tsdown, without Vite\n// and the manifest\nclient.router = router;\nclient.viewTransitions = manifest.viewTransitions ?? false;\n\n// Intercept clicks on links\nwindow.addEventListener(\"click\", async (e) => {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\te.preventDefault();\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tlet result: NavigationResult;\n\t\ttry {\n\t\t\tresult = await navigate(url);\n\t\t} catch (error) {\n\t\t\t// `navigate` already catches its own failures, but never let an\n\t\t\t// unexpected throw swallow the fallback\n\t\t\tconsole.error(error);\n\t\t\tresult = { type: \"failed\", error };\n\t\t}\n\t\tif (result.type === \"rendered\") {\n\t\t\t// Save the scroll position of the outgoing page on the current\n\t\t\t// history entry, so that going (or coming) back can restore it\n\t\t\twindow.history.replaceState({ scroll: window.scrollY }, \"\", document.location.href);\n\t\t\twindow.history.pushState({ scroll: 0 }, \"\", url);\n\t\t} else if (handleNavigationFailure(href, result) === \"document\") {\n\t\t\twindow.location.href = href;\n\t\t}\n\t}\n});\n\n// Intercept mouseover/focus/touchstart on links for prefetching\n// TODO: settings e.g. <a href=\"\" data-tb-prefetch=\"eager\"/\"visible\"/\"hover\"/\"touch\">\nwindow.addEventListener(\"mouseover\", maybePrefetch);\nwindow.addEventListener(\"touchstart\", maybePrefetch);\n// Keyboard focus, and the press-down that precedes a click (a fast click can\n// land before any hover), warm the target too, so the navigation can await the\n// same in-flight request rather than starting its own\nwindow.addEventListener(\"focusin\", maybePrefetch);\nwindow.addEventListener(\"pointerdown\", maybePrefetch);\n\nasync function maybePrefetch(e: Event) {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tconst path = url.pathname;\n\t\t// Nothing to warm for the page we're already on\n\t\tif (path === document.location.pathname) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst query = url.searchParams;\n\t\tconst route = router.match(path, query);\n\t\tif (route) {\n\t\t\tconst handler = route.handler;\n\t\t\tconst params = route.params || {};\n\n\t\t\ttry {\n\t\t\t\t// A route with no client endpoint (a pure `+server` route) has\n\t\t\t\t// nothing to prefetch\n\t\t\t\tconst clientEndPoint: PageEndPoint | undefined = handler.endPoint\n\t\t\t\t\t? (await handler.endPoint())?.default\n\t\t\t\t\t: undefined;\n\t\t\t\tif (!clientEndPoint?.component) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Just dummy this up\n\t\t\t\tlet newStack: LayoutPath[] = [];\n\n\t\t\t\tawait loadData(handler, params, path, query, newStack, clientEndPoint, true);\n\t\t\t} catch {\n\t\t\t\t// A prefetch is best-effort: the real navigation retries\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction getLink(target: EventTarget | null): HTMLAnchorElement | undefined {\n\t// The target may be a child element of the link (e.g. an icon inside it),\n\t// so walk up to the nearest actual link. Fragment-only links (href=\"#...\")\n\t// are left to the browser's native jump-to-anchor behavior\n\tif (!(target instanceof Element)) return;\n\tconst link = target.closest(\"a[href]\");\n\tif (link?.getAttribute(\"href\")?.startsWith(\"#\")) return;\n\treturn (link as HTMLAnchorElement) ?? undefined;\n}\n\nfunction ignoreAnchorMouseEvent(link: HTMLAnchorElement, e: Event) {\n\t// Ignore the event if it was already handled (e.g. a user handler calling\n\t// preventDefault), a modifier key is pressed, the target is not \"_self\"\n\t// (e.g. \"_blank\"), rel=\"external\", it's a download link, or it's in a\n\t// contenteditable region\n\tconst mouse = e as MouseEvent;\n\treturn (\n\t\te.defaultPrevented ||\n\t\tmouse.altKey ||\n\t\tmouse.ctrlKey ||\n\t\tmouse.metaKey ||\n\t\tmouse.shiftKey ||\n\t\t(link.target && link.target !== \"_self\") ||\n\t\tlink.rel === \"external\" ||\n\t\tlink.hasAttribute(\"download\") ||\n\t\tlink.isContentEditable\n\t);\n}\n\n// Listen for changes to the URL that occur when the user navigates using the\n// back or forward buttons\nwindow.addEventListener(\"popstate\", async () => {\n\tconst result = await navigateToLocation(document.location);\n\tif (result.type !== \"rendered\") {\n\t\t// TODO: keep the page and notify the app when offline, like a click\n\t\t// failure; the url has already moved here, so that needs a history fix\n\t\twindow.location.reload();\n\t\treturn;\n\t}\n\t// Restore the scroll position that was saved on the history entry\n\trequestAnimationFrame(() => {\n\t\tconst state = window.history.state as { scroll?: number } | null;\n\t\twindow.scrollTo(0, state?.scroll ?? 0);\n\t});\n});\n\n// Do the initial navigation and hydration\nawait navigateToLocation(document.location, true);\n\nasync function navigateToLocation(\n\tlocation: Location,\n\tfirstTime = false,\n): Promise<NavigationResult> {\n\t// Reset $page on submit and link navigation\n\t// TODO: Should we put data in $page.data??\n\t$page.form = undefined;\n\n\treturn await navigate(new URL(location.toString()), firstTime);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAwB,wBACvB,MACA,QACqB;CACrB,IAAI,OAAO,SAAS,YAAY,UAAU,WAAW,OACpD,OAAO;CAGR,MAAM,QAAQ,IAAI,YAAqC,4BAA4B;EAClF,YAAY;EACZ,QAAQ;GAAE;GAAM,QAAQ;GAAW,OAAO,OAAO;EAAM;CACxD,CAAC;CAGD,IAAI,CAAC,OAAO,cAAc,KAAK,GAC9B,OAAO;CAGR,QAAQ,KACP,iBAAiB,KAAK,iHAEvB;CACA,OAAO;AACR;;;AC/CA,YAAY,SAAS,IAAI;AAGzB,MAAM,SAAS,IAAI,OAAO;AAC1B,OAAO,SAAS,SAAS,MAAM;AAK/B,OAAO,SAAS;AAChB,OAAO,kBAAkB,SAAS,mBAAmB;AAGrD,OAAO,iBAAiB,SAAS,OAAO,MAAM;CAC7C,MAAM,OAAO,QAAQ,EAAE,MAAM;CAC7B,IAAI,MAAM;EACT,IAAI,uBAAuB,MAAM,CAAC,GACjC;EAGD,EAAE,eAAe;EAEjB,MAAM,OAAO,KAAK;EAClB,MAAM,MAAM,IAAI,IAAI,IAAI;EAExB,IAAI;EACJ,IAAI;GACH,SAAS,MAAM,SAAS,GAAG;EAC5B,SAAS,OAAO;GAGf,QAAQ,MAAM,KAAK;GACnB,SAAS;IAAE,MAAM;IAAU;GAAM;EAClC;EACA,IAAI,OAAO,SAAS,YAAY;GAG/B,OAAO,QAAQ,aAAa,EAAE,QAAQ,OAAO,QAAQ,GAAG,IAAI,SAAS,SAAS,IAAI;GAClF,OAAO,QAAQ,UAAU,EAAE,QAAQ,EA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,KAAK;AAEP;AAIA,OAAO,iBAAiB,YAAY,YAAY;CAE/C,KAAI,MADiB,mBAAmB,SAAS,QAAQ,EAAA,CAC9C,SAAS,YAAY;EAG/B,OAAO,SAAS,OAAO;EACvB;CACD;CAEA,4BAA4B;EAC3B,MAAM,QAAQ,OAAO,QAAQ;EAC7B,OAAO,SAAS,GAAG,OAAO,UAAU,CAAC;CACtC,CAAC;AACF,CAAC;AAGD,MAAM,mBAAmB,SAAS,UAAU,IAAI;AAEhD,eAAe,mBACd,UACA,YAAY,OACgB;CAG5B,MAAM,OAAO,KAAA;CAEb,OAAO,MAAM,SAAS,IAAI,IAAI,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D"}
|
|
1
|
+
{"version":3,"file":"clientEntry.mjs","names":[],"sources":["../src/nav/navigationFailure.ts","../src/site/clientEntry.ts"],"sourcesContent":["import type { NavigationResult } from \"./navigate.ts\";\n\n/**\n * The detail of the `torpor:navigation-failed` window event.\n */\nexport type NavigationFailureDetail = {\n\t/** The url the navigation was headed to. */\n\thref: string;\n\t/** Why the page was kept: the network is unreachable. */\n\treason: \"offline\";\n\t/** The failure that would have triggered the document fallback. */\n\terror?: unknown;\n};\n\n/** What the caller should do after a navigation rendered nothing. */\nexport type NavigationFallback = \"document\" | \"kept\";\n\n/**\n * Decides what happens after a navigation rendered nothing.\n *\n * A failed navigation while offline can't be recovered by a document load\n * either (unless a service worker has that url cached), so the current page is\n * kept — often holding an unsaved form or an optimistic edit — and the app is\n * told through the cancelable `torpor:navigation-failed` `CustomEvent` on\n * `window`. Everything else takes the document fallback: by-design server\n * navigations (`+server` routes, redirects), and online failures such as a\n * stale chunk hash, which a reload fixes by picking up the new manifest.\n *\n * `navigator.onLine` only reports that the machine has a network interface,\n * not that the server is reachable, so it is used here as a hint (it decides\n * whether to keep the page, not whether the network works). The event carries\n * the caught error so an app can tell the cases apart.\n *\n * Returns `\"document\"` when the caller should navigate the document, and\n * `\"kept\"` when the page was left in place.\n */\nexport default function handleNavigationFailure(\n\thref: string,\n\tresult: NavigationResult,\n): NavigationFallback {\n\tif (result.type !== \"failed\" || navigator.onLine !== false) {\n\t\treturn \"document\";\n\t}\n\n\tconst event = new CustomEvent<NavigationFailureDetail>(\"torpor:navigation-failed\", {\n\t\tcancelable: true,\n\t\tdetail: { href, reason: \"offline\", error: result.error },\n\t});\n\t// An app that cancels the event (e.g. its service worker caches the target\n\t// shell) asks for the document navigation after all\n\tif (!window.dispatchEvent(event)) {\n\t\treturn \"document\";\n\t}\n\n\tconsole.warn(\n\t\t`Navigation to ${href} failed while offline; staying on the current page. ` +\n\t\t\t\"Listen for torpor:navigation-failed to show your own notice.\",\n\t);\n\treturn \"kept\";\n}\n","import manifest from \"@torpor/build/manifest\";\nimport { setUrlRewriter } from \"@torpor/view\";\nimport loadData from \"../nav/loadData.ts\";\nimport navigate from \"../nav/navigate.ts\";\nimport type { NavigationResult } from \"../nav/navigate.ts\";\nimport handleNavigationFailure from \"../nav/navigationFailure.ts\";\nimport $page from \"../state/$page.ts\";\nimport client from \"../state/client\";\nimport type LayoutPath from \"../types/LayoutPath\";\nimport type PageEndPoint from \"../types/PageEndPoint\";\nimport Router from \"./Router.ts\";\nimport { addBaseToPath, getBasePath, setBasePath } from \"./basePath.ts\";\n\nsetBasePath(manifest.base);\n\n// Markup is written base-free: the server adds the base to the links in its\n// HTML, and this adds it to the ones the client sets (dynamic attributes,\n// and pages and branches rendered on the client)\nconst base = getBasePath();\nif (base) {\n\tsetUrlRewriter((url) => addBaseToPath(url, base));\n}\n\n// Build the router from the Site object created by the user\nconst router = new Router();\nrouter.addPages(manifest.routes);\n\n// Put it in client state so that it can be accessed from navigate. We can't\n// just import it to navigate because that gets built by tsdown, without Vite\n// and the manifest\nclient.router = router;\nclient.viewTransitions = manifest.viewTransitions ?? false;\n\n// Intercept clicks on links\nwindow.addEventListener(\"click\", async (e) => {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\te.preventDefault();\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tlet result: NavigationResult;\n\t\ttry {\n\t\t\tresult = await navigate(url);\n\t\t} catch (error) {\n\t\t\t// `navigate` already catches its own failures, but never let an\n\t\t\t// unexpected throw swallow the fallback\n\t\t\tconsole.error(error);\n\t\t\tresult = { type: \"failed\", error };\n\t\t}\n\t\tif (result.type === \"rendered\") {\n\t\t\t// Save the scroll position of the outgoing page on the current\n\t\t\t// history entry, so that going (or coming) back can restore it\n\t\t\twindow.history.replaceState({ scroll: window.scrollY }, \"\", document.location.href);\n\t\t\twindow.history.pushState({ scroll: 0 }, \"\", url);\n\t\t} else if (result.type === \"superseded\") {\n\t\t\t// A newer navigation won; it owns the history entry and the page,\n\t\t\t// so do nothing (in particular, don't fall back to a document load)\n\t\t\treturn;\n\t\t} else if (handleNavigationFailure(href, result) === \"document\") {\n\t\t\twindow.location.href = href;\n\t\t}\n\t}\n});\n\n// Intercept mouseover/focus/touchstart on links for prefetching\n// TODO: settings e.g. <a href=\"\" data-tb-prefetch=\"eager\"/\"visible\"/\"hover\"/\"touch\">\nwindow.addEventListener(\"mouseover\", maybePrefetch);\nwindow.addEventListener(\"touchstart\", maybePrefetch);\n// Keyboard focus, and the press-down that precedes a click (a fast click can\n// land before any hover), warm the target too, so the navigation can await the\n// same in-flight request rather than starting its own\nwindow.addEventListener(\"focusin\", maybePrefetch);\nwindow.addEventListener(\"pointerdown\", maybePrefetch);\n\nasync function maybePrefetch(e: Event) {\n\tconst link = getLink(e.target);\n\tif (link) {\n\t\tif (ignoreAnchorMouseEvent(link, e)) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst href = link.href;\n\t\tconst url = new URL(href);\n\n\t\tconst path = url.pathname;\n\t\t// Nothing to warm for the page we're already on\n\t\tif (path === document.location.pathname) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst query = url.searchParams;\n\t\tconst route = router.match(path, query);\n\t\tif (route) {\n\t\t\tconst handler = route.handler;\n\t\t\tconst params = route.params || {};\n\n\t\t\ttry {\n\t\t\t\t// A route with no client endpoint (a pure `+server` route) has\n\t\t\t\t// nothing to prefetch\n\t\t\t\tconst clientEndPoint: PageEndPoint | undefined = handler.endPoint\n\t\t\t\t\t? (await handler.endPoint())?.default\n\t\t\t\t\t: undefined;\n\t\t\t\tif (!clientEndPoint?.component) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Just dummy this up\n\t\t\t\tlet newStack: LayoutPath[] = [];\n\n\t\t\t\tawait loadData(handler, params, path, query, newStack, clientEndPoint, true);\n\t\t\t} catch {\n\t\t\t\t// A prefetch is best-effort: the real navigation retries\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction getLink(target: EventTarget | null): HTMLAnchorElement | undefined {\n\t// The target may be a child element of the link (e.g. an icon inside it),\n\t// so walk up to the nearest actual link. Fragment-only links (href=\"#...\")\n\t// are left to the browser's native jump-to-anchor behavior\n\tif (!(target instanceof Element)) return;\n\tconst link = target.closest(\"a[href]\");\n\tif (link?.getAttribute(\"href\")?.startsWith(\"#\")) return;\n\treturn (link as HTMLAnchorElement) ?? undefined;\n}\n\nfunction ignoreAnchorMouseEvent(link: HTMLAnchorElement, e: Event) {\n\t// Ignore the event if it was already handled (e.g. a user handler calling\n\t// preventDefault), a modifier key is pressed, the target is not \"_self\"\n\t// (e.g. \"_blank\"), rel=\"external\", it's a download link, or it's in a\n\t// contenteditable region\n\tconst mouse = e as MouseEvent;\n\treturn (\n\t\te.defaultPrevented ||\n\t\tmouse.altKey ||\n\t\tmouse.ctrlKey ||\n\t\tmouse.metaKey ||\n\t\tmouse.shiftKey ||\n\t\t(link.target && link.target !== \"_self\") ||\n\t\tlink.rel === \"external\" ||\n\t\tlink.hasAttribute(\"download\") ||\n\t\tlink.isContentEditable\n\t);\n}\n\n// Listen for changes to the URL that occur when the user navigates using the\n// back or forward buttons\nwindow.addEventListener(\"popstate\", async () => {\n\tconst result = await navigateToLocation(document.location);\n\tif (result.type === \"superseded\") {\n\t\t// A newer navigation (another popstate, or a click) owns the url; it\n\t\t// handles the page and the scroll position\n\t\treturn;\n\t}\n\tif (result.type !== \"rendered\") {\n\t\t// TODO: keep the page and notify the app when offline, like a click\n\t\t// failure; the url has already moved here, so that needs a history fix\n\t\twindow.location.reload();\n\t\treturn;\n\t}\n\t// Restore the scroll position that was saved on the history entry\n\trequestAnimationFrame(() => {\n\t\tconst state = window.history.state as { scroll?: number } | null;\n\t\twindow.scrollTo(0, state?.scroll ?? 0);\n\t});\n});\n\n// Do the initial navigation and hydration\nawait navigateToLocation(document.location, true);\n\nasync function navigateToLocation(\n\tlocation: Location,\n\tfirstTime = false,\n): Promise<NavigationResult> {\n\t// Reset $page on submit and link navigation\n\t// TODO: Should we put data in $page.data??\n\t$page.form = undefined;\n\n\treturn await navigate(new URL(location.toString()), firstTime);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAwB,wBACvB,MACA,QACqB;CACrB,IAAI,OAAO,SAAS,YAAY,UAAU,WAAW,OACpD,OAAO;CAGR,MAAM,QAAQ,IAAI,YAAqC,4BAA4B;EAClF,YAAY;EACZ,QAAQ;GAAE;GAAM,QAAQ;GAAW,OAAO,OAAO;EAAM;CACxD,CAAC;CAGD,IAAI,CAAC,OAAO,cAAc,KAAK,GAC9B,OAAO;CAGR,QAAQ,KACP,iBAAiB,KAAK,iHAEvB;CACA,OAAO;AACR;;;AC9CA,YAAY,SAAS,IAAI;AAKzB,MAAM,OAAO,YAAY;AACzB,IAAI,MACH,gBAAgB,QAAQ,cAAc,KAAK,IAAI,CAAC;AAIjD,MAAM,SAAS,IAAI,OAAO;AAC1B,OAAO,SAAS,SAAS,MAAM;AAK/B,OAAO,SAAS;AAChB,OAAO,kBAAkB,SAAS,mBAAmB;AAGrD,OAAO,iBAAiB,SAAS,OAAO,MAAM;CAC7C,MAAM,OAAO,QAAQ,EAAE,MAAM;CAC7B,IAAI,MA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,CAAO,GAAG,gBAAgB,IAAI;GAC5E,QAAQ,CAER;EACD;CACD;AACD;AAEA,SAAS,QAAQ,QAA2D;CAI3E,IAAI,EAAE,kBAAkB,UAAU;CAClC,MAAM,OAAO,OAAO,QAAQ,SAAS;CACrC,IAAI,MAAM,aAAa,MAAM,CAAC,EAAE,WAAW,GAAG,GAAG;CACjD,OAAQ,QAA8B,KAAA;AACvC;AAEA,SAAS,uBAAuB,MAAyB,GAAU;CAKlE,MAAM,QAAQ;CACd,OACC,EAAE,oBACF,MAAM,UACN,MAAM,WACN,MAAM,WACN,MAAM,YACL,KAAK,UAAU,KAAK,WAAW,WAChC,KAAK,QAAQ,cACb,KAAK,aAAa,UAAU,KAC5B,KAAK;AAEP;AAIA,OAAO,iBAAiB,YAAY,YAAY;CAC/C,MAAM,SAAS,MAAM,mBAAmB,SAAS,QAAQ;CACzD,IAAI,OAAO,SAAS,cAGnB;CAED,IAAI,OAAO,SAAS,YAAY;EAG/B,OAAO,SAAS,OAAO;EACvB;CACD;CAEA,4BAA4B;EAC3B,MAAM,QAAQ,OAAO,QAAQ;EAC7B,OAAO,SAAS,GAAG,OAAO,UAAU,CAAC;CACtC,CAAC;AACF,CAAC;AAGD,MAAM,mBAAmB,SAAS,UAAU,IAAI;AAEhD,eAAe,mBACd,UACA,YAAY,OACgB;CAG5B,MAAM,OAAO,KAAA;CAEb,OAAO,MAAM,SAAS,IAAI,IAAI,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D"}
|
package/dist/dev.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as Server } from "./Server-
|
|
2
|
-
import { t as load } from "./serverEntry-
|
|
1
|
+
import { t as Server } from "./Server-ClwvuilS.mjs";
|
|
2
|
+
import { t as load } from "./serverEntry-BFad1k1C.mjs";
|
|
3
3
|
export { Server, load };
|
package/dist/dev.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as Server } from "./Server-
|
|
2
|
-
import { t as load } from "./serverEntry-
|
|
1
|
+
import { t as Server } from "./Server-BCijhgZp.mjs";
|
|
2
|
+
import { t as load } from "./serverEntry-DAT7o7o2.mjs";
|
|
3
3
|
export { Server, load };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as serverError } from "./response-
|
|
2
|
-
import { t as Server } from "./Server-
|
|
1
|
+
import { r as serverError } from "./response-B4UoOJvv.mjs";
|
|
2
|
+
import { t as Server } from "./Server-BCijhgZp.mjs";
|
|
3
3
|
import { t as flattenHeaders } from "./flattenHeaders-DM5qsSqO.mjs";
|
|
4
4
|
import { existsSync, promises, realpathSync } from "node:fs";
|
|
5
5
|
import fpath from "node:path";
|
|
@@ -141,4 +141,4 @@ async function sendResponse(response, res) {
|
|
|
141
141
|
//#endregion
|
|
142
142
|
export { siteEntryPaths as i, prepareTemplate as n, detectSourceMode as r, devPlugin as t };
|
|
143
143
|
|
|
144
|
-
//# sourceMappingURL=devPlugin-
|
|
144
|
+
//# sourceMappingURL=devPlugin-BGrTpcC2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devPlugin-D9b5uhzm.mjs","names":["path","path","fs"],"sources":["../src/utils/entryPaths.ts","../src/run/prepareTemplate.ts","../src/run/devPlugin.ts"],"sourcesContent":["import { realpathSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Paths to the site entry files that `tb` loads from the installed\n * `@torpor/build` package, in either source (linked framework) or dist\n * (registry install) mode.\n */\nexport type SiteEntryPaths = {\n\tserverEntry: string;\n\tclientEntry: string;\n\tclientDevEntry: string;\n};\n\n/**\n * Whether tb should run the framework from its TypeScript source instead of\n * its compiled dist. This is a framework-development convenience: registry\n * installs always run dist. Source mode is enabled explicitly via the\n * TORPOR_SOURCE_DEV env var, or automatically when both `@torpor/build` and\n * `@torpor/view` are symlinked into the app from outside node_modules (as\n * workspace links and `link:` overrides do). Both packages must be linked,\n * because source mode resolves their `torpor:source` export conditions, which\n * point at src files that registry installs don't ship.\n */\nexport function detectSourceMode(siteRoot: string): boolean {\n\tif (process.env.TORPOR_SOURCE_DEV) return true;\n\tconst packages = [\"@torpor/build\", \"@torpor/view\"];\n\treturn packages.every((pkg) => {\n\t\ttry {\n\t\t\tconst dist = path.resolve(siteRoot, \"node_modules\", pkg, \"dist/index.mjs\");\n\t\t\tconst real = realpathSync(dist);\n\t\t\treturn !real.includes(\"node_modules\");\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\n/**\n * The site entry files for the given mode: raw TypeScript sources when the\n * framework is linked (Vite transforms them, and edits show up without a\n * rebuild), compiled `.mjs` bundles for registry installs.\n */\nexport function siteEntryPaths(siteRoot: string, sourceMode: boolean): SiteEntryPaths {\n\tconst folder = path.resolve(\n\t\tsiteRoot,\n\t\t\"node_modules/@torpor/build\",\n\t\tsourceMode ? \"src/site\" : \"dist\",\n\t);\n\tconst ext = sourceMode ? \".ts\" : \".mjs\";\n\treturn {\n\t\tserverEntry: path.join(folder, `serverEntry${ext}`),\n\t\tclientEntry: path.join(folder, `clientEntry${ext}`),\n\t\tclientDevEntry: path.join(folder, `clientEntryDev${ext}`),\n\t};\n}\n\n/**\n * The torpor `Server` class module that a Cloudflare `_worker.ts` imports,\n * for the given mode.\n */\nexport function serverClassPath(siteRoot: string, sourceMode: boolean): string {\n\treturn path.resolve(\n\t\tsiteRoot,\n\t\t\"node_modules/@torpor/build\",\n\t\tsourceMode ? \"src/server/Server.ts\" : \"dist/server/Server.mjs\",\n\t);\n}\n","export default function prepareTemplate(\n\ttemplate: string,\n\tclientScript: string,\n\tclientDevScript?: string,\n): string {\n\tlet result = template;\n\n\t// Put %COMPONENT_HEAD% before </head>\n\t// This is where styles will go\n\tlet headStart = result.indexOf(\"</head>\");\n\tif (headStart === -1) {\n\t\tthrow new Error(`Couldn't find <head> end tag`);\n\t}\n\tresult = result.substring(0, headStart) + \"%COMPONENT_HEAD%\" + result.substring(headStart);\n\n\t// Put %COMPONENT_BODY% inside <div id=\"app\"></div>\n\t// This is where the component's HTML will go\n\tlet divMatchStart = regexIndexOf(result, /<div\\s+id=(\"app\"|'app'|app)[\\s>]/);\n\tif (divMatchStart === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\tlet bodyStart = result.indexOf(\">\", divMatchStart) + 1;\n\tlet bodyEnd = result.indexOf(\"</div>\", bodyStart);\n\tif (bodyEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\tresult = result.substring(0, bodyStart) + \"%COMPONENT_BODY%\" + result.substring(bodyEnd);\n\n\t// Add the clientEntry script at the very end, for hydrating and navigating\n\tif (clientDevScript) {\n\t\tresult += `<script type=\"module\" src=\"${clientDevScript}\"></script>`;\n\t}\n\tresult += `<script type=\"module\" src=\"${clientScript}\"></script>`;\n\n\treturn result;\n}\n\n// From https://stackoverflow.com/a/274094\nfunction regexIndexOf(string: string, regex: RegExp, position?: number) {\n\tvar indexOf = string.substring(position || 0).search(regex);\n\treturn indexOf >= 0 ? indexOf + (position || 0) : indexOf;\n}\n","import { type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport { type Plugin, type ViteDevServer } from \"vite\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport flattenHeaders from \"../server/connect/flattenHeaders.ts\";\nimport type Site from \"../site/Site.ts\";\nimport { siteEntryPaths } from \"../utils/entryPaths\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\n\ntype ReqHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;\n\n/**\n * The default Node-runtime dev plugin. Reads `src/site.html`, sets up a torpor\n * `Server` whose catch-all route renders via `vite.ssrLoadModule`, and registers\n * a Connect middleware (after Vite's own middlewares) that bridges Node\n * req/res to the torpor Server's fetch handler.\n *\n * Adapters that need a different runtime (e.g. workerd) provide their own\n * `dev()` plugin instead.\n */\nexport default function devPlugin(site: Site, sourceMode = false): Plugin {\n\treturn {\n\t\tname: \"torpor-dev\",\n\t\tconfigureServer(vite) {\n\t\t\t// Kick off async setup immediately; the middleware awaits it so we\n\t\t\t// don't depend on whether Vite awaits configureServer itself.\n\t\t\tconst handlerPromise = createDevHandler(vite, site, sourceMode);\n\t\t\t// Return a post-hook so our middleware runs AFTER Vite's internal\n\t\t\t// middlewares (static serving, transforms, HMR), acting as the SSR\n\t\t\t// fallback.\n\t\t\treturn () => {\n\t\t\t\tvite.middlewares.use(async (req, res, next) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst handler = await handlerPromise;\n\t\t\t\t\t\tawait handler(req, res);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tnext(e as Error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t};\n}\n\nasync function createDevHandler(\n\tvite: ViteDevServer,\n\tsite: Site,\n\tsourceMode: boolean,\n): Promise<ReqHandler> {\n\tconst entries = siteEntryPaths(site.root, sourceMode);\n\tconst serverScript = entries.serverEntry;\n\n\t// Read site.html if present\n\t// It's called site.html because @torpor/build builds the site (html, routes\n\t// etc) while the user builds the app (components etc). An endpoints-only\n\t// site has no site.html, and no template is needed\n\tlet template: string | undefined;\n\tconst templateFile = path.resolve(site.root, \"src/site.html\");\n\tif (existsSync(templateFile)) {\n\t\ttemplate = await fs.readFile(templateFile, \"utf-8\");\n\n\t\t// Apply Vite HTML transforms. This injects the Vite HMR client, and also\n\t\t// applies HTML transforms from Vite plugins. Note that we only support a\n\t\t// universal transform, not individual transforms for each route\n\t\ttemplate = await vite.transformIndexHtml(\"\", template);\n\n\t\t// Prepare site.html so that we can just splice components into it\n\t\ttemplate = prepareTemplate(template, entries.clientEntry, entries.clientDevEntry);\n\t}\n\n\tconst server = new Server();\n\n\t// Every request (GET, POST, etc) goes through loadEndPoint\n\tserver.add(\"*\", async (ev) => {\n\t\ttry {\n\t\t\t// Load the server entry. ssrLoadModule automatically transforms ESM\n\t\t\t// source code to be usable in Node.js. No bundling is required, and\n\t\t\t// it provides efficient invalidation similar to HMR\n\t\t\tconst { load } = await vite.ssrLoadModule(serverScript);\n\n\t\t\t// Render the app HTML (or fetch server data etc) via serverEntry's\n\t\t\t// exported `load` function\n\t\t\treturn await load(ev, template);\n\t\t} catch (e: any) {\n\t\t\t// If an error is caught, let Vite fix the stack trace so it maps\n\t\t\t// back to your actual source code\n\t\t\tvite.ssrFixStacktrace(e);\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Put adapter-specific functionality in the `adapter` property of\n\t// globalThis for now\n\t// @ts-ignore\n\tglobalThis.adapter = { env: process.env };\n\n\treturn async (req, res) => {\n\t\tconst request = await nodeReqToRequest(req);\n\t\tconst response = await server.fetch(request);\n\t\tawait sendResponse(response, res);\n\t};\n}\n\nasync function nodeReqToRequest(req: IncomingMessage): Promise<Request> {\n\tconst url = req.url ?? \"/\";\n\tconst host = req.headers.host ?? \"localhost\";\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst init: RequestInit = {\n\t\tmethod: req.method,\n\t\theaders: flattenHeaders(req.headers),\n\t};\n\tif (req.method !== \"GET\" && req.method !== \"HEAD\") {\n\t\tinit.body = Readable.toWeb(req) as ReadableStream;\n\t\t// @ts-ignore duplex is required when streaming a body\n\t\tinit.duplex = \"half\";\n\t}\n\treturn new Request(`${protocol}://${host}${url}`, init);\n}\n\nasync function sendResponse(response: Response, res: ServerResponse): Promise<void> {\n\tres.statusCode = response.status;\n\tresponse.headers.forEach((value, key) => res.setHeader(key, value));\n\tif (!response.body) {\n\t\tres.end();\n\t\treturn;\n\t}\n\tReadable.fromWeb(response.body as unknown as import(\"node:stream/web\").ReadableStream).pipe(res);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAAgB,iBAAiB,UAA2B;CAC3D,IAAI,QAAQ,IAAI,mBAAmB,OAAO;CAE1C,OAAO,CADW,iBAAiB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C,MAAM,WAAW,eAAe,IAAI,UAAU,IAAI,OAAO,YAAY,UAAU;CAC/E,MAAM,OAAoB;EACzB,QAAQ,IAAI;EACZ,SAAS,eAAe,IAAI,OAAO;CACpC;CACA,IAAI,IAAI,WAAW,SAAS,IAAI,WAAW,QAAQ;EAClD,KAAK,OAAO,SAAS,MAAM,GAAG;EAE9B,KAAK,SAAS;CACf;CACA,OAAO,IAAI,QAAQ,GAAG,SAAS,KAAK,OAAO,OAAO,IAAI;AACvD;AAEA,eAAe,aAAa,UAAoB,KAAoC;CACnF,IAAI,aAAa,SAAS;CAC1B,SAAS,QAAQ,SAAS,OAAO,QAAQ,IAAI,UAAU,KAAK,KAAK,CAAC;CAClE,IAAI,CAAC,SAAS,MAAM;EACnB,IAAI,IAAI;EACR;CACD;CACA,SAAS,QAAQ,SAAS,IAA2D,CAAC,CAAC,KAAK,GAAG;AAChG"}
|
|
1
|
+
{"version":3,"file":"devPlugin-BGrTpcC2.mjs","names":["path","path","fs"],"sources":["../src/utils/entryPaths.ts","../src/run/prepareTemplate.ts","../src/run/devPlugin.ts"],"sourcesContent":["import { realpathSync } from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Paths to the site entry files that `tb` loads from the installed\n * `@torpor/build` package, in either source (linked framework) or dist\n * (registry install) mode.\n */\nexport type SiteEntryPaths = {\n\tserverEntry: string;\n\tclientEntry: string;\n\tclientDevEntry: string;\n};\n\n/**\n * Whether tb should run the framework from its TypeScript source instead of\n * its compiled dist. This is a framework-development convenience: registry\n * installs always run dist. Source mode is enabled explicitly via the\n * TORPOR_SOURCE_DEV env var, or automatically when both `@torpor/build` and\n * `@torpor/view` are symlinked into the app from outside node_modules (as\n * workspace links and `link:` overrides do). Both packages must be linked,\n * because source mode resolves their `torpor:source` export conditions, which\n * point at src files that registry installs don't ship.\n */\nexport function detectSourceMode(siteRoot: string): boolean {\n\tif (process.env.TORPOR_SOURCE_DEV) return true;\n\tconst packages = [\"@torpor/build\", \"@torpor/view\"];\n\treturn packages.every((pkg) => {\n\t\ttry {\n\t\t\tconst dist = path.resolve(siteRoot, \"node_modules\", pkg, \"dist/index.mjs\");\n\t\t\tconst real = realpathSync(dist);\n\t\t\treturn !real.includes(\"node_modules\");\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\n/**\n * The site entry files for the given mode: raw TypeScript sources when the\n * framework is linked (Vite transforms them, and edits show up without a\n * rebuild), compiled `.mjs` bundles for registry installs.\n */\nexport function siteEntryPaths(siteRoot: string, sourceMode: boolean): SiteEntryPaths {\n\tconst folder = path.resolve(\n\t\tsiteRoot,\n\t\t\"node_modules/@torpor/build\",\n\t\tsourceMode ? \"src/site\" : \"dist\",\n\t);\n\tconst ext = sourceMode ? \".ts\" : \".mjs\";\n\treturn {\n\t\tserverEntry: path.join(folder, `serverEntry${ext}`),\n\t\tclientEntry: path.join(folder, `clientEntry${ext}`),\n\t\tclientDevEntry: path.join(folder, `clientEntryDev${ext}`),\n\t};\n}\n\n/**\n * The torpor `Server` class module that a Cloudflare `_worker.ts` imports,\n * for the given mode.\n */\nexport function serverClassPath(siteRoot: string, sourceMode: boolean): string {\n\treturn path.resolve(\n\t\tsiteRoot,\n\t\t\"node_modules/@torpor/build\",\n\t\tsourceMode ? \"src/server/Server.ts\" : \"dist/server/Server.mjs\",\n\t);\n}\n","export default function prepareTemplate(\n\ttemplate: string,\n\tclientScript: string,\n\tclientDevScript?: string,\n): string {\n\tlet result = template;\n\n\t// Put %COMPONENT_HEAD% before </head>\n\t// This is where styles will go\n\tlet headStart = result.indexOf(\"</head>\");\n\tif (headStart === -1) {\n\t\tthrow new Error(`Couldn't find <head> end tag`);\n\t}\n\tresult = result.substring(0, headStart) + \"%COMPONENT_HEAD%\" + result.substring(headStart);\n\n\t// Put %COMPONENT_BODY% inside <div id=\"app\"></div>\n\t// This is where the component's HTML will go\n\tlet divMatchStart = regexIndexOf(result, /<div\\s+id=(\"app\"|'app'|app)[\\s>]/);\n\tif (divMatchStart === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\tlet bodyStart = result.indexOf(\">\", divMatchStart) + 1;\n\tlet bodyEnd = result.indexOf(\"</div>\", bodyStart);\n\tif (bodyEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\tresult = result.substring(0, bodyStart) + \"%COMPONENT_BODY%\" + result.substring(bodyEnd);\n\n\t// Add the clientEntry script at the very end, for hydrating and navigating\n\tif (clientDevScript) {\n\t\tresult += `<script type=\"module\" src=\"${clientDevScript}\"></script>`;\n\t}\n\tresult += `<script type=\"module\" src=\"${clientScript}\"></script>`;\n\n\treturn result;\n}\n\n// From https://stackoverflow.com/a/274094\nfunction regexIndexOf(string: string, regex: RegExp, position?: number) {\n\tvar indexOf = string.substring(position || 0).search(regex);\n\treturn indexOf >= 0 ? indexOf + (position || 0) : indexOf;\n}\n","import { type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport { type Plugin, type ViteDevServer } from \"vite\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport flattenHeaders from \"../server/connect/flattenHeaders.ts\";\nimport type Site from \"../site/Site.ts\";\nimport { siteEntryPaths } from \"../utils/entryPaths\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\n\ntype ReqHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;\n\n/**\n * The default Node-runtime dev plugin. Reads `src/site.html`, sets up a torpor\n * `Server` whose catch-all route renders via `vite.ssrLoadModule`, and registers\n * a Connect middleware (after Vite's own middlewares) that bridges Node\n * req/res to the torpor Server's fetch handler.\n *\n * Adapters that need a different runtime (e.g. workerd) provide their own\n * `dev()` plugin instead.\n */\nexport default function devPlugin(site: Site, sourceMode = false): Plugin {\n\treturn {\n\t\tname: \"torpor-dev\",\n\t\tconfigureServer(vite) {\n\t\t\t// Kick off async setup immediately; the middleware awaits it so we\n\t\t\t// don't depend on whether Vite awaits configureServer itself.\n\t\t\tconst handlerPromise = createDevHandler(vite, site, sourceMode);\n\t\t\t// Return a post-hook so our middleware runs AFTER Vite's internal\n\t\t\t// middlewares (static serving, transforms, HMR), acting as the SSR\n\t\t\t// fallback.\n\t\t\treturn () => {\n\t\t\t\tvite.middlewares.use(async (req, res, next) => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst handler = await handlerPromise;\n\t\t\t\t\t\tawait handler(req, res);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tnext(e as Error);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t};\n}\n\nasync function createDevHandler(\n\tvite: ViteDevServer,\n\tsite: Site,\n\tsourceMode: boolean,\n): Promise<ReqHandler> {\n\tconst entries = siteEntryPaths(site.root, sourceMode);\n\tconst serverScript = entries.serverEntry;\n\n\t// Read site.html if present\n\t// It's called site.html because @torpor/build builds the site (html, routes\n\t// etc) while the user builds the app (components etc). An endpoints-only\n\t// site has no site.html, and no template is needed\n\tlet template: string | undefined;\n\tconst templateFile = path.resolve(site.root, \"src/site.html\");\n\tif (existsSync(templateFile)) {\n\t\ttemplate = await fs.readFile(templateFile, \"utf-8\");\n\n\t\t// Apply Vite HTML transforms. This injects the Vite HMR client, and also\n\t\t// applies HTML transforms from Vite plugins. Note that we only support a\n\t\t// universal transform, not individual transforms for each route\n\t\ttemplate = await vite.transformIndexHtml(\"\", template);\n\n\t\t// Prepare site.html so that we can just splice components into it\n\t\ttemplate = prepareTemplate(template, entries.clientEntry, entries.clientDevEntry);\n\t}\n\n\tconst server = new Server();\n\n\t// Every request (GET, POST, etc) goes through loadEndPoint\n\tserver.add(\"*\", async (ev) => {\n\t\ttry {\n\t\t\t// Load the server entry. ssrLoadModule automatically transforms ESM\n\t\t\t// source code to be usable in Node.js. No bundling is required, and\n\t\t\t// it provides efficient invalidation similar to HMR\n\t\t\tconst { load } = await vite.ssrLoadModule(serverScript);\n\n\t\t\t// Render the app HTML (or fetch server data etc) via serverEntry's\n\t\t\t// exported `load` function\n\t\t\treturn await load(ev, template);\n\t\t} catch (e: any) {\n\t\t\t// If an error is caught, let Vite fix the stack trace so it maps\n\t\t\t// back to your actual source code\n\t\t\tvite.ssrFixStacktrace(e);\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Put adapter-specific functionality in the `adapter` property of\n\t// globalThis for now\n\t// @ts-ignore\n\tglobalThis.adapter = { env: process.env };\n\n\treturn async (req, res) => {\n\t\tconst request = await nodeReqToRequest(req);\n\t\tconst response = await server.fetch(request);\n\t\tawait sendResponse(response, res);\n\t};\n}\n\nasync function nodeReqToRequest(req: IncomingMessage): Promise<Request> {\n\tconst url = req.url ?? \"/\";\n\tconst host = req.headers.host ?? \"localhost\";\n\tconst protocol = \"encrypted\" in req.socket && req.socket.encrypted ? \"https\" : \"http\";\n\tconst init: RequestInit = {\n\t\tmethod: req.method,\n\t\theaders: flattenHeaders(req.headers),\n\t};\n\tif (req.method !== \"GET\" && req.method !== \"HEAD\") {\n\t\tinit.body = Readable.toWeb(req) as ReadableStream;\n\t\t// @ts-ignore duplex is required when streaming a body\n\t\tinit.duplex = \"half\";\n\t}\n\treturn new Request(`${protocol}://${host}${url}`, init);\n}\n\nasync function sendResponse(response: Response, res: ServerResponse): Promise<void> {\n\tres.statusCode = response.status;\n\tresponse.headers.forEach((value, key) => res.setHeader(key, value));\n\tif (!response.body) {\n\t\tres.end();\n\t\treturn;\n\t}\n\tReadable.fromWeb(response.body as unknown as import(\"node:stream/web\").ReadableStream).pipe(res);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAAgB,iBAAiB,UAA2B;CAC3D,IAAI,QAAQ,IAAI,mBAAmB,OAAO;CAE1C,OAAO,CADW,iBAAiB,cACrB,CAAC,CAAC,OAAO,QAAQ;EAC9B,IAAI;GACH,MAAM,OAAOA,MAAK,QAAQ,UAAU,gBAAgB,KAAK,gBAAgB;GAEzE,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,IAAI,OAAO;CACpC;CACA,IAAI,IAAI,WAAW,SAAS,IAAI,WAAW,QAAQ;EAClD,KAAK,OAAO,SAAS,MAAM,GAAG;EAE9B,KAAK,SAAS;CACf;CACA,OAAO,IAAI,QAAQ,GAAG,SAAS,KAAK,OAAO,OAAO,IAAI;AACvD;AAEA,eAAe,aAAa,UAAoB,KAAoC;CACnF,IAAI,aAAa,SAAS;CAC1B,SAAS,QAAQ,SAAS,OAAO,QAAQ,IAAI,UAAU,KAAK,KAAK,CAAC;CAClE,IAAI,CAAC,SAAS,MAAM;EACnB,IAAI,IAAI;EACR;CACD;CACA,SAAS,QAAQ,SAAS,IAA2D,CAAC,CAAC,KAAK,GAAG;AAChG"}
|
package/dist/discovery.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as sitemapResponse, r as HeadElement, t as SitemapOptions } from "./sitemap-
|
|
1
|
+
import { n as sitemapResponse, r as HeadElement, t as SitemapOptions } from "./sitemap-CKmagPyL.mjs";
|
|
2
2
|
//#region src/discovery/seo.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The elements to build head markup from: a page title, a description and
|
package/dist/discovery.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as Router } from "./Router-
|
|
1
|
+
import { t as Router } from "./Router-DyK3DTWQ.mjs";
|
|
2
2
|
import { a as RouteParamsOf, i as RouteArgsOf, n as ParseRouteParams, r as RouteArgs } from "./ParseRouteParams-BtC0eH3z.mjs";
|
|
3
|
-
import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-
|
|
4
|
-
import { t as ServerHook } from "./ServerHook-
|
|
5
|
-
import { a as PageLoadReturn, i as PageEndPoint, o as PageLoadEvent } from "./sitemap-
|
|
3
|
+
import { n as QueryRecord, r as ServerLoadEvent, t as FormDataRecord } from "./ServerLoadEvent-CpcgsKCU.mjs";
|
|
4
|
+
import { t as ServerHook } from "./ServerHook-DY-NSG6n.mjs";
|
|
5
|
+
import { a as PageLoadReturn, i as PageEndPoint, o as PageLoadEvent } from "./sitemap-CKmagPyL.mjs";
|
|
6
6
|
import { n as UntypedResponse, t as TypedResponse } from "./TypedResponse-6lznqN4U.mjs";
|
|
7
7
|
import { t as StandardSchemaV1 } from "./StandardSchema-D28L8_zZ.mjs";
|
|
8
|
-
import { C as
|
|
8
|
+
import { C as PageServerActionSchemas, D as SitePlugin, E as PageServerAction, O as Adapter, S as LoadQuery, T as PageServerLoad, a as SchemaQuery, b as ActionBody, c as ServerRequest, i as SchemaBody, n as Budgets, o as ServerEndPoint, r as ParamsOf, s as ServerEndPointSchemas, t as Site, w as PageServerEndPoint, x as LoadParams } from "./Site-BEMQW1_y.mjs";
|
|
9
9
|
import { t as Jsonify } from "./Jsonify-hFz5OjtZ.mjs";
|
|
10
10
|
//#region src/types/PageData.d.ts
|
|
11
11
|
/**
|
|
@@ -73,5 +73,21 @@ interface PageProps<Data = Record<string, any>, Form = Record<string, any>> {
|
|
|
73
73
|
form: Form | undefined;
|
|
74
74
|
}
|
|
75
75
|
//#endregion
|
|
76
|
-
|
|
76
|
+
//#region src/types/LayoutServerEndPoint.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* For _layout.server. The same as a `PageServerEndPoint`, except that it
|
|
79
|
+
* can't declare `middleware`: layout loads run for the pages below them, but
|
|
80
|
+
* not for the API endpoints (`+server.ts`) in the same folders, so a guard
|
|
81
|
+
* here would leave those open. Guard a folder with a `_hook.server.ts`,
|
|
82
|
+
* which runs for every request below it.
|
|
83
|
+
*/
|
|
84
|
+
type LayoutServerEndPoint<Route extends string | undefined = undefined, Data = Record<string, any>, Schemas extends PageServerActionSchemas = PageServerActionSchemas> = Omit<PageServerEndPoint<Route, Data, Schemas>, "middleware"> & {
|
|
85
|
+
/**
|
|
86
|
+
* Not supported on layouts, and an error at runtime. Use a
|
|
87
|
+
* `_hook.server.ts` in the layout's folder to guard it.
|
|
88
|
+
*/
|
|
89
|
+
middleware?: never;
|
|
90
|
+
};
|
|
91
|
+
//#endregion
|
|
92
|
+
export { type ActionBody, type Adapter, type Budgets, type FormDataRecord, type Jsonify, type LayoutServerEndPoint, type LoadParams, type LoadQuery, type MergePageData, type PageData, type PageEndPoint, type PageForm, type PageLoadEvent, type PageLoadReturn, type PageProps, type PageServerAction, type PageServerActionSchemas, type PageServerEndPoint, type PageServerLoad, type ParamsOf, type ParseRouteParams, type QueryRecord, type RouteArgs, type RouteArgsOf, type RouteParamsOf, Router, type SchemaBody, type SchemaQuery, type ServerEndPoint, type ServerEndPointSchemas, type ServerHook, type ServerLoadEvent, type ServerRequest, Site, type SitePlugin, type StandardSchemaV1, type TypedResponse, type UntypedResponse };
|
|
77
93
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/PageData.ts","../src/types/PageForm.ts","../src/types/PageProps.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KAaY,SAAS,YAAY;EAAmB,QAAQ,qBAAqB;IAC9E,YAAY,QAAQ,iBAAiB,oBAAoB,QACxD,OACA,sBACD;;;;;;;;;;;;;;KAeS,cAAc,2BAA2B,yBAAyB,gBAAgB,QAC3F,SAAS,SAAS,cAAc;;;;KC9B9B,cAAc,cACjB,WAAW,UAAU,QAAQ,aAAY,qBAAqB,UAC5D,YAAY,QAAQ,0BAEhB;;;;;;;;;;;;;;KAeI,SAAS,YAAY;EAAmB,gBAAgB;KAChE,YAAY,4BACZ,sBACA,cAAc,YAAY,kBAAkB,oBAAoB,QAC/D,OACA,sBACF;;;;;;;UCxBsB,UAAU,OAAO,qBAAqB,OAAO;;;;EAIrE,MAAM;;;;EAIN,MAAM"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/PageData.ts","../src/types/PageForm.ts","../src/types/PageProps.ts","../src/types/LayoutServerEndPoint.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KAaY,SAAS,YAAY;EAAmB,QAAQ,qBAAqB;IAC9E,YAAY,QAAQ,iBAAiB,oBAAoB,QACxD,OACA,sBACD;;;;;;;;;;;;;;KAeS,cAAc,2BAA2B,yBAAyB,gBAAgB,QAC3F,SAAS,SAAS,cAAc;;;;KC9B9B,cAAc,cACjB,WAAW,UAAU,QAAQ,aAAY,qBAAqB,UAC5D,YAAY,QAAQ,0BAEhB;;;;;;;;;;;;;;KAeI,SAAS,YAAY;EAAmB,gBAAgB;KAChE,YAAY,4BACZ,sBACA,cAAc,YAAY,kBAAkB,oBAAoB,QAC/D,OACA,sBACF;;;;;;;UCxBsB,UAAU,OAAO,qBAAqB,OAAO;;;;EAIrE,MAAM;;;;EAIN,MAAM;;;;;;;;;;;KCFF,qBACJ,8CACA,OAAO,qBACP,gBAAgB,0BAA0B,2BACvC,KAAK,mBAAmB,OAAO,MAAM;;;;;EAKxC"}
|
package/dist/index.mjs
CHANGED
|
@@ -280,6 +280,15 @@ var Site = class {
|
|
|
280
280
|
*/
|
|
281
281
|
sitemap;
|
|
282
282
|
/**
|
|
283
|
+
* Limits on what each page may ship, checked by `tb --build`, which
|
|
284
|
+
* also reports how much JavaScript the heaviest pages load before they
|
|
285
|
+
* hydrate. `js` is the most gzipped JavaScript (in bytes) a page may load
|
|
286
|
+
* that way, e.g. `{ js: 250_000 }`; a page over it is a warning, or a
|
|
287
|
+
* build failure with `fail: true`. Chunks loaded later through dynamic
|
|
288
|
+
* imports don't count.
|
|
289
|
+
*/
|
|
290
|
+
budgets;
|
|
291
|
+
/**
|
|
283
292
|
* A Standard Schema (zod, valibot, arktype, etc) used to validate (and
|
|
284
293
|
* parse) the server environment. When set, `env()` from
|
|
285
294
|
* `@torpor/build/env` checks the environment on first use per request and
|
|
@@ -355,6 +364,7 @@ var Site = class {
|
|
|
355
364
|
this.prerender = other.prerender;
|
|
356
365
|
this.sitemap = other.sitemap;
|
|
357
366
|
this.origin = other.origin;
|
|
367
|
+
this.budgets = other.budgets;
|
|
358
368
|
return changed;
|
|
359
369
|
}
|
|
360
370
|
/**
|