@teyik0/furin 0.2.0-alpha.2 → 0.2.0-alpha.3
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 -21
- package/README.md +33 -33
- package/dist/adapter/bun.d.ts +3 -0
- package/dist/adapter/static.d.ts +3 -0
- package/dist/build/client.d.ts +25 -0
- package/dist/build/compile-entry.d.ts +9 -0
- package/dist/build/compile-entry.ts +109 -0
- package/dist/build/entry-template.d.ts +38 -0
- package/dist/build/entry-template.ts +156 -0
- package/dist/build/hydrate.d.ts +24 -0
- package/dist/build/index.d.ts +8 -0
- package/dist/build/index.js +8106 -0
- package/dist/build/route-types.d.ts +23 -0
- package/dist/build/scan-server.d.ts +8 -0
- package/dist/build/server-routes-entry.d.ts +13 -0
- package/dist/build/server-routes-entry.ts +36 -0
- package/dist/build/shared.d.ts +12 -0
- package/dist/build/ssg-cache.d.ts +4 -0
- package/dist/build/types.d.ts +80 -0
- package/dist/cli/config.d.ts +9 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +8097 -0
- package/dist/client/boundaries.d.ts +117 -0
- package/dist/client/default-screens.d.ts +17 -0
- package/dist/client/link.d.ts +22 -0
- package/dist/client/link.js +4244 -0
- package/dist/client/router/boundary-tree.d.ts +26 -0
- package/dist/client/router/context.d.ts +8 -0
- package/dist/client/router/history.d.ts +9 -0
- package/dist/client/router/index.d.ts +11 -0
- package/dist/client/router/link-utils.d.ts +53 -0
- package/dist/client/router/navigation.d.ts +10 -0
- package/dist/client/router/provider.d.ts +4 -0
- package/dist/client/router/search/index.d.ts +18 -0
- package/dist/client/router/search-store.d.ts +21 -0
- package/dist/client/router/spa-response.d.ts +58 -0
- package/dist/client/router/types.d.ts +292 -0
- package/dist/client/server-error.d.ts +12 -0
- package/dist/client/sync.d.ts +25 -0
- package/dist/client.d.ts +243 -0
- package/dist/client.js +140 -0
- package/dist/config.d.ts +57 -0
- package/dist/config.js +29 -0
- package/dist/env.d.ts +50 -0
- package/dist/furin.d.ts +77 -0
- package/dist/furin.js +8693 -0
- package/dist/plugin/index.d.ts +20 -0
- package/dist/plugin/index.js +1500 -0
- package/dist/plugin/transform-client.d.ts +10 -0
- package/dist/server/auto-invalidate/index.d.ts +4 -0
- package/dist/server/auto-invalidate/plugin.d.ts +38 -0
- package/dist/server/auto-invalidate/registry.d.ts +9 -0
- package/dist/server/auto-invalidate/runtime.d.ts +9 -0
- package/dist/server/auto-invalidate/types.d.ts +12 -0
- package/dist/server/cache/dev-loader.d.ts +28 -0
- package/dist/server/cache/index.d.ts +10 -0
- package/dist/server/cache/invalidation.d.ts +12 -0
- package/dist/server/cache/isr-ssg.d.ts +26 -0
- package/dist/server/cache/isr.d.ts +6 -0
- package/dist/server/cache/registry.d.ts +5 -0
- package/dist/server/cache/route-cache.d.ts +26 -0
- package/dist/server/cache/ssg.d.ts +5 -0
- package/dist/server/context-logger.d.ts +28 -0
- package/dist/server/dev-inspector.d.ts +89 -0
- package/dist/server/dev-page-plugin.d.ts +112 -0
- package/dist/server/internal.d.ts +35 -0
- package/dist/server/internal.js +17 -0
- package/dist/server/lang-detect.d.ts +5 -0
- package/dist/server/render/assemble.d.ts +49 -0
- package/dist/server/render/element.d.ts +24 -0
- package/dist/server/render/index.d.ts +7 -0
- package/dist/server/render/index.ts +22 -0
- package/dist/server/render/isr.d.ts +4 -0
- package/dist/server/render/loaders.d.ts +64 -0
- package/dist/server/render/not-found.d.ts +6 -0
- package/dist/server/render/shell.d.ts +39 -0
- package/dist/server/render/shell.ts +202 -0
- package/dist/server/render/ssg.d.ts +9 -0
- package/dist/server/render/ssr.d.ts +108 -0
- package/dist/server/render/template.d.ts +6 -0
- package/dist/server/router/discovery.d.ts +16 -0
- package/dist/server/router/hmr.d.ts +65 -0
- package/dist/server/router/index.d.ts +6 -0
- package/dist/server/router/index.js +27 -0
- package/dist/server/router/index.ts +28 -0
- package/dist/server/router/patterns.d.ts +40 -0
- package/dist/server/router/plugin.d.ts +21 -0
- package/dist/server/router/schemas.d.ts +59 -0
- package/dist/server/router/types.d.ts +60 -0
- package/dist/server/runtime-env.d.ts +3 -0
- package/dist/server/runtime-env.js +10 -0
- package/dist/server/sync/config.d.ts +6 -0
- package/dist/server/sync/index.d.ts +4 -0
- package/dist/server/sync/plugin.d.ts +369 -0
- package/dist/server/sync/stream.d.ts +47 -0
- package/dist/shared/await.d.ts +67 -0
- package/dist/shared/deferred-ndjson.d.ts +32 -0
- package/dist/shared/digest.d.ts +16 -0
- package/dist/shared/error.d.ts +37 -0
- package/dist/shared/not-found.d.ts +19 -0
- package/dist/shared/search-params.d.ts +17 -0
- package/dist/shared/utils/ast-walk.d.ts +18 -0
- package/dist/shared/utils/index.d.ts +13 -0
- package/package.json +5 -5
- package/src/adapter/README.md +13 -13
- package/src/build/client.ts +152 -152
- package/src/build/compile-entry.ts +109 -109
- package/src/build/entry-template.ts +156 -156
- package/src/build/hydrate.ts +340 -337
- package/src/build/index.ts +152 -152
- package/src/build/route-types.ts +145 -145
- package/src/build/scan-server.ts +95 -95
- package/src/build/server-routes-entry.ts +36 -36
- package/src/build/shared.ts +80 -79
- package/src/build/ssg-cache.ts +32 -32
- package/src/build/types.ts +89 -89
- package/src/client/router/link-utils.ts +184 -177
- package/src/client/router/provider.tsx +804 -759
- package/src/client/router/types.ts +276 -271
- package/src/client/sync.ts +98 -0
- package/src/client.ts +369 -355
- package/src/furin.ts +465 -444
- package/src/server/auto-invalidate/runtime.ts +134 -133
- package/src/server/dev-page-plugin.ts +454 -449
- package/src/server/render/assemble.ts +160 -133
- package/src/server/render/isr.ts +323 -317
- package/src/server/render/ssr.ts +585 -583
- package/src/server/router/plugin.ts +384 -384
- package/src/server/sync/config.ts +29 -0
- package/src/server/sync/index.ts +14 -0
- package/src/server/sync/plugin.ts +108 -0
- package/src/server/sync/stream.ts +144 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Context } from "elysia";
|
|
2
|
+
import { type FurinNotFoundError } from "../../shared/not-found.ts";
|
|
3
|
+
import type { ResolvedRoute } from "../router/index.ts";
|
|
4
|
+
export type LoaderResult = {
|
|
5
|
+
type: "data";
|
|
6
|
+
/**
|
|
7
|
+
* Synchronous (JSON-serialisable) loader fields. Injected into the initial
|
|
8
|
+
* HTML shell as `__FURIN_DATA__` / the deferred registry's `_data` object.
|
|
9
|
+
*/
|
|
10
|
+
syncData: Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Promise-valued fields from a `defer()` return. `undefined` when the page
|
|
13
|
+
* loader did not call `defer()`. Streamed as late `<script>` resolution
|
|
14
|
+
* chunks (SSR) or as NDJSON chunks via `/_furin/data` (SPA nav).
|
|
15
|
+
*/
|
|
16
|
+
deferredPromises: Record<string, Promise<unknown>> | undefined;
|
|
17
|
+
headers: Record<string, string>;
|
|
18
|
+
} | {
|
|
19
|
+
type: "redirect";
|
|
20
|
+
response: Response;
|
|
21
|
+
} | {
|
|
22
|
+
type: "not-found";
|
|
23
|
+
error: FurinNotFoundError;
|
|
24
|
+
headers: Record<string, string>;
|
|
25
|
+
} | {
|
|
26
|
+
type: "error";
|
|
27
|
+
/**
|
|
28
|
+
* Original thrown value, kept for digest computation and server logging.
|
|
29
|
+
* For thrown `Response` objects this is the Response instance whose body
|
|
30
|
+
* has already been consumed by `runLoaders` (do NOT read it again).
|
|
31
|
+
*/
|
|
32
|
+
error: unknown;
|
|
33
|
+
/** HTTP status to return. Default 500; sourced from `Response.status` for thrown Response objects. */
|
|
34
|
+
status: number;
|
|
35
|
+
/**
|
|
36
|
+
* Safe public message extracted at the loader boundary. For thrown
|
|
37
|
+
* `Response` objects: response body or `statusText`. For thrown `Error`
|
|
38
|
+
* / non-Error values: a generic "Something went wrong" string (the raw
|
|
39
|
+
* error/message is never leaked here — `errorMessageOf` decides what to
|
|
40
|
+
* surface from the original `error` value when an `error.tsx` fallback
|
|
41
|
+
* exists).
|
|
42
|
+
*/
|
|
43
|
+
message: string;
|
|
44
|
+
headers: Record<string, string>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Normalises an error thrown inside a deferred Promise into a value that is
|
|
48
|
+
* safe to send through `toCrossJSON` and that preserves the original semantics
|
|
49
|
+
* after `fromCrossJSON` on the client.
|
|
50
|
+
*
|
|
51
|
+
* Symmetric to the rejection handling in `runLoaders` (lines 247-272) but for
|
|
52
|
+
* the *deferred* path, where the rejection is delivered to a client-side
|
|
53
|
+
* `<Await>` instead of becoming a top-level response.
|
|
54
|
+
*
|
|
55
|
+
* - `notFound()` → `Error` carrying `__furinBrand` + `data` so the
|
|
56
|
+
* client-side `isNotFoundError()` (duck-typed)
|
|
57
|
+
* recognises the rejection.
|
|
58
|
+
* - `Response(status, body)` → `Error` carrying `__furinStatus` and the
|
|
59
|
+
* body/statusText as `message`.
|
|
60
|
+
* - `Error` → returned unchanged.
|
|
61
|
+
* - anything else → wrapped in `new Error(String(value))`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function serializeDeferredRejection(err: unknown): Promise<unknown>;
|
|
64
|
+
export declare function runLoaders(route: ResolvedRoute, ctx: Context): Promise<LoaderResult>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RootLayout } from "../router/index.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Renders the root-level not-found component into a complete 404 HTML Response.
|
|
4
|
+
* Used by the Elysia `.onError` catch-all when no route matches the request URL.
|
|
5
|
+
*/
|
|
6
|
+
export declare function renderRootNotFound(root: RootLayout, request: Request | undefined): Promise<Response>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { HeadOptions, MetaDescriptor } from "../../client.ts";
|
|
2
|
+
export declare function extractTitle(meta?: MetaDescriptor[]): string | undefined;
|
|
3
|
+
export declare function isMetaTag(entry: MetaDescriptor): boolean;
|
|
4
|
+
export declare function escapeHtml(str: string): string;
|
|
5
|
+
export declare function safeJson(value: unknown): string;
|
|
6
|
+
export declare function renderAttrs(obj: Record<string, string | undefined>): string;
|
|
7
|
+
export declare function buildMetaParts(meta: MetaDescriptor[]): string[];
|
|
8
|
+
export declare function buildLinkParts(links: NonNullable<HeadOptions["links"]>): string[];
|
|
9
|
+
export declare function buildScriptParts(scripts: NonNullable<HeadOptions["scripts"]>): string[];
|
|
10
|
+
export declare function buildStyleParts(styles: NonNullable<HeadOptions["styles"]>): string[];
|
|
11
|
+
/**
|
|
12
|
+
* Builds the string to inject into the <!--ssr-head--> placeholder.
|
|
13
|
+
* Handles title, meta tags, links, inline scripts, and inline styles from
|
|
14
|
+
* the page's `head()` function. CSS is handled by Bun (imported in user files).
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildHeadInjection(headData: HeadOptions | undefined): string;
|
|
17
|
+
export declare function generateIndexHtml(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Generates the production SSR template (index.html) with hashed asset paths.
|
|
20
|
+
* Called after Bun.build() completes so we can inject the correct entry chunk
|
|
21
|
+
* and CSS paths derived from result.outputs.
|
|
22
|
+
*
|
|
23
|
+
* @param entryChunk - Hashed URL of the client entry script.
|
|
24
|
+
* @param cssChunks - Hashed URLs of the CSS chunks to inject as `<link>`s.
|
|
25
|
+
* @param buildId - Short hash identifying this specific build (or `undefined`
|
|
26
|
+
* for static exports where stale-deploy detection is not applicable).
|
|
27
|
+
* Injected as a `<meta name="furin-build-id">` tag so the client can
|
|
28
|
+
* detect stale deploys.
|
|
29
|
+
* @param faviconHref - Absolute href for the favicon (e.g. "/furin/favicon.ico"),
|
|
30
|
+
* or `undefined` when no favicon is provided. When set, a `<link rel="icon">`
|
|
31
|
+
* tag is injected so browsers can locate the favicon even when the site is
|
|
32
|
+
* served from a sub-path.
|
|
33
|
+
* @param staticMode - `true` for static exports, `false` for SSR/ISR. When
|
|
34
|
+
* `true`, a `<meta name="furin-mode" content="static">` tag is injected so
|
|
35
|
+
* the SPA client knows to fetch loader data from the per-route
|
|
36
|
+
* `__furin_data.ndjson` file instead of the runtime `/_furin/data` endpoint
|
|
37
|
+
* (which doesn't exist on a static host).
|
|
38
|
+
*/
|
|
39
|
+
export declare function generateProdIndexHtml(entryChunk: string, cssChunks: string[], buildId: string | undefined, faviconHref: string | undefined, staticMode: boolean): string;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { HeadOptions, MetaDescriptor } from "../../client.ts";
|
|
2
|
+
|
|
3
|
+
export function extractTitle(meta?: MetaDescriptor[]): string | undefined {
|
|
4
|
+
if (!meta) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
for (const entry of meta) {
|
|
8
|
+
if ("title" in entry) {
|
|
9
|
+
return (entry as { title: string }).title;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isMetaTag(entry: MetaDescriptor): boolean {
|
|
16
|
+
return !(
|
|
17
|
+
"title" in entry ||
|
|
18
|
+
"charSet" in entry ||
|
|
19
|
+
"script:ld+json" in entry ||
|
|
20
|
+
"tagName" in entry
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function escapeHtml(str: string): string {
|
|
25
|
+
return str
|
|
26
|
+
.replace(/&/g, "&")
|
|
27
|
+
.replace(/</g, "<")
|
|
28
|
+
.replace(/>/g, ">")
|
|
29
|
+
.replace(/"/g, """)
|
|
30
|
+
.replace(/'/g, "'");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function safeJson(value: unknown): string {
|
|
34
|
+
return JSON.stringify(value)
|
|
35
|
+
.replace(/</g, "\\u003c")
|
|
36
|
+
.replace(/>/g, "\\u003e")
|
|
37
|
+
.replace(/\u2028/g, "\\u2028")
|
|
38
|
+
.replace(/\u2029/g, "\\u2029");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function renderAttrs(obj: Record<string, string | undefined>): string {
|
|
42
|
+
const parts: string[] = [];
|
|
43
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
44
|
+
if (v !== undefined) {
|
|
45
|
+
parts.push(`${k}="${escapeHtml(String(v))}"`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return parts.join(" ");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Head injection helpers
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
export function buildMetaParts(meta: MetaDescriptor[]): string[] {
|
|
56
|
+
const parts: string[] = [];
|
|
57
|
+
const title = extractTitle(meta);
|
|
58
|
+
if (title) {
|
|
59
|
+
parts.push(`<title>${escapeHtml(title)}</title>`);
|
|
60
|
+
}
|
|
61
|
+
for (const m of meta) {
|
|
62
|
+
if (isMetaTag(m)) {
|
|
63
|
+
parts.push(`<meta ${renderAttrs(m as Record<string, string>)} />`);
|
|
64
|
+
}
|
|
65
|
+
if ("script:ld+json" in m) {
|
|
66
|
+
parts.push(`<script type="application/ld+json">${safeJson(m["script:ld+json"])}</script>`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return parts;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function buildLinkParts(links: NonNullable<HeadOptions["links"]>): string[] {
|
|
73
|
+
return links.map((link) => `<link ${renderAttrs(link)} />`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function buildScriptParts(scripts: NonNullable<HeadOptions["scripts"]>): string[] {
|
|
77
|
+
return scripts.map((script) => {
|
|
78
|
+
const { children, ...rest } = script;
|
|
79
|
+
const attrs = renderAttrs(rest as Record<string, string | undefined>);
|
|
80
|
+
if (children) {
|
|
81
|
+
return `<script ${attrs}>${children}</script>`;
|
|
82
|
+
}
|
|
83
|
+
return `<script ${attrs}></script>`;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function buildStyleParts(styles: NonNullable<HeadOptions["styles"]>): string[] {
|
|
88
|
+
return styles.map((style) => {
|
|
89
|
+
const typeAttr = style.type ? ` type="${escapeHtml(style.type)}"` : "";
|
|
90
|
+
return `<style${typeAttr}>${style.children}</style>`;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Builds the string to inject into the <!--ssr-head--> placeholder.
|
|
96
|
+
* Handles title, meta tags, links, inline scripts, and inline styles from
|
|
97
|
+
* the page's `head()` function. CSS is handled by Bun (imported in user files).
|
|
98
|
+
*/
|
|
99
|
+
export function buildHeadInjection(headData: HeadOptions | undefined): string {
|
|
100
|
+
const parts: string[] = [];
|
|
101
|
+
|
|
102
|
+
if (headData?.meta) {
|
|
103
|
+
parts.push(...buildMetaParts(headData.meta));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (headData?.links) {
|
|
107
|
+
parts.push(...buildLinkParts(headData.links));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (headData?.scripts) {
|
|
111
|
+
parts.push(...buildScriptParts(headData.scripts));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (headData?.styles) {
|
|
115
|
+
parts.push(...buildStyleParts(headData.styles));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return parts.length > 0 ? `\n ${parts.join("\n ")}\n` : "";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Inline script that synchronously applies the persisted theme class to <html>
|
|
123
|
+
* before the first paint, preventing a flash of unstyled content (FOUC).
|
|
124
|
+
* Reads the `furin-theme` key from localStorage; defaults to "dark" on error.
|
|
125
|
+
*/
|
|
126
|
+
const THEME_INIT_SCRIPT =
|
|
127
|
+
`<script>try{var __t=localStorage.getItem("furin-theme");` +
|
|
128
|
+
`document.documentElement.classList.add(__t==="light"?"light":"dark")}` +
|
|
129
|
+
`catch(e){document.documentElement.classList.add("dark")}</script>`;
|
|
130
|
+
|
|
131
|
+
export function generateIndexHtml(): string {
|
|
132
|
+
return `<!DOCTYPE html>
|
|
133
|
+
<html lang="en">
|
|
134
|
+
<head>
|
|
135
|
+
<meta charset="UTF-8">
|
|
136
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
137
|
+
${THEME_INIT_SCRIPT}
|
|
138
|
+
<!--ssr-head-->
|
|
139
|
+
</head>
|
|
140
|
+
<body>
|
|
141
|
+
<div id="root"><!--ssr-outlet--></div>
|
|
142
|
+
<script type="module" src="./_hydrate.tsx"></script>
|
|
143
|
+
</body>
|
|
144
|
+
</html>
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Generates the production SSR template (index.html) with hashed asset paths.
|
|
150
|
+
* Called after Bun.build() completes so we can inject the correct entry chunk
|
|
151
|
+
* and CSS paths derived from result.outputs.
|
|
152
|
+
*
|
|
153
|
+
* @param entryChunk - Hashed URL of the client entry script.
|
|
154
|
+
* @param cssChunks - Hashed URLs of the CSS chunks to inject as `<link>`s.
|
|
155
|
+
* @param buildId - Short hash identifying this specific build (or `undefined`
|
|
156
|
+
* for static exports where stale-deploy detection is not applicable).
|
|
157
|
+
* Injected as a `<meta name="furin-build-id">` tag so the client can
|
|
158
|
+
* detect stale deploys.
|
|
159
|
+
* @param faviconHref - Absolute href for the favicon (e.g. "/furin/favicon.ico"),
|
|
160
|
+
* or `undefined` when no favicon is provided. When set, a `<link rel="icon">`
|
|
161
|
+
* tag is injected so browsers can locate the favicon even when the site is
|
|
162
|
+
* served from a sub-path.
|
|
163
|
+
* @param staticMode - `true` for static exports, `false` for SSR/ISR. When
|
|
164
|
+
* `true`, a `<meta name="furin-mode" content="static">` tag is injected so
|
|
165
|
+
* the SPA client knows to fetch loader data from the per-route
|
|
166
|
+
* `__furin_data.ndjson` file instead of the runtime `/_furin/data` endpoint
|
|
167
|
+
* (which doesn't exist on a static host).
|
|
168
|
+
*/
|
|
169
|
+
export function generateProdIndexHtml(
|
|
170
|
+
entryChunk: string,
|
|
171
|
+
cssChunks: string[],
|
|
172
|
+
buildId: string | undefined,
|
|
173
|
+
faviconHref: string | undefined,
|
|
174
|
+
staticMode: boolean
|
|
175
|
+
): string {
|
|
176
|
+
const cssLinks = cssChunks
|
|
177
|
+
.map((c) => ` <link rel="stylesheet" crossorigin href="${c}">`)
|
|
178
|
+
.join("\n");
|
|
179
|
+
const scriptTag = `<script type="module" crossorigin src="${entryChunk}"></script>`;
|
|
180
|
+
const buildIdMeta = buildId
|
|
181
|
+
? ` <meta name="furin-build-id" content="${escapeHtml(buildId)}">\n`
|
|
182
|
+
: "";
|
|
183
|
+
const faviconLink = faviconHref
|
|
184
|
+
? ` <link rel="icon" href="${escapeHtml(faviconHref)}">\n`
|
|
185
|
+
: "";
|
|
186
|
+
const modeMeta = staticMode ? ` <meta name="furin-mode" content="static">\n` : "";
|
|
187
|
+
|
|
188
|
+
return `<!DOCTYPE html>
|
|
189
|
+
<html lang="en">
|
|
190
|
+
<head>
|
|
191
|
+
<meta charset="UTF-8">
|
|
192
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
193
|
+
${THEME_INIT_SCRIPT}
|
|
194
|
+
${buildIdMeta}${modeMeta}${faviconLink}${cssLinks ? `${cssLinks}\n` : ""} <!--ssr-head-->
|
|
195
|
+
</head>
|
|
196
|
+
<body>
|
|
197
|
+
<div id="root"><!--ssr-outlet--></div>
|
|
198
|
+
${scriptTag}
|
|
199
|
+
</body>
|
|
200
|
+
</html>
|
|
201
|
+
`;
|
|
202
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
2
|
+
import type { SsgCacheEntry } from "../cache/isr-ssg.ts";
|
|
3
|
+
import type { ResolvedRoute, RootLayout } from "../router/index.ts";
|
|
4
|
+
export declare function prerenderSSG(route: ResolvedRoute, params: Record<string, string>, root: RootLayout, origin: string, basePath?: string, searchRoutes?: SearchRouteMetadata[]): Promise<SsgCacheEntry | Response>;
|
|
5
|
+
/**
|
|
6
|
+
* Pre-renders all SSG routes that declare `staticParams` and populates the
|
|
7
|
+
* in-memory cache before the first real request arrives.
|
|
8
|
+
*/
|
|
9
|
+
export declare function warmSSGCache(routes: ResolvedRoute[], root: RootLayout, origin: string, searchRoutes?: SearchRouteMetadata[]): Promise<void>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Context } from "elysia";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import { renderToReadableStream } from "react-dom/server";
|
|
4
|
+
import { type RouterContextValue } from "../../client/router/index.ts";
|
|
5
|
+
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
6
|
+
import type { ResolvedRoute, RootLayout } from "../router/index.ts";
|
|
7
|
+
import { buildErrorElement } from "./element.tsx";
|
|
8
|
+
import { type LoaderResult } from "./loaders.ts";
|
|
9
|
+
export type { LoaderContext } from "./assemble.ts";
|
|
10
|
+
export type { LoaderResult } from "./loaders.ts";
|
|
11
|
+
export interface RenderResult {
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
html: string;
|
|
14
|
+
/**
|
|
15
|
+
* NDJSON payload (one CrossJSON-serialised line) carrying the loader's
|
|
16
|
+
* resolved sync + deferred data. Identical in shape to the body the live
|
|
17
|
+
* `/_furin/data` endpoint emits, so the SPA client can consume both
|
|
18
|
+
* interchangeably.
|
|
19
|
+
*/
|
|
20
|
+
ndjson: string;
|
|
21
|
+
status: number;
|
|
22
|
+
}
|
|
23
|
+
export interface PreparedRender {
|
|
24
|
+
/**
|
|
25
|
+
* All props passed to the React component tree. For deferred renders this
|
|
26
|
+
* includes the Promise objects (for `<Await resolve={promise}>`) alongside
|
|
27
|
+
* the scalar sync fields. Never serialise this directly — use `syncData`.
|
|
28
|
+
*/
|
|
29
|
+
componentProps: Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Promise-valued fields from a `defer()` loader return. Undefined for normal
|
|
32
|
+
* (non-deferred) loaders. These are streamed as late `<script>` chunks after
|
|
33
|
+
* the React stream finishes.
|
|
34
|
+
*/
|
|
35
|
+
deferredPromises: Record<string, Promise<unknown>> | undefined;
|
|
36
|
+
element: ReactNode;
|
|
37
|
+
/** Set when the prepared element is an error UI. */
|
|
38
|
+
errorDigest?: string;
|
|
39
|
+
headData: string;
|
|
40
|
+
headers: Record<string, string>;
|
|
41
|
+
loader_ms: number;
|
|
42
|
+
/**
|
|
43
|
+
* Populated only when the loader threw `notFound()`. Mirrored into
|
|
44
|
+
* `__FURIN_DATA__.__furinNotFound` so the client-side can render the
|
|
45
|
+
* not-found UI inline on SPA navigation.
|
|
46
|
+
*/
|
|
47
|
+
notFoundError?: {
|
|
48
|
+
data?: unknown;
|
|
49
|
+
message?: string;
|
|
50
|
+
};
|
|
51
|
+
ssrContext: RouterContextValue;
|
|
52
|
+
status: number;
|
|
53
|
+
/**
|
|
54
|
+
* JSON-serialisable subset of `componentProps`. For deferred renders this
|
|
55
|
+
* excludes the Promise fields (those are streamed separately).
|
|
56
|
+
*/
|
|
57
|
+
syncData: Record<string, unknown>;
|
|
58
|
+
template: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function withSSRRouterContext(element: ReactNode, contextValue: RouterContextValue): ReactNode;
|
|
61
|
+
interface ShellFallbackResult {
|
|
62
|
+
/**
|
|
63
|
+
* Set when the primary element threw synchronously during render and a
|
|
64
|
+
* fallback error UI was streamed instead. Carries the digest so the caller
|
|
65
|
+
* can surface it in logs and the `__furinError` payload.
|
|
66
|
+
*/
|
|
67
|
+
shellError: {
|
|
68
|
+
digest: string;
|
|
69
|
+
} | undefined;
|
|
70
|
+
stream: Awaited<ReturnType<typeof renderToReadableStream>>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Renders `element` to a React stream, recovering from a synchronous shell
|
|
74
|
+
* throw with a 500 error UI. The supplied error component (route-level, else
|
|
75
|
+
* root-level) is tried first; if it ALSO throws, the built-in error element is
|
|
76
|
+
* used, so a broken custom error page can never take down the whole response.
|
|
77
|
+
*
|
|
78
|
+
* Shared by SSR (which pipes the stream) and ISR/SSG non-200 (which drains it
|
|
79
|
+
* to a string) — both start from this same React stream and only diverge in how
|
|
80
|
+
* they consume it and which fields they log.
|
|
81
|
+
*/
|
|
82
|
+
export declare function renderElementWithShellFallback(element: ReactNode, errorComponent: Parameters<typeof buildErrorElement>[0], ssrContext: RouterContextValue): Promise<ShellFallbackResult>;
|
|
83
|
+
/**
|
|
84
|
+
* defer() streams data progressively — it only makes sense in SSR. In SSG/ISR
|
|
85
|
+
* the HTML is pre-rendered and cached, so the deferred fields would be absent
|
|
86
|
+
* from the embedded `__FURIN_DATA__` and the client `<Await>` would hydrate
|
|
87
|
+
* with `undefined`. Fail fast at the loader boundary.
|
|
88
|
+
*/
|
|
89
|
+
export declare function assertDeferredModeAllowed(route: ResolvedRoute, deferredPromises: Record<string, Promise<unknown>> | undefined): void;
|
|
90
|
+
/**
|
|
91
|
+
* Shared pipeline steps used by both `renderToHTML` (buffered) and `renderSSR`
|
|
92
|
+
* (streaming). Runs loaders, builds props, head injection, resolves template,
|
|
93
|
+
* and creates the React element.
|
|
94
|
+
*
|
|
95
|
+
* Returns the redirect Response directly when a loader redirects, so callers
|
|
96
|
+
* never need try/catch for redirect handling.
|
|
97
|
+
*/
|
|
98
|
+
export declare function prepareRender(route: ResolvedRoute, ctx: Context, root: RootLayout, basePath: string | undefined, throwOnFailure: boolean, precomputedLoaderResult: LoaderResult | undefined, searchRoutes?: SearchRouteMetadata[]): Promise<PreparedRender | Response>;
|
|
99
|
+
export declare function renderForPath(route: ResolvedRoute, params: Record<string, string>, root: RootLayout, origin: string, mode: "ssg" | "isr", basePath?: string, searchRoutes?: SearchRouteMetadata[]): Promise<RenderResult | Response>;
|
|
100
|
+
/**
|
|
101
|
+
* Serialises a loader's `syncData` + `deferredPromises` into the same one-line
|
|
102
|
+
* NDJSON shape the live `/_furin/data` endpoint emits.
|
|
103
|
+
*/
|
|
104
|
+
export declare function serializeLoaderDataNdjson(syncData: Record<string, unknown>, deferredPromises: Record<string, Promise<unknown>> | undefined): Promise<string>;
|
|
105
|
+
export declare function renderToHTML(route: ResolvedRoute, ctx: Context, root: RootLayout, searchRoutes?: SearchRouteMetadata[]): Promise<RenderResult>;
|
|
106
|
+
export declare function renderToStream(route: ResolvedRoute, ctx: Context, root: RootLayout): Promise<ReadableStream | Response>;
|
|
107
|
+
export declare function renderSSR(route: ResolvedRoute, ctx: Context, root: RootLayout, precomputedLoaderResult: LoaderResult | undefined, searchRoutes?: SearchRouteMetadata[]): Promise<Response>;
|
|
108
|
+
export declare function splitBeforeBodyClose(bodyPost: string): [string, string];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getDevTemplate(origin: string): Promise<string>;
|
|
2
|
+
export declare function setProductionTemplatePath(path: string | null): void;
|
|
3
|
+
export declare function setProductionTemplateContent(content: string): void;
|
|
4
|
+
export declare function getProductionTemplate(): string | null;
|
|
5
|
+
/** @internal test-only — resets all template state */
|
|
6
|
+
export declare function __resetTemplateState(): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RuntimePage, RuntimeRoute } from "../../client.ts";
|
|
2
|
+
import { type CompileContext } from "../internal.ts";
|
|
3
|
+
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
4
|
+
export declare function isModuleNotFoundError(err: unknown): boolean;
|
|
5
|
+
/** @internal Exported for unit testing. */
|
|
6
|
+
export declare function collectRouteTags(routeChain: RuntimeRoute[], page: Pick<RuntimePage, "tags"> | undefined): string[] | undefined;
|
|
7
|
+
export declare function loadProdRoutes(ctx: CompileContext): {
|
|
8
|
+
root: RootLayout;
|
|
9
|
+
routes: ResolvedRoute[];
|
|
10
|
+
};
|
|
11
|
+
export declare function scanPages(pagesDir: string): Promise<{
|
|
12
|
+
root: RootLayout;
|
|
13
|
+
routes: ResolvedRoute[];
|
|
14
|
+
}>;
|
|
15
|
+
export declare function scanRootLayout(pagesDir: string): Promise<RootLayout>;
|
|
16
|
+
export declare function getSourceModuleCandidates(dir: string, name: string): string[];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Context } from "elysia";
|
|
2
|
+
import type { RuntimePage, RuntimeRoute } from "../../client.ts";
|
|
3
|
+
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
4
|
+
import { type CompileContext } from "../internal.ts";
|
|
5
|
+
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
6
|
+
type RouteModuleImport = (specifier: string) => Promise<Record<string, unknown>>;
|
|
7
|
+
export declare function importFreshRouteModuleCandidate(layoutPath: string, timestamp: number, resolveImport: RouteModuleImport, ctx: CompileContext | null): Promise<Record<string, unknown> | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* Re-imports intermediate layout _route.tsx files with cache-busting so that
|
|
10
|
+
* server-side renders reflect the latest code after an HMR edit. Bun's ESM
|
|
11
|
+
* cache keeps the original module alive, so we import via ?furin-server and
|
|
12
|
+
* patch the layout/loader references on the existing route-chain objects.
|
|
13
|
+
*
|
|
14
|
+
* The optional `importFn` parameter exists only for unit testing. In production
|
|
15
|
+
* it defaults to the real `import()`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function refreshLayoutChain(chain: RuntimeRoute[], pagePath: string, rootPath: string, importFn: ((specifier: string) => Promise<Record<string, unknown>>) | undefined): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Rebuilds a `ResolvedRoute` from freshly-imported `page` and `chain` so that
|
|
20
|
+
* `mode` reflects the CURRENT contents of the page module — not the value
|
|
21
|
+
* captured at scan time.
|
|
22
|
+
*
|
|
23
|
+
* In dev, `handleDevRequest` re-imports the page on every request to pick up
|
|
24
|
+
* source edits via the `?furin-server&t=<ts>` cache-buster. Without this
|
|
25
|
+
* function the spread `{ ...route, page, chain }` would carry over the stale
|
|
26
|
+
* `route.mode` resolved at startup, so toggling `revalidate` or removing a
|
|
27
|
+
* loader in source would not retake effect until a server restart.
|
|
28
|
+
*
|
|
29
|
+
* Only `mode` is recomputed: it is the only field DERIVED from page+chain.
|
|
30
|
+
* Structural fields (`pattern`, `path`, `segmentBoundaries`, `error`,
|
|
31
|
+
* `notFound`) are scan-time invariants in dev and are preserved as-is.
|
|
32
|
+
*/
|
|
33
|
+
export declare function rebuildDevRoute(base: ResolvedRoute, page: RuntimePage, chain: RuntimeRoute[]): ResolvedRoute;
|
|
34
|
+
/** @internal Handles a request in dev mode — re-imports the page fresh on every request. */
|
|
35
|
+
export declare function handleDevRequest(route: ResolvedRoute, ctx: Context, root: RootLayout, searchRoutes?: SearchRouteMetadata[]): Promise<unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* @internal Dev "Live ISR" — caches loader output, not assembled HTML. On a
|
|
38
|
+
* fresh cache hit the loader chain is skipped; the React render still runs so
|
|
39
|
+
* the response embeds the latest dev shell (chunk URL, HMR runtime, …). On
|
|
40
|
+
* miss, runs loaders normally and stores the merged data record.
|
|
41
|
+
*/
|
|
42
|
+
export declare function renderDevISRWithLoaderCache(route: ResolvedRoute, ctx: Context, root: RootLayout, searchRoutes?: SearchRouteMetadata[]): Promise<Response>;
|
|
43
|
+
/**
|
|
44
|
+
* @internal Dev "Live SSG" — same shape as `renderDevISRWithLoaderCache`, but
|
|
45
|
+
* the cached entry is tagged forever-fresh (`revalidate: Infinity`) so it
|
|
46
|
+
* survives indefinitely until source-aware invalidation drops it. This makes
|
|
47
|
+
* dev SSG behave like production SSG: the loader runs ONCE per cache key,
|
|
48
|
+
* not on every refresh.
|
|
49
|
+
*/
|
|
50
|
+
export declare function renderDevSSGWithLoaderCache(route: ResolvedRoute, ctx: Context, root: RootLayout, searchRoutes?: SearchRouteMetadata[]): Promise<Response>;
|
|
51
|
+
/**
|
|
52
|
+
* @internal Lists every source file whose contents can affect the render
|
|
53
|
+
* output for a given page: the page itself, every intermediate `_route.*`
|
|
54
|
+
* between the page and the pages root, and `root.tsx`.
|
|
55
|
+
*
|
|
56
|
+
* Only paths that EXIST on disk are returned. `isDevLoaderCacheValid` treats
|
|
57
|
+
* a `statSync` throw as "invalid" (conservative on missing files), so listing
|
|
58
|
+
* non-authored extension candidates here would force a permanent cache MISS
|
|
59
|
+
* for every nested route — silently disabling the dev ISR/SSG cache for any
|
|
60
|
+
* page in a subdirectory. Renames and deletions of TRACKED deps are still
|
|
61
|
+
* detected: the path that previously existed will then `statSync`-throw on
|
|
62
|
+
* the next read and yield the same conservative miss.
|
|
63
|
+
*/
|
|
64
|
+
export declare function computeRouteDependencies(pagePath: string, rootPath: string): string[];
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { collectRouteTags, loadProdRoutes, scanPages, scanRootLayout } from "./discovery.ts";
|
|
2
|
+
export { computeRouteDependencies, importFreshRouteModuleCandidate, rebuildDevRoute, refreshLayoutChain, renderDevISRWithLoaderCache, renderDevSSGWithLoaderCache, } from "./hmr.ts";
|
|
3
|
+
export { buildRouteMatcher, buildRouteRegex, collectIntermediateLayoutDirs, compareRouteSpecificity, compareRouteSpecificity as routeSpecificity, escapeRegExpChar, filePathToPattern, resolveMode, } from "./patterns.ts";
|
|
4
|
+
export { createDataEndpoint, createRoutePlugin } from "./plugin.ts";
|
|
5
|
+
export { applySchemaDefaults, createSearchRouteMetadata, mergeRouteSchemas, parseDataEndpointPath, } from "./schemas.ts";
|
|
6
|
+
export type { ResolvedRoute, RootLayout, SegmentBoundary } from "./types.ts";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
export {
|
|
3
|
+
scanRootLayout,
|
|
4
|
+
scanPages,
|
|
5
|
+
compareRouteSpecificity2 as routeSpecificity,
|
|
6
|
+
resolveMode,
|
|
7
|
+
renderDevSSGWithLoaderCache,
|
|
8
|
+
renderDevISRWithLoaderCache,
|
|
9
|
+
refreshLayoutChain,
|
|
10
|
+
rebuildDevRoute,
|
|
11
|
+
parseDataEndpointPath,
|
|
12
|
+
mergeRouteSchemas,
|
|
13
|
+
loadProdRoutes,
|
|
14
|
+
importFreshRouteModuleCandidate,
|
|
15
|
+
filePathToPattern,
|
|
16
|
+
escapeRegExpChar,
|
|
17
|
+
createSearchRouteMetadata,
|
|
18
|
+
createRoutePlugin,
|
|
19
|
+
createDataEndpoint,
|
|
20
|
+
computeRouteDependencies,
|
|
21
|
+
compareRouteSpecificity,
|
|
22
|
+
collectRouteTags,
|
|
23
|
+
collectIntermediateLayoutDirs,
|
|
24
|
+
buildRouteRegex,
|
|
25
|
+
buildRouteMatcher,
|
|
26
|
+
applySchemaDefaults
|
|
27
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// biome-ignore-all lint/performance/noBarrelFile: server/router barrel is the public surface of the routing module
|
|
2
|
+
export { collectRouteTags, loadProdRoutes, scanPages, scanRootLayout } from "./discovery.ts";
|
|
3
|
+
export {
|
|
4
|
+
computeRouteDependencies,
|
|
5
|
+
importFreshRouteModuleCandidate,
|
|
6
|
+
rebuildDevRoute,
|
|
7
|
+
refreshLayoutChain,
|
|
8
|
+
renderDevISRWithLoaderCache,
|
|
9
|
+
renderDevSSGWithLoaderCache,
|
|
10
|
+
} from "./hmr.ts";
|
|
11
|
+
export {
|
|
12
|
+
buildRouteMatcher,
|
|
13
|
+
buildRouteRegex,
|
|
14
|
+
collectIntermediateLayoutDirs,
|
|
15
|
+
compareRouteSpecificity,
|
|
16
|
+
compareRouteSpecificity as routeSpecificity,
|
|
17
|
+
escapeRegExpChar,
|
|
18
|
+
filePathToPattern,
|
|
19
|
+
resolveMode,
|
|
20
|
+
} from "./patterns.ts";
|
|
21
|
+
export { createDataEndpoint, createRoutePlugin } from "./plugin.ts";
|
|
22
|
+
export {
|
|
23
|
+
applySchemaDefaults,
|
|
24
|
+
createSearchRouteMetadata,
|
|
25
|
+
mergeRouteSchemas,
|
|
26
|
+
parseDataEndpointPath,
|
|
27
|
+
} from "./schemas.ts";
|
|
28
|
+
export type { ResolvedRoute, RootLayout, SegmentBoundary } from "./types.ts";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { RuntimePage, RuntimeRoute } from "../../client.ts";
|
|
2
|
+
export declare function collectIntermediateLayoutDirs(pagePath: string, rootPath: string): string[];
|
|
3
|
+
export declare function resolveMode(page: RuntimePage, routeChain: RuntimeRoute[]): "ssr" | "ssg" | "isr";
|
|
4
|
+
export declare function filePathToPattern(path: string): string;
|
|
5
|
+
export declare function escapeRegExpChar(ch: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Compares two route patterns by specificity so the `/_furin/data` matcher can
|
|
8
|
+
* prefer the more specific of two siblings that both match a pathname.
|
|
9
|
+
*
|
|
10
|
+
* Patterns are compared segment by segment from the left; the first position
|
|
11
|
+
* where they differ decides (literal > `:param` > `*`). When every shared
|
|
12
|
+
* position ties, the pattern with more explicit segments wins over a shorter
|
|
13
|
+
* one whose wildcard absorbs the tail.
|
|
14
|
+
*
|
|
15
|
+
* Returns a positive number when `a` is MORE specific than `b`, negative when
|
|
16
|
+
* less, and `0` only when the two are indistinguishable. This lexicographic
|
|
17
|
+
* ranking replaces the previous summed-weight score, which produced ties such
|
|
18
|
+
* as `/blog/new/:section` vs `/blog/:id/edit` (both summed to 8) that resolved
|
|
19
|
+
* non-deterministically by scan order.
|
|
20
|
+
*/
|
|
21
|
+
export declare function compareRouteSpecificity(a: string, b: string): number;
|
|
22
|
+
/**
|
|
23
|
+
* Builds a regex from a route pattern, extracts named capture groups for
|
|
24
|
+
* each `:param` segment, and returns `{ regex, paramNames }`.
|
|
25
|
+
*
|
|
26
|
+
* Literal characters (e.g. dots in filenames like `v1.0`) are escaped so
|
|
27
|
+
* they are matched exactly rather than interpreted as regex syntax.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildRouteRegex(pattern: string): {
|
|
30
|
+
regex: RegExp;
|
|
31
|
+
paramNames: string[];
|
|
32
|
+
};
|
|
33
|
+
export interface RoutePatternLike {
|
|
34
|
+
pattern: string;
|
|
35
|
+
}
|
|
36
|
+
export interface RouteMatch<TRoute extends RoutePatternLike> {
|
|
37
|
+
params: Record<string, string>;
|
|
38
|
+
route: TRoute;
|
|
39
|
+
}
|
|
40
|
+
export declare function buildRouteMatcher<TRoute extends RoutePatternLike>(routes: TRoute[]): (pathname: string) => RouteMatch<TRoute> | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type AnyElysia } from "elysia";
|
|
2
|
+
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
3
|
+
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
4
|
+
export declare function createRoutePlugin(route: ResolvedRoute, root: RootLayout, buildId?: string, searchRoutes?: SearchRouteMetadata[]): AnyElysia;
|
|
5
|
+
/**
|
|
6
|
+
* Elysia plugin that handles `GET /_furin/data?path=<logicalHref>`.
|
|
7
|
+
*
|
|
8
|
+
* Returns an NDJSON stream (one-line, v1) produced by `toCrossJSONAsync`:
|
|
9
|
+
* Line 0 — CrossJSON serialisation of `{ ...syncData, ...deferredPromises }`
|
|
10
|
+
*
|
|
11
|
+
* The `deferredPromises` values are awaited by `toCrossJSONAsync` before
|
|
12
|
+
* serialising, so the client receives all data resolved in one round-trip.
|
|
13
|
+
* SPA navigation calls this endpoint via `parseDeferredNdjson` in
|
|
14
|
+
* `router-provider.tsx`.
|
|
15
|
+
*
|
|
16
|
+
* Special fields emitted alongside data:
|
|
17
|
+
* - `__furinStatus: 404` — when the loader called `notFound()`
|
|
18
|
+
* - `__furinNotFound` — not-found payload
|
|
19
|
+
* - `__furinRedirect` — logical path after a server-side redirect
|
|
20
|
+
*/
|
|
21
|
+
export declare function createDataEndpoint(routes: ResolvedRoute[]): AnyElysia;
|