@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/cli/index.js
CHANGED
|
@@ -270,7 +270,7 @@ function getBtoa() {
|
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
-
var
|
|
273
|
+
var btoa2 = /* @__PURE__ */ getBtoa();
|
|
274
274
|
|
|
275
275
|
class SourceMap {
|
|
276
276
|
constructor(properties) {
|
|
@@ -291,7 +291,7 @@ class SourceMap {
|
|
|
291
291
|
return JSON.stringify(this);
|
|
292
292
|
}
|
|
293
293
|
toUrl() {
|
|
294
|
-
return "data:application/json;charset=utf-8;base64," +
|
|
294
|
+
return "data:application/json;charset=utf-8;base64," + btoa2(this.toString());
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
function guessIndent(code) {
|
|
@@ -1158,16 +1158,41 @@ class MagicString {
|
|
|
1158
1158
|
|
|
1159
1159
|
// src/plugin/transform-client.ts
|
|
1160
1160
|
import { parse } from "yuku-parser";
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
jsxFactory: "React.createElement",
|
|
1167
|
-
jsxFragmentFactory: "React.Fragment"
|
|
1168
|
-
}
|
|
1161
|
+
|
|
1162
|
+
// src/lang-detect.ts
|
|
1163
|
+
function detectLangFromPath(filePath) {
|
|
1164
|
+
if (filePath.endsWith(".d.ts")) {
|
|
1165
|
+
return "dts";
|
|
1169
1166
|
}
|
|
1170
|
-
|
|
1167
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
1168
|
+
switch (ext) {
|
|
1169
|
+
case "ts":
|
|
1170
|
+
return "ts";
|
|
1171
|
+
case "tsx":
|
|
1172
|
+
return "tsx";
|
|
1173
|
+
case "jsx":
|
|
1174
|
+
return "jsx";
|
|
1175
|
+
default:
|
|
1176
|
+
return "js";
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
var TS_WRAPPER_TYPES = new Set([
|
|
1180
|
+
"TSAsExpression",
|
|
1181
|
+
"TSSatisfiesExpression",
|
|
1182
|
+
"TSTypeAssertion",
|
|
1183
|
+
"TSNonNullExpression",
|
|
1184
|
+
"TSInstantiationExpression",
|
|
1185
|
+
"ParenthesizedExpression"
|
|
1186
|
+
]);
|
|
1187
|
+
function unwrapTSExpression(node) {
|
|
1188
|
+
let current = node;
|
|
1189
|
+
while (current && typeof current === "object" && TS_WRAPPER_TYPES.has(current.type) && current.expression && typeof current.expression === "object") {
|
|
1190
|
+
current = current.expression;
|
|
1191
|
+
}
|
|
1192
|
+
return current;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// src/plugin/transform-client.ts
|
|
1171
1196
|
var SERVER_ONLY_PROPERTIES = new Set(["loader", "query", "params", "staticParams"]);
|
|
1172
1197
|
function walk(node, visitor) {
|
|
1173
1198
|
if (!node || typeof node !== "object") {
|
|
@@ -1251,6 +1276,45 @@ function removeServerProperties(s, source, obj) {
|
|
|
1251
1276
|
}
|
|
1252
1277
|
return true;
|
|
1253
1278
|
}
|
|
1279
|
+
var TYPE_SCOPE_NODES = new Set([
|
|
1280
|
+
"TSTypeAnnotation",
|
|
1281
|
+
"TSTypeParameterDeclaration",
|
|
1282
|
+
"TSTypeParameterInstantiation",
|
|
1283
|
+
"TSInterfaceDeclaration",
|
|
1284
|
+
"TSTypeAliasDeclaration",
|
|
1285
|
+
"TSTypePredicate",
|
|
1286
|
+
"TSClassImplements"
|
|
1287
|
+
]);
|
|
1288
|
+
function markTypeDescendants(node, excluded) {
|
|
1289
|
+
if (!node || typeof node !== "object") {
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
if (Array.isArray(node)) {
|
|
1293
|
+
for (const item of node) {
|
|
1294
|
+
markTypeDescendants(item, excluded);
|
|
1295
|
+
}
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
const n2 = node;
|
|
1299
|
+
if (n2.type === "Identifier" || n2.type === "JSXIdentifier") {
|
|
1300
|
+
excluded.add(n2);
|
|
1301
|
+
}
|
|
1302
|
+
for (const key of Object.keys(n2)) {
|
|
1303
|
+
if (key === "type" || key === "start" || key === "end") {
|
|
1304
|
+
continue;
|
|
1305
|
+
}
|
|
1306
|
+
markTypeDescendants(n2[key], excluded);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
function excludeTypePositionIdentifiers(node, excluded) {
|
|
1310
|
+
if (TYPE_SCOPE_NODES.has(node.type)) {
|
|
1311
|
+
markTypeDescendants(node, excluded);
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSTypeAssertion") {
|
|
1315
|
+
markTypeDescendants(node.typeAnnotation, excluded);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1254
1318
|
function collectReferencedNames(program) {
|
|
1255
1319
|
const refs = new Set;
|
|
1256
1320
|
const excluded = new Set;
|
|
@@ -1265,6 +1329,13 @@ function collectReferencedNames(program) {
|
|
|
1265
1329
|
if (node.type === "MemberExpression" && !node.computed) {
|
|
1266
1330
|
excluded.add(node.property);
|
|
1267
1331
|
}
|
|
1332
|
+
if (node.type === "JSXAttribute") {
|
|
1333
|
+
excluded.add(node.name);
|
|
1334
|
+
}
|
|
1335
|
+
if (node.type === "JSXMemberExpression") {
|
|
1336
|
+
excluded.add(node.property);
|
|
1337
|
+
}
|
|
1338
|
+
excludeTypePositionIdentifiers(node, excluded);
|
|
1268
1339
|
});
|
|
1269
1340
|
}
|
|
1270
1341
|
for (const stmt of program.body ?? []) {
|
|
@@ -1275,7 +1346,7 @@ function collectReferencedNames(program) {
|
|
|
1275
1346
|
if (excluded.has(node)) {
|
|
1276
1347
|
return;
|
|
1277
1348
|
}
|
|
1278
|
-
if (node.type === "Identifier" && typeof node.name === "string") {
|
|
1349
|
+
if ((node.type === "Identifier" || node.type === "JSXIdentifier") && typeof node.name === "string") {
|
|
1279
1350
|
refs.add(node.name);
|
|
1280
1351
|
}
|
|
1281
1352
|
});
|
|
@@ -1306,9 +1377,9 @@ function removeUnusedSpecifiers(s, code, decl, refs) {
|
|
|
1306
1377
|
s.remove(removeStart, removeEnd);
|
|
1307
1378
|
}
|
|
1308
1379
|
}
|
|
1309
|
-
function deadCodeElimination(s) {
|
|
1380
|
+
function deadCodeElimination(s, lang) {
|
|
1310
1381
|
const code = s.toString();
|
|
1311
|
-
const { program, diagnostics } = parse(code, { sourceType: "module" });
|
|
1382
|
+
const { program, diagnostics } = parse(code, { sourceType: "module", lang });
|
|
1312
1383
|
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
1313
1384
|
if (firstError) {
|
|
1314
1385
|
console.error("[furin] DCE: failed to parse transformed output:", firstError.message);
|
|
@@ -1349,7 +1420,7 @@ function removeServerExports(s, source, program) {
|
|
|
1349
1420
|
if (!isTargetCall(call)) {
|
|
1350
1421
|
return;
|
|
1351
1422
|
}
|
|
1352
|
-
const arg = call.arguments[0];
|
|
1423
|
+
const arg = call.arguments[0] ? unwrapTSExpression(call.arguments[0]) : undefined;
|
|
1353
1424
|
if (!arg || arg.type !== "ObjectExpression") {
|
|
1354
1425
|
return;
|
|
1355
1426
|
}
|
|
@@ -1360,16 +1431,19 @@ function removeServerExports(s, source, program) {
|
|
|
1360
1431
|
return removedServerCode;
|
|
1361
1432
|
}
|
|
1362
1433
|
function transformForClient(code, filename) {
|
|
1363
|
-
const
|
|
1364
|
-
|
|
1434
|
+
const lang = detectLangFromPath(filename);
|
|
1435
|
+
if (lang === "dts") {
|
|
1436
|
+
return { code, map: null, removedServerCode: false };
|
|
1437
|
+
}
|
|
1438
|
+
const { program, diagnostics } = parse(code, { sourceType: "module", lang });
|
|
1365
1439
|
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
1366
1440
|
if (firstError) {
|
|
1367
1441
|
throw new Error(`Failed to parse ${filename}: ${firstError.message}`);
|
|
1368
1442
|
}
|
|
1369
|
-
let s = new MagicString(
|
|
1370
|
-
const removedServerCode = removeServerExports(s,
|
|
1443
|
+
let s = new MagicString(code);
|
|
1444
|
+
const removedServerCode = removeServerExports(s, code, program);
|
|
1371
1445
|
if (removedServerCode) {
|
|
1372
|
-
s = deadCodeElimination(s);
|
|
1446
|
+
s = deadCodeElimination(s, lang);
|
|
1373
1447
|
}
|
|
1374
1448
|
return {
|
|
1375
1449
|
code: s.toString(),
|
|
@@ -1400,7 +1474,13 @@ function safeJson(value) {
|
|
|
1400
1474
|
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
1401
1475
|
}
|
|
1402
1476
|
function renderAttrs(obj) {
|
|
1403
|
-
|
|
1477
|
+
const parts = [];
|
|
1478
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
1479
|
+
if (v !== undefined) {
|
|
1480
|
+
parts.push(`${k}="${escapeHtml(String(v))}"`);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
return parts.join(" ");
|
|
1404
1484
|
}
|
|
1405
1485
|
function buildMetaParts(meta) {
|
|
1406
1486
|
const parts = [];
|
|
@@ -1473,13 +1553,15 @@ function generateIndexHtml() {
|
|
|
1473
1553
|
</html>
|
|
1474
1554
|
`;
|
|
1475
1555
|
}
|
|
1476
|
-
function generateProdIndexHtml(entryChunk, cssChunks, buildId, faviconHref) {
|
|
1556
|
+
function generateProdIndexHtml(entryChunk, cssChunks, buildId, faviconHref, staticMode) {
|
|
1477
1557
|
const cssLinks = cssChunks.map((c) => ` <link rel="stylesheet" crossorigin href="${c}">`).join(`
|
|
1478
1558
|
`);
|
|
1479
1559
|
const scriptTag = `<script type="module" crossorigin src="${entryChunk}"></script>`;
|
|
1480
1560
|
const buildIdMeta = buildId ? ` <meta name="furin-build-id" content="${escapeHtml(buildId)}">
|
|
1481
1561
|
` : "";
|
|
1482
1562
|
const faviconLink = faviconHref ? ` <link rel="icon" href="${escapeHtml(faviconHref)}">
|
|
1563
|
+
` : "";
|
|
1564
|
+
const modeMeta = staticMode ? ` <meta name="furin-mode" content="static">
|
|
1483
1565
|
` : "";
|
|
1484
1566
|
return `<!DOCTYPE html>
|
|
1485
1567
|
<html lang="en">
|
|
@@ -1487,7 +1569,7 @@ function generateProdIndexHtml(entryChunk, cssChunks, buildId, faviconHref) {
|
|
|
1487
1569
|
<meta charset="UTF-8">
|
|
1488
1570
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1489
1571
|
${THEME_INIT_SCRIPT}
|
|
1490
|
-
${buildIdMeta}${faviconLink}${cssLinks ? `${cssLinks}
|
|
1572
|
+
${buildIdMeta}${modeMeta}${faviconLink}${cssLinks ? `${cssLinks}
|
|
1491
1573
|
` : ""} <!--ssr-head-->
|
|
1492
1574
|
</head>
|
|
1493
1575
|
<body>
|
|
@@ -1555,6 +1637,8 @@ import { createElement } from "react";
|
|
|
1555
1637
|
import { initLogger, log } from "evlog";
|
|
1556
1638
|
import { createHttpLogDrain } from "evlog/http";
|
|
1557
1639
|
import { RouterProvider } from "@teyik0/furin/link";
|
|
1640
|
+
import { fromCrossJSON } from "@teyik0/furin/link";
|
|
1641
|
+
import type { SerovalNode } from "seroval";
|
|
1558
1642
|
import { route as root } from "${rootLayout.replace(/\\/g, "/")}";${conventionImportsBlock}
|
|
1559
1643
|
|
|
1560
1644
|
initLogger({ drain: createHttpLogDrain({ drain: { endpoint: ${logEndpoint} } }) });
|
|
@@ -1576,6 +1660,70 @@ const _match = routes.find((r) => r.regex.test(pathname));
|
|
|
1576
1660
|
// former does not \u2014 so the two cases fork on _match below.
|
|
1577
1661
|
const dataEl = document.getElementById("__FURIN_DATA__");
|
|
1578
1662
|
const loaderData = dataEl ? JSON.parse(dataEl.textContent || "{}") : {};
|
|
1663
|
+
|
|
1664
|
+
// \u2500\u2500 Deferred data hydration \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
1665
|
+
// window.__FURIN_DEFERRED__ is injected by the server when a loader returns
|
|
1666
|
+
// defer(). It carries:
|
|
1667
|
+
// - _chunks: raw CrossJSON chunks keyed by field name (from late <script> tags)
|
|
1668
|
+
// We deserialise each chunk with fromCrossJSON and create a Promise so <Await>
|
|
1669
|
+
// components receive a proper resolved Promise instead of the raw CrossJSON node.
|
|
1670
|
+
// Sync loader fields live exclusively in __FURIN_DATA__ (read above).
|
|
1671
|
+
interface FurinDeferredRegistry {
|
|
1672
|
+
_chunks: Record<string, { a: 0 | 1; v: SerovalNode }>;
|
|
1673
|
+
_deferredKeys: string[];
|
|
1674
|
+
_resolvers: Record<string, {
|
|
1675
|
+
promise: Promise<unknown>;
|
|
1676
|
+
reject: (reason: unknown) => void;
|
|
1677
|
+
resolve: (value: unknown) => void;
|
|
1678
|
+
}>;
|
|
1679
|
+
getPromise: (key: string) => Promise<unknown>;
|
|
1680
|
+
reject: (key: string, chunk: SerovalNode) => void;
|
|
1681
|
+
resolve: (key: string, chunk: SerovalNode) => void;
|
|
1682
|
+
}
|
|
1683
|
+
const __deferred = (window as unknown as { __FURIN_DEFERRED__?: FurinDeferredRegistry })
|
|
1684
|
+
.__FURIN_DEFERRED__;
|
|
1685
|
+
const deferredData: Record<string, Promise<unknown>> = {};
|
|
1686
|
+
if (__deferred && __deferred._chunks) {
|
|
1687
|
+
// Patch resolve/reject so any chunks that arrive AFTER this entry has run
|
|
1688
|
+
// settle immediately. The previous version stored late chunks in _chunks
|
|
1689
|
+
// when no resolver was registered yet, but the drain loop below only runs
|
|
1690
|
+
// ONCE at hydrate time \u2014 so any chunk landing after the drain would stay
|
|
1691
|
+
// orphaned and the corresponding Await would hang forever. Eagerly creating
|
|
1692
|
+
// the resolver via getPromise() fixes the race.
|
|
1693
|
+
__deferred.resolve = (key: string, chunk: SerovalNode) => {
|
|
1694
|
+
__deferred.getPromise(key);
|
|
1695
|
+
__deferred._resolvers[key].resolve(fromCrossJSON(chunk, {}));
|
|
1696
|
+
};
|
|
1697
|
+
__deferred.reject = (key: string, chunk: SerovalNode) => {
|
|
1698
|
+
__deferred.getPromise(key);
|
|
1699
|
+
__deferred._resolvers[key].reject(fromCrossJSON(chunk, {}));
|
|
1700
|
+
};
|
|
1701
|
+
for (const key of Object.keys(__deferred._chunks)) {
|
|
1702
|
+
const entry = __deferred._chunks[key] as { a: 0 | 1; v: SerovalNode };
|
|
1703
|
+
const p = __deferred.getPromise(key) as Promise<unknown>;
|
|
1704
|
+
const resolver = __deferred._resolvers[key];
|
|
1705
|
+
const value = fromCrossJSON(entry.v, {});
|
|
1706
|
+
if (entry.a === 0) {
|
|
1707
|
+
resolver.resolve(value);
|
|
1708
|
+
} else {
|
|
1709
|
+
resolver.reject(value);
|
|
1710
|
+
}
|
|
1711
|
+
deferredData[key] = p;
|
|
1712
|
+
}
|
|
1713
|
+
for (const key of __deferred._deferredKeys ?? []) {
|
|
1714
|
+
if (!(key in deferredData)) {
|
|
1715
|
+
deferredData[key] = __deferred.getPromise(key) as Promise<unknown>;
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
// Keys that have a resolver (getPromise was called by <Await>) but no
|
|
1719
|
+
// chunk yet (the late <script> hasn't arrived) still need a Promise entry
|
|
1720
|
+
// so the hydration data record is complete.
|
|
1721
|
+
for (const key of Object.keys(__deferred._resolvers ?? {})) {
|
|
1722
|
+
if (!(key in deferredData)) {
|
|
1723
|
+
deferredData[key] = __deferred.getPromise(key) as Promise<unknown>;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1579
1727
|
const rootEl = document.getElementById("root") as HTMLElement;
|
|
1580
1728
|
|
|
1581
1729
|
// Eagerly load only the current page module for initial hydration.
|
|
@@ -1594,7 +1742,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
1594
1742
|
routes,
|
|
1595
1743
|
root,
|
|
1596
1744
|
initialMatch: match,
|
|
1597
|
-
initialData: loaderData,
|
|
1745
|
+
initialData: { ...loaderData, ...deferredData },
|
|
1598
1746
|
initialDigest: loaderData.__furinError?.digest,
|
|
1599
1747
|
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${routerProviderDefaults}
|
|
1600
1748
|
} as any);
|
|
@@ -1721,7 +1869,6 @@ function buildTargetManifest(rootDir, buildRoot, target, serverEntry) {
|
|
|
1721
1869
|
|
|
1722
1870
|
// src/build/client.ts
|
|
1723
1871
|
var TS_FILE_FILTER = /\.(tsx|ts)$/;
|
|
1724
|
-
var REACT_IMPORT_RE = /import\s+React\b/;
|
|
1725
1872
|
async function buildClient(routes, { outDir, rootLayout, plugins, publicPath, basePath }) {
|
|
1726
1873
|
const clientDir = join2(outDir, "client");
|
|
1727
1874
|
if (!existsSync2(outDir)) {
|
|
@@ -1745,12 +1892,7 @@ async function buildClient(routes, { outDir, rootLayout, plugins, publicPath, ba
|
|
|
1745
1892
|
const code = await Bun.file(path).text();
|
|
1746
1893
|
try {
|
|
1747
1894
|
const result2 = transformForClient(code, path);
|
|
1748
|
-
|
|
1749
|
-
if (transformed.includes("React.createElement") && !REACT_IMPORT_RE.test(transformed)) {
|
|
1750
|
-
transformed = `import React from "react";
|
|
1751
|
-
${transformed}`;
|
|
1752
|
-
}
|
|
1753
|
-
transformed = transformed.replaceAll(`"@teyik0/furin/client"`, JSON.stringify(CLIENT_MODULE_PATH)).replaceAll(`'furin/client'`, JSON.stringify(CLIENT_MODULE_PATH)).replaceAll(`"@teyik0/furin/link"`, JSON.stringify(LINK_MODULE_PATH)).replaceAll(`'furin/link'`, JSON.stringify(LINK_MODULE_PATH));
|
|
1895
|
+
const transformed = result2.code.replaceAll(`"@teyik0/furin/client"`, JSON.stringify(CLIENT_MODULE_PATH)).replaceAll(`'furin/client'`, JSON.stringify(CLIENT_MODULE_PATH)).replaceAll(`"@teyik0/furin/link"`, JSON.stringify(LINK_MODULE_PATH)).replaceAll(`'furin/link'`, JSON.stringify(LINK_MODULE_PATH));
|
|
1754
1896
|
return {
|
|
1755
1897
|
contents: transformed,
|
|
1756
1898
|
loader: path.endsWith(".tsx") ? "tsx" : "ts"
|
|
@@ -2031,12 +2173,12 @@ async function createBuildFingerprint(entryChunk, cssChunks, routes, root, serve
|
|
|
2031
2173
|
}
|
|
2032
2174
|
fingerprintPaths.add(path);
|
|
2033
2175
|
}
|
|
2034
|
-
const fileParts = await Promise.all([...fingerprintPaths].
|
|
2176
|
+
const fileParts = await Promise.all([...fingerprintPaths].toSorted().map(async (path) => {
|
|
2035
2177
|
const content = existsSync5(path) ? await Bun.file(path).text() : "";
|
|
2036
2178
|
return `${toPosixPath(path)}:${content}`;
|
|
2037
2179
|
}));
|
|
2038
2180
|
const routeParts = routes.map((route) => JSON.stringify({ mode: route.mode, path: toPosixPath(route.path), pattern: route.pattern })).sort();
|
|
2039
|
-
return [entryChunk, ...[...cssChunks].
|
|
2181
|
+
return [entryChunk, ...[...cssChunks].toSorted(), ...routeParts, ...fileParts].join(`
|
|
2040
2182
|
`);
|
|
2041
2183
|
}
|
|
2042
2184
|
function buildCompileMetadata(root, routes) {
|
|
@@ -2077,7 +2219,7 @@ async function buildBunTarget(routes, rootDir, buildRoot, root, serverEntry, opt
|
|
|
2077
2219
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
2078
2220
|
targetManifest.buildId = buildId;
|
|
2079
2221
|
const clientDir = join6(targetDir, "client");
|
|
2080
|
-
writeFileSync4(join6(clientDir, "index.html"), generateProdIndexHtml(entryChunk, cssChunks, buildId));
|
|
2222
|
+
writeFileSync4(join6(clientDir, "index.html"), generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false));
|
|
2081
2223
|
const routeManifest = routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode }));
|
|
2082
2224
|
const publicDir = existsSync5(join6(rootDir, "public")) ? join6(rootDir, "public") : undefined;
|
|
2083
2225
|
const targetPublicDir = publicDir ? join6(targetDir, "public") : undefined;
|
|
@@ -2191,6 +2333,1045 @@ function assembleHTML(template, headData, reactHtml, data) {
|
|
|
2191
2333
|
import { createElement as createElement3 } from "react";
|
|
2192
2334
|
import { renderToReadableStream } from "react-dom/server";
|
|
2193
2335
|
|
|
2336
|
+
// ../../node_modules/.bun/seroval@1.5.4/node_modules/seroval/dist/esm/development/index.mjs
|
|
2337
|
+
var ALL_ENABLED = 1 | 2 | 4 | 8 | 16 | 32;
|
|
2338
|
+
var SYM_ASYNC_ITERATOR = Symbol.asyncIterator;
|
|
2339
|
+
var SYM_HAS_INSTANCE = Symbol.hasInstance;
|
|
2340
|
+
var SYM_IS_CONCAT_SPREADABLE = Symbol.isConcatSpreadable;
|
|
2341
|
+
var SYM_ITERATOR = Symbol.iterator;
|
|
2342
|
+
var SYM_MATCH = Symbol.match;
|
|
2343
|
+
var SYM_MATCH_ALL = Symbol.matchAll;
|
|
2344
|
+
var SYM_REPLACE = Symbol.replace;
|
|
2345
|
+
var SYM_SEARCH = Symbol.search;
|
|
2346
|
+
var SYM_SPECIES = Symbol.species;
|
|
2347
|
+
var SYM_SPLIT = Symbol.split;
|
|
2348
|
+
var SYM_TO_PRIMITIVE = Symbol.toPrimitive;
|
|
2349
|
+
var SYM_TO_STRING_TAG = Symbol.toStringTag;
|
|
2350
|
+
var SYM_UNSCOPABLES = Symbol.unscopables;
|
|
2351
|
+
var INV_SYMBOL_REF = {
|
|
2352
|
+
[SYM_ASYNC_ITERATOR]: 0,
|
|
2353
|
+
[SYM_HAS_INSTANCE]: 1,
|
|
2354
|
+
[SYM_IS_CONCAT_SPREADABLE]: 2,
|
|
2355
|
+
[SYM_ITERATOR]: 3,
|
|
2356
|
+
[SYM_MATCH]: 4,
|
|
2357
|
+
[SYM_MATCH_ALL]: 5,
|
|
2358
|
+
[SYM_REPLACE]: 6,
|
|
2359
|
+
[SYM_SEARCH]: 7,
|
|
2360
|
+
[SYM_SPECIES]: 8,
|
|
2361
|
+
[SYM_SPLIT]: 9,
|
|
2362
|
+
[SYM_TO_PRIMITIVE]: 10,
|
|
2363
|
+
[SYM_TO_STRING_TAG]: 11,
|
|
2364
|
+
[SYM_UNSCOPABLES]: 12
|
|
2365
|
+
};
|
|
2366
|
+
var NIL = undefined;
|
|
2367
|
+
var CONSTANT_VAL = {
|
|
2368
|
+
[2]: true,
|
|
2369
|
+
[3]: false,
|
|
2370
|
+
[1]: NIL,
|
|
2371
|
+
[0]: null,
|
|
2372
|
+
[4]: -0,
|
|
2373
|
+
[5]: Number.POSITIVE_INFINITY,
|
|
2374
|
+
[6]: Number.NEGATIVE_INFINITY,
|
|
2375
|
+
[7]: Number.NaN
|
|
2376
|
+
};
|
|
2377
|
+
var ERROR_CONSTRUCTOR_STRING = {
|
|
2378
|
+
[0]: "Error",
|
|
2379
|
+
[1]: "EvalError",
|
|
2380
|
+
[2]: "RangeError",
|
|
2381
|
+
[3]: "ReferenceError",
|
|
2382
|
+
[4]: "SyntaxError",
|
|
2383
|
+
[5]: "TypeError",
|
|
2384
|
+
[6]: "URIError"
|
|
2385
|
+
};
|
|
2386
|
+
function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o, l) {
|
|
2387
|
+
return {
|
|
2388
|
+
t,
|
|
2389
|
+
i,
|
|
2390
|
+
s,
|
|
2391
|
+
c,
|
|
2392
|
+
m,
|
|
2393
|
+
p,
|
|
2394
|
+
e,
|
|
2395
|
+
a,
|
|
2396
|
+
f,
|
|
2397
|
+
b,
|
|
2398
|
+
o,
|
|
2399
|
+
l
|
|
2400
|
+
};
|
|
2401
|
+
}
|
|
2402
|
+
function createConstantNode(value) {
|
|
2403
|
+
return createSerovalNode(2, NIL, value, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2404
|
+
}
|
|
2405
|
+
var TRUE_NODE = /* @__PURE__ */ createConstantNode(2);
|
|
2406
|
+
var FALSE_NODE = /* @__PURE__ */ createConstantNode(3);
|
|
2407
|
+
var UNDEFINED_NODE = /* @__PURE__ */ createConstantNode(1);
|
|
2408
|
+
var NULL_NODE = /* @__PURE__ */ createConstantNode(0);
|
|
2409
|
+
var NEG_ZERO_NODE = /* @__PURE__ */ createConstantNode(4);
|
|
2410
|
+
var INFINITY_NODE = /* @__PURE__ */ createConstantNode(5);
|
|
2411
|
+
var NEG_INFINITY_NODE = /* @__PURE__ */ createConstantNode(6);
|
|
2412
|
+
var NAN_NODE = /* @__PURE__ */ createConstantNode(7);
|
|
2413
|
+
function serializeChar(str) {
|
|
2414
|
+
switch (str) {
|
|
2415
|
+
case '"':
|
|
2416
|
+
return "\\\"";
|
|
2417
|
+
case "\\":
|
|
2418
|
+
return "\\\\";
|
|
2419
|
+
case `
|
|
2420
|
+
`:
|
|
2421
|
+
return "\\n";
|
|
2422
|
+
case "\r":
|
|
2423
|
+
return "\\r";
|
|
2424
|
+
case "\b":
|
|
2425
|
+
return "\\b";
|
|
2426
|
+
case "\t":
|
|
2427
|
+
return "\\t";
|
|
2428
|
+
case "\f":
|
|
2429
|
+
return "\\f";
|
|
2430
|
+
case "<":
|
|
2431
|
+
return "\\x3C";
|
|
2432
|
+
case "\u2028":
|
|
2433
|
+
return "\\u2028";
|
|
2434
|
+
case "\u2029":
|
|
2435
|
+
return "\\u2029";
|
|
2436
|
+
default:
|
|
2437
|
+
return NIL;
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
function serializeString(str) {
|
|
2441
|
+
let result = "";
|
|
2442
|
+
let lastPos = 0;
|
|
2443
|
+
let replacement;
|
|
2444
|
+
for (let i = 0, len = str.length;i < len; i++) {
|
|
2445
|
+
replacement = serializeChar(str[i]);
|
|
2446
|
+
if (replacement) {
|
|
2447
|
+
result += str.slice(lastPos, i) + replacement;
|
|
2448
|
+
lastPos = i + 1;
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
if (lastPos === 0) {
|
|
2452
|
+
result = str;
|
|
2453
|
+
} else {
|
|
2454
|
+
result += str.slice(lastPos);
|
|
2455
|
+
}
|
|
2456
|
+
return result;
|
|
2457
|
+
}
|
|
2458
|
+
var REFERENCES_KEY = "__SEROVAL_REFS__";
|
|
2459
|
+
var GLOBAL_CONTEXT_REFERENCES = "$R";
|
|
2460
|
+
var GLOBAL_CONTEXT_R = `self.${GLOBAL_CONTEXT_REFERENCES}`;
|
|
2461
|
+
var REFERENCE = /* @__PURE__ */ new Map;
|
|
2462
|
+
var INV_REFERENCE = /* @__PURE__ */ new Map;
|
|
2463
|
+
function hasReferenceID(value) {
|
|
2464
|
+
return REFERENCE.has(value);
|
|
2465
|
+
}
|
|
2466
|
+
function getReferenceID(value) {
|
|
2467
|
+
if (hasReferenceID(value)) {
|
|
2468
|
+
return REFERENCE.get(value);
|
|
2469
|
+
}
|
|
2470
|
+
throw new SerovalMissingReferenceError(value);
|
|
2471
|
+
}
|
|
2472
|
+
if (typeof globalThis !== "undefined") {
|
|
2473
|
+
Object.defineProperty(globalThis, REFERENCES_KEY, {
|
|
2474
|
+
value: INV_REFERENCE,
|
|
2475
|
+
configurable: true,
|
|
2476
|
+
writable: false,
|
|
2477
|
+
enumerable: false
|
|
2478
|
+
});
|
|
2479
|
+
} else if (typeof window !== "undefined") {
|
|
2480
|
+
Object.defineProperty(window, REFERENCES_KEY, {
|
|
2481
|
+
value: INV_REFERENCE,
|
|
2482
|
+
configurable: true,
|
|
2483
|
+
writable: false,
|
|
2484
|
+
enumerable: false
|
|
2485
|
+
});
|
|
2486
|
+
} else if (typeof self !== "undefined") {
|
|
2487
|
+
Object.defineProperty(self, REFERENCES_KEY, {
|
|
2488
|
+
value: INV_REFERENCE,
|
|
2489
|
+
configurable: true,
|
|
2490
|
+
writable: false,
|
|
2491
|
+
enumerable: false
|
|
2492
|
+
});
|
|
2493
|
+
} else if (typeof global !== "undefined") {
|
|
2494
|
+
Object.defineProperty(global, REFERENCES_KEY, {
|
|
2495
|
+
value: INV_REFERENCE,
|
|
2496
|
+
configurable: true,
|
|
2497
|
+
writable: false,
|
|
2498
|
+
enumerable: false
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
function getErrorConstructor(error) {
|
|
2502
|
+
if (error instanceof EvalError) {
|
|
2503
|
+
return 1;
|
|
2504
|
+
}
|
|
2505
|
+
if (error instanceof RangeError) {
|
|
2506
|
+
return 2;
|
|
2507
|
+
}
|
|
2508
|
+
if (error instanceof ReferenceError) {
|
|
2509
|
+
return 3;
|
|
2510
|
+
}
|
|
2511
|
+
if (error instanceof SyntaxError) {
|
|
2512
|
+
return 4;
|
|
2513
|
+
}
|
|
2514
|
+
if (error instanceof TypeError) {
|
|
2515
|
+
return 5;
|
|
2516
|
+
}
|
|
2517
|
+
if (error instanceof URIError) {
|
|
2518
|
+
return 6;
|
|
2519
|
+
}
|
|
2520
|
+
return 0;
|
|
2521
|
+
}
|
|
2522
|
+
function getInitialErrorOptions(error) {
|
|
2523
|
+
const construct = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
|
|
2524
|
+
if (error.name !== construct) {
|
|
2525
|
+
return { name: error.name };
|
|
2526
|
+
}
|
|
2527
|
+
if (error.constructor.name !== construct) {
|
|
2528
|
+
return { name: error.constructor.name };
|
|
2529
|
+
}
|
|
2530
|
+
return {};
|
|
2531
|
+
}
|
|
2532
|
+
function getErrorOptions(error, features) {
|
|
2533
|
+
let options = getInitialErrorOptions(error);
|
|
2534
|
+
const names = Object.getOwnPropertyNames(error);
|
|
2535
|
+
for (let i = 0, len = names.length, name;i < len; i++) {
|
|
2536
|
+
name = names[i];
|
|
2537
|
+
if (name !== "name" && name !== "message") {
|
|
2538
|
+
if (name === "stack") {
|
|
2539
|
+
if (features & 4) {
|
|
2540
|
+
options = options || {};
|
|
2541
|
+
options[name] = error[name];
|
|
2542
|
+
}
|
|
2543
|
+
} else {
|
|
2544
|
+
options = options || {};
|
|
2545
|
+
options[name] = error[name];
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
return options;
|
|
2550
|
+
}
|
|
2551
|
+
function getObjectFlag(obj) {
|
|
2552
|
+
if (Object.isFrozen(obj)) {
|
|
2553
|
+
return 3;
|
|
2554
|
+
}
|
|
2555
|
+
if (Object.isSealed(obj)) {
|
|
2556
|
+
return 2;
|
|
2557
|
+
}
|
|
2558
|
+
if (Object.isExtensible(obj)) {
|
|
2559
|
+
return 0;
|
|
2560
|
+
}
|
|
2561
|
+
return 1;
|
|
2562
|
+
}
|
|
2563
|
+
function createNumberNode(value) {
|
|
2564
|
+
switch (value) {
|
|
2565
|
+
case Number.POSITIVE_INFINITY:
|
|
2566
|
+
return INFINITY_NODE;
|
|
2567
|
+
case Number.NEGATIVE_INFINITY:
|
|
2568
|
+
return NEG_INFINITY_NODE;
|
|
2569
|
+
}
|
|
2570
|
+
if (value !== value) {
|
|
2571
|
+
return NAN_NODE;
|
|
2572
|
+
}
|
|
2573
|
+
if (Object.is(value, -0)) {
|
|
2574
|
+
return NEG_ZERO_NODE;
|
|
2575
|
+
}
|
|
2576
|
+
return createSerovalNode(0, NIL, value, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2577
|
+
}
|
|
2578
|
+
function createStringNode(value) {
|
|
2579
|
+
return createSerovalNode(1, NIL, serializeString(value), NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2580
|
+
}
|
|
2581
|
+
function createBigIntNode(current) {
|
|
2582
|
+
return createSerovalNode(3, NIL, "" + current, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2583
|
+
}
|
|
2584
|
+
function createIndexedValueNode(id) {
|
|
2585
|
+
return createSerovalNode(4, id, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2586
|
+
}
|
|
2587
|
+
function createDateNode(id, current) {
|
|
2588
|
+
const timestamp = current.valueOf();
|
|
2589
|
+
return createSerovalNode(5, id, timestamp !== timestamp ? "" : current.toISOString(), NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2590
|
+
}
|
|
2591
|
+
function createRegExpNode(id, current) {
|
|
2592
|
+
return createSerovalNode(6, id, NIL, serializeString(current.source), current.flags, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2593
|
+
}
|
|
2594
|
+
function createWKSymbolNode(id, current) {
|
|
2595
|
+
return createSerovalNode(17, id, INV_SYMBOL_REF[current], NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2596
|
+
}
|
|
2597
|
+
function createReferenceNode(id, ref) {
|
|
2598
|
+
return createSerovalNode(18, id, serializeString(getReferenceID(ref)), NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2599
|
+
}
|
|
2600
|
+
function createPluginNode(id, tag, value) {
|
|
2601
|
+
return createSerovalNode(25, id, value, serializeString(tag), NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2602
|
+
}
|
|
2603
|
+
function createArrayNode(id, current, parsedItems) {
|
|
2604
|
+
return createSerovalNode(9, id, NIL, NIL, NIL, NIL, NIL, parsedItems, NIL, NIL, getObjectFlag(current), NIL);
|
|
2605
|
+
}
|
|
2606
|
+
function createBoxedNode(id, boxed) {
|
|
2607
|
+
return createSerovalNode(21, id, NIL, NIL, NIL, NIL, NIL, NIL, boxed, NIL, NIL, NIL);
|
|
2608
|
+
}
|
|
2609
|
+
function createTypedArrayNode(id, current, buffer) {
|
|
2610
|
+
return createSerovalNode(15, id, NIL, current.constructor.name, NIL, NIL, NIL, NIL, buffer, current.byteOffset, NIL, current.length);
|
|
2611
|
+
}
|
|
2612
|
+
function createBigIntTypedArrayNode(id, current, buffer) {
|
|
2613
|
+
return createSerovalNode(16, id, NIL, current.constructor.name, NIL, NIL, NIL, NIL, buffer, current.byteOffset, NIL, current.byteLength);
|
|
2614
|
+
}
|
|
2615
|
+
function createDataViewNode(id, current, buffer) {
|
|
2616
|
+
return createSerovalNode(20, id, NIL, NIL, NIL, NIL, NIL, NIL, buffer, current.byteOffset, NIL, current.byteLength);
|
|
2617
|
+
}
|
|
2618
|
+
function createErrorNode(id, current, options) {
|
|
2619
|
+
return createSerovalNode(13, id, getErrorConstructor(current), NIL, serializeString(current.message), options, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2620
|
+
}
|
|
2621
|
+
function createAggregateErrorNode(id, current, options) {
|
|
2622
|
+
return createSerovalNode(14, id, getErrorConstructor(current), NIL, serializeString(current.message), options, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2623
|
+
}
|
|
2624
|
+
function createSetNode(id, items) {
|
|
2625
|
+
return createSerovalNode(7, id, NIL, NIL, NIL, NIL, NIL, items, NIL, NIL, NIL, NIL);
|
|
2626
|
+
}
|
|
2627
|
+
function createIteratorFactoryInstanceNode(factory, items) {
|
|
2628
|
+
return createSerovalNode(28, NIL, NIL, NIL, NIL, NIL, NIL, [factory, items], NIL, NIL, NIL, NIL);
|
|
2629
|
+
}
|
|
2630
|
+
function createAsyncIteratorFactoryInstanceNode(factory, items) {
|
|
2631
|
+
return createSerovalNode(30, NIL, NIL, NIL, NIL, NIL, NIL, [factory, items], NIL, NIL, NIL, NIL);
|
|
2632
|
+
}
|
|
2633
|
+
function createStreamConstructorNode(id, factory, sequence) {
|
|
2634
|
+
return createSerovalNode(31, id, NIL, NIL, NIL, NIL, NIL, sequence, factory, NIL, NIL, NIL);
|
|
2635
|
+
}
|
|
2636
|
+
function createStreamNextNode(id, parsed) {
|
|
2637
|
+
return createSerovalNode(32, id, NIL, NIL, NIL, NIL, NIL, NIL, parsed, NIL, NIL, NIL);
|
|
2638
|
+
}
|
|
2639
|
+
function createStreamThrowNode(id, parsed) {
|
|
2640
|
+
return createSerovalNode(33, id, NIL, NIL, NIL, NIL, NIL, NIL, parsed, NIL, NIL, NIL);
|
|
2641
|
+
}
|
|
2642
|
+
function createStreamReturnNode(id, parsed) {
|
|
2643
|
+
return createSerovalNode(34, id, NIL, NIL, NIL, NIL, NIL, NIL, parsed, NIL, NIL, NIL);
|
|
2644
|
+
}
|
|
2645
|
+
function createSequenceNode(id, sequence, throwAt, doneAt) {
|
|
2646
|
+
return createSerovalNode(35, id, throwAt, NIL, NIL, NIL, NIL, sequence, NIL, NIL, NIL, doneAt);
|
|
2647
|
+
}
|
|
2648
|
+
var { toString: objectToString } = Object.prototype;
|
|
2649
|
+
function getErrorMessageDev(type, cause) {
|
|
2650
|
+
if (cause instanceof Error) {
|
|
2651
|
+
return `Seroval caught an error during the ${type} process.
|
|
2652
|
+
|
|
2653
|
+
${cause.name}
|
|
2654
|
+
${cause.message}
|
|
2655
|
+
|
|
2656
|
+
- For more information, please check the "cause" property of this error.
|
|
2657
|
+
- If you believe this is an error in Seroval, please submit an issue at https://github.com/lxsmnsyc/seroval/issues/new`;
|
|
2658
|
+
}
|
|
2659
|
+
return `Seroval caught an error during the ${type} process.
|
|
2660
|
+
|
|
2661
|
+
"${objectToString.call(cause)}"
|
|
2662
|
+
|
|
2663
|
+
For more information, please check the "cause" property of this error.`;
|
|
2664
|
+
}
|
|
2665
|
+
var getErrorMessage = (type, cause) => getErrorMessageDev(type, cause);
|
|
2666
|
+
var SerovalError = class extends Error {
|
|
2667
|
+
constructor(type, cause) {
|
|
2668
|
+
super(getErrorMessage(type, cause));
|
|
2669
|
+
this.cause = cause;
|
|
2670
|
+
}
|
|
2671
|
+
};
|
|
2672
|
+
var SerovalParserError = class extends SerovalError {
|
|
2673
|
+
constructor(cause) {
|
|
2674
|
+
super("parsing", cause);
|
|
2675
|
+
}
|
|
2676
|
+
};
|
|
2677
|
+
var SerovalUnsupportedTypeError = class extends Error {
|
|
2678
|
+
constructor(value) {
|
|
2679
|
+
super(`The value ${objectToString.call(value)} of type "${typeof value}" cannot be parsed/serialized.
|
|
2680
|
+
|
|
2681
|
+
There are few workarounds for this problem:
|
|
2682
|
+
- Transform the value in a way that it can be serialized.
|
|
2683
|
+
- If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.`);
|
|
2684
|
+
this.value = value;
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
var SerovalMissingReferenceError = class extends Error {
|
|
2688
|
+
constructor(value) {
|
|
2689
|
+
super('Missing reference for the value "' + objectToString.call(value) + '" of type "' + typeof value + '"');
|
|
2690
|
+
this.value = value;
|
|
2691
|
+
}
|
|
2692
|
+
};
|
|
2693
|
+
var OpaqueReference = class {
|
|
2694
|
+
constructor(value, replacement) {
|
|
2695
|
+
this.value = value;
|
|
2696
|
+
this.replacement = replacement;
|
|
2697
|
+
}
|
|
2698
|
+
};
|
|
2699
|
+
var PROMISE_CONSTRUCTOR = () => {
|
|
2700
|
+
const resolver = {
|
|
2701
|
+
p: 0,
|
|
2702
|
+
s: 0,
|
|
2703
|
+
f: 0
|
|
2704
|
+
};
|
|
2705
|
+
resolver.p = new Promise((resolve2, reject) => {
|
|
2706
|
+
resolver.s = resolve2;
|
|
2707
|
+
resolver.f = reject;
|
|
2708
|
+
});
|
|
2709
|
+
return resolver;
|
|
2710
|
+
};
|
|
2711
|
+
var STREAM_CONSTRUCTOR = () => {
|
|
2712
|
+
const buffer = [];
|
|
2713
|
+
const listeners = [];
|
|
2714
|
+
let alive = true;
|
|
2715
|
+
let success = false;
|
|
2716
|
+
let count = 0;
|
|
2717
|
+
const flush = (value, mode, x) => {
|
|
2718
|
+
for (x = 0;x < count; x++) {
|
|
2719
|
+
if (listeners[x]) {
|
|
2720
|
+
listeners[x][mode](value);
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
};
|
|
2724
|
+
const up = (listener, x, z, current) => {
|
|
2725
|
+
for (x = 0, z = buffer.length;x < z; x++) {
|
|
2726
|
+
current = buffer[x];
|
|
2727
|
+
if (!alive && x === z - 1) {
|
|
2728
|
+
listener[success ? "return" : "throw"](current);
|
|
2729
|
+
} else {
|
|
2730
|
+
listener.next(current);
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
};
|
|
2734
|
+
const on = (listener, temp) => {
|
|
2735
|
+
if (alive) {
|
|
2736
|
+
temp = count++;
|
|
2737
|
+
listeners[temp] = listener;
|
|
2738
|
+
}
|
|
2739
|
+
up(listener);
|
|
2740
|
+
return () => {
|
|
2741
|
+
if (alive) {
|
|
2742
|
+
listeners[temp] = listeners[count];
|
|
2743
|
+
listeners[count--] = undefined;
|
|
2744
|
+
}
|
|
2745
|
+
};
|
|
2746
|
+
};
|
|
2747
|
+
return {
|
|
2748
|
+
__SEROVAL_STREAM__: true,
|
|
2749
|
+
on: (listener) => on(listener),
|
|
2750
|
+
next: (value) => {
|
|
2751
|
+
if (alive) {
|
|
2752
|
+
buffer.push(value);
|
|
2753
|
+
flush(value, "next");
|
|
2754
|
+
}
|
|
2755
|
+
},
|
|
2756
|
+
throw: (value) => {
|
|
2757
|
+
if (alive) {
|
|
2758
|
+
buffer.push(value);
|
|
2759
|
+
flush(value, "throw");
|
|
2760
|
+
alive = false;
|
|
2761
|
+
success = false;
|
|
2762
|
+
listeners.length = 0;
|
|
2763
|
+
}
|
|
2764
|
+
},
|
|
2765
|
+
return: (value) => {
|
|
2766
|
+
if (alive) {
|
|
2767
|
+
buffer.push(value);
|
|
2768
|
+
flush(value, "return");
|
|
2769
|
+
alive = false;
|
|
2770
|
+
success = true;
|
|
2771
|
+
listeners.length = 0;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
};
|
|
2775
|
+
};
|
|
2776
|
+
var ITERATOR_CONSTRUCTOR = (symbol) => (sequence) => () => {
|
|
2777
|
+
let index = 0;
|
|
2778
|
+
const instance = {
|
|
2779
|
+
[symbol]: () => instance,
|
|
2780
|
+
next: () => {
|
|
2781
|
+
if (index > sequence.d) {
|
|
2782
|
+
return {
|
|
2783
|
+
done: true,
|
|
2784
|
+
value: undefined
|
|
2785
|
+
};
|
|
2786
|
+
}
|
|
2787
|
+
const currentIndex = index++;
|
|
2788
|
+
const data = sequence.v[currentIndex];
|
|
2789
|
+
if (currentIndex === sequence.t) {
|
|
2790
|
+
throw data;
|
|
2791
|
+
}
|
|
2792
|
+
return {
|
|
2793
|
+
done: currentIndex === sequence.d,
|
|
2794
|
+
value: data
|
|
2795
|
+
};
|
|
2796
|
+
}
|
|
2797
|
+
};
|
|
2798
|
+
return instance;
|
|
2799
|
+
};
|
|
2800
|
+
var ASYNC_ITERATOR_CONSTRUCTOR = (symbol, createPromise) => (stream) => () => {
|
|
2801
|
+
let count = 0;
|
|
2802
|
+
let doneAt = -1;
|
|
2803
|
+
let isThrow = false;
|
|
2804
|
+
const buffer = [];
|
|
2805
|
+
const pending = [];
|
|
2806
|
+
const finalize = (i = 0, len = pending.length) => {
|
|
2807
|
+
for (;i < len; i++) {
|
|
2808
|
+
pending[i].s({
|
|
2809
|
+
done: true,
|
|
2810
|
+
value: undefined
|
|
2811
|
+
});
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
stream.on({
|
|
2815
|
+
next: (value) => {
|
|
2816
|
+
const temp = pending.shift();
|
|
2817
|
+
if (temp) {
|
|
2818
|
+
temp.s({ done: false, value });
|
|
2819
|
+
}
|
|
2820
|
+
buffer.push(value);
|
|
2821
|
+
},
|
|
2822
|
+
throw: (value) => {
|
|
2823
|
+
const temp = pending.shift();
|
|
2824
|
+
if (temp) {
|
|
2825
|
+
temp.f(value);
|
|
2826
|
+
}
|
|
2827
|
+
finalize();
|
|
2828
|
+
doneAt = buffer.length;
|
|
2829
|
+
isThrow = true;
|
|
2830
|
+
buffer.push(value);
|
|
2831
|
+
},
|
|
2832
|
+
return: (value) => {
|
|
2833
|
+
const temp = pending.shift();
|
|
2834
|
+
if (temp) {
|
|
2835
|
+
temp.s({ done: true, value });
|
|
2836
|
+
}
|
|
2837
|
+
finalize();
|
|
2838
|
+
doneAt = buffer.length;
|
|
2839
|
+
buffer.push(value);
|
|
2840
|
+
}
|
|
2841
|
+
});
|
|
2842
|
+
const instance = {
|
|
2843
|
+
[symbol]: () => instance,
|
|
2844
|
+
next: () => {
|
|
2845
|
+
if (doneAt === -1) {
|
|
2846
|
+
const index2 = count++;
|
|
2847
|
+
if (index2 >= buffer.length) {
|
|
2848
|
+
const temp = createPromise();
|
|
2849
|
+
pending.push(temp);
|
|
2850
|
+
return temp.p;
|
|
2851
|
+
}
|
|
2852
|
+
return {
|
|
2853
|
+
done: false,
|
|
2854
|
+
value: buffer[index2]
|
|
2855
|
+
};
|
|
2856
|
+
}
|
|
2857
|
+
if (count > doneAt) {
|
|
2858
|
+
return {
|
|
2859
|
+
done: true,
|
|
2860
|
+
value: undefined
|
|
2861
|
+
};
|
|
2862
|
+
}
|
|
2863
|
+
const index = count++;
|
|
2864
|
+
const value = buffer[index];
|
|
2865
|
+
if (index !== doneAt) {
|
|
2866
|
+
return {
|
|
2867
|
+
done: false,
|
|
2868
|
+
value
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
if (isThrow) {
|
|
2872
|
+
throw value;
|
|
2873
|
+
}
|
|
2874
|
+
return {
|
|
2875
|
+
done: true,
|
|
2876
|
+
value
|
|
2877
|
+
};
|
|
2878
|
+
}
|
|
2879
|
+
};
|
|
2880
|
+
return instance;
|
|
2881
|
+
};
|
|
2882
|
+
function isSequence(value) {
|
|
2883
|
+
return "__SEROVAL_SEQUENCE__" in value;
|
|
2884
|
+
}
|
|
2885
|
+
function createSequence(values, throwAt, doneAt) {
|
|
2886
|
+
return {
|
|
2887
|
+
__SEROVAL_SEQUENCE__: true,
|
|
2888
|
+
v: values,
|
|
2889
|
+
t: throwAt,
|
|
2890
|
+
d: doneAt
|
|
2891
|
+
};
|
|
2892
|
+
}
|
|
2893
|
+
function createSequenceFromIterable(source) {
|
|
2894
|
+
const values = [];
|
|
2895
|
+
let throwsAt = -1;
|
|
2896
|
+
let doneAt = -1;
|
|
2897
|
+
const iterator = source[SYM_ITERATOR]();
|
|
2898
|
+
while (true) {
|
|
2899
|
+
try {
|
|
2900
|
+
const value = iterator.next();
|
|
2901
|
+
values.push(value.value);
|
|
2902
|
+
if (value.done) {
|
|
2903
|
+
doneAt = values.length - 1;
|
|
2904
|
+
break;
|
|
2905
|
+
}
|
|
2906
|
+
} catch (error) {
|
|
2907
|
+
throwsAt = values.length;
|
|
2908
|
+
values.push(error);
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
return createSequence(values, throwsAt, doneAt);
|
|
2912
|
+
}
|
|
2913
|
+
var createIterator = ITERATOR_CONSTRUCTOR(SYM_ITERATOR);
|
|
2914
|
+
var ITERATOR = {};
|
|
2915
|
+
var ASYNC_ITERATOR = {};
|
|
2916
|
+
var SPECIAL_REFS = {
|
|
2917
|
+
[0]: {},
|
|
2918
|
+
[1]: {},
|
|
2919
|
+
[2]: {},
|
|
2920
|
+
[3]: {},
|
|
2921
|
+
[4]: {},
|
|
2922
|
+
[5]: {}
|
|
2923
|
+
};
|
|
2924
|
+
function isStream(value) {
|
|
2925
|
+
return "__SEROVAL_STREAM__" in value;
|
|
2926
|
+
}
|
|
2927
|
+
function createStream() {
|
|
2928
|
+
return STREAM_CONSTRUCTOR();
|
|
2929
|
+
}
|
|
2930
|
+
function createStreamFromAsyncIterable(iterable) {
|
|
2931
|
+
const stream = createStream();
|
|
2932
|
+
const iterator = iterable[SYM_ASYNC_ITERATOR]();
|
|
2933
|
+
async function push() {
|
|
2934
|
+
try {
|
|
2935
|
+
const value = await iterator.next();
|
|
2936
|
+
if (value.done) {
|
|
2937
|
+
stream.return(value.value);
|
|
2938
|
+
} else {
|
|
2939
|
+
stream.next(value.value);
|
|
2940
|
+
await push();
|
|
2941
|
+
}
|
|
2942
|
+
} catch (error) {
|
|
2943
|
+
stream.throw(error);
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
push().catch(() => {});
|
|
2947
|
+
return stream;
|
|
2948
|
+
}
|
|
2949
|
+
var createAsyncIterable = ASYNC_ITERATOR_CONSTRUCTOR(SYM_ASYNC_ITERATOR, PROMISE_CONSTRUCTOR);
|
|
2950
|
+
async function promiseToResult(current) {
|
|
2951
|
+
try {
|
|
2952
|
+
return [1, await current];
|
|
2953
|
+
} catch (e) {
|
|
2954
|
+
return [0, e];
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
function createBaseParserContext(mode, options) {
|
|
2958
|
+
return {
|
|
2959
|
+
plugins: options.plugins,
|
|
2960
|
+
mode,
|
|
2961
|
+
marked: /* @__PURE__ */ new Set,
|
|
2962
|
+
features: ALL_ENABLED ^ (options.disabledFeatures || 0),
|
|
2963
|
+
refs: options.refs || /* @__PURE__ */ new Map,
|
|
2964
|
+
depthLimit: options.depthLimit || 1000
|
|
2965
|
+
};
|
|
2966
|
+
}
|
|
2967
|
+
function markParserRef(ctx, id) {
|
|
2968
|
+
ctx.marked.add(id);
|
|
2969
|
+
}
|
|
2970
|
+
function createIndexForValue(ctx, current) {
|
|
2971
|
+
const id = ctx.refs.size;
|
|
2972
|
+
ctx.refs.set(current, id);
|
|
2973
|
+
return id;
|
|
2974
|
+
}
|
|
2975
|
+
function getNodeForIndexedValue(ctx, current) {
|
|
2976
|
+
const registeredId = ctx.refs.get(current);
|
|
2977
|
+
if (registeredId != null) {
|
|
2978
|
+
markParserRef(ctx, registeredId);
|
|
2979
|
+
return {
|
|
2980
|
+
type: 1,
|
|
2981
|
+
value: createIndexedValueNode(registeredId)
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
return {
|
|
2985
|
+
type: 0,
|
|
2986
|
+
value: createIndexForValue(ctx, current)
|
|
2987
|
+
};
|
|
2988
|
+
}
|
|
2989
|
+
function getReferenceNode(ctx, current) {
|
|
2990
|
+
const indexed = getNodeForIndexedValue(ctx, current);
|
|
2991
|
+
if (indexed.type === 1) {
|
|
2992
|
+
return indexed;
|
|
2993
|
+
}
|
|
2994
|
+
if (hasReferenceID(current)) {
|
|
2995
|
+
return {
|
|
2996
|
+
type: 2,
|
|
2997
|
+
value: createReferenceNode(indexed.value, current)
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
return indexed;
|
|
3001
|
+
}
|
|
3002
|
+
function parseWellKnownSymbol(ctx, current) {
|
|
3003
|
+
const ref = getReferenceNode(ctx, current);
|
|
3004
|
+
if (ref.type !== 0) {
|
|
3005
|
+
return ref.value;
|
|
3006
|
+
}
|
|
3007
|
+
if (current in INV_SYMBOL_REF) {
|
|
3008
|
+
return createWKSymbolNode(ref.value, current);
|
|
3009
|
+
}
|
|
3010
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
3011
|
+
}
|
|
3012
|
+
function parseSpecialReference(ctx, ref) {
|
|
3013
|
+
const result = getNodeForIndexedValue(ctx, SPECIAL_REFS[ref]);
|
|
3014
|
+
if (result.type === 1) {
|
|
3015
|
+
return result.value;
|
|
3016
|
+
}
|
|
3017
|
+
return createSerovalNode(26, result.value, ref, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
3018
|
+
}
|
|
3019
|
+
function parseIteratorFactory(ctx) {
|
|
3020
|
+
const result = getNodeForIndexedValue(ctx, ITERATOR);
|
|
3021
|
+
if (result.type === 1) {
|
|
3022
|
+
return result.value;
|
|
3023
|
+
}
|
|
3024
|
+
return createSerovalNode(27, result.value, NIL, NIL, NIL, NIL, NIL, NIL, parseWellKnownSymbol(ctx, SYM_ITERATOR), NIL, NIL, NIL);
|
|
3025
|
+
}
|
|
3026
|
+
function parseAsyncIteratorFactory(ctx) {
|
|
3027
|
+
const result = getNodeForIndexedValue(ctx, ASYNC_ITERATOR);
|
|
3028
|
+
if (result.type === 1) {
|
|
3029
|
+
return result.value;
|
|
3030
|
+
}
|
|
3031
|
+
return createSerovalNode(29, result.value, NIL, NIL, NIL, NIL, NIL, [
|
|
3032
|
+
parseSpecialReference(ctx, 1),
|
|
3033
|
+
parseWellKnownSymbol(ctx, SYM_ASYNC_ITERATOR)
|
|
3034
|
+
], NIL, NIL, NIL, NIL);
|
|
3035
|
+
}
|
|
3036
|
+
function createObjectNode(id, current, empty, record) {
|
|
3037
|
+
return createSerovalNode(empty ? 11 : 10, id, NIL, NIL, NIL, record, NIL, NIL, NIL, NIL, getObjectFlag(current), NIL);
|
|
3038
|
+
}
|
|
3039
|
+
function createMapNode(ctx, id, k, v) {
|
|
3040
|
+
return createSerovalNode(8, id, NIL, NIL, NIL, NIL, { k, v }, NIL, parseSpecialReference(ctx, 0), NIL, NIL, NIL);
|
|
3041
|
+
}
|
|
3042
|
+
function createArrayBufferNode(ctx, id, current) {
|
|
3043
|
+
const bytes = new Uint8Array(current);
|
|
3044
|
+
let result = "";
|
|
3045
|
+
for (let i = 0, len = bytes.length;i < len; i++) {
|
|
3046
|
+
result += String.fromCharCode(bytes[i]);
|
|
3047
|
+
}
|
|
3048
|
+
return createSerovalNode(19, id, serializeString(btoa(result)), NIL, NIL, NIL, NIL, NIL, parseSpecialReference(ctx, 5), NIL, NIL, NIL);
|
|
3049
|
+
}
|
|
3050
|
+
function createAsyncParserContext(mode, options) {
|
|
3051
|
+
return {
|
|
3052
|
+
base: createBaseParserContext(mode, options),
|
|
3053
|
+
child: undefined
|
|
3054
|
+
};
|
|
3055
|
+
}
|
|
3056
|
+
var AsyncParsePluginContext = class {
|
|
3057
|
+
constructor(_p, depth) {
|
|
3058
|
+
this._p = _p;
|
|
3059
|
+
this.depth = depth;
|
|
3060
|
+
}
|
|
3061
|
+
parse(current) {
|
|
3062
|
+
return parseAsync(this._p, this.depth, current);
|
|
3063
|
+
}
|
|
3064
|
+
};
|
|
3065
|
+
async function parseItems(ctx, depth, current) {
|
|
3066
|
+
const nodes = [];
|
|
3067
|
+
for (let i = 0, len = current.length;i < len; i++) {
|
|
3068
|
+
if (i in current) {
|
|
3069
|
+
nodes[i] = await parseAsync(ctx, depth, current[i]);
|
|
3070
|
+
} else {
|
|
3071
|
+
nodes[i] = 0;
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
return nodes;
|
|
3075
|
+
}
|
|
3076
|
+
async function parseArray(ctx, depth, id, current) {
|
|
3077
|
+
return createArrayNode(id, current, await parseItems(ctx, depth, current));
|
|
3078
|
+
}
|
|
3079
|
+
async function parseProperties(ctx, depth, properties) {
|
|
3080
|
+
const entries = Object.entries(properties);
|
|
3081
|
+
const keyNodes = [];
|
|
3082
|
+
const valueNodes = [];
|
|
3083
|
+
for (let i = 0, len = entries.length;i < len; i++) {
|
|
3084
|
+
keyNodes.push(serializeString(entries[i][0]));
|
|
3085
|
+
valueNodes.push(await parseAsync(ctx, depth, entries[i][1]));
|
|
3086
|
+
}
|
|
3087
|
+
if (SYM_ITERATOR in properties) {
|
|
3088
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ITERATOR));
|
|
3089
|
+
valueNodes.push(createIteratorFactoryInstanceNode(parseIteratorFactory(ctx.base), await parseAsync(ctx, depth, createSequenceFromIterable(properties))));
|
|
3090
|
+
}
|
|
3091
|
+
if (SYM_ASYNC_ITERATOR in properties) {
|
|
3092
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
|
|
3093
|
+
valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), await parseAsync(ctx, depth, createStreamFromAsyncIterable(properties))));
|
|
3094
|
+
}
|
|
3095
|
+
if (SYM_TO_STRING_TAG in properties) {
|
|
3096
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
|
|
3097
|
+
valueNodes.push(createStringNode(properties[SYM_TO_STRING_TAG]));
|
|
3098
|
+
}
|
|
3099
|
+
if (SYM_IS_CONCAT_SPREADABLE in properties) {
|
|
3100
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_IS_CONCAT_SPREADABLE));
|
|
3101
|
+
valueNodes.push(properties[SYM_IS_CONCAT_SPREADABLE] ? TRUE_NODE : FALSE_NODE);
|
|
3102
|
+
}
|
|
3103
|
+
return {
|
|
3104
|
+
k: keyNodes,
|
|
3105
|
+
v: valueNodes
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
async function parsePlainObject(ctx, depth, id, current, empty) {
|
|
3109
|
+
return createObjectNode(id, current, empty, await parseProperties(ctx, depth, current));
|
|
3110
|
+
}
|
|
3111
|
+
async function parseBoxed(ctx, depth, id, current) {
|
|
3112
|
+
return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
|
|
3113
|
+
}
|
|
3114
|
+
async function parseTypedArray(ctx, depth, id, current) {
|
|
3115
|
+
return createTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
3116
|
+
}
|
|
3117
|
+
async function parseBigIntTypedArray(ctx, depth, id, current) {
|
|
3118
|
+
return createBigIntTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
3119
|
+
}
|
|
3120
|
+
async function parseDataView(ctx, depth, id, current) {
|
|
3121
|
+
return createDataViewNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
3122
|
+
}
|
|
3123
|
+
async function parseError(ctx, depth, id, current) {
|
|
3124
|
+
const options = getErrorOptions(current, ctx.base.features);
|
|
3125
|
+
return createErrorNode(id, current, options ? await parseProperties(ctx, depth, options) : NIL);
|
|
3126
|
+
}
|
|
3127
|
+
async function parseAggregateError(ctx, depth, id, current) {
|
|
3128
|
+
const options = getErrorOptions(current, ctx.base.features);
|
|
3129
|
+
return createAggregateErrorNode(id, current, options ? await parseProperties(ctx, depth, options) : NIL);
|
|
3130
|
+
}
|
|
3131
|
+
async function parseMap(ctx, depth, id, current) {
|
|
3132
|
+
const keyNodes = [];
|
|
3133
|
+
const valueNodes = [];
|
|
3134
|
+
for (const [key, value] of current.entries()) {
|
|
3135
|
+
keyNodes.push(await parseAsync(ctx, depth, key));
|
|
3136
|
+
valueNodes.push(await parseAsync(ctx, depth, value));
|
|
3137
|
+
}
|
|
3138
|
+
return createMapNode(ctx.base, id, keyNodes, valueNodes);
|
|
3139
|
+
}
|
|
3140
|
+
async function parseSet(ctx, depth, id, current) {
|
|
3141
|
+
const items = [];
|
|
3142
|
+
for (const item of current.keys()) {
|
|
3143
|
+
items.push(await parseAsync(ctx, depth, item));
|
|
3144
|
+
}
|
|
3145
|
+
return createSetNode(id, items);
|
|
3146
|
+
}
|
|
3147
|
+
async function parsePlugin(ctx, depth, id, current) {
|
|
3148
|
+
const currentPlugins = ctx.base.plugins;
|
|
3149
|
+
if (currentPlugins) {
|
|
3150
|
+
for (let i = 0, len = currentPlugins.length;i < len; i++) {
|
|
3151
|
+
const plugin = currentPlugins[i];
|
|
3152
|
+
if (plugin.parse.async && plugin.test(current)) {
|
|
3153
|
+
return createPluginNode(id, plugin.tag, await plugin.parse.async(current, new AsyncParsePluginContext(ctx, depth), {
|
|
3154
|
+
id
|
|
3155
|
+
}));
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
return NIL;
|
|
3160
|
+
}
|
|
3161
|
+
async function parsePromise(ctx, depth, id, current) {
|
|
3162
|
+
const [status, result] = await promiseToResult(current);
|
|
3163
|
+
return createSerovalNode(12, id, status, NIL, NIL, NIL, NIL, NIL, await parseAsync(ctx, depth, result), NIL, NIL, NIL);
|
|
3164
|
+
}
|
|
3165
|
+
function parseStreamHandle(depth, id, current, resolve2, reject) {
|
|
3166
|
+
const sequence = [];
|
|
3167
|
+
const cleanup = current.on({
|
|
3168
|
+
next: (value) => {
|
|
3169
|
+
markParserRef(this.base, id);
|
|
3170
|
+
parseAsync(this, depth, value).then((data) => {
|
|
3171
|
+
sequence.push(createStreamNextNode(id, data));
|
|
3172
|
+
}, (data) => {
|
|
3173
|
+
reject(data);
|
|
3174
|
+
cleanup();
|
|
3175
|
+
});
|
|
3176
|
+
},
|
|
3177
|
+
throw: (value) => {
|
|
3178
|
+
markParserRef(this.base, id);
|
|
3179
|
+
parseAsync(this, depth, value).then((data) => {
|
|
3180
|
+
sequence.push(createStreamThrowNode(id, data));
|
|
3181
|
+
resolve2(sequence);
|
|
3182
|
+
cleanup();
|
|
3183
|
+
}, (data) => {
|
|
3184
|
+
reject(data);
|
|
3185
|
+
cleanup();
|
|
3186
|
+
});
|
|
3187
|
+
},
|
|
3188
|
+
return: (value) => {
|
|
3189
|
+
markParserRef(this.base, id);
|
|
3190
|
+
parseAsync(this, depth, value).then((data) => {
|
|
3191
|
+
sequence.push(createStreamReturnNode(id, data));
|
|
3192
|
+
resolve2(sequence);
|
|
3193
|
+
cleanup();
|
|
3194
|
+
}, (data) => {
|
|
3195
|
+
reject(data);
|
|
3196
|
+
cleanup();
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
});
|
|
3200
|
+
}
|
|
3201
|
+
async function parseStream(ctx, depth, id, current) {
|
|
3202
|
+
return createStreamConstructorNode(id, parseSpecialReference(ctx.base, 4), await new Promise(parseStreamHandle.bind(ctx, depth, id, current)));
|
|
3203
|
+
}
|
|
3204
|
+
async function parseSequence(ctx, depth, id, current) {
|
|
3205
|
+
const nodes = [];
|
|
3206
|
+
for (let i = 0, len = current.v.length;i < len; i++) {
|
|
3207
|
+
nodes[i] = await parseAsync(ctx, depth, current.v[i]);
|
|
3208
|
+
}
|
|
3209
|
+
return createSequenceNode(id, nodes, current.t, current.d);
|
|
3210
|
+
}
|
|
3211
|
+
async function parseObjectAsync(ctx, depth, id, current) {
|
|
3212
|
+
if (Array.isArray(current)) {
|
|
3213
|
+
return parseArray(ctx, depth, id, current);
|
|
3214
|
+
}
|
|
3215
|
+
if (isStream(current)) {
|
|
3216
|
+
return parseStream(ctx, depth, id, current);
|
|
3217
|
+
}
|
|
3218
|
+
if (isSequence(current)) {
|
|
3219
|
+
return parseSequence(ctx, depth, id, current);
|
|
3220
|
+
}
|
|
3221
|
+
const currentClass = current.constructor;
|
|
3222
|
+
if (currentClass === OpaqueReference) {
|
|
3223
|
+
return parseAsync(ctx, depth, current.replacement);
|
|
3224
|
+
}
|
|
3225
|
+
const parsed = await parsePlugin(ctx, depth, id, current);
|
|
3226
|
+
if (parsed) {
|
|
3227
|
+
return parsed;
|
|
3228
|
+
}
|
|
3229
|
+
switch (currentClass) {
|
|
3230
|
+
case Object:
|
|
3231
|
+
return parsePlainObject(ctx, depth, id, current, false);
|
|
3232
|
+
case NIL:
|
|
3233
|
+
return parsePlainObject(ctx, depth, id, current, true);
|
|
3234
|
+
case Date:
|
|
3235
|
+
return createDateNode(id, current);
|
|
3236
|
+
case Error:
|
|
3237
|
+
case EvalError:
|
|
3238
|
+
case RangeError:
|
|
3239
|
+
case ReferenceError:
|
|
3240
|
+
case SyntaxError:
|
|
3241
|
+
case TypeError:
|
|
3242
|
+
case URIError:
|
|
3243
|
+
return parseError(ctx, depth, id, current);
|
|
3244
|
+
case Number:
|
|
3245
|
+
case Boolean:
|
|
3246
|
+
case String:
|
|
3247
|
+
case BigInt:
|
|
3248
|
+
return parseBoxed(ctx, depth, id, current);
|
|
3249
|
+
case ArrayBuffer:
|
|
3250
|
+
return createArrayBufferNode(ctx.base, id, current);
|
|
3251
|
+
case Int8Array:
|
|
3252
|
+
case Int16Array:
|
|
3253
|
+
case Int32Array:
|
|
3254
|
+
case Uint8Array:
|
|
3255
|
+
case Uint16Array:
|
|
3256
|
+
case Uint32Array:
|
|
3257
|
+
case Uint8ClampedArray:
|
|
3258
|
+
case Float32Array:
|
|
3259
|
+
case Float64Array:
|
|
3260
|
+
return parseTypedArray(ctx, depth, id, current);
|
|
3261
|
+
case DataView:
|
|
3262
|
+
return parseDataView(ctx, depth, id, current);
|
|
3263
|
+
case Map:
|
|
3264
|
+
return parseMap(ctx, depth, id, current);
|
|
3265
|
+
case Set:
|
|
3266
|
+
return parseSet(ctx, depth, id, current);
|
|
3267
|
+
default:
|
|
3268
|
+
break;
|
|
3269
|
+
}
|
|
3270
|
+
if (currentClass === Promise || current instanceof Promise) {
|
|
3271
|
+
return parsePromise(ctx, depth, id, current);
|
|
3272
|
+
}
|
|
3273
|
+
const currentFeatures = ctx.base.features;
|
|
3274
|
+
if (currentFeatures & 32 && currentClass === RegExp) {
|
|
3275
|
+
return createRegExpNode(id, current);
|
|
3276
|
+
}
|
|
3277
|
+
if (currentFeatures & 16) {
|
|
3278
|
+
switch (currentClass) {
|
|
3279
|
+
case BigInt64Array:
|
|
3280
|
+
case BigUint64Array:
|
|
3281
|
+
return parseBigIntTypedArray(ctx, depth, id, current);
|
|
3282
|
+
default:
|
|
3283
|
+
break;
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
if (currentFeatures & 1 && typeof AggregateError !== "undefined" && (currentClass === AggregateError || current instanceof AggregateError)) {
|
|
3287
|
+
return parseAggregateError(ctx, depth, id, current);
|
|
3288
|
+
}
|
|
3289
|
+
if (current instanceof Error) {
|
|
3290
|
+
return parseError(ctx, depth, id, current);
|
|
3291
|
+
}
|
|
3292
|
+
if (SYM_ITERATOR in current || SYM_ASYNC_ITERATOR in current) {
|
|
3293
|
+
return parsePlainObject(ctx, depth, id, current, !!currentClass);
|
|
3294
|
+
}
|
|
3295
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
3296
|
+
}
|
|
3297
|
+
async function parseFunctionAsync(ctx, depth, current) {
|
|
3298
|
+
const ref = getReferenceNode(ctx.base, current);
|
|
3299
|
+
if (ref.type !== 0) {
|
|
3300
|
+
return ref.value;
|
|
3301
|
+
}
|
|
3302
|
+
const plugin = await parsePlugin(ctx, depth, ref.value, current);
|
|
3303
|
+
if (plugin) {
|
|
3304
|
+
return plugin;
|
|
3305
|
+
}
|
|
3306
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
3307
|
+
}
|
|
3308
|
+
async function parseAsync(ctx, depth, current) {
|
|
3309
|
+
switch (typeof current) {
|
|
3310
|
+
case "boolean":
|
|
3311
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
3312
|
+
case "undefined":
|
|
3313
|
+
return UNDEFINED_NODE;
|
|
3314
|
+
case "string":
|
|
3315
|
+
return createStringNode(current);
|
|
3316
|
+
case "number":
|
|
3317
|
+
return createNumberNode(current);
|
|
3318
|
+
case "bigint":
|
|
3319
|
+
return createBigIntNode(current);
|
|
3320
|
+
case "object": {
|
|
3321
|
+
if (current) {
|
|
3322
|
+
const ref = getReferenceNode(ctx.base, current);
|
|
3323
|
+
return ref.type === 0 ? await parseObjectAsync(ctx, depth + 1, ref.value, current) : ref.value;
|
|
3324
|
+
}
|
|
3325
|
+
return NULL_NODE;
|
|
3326
|
+
}
|
|
3327
|
+
case "symbol":
|
|
3328
|
+
return parseWellKnownSymbol(ctx.base, current);
|
|
3329
|
+
case "function":
|
|
3330
|
+
return parseFunctionAsync(ctx, depth, current);
|
|
3331
|
+
default:
|
|
3332
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
async function parseTopAsync(ctx, current) {
|
|
3336
|
+
try {
|
|
3337
|
+
return await parseAsync(ctx, 0, current);
|
|
3338
|
+
} catch (error) {
|
|
3339
|
+
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
function dedupePlugins(deduped, plugins) {
|
|
3343
|
+
for (let i = 0, len = plugins.length;i < len; i++) {
|
|
3344
|
+
const current = plugins[i];
|
|
3345
|
+
if (!deduped.has(current)) {
|
|
3346
|
+
deduped.add(current);
|
|
3347
|
+
if (current.extends) {
|
|
3348
|
+
dedupePlugins(deduped, current.extends);
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
function resolvePlugins(plugins) {
|
|
3354
|
+
if (plugins) {
|
|
3355
|
+
const deduped = /* @__PURE__ */ new Set;
|
|
3356
|
+
dedupePlugins(deduped, plugins);
|
|
3357
|
+
return [...deduped];
|
|
3358
|
+
}
|
|
3359
|
+
return;
|
|
3360
|
+
}
|
|
3361
|
+
var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
|
|
3362
|
+
var REF_START_CHARS_LEN = REF_START_CHARS.length;
|
|
3363
|
+
var REF_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_";
|
|
3364
|
+
var REF_CHARS_LEN = REF_CHARS.length;
|
|
3365
|
+
async function toCrossJSONAsync(source, options = {}) {
|
|
3366
|
+
const plugins = resolvePlugins(options.plugins);
|
|
3367
|
+
const ctx = createAsyncParserContext(2, {
|
|
3368
|
+
plugins,
|
|
3369
|
+
disabledFeatures: options.disabledFeatures,
|
|
3370
|
+
refs: options.refs
|
|
3371
|
+
});
|
|
3372
|
+
return await parseTopAsync(ctx, source);
|
|
3373
|
+
}
|
|
3374
|
+
|
|
2194
3375
|
// src/not-found.ts
|
|
2195
3376
|
var NOT_FOUND_BRAND = "FURIN_NOT_FOUND";
|
|
2196
3377
|
|
|
@@ -2206,7 +3387,7 @@ function isNotFoundError(err) {
|
|
|
2206
3387
|
return err instanceof FurinNotFoundError || typeof err === "object" && err !== null && err.__furinBrand === NOT_FOUND_BRAND;
|
|
2207
3388
|
}
|
|
2208
3389
|
|
|
2209
|
-
// ../../node_modules/.bun/evlog@2.
|
|
3390
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/utils.mjs
|
|
2210
3391
|
function formatDuration(ms) {
|
|
2211
3392
|
if (ms < 1000)
|
|
2212
3393
|
return `${Math.round(ms)}ms`;
|
|
@@ -2294,6 +3475,21 @@ function getCssLevelColor(level) {
|
|
|
2294
3475
|
function escapeFormatString(str) {
|
|
2295
3476
|
return str.replace(/%/g, "%%");
|
|
2296
3477
|
}
|
|
3478
|
+
var SENSITIVE_HEADERS = [
|
|
3479
|
+
"authorization",
|
|
3480
|
+
"cookie",
|
|
3481
|
+
"set-cookie",
|
|
3482
|
+
"x-api-key",
|
|
3483
|
+
"x-auth-token",
|
|
3484
|
+
"proxy-authorization"
|
|
3485
|
+
];
|
|
3486
|
+
function filterSafeHeaders(headers) {
|
|
3487
|
+
const safeHeaders = {};
|
|
3488
|
+
for (const [key, value] of Object.entries(headers))
|
|
3489
|
+
if (!SENSITIVE_HEADERS.includes(key.toLowerCase()))
|
|
3490
|
+
safeHeaders[key] = value;
|
|
3491
|
+
return safeHeaders;
|
|
3492
|
+
}
|
|
2297
3493
|
var patternCache = /* @__PURE__ */ new Map;
|
|
2298
3494
|
function matchesPattern(path, pattern) {
|
|
2299
3495
|
let regex = patternCache.get(pattern);
|
|
@@ -2305,7 +3501,25 @@ function matchesPattern(path, pattern) {
|
|
|
2305
3501
|
return regex.test(path);
|
|
2306
3502
|
}
|
|
2307
3503
|
|
|
2308
|
-
// ../../node_modules/.bun/evlog@2.
|
|
3504
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/headers-CU-QqnYg.mjs
|
|
3505
|
+
function extractSafeHeaders(headers) {
|
|
3506
|
+
const raw = {};
|
|
3507
|
+
headers.forEach((value, key) => {
|
|
3508
|
+
raw[key] = value;
|
|
3509
|
+
});
|
|
3510
|
+
return filterSafeHeaders(raw);
|
|
3511
|
+
}
|
|
3512
|
+
function extractSafeNodeHeaders(headers) {
|
|
3513
|
+
const raw = {};
|
|
3514
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
3515
|
+
if (value === undefined)
|
|
3516
|
+
continue;
|
|
3517
|
+
raw[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
3518
|
+
}
|
|
3519
|
+
return filterSafeHeaders(raw);
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/audit-pV5aLGP0.mjs
|
|
2309
3523
|
var DEFAULT_REPLACEMENT = "[REDACTED]";
|
|
2310
3524
|
var builtinPatterns = {
|
|
2311
3525
|
creditCard: {
|
|
@@ -2456,6 +3670,117 @@ function applyMaskers(value, maskers) {
|
|
|
2456
3670
|
}
|
|
2457
3671
|
return result;
|
|
2458
3672
|
}
|
|
3673
|
+
function logPluginError(name, hook, err) {
|
|
3674
|
+
console.error(`[evlog/${name}] ${hook} failed:`, err);
|
|
3675
|
+
}
|
|
3676
|
+
function createPluginRunner(plugins = []) {
|
|
3677
|
+
const byName = /* @__PURE__ */ new Map;
|
|
3678
|
+
for (const plugin of plugins)
|
|
3679
|
+
byName.set(plugin.name, plugin);
|
|
3680
|
+
const list = Array.from(byName.values());
|
|
3681
|
+
return {
|
|
3682
|
+
plugins: list,
|
|
3683
|
+
hasEnrich: list.some((p) => typeof p.enrich === "function"),
|
|
3684
|
+
hasDrain: list.some((p) => typeof p.drain === "function"),
|
|
3685
|
+
hasKeep: list.some((p) => typeof p.keep === "function"),
|
|
3686
|
+
hasRequestLifecycle: list.some((p) => typeof p.onRequestStart === "function" || typeof p.onRequestFinish === "function"),
|
|
3687
|
+
hasClientLog: list.some((p) => typeof p.onClientLog === "function"),
|
|
3688
|
+
hasExtendLogger: list.some((p) => typeof p.extendLogger === "function"),
|
|
3689
|
+
applyExtendLogger(logger) {
|
|
3690
|
+
for (const plugin of list) {
|
|
3691
|
+
if (!plugin.extendLogger)
|
|
3692
|
+
continue;
|
|
3693
|
+
try {
|
|
3694
|
+
plugin.extendLogger(logger);
|
|
3695
|
+
} catch (err) {
|
|
3696
|
+
logPluginError(plugin.name, "extendLogger", err);
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
},
|
|
3700
|
+
runOnRequestStart(ctx) {
|
|
3701
|
+
for (const plugin of list) {
|
|
3702
|
+
if (!plugin.onRequestStart)
|
|
3703
|
+
continue;
|
|
3704
|
+
try {
|
|
3705
|
+
plugin.onRequestStart(ctx);
|
|
3706
|
+
} catch (err) {
|
|
3707
|
+
logPluginError(plugin.name, "onRequestStart", err);
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
},
|
|
3711
|
+
runOnRequestFinish(ctx) {
|
|
3712
|
+
for (const plugin of list) {
|
|
3713
|
+
if (!plugin.onRequestFinish)
|
|
3714
|
+
continue;
|
|
3715
|
+
try {
|
|
3716
|
+
plugin.onRequestFinish(ctx);
|
|
3717
|
+
} catch (err) {
|
|
3718
|
+
logPluginError(plugin.name, "onRequestFinish", err);
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
},
|
|
3722
|
+
async runEnrich(ctx) {
|
|
3723
|
+
for (const plugin of list) {
|
|
3724
|
+
if (!plugin.enrich)
|
|
3725
|
+
continue;
|
|
3726
|
+
try {
|
|
3727
|
+
await plugin.enrich(ctx);
|
|
3728
|
+
} catch (err) {
|
|
3729
|
+
logPluginError(plugin.name, "enrich", err);
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
},
|
|
3733
|
+
async runDrain(ctx) {
|
|
3734
|
+
const drains = list.filter((p) => typeof p.drain === "function");
|
|
3735
|
+
if (drains.length === 0)
|
|
3736
|
+
return;
|
|
3737
|
+
await Promise.allSettled(drains.map(async (plugin) => {
|
|
3738
|
+
try {
|
|
3739
|
+
await plugin.drain(ctx);
|
|
3740
|
+
} catch (err) {
|
|
3741
|
+
logPluginError(plugin.name, "drain", err);
|
|
3742
|
+
}
|
|
3743
|
+
}));
|
|
3744
|
+
},
|
|
3745
|
+
async runKeep(ctx) {
|
|
3746
|
+
for (const plugin of list) {
|
|
3747
|
+
if (!plugin.keep)
|
|
3748
|
+
continue;
|
|
3749
|
+
try {
|
|
3750
|
+
await plugin.keep(ctx);
|
|
3751
|
+
} catch (err) {
|
|
3752
|
+
logPluginError(plugin.name, "keep", err);
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
},
|
|
3756
|
+
runOnClientLog(ctx) {
|
|
3757
|
+
for (const plugin of list) {
|
|
3758
|
+
if (!plugin.onClientLog)
|
|
3759
|
+
continue;
|
|
3760
|
+
try {
|
|
3761
|
+
plugin.onClientLog(ctx);
|
|
3762
|
+
} catch (err) {
|
|
3763
|
+
logPluginError(plugin.name, "onClientLog", err);
|
|
3764
|
+
}
|
|
3765
|
+
}
|
|
3766
|
+
},
|
|
3767
|
+
async runSetup(ctx) {
|
|
3768
|
+
for (const plugin of list) {
|
|
3769
|
+
if (!plugin.setup)
|
|
3770
|
+
continue;
|
|
3771
|
+
try {
|
|
3772
|
+
await plugin.setup(ctx);
|
|
3773
|
+
} catch (err) {
|
|
3774
|
+
logPluginError(plugin.name, "setup", err);
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
};
|
|
3779
|
+
}
|
|
3780
|
+
var emptyRunner = createPluginRunner([]);
|
|
3781
|
+
function getEmptyPluginRunner() {
|
|
3782
|
+
return emptyRunner;
|
|
3783
|
+
}
|
|
2459
3784
|
function isPlainObject(val) {
|
|
2460
3785
|
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
2461
3786
|
}
|
|
@@ -2494,6 +3819,7 @@ var globalRedact;
|
|
|
2494
3819
|
var globalEnabled = true;
|
|
2495
3820
|
var globalSilent = false;
|
|
2496
3821
|
var globalMinLevel = "debug";
|
|
3822
|
+
var globalPluginRunner = getEmptyPluginRunner();
|
|
2497
3823
|
function initLogger(config = {}) {
|
|
2498
3824
|
globalEnabled = config.enabled ?? true;
|
|
2499
3825
|
const detected = detectEnvironment();
|
|
@@ -2511,9 +3837,22 @@ function initLogger(config = {}) {
|
|
|
2511
3837
|
globalRedact = resolveRedactConfig(config.redact ?? !isDev());
|
|
2512
3838
|
globalSilent = config.silent ?? false;
|
|
2513
3839
|
globalMinLevel = config.minLevel ?? "debug";
|
|
2514
|
-
|
|
3840
|
+
globalPluginRunner = config.plugins?.length ? createPluginRunner(config.plugins) : getEmptyPluginRunner();
|
|
3841
|
+
if (globalPluginRunner.plugins.length > 0)
|
|
3842
|
+
globalPluginRunner.runSetup({ env: { ...globalEnv } });
|
|
3843
|
+
const hasAnyDrain = !!globalDrain || globalPluginRunner.hasDrain;
|
|
3844
|
+
if (globalSilent && !hasAnyDrain && !config._suppressDrainWarning)
|
|
2515
3845
|
console.warn("[evlog] silent mode is enabled but no drain is configured. Events will be built and sampled but not output anywhere. Set a drain via initLogger({ drain }) or a framework hook (evlog:drain).");
|
|
2516
3846
|
}
|
|
3847
|
+
function getGlobalPluginRunner() {
|
|
3848
|
+
return globalPluginRunner;
|
|
3849
|
+
}
|
|
3850
|
+
function isEnabled() {
|
|
3851
|
+
return globalEnabled;
|
|
3852
|
+
}
|
|
3853
|
+
function getGlobalDrain() {
|
|
3854
|
+
return globalDrain;
|
|
3855
|
+
}
|
|
2517
3856
|
function shouldSample(level) {
|
|
2518
3857
|
const { rates } = globalSampling;
|
|
2519
3858
|
if (!rates)
|
|
@@ -2581,12 +3920,20 @@ function emitWideEvent(level, event, options = {}) {
|
|
|
2581
3920
|
console[getConsoleMethod(level)](JSON.stringify(formatted));
|
|
2582
3921
|
else
|
|
2583
3922
|
console[getConsoleMethod(level)](formatted);
|
|
2584
|
-
if (
|
|
2585
|
-
const
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
3923
|
+
if (!deferDrain) {
|
|
3924
|
+
const drainPromises = [];
|
|
3925
|
+
if (globalDrain)
|
|
3926
|
+
drainPromises.push((async () => {
|
|
3927
|
+
try {
|
|
3928
|
+
await globalDrain({ event: formatted });
|
|
3929
|
+
} catch (err) {
|
|
3930
|
+
console.error("[evlog] drain failed:", err);
|
|
3931
|
+
}
|
|
3932
|
+
})());
|
|
3933
|
+
if (globalPluginRunner.hasDrain)
|
|
3934
|
+
drainPromises.push(globalPluginRunner.runDrain({ event: formatted }));
|
|
3935
|
+
if (drainPromises.length > 0 && waitUntil)
|
|
3936
|
+
waitUntil(Promise.all(drainPromises));
|
|
2590
3937
|
}
|
|
2591
3938
|
return formatted;
|
|
2592
3939
|
}
|
|
@@ -2955,6 +4302,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
2955
4302
|
};
|
|
2956
4303
|
const errRecord = err;
|
|
2957
4304
|
for (const k of [
|
|
4305
|
+
"code",
|
|
2958
4306
|
"status",
|
|
2959
4307
|
"statusText",
|
|
2960
4308
|
"statusCode",
|
|
@@ -3037,6 +4385,20 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
3037
4385
|
}
|
|
3038
4386
|
};
|
|
3039
4387
|
}
|
|
4388
|
+
function createRequestLogger(options = {}, internalOptions) {
|
|
4389
|
+
const { method, path, requestId, waitUntil: optionsWaitUntil } = options;
|
|
4390
|
+
const initial = {};
|
|
4391
|
+
if (method !== undefined)
|
|
4392
|
+
initial.method = method;
|
|
4393
|
+
if (path !== undefined)
|
|
4394
|
+
initial.path = path;
|
|
4395
|
+
if (requestId !== undefined)
|
|
4396
|
+
initial.requestId = requestId;
|
|
4397
|
+
return createLogger(initial, {
|
|
4398
|
+
...internalOptions,
|
|
4399
|
+
waitUntil: internalOptions?.waitUntil ?? optionsWaitUntil
|
|
4400
|
+
});
|
|
4401
|
+
}
|
|
3040
4402
|
if (typeof __EVLOG_CONFIG__ !== "undefined")
|
|
3041
4403
|
initLogger(__EVLOG_CONFIG__);
|
|
3042
4404
|
function stableStringify(value) {
|
|
@@ -3111,6 +4473,16 @@ function finalizeAudit(event) {
|
|
|
3111
4473
|
return;
|
|
3112
4474
|
event.audit = decorateAudit(a, String(event.timestamp));
|
|
3113
4475
|
}
|
|
4476
|
+
|
|
4477
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/errors-BQgyQ9xe.mjs
|
|
4478
|
+
function extractErrorStatus(error) {
|
|
4479
|
+
if (error === null || typeof error !== "object")
|
|
4480
|
+
return 500;
|
|
4481
|
+
const raw = error.status ?? error.statusCode;
|
|
4482
|
+
const status = Number(raw);
|
|
4483
|
+
return Number.isFinite(status) ? status : 500;
|
|
4484
|
+
}
|
|
4485
|
+
|
|
3114
4486
|
// src/router-provider.tsx
|
|
3115
4487
|
import {
|
|
3116
4488
|
createContext,
|
|
@@ -3130,12 +4502,29 @@ import { Component, Fragment } from "react";
|
|
|
3130
4502
|
// src/error.ts
|
|
3131
4503
|
function getPublicErrorMessage(error) {
|
|
3132
4504
|
const branded = error;
|
|
3133
|
-
if (branded?.__furinBrand === "FURIN_NOT_FOUND") {
|
|
4505
|
+
if (branded?.__furinBrand === "FURIN_NOT_FOUND" || branded?.__furinBrand === "FURIN_SERVER_ERROR") {
|
|
3134
4506
|
return error.message;
|
|
3135
4507
|
}
|
|
3136
4508
|
return "Something went wrong";
|
|
3137
4509
|
}
|
|
3138
4510
|
|
|
4511
|
+
// src/server-error.ts
|
|
4512
|
+
var SERVER_ERROR_BRAND = "FURIN_SERVER_ERROR";
|
|
4513
|
+
|
|
4514
|
+
class FurinServerError extends Error {
|
|
4515
|
+
__furinBrand = SERVER_ERROR_BRAND;
|
|
4516
|
+
digest;
|
|
4517
|
+
status;
|
|
4518
|
+
constructor(args) {
|
|
4519
|
+
super(args.message);
|
|
4520
|
+
this.status = args.status;
|
|
4521
|
+
this.digest = args.digest;
|
|
4522
|
+
}
|
|
4523
|
+
}
|
|
4524
|
+
function isFurinServerError(err) {
|
|
4525
|
+
return err instanceof FurinServerError || typeof err === "object" && err !== null && err.__furinBrand === SERVER_ERROR_BRAND;
|
|
4526
|
+
}
|
|
4527
|
+
|
|
3139
4528
|
// src/link.tsx
|
|
3140
4529
|
import { createElement, useCallback, useEffect, useRef } from "react";
|
|
3141
4530
|
function computeLinkView({
|
|
@@ -3185,9 +4574,10 @@ function LinkInteractive({
|
|
|
3185
4574
|
const effectivePreload = preload ?? router.defaultPreload;
|
|
3186
4575
|
const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
|
|
3187
4576
|
const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
|
|
4577
|
+
const { prefetch } = router;
|
|
3188
4578
|
const triggerPrefetch = useCallback(() => {
|
|
3189
|
-
|
|
3190
|
-
}, [
|
|
4579
|
+
prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
4580
|
+
}, [prefetch, logicalHref, effectiveStaleTime]);
|
|
3191
4581
|
useEffect(() => {
|
|
3192
4582
|
if (effectivePreload === "render") {
|
|
3193
4583
|
triggerPrefetch();
|
|
@@ -3238,6 +4628,10 @@ function LinkInteractive({
|
|
|
3238
4628
|
return;
|
|
3239
4629
|
}
|
|
3240
4630
|
e.preventDefault();
|
|
4631
|
+
if (typeof window !== "undefined" && router.navigate === SSR_FALLBACK_ROUTER.navigate) {
|
|
4632
|
+
window.location.href = href;
|
|
4633
|
+
return;
|
|
4634
|
+
}
|
|
3241
4635
|
router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
|
|
3242
4636
|
};
|
|
3243
4637
|
const handleMouseEnter = (e) => {
|
|
@@ -3400,11 +4794,6 @@ var BADGE_STYLE = {
|
|
|
3400
4794
|
marginBottom: "16px",
|
|
3401
4795
|
padding: "12px 36px"
|
|
3402
4796
|
};
|
|
3403
|
-
var NOT_FOUND_BADGE_STYLE = {
|
|
3404
|
-
...BADGE_STYLE,
|
|
3405
|
-
border: 0,
|
|
3406
|
-
padding: 0
|
|
3407
|
-
};
|
|
3408
4797
|
var HEADING_STYLE = {
|
|
3409
4798
|
color: COLOR_TEXT,
|
|
3410
4799
|
fontFamily: FONT_SANS,
|
|
@@ -3492,7 +4881,7 @@ function ScreenFrame({ badge, children }) {
|
|
|
3492
4881
|
style: PAGE_STYLE,
|
|
3493
4882
|
children: [
|
|
3494
4883
|
/* @__PURE__ */ jsxDEV("style", {
|
|
3495
|
-
|
|
4884
|
+
children: RESET_CSS
|
|
3496
4885
|
}, undefined, false, undefined, this),
|
|
3497
4886
|
/* @__PURE__ */ jsxDEV("div", {
|
|
3498
4887
|
style: FRAME_STYLE,
|
|
@@ -3573,7 +4962,7 @@ function DefaultErrorScreen({ message, digest, reset }) {
|
|
|
3573
4962
|
function DefaultNotFoundScreen({ message }) {
|
|
3574
4963
|
return /* @__PURE__ */ jsxDEV(ScreenFrame, {
|
|
3575
4964
|
badge: /* @__PURE__ */ jsxDEV("div", {
|
|
3576
|
-
style:
|
|
4965
|
+
style: BADGE_STYLE,
|
|
3577
4966
|
children: "404 \u2014 NOT FOUND"
|
|
3578
4967
|
}, undefined, false, undefined, this),
|
|
3579
4968
|
children: [
|
|
@@ -3639,6 +5028,7 @@ var DefaultErrorFallback = ({ error, reset }) => /* @__PURE__ */ jsxDEV2(Default
|
|
|
3639
5028
|
message: error.message,
|
|
3640
5029
|
reset
|
|
3641
5030
|
}, undefined, false, undefined, this);
|
|
5031
|
+
var DEFAULT_ERROR_STATUS = 500;
|
|
3642
5032
|
var DefaultNotFoundFallback = ({ error }) => /* @__PURE__ */ jsxDEV2(DefaultNotFoundScreen, {
|
|
3643
5033
|
message: error.message
|
|
3644
5034
|
}, undefined, false, undefined, this);
|
|
@@ -3670,10 +5060,12 @@ class FurinErrorBoundary extends Component {
|
|
|
3670
5060
|
throw error;
|
|
3671
5061
|
}
|
|
3672
5062
|
const Fallback = this.props.fallback ?? DefaultErrorFallback;
|
|
3673
|
-
const
|
|
5063
|
+
const serverDigest = isFurinServerError(error) ? error.digest : undefined;
|
|
5064
|
+
const finalDigest = serverDigest ?? digest ?? this.props.digest ?? computeErrorDigest(error);
|
|
3674
5065
|
const message = this.props.fallback ? error.message : getPublicErrorMessage(error);
|
|
5066
|
+
const status = isFurinServerError(error) ? error.status : DEFAULT_ERROR_STATUS;
|
|
3675
5067
|
return /* @__PURE__ */ jsxDEV2(Fallback, {
|
|
3676
|
-
error: { message, digest: finalDigest },
|
|
5068
|
+
error: { message, digest: finalDigest, status },
|
|
3677
5069
|
reset: typeof window === "undefined" ? SERVER_RESET_NOOP : this.reset
|
|
3678
5070
|
}, undefined, false, undefined, this);
|
|
3679
5071
|
}
|
|
@@ -3762,23 +5154,432 @@ function normalizeHref(href) {
|
|
|
3762
5154
|
return pathname + url.search + url.hash;
|
|
3763
5155
|
}
|
|
3764
5156
|
|
|
5157
|
+
// src/utils.ts
|
|
5158
|
+
function isFurinPage(value) {
|
|
5159
|
+
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_PAGE";
|
|
5160
|
+
}
|
|
5161
|
+
function isFurinRoute(value) {
|
|
5162
|
+
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_ROUTE";
|
|
5163
|
+
}
|
|
5164
|
+
function collectRouteChainFromRoute(route) {
|
|
5165
|
+
const chain = [];
|
|
5166
|
+
let current = route;
|
|
5167
|
+
while (current) {
|
|
5168
|
+
chain.unshift(current);
|
|
5169
|
+
current = current.parent;
|
|
5170
|
+
}
|
|
5171
|
+
return chain;
|
|
5172
|
+
}
|
|
5173
|
+
function hasCycle(route) {
|
|
5174
|
+
const visited = new Set;
|
|
5175
|
+
let current = route;
|
|
5176
|
+
while (current) {
|
|
5177
|
+
if (visited.has(current)) {
|
|
5178
|
+
return true;
|
|
5179
|
+
}
|
|
5180
|
+
visited.add(current);
|
|
5181
|
+
current = current.parent;
|
|
5182
|
+
}
|
|
5183
|
+
return false;
|
|
5184
|
+
}
|
|
5185
|
+
async function mapWithConcurrency(items, concurrency, fn) {
|
|
5186
|
+
if (items.length === 0) {
|
|
5187
|
+
return [];
|
|
5188
|
+
}
|
|
5189
|
+
const results = new Array(items.length);
|
|
5190
|
+
let cursor = 0;
|
|
5191
|
+
const workerCount = Math.min(Math.max(concurrency, 1), items.length);
|
|
5192
|
+
await Promise.all(Array.from({ length: workerCount }, async () => {
|
|
5193
|
+
while (true) {
|
|
5194
|
+
const index = cursor++;
|
|
5195
|
+
if (index >= items.length) {
|
|
5196
|
+
return;
|
|
5197
|
+
}
|
|
5198
|
+
results[index] = await fn(items[index], index);
|
|
5199
|
+
}
|
|
5200
|
+
}));
|
|
5201
|
+
return results;
|
|
5202
|
+
}
|
|
5203
|
+
function validateRouteChain(chain, root, pagePath) {
|
|
5204
|
+
const hasRoot = chain.some((r) => r === root);
|
|
5205
|
+
if (!hasRoot) {
|
|
5206
|
+
const location = pagePath ? `in ${pagePath}` : "";
|
|
5207
|
+
throw new Error(`[furin] Page ${location} must inherit from root route. ` + 'Add: import { route } from "./root"; and use route.page() or set parent: route');
|
|
5208
|
+
}
|
|
5209
|
+
for (const route of chain) {
|
|
5210
|
+
if (hasCycle(route)) {
|
|
5211
|
+
throw new Error("[furin] Cycle detected in route chain. A route cannot be its own ancestor.");
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
}
|
|
5215
|
+
|
|
3765
5216
|
// src/render/cache.ts
|
|
3766
5217
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
3767
5218
|
|
|
5219
|
+
// src/auto-invalidate/registry.ts
|
|
5220
|
+
class AutoInvalidateRegistry {
|
|
5221
|
+
pathToTags = new Map;
|
|
5222
|
+
tagToPaths = new Map;
|
|
5223
|
+
registerLoaderTags(urlPath, tags) {
|
|
5224
|
+
if (!tags || tags.length === 0) {
|
|
5225
|
+
this.unregisterPath(urlPath);
|
|
5226
|
+
return;
|
|
5227
|
+
}
|
|
5228
|
+
this.unregisterPath(urlPath);
|
|
5229
|
+
const uniqueTags = new Set(tags);
|
|
5230
|
+
this.pathToTags.set(urlPath, uniqueTags);
|
|
5231
|
+
for (const tag of uniqueTags) {
|
|
5232
|
+
let paths = this.tagToPaths.get(tag);
|
|
5233
|
+
if (!paths) {
|
|
5234
|
+
paths = new Set;
|
|
5235
|
+
this.tagToPaths.set(tag, paths);
|
|
5236
|
+
}
|
|
5237
|
+
paths.add(urlPath);
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
5240
|
+
pathsForTags(tags) {
|
|
5241
|
+
const paths = new Set;
|
|
5242
|
+
for (const tag of tags) {
|
|
5243
|
+
for (const path of this.tagToPaths.get(tag) ?? []) {
|
|
5244
|
+
paths.add(path);
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
5247
|
+
return [...paths];
|
|
5248
|
+
}
|
|
5249
|
+
unregisterPath(urlPath) {
|
|
5250
|
+
const tags = this.pathToTags.get(urlPath);
|
|
5251
|
+
if (!tags) {
|
|
5252
|
+
return;
|
|
5253
|
+
}
|
|
5254
|
+
for (const tag of tags) {
|
|
5255
|
+
const paths = this.tagToPaths.get(tag);
|
|
5256
|
+
if (!paths) {
|
|
5257
|
+
continue;
|
|
5258
|
+
}
|
|
5259
|
+
paths.delete(urlPath);
|
|
5260
|
+
if (paths.size === 0) {
|
|
5261
|
+
this.tagToPaths.delete(tag);
|
|
5262
|
+
}
|
|
5263
|
+
}
|
|
5264
|
+
this.pathToTags.delete(urlPath);
|
|
5265
|
+
}
|
|
5266
|
+
reset() {
|
|
5267
|
+
this.pathToTags.clear();
|
|
5268
|
+
this.tagToPaths.clear();
|
|
5269
|
+
}
|
|
5270
|
+
}
|
|
5271
|
+
var autoInvalidateRegistry = new AutoInvalidateRegistry;
|
|
5272
|
+
|
|
3768
5273
|
// src/context-logger.ts
|
|
3769
5274
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
3770
5275
|
|
|
3771
|
-
// ../../node_modules/.bun/evlog@2.
|
|
5276
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/routes-CnIgYWf8.mjs
|
|
5277
|
+
function shouldLog(path, include, exclude) {
|
|
5278
|
+
if (exclude && exclude.length > 0) {
|
|
5279
|
+
if (exclude.some((pattern) => matchesPattern(path, pattern)))
|
|
5280
|
+
return false;
|
|
5281
|
+
}
|
|
5282
|
+
if (!include || include.length === 0)
|
|
5283
|
+
return true;
|
|
5284
|
+
return include.some((pattern) => matchesPattern(path, pattern));
|
|
5285
|
+
}
|
|
5286
|
+
function getServiceForPath(path, routes) {
|
|
5287
|
+
if (!routes)
|
|
5288
|
+
return;
|
|
5289
|
+
for (const [pattern, config] of Object.entries(routes))
|
|
5290
|
+
if (matchesPattern(path, pattern))
|
|
5291
|
+
return config.service;
|
|
5292
|
+
}
|
|
5293
|
+
|
|
5294
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/fork-8u_zFOJq.mjs
|
|
5295
|
+
var noopResult = {
|
|
5296
|
+
logger: {
|
|
5297
|
+
set() {},
|
|
5298
|
+
error() {},
|
|
5299
|
+
info() {},
|
|
5300
|
+
warn() {},
|
|
5301
|
+
emit() {
|
|
5302
|
+
return null;
|
|
5303
|
+
},
|
|
5304
|
+
getContext() {
|
|
5305
|
+
return {};
|
|
5306
|
+
}
|
|
5307
|
+
},
|
|
5308
|
+
finish: () => Promise.resolve(null),
|
|
5309
|
+
skipped: true
|
|
5310
|
+
};
|
|
5311
|
+
var runnerCache = /* @__PURE__ */ new WeakMap;
|
|
5312
|
+
function resolveMiddlewarePluginRunner(options) {
|
|
5313
|
+
const global2 = getGlobalPluginRunner();
|
|
5314
|
+
const local = options.plugins;
|
|
5315
|
+
if (!local || local.length === 0)
|
|
5316
|
+
return global2;
|
|
5317
|
+
const cached = runnerCache.get(local);
|
|
5318
|
+
if (cached && cached.global === global2)
|
|
5319
|
+
return cached.merged;
|
|
5320
|
+
const merged = /* @__PURE__ */ new Map;
|
|
5321
|
+
for (const plugin of global2.plugins)
|
|
5322
|
+
merged.set(plugin.name, plugin);
|
|
5323
|
+
for (const plugin of local)
|
|
5324
|
+
merged.set(plugin.name, plugin);
|
|
5325
|
+
if (merged.size === 0)
|
|
5326
|
+
return getEmptyPluginRunner();
|
|
5327
|
+
const runner = createPluginRunner(Array.from(merged.values()));
|
|
5328
|
+
runnerCache.set(local, {
|
|
5329
|
+
global: global2,
|
|
5330
|
+
merged: runner
|
|
5331
|
+
});
|
|
5332
|
+
return runner;
|
|
5333
|
+
}
|
|
5334
|
+
async function runEnrichAndDrain(emittedEvent, options, requestInfo, responseStatus, plugins) {
|
|
5335
|
+
const runner = plugins ?? resolveMiddlewarePluginRunner(options);
|
|
5336
|
+
const resolvedRedact = resolveRedactConfig(options.redact);
|
|
5337
|
+
if (resolvedRedact)
|
|
5338
|
+
redactEvent(emittedEvent, resolvedRedact);
|
|
5339
|
+
if (options.enrich || runner.hasEnrich) {
|
|
5340
|
+
const enrichCtx = {
|
|
5341
|
+
event: emittedEvent,
|
|
5342
|
+
request: requestInfo,
|
|
5343
|
+
headers: options.headers,
|
|
5344
|
+
response: { status: responseStatus }
|
|
5345
|
+
};
|
|
5346
|
+
if (options.enrich)
|
|
5347
|
+
try {
|
|
5348
|
+
await options.enrich(enrichCtx);
|
|
5349
|
+
} catch (err) {
|
|
5350
|
+
console.error("[evlog] enrich failed:", err);
|
|
5351
|
+
}
|
|
5352
|
+
if (runner.hasEnrich)
|
|
5353
|
+
await runner.runEnrich(enrichCtx);
|
|
5354
|
+
}
|
|
5355
|
+
const drain = options.drain ?? getGlobalDrain();
|
|
5356
|
+
const hasUserDrain = !!drain;
|
|
5357
|
+
const hasPluginDrain = runner.hasDrain;
|
|
5358
|
+
if (hasUserDrain || hasPluginDrain) {
|
|
5359
|
+
const drainCtx = {
|
|
5360
|
+
event: emittedEvent,
|
|
5361
|
+
request: requestInfo,
|
|
5362
|
+
headers: options.headers
|
|
5363
|
+
};
|
|
5364
|
+
const tasks = [];
|
|
5365
|
+
if (hasUserDrain)
|
|
5366
|
+
tasks.push((async () => {
|
|
5367
|
+
try {
|
|
5368
|
+
await drain(drainCtx);
|
|
5369
|
+
} catch (err) {
|
|
5370
|
+
console.error("[evlog] drain failed:", err);
|
|
5371
|
+
}
|
|
5372
|
+
})());
|
|
5373
|
+
if (hasPluginDrain)
|
|
5374
|
+
tasks.push(runner.runDrain(drainCtx));
|
|
5375
|
+
await Promise.all(tasks);
|
|
5376
|
+
}
|
|
5377
|
+
}
|
|
5378
|
+
function createMiddlewareLogger(options) {
|
|
5379
|
+
if (!isEnabled())
|
|
5380
|
+
return noopResult;
|
|
5381
|
+
const { method, path, requestId, include, exclude, routes, keep } = options;
|
|
5382
|
+
if (!shouldLog(path, include, exclude))
|
|
5383
|
+
return noopResult;
|
|
5384
|
+
const resolvedRequestId = requestId || crypto.randomUUID();
|
|
5385
|
+
const logger = createRequestLogger({
|
|
5386
|
+
method,
|
|
5387
|
+
path,
|
|
5388
|
+
requestId: resolvedRequestId
|
|
5389
|
+
}, { _deferDrain: true });
|
|
5390
|
+
const routeService = getServiceForPath(path, routes);
|
|
5391
|
+
if (routeService)
|
|
5392
|
+
logger.set({ service: routeService });
|
|
5393
|
+
const pluginRunner = resolveMiddlewarePluginRunner(options);
|
|
5394
|
+
if (pluginRunner.hasExtendLogger)
|
|
5395
|
+
pluginRunner.applyExtendLogger(logger);
|
|
5396
|
+
const startTime = Date.now();
|
|
5397
|
+
const requestInfo = {
|
|
5398
|
+
method,
|
|
5399
|
+
path,
|
|
5400
|
+
requestId: resolvedRequestId
|
|
5401
|
+
};
|
|
5402
|
+
if (pluginRunner.hasRequestLifecycle)
|
|
5403
|
+
pluginRunner.runOnRequestStart({
|
|
5404
|
+
logger,
|
|
5405
|
+
request: requestInfo,
|
|
5406
|
+
headers: options.headers
|
|
5407
|
+
});
|
|
5408
|
+
const finish = async (opts) => {
|
|
5409
|
+
const { status, error } = opts ?? {};
|
|
5410
|
+
if (error) {
|
|
5411
|
+
logger.error(error);
|
|
5412
|
+
const errorStatus = extractErrorStatus(error);
|
|
5413
|
+
logger.set({ status: errorStatus });
|
|
5414
|
+
} else if (status !== undefined)
|
|
5415
|
+
logger.set({ status });
|
|
5416
|
+
const durationMs = Date.now() - startTime;
|
|
5417
|
+
const resolvedStatus = error ? extractErrorStatus(error) : status ?? logger.getContext().status;
|
|
5418
|
+
const tailCtx = {
|
|
5419
|
+
status: resolvedStatus,
|
|
5420
|
+
duration: durationMs,
|
|
5421
|
+
path,
|
|
5422
|
+
method,
|
|
5423
|
+
context: logger.getContext(),
|
|
5424
|
+
shouldKeep: false
|
|
5425
|
+
};
|
|
5426
|
+
if (keep)
|
|
5427
|
+
await keep(tailCtx);
|
|
5428
|
+
if (pluginRunner.hasKeep)
|
|
5429
|
+
await pluginRunner.runKeep(tailCtx);
|
|
5430
|
+
const forceKeep = tailCtx.shouldKeep || shouldKeep(tailCtx);
|
|
5431
|
+
const emittedEvent = logger.emit({ _forceKeep: forceKeep });
|
|
5432
|
+
if (emittedEvent && (options.enrich || options.drain || pluginRunner.hasEnrich || pluginRunner.hasDrain || getGlobalDrain()))
|
|
5433
|
+
await runEnrichAndDrain(emittedEvent, options, requestInfo, resolvedStatus, pluginRunner);
|
|
5434
|
+
if (pluginRunner.hasRequestLifecycle)
|
|
5435
|
+
pluginRunner.runOnRequestFinish({
|
|
5436
|
+
logger,
|
|
5437
|
+
request: requestInfo,
|
|
5438
|
+
headers: options.headers,
|
|
5439
|
+
event: emittedEvent,
|
|
5440
|
+
status: resolvedStatus,
|
|
5441
|
+
durationMs,
|
|
5442
|
+
error
|
|
5443
|
+
});
|
|
5444
|
+
return emittedEvent;
|
|
5445
|
+
};
|
|
5446
|
+
return {
|
|
5447
|
+
logger,
|
|
5448
|
+
finish,
|
|
5449
|
+
skipped: false
|
|
5450
|
+
};
|
|
5451
|
+
}
|
|
5452
|
+
function attachForkToLogger(storage, parent, middlewareOptions, lifecycle) {
|
|
5453
|
+
const log = parent;
|
|
5454
|
+
log.fork = (label, fn) => {
|
|
5455
|
+
forkBackgroundLogger({
|
|
5456
|
+
storage,
|
|
5457
|
+
parent,
|
|
5458
|
+
middlewareOptions,
|
|
5459
|
+
label,
|
|
5460
|
+
fn,
|
|
5461
|
+
lifecycle
|
|
5462
|
+
});
|
|
5463
|
+
};
|
|
5464
|
+
}
|
|
5465
|
+
function forkBackgroundLogger(options) {
|
|
5466
|
+
const { storage, parent, middlewareOptions, label, fn, lifecycle } = options;
|
|
5467
|
+
const parentCtx = parent.getContext();
|
|
5468
|
+
const parentRequestId = parentCtx.requestId;
|
|
5469
|
+
if (typeof parentRequestId !== "string" || parentRequestId.length === 0)
|
|
5470
|
+
throw new Error("[evlog] log.fork() requires the parent logger to have a requestId. Ensure the request was created by evlog middleware.");
|
|
5471
|
+
const method = String(parentCtx.method ?? middlewareOptions.method);
|
|
5472
|
+
const path = String(parentCtx.path ?? middlewareOptions.path);
|
|
5473
|
+
const child = createRequestLogger({
|
|
5474
|
+
method,
|
|
5475
|
+
path,
|
|
5476
|
+
requestId: crypto.randomUUID()
|
|
5477
|
+
}, { _deferDrain: true });
|
|
5478
|
+
child.set({
|
|
5479
|
+
operation: label,
|
|
5480
|
+
_parentRequestId: parentRequestId
|
|
5481
|
+
});
|
|
5482
|
+
const childRequestInfo = {
|
|
5483
|
+
method,
|
|
5484
|
+
path,
|
|
5485
|
+
requestId: child.getContext().requestId
|
|
5486
|
+
};
|
|
5487
|
+
storage.run(child, () => {
|
|
5488
|
+
lifecycle?.onChildEnter?.(child);
|
|
5489
|
+
Promise.resolve().then(() => fn()).then(async () => {
|
|
5490
|
+
const emittedEvent = child.emit();
|
|
5491
|
+
const ctxStatus = child.getContext().status;
|
|
5492
|
+
const status = emittedEvent?.status ?? (typeof ctxStatus === "number" ? ctxStatus : undefined);
|
|
5493
|
+
if (emittedEvent && (middlewareOptions.enrich || middlewareOptions.drain || getGlobalDrain()))
|
|
5494
|
+
await runEnrichAndDrain(emittedEvent, middlewareOptions, childRequestInfo, status);
|
|
5495
|
+
}).catch(async (err) => {
|
|
5496
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
5497
|
+
child.error(error);
|
|
5498
|
+
child.set({ status: extractErrorStatus(error) });
|
|
5499
|
+
const emittedEvent = child.emit();
|
|
5500
|
+
const status = extractErrorStatus(error);
|
|
5501
|
+
if (emittedEvent && (middlewareOptions.enrich || middlewareOptions.drain || getGlobalDrain()))
|
|
5502
|
+
await runEnrichAndDrain(emittedEvent, middlewareOptions, childRequestInfo, status);
|
|
5503
|
+
}).finally(() => {
|
|
5504
|
+
lifecycle?.onChildExit?.(child);
|
|
5505
|
+
});
|
|
5506
|
+
});
|
|
5507
|
+
}
|
|
5508
|
+
|
|
5509
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/integration-DTZtjSqh.mjs
|
|
5510
|
+
function normalizeHeaders(headers) {
|
|
5511
|
+
if (!headers)
|
|
5512
|
+
return;
|
|
5513
|
+
if (typeof headers.forEach === "function" && typeof headers.get === "function")
|
|
5514
|
+
return extractSafeHeaders(headers);
|
|
5515
|
+
return extractSafeNodeHeaders(headers);
|
|
5516
|
+
}
|
|
5517
|
+
function defineFrameworkIntegration(spec) {
|
|
5518
|
+
return { start(ctx, options = {}) {
|
|
5519
|
+
const extracted = spec.extractRequest(ctx);
|
|
5520
|
+
const headers = normalizeHeaders(extracted.headers);
|
|
5521
|
+
const middlewareOptions = {
|
|
5522
|
+
method: extracted.method,
|
|
5523
|
+
path: extracted.path,
|
|
5524
|
+
requestId: extracted.requestId || crypto.randomUUID(),
|
|
5525
|
+
headers,
|
|
5526
|
+
...options
|
|
5527
|
+
};
|
|
5528
|
+
const result = createMiddlewareLogger(middlewareOptions);
|
|
5529
|
+
if (!result.skipped) {
|
|
5530
|
+
if (spec.storage)
|
|
5531
|
+
attachForkToLogger(spec.storage, result.logger, middlewareOptions, spec.forkLifecycle);
|
|
5532
|
+
spec.attachLogger(ctx, result.logger);
|
|
5533
|
+
}
|
|
5534
|
+
const { storage } = spec;
|
|
5535
|
+
const runWith = async (fn) => {
|
|
5536
|
+
if (!storage || result.skipped)
|
|
5537
|
+
return await fn();
|
|
5538
|
+
return await storage.run(result.logger, fn);
|
|
5539
|
+
};
|
|
5540
|
+
return {
|
|
5541
|
+
...result,
|
|
5542
|
+
middlewareOptions,
|
|
5543
|
+
runWith
|
|
5544
|
+
};
|
|
5545
|
+
} };
|
|
5546
|
+
}
|
|
5547
|
+
|
|
5548
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/elysia/index.mjs
|
|
3772
5549
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3773
5550
|
import { Elysia } from "elysia";
|
|
3774
5551
|
var storage = new AsyncLocalStorage;
|
|
3775
5552
|
var activeLoggers = /* @__PURE__ */ new WeakSet;
|
|
3776
|
-
function
|
|
5553
|
+
function useLogger() {
|
|
3777
5554
|
const logger = storage.getStore();
|
|
3778
5555
|
if (!logger || !activeLoggers.has(logger))
|
|
3779
5556
|
throw new Error("[evlog] useLogger() was called outside of an evlog plugin context. Make sure app.use(evlog()) is registered before your routes.");
|
|
3780
5557
|
return logger;
|
|
3781
5558
|
}
|
|
5559
|
+
var integration = defineFrameworkIntegration({
|
|
5560
|
+
name: "elysia",
|
|
5561
|
+
extractRequest: ({ request, path, headers }) => ({
|
|
5562
|
+
method: request.method,
|
|
5563
|
+
path,
|
|
5564
|
+
headers,
|
|
5565
|
+
requestId: headers["x-request-id"]
|
|
5566
|
+
}),
|
|
5567
|
+
attachLogger: ({ request, path, headers }, logger) => {
|
|
5568
|
+
attachForkToLogger(storage, logger, {
|
|
5569
|
+
method: request.method,
|
|
5570
|
+
path,
|
|
5571
|
+
requestId: headers["x-request-id"]
|
|
5572
|
+
}, {
|
|
5573
|
+
onChildEnter: (child) => {
|
|
5574
|
+
activeLoggers.add(child);
|
|
5575
|
+
},
|
|
5576
|
+
onChildExit: (child) => {
|
|
5577
|
+
activeLoggers.delete(child);
|
|
5578
|
+
}
|
|
5579
|
+
});
|
|
5580
|
+
activeLoggers.add(logger);
|
|
5581
|
+
}
|
|
5582
|
+
});
|
|
3782
5583
|
|
|
3783
5584
|
// src/context-logger.ts
|
|
3784
5585
|
var noopLogger2 = {
|
|
@@ -3791,9 +5592,9 @@ var noopLogger2 = {
|
|
|
3791
5592
|
fork: (_label, fn) => fn()
|
|
3792
5593
|
};
|
|
3793
5594
|
var syntheticRenderStorage = new AsyncLocalStorage2;
|
|
3794
|
-
function
|
|
5595
|
+
function useLogger2() {
|
|
3795
5596
|
try {
|
|
3796
|
-
return
|
|
5597
|
+
return useLogger();
|
|
3797
5598
|
} catch {
|
|
3798
5599
|
return syntheticRenderStorage.getStore() ?? noopLogger2;
|
|
3799
5600
|
}
|
|
@@ -3906,11 +5707,17 @@ var MAX_ISR_CACHE_SIZE = 1000;
|
|
|
3906
5707
|
var MAX_SSG_CACHE_SIZE = 1000;
|
|
3907
5708
|
var isrRouteCache = createRouteCache({
|
|
3908
5709
|
maxSize: MAX_ISR_CACHE_SIZE,
|
|
3909
|
-
name: "render:isr-html"
|
|
5710
|
+
name: "render:isr-html",
|
|
5711
|
+
onDelete: (key) => {
|
|
5712
|
+
autoInvalidateRegistry.unregisterPath(key);
|
|
5713
|
+
}
|
|
3910
5714
|
});
|
|
3911
5715
|
var ssgRouteCache = createRouteCache({
|
|
3912
5716
|
maxSize: MAX_SSG_CACHE_SIZE,
|
|
3913
|
-
name: "render:ssg-html"
|
|
5717
|
+
name: "render:ssg-html",
|
|
5718
|
+
onDelete: (key) => {
|
|
5719
|
+
autoInvalidateRegistry.unregisterPath(key);
|
|
5720
|
+
}
|
|
3914
5721
|
});
|
|
3915
5722
|
var isrCache = isrRouteCache.store;
|
|
3916
5723
|
var ssgCache = ssgRouteCache.store;
|
|
@@ -4020,16 +5827,42 @@ function errorMessageOf(err) {
|
|
|
4020
5827
|
return "";
|
|
4021
5828
|
}
|
|
4022
5829
|
var SERVER_RESET_NOOP2 = () => {};
|
|
4023
|
-
function buildErrorElement(component, error, digest) {
|
|
5830
|
+
function buildErrorElement(component, error, digest, messageOverride, status) {
|
|
4024
5831
|
const ErrorView = component ?? DefaultErrorComponent;
|
|
4025
|
-
|
|
5832
|
+
let message;
|
|
5833
|
+
if (component) {
|
|
5834
|
+
message = messageOverride ?? errorMessageOf(error);
|
|
5835
|
+
} else {
|
|
5836
|
+
message = "An unexpected error occurred.";
|
|
5837
|
+
}
|
|
4026
5838
|
return /* @__PURE__ */ jsxDEV4(ErrorView, {
|
|
4027
|
-
error: { message, digest },
|
|
5839
|
+
error: { message, digest, status },
|
|
4028
5840
|
reset: SERVER_RESET_NOOP2
|
|
4029
5841
|
}, undefined, false, undefined, this);
|
|
4030
5842
|
}
|
|
4031
5843
|
|
|
5844
|
+
// src/client.ts
|
|
5845
|
+
var DEFERRED_BRAND = "__isDeferred";
|
|
5846
|
+
function isDeferred(v) {
|
|
5847
|
+
return typeof v === "object" && v !== null && Object.hasOwn(v, DEFERRED_BRAND) && v[DEFERRED_BRAND] === true;
|
|
5848
|
+
}
|
|
5849
|
+
|
|
4032
5850
|
// src/render/loaders.ts
|
|
5851
|
+
var REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
5852
|
+
function isHttpRedirect(res) {
|
|
5853
|
+
return REDIRECT_STATUSES.has(res.status) && res.headers.has("location");
|
|
5854
|
+
}
|
|
5855
|
+
async function readResponseMessage(res) {
|
|
5856
|
+
if (res.body === null) {
|
|
5857
|
+
return res.statusText;
|
|
5858
|
+
}
|
|
5859
|
+
try {
|
|
5860
|
+
const body = await res.text();
|
|
5861
|
+
return body || res.statusText;
|
|
5862
|
+
} catch {
|
|
5863
|
+
return res.statusText;
|
|
5864
|
+
}
|
|
5865
|
+
}
|
|
4033
5866
|
function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
4034
5867
|
const cache = new Map;
|
|
4035
5868
|
return new Proxy(ctx, {
|
|
@@ -4052,9 +5885,44 @@ function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
|
4052
5885
|
}
|
|
4053
5886
|
});
|
|
4054
5887
|
}
|
|
4055
|
-
|
|
5888
|
+
function splitOneLoaderResult(result) {
|
|
5889
|
+
const sync = {};
|
|
5890
|
+
const deferred = {};
|
|
5891
|
+
const isDef = isDeferred(result);
|
|
5892
|
+
for (const [key, value] of Object.entries(result)) {
|
|
5893
|
+
if (key === "__isDeferred") {
|
|
5894
|
+
continue;
|
|
5895
|
+
}
|
|
5896
|
+
if (isDef && isPromiseLike(value)) {
|
|
5897
|
+
deferred[key] = Promise.resolve(value);
|
|
5898
|
+
} else {
|
|
5899
|
+
sync[key] = value;
|
|
5900
|
+
}
|
|
5901
|
+
}
|
|
5902
|
+
return { sync, deferred };
|
|
5903
|
+
}
|
|
5904
|
+
function isPromiseLike(value) {
|
|
5905
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
5906
|
+
}
|
|
5907
|
+
function mergeLoaderResults(results) {
|
|
5908
|
+
const allSync = {};
|
|
5909
|
+
const allDeferred = {};
|
|
5910
|
+
for (const result of results) {
|
|
5911
|
+
const { sync, deferred } = splitOneLoaderResult(result);
|
|
5912
|
+
for (const k of Object.keys(sync)) {
|
|
5913
|
+
delete allDeferred[k];
|
|
5914
|
+
}
|
|
5915
|
+
for (const k of Object.keys(deferred)) {
|
|
5916
|
+
delete allSync[k];
|
|
5917
|
+
}
|
|
5918
|
+
Object.assign(allSync, sync);
|
|
5919
|
+
Object.assign(allDeferred, deferred);
|
|
5920
|
+
}
|
|
5921
|
+
return { allSync, allDeferred };
|
|
5922
|
+
}
|
|
5923
|
+
async function runLoaders(route, ctx) {
|
|
4056
5924
|
try {
|
|
4057
|
-
const ctxRecord = { ...ctx, log:
|
|
5925
|
+
const ctxRecord = { ...ctx, log: useLogger2() };
|
|
4058
5926
|
const loaderMap = new Map;
|
|
4059
5927
|
let accumulatedParentPromise = Promise.resolve({});
|
|
4060
5928
|
for (const r of route.routeChain) {
|
|
@@ -4073,22 +5941,39 @@ async function runLoaders(route, ctx, _rootLayout) {
|
|
|
4073
5941
|
const pageCtx = createLoaderCtx(ctxRecord, accumulatedParentPromise);
|
|
4074
5942
|
const pagePromise = route.page?.loader ? Promise.resolve(route.page.loader(pageCtx)).then((r) => r ?? {}) : Promise.resolve({});
|
|
4075
5943
|
const results = await Promise.all([...loaderMap.values(), pagePromise]);
|
|
4076
|
-
const data = Object.assign({}, ...results);
|
|
4077
5944
|
const headers = {};
|
|
4078
5945
|
Object.assign(headers, ctx.set.headers);
|
|
4079
|
-
|
|
5946
|
+
const { allSync, allDeferred } = mergeLoaderResults(results);
|
|
5947
|
+
const routeCtx = { params: ctx.params, query: ctx.query, path: ctx.path };
|
|
5948
|
+
return {
|
|
5949
|
+
type: "data",
|
|
5950
|
+
syncData: { ...allSync, ...routeCtx },
|
|
5951
|
+
deferredPromises: Object.keys(allDeferred).length > 0 ? allDeferred : undefined,
|
|
5952
|
+
headers
|
|
5953
|
+
};
|
|
4080
5954
|
} catch (err) {
|
|
5955
|
+
const headers = {};
|
|
5956
|
+
Object.assign(headers, ctx.set.headers);
|
|
4081
5957
|
if (isNotFoundError(err)) {
|
|
4082
|
-
|
|
4083
|
-
Object.assign(headers2, ctx.set.headers);
|
|
4084
|
-
return { type: "not-found", error: err, headers: headers2 };
|
|
5958
|
+
return { type: "not-found", error: err, headers };
|
|
4085
5959
|
}
|
|
4086
5960
|
if (err instanceof Response) {
|
|
4087
|
-
|
|
5961
|
+
if (isHttpRedirect(err)) {
|
|
5962
|
+
return { type: "redirect", response: err };
|
|
5963
|
+
}
|
|
5964
|
+
const isMalformedRedirect = REDIRECT_STATUSES.has(err.status);
|
|
5965
|
+
const status = isMalformedRedirect ? 500 : err.status;
|
|
5966
|
+
const body = await readResponseMessage(err);
|
|
5967
|
+
const message = body || "Something went wrong";
|
|
5968
|
+
return { type: "error", error: err, status, message, headers };
|
|
4088
5969
|
}
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
5970
|
+
return {
|
|
5971
|
+
type: "error",
|
|
5972
|
+
error: err,
|
|
5973
|
+
status: 500,
|
|
5974
|
+
message: "Something went wrong",
|
|
5975
|
+
headers
|
|
5976
|
+
};
|
|
4092
5977
|
}
|
|
4093
5978
|
}
|
|
4094
5979
|
|
|
@@ -4136,9 +6021,14 @@ var IS_DEV = true;
|
|
|
4136
6021
|
function withSSRRouterContext(element, contextValue) {
|
|
4137
6022
|
return createElement3(RouterContext.Provider, { value: contextValue }, element);
|
|
4138
6023
|
}
|
|
6024
|
+
function assertDeferredModeAllowed(route, deferredPromises) {
|
|
6025
|
+
if (deferredPromises !== undefined && route.mode !== "ssr") {
|
|
6026
|
+
throw new Error(`[furin] page "${route.pattern}" returned defer() but the route is rendered in "${route.mode}" mode. ` + "defer() streams data progressively and is only supported in SSR. " + "Return the data directly (await it inside the loader) or switch the route to SSR mode.");
|
|
6027
|
+
}
|
|
6028
|
+
}
|
|
4139
6029
|
async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult) {
|
|
4140
6030
|
const loaderStart = Date.now();
|
|
4141
|
-
const loaderResult = precomputedLoaderResult ?? await runLoaders(route, ctx
|
|
6031
|
+
const loaderResult = precomputedLoaderResult ?? await runLoaders(route, ctx);
|
|
4142
6032
|
const loader_ms = Date.now() - loaderStart;
|
|
4143
6033
|
if (loaderResult.type === "redirect") {
|
|
4144
6034
|
return loaderResult.response;
|
|
@@ -4149,10 +6039,13 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4149
6039
|
const isNotFound = loaderResult.type === "not-found";
|
|
4150
6040
|
const isError = loaderResult.type === "error";
|
|
4151
6041
|
const isFallback = isNotFound || isError;
|
|
4152
|
-
const
|
|
6042
|
+
const syncData = isFallback ? {} : loaderResult.syncData;
|
|
6043
|
+
const deferredPromises = !isFallback && loaderResult.type === "data" ? loaderResult.deferredPromises : undefined;
|
|
6044
|
+
assertDeferredModeAllowed(route, deferredPromises);
|
|
4153
6045
|
const headers = loaderResult.headers;
|
|
4154
6046
|
const componentProps = {
|
|
4155
|
-
...
|
|
6047
|
+
...syncData,
|
|
6048
|
+
...deferredPromises ?? {},
|
|
4156
6049
|
params: ctx.params,
|
|
4157
6050
|
query: ctx.query,
|
|
4158
6051
|
path: ctx.path
|
|
@@ -4170,8 +6063,8 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4170
6063
|
notFoundError = { message: loaderResult.error.message, data: loaderResult.error.data };
|
|
4171
6064
|
} else if (loaderResult.type === "error") {
|
|
4172
6065
|
errorDigest = computeErrorDigest(loaderResult.error);
|
|
4173
|
-
element = buildErrorElement(route.error ?? root.error, loaderResult.error, errorDigest);
|
|
4174
|
-
status =
|
|
6066
|
+
element = buildErrorElement(route.error ?? root.error, loaderResult.error, errorDigest, loaderResult.message, loaderResult.status);
|
|
6067
|
+
status = loaderResult.status;
|
|
4175
6068
|
} else {
|
|
4176
6069
|
element = buildElement(route, componentProps, root.route);
|
|
4177
6070
|
}
|
|
@@ -4190,12 +6083,14 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4190
6083
|
element = withSSRRouterContext(element, ssrContext);
|
|
4191
6084
|
return {
|
|
4192
6085
|
componentProps,
|
|
6086
|
+
deferredPromises,
|
|
4193
6087
|
element,
|
|
4194
6088
|
errorDigest,
|
|
4195
6089
|
headData,
|
|
4196
6090
|
headers,
|
|
4197
6091
|
loader_ms,
|
|
4198
6092
|
notFoundError,
|
|
6093
|
+
syncData,
|
|
4199
6094
|
ssrContext,
|
|
4200
6095
|
status,
|
|
4201
6096
|
template
|
|
@@ -4218,7 +6113,7 @@ function renderForPath(route, params, root, origin, mode, basePath) {
|
|
|
4218
6113
|
if (prepared instanceof Response) {
|
|
4219
6114
|
return prepared;
|
|
4220
6115
|
}
|
|
4221
|
-
|
|
6116
|
+
useLogger2().set({
|
|
4222
6117
|
furin: {
|
|
4223
6118
|
render: mode,
|
|
4224
6119
|
route: route.pattern,
|
|
@@ -4227,17 +6122,27 @@ function renderForPath(route, params, root, origin, mode, basePath) {
|
|
|
4227
6122
|
...prepared.errorDigest ? { digest: prepared.errorDigest } : {}
|
|
4228
6123
|
}
|
|
4229
6124
|
});
|
|
4230
|
-
const {
|
|
6125
|
+
const { deferredPromises, element, headData, headers, status, syncData, template } = prepared;
|
|
4231
6126
|
const stream = await renderToReadableStream(element);
|
|
4232
6127
|
await stream.allReady;
|
|
4233
6128
|
const reactHtml = await streamToString(stream);
|
|
4234
6129
|
return {
|
|
4235
|
-
html: assembleHTML(template, headData, reactHtml,
|
|
6130
|
+
html: assembleHTML(template, headData, reactHtml, syncData),
|
|
4236
6131
|
headers,
|
|
6132
|
+
ndjson: await serializeLoaderDataNdjson(syncData, deferredPromises),
|
|
4237
6133
|
status
|
|
4238
6134
|
};
|
|
4239
6135
|
}, { route: route.pattern, render: mode });
|
|
4240
6136
|
}
|
|
6137
|
+
async function serializeLoaderDataNdjson(syncData, deferredPromises) {
|
|
6138
|
+
const payload = {
|
|
6139
|
+
...syncData,
|
|
6140
|
+
...deferredPromises ?? {}
|
|
6141
|
+
};
|
|
6142
|
+
const serialized = await toCrossJSONAsync(payload);
|
|
6143
|
+
return `${JSON.stringify(serialized)}
|
|
6144
|
+
`;
|
|
6145
|
+
}
|
|
4241
6146
|
async function prerenderSSG(route, params, root, origin, basePath) {
|
|
4242
6147
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
4243
6148
|
const cached = getSSGCache(resolvedPath);
|
|
@@ -4249,8 +6154,14 @@ async function prerenderSSG(route, params, root, origin, basePath) {
|
|
|
4249
6154
|
return renderResult;
|
|
4250
6155
|
}
|
|
4251
6156
|
const result = renderResult;
|
|
4252
|
-
const entry = {
|
|
6157
|
+
const entry = {
|
|
6158
|
+
cachedAt: Date.now(),
|
|
6159
|
+
html: result.html,
|
|
6160
|
+
ndjson: result.ndjson,
|
|
6161
|
+
status: result.status
|
|
6162
|
+
};
|
|
4253
6163
|
setSSGCache(resolvedPath, entry);
|
|
6164
|
+
autoInvalidateRegistry.registerLoaderTags(resolvedPath, route.tags);
|
|
4254
6165
|
return entry;
|
|
4255
6166
|
}
|
|
4256
6167
|
var pendingRevalidations = new Set;
|
|
@@ -4259,12 +6170,12 @@ var pendingRevalidations = new Set;
|
|
|
4259
6170
|
var STATIC_CONCURRENCY = 4;
|
|
4260
6171
|
var DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
|
|
4261
6172
|
var TRAILING_SLASHES_RE = /\/+$/;
|
|
4262
|
-
function pathToOutputFile(urlPath, outDir) {
|
|
6173
|
+
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
4263
6174
|
const normalizedOutDir = resolve2(outDir);
|
|
4264
6175
|
if (urlPath === "/" || urlPath === "") {
|
|
4265
|
-
return join7(normalizedOutDir,
|
|
6176
|
+
return join7(normalizedOutDir, fileName);
|
|
4266
6177
|
}
|
|
4267
|
-
const resolved = resolve2(normalizedOutDir, urlPath.slice(1),
|
|
6178
|
+
const resolved = resolve2(normalizedOutDir, urlPath.slice(1), fileName);
|
|
4268
6179
|
if (!resolved.startsWith(`${normalizedOutDir}${sep}`)) {
|
|
4269
6180
|
throw new Error(`[furin] static: unsafe output path detected for URL "${urlPath}" \u2014 path traversal via ".." is not allowed.`);
|
|
4270
6181
|
}
|
|
@@ -4272,17 +6183,19 @@ function pathToOutputFile(urlPath, outDir) {
|
|
|
4272
6183
|
}
|
|
4273
6184
|
async function prerenderAndWrite(route, params, root, outDir, renderedRoutes, skippedRoutes, basePath) {
|
|
4274
6185
|
const urlPath = resolvePath(route.pattern, params);
|
|
4275
|
-
const
|
|
6186
|
+
const htmlOutputFile = pathToOutputFile(urlPath, outDir, "index.html");
|
|
6187
|
+
const dataOutputFile = pathToOutputFile(urlPath, outDir, "__furin_data.ndjson");
|
|
4276
6188
|
try {
|
|
4277
6189
|
const entry = await prerenderSSG(route, params, root, "http://localhost", basePath);
|
|
4278
6190
|
if (entry instanceof Response) {
|
|
4279
6191
|
console.warn(`[furin] static: route "${route.pattern}" loader returned a redirect \u2014 skipping.`);
|
|
4280
6192
|
return;
|
|
4281
6193
|
}
|
|
4282
|
-
ensureDir(dirname3(
|
|
4283
|
-
writeFileSync5(
|
|
6194
|
+
ensureDir(dirname3(htmlOutputFile));
|
|
6195
|
+
writeFileSync5(htmlOutputFile, entry.html);
|
|
6196
|
+
writeFileSync5(dataOutputFile, entry.ndjson);
|
|
4284
6197
|
renderedRoutes.push(urlPath);
|
|
4285
|
-
console.log(`[furin] static: ${urlPath} \u2192 ${toPosixPath(
|
|
6198
|
+
console.log(`[furin] static: ${urlPath} \u2192 ${toPosixPath(htmlOutputFile)}`);
|
|
4286
6199
|
} catch (err) {
|
|
4287
6200
|
console.error(`[furin] static: prerender failed for "${route.pattern}" (params: ${JSON.stringify(params)}):`, err);
|
|
4288
6201
|
skippedRoutes.push(urlPath);
|
|
@@ -4309,24 +6222,38 @@ function collectSsgRoutes(routes, onSSR, skippedRoutes) {
|
|
|
4309
6222
|
}
|
|
4310
6223
|
async function buildTaskQueue(ssgRoutes, root, outDir, renderedRoutes, skippedRoutes, basePath) {
|
|
4311
6224
|
const tasks = [];
|
|
4312
|
-
|
|
6225
|
+
const staticParamsResults = await mapWithConcurrency(ssgRoutes, STATIC_CONCURRENCY, async (route) => {
|
|
4313
6226
|
if (!DYNAMIC_SEGMENT_RE.test(route.pattern)) {
|
|
4314
|
-
|
|
4315
|
-
continue;
|
|
6227
|
+
return { route, paramSets: [{}] };
|
|
4316
6228
|
}
|
|
4317
6229
|
if (!route.page.staticParams) {
|
|
4318
6230
|
console.warn(`[furin] static: skipping dynamic route "${route.pattern}" \u2014 no staticParams() defined.`);
|
|
4319
6231
|
skippedRoutes.push(route.pattern);
|
|
4320
|
-
|
|
6232
|
+
return { route, paramSets: null };
|
|
4321
6233
|
}
|
|
4322
6234
|
try {
|
|
4323
6235
|
const paramSets = await route.page.staticParams() ?? [];
|
|
4324
|
-
|
|
4325
|
-
tasks.push(() => prerenderAndWrite(route, params, root, outDir, renderedRoutes, skippedRoutes, basePath));
|
|
4326
|
-
}
|
|
6236
|
+
return { route, paramSets };
|
|
4327
6237
|
} catch (err) {
|
|
4328
|
-
|
|
4329
|
-
|
|
6238
|
+
return { error: err, paramSets: null, route };
|
|
6239
|
+
}
|
|
6240
|
+
});
|
|
6241
|
+
for (const result of staticParamsResults) {
|
|
6242
|
+
if ("error" in result) {
|
|
6243
|
+
console.error(`[furin] static: staticParams() failed for "${result.route.pattern}":`, result.error);
|
|
6244
|
+
skippedRoutes.push(result.route.pattern);
|
|
6245
|
+
continue;
|
|
6246
|
+
}
|
|
6247
|
+
if (result.paramSets === null) {
|
|
6248
|
+
continue;
|
|
6249
|
+
}
|
|
6250
|
+
if (!Array.isArray(result.paramSets)) {
|
|
6251
|
+
console.error(`[furin] static: staticParams() for "${result.route.pattern}" returned a non-array value; skipping route.`);
|
|
6252
|
+
skippedRoutes.push(result.route.pattern);
|
|
6253
|
+
continue;
|
|
6254
|
+
}
|
|
6255
|
+
for (const params of result.paramSets) {
|
|
6256
|
+
tasks.push(() => prerenderAndWrite(result.route, params, root, outDir, renderedRoutes, skippedRoutes, basePath));
|
|
4330
6257
|
}
|
|
4331
6258
|
}
|
|
4332
6259
|
return tasks;
|
|
@@ -4386,7 +6313,7 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4386
6313
|
});
|
|
4387
6314
|
const publicFavicon = join7(rootDir, "public", "favicon.ico");
|
|
4388
6315
|
const faviconHref = existsSync6(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
4389
|
-
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref);
|
|
6316
|
+
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
|
|
4390
6317
|
setProductionTemplateContent(shellHtml);
|
|
4391
6318
|
const publicSrcDir = join7(rootDir, "public");
|
|
4392
6319
|
if (existsSync6(publicSrcDir)) {
|
|
@@ -4452,48 +6379,19 @@ function getCompileContext() {
|
|
|
4452
6379
|
return _compileCtx;
|
|
4453
6380
|
}
|
|
4454
6381
|
|
|
4455
|
-
// src/
|
|
4456
|
-
function
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
}
|
|
4462
|
-
function collectRouteChainFromRoute(route) {
|
|
4463
|
-
const chain = [];
|
|
4464
|
-
let current = route;
|
|
4465
|
-
while (current) {
|
|
4466
|
-
chain.unshift(current);
|
|
4467
|
-
current = current.parent;
|
|
4468
|
-
}
|
|
4469
|
-
return chain;
|
|
4470
|
-
}
|
|
4471
|
-
function hasCycle(route) {
|
|
4472
|
-
const visited = new Set;
|
|
4473
|
-
let current = route;
|
|
4474
|
-
while (current) {
|
|
4475
|
-
if (visited.has(current)) {
|
|
4476
|
-
return true;
|
|
6382
|
+
// src/router.ts
|
|
6383
|
+
function collectRouteTags(routeChain, page) {
|
|
6384
|
+
const tags = new Set;
|
|
6385
|
+
for (const route of routeChain) {
|
|
6386
|
+
for (const tag of route.tags ?? []) {
|
|
6387
|
+
tags.add(tag);
|
|
4477
6388
|
}
|
|
4478
|
-
visited.add(current);
|
|
4479
|
-
current = current.parent;
|
|
4480
|
-
}
|
|
4481
|
-
return false;
|
|
4482
|
-
}
|
|
4483
|
-
function validateRouteChain(chain, root, pagePath) {
|
|
4484
|
-
const hasRoot = chain.some((r) => r === root);
|
|
4485
|
-
if (!hasRoot) {
|
|
4486
|
-
const location = pagePath ? `in ${pagePath}` : "";
|
|
4487
|
-
throw new Error(`[furin] Page ${location} must inherit from root route. ` + 'Add: import { route } from "./root"; and use route.page() or set parent: route');
|
|
4488
6389
|
}
|
|
4489
|
-
for (const
|
|
4490
|
-
|
|
4491
|
-
throw new Error("[furin] Cycle detected in route chain. A route cannot be its own ancestor.");
|
|
4492
|
-
}
|
|
6390
|
+
for (const tag of page?.tags ?? []) {
|
|
6391
|
+
tags.add(tag);
|
|
4493
6392
|
}
|
|
6393
|
+
return tags.size > 0 ? [...tags] : undefined;
|
|
4494
6394
|
}
|
|
4495
|
-
|
|
4496
|
-
// src/router.ts
|
|
4497
6395
|
async function scanPages(pagesDir) {
|
|
4498
6396
|
const root = await scanRootLayout(pagesDir);
|
|
4499
6397
|
const routes = await scanPageFiles(pagesDir, root);
|
|
@@ -4513,8 +6411,10 @@ async function scanRootLayout(pagesDir) {
|
|
|
4513
6411
|
if (!rootExport.layout) {
|
|
4514
6412
|
throw new Error("[furin] root.tsx: createRoute() has no layout.");
|
|
4515
6413
|
}
|
|
4516
|
-
const notFoundEntry = await
|
|
4517
|
-
|
|
6414
|
+
const [notFoundEntry, errorEntry] = await Promise.all([
|
|
6415
|
+
loadConventionComponent(pagesDir, "not-found"),
|
|
6416
|
+
loadConventionComponent(pagesDir, "error")
|
|
6417
|
+
]);
|
|
4518
6418
|
return {
|
|
4519
6419
|
path: rootPath,
|
|
4520
6420
|
route: rootExport,
|
|
@@ -4557,9 +6457,11 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
4557
6457
|
if (fileName.startsWith("_") || fileName === "root" || isConventionFileName(fileName)) {
|
|
4558
6458
|
continue;
|
|
4559
6459
|
}
|
|
4560
|
-
const notFound
|
|
4561
|
-
|
|
4562
|
-
|
|
6460
|
+
const [notFound, errorComponent, segmentBoundaries] = await Promise.all([
|
|
6461
|
+
resolveNearestConvention(absolutePath, pagesDir, "not-found", notFoundCache, root.notFound),
|
|
6462
|
+
resolveNearestConvention(absolutePath, pagesDir, "error", errorCache, root.error),
|
|
6463
|
+
collectSegmentBoundaries(absolutePath, pagesDir, notFoundCache, errorCache)
|
|
6464
|
+
]);
|
|
4563
6465
|
if (IS_DEV) {
|
|
4564
6466
|
const devRoute = await buildDevRoute(absolutePath, relativePath, root);
|
|
4565
6467
|
devRoute.notFound = notFound;
|
|
@@ -4584,7 +6486,8 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
4584
6486
|
mode: resolveMode(page, routeChain),
|
|
4585
6487
|
notFound,
|
|
4586
6488
|
error: errorComponent,
|
|
4587
|
-
segmentBoundaries
|
|
6489
|
+
segmentBoundaries,
|
|
6490
|
+
tags: collectRouteTags(routeChain, page)
|
|
4588
6491
|
});
|
|
4589
6492
|
}
|
|
4590
6493
|
return routes;
|
|
@@ -4604,14 +6507,16 @@ async function collectSegmentBoundaries(pageAbsolutePath, pagesDir, notFoundCach
|
|
|
4604
6507
|
const boundaries = [];
|
|
4605
6508
|
for (let depth = 0;depth < dirs.length; depth++) {
|
|
4606
6509
|
const dir = dirs[depth];
|
|
4607
|
-
|
|
4608
|
-
errorCache.
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
6510
|
+
const [errorEntry, notFoundEntry] = await Promise.all([
|
|
6511
|
+
errorCache.has(dir) ? Promise.resolve(errorCache.get(dir)) : loadConventionComponent(dir, "error").then((r) => {
|
|
6512
|
+
errorCache.set(dir, r);
|
|
6513
|
+
return r;
|
|
6514
|
+
}),
|
|
6515
|
+
notFoundCache.has(dir) ? Promise.resolve(notFoundCache.get(dir)) : loadConventionComponent(dir, "not-found").then((r) => {
|
|
6516
|
+
notFoundCache.set(dir, r);
|
|
6517
|
+
return r;
|
|
6518
|
+
})
|
|
6519
|
+
]);
|
|
4615
6520
|
if (errorEntry || notFoundEntry) {
|
|
4616
6521
|
boundaries.push({
|
|
4617
6522
|
path: dir,
|
|
@@ -4664,22 +6569,27 @@ async function buildDevRoute(absolutePath, relativePath, root) {
|
|
|
4664
6569
|
mode: page ? resolveMode(page, routeChain) : "ssr",
|
|
4665
6570
|
page: page ?? devStubPage,
|
|
4666
6571
|
routeChain,
|
|
6572
|
+
tags: collectRouteTags(routeChain, page),
|
|
4667
6573
|
segmentBoundaries: []
|
|
4668
6574
|
};
|
|
4669
6575
|
}
|
|
4670
6576
|
var TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
|
|
6577
|
+
var DIR_SCAN_CONCURRENCY = 8;
|
|
4671
6578
|
async function collectPageFilePaths(dir) {
|
|
4672
6579
|
const files = [];
|
|
4673
6580
|
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
4674
|
-
|
|
6581
|
+
const resolved = await mapWithConcurrency(entries, DIR_SCAN_CONCURRENCY, async (entry) => {
|
|
4675
6582
|
const absolutePath = join8(dir, entry.name);
|
|
4676
6583
|
if (entry.isDirectory()) {
|
|
4677
|
-
|
|
4678
|
-
continue;
|
|
6584
|
+
return await collectPageFilePaths(absolutePath);
|
|
4679
6585
|
}
|
|
4680
6586
|
if (entry.isFile()) {
|
|
4681
|
-
|
|
6587
|
+
return [absolutePath];
|
|
4682
6588
|
}
|
|
6589
|
+
return [];
|
|
6590
|
+
});
|
|
6591
|
+
for (const chunk of resolved) {
|
|
6592
|
+
files.push(...chunk);
|
|
4683
6593
|
}
|
|
4684
6594
|
return files;
|
|
4685
6595
|
}
|
|
@@ -4724,35 +6634,13 @@ function filePathToPattern(path) {
|
|
|
4724
6634
|
// src/build/scan-server.ts
|
|
4725
6635
|
import { readFileSync as readFileSync2 } from "fs";
|
|
4726
6636
|
import { parse as parse3 } from "yuku-parser";
|
|
4727
|
-
function detectLangFromPath(filePath) {
|
|
4728
|
-
if (filePath.endsWith(".d.ts")) {
|
|
4729
|
-
return "dts";
|
|
4730
|
-
}
|
|
4731
|
-
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
4732
|
-
switch (ext) {
|
|
4733
|
-
case "ts":
|
|
4734
|
-
return "ts";
|
|
4735
|
-
case "tsx":
|
|
4736
|
-
return "tsx";
|
|
4737
|
-
case "jsx":
|
|
4738
|
-
return "jsx";
|
|
4739
|
-
default:
|
|
4740
|
-
return "js";
|
|
4741
|
-
}
|
|
4742
|
-
}
|
|
4743
6637
|
function scanFurinInstances(serverEntryPath) {
|
|
4744
6638
|
const code = readFileSync2(serverEntryPath, "utf8");
|
|
4745
|
-
|
|
6639
|
+
const lang = detectLangFromPath(serverEntryPath);
|
|
4746
6640
|
if (lang === "dts") {
|
|
4747
6641
|
return [];
|
|
4748
6642
|
}
|
|
4749
|
-
|
|
4750
|
-
if (lang === "ts" || lang === "tsx") {
|
|
4751
|
-
const transpiler = new Bun.Transpiler({ loader: lang });
|
|
4752
|
-
parseInput = transpiler.transformSync(code);
|
|
4753
|
-
lang = "js";
|
|
4754
|
-
}
|
|
4755
|
-
const { program, diagnostics } = parse3(parseInput, { sourceType: "module", lang });
|
|
6643
|
+
const { program, diagnostics } = parse3(code, { sourceType: "module", lang });
|
|
4756
6644
|
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
4757
6645
|
if (firstError) {
|
|
4758
6646
|
console.error("[furin] scan-server: parse error:", firstError.message, "in", serverEntryPath);
|
|
@@ -4770,7 +6658,7 @@ function checkFurinCall(node, out) {
|
|
|
4770
6658
|
if (!(isFurinCall && Array.isArray(args)) || args.length === 0) {
|
|
4771
6659
|
return;
|
|
4772
6660
|
}
|
|
4773
|
-
const firstArg = args[0];
|
|
6661
|
+
const firstArg = unwrapTSExpression(args[0]);
|
|
4774
6662
|
if (firstArg?.type !== "ObjectExpression") {
|
|
4775
6663
|
return;
|
|
4776
6664
|
}
|