@teyik0/furin 0.1.0-alpha.13 → 0.1.0-alpha.14
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/await.d.ts +67 -0
- package/dist/build/index.js +2013 -191
- package/dist/cli/index.js +2007 -190
- package/dist/client.d.ts +33 -2
- 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 +3 -0
- package/dist/furin.js +2684 -318
- 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 +247 -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 +63 -0
- package/dist/router.js +2768 -317
- package/dist/router.ts +543 -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/await.tsx +175 -0
- package/src/build/client.ts +4 -8
- package/src/build/hydrate.ts +67 -1
- package/src/build/route-types.ts +5 -1
- package/src/build/scan-server.ts +6 -23
- package/src/client.ts +58 -1
- 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 +12 -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 +7 -0
- package/src/render/default-screens.tsx +4 -11
- package/src/render/element.tsx +26 -3
- package/src/render/index.ts +247 -44
- package/src/render/loaders.ts +221 -18
- package/src/render/shell.ts +27 -12
- package/src/router-provider.tsx +414 -122
- package/src/router.ts +543 -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: {
|
|
@@ -2446,15 +3660,126 @@ function applyMaskersToTree(obj, maskers) {
|
|
|
2446
3660
|
else if (typeof val === "object")
|
|
2447
3661
|
applyMaskersToTree(val, maskers);
|
|
2448
3662
|
}
|
|
2449
|
-
}
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
function applyMaskers(value, maskers) {
|
|
3666
|
+
let result = value;
|
|
3667
|
+
for (const [pattern, mask] of maskers) {
|
|
3668
|
+
pattern.lastIndex = 0;
|
|
3669
|
+
result = result.replace(pattern, mask);
|
|
3670
|
+
}
|
|
3671
|
+
return result;
|
|
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
|
+
};
|
|
2450
3779
|
}
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
pattern.lastIndex = 0;
|
|
2455
|
-
result = result.replace(pattern, mask);
|
|
2456
|
-
}
|
|
2457
|
-
return result;
|
|
3780
|
+
var emptyRunner = createPluginRunner([]);
|
|
3781
|
+
function getEmptyPluginRunner() {
|
|
3782
|
+
return emptyRunner;
|
|
2458
3783
|
}
|
|
2459
3784
|
function isPlainObject(val) {
|
|
2460
3785
|
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
@@ -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,378 @@ 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
|
|
|
3768
5219
|
// src/context-logger.ts
|
|
3769
5220
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
3770
5221
|
|
|
3771
|
-
// ../../node_modules/.bun/evlog@2.
|
|
5222
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/routes-CnIgYWf8.mjs
|
|
5223
|
+
function shouldLog(path, include, exclude) {
|
|
5224
|
+
if (exclude && exclude.length > 0) {
|
|
5225
|
+
if (exclude.some((pattern) => matchesPattern(path, pattern)))
|
|
5226
|
+
return false;
|
|
5227
|
+
}
|
|
5228
|
+
if (!include || include.length === 0)
|
|
5229
|
+
return true;
|
|
5230
|
+
return include.some((pattern) => matchesPattern(path, pattern));
|
|
5231
|
+
}
|
|
5232
|
+
function getServiceForPath(path, routes) {
|
|
5233
|
+
if (!routes)
|
|
5234
|
+
return;
|
|
5235
|
+
for (const [pattern, config] of Object.entries(routes))
|
|
5236
|
+
if (matchesPattern(path, pattern))
|
|
5237
|
+
return config.service;
|
|
5238
|
+
}
|
|
5239
|
+
|
|
5240
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/fork-8u_zFOJq.mjs
|
|
5241
|
+
var noopResult = {
|
|
5242
|
+
logger: {
|
|
5243
|
+
set() {},
|
|
5244
|
+
error() {},
|
|
5245
|
+
info() {},
|
|
5246
|
+
warn() {},
|
|
5247
|
+
emit() {
|
|
5248
|
+
return null;
|
|
5249
|
+
},
|
|
5250
|
+
getContext() {
|
|
5251
|
+
return {};
|
|
5252
|
+
}
|
|
5253
|
+
},
|
|
5254
|
+
finish: () => Promise.resolve(null),
|
|
5255
|
+
skipped: true
|
|
5256
|
+
};
|
|
5257
|
+
var runnerCache = /* @__PURE__ */ new WeakMap;
|
|
5258
|
+
function resolveMiddlewarePluginRunner(options) {
|
|
5259
|
+
const global2 = getGlobalPluginRunner();
|
|
5260
|
+
const local = options.plugins;
|
|
5261
|
+
if (!local || local.length === 0)
|
|
5262
|
+
return global2;
|
|
5263
|
+
const cached = runnerCache.get(local);
|
|
5264
|
+
if (cached && cached.global === global2)
|
|
5265
|
+
return cached.merged;
|
|
5266
|
+
const merged = /* @__PURE__ */ new Map;
|
|
5267
|
+
for (const plugin of global2.plugins)
|
|
5268
|
+
merged.set(plugin.name, plugin);
|
|
5269
|
+
for (const plugin of local)
|
|
5270
|
+
merged.set(plugin.name, plugin);
|
|
5271
|
+
if (merged.size === 0)
|
|
5272
|
+
return getEmptyPluginRunner();
|
|
5273
|
+
const runner = createPluginRunner(Array.from(merged.values()));
|
|
5274
|
+
runnerCache.set(local, {
|
|
5275
|
+
global: global2,
|
|
5276
|
+
merged: runner
|
|
5277
|
+
});
|
|
5278
|
+
return runner;
|
|
5279
|
+
}
|
|
5280
|
+
async function runEnrichAndDrain(emittedEvent, options, requestInfo, responseStatus, plugins) {
|
|
5281
|
+
const runner = plugins ?? resolveMiddlewarePluginRunner(options);
|
|
5282
|
+
const resolvedRedact = resolveRedactConfig(options.redact);
|
|
5283
|
+
if (resolvedRedact)
|
|
5284
|
+
redactEvent(emittedEvent, resolvedRedact);
|
|
5285
|
+
if (options.enrich || runner.hasEnrich) {
|
|
5286
|
+
const enrichCtx = {
|
|
5287
|
+
event: emittedEvent,
|
|
5288
|
+
request: requestInfo,
|
|
5289
|
+
headers: options.headers,
|
|
5290
|
+
response: { status: responseStatus }
|
|
5291
|
+
};
|
|
5292
|
+
if (options.enrich)
|
|
5293
|
+
try {
|
|
5294
|
+
await options.enrich(enrichCtx);
|
|
5295
|
+
} catch (err) {
|
|
5296
|
+
console.error("[evlog] enrich failed:", err);
|
|
5297
|
+
}
|
|
5298
|
+
if (runner.hasEnrich)
|
|
5299
|
+
await runner.runEnrich(enrichCtx);
|
|
5300
|
+
}
|
|
5301
|
+
const drain = options.drain ?? getGlobalDrain();
|
|
5302
|
+
const hasUserDrain = !!drain;
|
|
5303
|
+
const hasPluginDrain = runner.hasDrain;
|
|
5304
|
+
if (hasUserDrain || hasPluginDrain) {
|
|
5305
|
+
const drainCtx = {
|
|
5306
|
+
event: emittedEvent,
|
|
5307
|
+
request: requestInfo,
|
|
5308
|
+
headers: options.headers
|
|
5309
|
+
};
|
|
5310
|
+
const tasks = [];
|
|
5311
|
+
if (hasUserDrain)
|
|
5312
|
+
tasks.push((async () => {
|
|
5313
|
+
try {
|
|
5314
|
+
await drain(drainCtx);
|
|
5315
|
+
} catch (err) {
|
|
5316
|
+
console.error("[evlog] drain failed:", err);
|
|
5317
|
+
}
|
|
5318
|
+
})());
|
|
5319
|
+
if (hasPluginDrain)
|
|
5320
|
+
tasks.push(runner.runDrain(drainCtx));
|
|
5321
|
+
await Promise.all(tasks);
|
|
5322
|
+
}
|
|
5323
|
+
}
|
|
5324
|
+
function createMiddlewareLogger(options) {
|
|
5325
|
+
if (!isEnabled())
|
|
5326
|
+
return noopResult;
|
|
5327
|
+
const { method, path, requestId, include, exclude, routes, keep } = options;
|
|
5328
|
+
if (!shouldLog(path, include, exclude))
|
|
5329
|
+
return noopResult;
|
|
5330
|
+
const resolvedRequestId = requestId || crypto.randomUUID();
|
|
5331
|
+
const logger = createRequestLogger({
|
|
5332
|
+
method,
|
|
5333
|
+
path,
|
|
5334
|
+
requestId: resolvedRequestId
|
|
5335
|
+
}, { _deferDrain: true });
|
|
5336
|
+
const routeService = getServiceForPath(path, routes);
|
|
5337
|
+
if (routeService)
|
|
5338
|
+
logger.set({ service: routeService });
|
|
5339
|
+
const pluginRunner = resolveMiddlewarePluginRunner(options);
|
|
5340
|
+
if (pluginRunner.hasExtendLogger)
|
|
5341
|
+
pluginRunner.applyExtendLogger(logger);
|
|
5342
|
+
const startTime = Date.now();
|
|
5343
|
+
const requestInfo = {
|
|
5344
|
+
method,
|
|
5345
|
+
path,
|
|
5346
|
+
requestId: resolvedRequestId
|
|
5347
|
+
};
|
|
5348
|
+
if (pluginRunner.hasRequestLifecycle)
|
|
5349
|
+
pluginRunner.runOnRequestStart({
|
|
5350
|
+
logger,
|
|
5351
|
+
request: requestInfo,
|
|
5352
|
+
headers: options.headers
|
|
5353
|
+
});
|
|
5354
|
+
const finish = async (opts) => {
|
|
5355
|
+
const { status, error } = opts ?? {};
|
|
5356
|
+
if (error) {
|
|
5357
|
+
logger.error(error);
|
|
5358
|
+
const errorStatus = extractErrorStatus(error);
|
|
5359
|
+
logger.set({ status: errorStatus });
|
|
5360
|
+
} else if (status !== undefined)
|
|
5361
|
+
logger.set({ status });
|
|
5362
|
+
const durationMs = Date.now() - startTime;
|
|
5363
|
+
const resolvedStatus = error ? extractErrorStatus(error) : status ?? logger.getContext().status;
|
|
5364
|
+
const tailCtx = {
|
|
5365
|
+
status: resolvedStatus,
|
|
5366
|
+
duration: durationMs,
|
|
5367
|
+
path,
|
|
5368
|
+
method,
|
|
5369
|
+
context: logger.getContext(),
|
|
5370
|
+
shouldKeep: false
|
|
5371
|
+
};
|
|
5372
|
+
if (keep)
|
|
5373
|
+
await keep(tailCtx);
|
|
5374
|
+
if (pluginRunner.hasKeep)
|
|
5375
|
+
await pluginRunner.runKeep(tailCtx);
|
|
5376
|
+
const forceKeep = tailCtx.shouldKeep || shouldKeep(tailCtx);
|
|
5377
|
+
const emittedEvent = logger.emit({ _forceKeep: forceKeep });
|
|
5378
|
+
if (emittedEvent && (options.enrich || options.drain || pluginRunner.hasEnrich || pluginRunner.hasDrain || getGlobalDrain()))
|
|
5379
|
+
await runEnrichAndDrain(emittedEvent, options, requestInfo, resolvedStatus, pluginRunner);
|
|
5380
|
+
if (pluginRunner.hasRequestLifecycle)
|
|
5381
|
+
pluginRunner.runOnRequestFinish({
|
|
5382
|
+
logger,
|
|
5383
|
+
request: requestInfo,
|
|
5384
|
+
headers: options.headers,
|
|
5385
|
+
event: emittedEvent,
|
|
5386
|
+
status: resolvedStatus,
|
|
5387
|
+
durationMs,
|
|
5388
|
+
error
|
|
5389
|
+
});
|
|
5390
|
+
return emittedEvent;
|
|
5391
|
+
};
|
|
5392
|
+
return {
|
|
5393
|
+
logger,
|
|
5394
|
+
finish,
|
|
5395
|
+
skipped: false
|
|
5396
|
+
};
|
|
5397
|
+
}
|
|
5398
|
+
function attachForkToLogger(storage, parent, middlewareOptions, lifecycle) {
|
|
5399
|
+
const log = parent;
|
|
5400
|
+
log.fork = (label, fn) => {
|
|
5401
|
+
forkBackgroundLogger({
|
|
5402
|
+
storage,
|
|
5403
|
+
parent,
|
|
5404
|
+
middlewareOptions,
|
|
5405
|
+
label,
|
|
5406
|
+
fn,
|
|
5407
|
+
lifecycle
|
|
5408
|
+
});
|
|
5409
|
+
};
|
|
5410
|
+
}
|
|
5411
|
+
function forkBackgroundLogger(options) {
|
|
5412
|
+
const { storage, parent, middlewareOptions, label, fn, lifecycle } = options;
|
|
5413
|
+
const parentCtx = parent.getContext();
|
|
5414
|
+
const parentRequestId = parentCtx.requestId;
|
|
5415
|
+
if (typeof parentRequestId !== "string" || parentRequestId.length === 0)
|
|
5416
|
+
throw new Error("[evlog] log.fork() requires the parent logger to have a requestId. Ensure the request was created by evlog middleware.");
|
|
5417
|
+
const method = String(parentCtx.method ?? middlewareOptions.method);
|
|
5418
|
+
const path = String(parentCtx.path ?? middlewareOptions.path);
|
|
5419
|
+
const child = createRequestLogger({
|
|
5420
|
+
method,
|
|
5421
|
+
path,
|
|
5422
|
+
requestId: crypto.randomUUID()
|
|
5423
|
+
}, { _deferDrain: true });
|
|
5424
|
+
child.set({
|
|
5425
|
+
operation: label,
|
|
5426
|
+
_parentRequestId: parentRequestId
|
|
5427
|
+
});
|
|
5428
|
+
const childRequestInfo = {
|
|
5429
|
+
method,
|
|
5430
|
+
path,
|
|
5431
|
+
requestId: child.getContext().requestId
|
|
5432
|
+
};
|
|
5433
|
+
storage.run(child, () => {
|
|
5434
|
+
lifecycle?.onChildEnter?.(child);
|
|
5435
|
+
Promise.resolve().then(() => fn()).then(async () => {
|
|
5436
|
+
const emittedEvent = child.emit();
|
|
5437
|
+
const ctxStatus = child.getContext().status;
|
|
5438
|
+
const status = emittedEvent?.status ?? (typeof ctxStatus === "number" ? ctxStatus : undefined);
|
|
5439
|
+
if (emittedEvent && (middlewareOptions.enrich || middlewareOptions.drain || getGlobalDrain()))
|
|
5440
|
+
await runEnrichAndDrain(emittedEvent, middlewareOptions, childRequestInfo, status);
|
|
5441
|
+
}).catch(async (err) => {
|
|
5442
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
5443
|
+
child.error(error);
|
|
5444
|
+
child.set({ status: extractErrorStatus(error) });
|
|
5445
|
+
const emittedEvent = child.emit();
|
|
5446
|
+
const status = extractErrorStatus(error);
|
|
5447
|
+
if (emittedEvent && (middlewareOptions.enrich || middlewareOptions.drain || getGlobalDrain()))
|
|
5448
|
+
await runEnrichAndDrain(emittedEvent, middlewareOptions, childRequestInfo, status);
|
|
5449
|
+
}).finally(() => {
|
|
5450
|
+
lifecycle?.onChildExit?.(child);
|
|
5451
|
+
});
|
|
5452
|
+
});
|
|
5453
|
+
}
|
|
5454
|
+
|
|
5455
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/integration-DTZtjSqh.mjs
|
|
5456
|
+
function normalizeHeaders(headers) {
|
|
5457
|
+
if (!headers)
|
|
5458
|
+
return;
|
|
5459
|
+
if (typeof headers.forEach === "function" && typeof headers.get === "function")
|
|
5460
|
+
return extractSafeHeaders(headers);
|
|
5461
|
+
return extractSafeNodeHeaders(headers);
|
|
5462
|
+
}
|
|
5463
|
+
function defineFrameworkIntegration(spec) {
|
|
5464
|
+
return { start(ctx, options = {}) {
|
|
5465
|
+
const extracted = spec.extractRequest(ctx);
|
|
5466
|
+
const headers = normalizeHeaders(extracted.headers);
|
|
5467
|
+
const middlewareOptions = {
|
|
5468
|
+
method: extracted.method,
|
|
5469
|
+
path: extracted.path,
|
|
5470
|
+
requestId: extracted.requestId || crypto.randomUUID(),
|
|
5471
|
+
headers,
|
|
5472
|
+
...options
|
|
5473
|
+
};
|
|
5474
|
+
const result = createMiddlewareLogger(middlewareOptions);
|
|
5475
|
+
if (!result.skipped) {
|
|
5476
|
+
if (spec.storage)
|
|
5477
|
+
attachForkToLogger(spec.storage, result.logger, middlewareOptions, spec.forkLifecycle);
|
|
5478
|
+
spec.attachLogger(ctx, result.logger);
|
|
5479
|
+
}
|
|
5480
|
+
const { storage } = spec;
|
|
5481
|
+
const runWith = async (fn) => {
|
|
5482
|
+
if (!storage || result.skipped)
|
|
5483
|
+
return await fn();
|
|
5484
|
+
return await storage.run(result.logger, fn);
|
|
5485
|
+
};
|
|
5486
|
+
return {
|
|
5487
|
+
...result,
|
|
5488
|
+
middlewareOptions,
|
|
5489
|
+
runWith
|
|
5490
|
+
};
|
|
5491
|
+
} };
|
|
5492
|
+
}
|
|
5493
|
+
|
|
5494
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/elysia/index.mjs
|
|
3772
5495
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3773
5496
|
import { Elysia } from "elysia";
|
|
3774
5497
|
var storage = new AsyncLocalStorage;
|
|
3775
5498
|
var activeLoggers = /* @__PURE__ */ new WeakSet;
|
|
3776
|
-
function
|
|
5499
|
+
function useLogger() {
|
|
3777
5500
|
const logger = storage.getStore();
|
|
3778
5501
|
if (!logger || !activeLoggers.has(logger))
|
|
3779
5502
|
throw new Error("[evlog] useLogger() was called outside of an evlog plugin context. Make sure app.use(evlog()) is registered before your routes.");
|
|
3780
5503
|
return logger;
|
|
3781
5504
|
}
|
|
5505
|
+
var integration = defineFrameworkIntegration({
|
|
5506
|
+
name: "elysia",
|
|
5507
|
+
extractRequest: ({ request, path, headers }) => ({
|
|
5508
|
+
method: request.method,
|
|
5509
|
+
path,
|
|
5510
|
+
headers,
|
|
5511
|
+
requestId: headers["x-request-id"]
|
|
5512
|
+
}),
|
|
5513
|
+
attachLogger: ({ request, path, headers }, logger) => {
|
|
5514
|
+
attachForkToLogger(storage, logger, {
|
|
5515
|
+
method: request.method,
|
|
5516
|
+
path,
|
|
5517
|
+
requestId: headers["x-request-id"]
|
|
5518
|
+
}, {
|
|
5519
|
+
onChildEnter: (child) => {
|
|
5520
|
+
activeLoggers.add(child);
|
|
5521
|
+
},
|
|
5522
|
+
onChildExit: (child) => {
|
|
5523
|
+
activeLoggers.delete(child);
|
|
5524
|
+
}
|
|
5525
|
+
});
|
|
5526
|
+
activeLoggers.add(logger);
|
|
5527
|
+
}
|
|
5528
|
+
});
|
|
3782
5529
|
|
|
3783
5530
|
// src/context-logger.ts
|
|
3784
5531
|
var noopLogger2 = {
|
|
@@ -3791,9 +5538,9 @@ var noopLogger2 = {
|
|
|
3791
5538
|
fork: (_label, fn) => fn()
|
|
3792
5539
|
};
|
|
3793
5540
|
var syntheticRenderStorage = new AsyncLocalStorage2;
|
|
3794
|
-
function
|
|
5541
|
+
function useLogger2() {
|
|
3795
5542
|
try {
|
|
3796
|
-
return
|
|
5543
|
+
return useLogger();
|
|
3797
5544
|
} catch {
|
|
3798
5545
|
return syntheticRenderStorage.getStore() ?? noopLogger2;
|
|
3799
5546
|
}
|
|
@@ -4020,16 +5767,42 @@ function errorMessageOf(err) {
|
|
|
4020
5767
|
return "";
|
|
4021
5768
|
}
|
|
4022
5769
|
var SERVER_RESET_NOOP2 = () => {};
|
|
4023
|
-
function buildErrorElement(component, error, digest) {
|
|
5770
|
+
function buildErrorElement(component, error, digest, messageOverride, status) {
|
|
4024
5771
|
const ErrorView = component ?? DefaultErrorComponent;
|
|
4025
|
-
|
|
5772
|
+
let message;
|
|
5773
|
+
if (component) {
|
|
5774
|
+
message = messageOverride ?? errorMessageOf(error);
|
|
5775
|
+
} else {
|
|
5776
|
+
message = "An unexpected error occurred.";
|
|
5777
|
+
}
|
|
4026
5778
|
return /* @__PURE__ */ jsxDEV4(ErrorView, {
|
|
4027
|
-
error: { message, digest },
|
|
5779
|
+
error: { message, digest, status },
|
|
4028
5780
|
reset: SERVER_RESET_NOOP2
|
|
4029
5781
|
}, undefined, false, undefined, this);
|
|
4030
5782
|
}
|
|
4031
5783
|
|
|
5784
|
+
// src/client.ts
|
|
5785
|
+
var DEFERRED_BRAND = "__isDeferred";
|
|
5786
|
+
function isDeferred(v) {
|
|
5787
|
+
return typeof v === "object" && v !== null && Object.hasOwn(v, DEFERRED_BRAND) && v[DEFERRED_BRAND] === true;
|
|
5788
|
+
}
|
|
5789
|
+
|
|
4032
5790
|
// src/render/loaders.ts
|
|
5791
|
+
var REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
5792
|
+
function isHttpRedirect(res) {
|
|
5793
|
+
return REDIRECT_STATUSES.has(res.status) && res.headers.has("location");
|
|
5794
|
+
}
|
|
5795
|
+
async function readResponseMessage(res) {
|
|
5796
|
+
if (res.body === null) {
|
|
5797
|
+
return res.statusText;
|
|
5798
|
+
}
|
|
5799
|
+
try {
|
|
5800
|
+
const body = await res.text();
|
|
5801
|
+
return body || res.statusText;
|
|
5802
|
+
} catch {
|
|
5803
|
+
return res.statusText;
|
|
5804
|
+
}
|
|
5805
|
+
}
|
|
4033
5806
|
function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
4034
5807
|
const cache = new Map;
|
|
4035
5808
|
return new Proxy(ctx, {
|
|
@@ -4052,9 +5825,40 @@ function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
|
4052
5825
|
}
|
|
4053
5826
|
});
|
|
4054
5827
|
}
|
|
4055
|
-
|
|
5828
|
+
function splitDeferredResult(pageResult, routeChainData) {
|
|
5829
|
+
const syncData = {};
|
|
5830
|
+
const deferredPromises = {};
|
|
5831
|
+
for (const [key, value] of Object.entries(routeChainData)) {
|
|
5832
|
+
syncData[key] = value;
|
|
5833
|
+
}
|
|
5834
|
+
for (const [key, value] of Object.entries(pageResult)) {
|
|
5835
|
+
if (key === "__isDeferred") {
|
|
5836
|
+
continue;
|
|
5837
|
+
}
|
|
5838
|
+
if (isPromiseLike(value)) {
|
|
5839
|
+
deferredPromises[key] = Promise.resolve(value);
|
|
5840
|
+
} else {
|
|
5841
|
+
syncData[key] = value;
|
|
5842
|
+
}
|
|
5843
|
+
}
|
|
5844
|
+
return {
|
|
5845
|
+
syncData,
|
|
5846
|
+
deferredPromises: Object.keys(deferredPromises).length > 0 ? deferredPromises : undefined
|
|
5847
|
+
};
|
|
5848
|
+
}
|
|
5849
|
+
function isPromiseLike(value) {
|
|
5850
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
5851
|
+
}
|
|
5852
|
+
function assertNoDeferredInRouteLoaders(routeResults) {
|
|
5853
|
+
for (const result of routeResults) {
|
|
5854
|
+
if (isDeferred(result)) {
|
|
5855
|
+
throw new Error("[furin] defer() is only supported in a page loader (route.page({ loader })). A route/layout loader returned a deferred object; move the deferred fields to the page loader, or `await` them in the route loader and return resolved values.");
|
|
5856
|
+
}
|
|
5857
|
+
}
|
|
5858
|
+
}
|
|
5859
|
+
async function runLoaders(route, ctx) {
|
|
4056
5860
|
try {
|
|
4057
|
-
const ctxRecord = { ...ctx, log:
|
|
5861
|
+
const ctxRecord = { ...ctx, log: useLogger2() };
|
|
4058
5862
|
const loaderMap = new Map;
|
|
4059
5863
|
let accumulatedParentPromise = Promise.resolve({});
|
|
4060
5864
|
for (const r of route.routeChain) {
|
|
@@ -4073,22 +5877,47 @@ async function runLoaders(route, ctx, _rootLayout) {
|
|
|
4073
5877
|
const pageCtx = createLoaderCtx(ctxRecord, accumulatedParentPromise);
|
|
4074
5878
|
const pagePromise = route.page?.loader ? Promise.resolve(route.page.loader(pageCtx)).then((r) => r ?? {}) : Promise.resolve({});
|
|
4075
5879
|
const results = await Promise.all([...loaderMap.values(), pagePromise]);
|
|
4076
|
-
const
|
|
5880
|
+
const merged = Object.assign({}, ...results);
|
|
4077
5881
|
const headers = {};
|
|
4078
5882
|
Object.assign(headers, ctx.set.headers);
|
|
4079
|
-
|
|
5883
|
+
const routeOnlyResults = results.slice(0, loaderMap.size);
|
|
5884
|
+
const pageResult = results[loaderMap.size];
|
|
5885
|
+
assertNoDeferredInRouteLoaders(routeOnlyResults);
|
|
5886
|
+
const routeCtx = { params: ctx.params, query: ctx.query, path: ctx.path };
|
|
5887
|
+
if (isDeferred(pageResult)) {
|
|
5888
|
+
const routeMerged = Object.assign({}, ...routeOnlyResults);
|
|
5889
|
+
const { syncData, deferredPromises } = splitDeferredResult(pageResult, routeMerged);
|
|
5890
|
+
return { type: "data", syncData: { ...syncData, ...routeCtx }, deferredPromises, headers };
|
|
5891
|
+
}
|
|
5892
|
+
return {
|
|
5893
|
+
type: "data",
|
|
5894
|
+
syncData: { ...merged, ...routeCtx },
|
|
5895
|
+
deferredPromises: undefined,
|
|
5896
|
+
headers
|
|
5897
|
+
};
|
|
4080
5898
|
} catch (err) {
|
|
5899
|
+
const headers = {};
|
|
5900
|
+
Object.assign(headers, ctx.set.headers);
|
|
4081
5901
|
if (isNotFoundError(err)) {
|
|
4082
|
-
|
|
4083
|
-
Object.assign(headers2, ctx.set.headers);
|
|
4084
|
-
return { type: "not-found", error: err, headers: headers2 };
|
|
5902
|
+
return { type: "not-found", error: err, headers };
|
|
4085
5903
|
}
|
|
4086
5904
|
if (err instanceof Response) {
|
|
4087
|
-
|
|
5905
|
+
if (isHttpRedirect(err)) {
|
|
5906
|
+
return { type: "redirect", response: err };
|
|
5907
|
+
}
|
|
5908
|
+
const isMalformedRedirect = REDIRECT_STATUSES.has(err.status);
|
|
5909
|
+
const status = isMalformedRedirect ? 500 : err.status;
|
|
5910
|
+
const body = await readResponseMessage(err);
|
|
5911
|
+
const message = body || "Something went wrong";
|
|
5912
|
+
return { type: "error", error: err, status, message, headers };
|
|
4088
5913
|
}
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
5914
|
+
return {
|
|
5915
|
+
type: "error",
|
|
5916
|
+
error: err,
|
|
5917
|
+
status: 500,
|
|
5918
|
+
message: "Something went wrong",
|
|
5919
|
+
headers
|
|
5920
|
+
};
|
|
4092
5921
|
}
|
|
4093
5922
|
}
|
|
4094
5923
|
|
|
@@ -4136,9 +5965,14 @@ var IS_DEV = true;
|
|
|
4136
5965
|
function withSSRRouterContext(element, contextValue) {
|
|
4137
5966
|
return createElement3(RouterContext.Provider, { value: contextValue }, element);
|
|
4138
5967
|
}
|
|
5968
|
+
function assertDeferredModeAllowed(route, deferredPromises) {
|
|
5969
|
+
if (deferredPromises !== undefined && route.mode !== "ssr") {
|
|
5970
|
+
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.");
|
|
5971
|
+
}
|
|
5972
|
+
}
|
|
4139
5973
|
async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult) {
|
|
4140
5974
|
const loaderStart = Date.now();
|
|
4141
|
-
const loaderResult = precomputedLoaderResult ?? await runLoaders(route, ctx
|
|
5975
|
+
const loaderResult = precomputedLoaderResult ?? await runLoaders(route, ctx);
|
|
4142
5976
|
const loader_ms = Date.now() - loaderStart;
|
|
4143
5977
|
if (loaderResult.type === "redirect") {
|
|
4144
5978
|
return loaderResult.response;
|
|
@@ -4149,10 +5983,13 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4149
5983
|
const isNotFound = loaderResult.type === "not-found";
|
|
4150
5984
|
const isError = loaderResult.type === "error";
|
|
4151
5985
|
const isFallback = isNotFound || isError;
|
|
4152
|
-
const
|
|
5986
|
+
const syncData = isFallback ? {} : loaderResult.syncData;
|
|
5987
|
+
const deferredPromises = !isFallback && loaderResult.type === "data" ? loaderResult.deferredPromises : undefined;
|
|
5988
|
+
assertDeferredModeAllowed(route, deferredPromises);
|
|
4153
5989
|
const headers = loaderResult.headers;
|
|
4154
5990
|
const componentProps = {
|
|
4155
|
-
...
|
|
5991
|
+
...syncData,
|
|
5992
|
+
...deferredPromises ?? {},
|
|
4156
5993
|
params: ctx.params,
|
|
4157
5994
|
query: ctx.query,
|
|
4158
5995
|
path: ctx.path
|
|
@@ -4170,8 +6007,8 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4170
6007
|
notFoundError = { message: loaderResult.error.message, data: loaderResult.error.data };
|
|
4171
6008
|
} else if (loaderResult.type === "error") {
|
|
4172
6009
|
errorDigest = computeErrorDigest(loaderResult.error);
|
|
4173
|
-
element = buildErrorElement(route.error ?? root.error, loaderResult.error, errorDigest);
|
|
4174
|
-
status =
|
|
6010
|
+
element = buildErrorElement(route.error ?? root.error, loaderResult.error, errorDigest, loaderResult.message, loaderResult.status);
|
|
6011
|
+
status = loaderResult.status;
|
|
4175
6012
|
} else {
|
|
4176
6013
|
element = buildElement(route, componentProps, root.route);
|
|
4177
6014
|
}
|
|
@@ -4190,12 +6027,14 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4190
6027
|
element = withSSRRouterContext(element, ssrContext);
|
|
4191
6028
|
return {
|
|
4192
6029
|
componentProps,
|
|
6030
|
+
deferredPromises,
|
|
4193
6031
|
element,
|
|
4194
6032
|
errorDigest,
|
|
4195
6033
|
headData,
|
|
4196
6034
|
headers,
|
|
4197
6035
|
loader_ms,
|
|
4198
6036
|
notFoundError,
|
|
6037
|
+
syncData,
|
|
4199
6038
|
ssrContext,
|
|
4200
6039
|
status,
|
|
4201
6040
|
template
|
|
@@ -4218,7 +6057,7 @@ function renderForPath(route, params, root, origin, mode, basePath) {
|
|
|
4218
6057
|
if (prepared instanceof Response) {
|
|
4219
6058
|
return prepared;
|
|
4220
6059
|
}
|
|
4221
|
-
|
|
6060
|
+
useLogger2().set({
|
|
4222
6061
|
furin: {
|
|
4223
6062
|
render: mode,
|
|
4224
6063
|
route: route.pattern,
|
|
@@ -4227,17 +6066,27 @@ function renderForPath(route, params, root, origin, mode, basePath) {
|
|
|
4227
6066
|
...prepared.errorDigest ? { digest: prepared.errorDigest } : {}
|
|
4228
6067
|
}
|
|
4229
6068
|
});
|
|
4230
|
-
const {
|
|
6069
|
+
const { deferredPromises, element, headData, headers, status, syncData, template } = prepared;
|
|
4231
6070
|
const stream = await renderToReadableStream(element);
|
|
4232
6071
|
await stream.allReady;
|
|
4233
6072
|
const reactHtml = await streamToString(stream);
|
|
4234
6073
|
return {
|
|
4235
|
-
html: assembleHTML(template, headData, reactHtml,
|
|
6074
|
+
html: assembleHTML(template, headData, reactHtml, syncData),
|
|
4236
6075
|
headers,
|
|
6076
|
+
ndjson: await serializeLoaderDataNdjson(syncData, deferredPromises),
|
|
4237
6077
|
status
|
|
4238
6078
|
};
|
|
4239
6079
|
}, { route: route.pattern, render: mode });
|
|
4240
6080
|
}
|
|
6081
|
+
async function serializeLoaderDataNdjson(syncData, deferredPromises) {
|
|
6082
|
+
const payload = {
|
|
6083
|
+
...syncData,
|
|
6084
|
+
...deferredPromises ?? {}
|
|
6085
|
+
};
|
|
6086
|
+
const serialized = await toCrossJSONAsync(payload);
|
|
6087
|
+
return `${JSON.stringify(serialized)}
|
|
6088
|
+
`;
|
|
6089
|
+
}
|
|
4241
6090
|
async function prerenderSSG(route, params, root, origin, basePath) {
|
|
4242
6091
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
4243
6092
|
const cached = getSSGCache(resolvedPath);
|
|
@@ -4249,7 +6098,12 @@ async function prerenderSSG(route, params, root, origin, basePath) {
|
|
|
4249
6098
|
return renderResult;
|
|
4250
6099
|
}
|
|
4251
6100
|
const result = renderResult;
|
|
4252
|
-
const entry = {
|
|
6101
|
+
const entry = {
|
|
6102
|
+
cachedAt: Date.now(),
|
|
6103
|
+
html: result.html,
|
|
6104
|
+
ndjson: result.ndjson,
|
|
6105
|
+
status: result.status
|
|
6106
|
+
};
|
|
4253
6107
|
setSSGCache(resolvedPath, entry);
|
|
4254
6108
|
return entry;
|
|
4255
6109
|
}
|
|
@@ -4259,12 +6113,12 @@ var pendingRevalidations = new Set;
|
|
|
4259
6113
|
var STATIC_CONCURRENCY = 4;
|
|
4260
6114
|
var DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
|
|
4261
6115
|
var TRAILING_SLASHES_RE = /\/+$/;
|
|
4262
|
-
function pathToOutputFile(urlPath, outDir) {
|
|
6116
|
+
function pathToOutputFile(urlPath, outDir, fileName) {
|
|
4263
6117
|
const normalizedOutDir = resolve2(outDir);
|
|
4264
6118
|
if (urlPath === "/" || urlPath === "") {
|
|
4265
|
-
return join7(normalizedOutDir,
|
|
6119
|
+
return join7(normalizedOutDir, fileName);
|
|
4266
6120
|
}
|
|
4267
|
-
const resolved = resolve2(normalizedOutDir, urlPath.slice(1),
|
|
6121
|
+
const resolved = resolve2(normalizedOutDir, urlPath.slice(1), fileName);
|
|
4268
6122
|
if (!resolved.startsWith(`${normalizedOutDir}${sep}`)) {
|
|
4269
6123
|
throw new Error(`[furin] static: unsafe output path detected for URL "${urlPath}" \u2014 path traversal via ".." is not allowed.`);
|
|
4270
6124
|
}
|
|
@@ -4272,17 +6126,19 @@ function pathToOutputFile(urlPath, outDir) {
|
|
|
4272
6126
|
}
|
|
4273
6127
|
async function prerenderAndWrite(route, params, root, outDir, renderedRoutes, skippedRoutes, basePath) {
|
|
4274
6128
|
const urlPath = resolvePath(route.pattern, params);
|
|
4275
|
-
const
|
|
6129
|
+
const htmlOutputFile = pathToOutputFile(urlPath, outDir, "index.html");
|
|
6130
|
+
const dataOutputFile = pathToOutputFile(urlPath, outDir, "__furin_data.ndjson");
|
|
4276
6131
|
try {
|
|
4277
6132
|
const entry = await prerenderSSG(route, params, root, "http://localhost", basePath);
|
|
4278
6133
|
if (entry instanceof Response) {
|
|
4279
6134
|
console.warn(`[furin] static: route "${route.pattern}" loader returned a redirect \u2014 skipping.`);
|
|
4280
6135
|
return;
|
|
4281
6136
|
}
|
|
4282
|
-
ensureDir(dirname3(
|
|
4283
|
-
writeFileSync5(
|
|
6137
|
+
ensureDir(dirname3(htmlOutputFile));
|
|
6138
|
+
writeFileSync5(htmlOutputFile, entry.html);
|
|
6139
|
+
writeFileSync5(dataOutputFile, entry.ndjson);
|
|
4284
6140
|
renderedRoutes.push(urlPath);
|
|
4285
|
-
console.log(`[furin] static: ${urlPath} \u2192 ${toPosixPath(
|
|
6141
|
+
console.log(`[furin] static: ${urlPath} \u2192 ${toPosixPath(htmlOutputFile)}`);
|
|
4286
6142
|
} catch (err) {
|
|
4287
6143
|
console.error(`[furin] static: prerender failed for "${route.pattern}" (params: ${JSON.stringify(params)}):`, err);
|
|
4288
6144
|
skippedRoutes.push(urlPath);
|
|
@@ -4309,24 +6165,38 @@ function collectSsgRoutes(routes, onSSR, skippedRoutes) {
|
|
|
4309
6165
|
}
|
|
4310
6166
|
async function buildTaskQueue(ssgRoutes, root, outDir, renderedRoutes, skippedRoutes, basePath) {
|
|
4311
6167
|
const tasks = [];
|
|
4312
|
-
|
|
6168
|
+
const staticParamsResults = await mapWithConcurrency(ssgRoutes, STATIC_CONCURRENCY, async (route) => {
|
|
4313
6169
|
if (!DYNAMIC_SEGMENT_RE.test(route.pattern)) {
|
|
4314
|
-
|
|
4315
|
-
continue;
|
|
6170
|
+
return { route, paramSets: [{}] };
|
|
4316
6171
|
}
|
|
4317
6172
|
if (!route.page.staticParams) {
|
|
4318
6173
|
console.warn(`[furin] static: skipping dynamic route "${route.pattern}" \u2014 no staticParams() defined.`);
|
|
4319
6174
|
skippedRoutes.push(route.pattern);
|
|
4320
|
-
|
|
6175
|
+
return { route, paramSets: null };
|
|
4321
6176
|
}
|
|
4322
6177
|
try {
|
|
4323
6178
|
const paramSets = await route.page.staticParams() ?? [];
|
|
4324
|
-
|
|
4325
|
-
tasks.push(() => prerenderAndWrite(route, params, root, outDir, renderedRoutes, skippedRoutes, basePath));
|
|
4326
|
-
}
|
|
6179
|
+
return { route, paramSets };
|
|
4327
6180
|
} catch (err) {
|
|
4328
|
-
|
|
4329
|
-
|
|
6181
|
+
return { error: err, paramSets: null, route };
|
|
6182
|
+
}
|
|
6183
|
+
});
|
|
6184
|
+
for (const result of staticParamsResults) {
|
|
6185
|
+
if ("error" in result) {
|
|
6186
|
+
console.error(`[furin] static: staticParams() failed for "${result.route.pattern}":`, result.error);
|
|
6187
|
+
skippedRoutes.push(result.route.pattern);
|
|
6188
|
+
continue;
|
|
6189
|
+
}
|
|
6190
|
+
if (result.paramSets === null) {
|
|
6191
|
+
continue;
|
|
6192
|
+
}
|
|
6193
|
+
if (!Array.isArray(result.paramSets)) {
|
|
6194
|
+
console.error(`[furin] static: staticParams() for "${result.route.pattern}" returned a non-array value; skipping route.`);
|
|
6195
|
+
skippedRoutes.push(result.route.pattern);
|
|
6196
|
+
continue;
|
|
6197
|
+
}
|
|
6198
|
+
for (const params of result.paramSets) {
|
|
6199
|
+
tasks.push(() => prerenderAndWrite(result.route, params, root, outDir, renderedRoutes, skippedRoutes, basePath));
|
|
4330
6200
|
}
|
|
4331
6201
|
}
|
|
4332
6202
|
return tasks;
|
|
@@ -4386,7 +6256,7 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
4386
6256
|
});
|
|
4387
6257
|
const publicFavicon = join7(rootDir, "public", "favicon.ico");
|
|
4388
6258
|
const faviconHref = existsSync6(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
4389
|
-
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref);
|
|
6259
|
+
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
|
|
4390
6260
|
setProductionTemplateContent(shellHtml);
|
|
4391
6261
|
const publicSrcDir = join7(rootDir, "public");
|
|
4392
6262
|
if (existsSync6(publicSrcDir)) {
|
|
@@ -4452,47 +6322,6 @@ function getCompileContext() {
|
|
|
4452
6322
|
return _compileCtx;
|
|
4453
6323
|
}
|
|
4454
6324
|
|
|
4455
|
-
// src/utils.ts
|
|
4456
|
-
function isFurinPage(value) {
|
|
4457
|
-
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_PAGE";
|
|
4458
|
-
}
|
|
4459
|
-
function isFurinRoute(value) {
|
|
4460
|
-
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_ROUTE";
|
|
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;
|
|
4477
|
-
}
|
|
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
|
-
}
|
|
4489
|
-
for (const route of chain) {
|
|
4490
|
-
if (hasCycle(route)) {
|
|
4491
|
-
throw new Error("[furin] Cycle detected in route chain. A route cannot be its own ancestor.");
|
|
4492
|
-
}
|
|
4493
|
-
}
|
|
4494
|
-
}
|
|
4495
|
-
|
|
4496
6325
|
// src/router.ts
|
|
4497
6326
|
async function scanPages(pagesDir) {
|
|
4498
6327
|
const root = await scanRootLayout(pagesDir);
|
|
@@ -4513,8 +6342,10 @@ async function scanRootLayout(pagesDir) {
|
|
|
4513
6342
|
if (!rootExport.layout) {
|
|
4514
6343
|
throw new Error("[furin] root.tsx: createRoute() has no layout.");
|
|
4515
6344
|
}
|
|
4516
|
-
const notFoundEntry = await
|
|
4517
|
-
|
|
6345
|
+
const [notFoundEntry, errorEntry] = await Promise.all([
|
|
6346
|
+
loadConventionComponent(pagesDir, "not-found"),
|
|
6347
|
+
loadConventionComponent(pagesDir, "error")
|
|
6348
|
+
]);
|
|
4518
6349
|
return {
|
|
4519
6350
|
path: rootPath,
|
|
4520
6351
|
route: rootExport,
|
|
@@ -4557,9 +6388,11 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
4557
6388
|
if (fileName.startsWith("_") || fileName === "root" || isConventionFileName(fileName)) {
|
|
4558
6389
|
continue;
|
|
4559
6390
|
}
|
|
4560
|
-
const notFound
|
|
4561
|
-
|
|
4562
|
-
|
|
6391
|
+
const [notFound, errorComponent, segmentBoundaries] = await Promise.all([
|
|
6392
|
+
resolveNearestConvention(absolutePath, pagesDir, "not-found", notFoundCache, root.notFound),
|
|
6393
|
+
resolveNearestConvention(absolutePath, pagesDir, "error", errorCache, root.error),
|
|
6394
|
+
collectSegmentBoundaries(absolutePath, pagesDir, notFoundCache, errorCache)
|
|
6395
|
+
]);
|
|
4563
6396
|
if (IS_DEV) {
|
|
4564
6397
|
const devRoute = await buildDevRoute(absolutePath, relativePath, root);
|
|
4565
6398
|
devRoute.notFound = notFound;
|
|
@@ -4604,14 +6437,16 @@ async function collectSegmentBoundaries(pageAbsolutePath, pagesDir, notFoundCach
|
|
|
4604
6437
|
const boundaries = [];
|
|
4605
6438
|
for (let depth = 0;depth < dirs.length; depth++) {
|
|
4606
6439
|
const dir = dirs[depth];
|
|
4607
|
-
|
|
4608
|
-
errorCache.
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
6440
|
+
const [errorEntry, notFoundEntry] = await Promise.all([
|
|
6441
|
+
errorCache.has(dir) ? Promise.resolve(errorCache.get(dir)) : loadConventionComponent(dir, "error").then((r) => {
|
|
6442
|
+
errorCache.set(dir, r);
|
|
6443
|
+
return r;
|
|
6444
|
+
}),
|
|
6445
|
+
notFoundCache.has(dir) ? Promise.resolve(notFoundCache.get(dir)) : loadConventionComponent(dir, "not-found").then((r) => {
|
|
6446
|
+
notFoundCache.set(dir, r);
|
|
6447
|
+
return r;
|
|
6448
|
+
})
|
|
6449
|
+
]);
|
|
4615
6450
|
if (errorEntry || notFoundEntry) {
|
|
4616
6451
|
boundaries.push({
|
|
4617
6452
|
path: dir,
|
|
@@ -4668,18 +6503,22 @@ async function buildDevRoute(absolutePath, relativePath, root) {
|
|
|
4668
6503
|
};
|
|
4669
6504
|
}
|
|
4670
6505
|
var TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
|
|
6506
|
+
var DIR_SCAN_CONCURRENCY = 8;
|
|
4671
6507
|
async function collectPageFilePaths(dir) {
|
|
4672
6508
|
const files = [];
|
|
4673
6509
|
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
4674
|
-
|
|
6510
|
+
const resolved = await mapWithConcurrency(entries, DIR_SCAN_CONCURRENCY, async (entry) => {
|
|
4675
6511
|
const absolutePath = join8(dir, entry.name);
|
|
4676
6512
|
if (entry.isDirectory()) {
|
|
4677
|
-
|
|
4678
|
-
continue;
|
|
6513
|
+
return await collectPageFilePaths(absolutePath);
|
|
4679
6514
|
}
|
|
4680
6515
|
if (entry.isFile()) {
|
|
4681
|
-
|
|
6516
|
+
return [absolutePath];
|
|
4682
6517
|
}
|
|
6518
|
+
return [];
|
|
6519
|
+
});
|
|
6520
|
+
for (const chunk of resolved) {
|
|
6521
|
+
files.push(...chunk);
|
|
4683
6522
|
}
|
|
4684
6523
|
return files;
|
|
4685
6524
|
}
|
|
@@ -4724,35 +6563,13 @@ function filePathToPattern(path) {
|
|
|
4724
6563
|
// src/build/scan-server.ts
|
|
4725
6564
|
import { readFileSync as readFileSync2 } from "fs";
|
|
4726
6565
|
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
6566
|
function scanFurinInstances(serverEntryPath) {
|
|
4744
6567
|
const code = readFileSync2(serverEntryPath, "utf8");
|
|
4745
|
-
|
|
6568
|
+
const lang = detectLangFromPath(serverEntryPath);
|
|
4746
6569
|
if (lang === "dts") {
|
|
4747
6570
|
return [];
|
|
4748
6571
|
}
|
|
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 });
|
|
6572
|
+
const { program, diagnostics } = parse3(code, { sourceType: "module", lang });
|
|
4756
6573
|
const firstError = diagnostics.find((d) => d.severity === "error");
|
|
4757
6574
|
if (firstError) {
|
|
4758
6575
|
console.error("[furin] scan-server: parse error:", firstError.message, "in", serverEntryPath);
|
|
@@ -4770,7 +6587,7 @@ function checkFurinCall(node, out) {
|
|
|
4770
6587
|
if (!(isFurinCall && Array.isArray(args)) || args.length === 0) {
|
|
4771
6588
|
return;
|
|
4772
6589
|
}
|
|
4773
|
-
const firstArg = args[0];
|
|
6590
|
+
const firstArg = unwrapTSExpression(args[0]);
|
|
4774
6591
|
if (firstArg?.type !== "ObjectExpression") {
|
|
4775
6592
|
return;
|
|
4776
6593
|
}
|