@nifrajs/web 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +18 -0
- package/css-modules.d.ts +34 -0
- package/dist/build.d.ts +110 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +238 -0
- package/dist/build.js.map +1 -0
- package/dist/client.d.ts +32 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +204 -0
- package/dist/client.js.map +1 -0
- package/dist/deferred.d.ts +90 -0
- package/dist/deferred.d.ts.map +1 -0
- package/dist/deferred.js +310 -0
- package/dist/deferred.js.map +1 -0
- package/dist/dev-error.d.ts +17 -0
- package/dist/dev-error.d.ts.map +1 -0
- package/dist/dev-error.js +59 -0
- package/dist/dev-error.js.map +1 -0
- package/dist/dev.d.ts +25 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/dev.js +83 -0
- package/dist/dev.js.map +1 -0
- package/dist/draft.d.ts +58 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js +55 -0
- package/dist/draft.js.map +1 -0
- package/dist/fonts-google.d.ts +109 -0
- package/dist/fonts-google.d.ts.map +1 -0
- package/dist/fonts-google.js +291 -0
- package/dist/fonts-google.js.map +1 -0
- package/dist/fonts.d.ts +67 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +103 -0
- package/dist/fonts.js.map +1 -0
- package/dist/fs.d.ts +10 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +24 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.d.ts +280 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +784 -0
- package/dist/index.js.map +1 -0
- package/dist/islands.d.ts +37 -0
- package/dist/islands.d.ts.map +1 -0
- package/dist/islands.js +107 -0
- package/dist/islands.js.map +1 -0
- package/dist/isr.d.ts +154 -0
- package/dist/isr.d.ts.map +1 -0
- package/dist/isr.js +331 -0
- package/dist/isr.js.map +1 -0
- package/dist/manifest.d.ts +178 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +213 -0
- package/dist/manifest.js.map +1 -0
- package/dist/plugins/css-modules.d.ts +40 -0
- package/dist/plugins/css-modules.d.ts.map +1 -0
- package/dist/plugins/css-modules.js +0 -0
- package/dist/plugins/css-modules.js.map +1 -0
- package/dist/plugins/kit.d.ts +44 -0
- package/dist/plugins/kit.d.ts.map +1 -0
- package/dist/plugins/kit.js +105 -0
- package/dist/plugins/kit.js.map +1 -0
- package/dist/plugins/scss.d.ts +27 -0
- package/dist/plugins/scss.d.ts.map +1 -0
- package/dist/plugins/scss.js +78 -0
- package/dist/plugins/scss.js.map +1 -0
- package/dist/prerender.d.ts +77 -0
- package/dist/prerender.d.ts.map +1 -0
- package/dist/prerender.js +139 -0
- package/dist/prerender.js.map +1 -0
- package/dist/query.d.ts +62 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +184 -0
- package/dist/query.js.map +1 -0
- package/dist/router.d.ts +169 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +531 -0
- package/dist/router.js.map +1 -0
- package/dist/vite.d.ts +49 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +144 -0
- package/dist/vite.js.map +1 -0
- package/package.json +127 -0
- package/src/build.ts +375 -0
- package/src/client.ts +218 -0
- package/src/deferred.ts +339 -0
- package/src/dev-error.ts +62 -0
- package/src/dev.ts +108 -0
- package/src/draft.ts +82 -0
- package/src/fonts-google.ts +397 -0
- package/src/fonts.ts +147 -0
- package/src/fs.ts +26 -0
- package/src/index.ts +1202 -0
- package/src/islands.ts +121 -0
- package/src/isr.ts +461 -0
- package/src/manifest.ts +366 -0
- package/src/plugins/css-modules.ts +0 -0
- package/src/plugins/kit.ts +123 -0
- package/src/plugins/scss.ts +108 -0
- package/src/prerender.ts +209 -0
- package/src/query.ts +250 -0
- package/src/router.ts +676 -0
- package/src/vite.ts +212 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nifrajs/web — the framework-agnostic SSR core. It owns the render *seam* and the HTML
|
|
3
|
+
* document orchestration, and knows nothing about any specific UI framework: a render
|
|
4
|
+
* adapter (@nifrajs/web-solid, @nifrajs/web-react, …) supplies the actual render + hydrate.
|
|
5
|
+
*
|
|
6
|
+
* The core treats a "component" and a hydration "container" as opaque `unknown` — only
|
|
7
|
+
* the adapter interprets them. That keeps this package both framework-agnostic and free
|
|
8
|
+
* of DOM types: it is pure server orchestration + string building.
|
|
9
|
+
*/
|
|
10
|
+
import { type Server } from "@nifrajs/core";
|
|
11
|
+
import { type Deferred, defer } from "./deferred.js";
|
|
12
|
+
import type { Manifest, Meta, MetaArgs, MetaInput } from "./manifest.js";
|
|
13
|
+
import { type Submission } from "./router.js";
|
|
14
|
+
export { DRAFT_COOKIE, type DraftCookieControls, disableDraft, type EnableDraftOptions, enableDraft, isDraftEnabled, } from "./draft.js";
|
|
15
|
+
export { type FontDisplay, type FontFace, type FontPreloadInput, type FontSource, fontFace, fontPreload, } from "./fonts.js";
|
|
16
|
+
export { type CachedResponse, type CacheStore, ISR_REVALIDATE_HEADER, ISR_STATUS_HEADER, type ISRApp, type ISROptions, type ISRPlatform, KVCacheStore, type KVCacheStoreOptions, type KVNamespaceLike, MemoryCacheStore, type MemoryCacheStoreOptions, type RevalidateEndpointOptions, revalidateEndpoint, withISR, } from "./isr.js";
|
|
17
|
+
export { type Action, buildManifest, enumeratePrerenderedPaths, enumerateStaticRoutes, filePathToPattern, filePathToPatterns, type GetStaticPaths, type LayoutEntry, type Loader, type LoaderContext, type Manifest, type Meta, type MetaArgs, type MetaInput, type RouteEntry, type RouteModule, type StaticPath, type StaticPaths, type StaticRoutes, } from "./manifest.js";
|
|
18
|
+
export { createQueryClient, hashQueryKey, type QueryClient, type QueryClientOptions, type QueryHandle, type QueryState, type QueryStatus, } from "./query.js";
|
|
19
|
+
export { type ClientRouter, type ClientRouterOptions, createClientRouter, createMatcher, DATA_HEADER, type Fetcher, type FetcherState, type FetchRouteData, type MountRouterOptions, REDIRECT_HEADER, REVALIDATE_HEADER, type RouteMatch, type RoutePattern, type RouterState, type Submission, type SubmitOptions, } from "./router.js";
|
|
20
|
+
export { type Deferred, defer };
|
|
21
|
+
/** The data handed to a route component. Opaque to the core. `actionData` is the return of a
|
|
22
|
+
* route `action` after a POST (absent on plain GETs). `pending` + `submission` are client-only
|
|
23
|
+
* (absent on SSR): they drive **optimistic UI** — render from `submission.formData` while `pending`. */
|
|
24
|
+
export interface RenderProps {
|
|
25
|
+
readonly data: unknown;
|
|
26
|
+
readonly actionData?: unknown;
|
|
27
|
+
/** True while a client navigation or submit is in flight (client-only; absent/false on SSR). */
|
|
28
|
+
readonly pending?: boolean;
|
|
29
|
+
/** The in-flight client submit, for optimistic UI (client-only; absent on SSR + when idle). */
|
|
30
|
+
readonly submission?: Submission;
|
|
31
|
+
}
|
|
32
|
+
/** The seam every render adapter implements. */
|
|
33
|
+
export interface RenderAdapter {
|
|
34
|
+
/**
|
|
35
|
+
* Server: render a route's layout `chain` (outermost layout → page) to a **stream** of HTML
|
|
36
|
+
* bytes, including the framework's hydration markers. The page (innermost) receives `props`
|
|
37
|
+
* (the loader data); each layout wraps the child via its `children`. Returns (or resolves to)
|
|
38
|
+
* a Web `ReadableStream<Uint8Array>`: a streaming renderer flushes the shell first and streams
|
|
39
|
+
* Suspense boundaries as they resolve; a non-streaming renderer may return a one-chunk stream.
|
|
40
|
+
* May be async — e.g. React resolves once the shell is renderable, so a shell-render throw can
|
|
41
|
+
* still map to an error status before any byte is sent.
|
|
42
|
+
*/
|
|
43
|
+
renderToStream(chain: readonly unknown[], props: RenderProps): ReadableStream<Uint8Array> | Promise<ReadableStream<Uint8Array>>;
|
|
44
|
+
/**
|
|
45
|
+
* Server (optional): render the chain to a complete HTML **string** in one pass, with the same
|
|
46
|
+
* hydration markers `renderToStream` produces. When provided, `renderPage` uses it for any page
|
|
47
|
+
* that does **not** `defer()` — buffering the document is faster than the streaming pipeline there,
|
|
48
|
+
* because the framework's synchronous renderer (React `renderToString`, Solid `renderToString`,
|
|
49
|
+
* Preact `render`, Vue `renderToString`, Svelte `render`) is markedly cheaper than its streaming
|
|
50
|
+
* renderer — most visibly on Bun, where React Fizz / Solid `renderToStream` are the heaviest. Pages
|
|
51
|
+
* that `defer()` keep the streaming path (progressive `<Await>` needs it). Markup MUST be
|
|
52
|
+
* hydration-equivalent to `renderToStream`; a throw surfaces like the streaming shell-readiness
|
|
53
|
+
* await (the `_error` boundary maps it to a status). Omit it to always stream.
|
|
54
|
+
*/
|
|
55
|
+
renderToString?(chain: readonly unknown[], props: RenderProps): string | Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Server: per-document bootstrap markup injected into `<head>` that the client
|
|
58
|
+
* `hydrate` requires (Solid: `generateHydrationScript()`). Empty string if none.
|
|
59
|
+
*/
|
|
60
|
+
hydrationHead(): string;
|
|
61
|
+
}
|
|
62
|
+
/** Global the server serializes loader data into; the client reads it to hydrate. */
|
|
63
|
+
export declare const DATA_GLOBAL = "__NIFRA_DATA__";
|
|
64
|
+
/** Global the server writes the matched route id into; the client uses it to pick the chain. */
|
|
65
|
+
export declare const ROUTE_GLOBAL = "__NIFRA_ROUTE__";
|
|
66
|
+
/** Global the server serializes an action's data return into (absent on GETs); the client
|
|
67
|
+
* reads it so hydration after a native form POST matches the server-rendered markup. */
|
|
68
|
+
export declare const ACTION_GLOBAL = "__NIFRA_ACTION__";
|
|
69
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
70
|
+
declare const RESPONSE_RESULT: unique symbol;
|
|
71
|
+
export interface RenderedPage {
|
|
72
|
+
readonly [RESPONSE_RESULT]: true;
|
|
73
|
+
toResponse(): Response;
|
|
74
|
+
toNodeBody?(): {
|
|
75
|
+
readonly status: number;
|
|
76
|
+
readonly headers: Readonly<Record<string, string | readonly string[]>> | undefined;
|
|
77
|
+
readonly body: string | Uint8Array;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export interface RenderPageOptions {
|
|
81
|
+
readonly adapter: RenderAdapter;
|
|
82
|
+
/** The layout chain to render — outermost layout → page (opaque; the adapter renders it). */
|
|
83
|
+
readonly chain: readonly unknown[];
|
|
84
|
+
/** The loader output for this request. */
|
|
85
|
+
readonly data: unknown;
|
|
86
|
+
/** An action's data return (POST only) — surfaced to the page as `actionData` + serialized
|
|
87
|
+
* for the client so post-POST hydration matches. Omit on GETs. */
|
|
88
|
+
readonly actionData?: unknown;
|
|
89
|
+
/** URL of the built client entry (loaded as a module script). */
|
|
90
|
+
readonly clientEntry: string;
|
|
91
|
+
/** Chunk URLs for the **matched** route (its layout chain + own chunk) to `modulepreload` in the
|
|
92
|
+
* shell — so the route code downloads in parallel with the entry instead of after it
|
|
93
|
+
* (`buildClient`'s per-route map). Empty/omitted ⇒ only the entry is preloaded (unchanged). */
|
|
94
|
+
readonly preload?: readonly string[];
|
|
95
|
+
/** Stylesheet URLs for the **matched** route (its layout chain + own CSS, from `buildClient`'s
|
|
96
|
+
* `BuildManifest.css`) — injected as `<link rel="stylesheet">` in `<head>` so styles arrive with the
|
|
97
|
+
* first paint (no FOUC). Rendered even on non-hydrated pages. Empty/omitted ⇒ none (unchanged). */
|
|
98
|
+
readonly styles?: readonly string[];
|
|
99
|
+
/** SSG: the prerendered-path set, serialized to `window.__NIFRA_PRERENDERED__` so the client fetches
|
|
100
|
+
* a static `_data.json` on soft-nav into a prerendered route. Empty/omitted ⇒ not injected. */
|
|
101
|
+
readonly prerenderedPaths?: readonly string[];
|
|
102
|
+
/** ISR: route freshness in seconds, emitted as the `x-nifra-isr-revalidate` header for a `withISR`
|
|
103
|
+
* wrapper to read. Omit ⇒ no header (the wrapper's default TTL applies). */
|
|
104
|
+
readonly revalidate?: number;
|
|
105
|
+
/** Matched route id; written to `window.__NIFRA_ROUTE__` so the client hydrates this chain. */
|
|
106
|
+
readonly routeId?: string;
|
|
107
|
+
/** HTTP status for the response (default 200; e.g. 404 for a not-found page). */
|
|
108
|
+
readonly status?: number;
|
|
109
|
+
/** Document title (fallback when `head.title` is unset). */
|
|
110
|
+
readonly title?: string;
|
|
111
|
+
/** Resolved route head — `title` overrides `title` above; `meta`/`link` render as managed
|
|
112
|
+
* (`data-nifra`) tags the client updates on navigation. */
|
|
113
|
+
readonly head?: Meta;
|
|
114
|
+
/** Id of the container wrapping the app markup (default `"root"`). */
|
|
115
|
+
readonly rootId?: string;
|
|
116
|
+
/** When `false`, emit a complete but **non-hydrated** document — no client entry script, data
|
|
117
|
+
* globals, or modulepreloads. Used for server-rendered `_error` pages: a terminal state that needs no
|
|
118
|
+
* client takeover, and it sidesteps an SSR/hydrate mismatch (the server rendered the boundary, not
|
|
119
|
+
* the page the client manifest maps this route id to). Default `true`. */
|
|
120
|
+
readonly hydrate?: boolean;
|
|
121
|
+
/** Island client bundles (`@nifrajs/web/islands`) to load as `<script type="module">` in the document
|
|
122
|
+
* tail — emitted **regardless of `hydrate`**, so a static (`hydrate: false`) page can still mount
|
|
123
|
+
* no-framework islands. URLs are attribute-escaped. Empty/omitted ⇒ none (unchanged output). */
|
|
124
|
+
readonly islandScripts?: readonly string[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Server: render a full HTML document for a page — the adapter's hydration head + the SSR
|
|
128
|
+
* markup (**streamed**) + the serialized loader data + the client module — as a `Response`.
|
|
129
|
+
* The shell (`<head>` + the open container) flushes first, the adapter's app stream follows,
|
|
130
|
+
* then the tail (data globals + client entry). Pure Web Standards, so it returns straight from
|
|
131
|
+
* a nifra route handler and streams on any fetch runtime (Bun/Node/Deno/Workers).
|
|
132
|
+
*/
|
|
133
|
+
export declare function renderPage(options: RenderPageOptions): MaybePromise<Response>;
|
|
134
|
+
export declare function renderPageResult(options: RenderPageOptions): MaybePromise<RenderedPage>;
|
|
135
|
+
/** Options for {@link redirect}. */
|
|
136
|
+
export interface RedirectOptions {
|
|
137
|
+
/** HTTP status (default 303 See Other; pass 307/308 to preserve the method). */
|
|
138
|
+
readonly status?: number;
|
|
139
|
+
/** Allow an off-origin / absolute destination. Off by default: only a same-origin path (a single
|
|
140
|
+
* leading `/`) is permitted, so an action can't be turned into an open redirect by passing
|
|
141
|
+
* attacker-controlled input straight through. Set `true` for a deliberate external redirect. */
|
|
142
|
+
readonly external?: boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Build a redirect `Response` — return it from a route `action` for the Post/Redirect/Get
|
|
146
|
+
* pattern (POST mutates, 303 sends the browser to a fresh GET, so a reload doesn't re-submit).
|
|
147
|
+
* Defaults to 303 (See Other); pass `307`/`308` (or `{ status }`) to preserve the method.
|
|
148
|
+
*
|
|
149
|
+
* **Secure by default:** `location` must be a same-origin path (begins with `/`, not `//`). An
|
|
150
|
+
* off-origin/absolute destination throws unless you pass `{ external: true }` — this closes the
|
|
151
|
+
* open-redirect footgun of `return redirect(formData.get("next"))` on the no-JS (native-form) path,
|
|
152
|
+
* which returns the action's `Response` verbatim.
|
|
153
|
+
*
|
|
154
|
+
* @param statusOrOptions a status number (back-compat) or `{ status?, external? }`.
|
|
155
|
+
*/
|
|
156
|
+
export declare function redirect(location: string, statusOrOptions?: number | RedirectOptions): Response;
|
|
157
|
+
/** The wrapper `revalidate()` returns: the action's `data` plus the paths it changed. A plain tagged
|
|
158
|
+
* shape (not a class) so `@nifrajs/client`'s `ActionData` can unwrap it structurally without importing
|
|
159
|
+
* from `@nifrajs/web`. `createWebApp` strips the wrapper — the client receives `data` as the body and
|
|
160
|
+
* the paths via the `X-Nifra-Revalidate` header. */
|
|
161
|
+
export interface RevalidateResult<T> {
|
|
162
|
+
readonly __nifraRevalidate: readonly string[];
|
|
163
|
+
readonly data: T;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Return this from an action to declare which routes the mutation changed (alongside the action's
|
|
167
|
+
* `data`). `createWebApp` sets the `X-Nifra-Revalidate` response header; after the submit the client
|
|
168
|
+
* marks those cached routes stale — refetching the active one and any mounted fetcher showing them —
|
|
169
|
+
* so a mutation can refresh views beyond the one that was submitted. `data` is still surfaced to the
|
|
170
|
+
* component as `actionData` (the wrapper is transparent to `ActionData<typeof action>`).
|
|
171
|
+
*/
|
|
172
|
+
export declare function revalidate<T>(paths: readonly string[], data: T): RevalidateResult<T>;
|
|
173
|
+
/**
|
|
174
|
+
* Serialize loader data for embedding inside an inline `<script>`. `JSON.stringify` alone
|
|
175
|
+
* is NOT safe there: a string containing `</script>` or `<!--` would break out of the
|
|
176
|
+
* script element (an XSS vector). Escape `<`/`>` to `\uXXXX`, plus the U+2028/U+2029
|
|
177
|
+
* separators.
|
|
178
|
+
*/
|
|
179
|
+
export declare function serializeData(data: unknown): string;
|
|
180
|
+
/** Resolve a route's `meta` (static or a function of the loader data + params) to a {@link Meta}. */
|
|
181
|
+
export declare function resolveMeta(meta: MetaInput | undefined, args: MetaArgs): Meta;
|
|
182
|
+
export interface CreateWebAppOptions {
|
|
183
|
+
readonly adapter: RenderAdapter;
|
|
184
|
+
readonly manifest: Manifest;
|
|
185
|
+
/** URL of the built client entry (module script) injected into every page. */
|
|
186
|
+
readonly clientEntry: string;
|
|
187
|
+
/** Default document title for all pages. */
|
|
188
|
+
readonly title?: string;
|
|
189
|
+
/** Injected into each loader's `ctx.api` — typically an `inProcessClient(app)` (typed
|
|
190
|
+
* per-route via `@nifrajs/client`'s `createRoutes`). Opaque to the core. */
|
|
191
|
+
readonly api?: unknown;
|
|
192
|
+
/** Secret for **draft / preview mode** (see `enableDraft`). When set, a request carrying a valid
|
|
193
|
+
* signed `__nifra_draft` cookie gets `ctx.draft === true` in loaders/actions (else always `false`).
|
|
194
|
+
* Pair with `withISR({ draftSecret })` so editors bypass the cache. Omit to disable draft mode. */
|
|
195
|
+
readonly draftSecret?: string;
|
|
196
|
+
/** Per-route chunk URLs (`buildClient`'s `BuildManifest.routes`) — `routeId → [layout chunks…, own
|
|
197
|
+
* chunk]`. When present, each page `modulepreload`s its matched route's chunks alongside the entry,
|
|
198
|
+
* so the route code downloads in parallel (no entry→route-chunk waterfall). Omit ⇒ entry-only. */
|
|
199
|
+
readonly routePreload?: Readonly<Record<string, readonly string[]>>;
|
|
200
|
+
/** The app's bundled stylesheet URLs (`buildClient`'s `BuildManifest.css`) — the aggregate, injected
|
|
201
|
+
* as `<link rel="stylesheet">` in a page's `<head>`. Used as the fallback for any route absent from
|
|
202
|
+
* {@link routeStyles}. Omit ⇒ no links (dev, where Vite injects CSS, or a CSS-free app). */
|
|
203
|
+
readonly styles?: readonly string[];
|
|
204
|
+
/** Per-route stylesheet URLs (`buildClient`'s `BuildManifest.routeStyles`) — `routeId → [chain CSS]`.
|
|
205
|
+
* When a matched route has an entry here, only those (its layout chain + own CSS) are linked instead
|
|
206
|
+
* of the aggregate `styles`, so a page ships only the CSS it uses. An empty array ⇒ no `<link>` (the
|
|
207
|
+
* page imports no CSS). Routes absent here fall back to `styles`. Omit ⇒ always use `styles`. */
|
|
208
|
+
readonly routeStyles?: Readonly<Record<string, readonly string[]>>;
|
|
209
|
+
/** SSG: the prerendered-path set (e.g. from `enumeratePrerenderedPaths` or the build's
|
|
210
|
+
* `prerendered.json`). Injected as `window.__NIFRA_PRERENDERED__` on every page so a client soft-nav
|
|
211
|
+
* into a prerendered route fetches its static `_data.json` instead of hitting the worker. */
|
|
212
|
+
readonly prerenderedPaths?: readonly string[];
|
|
213
|
+
/** SSG: per dynamic route pattern, its `getStaticPaths` `fallback` (from `enumerateStaticRoutes` or
|
|
214
|
+
* the build's `prerendered.json`). A route mapped to `"404"` rejects any path NOT in
|
|
215
|
+
* `prerenderedPaths` with the 404 page — the unlisted path simply doesn't exist. `"ssr"` (the
|
|
216
|
+
* default for unmapped routes) renders unlisted paths on-demand. */
|
|
217
|
+
readonly staticFallbacks?: Readonly<Record<string, "ssr" | "404">>;
|
|
218
|
+
/** Observe every loader/action failure — for error-reporting plugins (Sentry-style). Called for
|
|
219
|
+
* real throws (not control-flow `Response`s like `redirect`), **before** the nearest `_error`
|
|
220
|
+
* boundary renders / a soft-nav 500 / a rethrow — so it sees errors that the boundary would
|
|
221
|
+
* otherwise hide. Observation only; its own throws are swallowed so a faulty reporter can't break
|
|
222
|
+
* rendering. (`beforeLoader` is intentionally omitted — the core HTTP hooks already cover
|
|
223
|
+
* pre-request work.) */
|
|
224
|
+
readonly onLoaderError?: (error: unknown, ctx: {
|
|
225
|
+
readonly request: Request;
|
|
226
|
+
readonly params: Readonly<Record<string, string>>;
|
|
227
|
+
readonly route: string;
|
|
228
|
+
}) => void;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Build a nifra app from a route manifest: every route SSRs its layout chain via `renderPage`,
|
|
232
|
+
* and a wildcard catch-all renders `_404` (or a plain 404). Reuses @nifrajs/core's router +
|
|
233
|
+
* lifecycle, so matching, params, and precedence are battle-tested. fs-free — feed it a
|
|
234
|
+
* manifest from `discoverRoutes` (`@nifrajs/web/fs`) at startup, so the served app stays portable.
|
|
235
|
+
*/
|
|
236
|
+
export declare function createWebApp(options: CreateWebAppOptions): Server;
|
|
237
|
+
export interface GenerateClientEntryOptions {
|
|
238
|
+
/** Module specifier for the adapter's client runtime (exports `mountRouter`), e.g.
|
|
239
|
+
* `"@nifrajs/web-solid/client"`. */
|
|
240
|
+
readonly clientModule: string;
|
|
241
|
+
/** Turn a route/layout source file (relative to the routes dir) into an import specifier. */
|
|
242
|
+
readonly resolve: (file: string) => string;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Codegen: emit a client-entry module (as source) that lazily imports each route's layout chain
|
|
246
|
+
* (so `Bun.build` with `splitting` code-splits one chunk per route), builds a `patterns` list,
|
|
247
|
+
* then creates the agnostic router store (with a `loadModule` hook), installs history + form
|
|
248
|
+
* interception, loads the initial route's chunk, and hydrates the adapter's stateful Router. The
|
|
249
|
+
* initial route is derived from the URL (falling back to the server-injected route id, e.g.
|
|
250
|
+
* `_404`), so after hydration the Router owns navigation and swaps routes without full reloads.
|
|
251
|
+
* Bun has no `import.meta.glob`, so file-based routing needs this. Write the result to a file and
|
|
252
|
+
* bundle it with `buildClient` / `Bun.build` (+ the adapter's transform).
|
|
253
|
+
*/
|
|
254
|
+
export declare function generateClientEntry(manifest: Manifest, options: GenerateClientEntryOptions): string;
|
|
255
|
+
export interface GenerateServerManifestOptions {
|
|
256
|
+
/** Turn a route/layout source file (relative to the routes dir) into an import specifier —
|
|
257
|
+
* same contract as `generateClientEntry`'s `resolve`. */
|
|
258
|
+
readonly resolve: (file: string) => string;
|
|
259
|
+
/** The content-hashed client entry URL (from `buildClient`'s manifest), **baked** into the emitted
|
|
260
|
+
* module — a disk-less worker can't read `manifest.json` at runtime. */
|
|
261
|
+
readonly clientEntry: string;
|
|
262
|
+
/** Emit **lazy** per-route loaders (`() => import("./routes/x")`, a static specifier) instead of
|
|
263
|
+
* eager `import * as`, so a bundler with code-splitting emits one chunk per route — loaded on the
|
|
264
|
+
* first request to it, not all at boot (smaller cold-start parse). Default `false` (eager). Both
|
|
265
|
+
* modes are fs-free with statically-analyzable specifiers; only the *when* differs. */
|
|
266
|
+
readonly lazy?: boolean;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Codegen: emit a **server manifest** module (as source) for disk-less edge runtimes (Cloudflare
|
|
270
|
+
* Workers, …) — and, with a `target`, any portable server bundle. `discoverRoutes` scans `node:fs`
|
|
271
|
+
* and dynamic-imports each route by a *runtime* path — neither exists on workerd. This instead emits
|
|
272
|
+
* **statically-analyzable** imports of every route/layout/`_error`/`_404` (so the bundler includes them) and
|
|
273
|
+
* rebuilds the manifest with `buildManifest` — the SAME pure logic `discoverRoutes` feeds, so patterns
|
|
274
|
+
* + layout chains are identical. Eager (`import * as`) by default; `lazy` emits `() => import(...)` so
|
|
275
|
+
* a code-splitting bundler chunks per route. The emitted module exports `manifest` (consumed by
|
|
276
|
+
* `createWebApp`, unchanged) + `clientEntry` (baked). Write it to a file and bundle it into the worker
|
|
277
|
+
* entry (see `buildServer` in `@nifrajs/web/build`).
|
|
278
|
+
*/
|
|
279
|
+
export declare function generateServerManifest(manifest: Manifest, options: GenerateServerManifestOptions): string;
|
|
280
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,MAAM,EAAU,MAAM,eAAe,CAAA;AACnD,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,EAIN,MAAM,eAAe,CAAA;AAGtB,OAAO,KAAK,EAAe,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAc,MAAM,eAAe,CAAA;AACjG,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,aAAa,CAAA;AAGpB,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,YAAY,EACZ,KAAK,kBAAkB,EACvB,WAAW,EACX,cAAc,GACf,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,QAAQ,EACR,WAAW,GACZ,MAAM,YAAY,CAAA;AAGnB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,qBAAqB,EACrB,iBAAiB,EACjB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,OAAO,GACR,MAAM,UAAU,CAAA;AAGjB,OAAO,EACL,KAAK,MAAM,EACX,aAAa,EACb,yBAAyB,EACzB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAA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