@teyik0/furin 0.1.0-alpha.13 → 0.1.0-alpha.15
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 +14 -232
- package/dist/auto-invalidate/index.d.ts +4 -0
- package/dist/auto-invalidate/plugin.d.ts +38 -0
- package/dist/auto-invalidate/registry.d.ts +9 -0
- package/dist/auto-invalidate/runtime.d.ts +9 -0
- package/dist/auto-invalidate/types.d.ts +12 -0
- package/dist/await.d.ts +67 -0
- package/dist/build/index.js +2095 -185
- package/dist/cli/index.js +2070 -182
- package/dist/client.d.ts +51 -4
- package/dist/client.js +65 -1
- package/dist/deferred-ndjson.d.ts +32 -0
- package/dist/error.d.ts +14 -0
- package/dist/furin.d.ts +8 -0
- package/dist/furin.js +2927 -319
- package/dist/lang-detect.d.ts +5 -0
- package/dist/link.d.ts +1 -0
- package/dist/link.js +1453 -95
- package/dist/plugin/index.js +96 -25
- package/dist/plugin/transform-client.d.ts +2 -1
- package/dist/render/assemble.d.ts +32 -0
- package/dist/render/cache.d.ts +7 -0
- package/dist/render/element.d.ts +17 -1
- package/dist/render/index.d.ts +10 -1
- package/dist/render/index.ts +250 -44
- package/dist/render/loaders.d.ts +46 -3
- package/dist/render/shell.d.ts +16 -6
- package/dist/render/shell.ts +27 -12
- package/dist/router-provider.d.ts +86 -18
- package/dist/router.d.ts +66 -0
- package/dist/router.js +2909 -374
- package/dist/router.ts +586 -54
- package/dist/server-error.d.ts +12 -0
- package/dist/utils.d.ts +7 -0
- package/package.json +8 -7
- package/src/adapter/bun.ts +3 -3
- package/src/adapter/static.ts +73 -31
- package/src/auto-invalidate/index.ts +10 -0
- package/src/auto-invalidate/plugin.ts +25 -0
- package/src/auto-invalidate/registry.ts +60 -0
- package/src/auto-invalidate/runtime.ts +133 -0
- package/src/auto-invalidate/types.ts +16 -0
- package/src/await.tsx +175 -0
- package/src/build/client.ts +4 -8
- package/src/build/hydrate.ts +67 -1
- package/src/build/route-types.ts +29 -3
- package/src/build/scan-server.ts +6 -23
- package/src/client.ts +80 -3
- package/src/deferred-ndjson.ts +212 -0
- package/src/dev-page-plugin.ts +2 -0
- package/src/error.ts +18 -1
- package/src/furin.ts +19 -2
- package/src/lang-detect.ts +46 -0
- package/src/link.tsx +16 -3
- package/src/plugin/index.ts +7 -8
- package/src/plugin/transform-client.ts +108 -39
- package/src/render/assemble.ts +67 -0
- package/src/render/boundaries.tsx +23 -5
- package/src/render/cache.ts +14 -0
- package/src/render/default-screens.tsx +4 -11
- package/src/render/dev-cache.ts +5 -0
- package/src/render/element.tsx +26 -3
- package/src/render/index.ts +250 -44
- package/src/render/loaders.ts +219 -18
- package/src/render/shell.ts +27 -12
- package/src/router-provider.tsx +414 -122
- package/src/router.ts +586 -54
- package/src/server-error.ts +47 -0
- package/src/utils.ts +31 -0
package/dist/render/shell.ts
CHANGED
|
@@ -39,10 +39,13 @@ export function safeJson(value: unknown): string {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function renderAttrs(obj: Record<string, string | undefined>): string {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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(" ");
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
// ---------------------------------------------------------------------------
|
|
@@ -147,17 +150,28 @@ export function generateIndexHtml(): string {
|
|
|
147
150
|
* Called after Bun.build() completes so we can inject the correct entry chunk
|
|
148
151
|
* and CSS paths derived from result.outputs.
|
|
149
152
|
*
|
|
150
|
-
* @param
|
|
151
|
-
*
|
|
152
|
-
* @param
|
|
153
|
-
*
|
|
154
|
-
*
|
|
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).
|
|
155
168
|
*/
|
|
156
169
|
export function generateProdIndexHtml(
|
|
157
170
|
entryChunk: string,
|
|
158
171
|
cssChunks: string[],
|
|
159
|
-
buildId
|
|
160
|
-
faviconHref
|
|
172
|
+
buildId: string | undefined,
|
|
173
|
+
faviconHref: string | undefined,
|
|
174
|
+
staticMode: boolean
|
|
161
175
|
): string {
|
|
162
176
|
const cssLinks = cssChunks
|
|
163
177
|
.map((c) => ` <link rel="stylesheet" crossorigin href="${c}">`)
|
|
@@ -169,6 +183,7 @@ export function generateProdIndexHtml(
|
|
|
169
183
|
const faviconLink = faviconHref
|
|
170
184
|
? ` <link rel="icon" href="${escapeHtml(faviconHref)}">\n`
|
|
171
185
|
: "";
|
|
186
|
+
const modeMeta = staticMode ? ` <meta name="furin-mode" content="static">\n` : "";
|
|
172
187
|
|
|
173
188
|
return `<!DOCTYPE html>
|
|
174
189
|
<html lang="en">
|
|
@@ -176,7 +191,7 @@ export function generateProdIndexHtml(
|
|
|
176
191
|
<meta charset="UTF-8">
|
|
177
192
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
178
193
|
${THEME_INIT_SCRIPT}
|
|
179
|
-
${buildIdMeta}${faviconLink}${cssLinks ? `${cssLinks}\n` : ""} <!--ssr-head-->
|
|
194
|
+
${buildIdMeta}${modeMeta}${faviconLink}${cssLinks ? `${cssLinks}\n` : ""} <!--ssr-head-->
|
|
180
195
|
</head>
|
|
181
196
|
<body>
|
|
182
197
|
<div id="root"><!--ssr-outlet--></div>
|
|
@@ -269,6 +269,19 @@ export interface RouterProviderProps {
|
|
|
269
269
|
}
|
|
270
270
|
interface RouterState {
|
|
271
271
|
data: Record<string, unknown>;
|
|
272
|
+
/**
|
|
273
|
+
* Set when the server's NDJSON payload carried an `__furinError` sentinel
|
|
274
|
+
* (loader threw a non-redirect `Response`, or an `Error`). The provider's
|
|
275
|
+
* render path injects a `<RouteErrorThrower>` in place of the page so the
|
|
276
|
+
* nearest `<FurinErrorBoundary>` catches a `FurinServerError` carrying the
|
|
277
|
+
* server's digest + status. Mirrors the `__furinError` channel that already
|
|
278
|
+
* exists for SSR digest correlation.
|
|
279
|
+
*/
|
|
280
|
+
error?: {
|
|
281
|
+
digest: string;
|
|
282
|
+
message: string;
|
|
283
|
+
status: number;
|
|
284
|
+
};
|
|
272
285
|
/** The canonical href after server-side redirects (e.g. query-default redirect). */
|
|
273
286
|
finalHref?: string;
|
|
274
287
|
/**
|
|
@@ -322,9 +335,13 @@ export declare function normalizeHref(href: string): string;
|
|
|
322
335
|
* - `ok` — 2xx response with usable loader data; render normally.
|
|
323
336
|
* - `not-found` — server signalled `__FURIN_DATA__.__furinStatus === 404`; the
|
|
324
337
|
* caller should render the not-found UI inline (no full-page reload).
|
|
325
|
-
* - `
|
|
326
|
-
*
|
|
327
|
-
*
|
|
338
|
+
* - `error` — server signalled `__FURIN_DATA__.__furinError` (loader threw a
|
|
339
|
+
* non-redirect `Response` or an `Error`). The caller surfaces this through
|
|
340
|
+
* the nearest `error.tsx` inline by throwing a `FurinServerError` during
|
|
341
|
+
* render so the existing `FurinErrorBoundary` catches it.
|
|
342
|
+
* - `bail` — any other non-2xx without sentinels (stale-deploy, unparseable
|
|
343
|
+
* payload, opaque crash…); the caller falls back to a full-page navigation
|
|
344
|
+
* so the browser shows whatever the server actually sent.
|
|
328
345
|
*
|
|
329
346
|
* @internal Exported for unit testing only.
|
|
330
347
|
*/
|
|
@@ -336,15 +353,24 @@ export type SpaResponseKind = {
|
|
|
336
353
|
data?: unknown;
|
|
337
354
|
message?: string;
|
|
338
355
|
};
|
|
356
|
+
} | {
|
|
357
|
+
kind: "error";
|
|
358
|
+
error: {
|
|
359
|
+
digest: string;
|
|
360
|
+
message: string;
|
|
361
|
+
status: number;
|
|
362
|
+
};
|
|
339
363
|
} | {
|
|
340
364
|
kind: "bail";
|
|
341
365
|
};
|
|
342
366
|
/**
|
|
343
367
|
* Pure classifier for an SPA-nav fetch result. Takes the HTTP status and the
|
|
344
|
-
* already-parsed `__FURIN_DATA__` payload.
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
368
|
+
* already-parsed `__FURIN_DATA__` payload.
|
|
369
|
+
*
|
|
370
|
+
* Sentinels (`__furinError`, `__furinStatus`) are trusted over the raw HTTP
|
|
371
|
+
* status — proxies / CDNs sometimes rewrite the status code but pass the body
|
|
372
|
+
* through untouched. A non-2xx response without any sentinel triggers a bail
|
|
373
|
+
* so the browser handles it (could be an error page, redirect, etc.).
|
|
348
374
|
*
|
|
349
375
|
* @internal Exported for unit testing only.
|
|
350
376
|
*/
|
|
@@ -418,19 +444,26 @@ export interface RootBoundaryOptions {
|
|
|
418
444
|
/**
|
|
419
445
|
* Composes the outermost tree produced by `RouterProvider`:
|
|
420
446
|
*
|
|
421
|
-
* <
|
|
422
|
-
* <
|
|
447
|
+
* <RouterContext.Provider value={context}>
|
|
448
|
+
* <FurinErrorBoundary digest onReset resetKey>
|
|
423
449
|
* {pageElement}
|
|
424
|
-
* </
|
|
425
|
-
* </
|
|
450
|
+
* </FurinErrorBoundary>
|
|
451
|
+
* </RouterContext.Provider>
|
|
452
|
+
*
|
|
453
|
+
* `RouterContext.Provider` is the OUTERMOST element so that a root-level
|
|
454
|
+
* `error.tsx` rendered by the boundary can still call `useRouter()` / render
|
|
455
|
+
* `<Link>` (the context is in scope above the boundary).
|
|
426
456
|
*
|
|
427
|
-
*
|
|
428
|
-
* `FurinErrorBoundary`s inserted by `buildPageElement` only wrap
|
|
429
|
-
* subtree BELOW the root layout, so
|
|
457
|
+
* The `FurinErrorBoundary` is the LAST line of defence for render errors.
|
|
458
|
+
* Per-segment `FurinErrorBoundary`s inserted by `buildPageElement` only wrap
|
|
459
|
+
* the page subtree BELOW the root layout, so this top boundary is the only one
|
|
460
|
+
* that catches errors thrown in:
|
|
430
461
|
* - the root layout itself,
|
|
431
|
-
* - hydration mismatches
|
|
432
|
-
*
|
|
433
|
-
*
|
|
462
|
+
* - hydration mismatches within the rendered tree.
|
|
463
|
+
*
|
|
464
|
+
* It does NOT catch errors thrown by `RouterProvider` itself or by the
|
|
465
|
+
* `buildPageElement` / `buildRouterTree` scaffolding — those run before the
|
|
466
|
+
* boundary exists in the tree, so React has no boundary to propagate to.
|
|
434
467
|
*
|
|
435
468
|
* We deliberately omit the `fallback` prop so the boundary falls back to its
|
|
436
469
|
* built-in `DefaultErrorFallback` — if a user-authored fallback crashed
|
|
@@ -460,7 +493,42 @@ export interface BoundaryOptions {
|
|
|
460
493
|
resetKey?: string | number;
|
|
461
494
|
}
|
|
462
495
|
/** @internal Exported for unit testing only. */
|
|
463
|
-
export declare function buildPageElement(match: LoadedClientRoute, root: RuntimeRoute | null, data: Record<string, unknown>, options: BoundaryOptions | undefined
|
|
496
|
+
export declare function buildPageElement(match: LoadedClientRoute, root: RuntimeRoute | null, data: Record<string, unknown>, options: BoundaryOptions | undefined, error: {
|
|
497
|
+
digest: string;
|
|
498
|
+
message: string;
|
|
499
|
+
status: number;
|
|
500
|
+
} | undefined): React.ReactNode;
|
|
501
|
+
/**
|
|
502
|
+
* Builds the URL the SPA navigation flow uses to fetch a route's loader data.
|
|
503
|
+
*
|
|
504
|
+
* Two transports are supported:
|
|
505
|
+
*
|
|
506
|
+
* • **Runtime (SSR/ISR/dev)** — `${basePath}/_furin/data?path=<logicalHref>`.
|
|
507
|
+
* Served by the Elysia plugin in `createDataEndpoint`, which dynamically
|
|
508
|
+
* re-runs the loader with the requested path/query.
|
|
509
|
+
*
|
|
510
|
+
* • **Static export** — `${basePath}<logicalPathname>/__furin_data.ndjson`.
|
|
511
|
+
* Pre-written next to each `index.html` by `buildStaticTarget`, served
|
|
512
|
+
* verbatim by any file server (GitHub Pages, S3, …). The loader does not
|
|
513
|
+
* execute at request time, so query strings are *intentionally* ignored:
|
|
514
|
+
* a single NDJSON exists per route, computed at build time.
|
|
515
|
+
*
|
|
516
|
+
* `staticMode` is decided once at boot from the `<meta name="furin-mode">`
|
|
517
|
+
* tag injected by `generateProdIndexHtml` — flipping the transport at runtime
|
|
518
|
+
* for the wrong deployment would just produce 404s.
|
|
519
|
+
*
|
|
520
|
+
* @internal Exported for unit testing.
|
|
521
|
+
*/
|
|
522
|
+
export declare function buildDataEndpoint(basePath: string, logicalHref: string, staticMode: boolean): string;
|
|
523
|
+
/**
|
|
524
|
+
* Reads `<meta name="furin-mode" content="static">` from the document at boot.
|
|
525
|
+
* The static adapter injects this tag (`shell.ts:generateProdIndexHtml`) so the
|
|
526
|
+
* SPA client picks the static-friendly transport. SSR/dev shells omit the tag
|
|
527
|
+
* and the client uses the runtime endpoint.
|
|
528
|
+
*
|
|
529
|
+
* @internal Exported for unit testing.
|
|
530
|
+
*/
|
|
531
|
+
export declare function detectStaticMode(): boolean;
|
|
464
532
|
/** Strips basePath prefix from a physical pathname, returning the logical path. */
|
|
465
533
|
export declare function toLogical(physicalPathname: string, basePath: string): string;
|
|
466
534
|
export declare function RouterProvider({ routes, root, initialMatch, initialData, initialDigest, initialNotFound, autoRefresh, basePath, defaultPreload, defaultPreloadDelay, defaultPreloadStaleTime, prefetchCacheSize, }: RouterProviderProps): React.ReactElement;
|
package/dist/router.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export interface ResolvedRoute {
|
|
|
51
51
|
*/
|
|
52
52
|
segmentBoundaries: SegmentBoundary[];
|
|
53
53
|
ssgHtml?: string;
|
|
54
|
+
tags?: string[];
|
|
54
55
|
}
|
|
55
56
|
export interface RootLayout {
|
|
56
57
|
error?: ErrorComponent;
|
|
@@ -60,6 +61,8 @@ export interface RootLayout {
|
|
|
60
61
|
path: string;
|
|
61
62
|
route: RuntimeRoute;
|
|
62
63
|
}
|
|
64
|
+
/** @internal Exported for unit testing. */
|
|
65
|
+
export declare function collectRouteTags(routeChain: RuntimeRoute[], page: Pick<RuntimePage, "tags"> | undefined): string[] | undefined;
|
|
63
66
|
export declare function loadProdRoutes(ctx: CompileContext): {
|
|
64
67
|
root: RootLayout;
|
|
65
68
|
routes: ResolvedRoute[];
|
|
@@ -69,6 +72,36 @@ export declare function scanPages(pagesDir: string): Promise<{
|
|
|
69
72
|
routes: ResolvedRoute[];
|
|
70
73
|
}>;
|
|
71
74
|
export declare function scanRootLayout(pagesDir: string): Promise<RootLayout>;
|
|
75
|
+
/**
|
|
76
|
+
* Detects whether a validator filled in default query values that the original
|
|
77
|
+
* URL did not carry, and returns the canonical `pathname + search` to redirect
|
|
78
|
+
* to — or `undefined` when the URL already reflects the resolved query.
|
|
79
|
+
*
|
|
80
|
+
* Pure helper extracted from `queryDefaultRedirectHook` so the `/_furin/data`
|
|
81
|
+
* NDJSON endpoint can detect the same condition without going through
|
|
82
|
+
* Elysia's `status()` shim (which only emits HTTP 302s, unparseable by the
|
|
83
|
+
* SPA client).
|
|
84
|
+
*
|
|
85
|
+
* @internal Exported for unit testing.
|
|
86
|
+
*/
|
|
87
|
+
export declare function detectQueryDefaultRedirect(request: Request, resolvedQuery: Record<string, unknown>): string | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Parses the `?path=` argument of `/_furin/data`, rejecting absolute /
|
|
90
|
+
* protocol-relative inputs that would let a caller smuggle a foreign origin
|
|
91
|
+
* into the synthetic loader request.
|
|
92
|
+
*
|
|
93
|
+
* Returns `{ url, pathname }` on success, or `undefined` when the input is
|
|
94
|
+
* unsafe (the caller should reply 400). `new URL(rawPath, base)` ignores the
|
|
95
|
+
* base when `rawPath` is itself absolute, so without these prefix and origin
|
|
96
|
+
* checks a value like `https://evil.com/foo` would propagate to
|
|
97
|
+
* `syntheticRequest.url`.
|
|
98
|
+
*
|
|
99
|
+
* @internal Exported for unit testing.
|
|
100
|
+
*/
|
|
101
|
+
export declare function parseDataEndpointPath(rawPath: string): {
|
|
102
|
+
url: URL;
|
|
103
|
+
pathname: string;
|
|
104
|
+
} | undefined;
|
|
72
105
|
/** @internal Exported for unit testing. */
|
|
73
106
|
export declare function queryDefaultRedirectHook({ request, query, status, set }: Context): import("elysia").ElysiaCustomStatusResponse<"Found", "Found", 302> | undefined;
|
|
74
107
|
/**
|
|
@@ -81,6 +114,22 @@ export declare function queryDefaultRedirectHook({ request, query, status, set }
|
|
|
81
114
|
* it defaults to the real `import()`.
|
|
82
115
|
*/
|
|
83
116
|
export declare function refreshLayoutChain(chain: RuntimeRoute[], pagePath: string, rootPath: string, importFn: ((specifier: string) => Promise<Record<string, unknown>>) | undefined): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Rebuilds a `ResolvedRoute` from freshly-imported `page` and `chain` so that
|
|
119
|
+
* `mode` reflects the CURRENT contents of the page module — not the value
|
|
120
|
+
* captured at scan time.
|
|
121
|
+
*
|
|
122
|
+
* In dev, `handleDevRequest` re-imports the page on every request to pick up
|
|
123
|
+
* source edits via the `?furin-server&t=<ts>` cache-buster. Without this
|
|
124
|
+
* function the spread `{ ...route, page, chain }` would carry over the stale
|
|
125
|
+
* `route.mode` resolved at startup, so toggling `revalidate` or removing a
|
|
126
|
+
* loader in source would not retake effect until a server restart.
|
|
127
|
+
*
|
|
128
|
+
* Only `mode` is recomputed: it is the only field DERIVED from page+chain.
|
|
129
|
+
* Structural fields (`pattern`, `path`, `segmentBoundaries`, `error`,
|
|
130
|
+
* `notFound`) are scan-time invariants in dev and are preserved as-is.
|
|
131
|
+
*/
|
|
132
|
+
export declare function rebuildDevRoute(base: ResolvedRoute, page: RuntimePage, chain: RuntimeRoute[]): ResolvedRoute;
|
|
84
133
|
/**
|
|
85
134
|
* @internal Lists every source file whose contents can affect the render
|
|
86
135
|
* output for a given page: the page itself, every intermediate `_route.*`
|
|
@@ -108,3 +157,20 @@ export declare function mergeRouteSchemas(routeChain: RuntimeRoute[], key: "para
|
|
|
108
157
|
export declare function createRoutePlugin(route: ResolvedRoute, root: RootLayout, buildId?: string): AnyElysia;
|
|
109
158
|
export declare function resolveMode(page: RuntimePage, routeChain: RuntimeRoute[]): "ssr" | "ssg" | "isr";
|
|
110
159
|
export declare function filePathToPattern(path: string): string;
|
|
160
|
+
/**
|
|
161
|
+
* Elysia plugin that handles `GET /_furin/data?path=<logicalHref>`.
|
|
162
|
+
*
|
|
163
|
+
* Returns an NDJSON stream (one-line, v1) produced by `toCrossJSONAsync`:
|
|
164
|
+
* Line 0 — CrossJSON serialisation of `{ ...syncData, ...deferredPromises }`
|
|
165
|
+
*
|
|
166
|
+
* The `deferredPromises` values are awaited by `toCrossJSONAsync` before
|
|
167
|
+
* serialising, so the client receives all data resolved in one round-trip.
|
|
168
|
+
* SPA navigation calls this endpoint via `parseDeferredNdjson` in
|
|
169
|
+
* `router-provider.tsx`.
|
|
170
|
+
*
|
|
171
|
+
* Special fields emitted alongside data:
|
|
172
|
+
* - `__furinStatus: 404` — when the loader called `notFound()`
|
|
173
|
+
* - `__furinNotFound` — not-found payload
|
|
174
|
+
* - `__furinRedirect` — logical path after a server-side redirect
|
|
175
|
+
*/
|
|
176
|
+
export declare function createDataEndpoint(routes: ResolvedRoute[]): AnyElysia;
|