@teyik0/furin 0.5.0-alpha.1 → 0.5.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/entry-template.ts +3 -1
- package/dist/build/index.js +360 -219
- package/dist/build/private-server-sourcemaps.d.ts +2 -0
- package/dist/build/types.d.ts +2 -0
- package/dist/cli/index.js +363 -221
- package/dist/client/document.d.ts +2 -0
- package/dist/client/link.js +11 -0
- package/dist/client.js +11 -0
- package/dist/config.d.ts +7 -2
- package/dist/config.js +24 -1
- package/dist/furin.js +217 -82
- package/dist/rsc-client.js +9 -1
- package/dist/rsc.js +19 -7
- package/dist/server/browser-events/shutdown.d.ts +3 -0
- package/dist/server/cache/redis/index.d.ts +2 -0
- package/dist/server/cache/redis/index.js +67 -12
- package/dist/server/cache/redis/scripts.d.ts +5 -5
- package/dist/server/dev/plugin.d.ts +1 -0
- package/dist/server/evlog.d.ts +1 -1
- package/dist/server/internal.js +3 -1
- package/dist/server/production-server.d.ts +13 -0
- package/dist/server/production-server.js +2906 -0
- package/dist/server/router/hmr.d.ts +6 -0
- package/dist/server/router/hmr.production.d.ts +5 -0
- package/dist/server/router/plugin.d.ts +5 -1
- package/dist/server/sync/index.js +5 -2
- package/dist/server/sync/stream.d.ts +4 -0
- package/dist/shared/production-build.d.ts +2 -0
- package/package.json +8 -3
- package/src/adapter/bun.ts +74 -15
- package/src/adapter/vercel.ts +15 -1
- package/src/build/elysia-aot.ts +1 -1
- package/src/build/entry-template.ts +3 -1
- package/src/build/hydrate.ts +5 -1
- package/src/build/index.ts +5 -0
- package/src/build/private-server-sourcemaps.ts +20 -0
- package/src/build/server-app-entry.ts +3 -2
- package/src/build/types.ts +2 -0
- package/src/cli/index.ts +1 -0
- package/src/client/document.tsx +19 -0
- package/src/config.ts +30 -2
- package/src/furin.ts +37 -12
- package/src/rsc/codec.ts +11 -6
- package/src/rsc/render-error.ts +3 -1
- package/src/server/browser-events/plugin.ts +7 -0
- package/src/server/browser-events/shutdown.ts +32 -0
- package/src/server/cache/redis/index.ts +19 -2
- package/src/server/cache/redis/scripts.ts +47 -7
- package/src/server/dev/plugin.ts +10 -1
- package/src/server/evlog.ts +11 -4
- package/src/server/production-server.ts +135 -0
- package/src/server/render/document.tsx +7 -1
- package/src/server/render/ssr.ts +2 -1
- package/src/server/render/template.ts +5 -1
- package/src/server/router/discovery.ts +3 -1
- package/src/server/router/hmr.production.ts +11 -0
- package/src/server/router/hmr.ts +84 -77
- package/src/server/router/plugin.ts +76 -17
- package/src/server/router/schema-merge.ts +9 -2
- package/src/server/sync/stream.ts +43 -2
- package/src/shared/production-build.ts +20 -0
package/dist/furin.js
CHANGED
|
@@ -353,7 +353,6 @@ var init_patterns = __esm(() => {
|
|
|
353
353
|
});
|
|
354
354
|
|
|
355
355
|
// src/server/router/schema-merge.ts
|
|
356
|
-
import { t } from "elysia";
|
|
357
356
|
function mergeRouteSchemas(routeChain, key) {
|
|
358
357
|
const schemas = routeChain.flatMap((route) => route[key] ? [route[key]] : []);
|
|
359
358
|
if (schemas.length === 0) {
|
|
@@ -367,12 +366,19 @@ function mergeRouteSchemas(routeChain, key) {
|
|
|
367
366
|
}
|
|
368
367
|
const properties = Object.assign({}, ...schemas.map((schema) => schema.properties));
|
|
369
368
|
const options = Object.assign({}, ...schemas.map((schema) => Object.fromEntries(Object.entries(schema).filter(([name]) => !TOBJECT_STRUCTURAL_KEYS.has(name)))));
|
|
370
|
-
|
|
369
|
+
const required = Object.keys(properties).filter((name) => {
|
|
370
|
+
const property = properties[name];
|
|
371
|
+
return !(property["~optional"] || property[TYPEBOX_OPTIONAL]);
|
|
372
|
+
});
|
|
373
|
+
return Object.defineProperty({ ...options, properties, required, type: "object" }, "~kind", {
|
|
374
|
+
value: "Object"
|
|
375
|
+
});
|
|
371
376
|
}
|
|
372
|
-
var TOBJECT_STRUCTURAL_KEYS;
|
|
377
|
+
var TOBJECT_STRUCTURAL_KEYS, TYPEBOX_OPTIONAL;
|
|
373
378
|
var init_schema_merge = __esm(() => {
|
|
374
379
|
init_elysia_contract();
|
|
375
380
|
TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
|
|
381
|
+
TYPEBOX_OPTIONAL = Symbol.for("TypeBox.Optional");
|
|
376
382
|
});
|
|
377
383
|
|
|
378
384
|
// src/server/router/schemas.ts
|
|
@@ -4884,7 +4890,13 @@ function createFurinEvlog(options) {
|
|
|
4884
4890
|
});
|
|
4885
4891
|
}, 0);
|
|
4886
4892
|
});
|
|
4887
|
-
(options.waitUntil
|
|
4893
|
+
if (options.waitUntil) {
|
|
4894
|
+
options.waitUntil(emission);
|
|
4895
|
+
} else {
|
|
4896
|
+
for (const waitUntil of runtimeWaitUntil) {
|
|
4897
|
+
waitUntil(emission);
|
|
4898
|
+
}
|
|
4899
|
+
}
|
|
4888
4900
|
return response;
|
|
4889
4901
|
} catch (error) {
|
|
4890
4902
|
await handle.finish({
|
|
@@ -4917,6 +4929,7 @@ var init_evlog = __esm(() => {
|
|
|
4917
4929
|
storage: loggerStorage.storage
|
|
4918
4930
|
});
|
|
4919
4931
|
getRequestLogger = loggerStorage.useLogger;
|
|
4932
|
+
runtimeWaitUntil = new Set;
|
|
4920
4933
|
});
|
|
4921
4934
|
|
|
4922
4935
|
// src/server/context-logger.ts
|
|
@@ -5334,6 +5347,19 @@ __export(exports_stream, {
|
|
|
5334
5347
|
subscribeSyncCursor: () => subscribeSyncCursor
|
|
5335
5348
|
});
|
|
5336
5349
|
import { Elysia as Elysia5 } from "elysia";
|
|
5350
|
+
function trackUnsubscription(subscription) {
|
|
5351
|
+
const existing = unsubscriptions.get(subscription);
|
|
5352
|
+
if (existing) {
|
|
5353
|
+
return existing;
|
|
5354
|
+
}
|
|
5355
|
+
const pending = subscription.unsubscribe();
|
|
5356
|
+
unsubscriptions.set(subscription, pending);
|
|
5357
|
+
pendingUnsubscriptions.add(pending);
|
|
5358
|
+
pending.finally(() => pendingUnsubscriptions.delete(pending)).catch(() => {
|
|
5359
|
+
return;
|
|
5360
|
+
});
|
|
5361
|
+
return pending;
|
|
5362
|
+
}
|
|
5337
5363
|
function notifyState(state, cursor) {
|
|
5338
5364
|
if (state.cursor === cursor) {
|
|
5339
5365
|
return;
|
|
@@ -5390,9 +5416,7 @@ async function subscribeSyncCursor(options, listener) {
|
|
|
5390
5416
|
if (state.safetyPoll) {
|
|
5391
5417
|
clearInterval(state.safetyPoll);
|
|
5392
5418
|
}
|
|
5393
|
-
state.subscription
|
|
5394
|
-
return;
|
|
5395
|
-
});
|
|
5419
|
+
trackUnsubscription(state.subscription);
|
|
5396
5420
|
}
|
|
5397
5421
|
};
|
|
5398
5422
|
}
|
|
@@ -5456,7 +5480,7 @@ function createSyncChangesPlugin(options) {
|
|
|
5456
5480
|
};
|
|
5457
5481
|
});
|
|
5458
5482
|
}
|
|
5459
|
-
var DEFAULT_CHANGE_LIMIT = 100, MAX_CHANGE_LIMIT = 500, MAX_CURSOR_LENGTH = 128, SAFETY_POLL_INTERVAL_MS, UNSIGNED_INTEGER_PATTERN, defaultSyncPath = "/_furin/sync", noOpSubscription, cursorStates, resolvedStates;
|
|
5483
|
+
var DEFAULT_CHANGE_LIMIT = 100, MAX_CHANGE_LIMIT = 500, MAX_CURSOR_LENGTH = 128, SAFETY_POLL_INTERVAL_MS, UNSIGNED_INTEGER_PATTERN, defaultSyncPath = "/_furin/sync", noOpSubscription, cursorStates, resolvedStates, pendingUnsubscriptions, unsubscriptions;
|
|
5460
5484
|
var init_stream = __esm(() => {
|
|
5461
5485
|
init_config();
|
|
5462
5486
|
init_runtime();
|
|
@@ -5467,6 +5491,25 @@ var init_stream = __esm(() => {
|
|
|
5467
5491
|
};
|
|
5468
5492
|
cursorStates = new Map;
|
|
5469
5493
|
resolvedStates = new Set;
|
|
5494
|
+
pendingUnsubscriptions = new Set;
|
|
5495
|
+
unsubscriptions = new WeakMap;
|
|
5496
|
+
});
|
|
5497
|
+
|
|
5498
|
+
// src/server/browser-events/shutdown.ts
|
|
5499
|
+
function registerBrowserEventConnection(server, close) {
|
|
5500
|
+
let connections = closeConnections.get(server);
|
|
5501
|
+
if (!connections) {
|
|
5502
|
+
connections = new Set;
|
|
5503
|
+
closeConnections.set(server, connections);
|
|
5504
|
+
}
|
|
5505
|
+
connections.add(close);
|
|
5506
|
+
}
|
|
5507
|
+
function unregisterBrowserEventConnection(server, close) {
|
|
5508
|
+
closeConnections.get(server)?.delete(close);
|
|
5509
|
+
}
|
|
5510
|
+
var closeConnections;
|
|
5511
|
+
var init_shutdown = __esm(() => {
|
|
5512
|
+
closeConnections = new WeakMap;
|
|
5470
5513
|
});
|
|
5471
5514
|
|
|
5472
5515
|
// src/server/browser-events/plugin.ts
|
|
@@ -5483,6 +5526,7 @@ function releaseConnection(state) {
|
|
|
5483
5526
|
return;
|
|
5484
5527
|
}
|
|
5485
5528
|
state.closed = true;
|
|
5529
|
+
unregisterBrowserEventConnection(state.server, state.close);
|
|
5486
5530
|
clearInterval(state.heartbeat);
|
|
5487
5531
|
for (const subscription of state.subscriptions) {
|
|
5488
5532
|
subscription.unsubscribe();
|
|
@@ -5548,12 +5592,15 @@ function createBrowserEventsPlugin(options) {
|
|
|
5548
5592
|
}
|
|
5549
5593
|
};
|
|
5550
5594
|
const state = {
|
|
5595
|
+
close: () => ws.close(1001, "Server shutting down"),
|
|
5551
5596
|
closed: false,
|
|
5552
5597
|
heartbeat: setInterval(() => ws.ping(), HEARTBEAT_INTERVAL_MS),
|
|
5598
|
+
server: ws.server,
|
|
5553
5599
|
subscriptions: []
|
|
5554
5600
|
};
|
|
5555
5601
|
state.heartbeat.unref?.();
|
|
5556
5602
|
connections.set(ws.id, state);
|
|
5603
|
+
registerBrowserEventConnection(state.server, state.close);
|
|
5557
5604
|
const keep = (subscription) => {
|
|
5558
5605
|
if (state.closed) {
|
|
5559
5606
|
subscription.unsubscribe();
|
|
@@ -5603,6 +5650,7 @@ function injectBrowserEventsClient(html, basePath) {
|
|
|
5603
5650
|
var CLIENT_PATH2 = "/_furin/events/client.js", SOCKET_PATH = "/_furin/events", HEARTBEAT_INTERVAL_MS = 30000, MAX_BROWSER_EVENT_CONNECTIONS = 100, CLIENT_SOURCE;
|
|
5604
5651
|
var init_plugin2 = __esm(() => {
|
|
5605
5652
|
init_stream();
|
|
5653
|
+
init_shutdown();
|
|
5606
5654
|
CLIENT_SOURCE = browserEventsClientSource();
|
|
5607
5655
|
});
|
|
5608
5656
|
|
|
@@ -6534,7 +6582,7 @@ function injectDevDiagnosticClient(html, basePath) {
|
|
|
6534
6582
|
}
|
|
6535
6583
|
function renderDevDiagnosticResponse(event, basePath) {
|
|
6536
6584
|
const state = serializeForHtml({ basePath, event });
|
|
6537
|
-
return new Response(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Furin development error</title>${browserEventsClientScript(basePath)}</head><body><script id="__FURIN_DEV_DIAGNOSTIC__" type="application/json">${state}</script><script type="module" src="${basePath}/_furin/dev/overlay.js"></script></body></html>`, {
|
|
6585
|
+
return new Response(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Furin development error</title><script data-furin-extension-error-filter="">${extensionErrorFilterScript}</script>${browserEventsClientScript(basePath)}</head><body><script id="__FURIN_DEV_DIAGNOSTIC__" type="application/json">${state}</script><script type="module" src="${basePath}/_furin/dev/overlay.js"></script></body></html>`, {
|
|
6538
6586
|
headers: {
|
|
6539
6587
|
"cache-control": "no-store",
|
|
6540
6588
|
"content-type": "text/html; charset=utf-8"
|
|
@@ -6542,7 +6590,14 @@ function renderDevDiagnosticResponse(event, basePath) {
|
|
|
6542
6590
|
status: 500
|
|
6543
6591
|
});
|
|
6544
6592
|
}
|
|
6545
|
-
var
|
|
6593
|
+
var extensionErrorFilterScript = `window.addEventListener("unhandledrejection", (event) => {
|
|
6594
|
+
const stack = event.reason?.stack;
|
|
6595
|
+
if (typeof stack !== "string") return;
|
|
6596
|
+
const firstFrame = stack.match(/^(?:\\s*at [^\\n]*|[^\\n]*@[^\\n]*)/m)?.[0];
|
|
6597
|
+
if (firstFrame && /\\b(?:chrome|moz)-extension:\\/\\//.test(firstFrame)) {
|
|
6598
|
+
event.stopImmediatePropagation();
|
|
6599
|
+
}
|
|
6600
|
+
}, true);`, overlayClientSource;
|
|
6546
6601
|
var init_plugin3 = __esm(() => {
|
|
6547
6602
|
init_plugin2();
|
|
6548
6603
|
init_diagnostics();
|
|
@@ -6998,7 +7053,7 @@ async function resolveDefinedLayoutParent(pagePath, pagesDir, rootRoute) {
|
|
|
6998
7053
|
if (!existsSync2(candidate)) {
|
|
6999
7054
|
continue;
|
|
7000
7055
|
}
|
|
7001
|
-
const layoutModule = await import(candidate);
|
|
7056
|
+
const layoutModule = await (IS_DEV ? import(`${candidate}?furin-server&t=${routeModuleSourceVersion(candidate)}`) : import(candidate));
|
|
7002
7057
|
const layout = layoutModule.route;
|
|
7003
7058
|
if (isDefinedRouteTerminal(layout) && typeof layout.layout === "function") {
|
|
7004
7059
|
parent = adaptDefinedLayout(layout, parent, candidate);
|
|
@@ -11726,6 +11781,7 @@ const _match = routes.find((r) => r.regex.test(pathname));
|
|
|
11726
11781
|
// a matched loader threw notFound(). The latter still has a _match; the
|
|
11727
11782
|
// former does not \u2014 so the two cases fork on _match below.
|
|
11728
11783
|
const dataEl = document.getElementById("__FURIN_DATA__");
|
|
11784
|
+
const frameTemplate = document.getElementById("__FURIN_ROUTE_FRAMES__") as HTMLTemplateElement | null;
|
|
11729
11785
|
let loaderData = dataEl ? JSON.parse(dataEl.textContent || "{}") : {};
|
|
11730
11786
|
const syncEl = document.getElementById("__FURIN_SYNC__");
|
|
11731
11787
|
const syncConfig = syncEl ? JSON.parse(syncEl.textContent || "{}") : {};
|
|
@@ -11742,6 +11798,7 @@ const documentState: DocumentState = {
|
|
|
11742
11798
|
assets: {
|
|
11743
11799
|
buildId,
|
|
11744
11800
|
entryModule: entryEl?.getAttribute("src") ?? undefined,
|
|
11801
|
+
extensionErrorFilterScript: document.querySelector("[data-furin-extension-error-filter]")?.textContent ?? undefined,
|
|
11745
11802
|
faviconHref,
|
|
11746
11803
|
frameworkModules,
|
|
11747
11804
|
staticMode: document.querySelector('meta[name="furin-mode"][content="static"]') !== null,
|
|
@@ -11751,6 +11808,9 @@ const documentState: DocumentState = {
|
|
|
11751
11808
|
},
|
|
11752
11809
|
dataJson: dataEl?.textContent ?? undefined,
|
|
11753
11810
|
head,
|
|
11811
|
+
routeFrames: frameTemplate?.hasAttribute("data-furin-document-state")
|
|
11812
|
+
? (frameTemplate.content.textContent ?? "")
|
|
11813
|
+
: undefined,
|
|
11754
11814
|
syncJson: syncEl?.textContent ?? undefined,
|
|
11755
11815
|
};
|
|
11756
11816
|
|
|
@@ -11825,7 +11885,6 @@ if (__deferred && __deferred._chunks) {
|
|
|
11825
11885
|
// Wrapped in an async IIFE to avoid top-level await, which causes Bun's HTML
|
|
11826
11886
|
// bundler to misidentify which chunk to reference as the entry in index.html.
|
|
11827
11887
|
(async () => {
|
|
11828
|
-
const frameTemplate = document.getElementById("__FURIN_ROUTE_FRAMES__") as HTMLTemplateElement | null;
|
|
11829
11888
|
if (frameTemplate) {
|
|
11830
11889
|
const payload = frameTemplate.content.textContent || "";
|
|
11831
11890
|
const routeFrameStream = (window as unknown as { __FURIN_ROUTE_FRAME_STREAM__?: FurinRouteFrameStream })
|
|
@@ -12282,6 +12341,10 @@ function HeadContent() {
|
|
|
12282
12341
|
}
|
|
12283
12342
|
return /* @__PURE__ */ jsxDEV(Fragment, {
|
|
12284
12343
|
children: [
|
|
12344
|
+
state.assets.extensionErrorFilterScript === undefined ? null : /* @__PURE__ */ jsxDEV("script", {
|
|
12345
|
+
dangerouslySetInnerHTML: { __html: state.assets.extensionErrorFilterScript },
|
|
12346
|
+
"data-furin-extension-error-filter": ""
|
|
12347
|
+
}, undefined, false, undefined, this),
|
|
12285
12348
|
/* @__PURE__ */ jsxDEV("meta", {
|
|
12286
12349
|
charSet: "utf-8",
|
|
12287
12350
|
"data-furin-head": ""
|
|
@@ -12339,6 +12402,13 @@ function Scripts() {
|
|
|
12339
12402
|
id: "__FURIN_DATA__",
|
|
12340
12403
|
type: "application/json"
|
|
12341
12404
|
}, undefined, false, undefined, this),
|
|
12405
|
+
state.routeFrames === undefined ? null : /* @__PURE__ */ jsxDEV("template", {
|
|
12406
|
+
dangerouslySetInnerHTML: {
|
|
12407
|
+
__html: state.routeFrames.replaceAll("&", "&").replaceAll("<", "<")
|
|
12408
|
+
},
|
|
12409
|
+
"data-furin-document-state": "",
|
|
12410
|
+
id: "__FURIN_ROUTE_FRAMES__"
|
|
12411
|
+
}, undefined, false, undefined, this),
|
|
12342
12412
|
/* @__PURE__ */ jsxDEV("script", {
|
|
12343
12413
|
dangerouslySetInnerHTML: { __html: serializeJson(state.head ?? {}) },
|
|
12344
12414
|
"data-furin-scripts": "",
|
|
@@ -12450,6 +12520,12 @@ function isDeferred(value) {
|
|
|
12450
12520
|
return typeof value === "object" && value !== null && DEFERRED_BRAND in value && Object.hasOwn(value, DEFERRED_BRAND) && value[DEFERRED_BRAND] === true;
|
|
12451
12521
|
}
|
|
12452
12522
|
|
|
12523
|
+
// src/shared/production-build.ts
|
|
12524
|
+
var productionBuildScope;
|
|
12525
|
+
function isProductionBuild() {
|
|
12526
|
+
return productionBuildScope?.getStore() === true || typeof process !== "undefined" && false;
|
|
12527
|
+
}
|
|
12528
|
+
|
|
12453
12529
|
// src/rsc/render-error.ts
|
|
12454
12530
|
var INTERNAL_STACK_FRAMES = new Set([
|
|
12455
12531
|
"<anonymous>",
|
|
@@ -12467,7 +12543,9 @@ function errorStack(error) {
|
|
|
12467
12543
|
return error instanceof Error ? error.stack : undefined;
|
|
12468
12544
|
}
|
|
12469
12545
|
function renderErrorMessage(options) {
|
|
12470
|
-
if (
|
|
12546
|
+
if (isProductionBuild()) {
|
|
12547
|
+
return `[furin/rsc] Server Component rendering failed inside ${options.operation}().`;
|
|
12548
|
+
}
|
|
12471
12549
|
if (options.hook !== undefined && options.component !== undefined) {
|
|
12472
12550
|
const diagnostic = `[furin/rsc] A component rendered inside ${options.operation}()
|
|
12473
12551
|
used a client-only React hook.
|
|
@@ -15402,10 +15480,12 @@ function withDocumentState(element, assets, head, data) {
|
|
|
15402
15480
|
...assets,
|
|
15403
15481
|
frameworkModules: [browserEventsClientPath, ...assets.frameworkModules]
|
|
15404
15482
|
};
|
|
15483
|
+
const routeFrames = data !== undefined && containsRscSource(data) ? serializeRouteFrames(data, undefined) : undefined;
|
|
15405
15484
|
const state = {
|
|
15406
15485
|
assets: resolvedAssets,
|
|
15407
|
-
dataJson: data === undefined ? undefined : safeJson(data),
|
|
15486
|
+
dataJson: data === undefined || routeFrames !== undefined ? undefined : safeJson(data),
|
|
15408
15487
|
head,
|
|
15488
|
+
routeFrames,
|
|
15409
15489
|
syncJson: syncPath === undefined ? undefined : safeJson({ path: syncPath })
|
|
15410
15490
|
};
|
|
15411
15491
|
return createElement4(DocumentProvider, { value: state }, element);
|
|
@@ -16475,7 +16555,11 @@ async function getDevDocumentAssets(origin) {
|
|
|
16475
16555
|
if (state.devAssets && Date.now() - state.devAssets.ts < DEV_TEMPLATE_TTL_MS) {
|
|
16476
16556
|
return state.devAssets.assets;
|
|
16477
16557
|
}
|
|
16478
|
-
|
|
16558
|
+
await Promise.resolve().then(() => init_plugin3());
|
|
16559
|
+
const assets = {
|
|
16560
|
+
...documentAssetsFromTemplate(await getDevTemplate(origin)),
|
|
16561
|
+
extensionErrorFilterScript
|
|
16562
|
+
};
|
|
16479
16563
|
state.devAssets = { assets, ts: Date.now() };
|
|
16480
16564
|
return assets;
|
|
16481
16565
|
}
|
|
@@ -16980,7 +17064,7 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult, searchRoutes
|
|
|
16980
17064
|
dataPayload.__furinNotFound = prepared.notFoundError;
|
|
16981
17065
|
}
|
|
16982
17066
|
}
|
|
16983
|
-
if (dataPayload.__furinError !== undefined && dataPayload.__furinNotFound !== undefined) {
|
|
17067
|
+
if (!isProductionBuild() && dataPayload.__furinError !== undefined && dataPayload.__furinNotFound !== undefined) {
|
|
16984
17068
|
throw new Error("[furin] internal invariant violated: __furinError and __furinNotFound were both set on the same SSR payload.");
|
|
16985
17069
|
}
|
|
16986
17070
|
const hasDeferred = !shellErrored && deferredPromises !== undefined;
|
|
@@ -18017,6 +18101,14 @@ function devFailure(error) {
|
|
|
18017
18101
|
}
|
|
18018
18102
|
return { error, phase: "import" };
|
|
18019
18103
|
}
|
|
18104
|
+
function reportDevRouteFailure(error, route) {
|
|
18105
|
+
const failure = devFailure(error);
|
|
18106
|
+
publishDevDiagnostic(failure.error, {
|
|
18107
|
+
entryPath: route.path,
|
|
18108
|
+
phase: failure.phase,
|
|
18109
|
+
route: route.pattern
|
|
18110
|
+
});
|
|
18111
|
+
}
|
|
18020
18112
|
function importStampedRouteModule(path, resolveImport) {
|
|
18021
18113
|
const stamp = routeModuleSourceVersion(path);
|
|
18022
18114
|
return devGraph(undefined).importModule(path, stamp, resolveImport);
|
|
@@ -18100,54 +18192,57 @@ function rebuildDevRoute(base, page, chain) {
|
|
|
18100
18192
|
tags: collectRouteTags(chain, page)
|
|
18101
18193
|
};
|
|
18102
18194
|
}
|
|
18195
|
+
async function resolveCurrentDevRoute(route, root) {
|
|
18196
|
+
let currentRoot = root;
|
|
18197
|
+
const rootMod = await importStampedRouteModule(root.path, routeModuleImport);
|
|
18198
|
+
const rootExport = rootMod.route;
|
|
18199
|
+
if (isDefinedRouteTerminal(rootExport) && typeof rootExport.layout === "function") {
|
|
18200
|
+
currentRoot = {
|
|
18201
|
+
...currentRoot,
|
|
18202
|
+
route: adaptDefinedLayout(rootExport, undefined, root.path)
|
|
18203
|
+
};
|
|
18204
|
+
}
|
|
18205
|
+
const pageMod = await importStampedRouteModule(route.path, routeModuleImport);
|
|
18206
|
+
let page;
|
|
18207
|
+
let chain;
|
|
18208
|
+
if (isDefinedRouteTerminal(pageMod.route) && typeof pageMod.route.page === "function") {
|
|
18209
|
+
const currentChain = route.routeChain;
|
|
18210
|
+
await refreshLayoutChain(currentChain, route.path, root.path, undefined);
|
|
18211
|
+
const parent = currentChain.at(-2) ?? currentRoot.route;
|
|
18212
|
+
const adaptedPage = adaptDefinedPage(pageMod.route, parent);
|
|
18213
|
+
page = adaptedPage;
|
|
18214
|
+
chain = collectRouteChainFromRoute(adaptedPage._route);
|
|
18215
|
+
}
|
|
18216
|
+
if (page && chain) {
|
|
18217
|
+
if (chain[0] && currentRoot.route) {
|
|
18218
|
+
chain[0].layout = currentRoot.route.layout;
|
|
18219
|
+
chain[0].loader = currentRoot.route.loader;
|
|
18220
|
+
chain[0].staticParams = currentRoot.route.staticParams;
|
|
18221
|
+
}
|
|
18222
|
+
return { root: currentRoot, route: rebuildDevRoute(route, page, chain) };
|
|
18223
|
+
}
|
|
18224
|
+
const invalidExport = new Error(`${route.path} must provide a valid Furin page export`);
|
|
18225
|
+
Reflect.set(invalidExport, "furinPosition", {
|
|
18226
|
+
column: 1,
|
|
18227
|
+
file: route.path,
|
|
18228
|
+
line: 1
|
|
18229
|
+
});
|
|
18230
|
+
throw new DevTransformFailure(invalidExport, { cause: invalidExport });
|
|
18231
|
+
}
|
|
18103
18232
|
async function handleDevRequest(route, ctx, root, searchRoutes) {
|
|
18104
18233
|
try {
|
|
18105
|
-
|
|
18106
|
-
|
|
18107
|
-
|
|
18108
|
-
|
|
18109
|
-
|
|
18110
|
-
|
|
18111
|
-
|
|
18112
|
-
|
|
18113
|
-
|
|
18114
|
-
const pageMod = await importStampedRouteModule(route.path, routeModuleImport);
|
|
18115
|
-
let page;
|
|
18116
|
-
let chain;
|
|
18117
|
-
if (isDefinedRouteTerminal(pageMod.route) && typeof pageMod.route.page === "function") {
|
|
18118
|
-
const currentChain = route.routeChain;
|
|
18119
|
-
await refreshLayoutChain(currentChain, route.path, root.path, undefined);
|
|
18120
|
-
const parent = currentChain.at(-2) ?? currentRoot.route;
|
|
18121
|
-
const adaptedPage = adaptDefinedPage(pageMod.route, parent);
|
|
18122
|
-
page = adaptedPage;
|
|
18123
|
-
chain = collectRouteChainFromRoute(adaptedPage._route);
|
|
18124
|
-
}
|
|
18125
|
-
if (page && chain) {
|
|
18126
|
-
if (chain[0] && currentRoot.route) {
|
|
18127
|
-
chain[0].layout = currentRoot.route.layout;
|
|
18128
|
-
chain[0].loader = currentRoot.route.loader;
|
|
18129
|
-
chain[0].staticParams = currentRoot.route.staticParams;
|
|
18130
|
-
}
|
|
18131
|
-
const refreshedRoute = rebuildDevRoute(route, page, chain);
|
|
18132
|
-
let response;
|
|
18133
|
-
if (refreshedRoute.mode === "isr") {
|
|
18134
|
-
response = await renderDevISRWithLoaderCache(refreshedRoute, ctx, currentRoot, searchRoutes);
|
|
18135
|
-
} else if (refreshedRoute.mode === "ssg") {
|
|
18136
|
-
response = await renderDevSSGWithLoaderCache(refreshedRoute, ctx, currentRoot, searchRoutes);
|
|
18137
|
-
} else {
|
|
18138
|
-
const loaderResult = await runDevLoaders(refreshedRoute, ctx);
|
|
18139
|
-
response = await runDevRender(() => renderSSR(refreshedRoute, ctx, currentRoot, loaderResult, searchRoutes));
|
|
18140
|
-
}
|
|
18141
|
-
devDiagnosticStore().markReady(route.pattern);
|
|
18142
|
-
return response;
|
|
18234
|
+
const { route: refreshedRoute, root: currentRoot } = await resolveCurrentDevRoute(route, root);
|
|
18235
|
+
let response;
|
|
18236
|
+
if (refreshedRoute.mode === "isr") {
|
|
18237
|
+
response = await renderDevISRWithLoaderCache(refreshedRoute, ctx, currentRoot, searchRoutes);
|
|
18238
|
+
} else if (refreshedRoute.mode === "ssg") {
|
|
18239
|
+
response = await renderDevSSGWithLoaderCache(refreshedRoute, ctx, currentRoot, searchRoutes);
|
|
18240
|
+
} else {
|
|
18241
|
+
const loaderResult = await runDevLoaders(refreshedRoute, ctx);
|
|
18242
|
+
response = await runDevRender(() => renderSSR(refreshedRoute, ctx, currentRoot, loaderResult, searchRoutes));
|
|
18143
18243
|
}
|
|
18144
|
-
|
|
18145
|
-
|
|
18146
|
-
column: 1,
|
|
18147
|
-
file: route.path,
|
|
18148
|
-
line: 1
|
|
18149
|
-
});
|
|
18150
|
-
throw new DevTransformFailure(invalidExport, { cause: invalidExport });
|
|
18244
|
+
devDiagnosticStore().markReady(route.pattern);
|
|
18245
|
+
return response;
|
|
18151
18246
|
} catch (err) {
|
|
18152
18247
|
console.error(`[furin] Dev page load error for ${route.path}:`, err);
|
|
18153
18248
|
const failure = devFailure(err);
|
|
@@ -18231,7 +18326,7 @@ function computeRouteDependencies(pagePath, rootPath) {
|
|
|
18231
18326
|
init_patterns();
|
|
18232
18327
|
|
|
18233
18328
|
// src/server/router/plugin.ts
|
|
18234
|
-
import { Elysia as Elysia8, problem
|
|
18329
|
+
import { Elysia as Elysia8, problem } from "elysia";
|
|
18235
18330
|
init_context_logger();
|
|
18236
18331
|
init_instrumentation();
|
|
18237
18332
|
init_external_prerender();
|
|
@@ -18815,6 +18910,31 @@ async function createRouteDataErrorResponse(error, message, status, routeContext
|
|
|
18815
18910
|
status
|
|
18816
18911
|
});
|
|
18817
18912
|
}
|
|
18913
|
+
async function resolveDataRoute(route, resolveRoute) {
|
|
18914
|
+
try {
|
|
18915
|
+
return await resolveRoute(route);
|
|
18916
|
+
} catch (error) {
|
|
18917
|
+
getLogger().error(error instanceof Error ? error : new Error(String(error)));
|
|
18918
|
+
if (IS_DEV) {
|
|
18919
|
+
reportDevRouteFailure(error, route);
|
|
18920
|
+
}
|
|
18921
|
+
return createRouteDataErrorResponse(error, "Something went wrong", 500, undefined);
|
|
18922
|
+
}
|
|
18923
|
+
}
|
|
18924
|
+
async function resolveDataRoutes(routesSource, request) {
|
|
18925
|
+
try {
|
|
18926
|
+
return typeof routesSource === "function" ? await routesSource(request) : routesSource;
|
|
18927
|
+
} catch (error) {
|
|
18928
|
+
getLogger().error(error instanceof Error ? error : new Error(String(error)));
|
|
18929
|
+
return createRouteDataErrorResponse(error, "Something went wrong", 500, undefined);
|
|
18930
|
+
}
|
|
18931
|
+
}
|
|
18932
|
+
function resolvedSearchRoutes(routes, matchedRoute, currentRoute, searchRoutes, refreshDevRoute) {
|
|
18933
|
+
if (refreshDevRoute === undefined) {
|
|
18934
|
+
return searchRoutes;
|
|
18935
|
+
}
|
|
18936
|
+
return createSearchRouteMetadata(routes.map((route) => route === matchedRoute ? currentRoute : route));
|
|
18937
|
+
}
|
|
18818
18938
|
async function handleSSGRequest(route, ctx, root, buildId, searchRoutes) {
|
|
18819
18939
|
const { origin } = new URL(ctx.request.url);
|
|
18820
18940
|
const params = ctx.params ?? {};
|
|
@@ -18857,14 +18977,13 @@ function renderResolvedRoute(route, ctx, root, buildId, searchRoutes) {
|
|
|
18857
18977
|
}
|
|
18858
18978
|
return renderSSR(route, ctx, root, undefined, searchRoutes);
|
|
18859
18979
|
}
|
|
18860
|
-
function createDataEndpoint(routesSource, root) {
|
|
18980
|
+
function createDataEndpoint(routesSource, root, refreshDevRoute) {
|
|
18861
18981
|
const plugin = new Elysia8;
|
|
18862
18982
|
let matchedRoutes = Array.isArray(routesSource) ? routesSource : [];
|
|
18863
18983
|
let matchRoute = buildRouteMatcher(matchedRoutes);
|
|
18864
18984
|
let searchRoutes = createSearchRouteMetadata(matchedRoutes);
|
|
18865
|
-
|
|
18866
|
-
|
|
18867
|
-
}, async (ctx) => {
|
|
18985
|
+
const resolveRoute = refreshDevRoute ?? ((route) => Promise.resolve({ root, route }));
|
|
18986
|
+
plugin.get("/_furin/data", {}, async (ctx) => {
|
|
18868
18987
|
const rawPath = ctx.query.path;
|
|
18869
18988
|
if (!rawPath || typeof rawPath !== "string") {
|
|
18870
18989
|
return problem("Bad Request", { detail: "Missing required query param: path" });
|
|
@@ -18876,12 +18995,9 @@ function createDataEndpoint(routesSource, root) {
|
|
|
18876
18995
|
const { url, pathname } = parsed;
|
|
18877
18996
|
const wideEventLog = getLogger();
|
|
18878
18997
|
wideEventLog.set({ path: rawPath });
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
currentRoutes
|
|
18882
|
-
} catch (error) {
|
|
18883
|
-
wideEventLog.error(error instanceof Error ? error : new Error(String(error)));
|
|
18884
|
-
return createRouteDataErrorResponse(error, "Something went wrong", 500, undefined);
|
|
18998
|
+
const currentRoutes = await resolveDataRoutes(routesSource, ctx.request);
|
|
18999
|
+
if (currentRoutes instanceof Response) {
|
|
19000
|
+
return currentRoutes;
|
|
18885
19001
|
}
|
|
18886
19002
|
if (currentRoutes !== matchedRoutes) {
|
|
18887
19003
|
matchedRoutes = currentRoutes;
|
|
@@ -18893,6 +19009,11 @@ function createDataEndpoint(routesSource, root) {
|
|
|
18893
19009
|
return problem("Not Found", { detail: "Route not found" });
|
|
18894
19010
|
}
|
|
18895
19011
|
wideEventLog.set({ routePattern: matched.route.pattern });
|
|
19012
|
+
const current = await resolveDataRoute(matched.route, resolveRoute);
|
|
19013
|
+
if (current instanceof Response) {
|
|
19014
|
+
return current;
|
|
19015
|
+
}
|
|
19016
|
+
const currentSearchRoutes = resolvedSearchRoutes(matchedRoutes, matched.route, current.route, searchRoutes, refreshDevRoute);
|
|
18896
19017
|
const syntheticRequest = new Request(new URL(pathname + url.search, ctx.request.url), {
|
|
18897
19018
|
headers: ctx.request.headers
|
|
18898
19019
|
});
|
|
@@ -18908,8 +19029,8 @@ function createDataEndpoint(routesSource, root) {
|
|
|
18908
19029
|
set: syntheticSet,
|
|
18909
19030
|
status: (code) => new Response(null, { status: code })
|
|
18910
19031
|
};
|
|
18911
|
-
const mergedParams = mergeRouteSchemas(
|
|
18912
|
-
const mergedQuery = mergeRouteSchemas(
|
|
19032
|
+
const mergedParams = mergeRouteSchemas(current.route.routeChain, "params");
|
|
19033
|
+
const mergedQuery = mergeRouteSchemas(current.route.routeChain, "query");
|
|
18913
19034
|
const parsedParams = await parseRouteParams(matched.params, mergedParams);
|
|
18914
19035
|
if (!parsedParams.ok) {
|
|
18915
19036
|
return problem(422, { detail: "Invalid params", errors: parsedParams.errors });
|
|
@@ -18920,8 +19041,8 @@ function createDataEndpoint(routesSource, root) {
|
|
|
18920
19041
|
}
|
|
18921
19042
|
syntheticCtx.params = parsedParams.params;
|
|
18922
19043
|
syntheticCtx.query = parsedQuery.query;
|
|
18923
|
-
const result = await runDataEndpointLoaders(
|
|
18924
|
-
return createLoaderDataResponse(result,
|
|
19044
|
+
const result = await runDataEndpointLoaders(current.route, syntheticCtx, current.root, currentSearchRoutes);
|
|
19045
|
+
return createLoaderDataResponse(result, current.route, syntheticRequest.url, syntheticCtx);
|
|
18925
19046
|
});
|
|
18926
19047
|
return plugin;
|
|
18927
19048
|
}
|
|
@@ -19810,9 +19931,22 @@ function wrapWithRequestScope(app) {
|
|
|
19810
19931
|
});
|
|
19811
19932
|
});
|
|
19812
19933
|
}
|
|
19813
|
-
function createFurinPlugin(app) {
|
|
19934
|
+
function createFurinPlugin(app, hmrPrefix) {
|
|
19814
19935
|
const scopedApp = wrapWithRequestScope(app);
|
|
19815
|
-
return (parentApp) =>
|
|
19936
|
+
return (parentApp) => {
|
|
19937
|
+
const mounted = parentApp.use(scopedApp);
|
|
19938
|
+
if (hmrPrefix !== undefined) {
|
|
19939
|
+
const parentConfig = Reflect.get(parentApp, "~config");
|
|
19940
|
+
const entryPath = `${parentConfig?.prefix ?? ""}${hmrPrefix}/_bun_hmr_entry`;
|
|
19941
|
+
const routes = Reflect.get(mounted, "~routes");
|
|
19942
|
+
for (const route of routes ?? []) {
|
|
19943
|
+
if (route[0] === "GET" && (route[1] === entryPath || route[1] === `${entryPath}/index.html`)) {
|
|
19944
|
+
route[6] = undefined;
|
|
19945
|
+
}
|
|
19946
|
+
}
|
|
19947
|
+
}
|
|
19948
|
+
return mounted;
|
|
19949
|
+
};
|
|
19816
19950
|
}
|
|
19817
19951
|
async function loadDevelopmentRoutes(resolvedPagesDir) {
|
|
19818
19952
|
await Promise.resolve().then(() => init_discovery());
|
|
@@ -19958,6 +20092,7 @@ async function furin({
|
|
|
19958
20092
|
};
|
|
19959
20093
|
writeCurrentDevFiles(initialSnapshot);
|
|
19960
20094
|
graph.commit(initialSnapshot);
|
|
20095
|
+
const hmrEntry = (await import(join7(furinDir, "index.html"))).default;
|
|
19961
20096
|
const refreshDevelopmentRoutes = (changedSources) => withInstance(instance, async () => {
|
|
19962
20097
|
invalidateStampedRouteModules();
|
|
19963
20098
|
try {
|
|
@@ -20015,7 +20150,7 @@ async function furin({
|
|
|
20015
20150
|
}).cleanup(() => {
|
|
20016
20151
|
routeTopologyWatcher?.close();
|
|
20017
20152
|
routeTopologyWatcher = undefined;
|
|
20018
|
-
}).
|
|
20153
|
+
}).get("/_bun_hmr_entry/index.html", hmrEntry).get("/_bun_hmr_entry", hmrEntry).use(loggerPlugin).error(NotFound, async ({ request, server }) => renderRootNotFound(currentSnapshot().root, request, server?.url.origin)).afterHandle(({ set }) => {
|
|
20019
20154
|
const pending = consumePendingInvalidations();
|
|
20020
20155
|
if (pending.length > 0) {
|
|
20021
20156
|
set.headers["x-furin-revalidate"] = pending.join(",");
|
|
@@ -20030,7 +20165,7 @@ async function furin({
|
|
|
20030
20165
|
await routeTopologyWatcher?.refresh();
|
|
20031
20166
|
}
|
|
20032
20167
|
return currentSnapshot().routes;
|
|
20033
|
-
})).decorate(FURIN_RENDER_DECORATOR, dispatchNativeRoute).use(nativeRoutesApp).use(createNotFoundHandling(prefix, routes, root, async (notFoundContext) => {
|
|
20168
|
+
}, undefined, (route) => resolveCurrentDevRoute(route, currentSnapshot().root))).decorate(FURIN_RENDER_DECORATOR, dispatchNativeRoute).use(nativeRoutesApp).use(createNotFoundHandling(prefix, routes, root, async (notFoundContext) => {
|
|
20034
20169
|
const { pathname } = new URL(notFoundContext.request.url);
|
|
20035
20170
|
if (!nativeRouteRenderers.has(resolveInstanceByPath(pathname))) {
|
|
20036
20171
|
return;
|
|
@@ -20038,7 +20173,7 @@ async function furin({
|
|
|
20038
20173
|
return await dispatchNativeRoute(notFoundContext);
|
|
20039
20174
|
}));
|
|
20040
20175
|
registerInstance(instance);
|
|
20041
|
-
return createFurinPlugin(devApp);
|
|
20176
|
+
return createFurinPlugin(devApp, prefix);
|
|
20042
20177
|
}
|
|
20043
20178
|
if (!ctx) {
|
|
20044
20179
|
throw new Error("[furin] No pre-built assets found. Run `bunx furin build` first.");
|
|
@@ -20078,7 +20213,7 @@ async function furin({
|
|
|
20078
20213
|
await withInstance(instance, () => warmSSGCache(routes, root, origin, searchRoutes));
|
|
20079
20214
|
}).use(await createProductionAssetsPlugin(ctx, embedded, clientDir)).use(await createProductionBrowserEventsPlugin(sync)).use(sync ? (await Promise.resolve().then(() => (init_stream(), exports_stream))).createSyncChangesPlugin(sync) : new Elysia12).use(createDataEndpoint(routes, root)).decorate(FURIN_RENDER_DECORATOR, dispatchNativeRoute).use(ctx.nativeRoutes).use(createNotFoundHandling(prefix, routes, root));
|
|
20080
20215
|
registerInstance(instance);
|
|
20081
|
-
return createFurinPlugin(prodApp);
|
|
20216
|
+
return createFurinPlugin(prodApp, undefined);
|
|
20082
20217
|
}
|
|
20083
20218
|
function createNotFoundHandling(prefix, routes, root, tryNativeDispatch) {
|
|
20084
20219
|
const app = new Elysia12;
|
package/dist/rsc-client.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// src/shared/production-build.ts
|
|
3
|
+
var productionBuildScope;
|
|
4
|
+
function isProductionBuild() {
|
|
5
|
+
return productionBuildScope?.getStore() === true || typeof process !== "undefined" && false;
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
// src/rsc/render-error.ts
|
|
3
9
|
var INTERNAL_STACK_FRAMES = new Set([
|
|
4
10
|
"<anonymous>",
|
|
@@ -16,7 +22,9 @@ function errorStack(error) {
|
|
|
16
22
|
return error instanceof Error ? error.stack : undefined;
|
|
17
23
|
}
|
|
18
24
|
function renderErrorMessage(options) {
|
|
19
|
-
if (
|
|
25
|
+
if (isProductionBuild()) {
|
|
26
|
+
return `[furin/rsc] Server Component rendering failed inside ${options.operation}().`;
|
|
27
|
+
}
|
|
20
28
|
if (options.hook !== undefined && options.component !== undefined) {
|
|
21
29
|
const diagnostic = `[furin/rsc] A component rendered inside ${options.operation}()
|
|
22
30
|
used a client-only React hook.
|