@teyik0/furin 0.1.0-alpha.13 → 0.1.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -232
- package/dist/auto-invalidate/index.d.ts +4 -0
- package/dist/auto-invalidate/plugin.d.ts +38 -0
- package/dist/auto-invalidate/registry.d.ts +9 -0
- package/dist/auto-invalidate/runtime.d.ts +9 -0
- package/dist/auto-invalidate/types.d.ts +12 -0
- package/dist/await.d.ts +67 -0
- package/dist/build/index.js +2095 -185
- package/dist/cli/index.js +2070 -182
- package/dist/client.d.ts +51 -4
- package/dist/client.js +65 -1
- package/dist/deferred-ndjson.d.ts +32 -0
- package/dist/error.d.ts +14 -0
- package/dist/furin.d.ts +8 -0
- package/dist/furin.js +2927 -319
- package/dist/lang-detect.d.ts +5 -0
- package/dist/link.d.ts +1 -0
- package/dist/link.js +1453 -95
- package/dist/plugin/index.js +96 -25
- package/dist/plugin/transform-client.d.ts +2 -1
- package/dist/render/assemble.d.ts +32 -0
- package/dist/render/cache.d.ts +7 -0
- package/dist/render/element.d.ts +17 -1
- package/dist/render/index.d.ts +10 -1
- package/dist/render/index.ts +250 -44
- package/dist/render/loaders.d.ts +46 -3
- package/dist/render/shell.d.ts +16 -6
- package/dist/render/shell.ts +27 -12
- package/dist/router-provider.d.ts +86 -18
- package/dist/router.d.ts +66 -0
- package/dist/router.js +2909 -374
- package/dist/router.ts +586 -54
- package/dist/server-error.d.ts +12 -0
- package/dist/utils.d.ts +7 -0
- package/package.json +8 -7
- package/src/adapter/bun.ts +3 -3
- package/src/adapter/static.ts +73 -31
- package/src/auto-invalidate/index.ts +10 -0
- package/src/auto-invalidate/plugin.ts +25 -0
- package/src/auto-invalidate/registry.ts +60 -0
- package/src/auto-invalidate/runtime.ts +133 -0
- package/src/auto-invalidate/types.ts +16 -0
- package/src/await.tsx +175 -0
- package/src/build/client.ts +4 -8
- package/src/build/hydrate.ts +67 -1
- package/src/build/route-types.ts +29 -3
- package/src/build/scan-server.ts +6 -23
- package/src/client.ts +80 -3
- package/src/deferred-ndjson.ts +212 -0
- package/src/dev-page-plugin.ts +2 -0
- package/src/error.ts +18 -1
- package/src/furin.ts +19 -2
- package/src/lang-detect.ts +46 -0
- package/src/link.tsx +16 -3
- package/src/plugin/index.ts +7 -8
- package/src/plugin/transform-client.ts +108 -39
- package/src/render/assemble.ts +67 -0
- package/src/render/boundaries.tsx +23 -5
- package/src/render/cache.ts +14 -0
- package/src/render/default-screens.tsx +4 -11
- package/src/render/dev-cache.ts +5 -0
- package/src/render/element.tsx +26 -3
- package/src/render/index.ts +250 -44
- package/src/render/loaders.ts +219 -18
- package/src/render/shell.ts +27 -12
- package/src/router-provider.tsx +414 -122
- package/src/router.ts +586 -54
- package/src/server-error.ts +47 -0
- package/src/utils.ts +31 -0
package/dist/furin.js
CHANGED
|
@@ -15,7 +15,7 @@ var __export = (target, all) => {
|
|
|
15
15
|
};
|
|
16
16
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
17
|
|
|
18
|
-
// ../../node_modules/.bun/evlog@2.
|
|
18
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/utils.mjs
|
|
19
19
|
function formatDuration(ms) {
|
|
20
20
|
if (ms < 1000)
|
|
21
21
|
return `${Math.round(ms)}ms`;
|
|
@@ -132,7 +132,28 @@ var init_utils = __esm(() => {
|
|
|
132
132
|
patternCache = /* @__PURE__ */ new Map;
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
// ../../node_modules/.bun/evlog@2.
|
|
135
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/headers-CU-QqnYg.mjs
|
|
136
|
+
function extractSafeHeaders(headers) {
|
|
137
|
+
const raw = {};
|
|
138
|
+
headers.forEach((value, key) => {
|
|
139
|
+
raw[key] = value;
|
|
140
|
+
});
|
|
141
|
+
return filterSafeHeaders(raw);
|
|
142
|
+
}
|
|
143
|
+
function extractSafeNodeHeaders(headers) {
|
|
144
|
+
const raw = {};
|
|
145
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
146
|
+
if (value === undefined)
|
|
147
|
+
continue;
|
|
148
|
+
raw[key] = Array.isArray(value) ? value.join(", ") : value;
|
|
149
|
+
}
|
|
150
|
+
return filterSafeHeaders(raw);
|
|
151
|
+
}
|
|
152
|
+
var init_headers_CU_QqnYg = __esm(() => {
|
|
153
|
+
init_utils();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/audit-pV5aLGP0.mjs
|
|
136
157
|
function resolveRedactConfig(input) {
|
|
137
158
|
if (input === undefined || input === false)
|
|
138
159
|
return;
|
|
@@ -235,6 +256,116 @@ function applyMaskers(value, maskers) {
|
|
|
235
256
|
}
|
|
236
257
|
return result;
|
|
237
258
|
}
|
|
259
|
+
function logPluginError(name, hook, err) {
|
|
260
|
+
console.error(`[evlog/${name}] ${hook} failed:`, err);
|
|
261
|
+
}
|
|
262
|
+
function createPluginRunner(plugins = []) {
|
|
263
|
+
const byName = /* @__PURE__ */ new Map;
|
|
264
|
+
for (const plugin of plugins)
|
|
265
|
+
byName.set(plugin.name, plugin);
|
|
266
|
+
const list = Array.from(byName.values());
|
|
267
|
+
return {
|
|
268
|
+
plugins: list,
|
|
269
|
+
hasEnrich: list.some((p) => typeof p.enrich === "function"),
|
|
270
|
+
hasDrain: list.some((p) => typeof p.drain === "function"),
|
|
271
|
+
hasKeep: list.some((p) => typeof p.keep === "function"),
|
|
272
|
+
hasRequestLifecycle: list.some((p) => typeof p.onRequestStart === "function" || typeof p.onRequestFinish === "function"),
|
|
273
|
+
hasClientLog: list.some((p) => typeof p.onClientLog === "function"),
|
|
274
|
+
hasExtendLogger: list.some((p) => typeof p.extendLogger === "function"),
|
|
275
|
+
applyExtendLogger(logger) {
|
|
276
|
+
for (const plugin of list) {
|
|
277
|
+
if (!plugin.extendLogger)
|
|
278
|
+
continue;
|
|
279
|
+
try {
|
|
280
|
+
plugin.extendLogger(logger);
|
|
281
|
+
} catch (err) {
|
|
282
|
+
logPluginError(plugin.name, "extendLogger", err);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
runOnRequestStart(ctx) {
|
|
287
|
+
for (const plugin of list) {
|
|
288
|
+
if (!plugin.onRequestStart)
|
|
289
|
+
continue;
|
|
290
|
+
try {
|
|
291
|
+
plugin.onRequestStart(ctx);
|
|
292
|
+
} catch (err) {
|
|
293
|
+
logPluginError(plugin.name, "onRequestStart", err);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
runOnRequestFinish(ctx) {
|
|
298
|
+
for (const plugin of list) {
|
|
299
|
+
if (!plugin.onRequestFinish)
|
|
300
|
+
continue;
|
|
301
|
+
try {
|
|
302
|
+
plugin.onRequestFinish(ctx);
|
|
303
|
+
} catch (err) {
|
|
304
|
+
logPluginError(plugin.name, "onRequestFinish", err);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
async runEnrich(ctx) {
|
|
309
|
+
for (const plugin of list) {
|
|
310
|
+
if (!plugin.enrich)
|
|
311
|
+
continue;
|
|
312
|
+
try {
|
|
313
|
+
await plugin.enrich(ctx);
|
|
314
|
+
} catch (err) {
|
|
315
|
+
logPluginError(plugin.name, "enrich", err);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
async runDrain(ctx) {
|
|
320
|
+
const drains = list.filter((p) => typeof p.drain === "function");
|
|
321
|
+
if (drains.length === 0)
|
|
322
|
+
return;
|
|
323
|
+
await Promise.allSettled(drains.map(async (plugin) => {
|
|
324
|
+
try {
|
|
325
|
+
await plugin.drain(ctx);
|
|
326
|
+
} catch (err) {
|
|
327
|
+
logPluginError(plugin.name, "drain", err);
|
|
328
|
+
}
|
|
329
|
+
}));
|
|
330
|
+
},
|
|
331
|
+
async runKeep(ctx) {
|
|
332
|
+
for (const plugin of list) {
|
|
333
|
+
if (!plugin.keep)
|
|
334
|
+
continue;
|
|
335
|
+
try {
|
|
336
|
+
await plugin.keep(ctx);
|
|
337
|
+
} catch (err) {
|
|
338
|
+
logPluginError(plugin.name, "keep", err);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
runOnClientLog(ctx) {
|
|
343
|
+
for (const plugin of list) {
|
|
344
|
+
if (!plugin.onClientLog)
|
|
345
|
+
continue;
|
|
346
|
+
try {
|
|
347
|
+
plugin.onClientLog(ctx);
|
|
348
|
+
} catch (err) {
|
|
349
|
+
logPluginError(plugin.name, "onClientLog", err);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
async runSetup(ctx) {
|
|
354
|
+
for (const plugin of list) {
|
|
355
|
+
if (!plugin.setup)
|
|
356
|
+
continue;
|
|
357
|
+
try {
|
|
358
|
+
await plugin.setup(ctx);
|
|
359
|
+
} catch (err) {
|
|
360
|
+
logPluginError(plugin.name, "setup", err);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function getEmptyPluginRunner() {
|
|
367
|
+
return emptyRunner;
|
|
368
|
+
}
|
|
238
369
|
function isPlainObject(val) {
|
|
239
370
|
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
240
371
|
}
|
|
@@ -276,9 +407,16 @@ function initLogger(config = {}) {
|
|
|
276
407
|
globalRedact = resolveRedactConfig(config.redact ?? !isDev());
|
|
277
408
|
globalSilent = config.silent ?? false;
|
|
278
409
|
globalMinLevel = config.minLevel ?? "debug";
|
|
279
|
-
|
|
410
|
+
globalPluginRunner = config.plugins?.length ? createPluginRunner(config.plugins) : getEmptyPluginRunner();
|
|
411
|
+
if (globalPluginRunner.plugins.length > 0)
|
|
412
|
+
globalPluginRunner.runSetup({ env: { ...globalEnv } });
|
|
413
|
+
const hasAnyDrain = !!globalDrain || globalPluginRunner.hasDrain;
|
|
414
|
+
if (globalSilent && !hasAnyDrain && !config._suppressDrainWarning)
|
|
280
415
|
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).");
|
|
281
416
|
}
|
|
417
|
+
function getGlobalPluginRunner() {
|
|
418
|
+
return globalPluginRunner;
|
|
419
|
+
}
|
|
282
420
|
function isEnabled() {
|
|
283
421
|
return globalEnabled;
|
|
284
422
|
}
|
|
@@ -352,12 +490,20 @@ function emitWideEvent(level, event, options = {}) {
|
|
|
352
490
|
console[getConsoleMethod(level)](JSON.stringify(formatted));
|
|
353
491
|
else
|
|
354
492
|
console[getConsoleMethod(level)](formatted);
|
|
355
|
-
if (
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
493
|
+
if (!deferDrain) {
|
|
494
|
+
const drainPromises = [];
|
|
495
|
+
if (globalDrain)
|
|
496
|
+
drainPromises.push((async () => {
|
|
497
|
+
try {
|
|
498
|
+
await globalDrain({ event: formatted });
|
|
499
|
+
} catch (err) {
|
|
500
|
+
console.error("[evlog] drain failed:", err);
|
|
501
|
+
}
|
|
502
|
+
})());
|
|
503
|
+
if (globalPluginRunner.hasDrain)
|
|
504
|
+
drainPromises.push(globalPluginRunner.runDrain({ event: formatted }));
|
|
505
|
+
if (drainPromises.length > 0 && waitUntil)
|
|
506
|
+
waitUntil(Promise.all(drainPromises));
|
|
361
507
|
}
|
|
362
508
|
return formatted;
|
|
363
509
|
}
|
|
@@ -707,6 +853,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
707
853
|
};
|
|
708
854
|
const errRecord = err;
|
|
709
855
|
for (const k of [
|
|
856
|
+
"code",
|
|
710
857
|
"status",
|
|
711
858
|
"statusText",
|
|
712
859
|
"statusCode",
|
|
@@ -875,8 +1022,8 @@ function finalizeAudit(event) {
|
|
|
875
1022
|
return;
|
|
876
1023
|
event.audit = decorateAudit(a, String(event.timestamp));
|
|
877
1024
|
}
|
|
878
|
-
var DEFAULT_REPLACEMENT = "[REDACTED]", builtinPatterns, _tsDate, POST_EMIT_FORK_HINT = "For intentional background work tied to this request, use log.fork('label', fn) when your integration supports it (see https://evlog.dev).", globalEnv, globalPretty, globalSampling, globalStringify = true, globalDrain, globalRedact, globalEnabled = true, globalSilent = false, globalMinLevel = "debug", _log, noopLogger;
|
|
879
|
-
var
|
|
1025
|
+
var DEFAULT_REPLACEMENT = "[REDACTED]", builtinPatterns, emptyRunner, _tsDate, POST_EMIT_FORK_HINT = "For intentional background work tied to this request, use log.fork('label', fn) when your integration supports it (see https://evlog.dev).", globalEnv, globalPretty, globalSampling, globalStringify = true, globalDrain, globalRedact, globalEnabled = true, globalSilent = false, globalMinLevel = "debug", globalPluginRunner, _log, noopLogger;
|
|
1026
|
+
var init_audit_pV5aLGP0 = __esm(() => {
|
|
880
1027
|
init_utils();
|
|
881
1028
|
builtinPatterns = {
|
|
882
1029
|
creditCard: {
|
|
@@ -925,6 +1072,7 @@ var init_audit_DQoBo7Dl = __esm(() => {
|
|
|
925
1072
|
}
|
|
926
1073
|
}
|
|
927
1074
|
};
|
|
1075
|
+
emptyRunner = createPluginRunner([]);
|
|
928
1076
|
_tsDate = /* @__PURE__ */ new Date;
|
|
929
1077
|
globalEnv = {
|
|
930
1078
|
service: "app",
|
|
@@ -932,6 +1080,7 @@ var init_audit_DQoBo7Dl = __esm(() => {
|
|
|
932
1080
|
};
|
|
933
1081
|
globalPretty = isDev();
|
|
934
1082
|
globalSampling = {};
|
|
1083
|
+
globalPluginRunner = getEmptyPluginRunner();
|
|
935
1084
|
_log = {
|
|
936
1085
|
info: createLogMethod("info"),
|
|
937
1086
|
error: createLogMethod("error"),
|
|
@@ -955,12 +1104,7 @@ var init_audit_DQoBo7Dl = __esm(() => {
|
|
|
955
1104
|
initLogger(__EVLOG_CONFIG__);
|
|
956
1105
|
});
|
|
957
1106
|
|
|
958
|
-
// ../../node_modules/.bun/evlog@2.
|
|
959
|
-
var init_dist = __esm(() => {
|
|
960
|
-
init_audit_DQoBo7Dl();
|
|
961
|
-
});
|
|
962
|
-
|
|
963
|
-
// ../../node_modules/.bun/evlog@2.14.1+6b630eaba8c4f70c/node_modules/evlog/dist/errors-BJRXUfMg.mjs
|
|
1107
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/errors-BQgyQ9xe.mjs
|
|
964
1108
|
function extractErrorStatus(error) {
|
|
965
1109
|
if (error === null || typeof error !== "object")
|
|
966
1110
|
return 500;
|
|
@@ -968,9 +1112,14 @@ function extractErrorStatus(error) {
|
|
|
968
1112
|
const status = Number(raw);
|
|
969
1113
|
return Number.isFinite(status) ? status : 500;
|
|
970
1114
|
}
|
|
971
|
-
var
|
|
1115
|
+
var init_errors_BQgyQ9xe = () => {};
|
|
972
1116
|
|
|
973
|
-
// ../../node_modules/.bun/evlog@2.
|
|
1117
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/index.mjs
|
|
1118
|
+
var init_dist = __esm(() => {
|
|
1119
|
+
init_audit_pV5aLGP0();
|
|
1120
|
+
});
|
|
1121
|
+
|
|
1122
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/routes-CnIgYWf8.mjs
|
|
974
1123
|
function shouldLog(path, include, exclude) {
|
|
975
1124
|
if (exclude && exclude.length > 0) {
|
|
976
1125
|
if (exclude.some((pattern) => matchesPattern(path, pattern)))
|
|
@@ -987,40 +1136,75 @@ function getServiceForPath(path, routes) {
|
|
|
987
1136
|
if (matchesPattern(path, pattern))
|
|
988
1137
|
return config.service;
|
|
989
1138
|
}
|
|
990
|
-
var
|
|
1139
|
+
var init_routes_CnIgYWf8 = __esm(() => {
|
|
991
1140
|
init_utils();
|
|
992
1141
|
});
|
|
993
1142
|
|
|
994
|
-
// ../../node_modules/.bun/evlog@2.
|
|
995
|
-
|
|
1143
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/fork-8u_zFOJq.mjs
|
|
1144
|
+
function resolveMiddlewarePluginRunner(options) {
|
|
1145
|
+
const global2 = getGlobalPluginRunner();
|
|
1146
|
+
const local = options.plugins;
|
|
1147
|
+
if (!local || local.length === 0)
|
|
1148
|
+
return global2;
|
|
1149
|
+
const cached = runnerCache.get(local);
|
|
1150
|
+
if (cached && cached.global === global2)
|
|
1151
|
+
return cached.merged;
|
|
1152
|
+
const merged = /* @__PURE__ */ new Map;
|
|
1153
|
+
for (const plugin of global2.plugins)
|
|
1154
|
+
merged.set(plugin.name, plugin);
|
|
1155
|
+
for (const plugin of local)
|
|
1156
|
+
merged.set(plugin.name, plugin);
|
|
1157
|
+
if (merged.size === 0)
|
|
1158
|
+
return getEmptyPluginRunner();
|
|
1159
|
+
const runner = createPluginRunner(Array.from(merged.values()));
|
|
1160
|
+
runnerCache.set(local, {
|
|
1161
|
+
global: global2,
|
|
1162
|
+
merged: runner
|
|
1163
|
+
});
|
|
1164
|
+
return runner;
|
|
1165
|
+
}
|
|
1166
|
+
async function runEnrichAndDrain(emittedEvent, options, requestInfo, responseStatus, plugins) {
|
|
1167
|
+
const runner = plugins ?? resolveMiddlewarePluginRunner(options);
|
|
996
1168
|
const resolvedRedact = resolveRedactConfig(options.redact);
|
|
997
1169
|
if (resolvedRedact)
|
|
998
1170
|
redactEvent(emittedEvent, resolvedRedact);
|
|
999
|
-
if (options.enrich) {
|
|
1171
|
+
if (options.enrich || runner.hasEnrich) {
|
|
1000
1172
|
const enrichCtx = {
|
|
1001
1173
|
event: emittedEvent,
|
|
1002
1174
|
request: requestInfo,
|
|
1003
1175
|
headers: options.headers,
|
|
1004
1176
|
response: { status: responseStatus }
|
|
1005
1177
|
};
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1178
|
+
if (options.enrich)
|
|
1179
|
+
try {
|
|
1180
|
+
await options.enrich(enrichCtx);
|
|
1181
|
+
} catch (err) {
|
|
1182
|
+
console.error("[evlog] enrich failed:", err);
|
|
1183
|
+
}
|
|
1184
|
+
if (runner.hasEnrich)
|
|
1185
|
+
await runner.runEnrich(enrichCtx);
|
|
1011
1186
|
}
|
|
1012
1187
|
const drain = options.drain ?? getGlobalDrain();
|
|
1013
|
-
|
|
1188
|
+
const hasUserDrain = !!drain;
|
|
1189
|
+
const hasPluginDrain = runner.hasDrain;
|
|
1190
|
+
if (hasUserDrain || hasPluginDrain) {
|
|
1014
1191
|
const drainCtx = {
|
|
1015
1192
|
event: emittedEvent,
|
|
1016
1193
|
request: requestInfo,
|
|
1017
1194
|
headers: options.headers
|
|
1018
1195
|
};
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1196
|
+
const tasks = [];
|
|
1197
|
+
if (hasUserDrain)
|
|
1198
|
+
tasks.push((async () => {
|
|
1199
|
+
try {
|
|
1200
|
+
await drain(drainCtx);
|
|
1201
|
+
} catch (err) {
|
|
1202
|
+
console.error("[evlog] drain failed:", err);
|
|
1203
|
+
}
|
|
1204
|
+
})());
|
|
1205
|
+
if (hasPluginDrain)
|
|
1206
|
+
tasks.push(runner.runDrain(drainCtx));
|
|
1207
|
+
await Promise.all(tasks);
|
|
1024
1208
|
}
|
|
1025
1209
|
}
|
|
1026
1210
|
function createMiddlewareLogger(options) {
|
|
@@ -1038,12 +1222,21 @@ function createMiddlewareLogger(options) {
|
|
|
1038
1222
|
const routeService = getServiceForPath(path, routes);
|
|
1039
1223
|
if (routeService)
|
|
1040
1224
|
logger.set({ service: routeService });
|
|
1225
|
+
const pluginRunner = resolveMiddlewarePluginRunner(options);
|
|
1226
|
+
if (pluginRunner.hasExtendLogger)
|
|
1227
|
+
pluginRunner.applyExtendLogger(logger);
|
|
1041
1228
|
const startTime = Date.now();
|
|
1042
1229
|
const requestInfo = {
|
|
1043
1230
|
method,
|
|
1044
1231
|
path,
|
|
1045
1232
|
requestId: resolvedRequestId
|
|
1046
1233
|
};
|
|
1234
|
+
if (pluginRunner.hasRequestLifecycle)
|
|
1235
|
+
pluginRunner.runOnRequestStart({
|
|
1236
|
+
logger,
|
|
1237
|
+
request: requestInfo,
|
|
1238
|
+
headers: options.headers
|
|
1239
|
+
});
|
|
1047
1240
|
const finish = async (opts) => {
|
|
1048
1241
|
const { status, error } = opts ?? {};
|
|
1049
1242
|
if (error) {
|
|
@@ -1064,10 +1257,22 @@ function createMiddlewareLogger(options) {
|
|
|
1064
1257
|
};
|
|
1065
1258
|
if (keep)
|
|
1066
1259
|
await keep(tailCtx);
|
|
1260
|
+
if (pluginRunner.hasKeep)
|
|
1261
|
+
await pluginRunner.runKeep(tailCtx);
|
|
1067
1262
|
const forceKeep = tailCtx.shouldKeep || shouldKeep(tailCtx);
|
|
1068
1263
|
const emittedEvent = logger.emit({ _forceKeep: forceKeep });
|
|
1069
|
-
if (emittedEvent && (options.enrich || options.drain || getGlobalDrain()))
|
|
1070
|
-
await runEnrichAndDrain(emittedEvent, options, requestInfo, resolvedStatus);
|
|
1264
|
+
if (emittedEvent && (options.enrich || options.drain || pluginRunner.hasEnrich || pluginRunner.hasDrain || getGlobalDrain()))
|
|
1265
|
+
await runEnrichAndDrain(emittedEvent, options, requestInfo, resolvedStatus, pluginRunner);
|
|
1266
|
+
if (pluginRunner.hasRequestLifecycle)
|
|
1267
|
+
pluginRunner.runOnRequestFinish({
|
|
1268
|
+
logger,
|
|
1269
|
+
request: requestInfo,
|
|
1270
|
+
headers: options.headers,
|
|
1271
|
+
event: emittedEvent,
|
|
1272
|
+
status: resolvedStatus,
|
|
1273
|
+
durationMs,
|
|
1274
|
+
error
|
|
1275
|
+
});
|
|
1071
1276
|
return emittedEvent;
|
|
1072
1277
|
};
|
|
1073
1278
|
return {
|
|
@@ -1076,30 +1281,6 @@ function createMiddlewareLogger(options) {
|
|
|
1076
1281
|
skipped: false
|
|
1077
1282
|
};
|
|
1078
1283
|
}
|
|
1079
|
-
var noopResult;
|
|
1080
|
-
var init_middleware_oAccqyPp = __esm(() => {
|
|
1081
|
-
init_audit_DQoBo7Dl();
|
|
1082
|
-
init_errors_BJRXUfMg();
|
|
1083
|
-
init_routes_CGPmbzCZ();
|
|
1084
|
-
noopResult = {
|
|
1085
|
-
logger: {
|
|
1086
|
-
set() {},
|
|
1087
|
-
error() {},
|
|
1088
|
-
info() {},
|
|
1089
|
-
warn() {},
|
|
1090
|
-
emit() {
|
|
1091
|
-
return null;
|
|
1092
|
-
},
|
|
1093
|
-
getContext() {
|
|
1094
|
-
return {};
|
|
1095
|
-
}
|
|
1096
|
-
},
|
|
1097
|
-
finish: () => Promise.resolve(null),
|
|
1098
|
-
skipped: true
|
|
1099
|
-
};
|
|
1100
|
-
});
|
|
1101
|
-
|
|
1102
|
-
// ../../node_modules/.bun/evlog@2.14.1+6b630eaba8c4f70c/node_modules/evlog/dist/fork-D1j1Fuzy.mjs
|
|
1103
1284
|
function attachForkToLogger(storage, parent, middlewareOptions, lifecycle) {
|
|
1104
1285
|
const log = parent;
|
|
1105
1286
|
log.fork = (label, fn) => {
|
|
@@ -1156,16 +1337,77 @@ function forkBackgroundLogger(options) {
|
|
|
1156
1337
|
});
|
|
1157
1338
|
});
|
|
1158
1339
|
}
|
|
1159
|
-
var
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1340
|
+
var noopResult, runnerCache;
|
|
1341
|
+
var init_fork_8u_zFOJq = __esm(() => {
|
|
1342
|
+
init_audit_pV5aLGP0();
|
|
1343
|
+
init_errors_BQgyQ9xe();
|
|
1344
|
+
init_routes_CnIgYWf8();
|
|
1345
|
+
noopResult = {
|
|
1346
|
+
logger: {
|
|
1347
|
+
set() {},
|
|
1348
|
+
error() {},
|
|
1349
|
+
info() {},
|
|
1350
|
+
warn() {},
|
|
1351
|
+
emit() {
|
|
1352
|
+
return null;
|
|
1353
|
+
},
|
|
1354
|
+
getContext() {
|
|
1355
|
+
return {};
|
|
1356
|
+
}
|
|
1357
|
+
},
|
|
1358
|
+
finish: () => Promise.resolve(null),
|
|
1359
|
+
skipped: true
|
|
1360
|
+
};
|
|
1361
|
+
runnerCache = /* @__PURE__ */ new WeakMap;
|
|
1362
|
+
});
|
|
1363
|
+
|
|
1364
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/integration-DTZtjSqh.mjs
|
|
1365
|
+
function normalizeHeaders(headers) {
|
|
1366
|
+
if (!headers)
|
|
1367
|
+
return;
|
|
1368
|
+
if (typeof headers.forEach === "function" && typeof headers.get === "function")
|
|
1369
|
+
return extractSafeHeaders(headers);
|
|
1370
|
+
return extractSafeNodeHeaders(headers);
|
|
1371
|
+
}
|
|
1372
|
+
function defineFrameworkIntegration(spec) {
|
|
1373
|
+
return { start(ctx, options = {}) {
|
|
1374
|
+
const extracted = spec.extractRequest(ctx);
|
|
1375
|
+
const headers = normalizeHeaders(extracted.headers);
|
|
1376
|
+
const middlewareOptions = {
|
|
1377
|
+
method: extracted.method,
|
|
1378
|
+
path: extracted.path,
|
|
1379
|
+
requestId: extracted.requestId || crypto.randomUUID(),
|
|
1380
|
+
headers,
|
|
1381
|
+
...options
|
|
1382
|
+
};
|
|
1383
|
+
const result = createMiddlewareLogger(middlewareOptions);
|
|
1384
|
+
if (!result.skipped) {
|
|
1385
|
+
if (spec.storage)
|
|
1386
|
+
attachForkToLogger(spec.storage, result.logger, middlewareOptions, spec.forkLifecycle);
|
|
1387
|
+
spec.attachLogger(ctx, result.logger);
|
|
1388
|
+
}
|
|
1389
|
+
const { storage } = spec;
|
|
1390
|
+
const runWith = async (fn) => {
|
|
1391
|
+
if (!storage || result.skipped)
|
|
1392
|
+
return await fn();
|
|
1393
|
+
return await storage.run(result.logger, fn);
|
|
1394
|
+
};
|
|
1395
|
+
return {
|
|
1396
|
+
...result,
|
|
1397
|
+
middlewareOptions,
|
|
1398
|
+
runWith
|
|
1399
|
+
};
|
|
1400
|
+
} };
|
|
1401
|
+
}
|
|
1402
|
+
var init_integration_DTZtjSqh = __esm(() => {
|
|
1403
|
+
init_headers_CU_QqnYg();
|
|
1404
|
+
init_fork_8u_zFOJq();
|
|
1163
1405
|
});
|
|
1164
1406
|
|
|
1165
|
-
// ../../node_modules/.bun/evlog@2.
|
|
1407
|
+
// ../../node_modules/.bun/evlog@2.17.0+f5a9d28f69418da1/node_modules/evlog/dist/elysia/index.mjs
|
|
1166
1408
|
import { AsyncLocalStorage } from "async_hooks";
|
|
1167
1409
|
import { Elysia } from "elysia";
|
|
1168
|
-
function
|
|
1410
|
+
function useLogger() {
|
|
1169
1411
|
const logger = storage.getStore();
|
|
1170
1412
|
if (!logger || !activeLoggers.has(logger))
|
|
1171
1413
|
throw new Error("[evlog] useLogger() was called outside of an evlog plugin context. Make sure app.use(evlog()) is registered before your routes.");
|
|
@@ -1175,25 +1417,12 @@ function evlog(options = {}) {
|
|
|
1175
1417
|
const emitted = /* @__PURE__ */ new WeakSet;
|
|
1176
1418
|
const requestState = /* @__PURE__ */ new WeakMap;
|
|
1177
1419
|
return new Elysia({ name: "evlog" }).derive({ as: "global" }, ({ request, path, headers }) => {
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1420
|
+
const ctx = {
|
|
1421
|
+
request,
|
|
1180
1422
|
path,
|
|
1181
|
-
|
|
1182
|
-
headers: filterSafeHeaders(headers),
|
|
1183
|
-
...options
|
|
1423
|
+
headers
|
|
1184
1424
|
};
|
|
1185
|
-
const { logger, finish, skipped } =
|
|
1186
|
-
if (!skipped) {
|
|
1187
|
-
attachForkToLogger(storage, logger, middlewareOpts, {
|
|
1188
|
-
onChildEnter: (child) => {
|
|
1189
|
-
activeLoggers.add(child);
|
|
1190
|
-
},
|
|
1191
|
-
onChildExit: (child) => {
|
|
1192
|
-
activeLoggers.delete(child);
|
|
1193
|
-
}
|
|
1194
|
-
});
|
|
1195
|
-
activeLoggers.add(logger);
|
|
1196
|
-
}
|
|
1425
|
+
const { logger, finish, skipped } = integration.start(ctx, options);
|
|
1197
1426
|
storage.enterWith(logger);
|
|
1198
1427
|
requestState.set(request, {
|
|
1199
1428
|
finish,
|
|
@@ -1221,13 +1450,36 @@ function evlog(options = {}) {
|
|
|
1221
1450
|
storage.enterWith(undefined);
|
|
1222
1451
|
});
|
|
1223
1452
|
}
|
|
1224
|
-
var storage, activeLoggers;
|
|
1453
|
+
var storage, activeLoggers, integration;
|
|
1225
1454
|
var init_elysia = __esm(() => {
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
init_fork_D1j1Fuzy();
|
|
1455
|
+
init_fork_8u_zFOJq();
|
|
1456
|
+
init_integration_DTZtjSqh();
|
|
1229
1457
|
storage = new AsyncLocalStorage;
|
|
1230
1458
|
activeLoggers = /* @__PURE__ */ new WeakSet;
|
|
1459
|
+
integration = defineFrameworkIntegration({
|
|
1460
|
+
name: "elysia",
|
|
1461
|
+
extractRequest: ({ request, path, headers }) => ({
|
|
1462
|
+
method: request.method,
|
|
1463
|
+
path,
|
|
1464
|
+
headers,
|
|
1465
|
+
requestId: headers["x-request-id"]
|
|
1466
|
+
}),
|
|
1467
|
+
attachLogger: ({ request, path, headers }, logger) => {
|
|
1468
|
+
attachForkToLogger(storage, logger, {
|
|
1469
|
+
method: request.method,
|
|
1470
|
+
path,
|
|
1471
|
+
requestId: headers["x-request-id"]
|
|
1472
|
+
}, {
|
|
1473
|
+
onChildEnter: (child) => {
|
|
1474
|
+
activeLoggers.add(child);
|
|
1475
|
+
},
|
|
1476
|
+
onChildExit: (child) => {
|
|
1477
|
+
activeLoggers.delete(child);
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
activeLoggers.add(logger);
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1231
1483
|
});
|
|
1232
1484
|
|
|
1233
1485
|
// src/internal.ts
|
|
@@ -1236,11 +1488,68 @@ function getCompileContext() {
|
|
|
1236
1488
|
}
|
|
1237
1489
|
var _compileCtx = null;
|
|
1238
1490
|
|
|
1491
|
+
// src/auto-invalidate/registry.ts
|
|
1492
|
+
class AutoInvalidateRegistry {
|
|
1493
|
+
pathToTags = new Map;
|
|
1494
|
+
tagToPaths = new Map;
|
|
1495
|
+
registerLoaderTags(urlPath, tags) {
|
|
1496
|
+
if (!tags || tags.length === 0) {
|
|
1497
|
+
this.unregisterPath(urlPath);
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
this.unregisterPath(urlPath);
|
|
1501
|
+
const uniqueTags = new Set(tags);
|
|
1502
|
+
this.pathToTags.set(urlPath, uniqueTags);
|
|
1503
|
+
for (const tag of uniqueTags) {
|
|
1504
|
+
let paths = this.tagToPaths.get(tag);
|
|
1505
|
+
if (!paths) {
|
|
1506
|
+
paths = new Set;
|
|
1507
|
+
this.tagToPaths.set(tag, paths);
|
|
1508
|
+
}
|
|
1509
|
+
paths.add(urlPath);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
pathsForTags(tags) {
|
|
1513
|
+
const paths = new Set;
|
|
1514
|
+
for (const tag of tags) {
|
|
1515
|
+
for (const path of this.tagToPaths.get(tag) ?? []) {
|
|
1516
|
+
paths.add(path);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return [...paths];
|
|
1520
|
+
}
|
|
1521
|
+
unregisterPath(urlPath) {
|
|
1522
|
+
const tags = this.pathToTags.get(urlPath);
|
|
1523
|
+
if (!tags) {
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1526
|
+
for (const tag of tags) {
|
|
1527
|
+
const paths = this.tagToPaths.get(tag);
|
|
1528
|
+
if (!paths) {
|
|
1529
|
+
continue;
|
|
1530
|
+
}
|
|
1531
|
+
paths.delete(urlPath);
|
|
1532
|
+
if (paths.size === 0) {
|
|
1533
|
+
this.tagToPaths.delete(tag);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
this.pathToTags.delete(urlPath);
|
|
1537
|
+
}
|
|
1538
|
+
reset() {
|
|
1539
|
+
this.pathToTags.clear();
|
|
1540
|
+
this.tagToPaths.clear();
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
var autoInvalidateRegistry;
|
|
1544
|
+
var init_registry = __esm(() => {
|
|
1545
|
+
autoInvalidateRegistry = new AutoInvalidateRegistry;
|
|
1546
|
+
});
|
|
1547
|
+
|
|
1239
1548
|
// src/context-logger.ts
|
|
1240
1549
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
1241
|
-
function
|
|
1550
|
+
function useLogger2() {
|
|
1242
1551
|
try {
|
|
1243
|
-
return
|
|
1552
|
+
return useLogger();
|
|
1244
1553
|
} catch {
|
|
1245
1554
|
return syntheticRenderStorage.getStore() ?? noopLogger2;
|
|
1246
1555
|
}
|
|
@@ -1453,14 +1762,21 @@ function revalidatePath(path, type) {
|
|
|
1453
1762
|
}
|
|
1454
1763
|
var MAX_ISR_CACHE_SIZE = 1000, MAX_SSG_CACHE_SIZE = 1000, isrRouteCache, ssgRouteCache, isrCache, ssgCache, _buildId = "", _requestInvalidationScope, _globalPendingInvalidations, _cachePurger = null, _cacheInvalidators;
|
|
1455
1764
|
var init_cache = __esm(() => {
|
|
1765
|
+
init_registry();
|
|
1456
1766
|
init_context_logger();
|
|
1457
1767
|
isrRouteCache = createRouteCache({
|
|
1458
1768
|
maxSize: MAX_ISR_CACHE_SIZE,
|
|
1459
|
-
name: "render:isr-html"
|
|
1769
|
+
name: "render:isr-html",
|
|
1770
|
+
onDelete: (key) => {
|
|
1771
|
+
autoInvalidateRegistry.unregisterPath(key);
|
|
1772
|
+
}
|
|
1460
1773
|
});
|
|
1461
1774
|
ssgRouteCache = createRouteCache({
|
|
1462
1775
|
maxSize: MAX_SSG_CACHE_SIZE,
|
|
1463
|
-
name: "render:ssg-html"
|
|
1776
|
+
name: "render:ssg-html",
|
|
1777
|
+
onDelete: (key) => {
|
|
1778
|
+
autoInvalidateRegistry.unregisterPath(key);
|
|
1779
|
+
}
|
|
1464
1780
|
});
|
|
1465
1781
|
isrCache = isrRouteCache.store;
|
|
1466
1782
|
ssgCache = ssgRouteCache.store;
|
|
@@ -1471,86 +1787,1559 @@ var init_cache = __esm(() => {
|
|
|
1471
1787
|
registerCacheInvalidator(ssgRouteCache);
|
|
1472
1788
|
});
|
|
1473
1789
|
|
|
1474
|
-
//
|
|
1475
|
-
function
|
|
1476
|
-
|
|
1790
|
+
// ../../node_modules/.bun/seroval@1.5.4/node_modules/seroval/dist/esm/development/index.mjs
|
|
1791
|
+
function createSerovalNode(t, i, s, c, m, p, e, a, f, b, o, l) {
|
|
1792
|
+
return {
|
|
1793
|
+
t,
|
|
1794
|
+
i,
|
|
1795
|
+
s,
|
|
1796
|
+
c,
|
|
1797
|
+
m,
|
|
1798
|
+
p,
|
|
1799
|
+
e,
|
|
1800
|
+
a,
|
|
1801
|
+
f,
|
|
1802
|
+
b,
|
|
1803
|
+
o,
|
|
1804
|
+
l
|
|
1805
|
+
};
|
|
1477
1806
|
}
|
|
1478
|
-
function
|
|
1479
|
-
return
|
|
1807
|
+
function createConstantNode(value) {
|
|
1808
|
+
return createSerovalNode(2, NIL, value, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1809
|
+
}
|
|
1810
|
+
function serializeChar(str) {
|
|
1811
|
+
switch (str) {
|
|
1812
|
+
case '"':
|
|
1813
|
+
return "\\\"";
|
|
1814
|
+
case "\\":
|
|
1815
|
+
return "\\\\";
|
|
1816
|
+
case `
|
|
1817
|
+
`:
|
|
1818
|
+
return "\\n";
|
|
1819
|
+
case "\r":
|
|
1820
|
+
return "\\r";
|
|
1821
|
+
case "\b":
|
|
1822
|
+
return "\\b";
|
|
1823
|
+
case "\t":
|
|
1824
|
+
return "\\t";
|
|
1825
|
+
case "\f":
|
|
1826
|
+
return "\\f";
|
|
1827
|
+
case "<":
|
|
1828
|
+
return "\\x3C";
|
|
1829
|
+
case "\u2028":
|
|
1830
|
+
return "\\u2028";
|
|
1831
|
+
case "\u2029":
|
|
1832
|
+
return "\\u2029";
|
|
1833
|
+
default:
|
|
1834
|
+
return NIL;
|
|
1835
|
+
}
|
|
1480
1836
|
}
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1837
|
+
function serializeString(str) {
|
|
1838
|
+
let result = "";
|
|
1839
|
+
let lastPos = 0;
|
|
1840
|
+
let replacement;
|
|
1841
|
+
for (let i = 0, len = str.length;i < len; i++) {
|
|
1842
|
+
replacement = serializeChar(str[i]);
|
|
1843
|
+
if (replacement) {
|
|
1844
|
+
result += str.slice(lastPos, i) + replacement;
|
|
1845
|
+
lastPos = i + 1;
|
|
1489
1846
|
}
|
|
1490
|
-
};
|
|
1491
|
-
});
|
|
1492
|
-
|
|
1493
|
-
// src/error.ts
|
|
1494
|
-
function getPublicErrorMessage(error) {
|
|
1495
|
-
const branded = error;
|
|
1496
|
-
if (branded?.__furinBrand === "FURIN_NOT_FOUND") {
|
|
1497
|
-
return error.message;
|
|
1498
1847
|
}
|
|
1499
|
-
|
|
1848
|
+
if (lastPos === 0) {
|
|
1849
|
+
result = str;
|
|
1850
|
+
} else {
|
|
1851
|
+
result += str.slice(lastPos);
|
|
1852
|
+
}
|
|
1853
|
+
return result;
|
|
1500
1854
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
import { createElement, useCallback, useEffect, useRef } from "react";
|
|
1504
|
-
function computeLinkView({
|
|
1505
|
-
to,
|
|
1506
|
-
search,
|
|
1507
|
-
hash,
|
|
1508
|
-
children,
|
|
1509
|
-
activeProps,
|
|
1510
|
-
inactiveProps
|
|
1511
|
-
}, router) {
|
|
1512
|
-
const logicalHref = buildHref(to, search, hash);
|
|
1513
|
-
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
1514
|
-
const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
|
|
1515
|
-
const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
|
|
1516
|
-
const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
|
|
1517
|
-
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
1518
|
-
const extraProps = {
|
|
1519
|
-
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
1520
|
-
...activeProps ? activeProps({ isActive }) : {}
|
|
1521
|
-
};
|
|
1522
|
-
return { logicalHref, href, isActive, resolvedChildren, extraProps };
|
|
1855
|
+
function hasReferenceID(value) {
|
|
1856
|
+
return REFERENCE.has(value);
|
|
1523
1857
|
}
|
|
1524
|
-
function
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1858
|
+
function getReferenceID(value) {
|
|
1859
|
+
if (hasReferenceID(value)) {
|
|
1860
|
+
return REFERENCE.get(value);
|
|
1861
|
+
}
|
|
1862
|
+
throw new SerovalMissingReferenceError(value);
|
|
1863
|
+
}
|
|
1864
|
+
function getErrorConstructor(error) {
|
|
1865
|
+
if (error instanceof EvalError) {
|
|
1866
|
+
return 1;
|
|
1867
|
+
}
|
|
1868
|
+
if (error instanceof RangeError) {
|
|
1869
|
+
return 2;
|
|
1870
|
+
}
|
|
1871
|
+
if (error instanceof ReferenceError) {
|
|
1872
|
+
return 3;
|
|
1873
|
+
}
|
|
1874
|
+
if (error instanceof SyntaxError) {
|
|
1875
|
+
return 4;
|
|
1876
|
+
}
|
|
1877
|
+
if (error instanceof TypeError) {
|
|
1878
|
+
return 5;
|
|
1879
|
+
}
|
|
1880
|
+
if (error instanceof URIError) {
|
|
1881
|
+
return 6;
|
|
1882
|
+
}
|
|
1883
|
+
return 0;
|
|
1884
|
+
}
|
|
1885
|
+
function getInitialErrorOptions(error) {
|
|
1886
|
+
const construct = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
|
|
1887
|
+
if (error.name !== construct) {
|
|
1888
|
+
return { name: error.name };
|
|
1889
|
+
}
|
|
1890
|
+
if (error.constructor.name !== construct) {
|
|
1891
|
+
return { name: error.constructor.name };
|
|
1892
|
+
}
|
|
1893
|
+
return {};
|
|
1894
|
+
}
|
|
1895
|
+
function getErrorOptions(error, features) {
|
|
1896
|
+
let options = getInitialErrorOptions(error);
|
|
1897
|
+
const names = Object.getOwnPropertyNames(error);
|
|
1898
|
+
for (let i = 0, len = names.length, name;i < len; i++) {
|
|
1899
|
+
name = names[i];
|
|
1900
|
+
if (name !== "name" && name !== "message") {
|
|
1901
|
+
if (name === "stack") {
|
|
1902
|
+
if (features & 4) {
|
|
1903
|
+
options = options || {};
|
|
1904
|
+
options[name] = error[name];
|
|
1905
|
+
}
|
|
1906
|
+
} else {
|
|
1907
|
+
options = options || {};
|
|
1908
|
+
options[name] = error[name];
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
return options;
|
|
1913
|
+
}
|
|
1914
|
+
function getObjectFlag(obj) {
|
|
1915
|
+
if (Object.isFrozen(obj)) {
|
|
1916
|
+
return 3;
|
|
1917
|
+
}
|
|
1918
|
+
if (Object.isSealed(obj)) {
|
|
1919
|
+
return 2;
|
|
1920
|
+
}
|
|
1921
|
+
if (Object.isExtensible(obj)) {
|
|
1922
|
+
return 0;
|
|
1923
|
+
}
|
|
1924
|
+
return 1;
|
|
1925
|
+
}
|
|
1926
|
+
function createNumberNode(value) {
|
|
1927
|
+
switch (value) {
|
|
1928
|
+
case Number.POSITIVE_INFINITY:
|
|
1929
|
+
return INFINITY_NODE;
|
|
1930
|
+
case Number.NEGATIVE_INFINITY:
|
|
1931
|
+
return NEG_INFINITY_NODE;
|
|
1932
|
+
}
|
|
1933
|
+
if (value !== value) {
|
|
1934
|
+
return NAN_NODE;
|
|
1935
|
+
}
|
|
1936
|
+
if (Object.is(value, -0)) {
|
|
1937
|
+
return NEG_ZERO_NODE;
|
|
1938
|
+
}
|
|
1939
|
+
return createSerovalNode(0, NIL, value, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1940
|
+
}
|
|
1941
|
+
function createStringNode(value) {
|
|
1942
|
+
return createSerovalNode(1, NIL, serializeString(value), NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1943
|
+
}
|
|
1944
|
+
function createBigIntNode(current) {
|
|
1945
|
+
return createSerovalNode(3, NIL, "" + current, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1946
|
+
}
|
|
1947
|
+
function createIndexedValueNode(id) {
|
|
1948
|
+
return createSerovalNode(4, id, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1949
|
+
}
|
|
1950
|
+
function createDateNode(id, current) {
|
|
1951
|
+
const timestamp = current.valueOf();
|
|
1952
|
+
return createSerovalNode(5, id, timestamp !== timestamp ? "" : current.toISOString(), NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1953
|
+
}
|
|
1954
|
+
function createRegExpNode(id, current) {
|
|
1955
|
+
return createSerovalNode(6, id, NIL, serializeString(current.source), current.flags, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1956
|
+
}
|
|
1957
|
+
function createWKSymbolNode(id, current) {
|
|
1958
|
+
return createSerovalNode(17, id, INV_SYMBOL_REF[current], NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1959
|
+
}
|
|
1960
|
+
function createReferenceNode(id, ref) {
|
|
1961
|
+
return createSerovalNode(18, id, serializeString(getReferenceID(ref)), NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1962
|
+
}
|
|
1963
|
+
function createPluginNode(id, tag, value) {
|
|
1964
|
+
return createSerovalNode(25, id, value, serializeString(tag), NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1965
|
+
}
|
|
1966
|
+
function createArrayNode(id, current, parsedItems) {
|
|
1967
|
+
return createSerovalNode(9, id, NIL, NIL, NIL, NIL, NIL, parsedItems, NIL, NIL, getObjectFlag(current), NIL);
|
|
1968
|
+
}
|
|
1969
|
+
function createBoxedNode(id, boxed) {
|
|
1970
|
+
return createSerovalNode(21, id, NIL, NIL, NIL, NIL, NIL, NIL, boxed, NIL, NIL, NIL);
|
|
1971
|
+
}
|
|
1972
|
+
function createTypedArrayNode(id, current, buffer) {
|
|
1973
|
+
return createSerovalNode(15, id, NIL, current.constructor.name, NIL, NIL, NIL, NIL, buffer, current.byteOffset, NIL, current.length);
|
|
1974
|
+
}
|
|
1975
|
+
function createBigIntTypedArrayNode(id, current, buffer) {
|
|
1976
|
+
return createSerovalNode(16, id, NIL, current.constructor.name, NIL, NIL, NIL, NIL, buffer, current.byteOffset, NIL, current.byteLength);
|
|
1977
|
+
}
|
|
1978
|
+
function createDataViewNode(id, current, buffer) {
|
|
1979
|
+
return createSerovalNode(20, id, NIL, NIL, NIL, NIL, NIL, NIL, buffer, current.byteOffset, NIL, current.byteLength);
|
|
1980
|
+
}
|
|
1981
|
+
function createErrorNode(id, current, options) {
|
|
1982
|
+
return createSerovalNode(13, id, getErrorConstructor(current), NIL, serializeString(current.message), options, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1983
|
+
}
|
|
1984
|
+
function createAggregateErrorNode(id, current, options) {
|
|
1985
|
+
return createSerovalNode(14, id, getErrorConstructor(current), NIL, serializeString(current.message), options, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
1986
|
+
}
|
|
1987
|
+
function createSetNode(id, items) {
|
|
1988
|
+
return createSerovalNode(7, id, NIL, NIL, NIL, NIL, NIL, items, NIL, NIL, NIL, NIL);
|
|
1989
|
+
}
|
|
1990
|
+
function createIteratorFactoryInstanceNode(factory, items) {
|
|
1991
|
+
return createSerovalNode(28, NIL, NIL, NIL, NIL, NIL, NIL, [factory, items], NIL, NIL, NIL, NIL);
|
|
1992
|
+
}
|
|
1993
|
+
function createAsyncIteratorFactoryInstanceNode(factory, items) {
|
|
1994
|
+
return createSerovalNode(30, NIL, NIL, NIL, NIL, NIL, NIL, [factory, items], NIL, NIL, NIL, NIL);
|
|
1995
|
+
}
|
|
1996
|
+
function createStreamConstructorNode(id, factory, sequence) {
|
|
1997
|
+
return createSerovalNode(31, id, NIL, NIL, NIL, NIL, NIL, sequence, factory, NIL, NIL, NIL);
|
|
1998
|
+
}
|
|
1999
|
+
function createStreamNextNode(id, parsed) {
|
|
2000
|
+
return createSerovalNode(32, id, NIL, NIL, NIL, NIL, NIL, NIL, parsed, NIL, NIL, NIL);
|
|
2001
|
+
}
|
|
2002
|
+
function createStreamThrowNode(id, parsed) {
|
|
2003
|
+
return createSerovalNode(33, id, NIL, NIL, NIL, NIL, NIL, NIL, parsed, NIL, NIL, NIL);
|
|
2004
|
+
}
|
|
2005
|
+
function createStreamReturnNode(id, parsed) {
|
|
2006
|
+
return createSerovalNode(34, id, NIL, NIL, NIL, NIL, NIL, NIL, parsed, NIL, NIL, NIL);
|
|
2007
|
+
}
|
|
2008
|
+
function createSequenceNode(id, sequence, throwAt, doneAt) {
|
|
2009
|
+
return createSerovalNode(35, id, throwAt, NIL, NIL, NIL, NIL, sequence, NIL, NIL, NIL, doneAt);
|
|
2010
|
+
}
|
|
2011
|
+
function getErrorMessageDev(type, cause) {
|
|
2012
|
+
if (cause instanceof Error) {
|
|
2013
|
+
return `Seroval caught an error during the ${type} process.
|
|
2014
|
+
|
|
2015
|
+
${cause.name}
|
|
2016
|
+
${cause.message}
|
|
2017
|
+
|
|
2018
|
+
- For more information, please check the "cause" property of this error.
|
|
2019
|
+
- If you believe this is an error in Seroval, please submit an issue at https://github.com/lxsmnsyc/seroval/issues/new`;
|
|
2020
|
+
}
|
|
2021
|
+
return `Seroval caught an error during the ${type} process.
|
|
2022
|
+
|
|
2023
|
+
"${objectToString.call(cause)}"
|
|
2024
|
+
|
|
2025
|
+
For more information, please check the "cause" property of this error.`;
|
|
2026
|
+
}
|
|
2027
|
+
function isSequence(value) {
|
|
2028
|
+
return "__SEROVAL_SEQUENCE__" in value;
|
|
2029
|
+
}
|
|
2030
|
+
function createSequence(values, throwAt, doneAt) {
|
|
2031
|
+
return {
|
|
2032
|
+
__SEROVAL_SEQUENCE__: true,
|
|
2033
|
+
v: values,
|
|
2034
|
+
t: throwAt,
|
|
2035
|
+
d: doneAt
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
function createSequenceFromIterable(source) {
|
|
2039
|
+
const values = [];
|
|
2040
|
+
let throwsAt = -1;
|
|
2041
|
+
let doneAt = -1;
|
|
2042
|
+
const iterator = source[SYM_ITERATOR]();
|
|
2043
|
+
while (true) {
|
|
2044
|
+
try {
|
|
2045
|
+
const value = iterator.next();
|
|
2046
|
+
values.push(value.value);
|
|
2047
|
+
if (value.done) {
|
|
2048
|
+
doneAt = values.length - 1;
|
|
2049
|
+
break;
|
|
2050
|
+
}
|
|
2051
|
+
} catch (error) {
|
|
2052
|
+
throwsAt = values.length;
|
|
2053
|
+
values.push(error);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
return createSequence(values, throwsAt, doneAt);
|
|
2057
|
+
}
|
|
2058
|
+
function isStream(value) {
|
|
2059
|
+
return "__SEROVAL_STREAM__" in value;
|
|
2060
|
+
}
|
|
2061
|
+
function createStream() {
|
|
2062
|
+
return STREAM_CONSTRUCTOR();
|
|
2063
|
+
}
|
|
2064
|
+
function createStreamFromAsyncIterable(iterable) {
|
|
2065
|
+
const stream = createStream();
|
|
2066
|
+
const iterator = iterable[SYM_ASYNC_ITERATOR]();
|
|
2067
|
+
async function push() {
|
|
2068
|
+
try {
|
|
2069
|
+
const value = await iterator.next();
|
|
2070
|
+
if (value.done) {
|
|
2071
|
+
stream.return(value.value);
|
|
2072
|
+
} else {
|
|
2073
|
+
stream.next(value.value);
|
|
2074
|
+
await push();
|
|
2075
|
+
}
|
|
2076
|
+
} catch (error) {
|
|
2077
|
+
stream.throw(error);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
push().catch(() => {});
|
|
2081
|
+
return stream;
|
|
2082
|
+
}
|
|
2083
|
+
async function promiseToResult(current) {
|
|
2084
|
+
try {
|
|
2085
|
+
return [1, await current];
|
|
2086
|
+
} catch (e) {
|
|
2087
|
+
return [0, e];
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
function createBaseParserContext(mode, options) {
|
|
2091
|
+
return {
|
|
2092
|
+
plugins: options.plugins,
|
|
2093
|
+
mode,
|
|
2094
|
+
marked: /* @__PURE__ */ new Set,
|
|
2095
|
+
features: ALL_ENABLED ^ (options.disabledFeatures || 0),
|
|
2096
|
+
refs: options.refs || /* @__PURE__ */ new Map,
|
|
2097
|
+
depthLimit: options.depthLimit || 1000
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
function markParserRef(ctx, id) {
|
|
2101
|
+
ctx.marked.add(id);
|
|
2102
|
+
}
|
|
2103
|
+
function createIndexForValue(ctx, current) {
|
|
2104
|
+
const id = ctx.refs.size;
|
|
2105
|
+
ctx.refs.set(current, id);
|
|
2106
|
+
return id;
|
|
2107
|
+
}
|
|
2108
|
+
function getNodeForIndexedValue(ctx, current) {
|
|
2109
|
+
const registeredId = ctx.refs.get(current);
|
|
2110
|
+
if (registeredId != null) {
|
|
2111
|
+
markParserRef(ctx, registeredId);
|
|
2112
|
+
return {
|
|
2113
|
+
type: 1,
|
|
2114
|
+
value: createIndexedValueNode(registeredId)
|
|
2115
|
+
};
|
|
2116
|
+
}
|
|
2117
|
+
return {
|
|
2118
|
+
type: 0,
|
|
2119
|
+
value: createIndexForValue(ctx, current)
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
function getReferenceNode(ctx, current) {
|
|
2123
|
+
const indexed = getNodeForIndexedValue(ctx, current);
|
|
2124
|
+
if (indexed.type === 1) {
|
|
2125
|
+
return indexed;
|
|
2126
|
+
}
|
|
2127
|
+
if (hasReferenceID(current)) {
|
|
2128
|
+
return {
|
|
2129
|
+
type: 2,
|
|
2130
|
+
value: createReferenceNode(indexed.value, current)
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
return indexed;
|
|
2134
|
+
}
|
|
2135
|
+
function parseWellKnownSymbol(ctx, current) {
|
|
2136
|
+
const ref = getReferenceNode(ctx, current);
|
|
2137
|
+
if (ref.type !== 0) {
|
|
2138
|
+
return ref.value;
|
|
2139
|
+
}
|
|
2140
|
+
if (current in INV_SYMBOL_REF) {
|
|
2141
|
+
return createWKSymbolNode(ref.value, current);
|
|
2142
|
+
}
|
|
2143
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
2144
|
+
}
|
|
2145
|
+
function parseSpecialReference(ctx, ref) {
|
|
2146
|
+
const result = getNodeForIndexedValue(ctx, SPECIAL_REFS[ref]);
|
|
2147
|
+
if (result.type === 1) {
|
|
2148
|
+
return result.value;
|
|
2149
|
+
}
|
|
2150
|
+
return createSerovalNode(26, result.value, ref, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
|
|
2151
|
+
}
|
|
2152
|
+
function parseIteratorFactory(ctx) {
|
|
2153
|
+
const result = getNodeForIndexedValue(ctx, ITERATOR);
|
|
2154
|
+
if (result.type === 1) {
|
|
2155
|
+
return result.value;
|
|
2156
|
+
}
|
|
2157
|
+
return createSerovalNode(27, result.value, NIL, NIL, NIL, NIL, NIL, NIL, parseWellKnownSymbol(ctx, SYM_ITERATOR), NIL, NIL, NIL);
|
|
2158
|
+
}
|
|
2159
|
+
function parseAsyncIteratorFactory(ctx) {
|
|
2160
|
+
const result = getNodeForIndexedValue(ctx, ASYNC_ITERATOR);
|
|
2161
|
+
if (result.type === 1) {
|
|
2162
|
+
return result.value;
|
|
2163
|
+
}
|
|
2164
|
+
return createSerovalNode(29, result.value, NIL, NIL, NIL, NIL, NIL, [
|
|
2165
|
+
parseSpecialReference(ctx, 1),
|
|
2166
|
+
parseWellKnownSymbol(ctx, SYM_ASYNC_ITERATOR)
|
|
2167
|
+
], NIL, NIL, NIL, NIL);
|
|
2168
|
+
}
|
|
2169
|
+
function createObjectNode(id, current, empty, record) {
|
|
2170
|
+
return createSerovalNode(empty ? 11 : 10, id, NIL, NIL, NIL, record, NIL, NIL, NIL, NIL, getObjectFlag(current), NIL);
|
|
2171
|
+
}
|
|
2172
|
+
function createMapNode(ctx, id, k, v) {
|
|
2173
|
+
return createSerovalNode(8, id, NIL, NIL, NIL, NIL, { k, v }, NIL, parseSpecialReference(ctx, 0), NIL, NIL, NIL);
|
|
2174
|
+
}
|
|
2175
|
+
function createPromiseConstructorNode(ctx, id, resolver) {
|
|
2176
|
+
return createSerovalNode(22, id, resolver, NIL, NIL, NIL, NIL, NIL, parseSpecialReference(ctx, 1), NIL, NIL, NIL);
|
|
2177
|
+
}
|
|
2178
|
+
function createArrayBufferNode(ctx, id, current) {
|
|
2179
|
+
const bytes = new Uint8Array(current);
|
|
2180
|
+
let result = "";
|
|
2181
|
+
for (let i = 0, len = bytes.length;i < len; i++) {
|
|
2182
|
+
result += String.fromCharCode(bytes[i]);
|
|
2183
|
+
}
|
|
2184
|
+
return createSerovalNode(19, id, serializeString(btoa(result)), NIL, NIL, NIL, NIL, NIL, parseSpecialReference(ctx, 5), NIL, NIL, NIL);
|
|
2185
|
+
}
|
|
2186
|
+
function createAsyncParserContext(mode, options) {
|
|
2187
|
+
return {
|
|
2188
|
+
base: createBaseParserContext(mode, options),
|
|
2189
|
+
child: undefined
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
async function parseItems(ctx, depth, current) {
|
|
2193
|
+
const nodes = [];
|
|
2194
|
+
for (let i = 0, len = current.length;i < len; i++) {
|
|
2195
|
+
if (i in current) {
|
|
2196
|
+
nodes[i] = await parseAsync(ctx, depth, current[i]);
|
|
2197
|
+
} else {
|
|
2198
|
+
nodes[i] = 0;
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
return nodes;
|
|
2202
|
+
}
|
|
2203
|
+
async function parseArray(ctx, depth, id, current) {
|
|
2204
|
+
return createArrayNode(id, current, await parseItems(ctx, depth, current));
|
|
2205
|
+
}
|
|
2206
|
+
async function parseProperties(ctx, depth, properties) {
|
|
2207
|
+
const entries = Object.entries(properties);
|
|
2208
|
+
const keyNodes = [];
|
|
2209
|
+
const valueNodes = [];
|
|
2210
|
+
for (let i = 0, len = entries.length;i < len; i++) {
|
|
2211
|
+
keyNodes.push(serializeString(entries[i][0]));
|
|
2212
|
+
valueNodes.push(await parseAsync(ctx, depth, entries[i][1]));
|
|
2213
|
+
}
|
|
2214
|
+
if (SYM_ITERATOR in properties) {
|
|
2215
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ITERATOR));
|
|
2216
|
+
valueNodes.push(createIteratorFactoryInstanceNode(parseIteratorFactory(ctx.base), await parseAsync(ctx, depth, createSequenceFromIterable(properties))));
|
|
2217
|
+
}
|
|
2218
|
+
if (SYM_ASYNC_ITERATOR in properties) {
|
|
2219
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
|
|
2220
|
+
valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), await parseAsync(ctx, depth, createStreamFromAsyncIterable(properties))));
|
|
2221
|
+
}
|
|
2222
|
+
if (SYM_TO_STRING_TAG in properties) {
|
|
2223
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
|
|
2224
|
+
valueNodes.push(createStringNode(properties[SYM_TO_STRING_TAG]));
|
|
2225
|
+
}
|
|
2226
|
+
if (SYM_IS_CONCAT_SPREADABLE in properties) {
|
|
2227
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_IS_CONCAT_SPREADABLE));
|
|
2228
|
+
valueNodes.push(properties[SYM_IS_CONCAT_SPREADABLE] ? TRUE_NODE : FALSE_NODE);
|
|
2229
|
+
}
|
|
2230
|
+
return {
|
|
2231
|
+
k: keyNodes,
|
|
2232
|
+
v: valueNodes
|
|
2233
|
+
};
|
|
2234
|
+
}
|
|
2235
|
+
async function parsePlainObject(ctx, depth, id, current, empty) {
|
|
2236
|
+
return createObjectNode(id, current, empty, await parseProperties(ctx, depth, current));
|
|
2237
|
+
}
|
|
2238
|
+
async function parseBoxed(ctx, depth, id, current) {
|
|
2239
|
+
return createBoxedNode(id, await parseAsync(ctx, depth, current.valueOf()));
|
|
2240
|
+
}
|
|
2241
|
+
async function parseTypedArray(ctx, depth, id, current) {
|
|
2242
|
+
return createTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
2243
|
+
}
|
|
2244
|
+
async function parseBigIntTypedArray(ctx, depth, id, current) {
|
|
2245
|
+
return createBigIntTypedArrayNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
2246
|
+
}
|
|
2247
|
+
async function parseDataView(ctx, depth, id, current) {
|
|
2248
|
+
return createDataViewNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
2249
|
+
}
|
|
2250
|
+
async function parseError(ctx, depth, id, current) {
|
|
2251
|
+
const options = getErrorOptions(current, ctx.base.features);
|
|
2252
|
+
return createErrorNode(id, current, options ? await parseProperties(ctx, depth, options) : NIL);
|
|
2253
|
+
}
|
|
2254
|
+
async function parseAggregateError(ctx, depth, id, current) {
|
|
2255
|
+
const options = getErrorOptions(current, ctx.base.features);
|
|
2256
|
+
return createAggregateErrorNode(id, current, options ? await parseProperties(ctx, depth, options) : NIL);
|
|
2257
|
+
}
|
|
2258
|
+
async function parseMap(ctx, depth, id, current) {
|
|
2259
|
+
const keyNodes = [];
|
|
2260
|
+
const valueNodes = [];
|
|
2261
|
+
for (const [key, value] of current.entries()) {
|
|
2262
|
+
keyNodes.push(await parseAsync(ctx, depth, key));
|
|
2263
|
+
valueNodes.push(await parseAsync(ctx, depth, value));
|
|
2264
|
+
}
|
|
2265
|
+
return createMapNode(ctx.base, id, keyNodes, valueNodes);
|
|
2266
|
+
}
|
|
2267
|
+
async function parseSet(ctx, depth, id, current) {
|
|
2268
|
+
const items = [];
|
|
2269
|
+
for (const item of current.keys()) {
|
|
2270
|
+
items.push(await parseAsync(ctx, depth, item));
|
|
2271
|
+
}
|
|
2272
|
+
return createSetNode(id, items);
|
|
2273
|
+
}
|
|
2274
|
+
async function parsePlugin(ctx, depth, id, current) {
|
|
2275
|
+
const currentPlugins = ctx.base.plugins;
|
|
2276
|
+
if (currentPlugins) {
|
|
2277
|
+
for (let i = 0, len = currentPlugins.length;i < len; i++) {
|
|
2278
|
+
const plugin = currentPlugins[i];
|
|
2279
|
+
if (plugin.parse.async && plugin.test(current)) {
|
|
2280
|
+
return createPluginNode(id, plugin.tag, await plugin.parse.async(current, new AsyncParsePluginContext(ctx, depth), {
|
|
2281
|
+
id
|
|
2282
|
+
}));
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
return NIL;
|
|
2287
|
+
}
|
|
2288
|
+
async function parsePromise(ctx, depth, id, current) {
|
|
2289
|
+
const [status, result] = await promiseToResult(current);
|
|
2290
|
+
return createSerovalNode(12, id, status, NIL, NIL, NIL, NIL, NIL, await parseAsync(ctx, depth, result), NIL, NIL, NIL);
|
|
2291
|
+
}
|
|
2292
|
+
function parseStreamHandle(depth, id, current, resolve, reject) {
|
|
2293
|
+
const sequence = [];
|
|
2294
|
+
const cleanup = current.on({
|
|
2295
|
+
next: (value) => {
|
|
2296
|
+
markParserRef(this.base, id);
|
|
2297
|
+
parseAsync(this, depth, value).then((data) => {
|
|
2298
|
+
sequence.push(createStreamNextNode(id, data));
|
|
2299
|
+
}, (data) => {
|
|
2300
|
+
reject(data);
|
|
2301
|
+
cleanup();
|
|
2302
|
+
});
|
|
2303
|
+
},
|
|
2304
|
+
throw: (value) => {
|
|
2305
|
+
markParserRef(this.base, id);
|
|
2306
|
+
parseAsync(this, depth, value).then((data) => {
|
|
2307
|
+
sequence.push(createStreamThrowNode(id, data));
|
|
2308
|
+
resolve(sequence);
|
|
2309
|
+
cleanup();
|
|
2310
|
+
}, (data) => {
|
|
2311
|
+
reject(data);
|
|
2312
|
+
cleanup();
|
|
2313
|
+
});
|
|
2314
|
+
},
|
|
2315
|
+
return: (value) => {
|
|
2316
|
+
markParserRef(this.base, id);
|
|
2317
|
+
parseAsync(this, depth, value).then((data) => {
|
|
2318
|
+
sequence.push(createStreamReturnNode(id, data));
|
|
2319
|
+
resolve(sequence);
|
|
2320
|
+
cleanup();
|
|
2321
|
+
}, (data) => {
|
|
2322
|
+
reject(data);
|
|
2323
|
+
cleanup();
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
async function parseStream(ctx, depth, id, current) {
|
|
2329
|
+
return createStreamConstructorNode(id, parseSpecialReference(ctx.base, 4), await new Promise(parseStreamHandle.bind(ctx, depth, id, current)));
|
|
2330
|
+
}
|
|
2331
|
+
async function parseSequence(ctx, depth, id, current) {
|
|
2332
|
+
const nodes = [];
|
|
2333
|
+
for (let i = 0, len = current.v.length;i < len; i++) {
|
|
2334
|
+
nodes[i] = await parseAsync(ctx, depth, current.v[i]);
|
|
2335
|
+
}
|
|
2336
|
+
return createSequenceNode(id, nodes, current.t, current.d);
|
|
2337
|
+
}
|
|
2338
|
+
async function parseObjectAsync(ctx, depth, id, current) {
|
|
2339
|
+
if (Array.isArray(current)) {
|
|
2340
|
+
return parseArray(ctx, depth, id, current);
|
|
2341
|
+
}
|
|
2342
|
+
if (isStream(current)) {
|
|
2343
|
+
return parseStream(ctx, depth, id, current);
|
|
2344
|
+
}
|
|
2345
|
+
if (isSequence(current)) {
|
|
2346
|
+
return parseSequence(ctx, depth, id, current);
|
|
2347
|
+
}
|
|
2348
|
+
const currentClass = current.constructor;
|
|
2349
|
+
if (currentClass === OpaqueReference) {
|
|
2350
|
+
return parseAsync(ctx, depth, current.replacement);
|
|
2351
|
+
}
|
|
2352
|
+
const parsed = await parsePlugin(ctx, depth, id, current);
|
|
2353
|
+
if (parsed) {
|
|
2354
|
+
return parsed;
|
|
2355
|
+
}
|
|
2356
|
+
switch (currentClass) {
|
|
2357
|
+
case Object:
|
|
2358
|
+
return parsePlainObject(ctx, depth, id, current, false);
|
|
2359
|
+
case NIL:
|
|
2360
|
+
return parsePlainObject(ctx, depth, id, current, true);
|
|
2361
|
+
case Date:
|
|
2362
|
+
return createDateNode(id, current);
|
|
2363
|
+
case Error:
|
|
2364
|
+
case EvalError:
|
|
2365
|
+
case RangeError:
|
|
2366
|
+
case ReferenceError:
|
|
2367
|
+
case SyntaxError:
|
|
2368
|
+
case TypeError:
|
|
2369
|
+
case URIError:
|
|
2370
|
+
return parseError(ctx, depth, id, current);
|
|
2371
|
+
case Number:
|
|
2372
|
+
case Boolean:
|
|
2373
|
+
case String:
|
|
2374
|
+
case BigInt:
|
|
2375
|
+
return parseBoxed(ctx, depth, id, current);
|
|
2376
|
+
case ArrayBuffer:
|
|
2377
|
+
return createArrayBufferNode(ctx.base, id, current);
|
|
2378
|
+
case Int8Array:
|
|
2379
|
+
case Int16Array:
|
|
2380
|
+
case Int32Array:
|
|
2381
|
+
case Uint8Array:
|
|
2382
|
+
case Uint16Array:
|
|
2383
|
+
case Uint32Array:
|
|
2384
|
+
case Uint8ClampedArray:
|
|
2385
|
+
case Float32Array:
|
|
2386
|
+
case Float64Array:
|
|
2387
|
+
return parseTypedArray(ctx, depth, id, current);
|
|
2388
|
+
case DataView:
|
|
2389
|
+
return parseDataView(ctx, depth, id, current);
|
|
2390
|
+
case Map:
|
|
2391
|
+
return parseMap(ctx, depth, id, current);
|
|
2392
|
+
case Set:
|
|
2393
|
+
return parseSet(ctx, depth, id, current);
|
|
2394
|
+
default:
|
|
2395
|
+
break;
|
|
2396
|
+
}
|
|
2397
|
+
if (currentClass === Promise || current instanceof Promise) {
|
|
2398
|
+
return parsePromise(ctx, depth, id, current);
|
|
2399
|
+
}
|
|
2400
|
+
const currentFeatures = ctx.base.features;
|
|
2401
|
+
if (currentFeatures & 32 && currentClass === RegExp) {
|
|
2402
|
+
return createRegExpNode(id, current);
|
|
2403
|
+
}
|
|
2404
|
+
if (currentFeatures & 16) {
|
|
2405
|
+
switch (currentClass) {
|
|
2406
|
+
case BigInt64Array:
|
|
2407
|
+
case BigUint64Array:
|
|
2408
|
+
return parseBigIntTypedArray(ctx, depth, id, current);
|
|
2409
|
+
default:
|
|
2410
|
+
break;
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
if (currentFeatures & 1 && typeof AggregateError !== "undefined" && (currentClass === AggregateError || current instanceof AggregateError)) {
|
|
2414
|
+
return parseAggregateError(ctx, depth, id, current);
|
|
2415
|
+
}
|
|
2416
|
+
if (current instanceof Error) {
|
|
2417
|
+
return parseError(ctx, depth, id, current);
|
|
2418
|
+
}
|
|
2419
|
+
if (SYM_ITERATOR in current || SYM_ASYNC_ITERATOR in current) {
|
|
2420
|
+
return parsePlainObject(ctx, depth, id, current, !!currentClass);
|
|
2421
|
+
}
|
|
2422
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
2423
|
+
}
|
|
2424
|
+
async function parseFunctionAsync(ctx, depth, current) {
|
|
2425
|
+
const ref = getReferenceNode(ctx.base, current);
|
|
2426
|
+
if (ref.type !== 0) {
|
|
2427
|
+
return ref.value;
|
|
2428
|
+
}
|
|
2429
|
+
const plugin = await parsePlugin(ctx, depth, ref.value, current);
|
|
2430
|
+
if (plugin) {
|
|
2431
|
+
return plugin;
|
|
2432
|
+
}
|
|
2433
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
2434
|
+
}
|
|
2435
|
+
async function parseAsync(ctx, depth, current) {
|
|
2436
|
+
switch (typeof current) {
|
|
2437
|
+
case "boolean":
|
|
2438
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
2439
|
+
case "undefined":
|
|
2440
|
+
return UNDEFINED_NODE;
|
|
2441
|
+
case "string":
|
|
2442
|
+
return createStringNode(current);
|
|
2443
|
+
case "number":
|
|
2444
|
+
return createNumberNode(current);
|
|
2445
|
+
case "bigint":
|
|
2446
|
+
return createBigIntNode(current);
|
|
2447
|
+
case "object": {
|
|
2448
|
+
if (current) {
|
|
2449
|
+
const ref = getReferenceNode(ctx.base, current);
|
|
2450
|
+
return ref.type === 0 ? await parseObjectAsync(ctx, depth + 1, ref.value, current) : ref.value;
|
|
2451
|
+
}
|
|
2452
|
+
return NULL_NODE;
|
|
2453
|
+
}
|
|
2454
|
+
case "symbol":
|
|
2455
|
+
return parseWellKnownSymbol(ctx.base, current);
|
|
2456
|
+
case "function":
|
|
2457
|
+
return parseFunctionAsync(ctx, depth, current);
|
|
2458
|
+
default:
|
|
2459
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
async function parseTopAsync(ctx, current) {
|
|
2463
|
+
try {
|
|
2464
|
+
return await parseAsync(ctx, 0, current);
|
|
2465
|
+
} catch (error) {
|
|
2466
|
+
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
function dedupePlugins(deduped, plugins) {
|
|
2470
|
+
for (let i = 0, len = plugins.length;i < len; i++) {
|
|
2471
|
+
const current = plugins[i];
|
|
2472
|
+
if (!deduped.has(current)) {
|
|
2473
|
+
deduped.add(current);
|
|
2474
|
+
if (current.extends) {
|
|
2475
|
+
dedupePlugins(deduped, current.extends);
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
function resolvePlugins(plugins) {
|
|
2481
|
+
if (plugins) {
|
|
2482
|
+
const deduped = /* @__PURE__ */ new Set;
|
|
2483
|
+
dedupePlugins(deduped, plugins);
|
|
2484
|
+
return [...deduped];
|
|
2485
|
+
}
|
|
2486
|
+
return;
|
|
2487
|
+
}
|
|
2488
|
+
function createSyncParserContext(mode, options) {
|
|
2489
|
+
return {
|
|
2490
|
+
type: 1,
|
|
2491
|
+
base: createBaseParserContext(mode, options),
|
|
2492
|
+
child: NIL
|
|
2493
|
+
};
|
|
2494
|
+
}
|
|
2495
|
+
function parseItems2(ctx, depth, current) {
|
|
2496
|
+
const nodes = [];
|
|
2497
|
+
for (let i = 0, len = current.length;i < len; i++) {
|
|
2498
|
+
if (i in current) {
|
|
2499
|
+
nodes[i] = parseSOS(ctx, depth, current[i]);
|
|
2500
|
+
} else {
|
|
2501
|
+
nodes[i] = 0;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
return nodes;
|
|
2505
|
+
}
|
|
2506
|
+
function parseArray2(ctx, depth, id, current) {
|
|
2507
|
+
return createArrayNode(id, current, parseItems2(ctx, depth, current));
|
|
2508
|
+
}
|
|
2509
|
+
function parseProperties2(ctx, depth, properties) {
|
|
2510
|
+
const entries = Object.entries(properties);
|
|
2511
|
+
const keyNodes = [];
|
|
2512
|
+
const valueNodes = [];
|
|
2513
|
+
for (let i = 0, len = entries.length;i < len; i++) {
|
|
2514
|
+
keyNodes.push(serializeString(entries[i][0]));
|
|
2515
|
+
valueNodes.push(parseSOS(ctx, depth, entries[i][1]));
|
|
2516
|
+
}
|
|
2517
|
+
if (SYM_ITERATOR in properties) {
|
|
2518
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ITERATOR));
|
|
2519
|
+
valueNodes.push(createIteratorFactoryInstanceNode(parseIteratorFactory(ctx.base), parseSOS(ctx, depth, createSequenceFromIterable(properties))));
|
|
2520
|
+
}
|
|
2521
|
+
if (SYM_ASYNC_ITERATOR in properties) {
|
|
2522
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_ASYNC_ITERATOR));
|
|
2523
|
+
valueNodes.push(createAsyncIteratorFactoryInstanceNode(parseAsyncIteratorFactory(ctx.base), parseSOS(ctx, depth, ctx.type === 1 ? createStream() : createStreamFromAsyncIterable(properties))));
|
|
2524
|
+
}
|
|
2525
|
+
if (SYM_TO_STRING_TAG in properties) {
|
|
2526
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_TO_STRING_TAG));
|
|
2527
|
+
valueNodes.push(createStringNode(properties[SYM_TO_STRING_TAG]));
|
|
2528
|
+
}
|
|
2529
|
+
if (SYM_IS_CONCAT_SPREADABLE in properties) {
|
|
2530
|
+
keyNodes.push(parseWellKnownSymbol(ctx.base, SYM_IS_CONCAT_SPREADABLE));
|
|
2531
|
+
valueNodes.push(properties[SYM_IS_CONCAT_SPREADABLE] ? TRUE_NODE : FALSE_NODE);
|
|
2532
|
+
}
|
|
2533
|
+
return {
|
|
2534
|
+
k: keyNodes,
|
|
2535
|
+
v: valueNodes
|
|
2536
|
+
};
|
|
2537
|
+
}
|
|
2538
|
+
function parsePlainObject2(ctx, depth, id, current, empty) {
|
|
2539
|
+
return createObjectNode(id, current, empty, parseProperties2(ctx, depth, current));
|
|
2540
|
+
}
|
|
2541
|
+
function parseBoxed2(ctx, depth, id, current) {
|
|
2542
|
+
return createBoxedNode(id, parseSOS(ctx, depth, current.valueOf()));
|
|
2543
|
+
}
|
|
2544
|
+
function parseTypedArray2(ctx, depth, id, current) {
|
|
2545
|
+
return createTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2546
|
+
}
|
|
2547
|
+
function parseBigIntTypedArray2(ctx, depth, id, current) {
|
|
2548
|
+
return createBigIntTypedArrayNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2549
|
+
}
|
|
2550
|
+
function parseDataView2(ctx, depth, id, current) {
|
|
2551
|
+
return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2552
|
+
}
|
|
2553
|
+
function parseError2(ctx, depth, id, current) {
|
|
2554
|
+
const options = getErrorOptions(current, ctx.base.features);
|
|
2555
|
+
return createErrorNode(id, current, options ? parseProperties2(ctx, depth, options) : NIL);
|
|
2556
|
+
}
|
|
2557
|
+
function parseAggregateError2(ctx, depth, id, current) {
|
|
2558
|
+
const options = getErrorOptions(current, ctx.base.features);
|
|
2559
|
+
return createAggregateErrorNode(id, current, options ? parseProperties2(ctx, depth, options) : NIL);
|
|
2560
|
+
}
|
|
2561
|
+
function parseMap2(ctx, depth, id, current) {
|
|
2562
|
+
const keyNodes = [];
|
|
2563
|
+
const valueNodes = [];
|
|
2564
|
+
for (const [key, value] of current.entries()) {
|
|
2565
|
+
keyNodes.push(parseSOS(ctx, depth, key));
|
|
2566
|
+
valueNodes.push(parseSOS(ctx, depth, value));
|
|
2567
|
+
}
|
|
2568
|
+
return createMapNode(ctx.base, id, keyNodes, valueNodes);
|
|
2569
|
+
}
|
|
2570
|
+
function parseSet2(ctx, depth, id, current) {
|
|
2571
|
+
const items = [];
|
|
2572
|
+
for (const item of current.keys()) {
|
|
2573
|
+
items.push(parseSOS(ctx, depth, item));
|
|
2574
|
+
}
|
|
2575
|
+
return createSetNode(id, items);
|
|
2576
|
+
}
|
|
2577
|
+
function parseStream2(ctx, depth, id, current) {
|
|
2578
|
+
const result = createStreamConstructorNode(id, parseSpecialReference(ctx.base, 4), []);
|
|
2579
|
+
if (ctx.type === 1) {
|
|
2580
|
+
return result;
|
|
2581
|
+
}
|
|
2582
|
+
pushPendingState(ctx);
|
|
2583
|
+
current.on({
|
|
2584
|
+
next: (value) => {
|
|
2585
|
+
if (ctx.state.alive) {
|
|
2586
|
+
const parsed = parseWithError(ctx, depth, value);
|
|
2587
|
+
if (parsed) {
|
|
2588
|
+
onParse(ctx, createStreamNextNode(id, parsed));
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
},
|
|
2592
|
+
throw: (value) => {
|
|
2593
|
+
if (ctx.state.alive) {
|
|
2594
|
+
const parsed = parseWithError(ctx, depth, value);
|
|
2595
|
+
if (parsed) {
|
|
2596
|
+
onParse(ctx, createStreamThrowNode(id, parsed));
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
popPendingState(ctx);
|
|
2600
|
+
},
|
|
2601
|
+
return: (value) => {
|
|
2602
|
+
if (ctx.state.alive) {
|
|
2603
|
+
const parsed = parseWithError(ctx, depth, value);
|
|
2604
|
+
if (parsed) {
|
|
2605
|
+
onParse(ctx, createStreamReturnNode(id, parsed));
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
popPendingState(ctx);
|
|
2609
|
+
}
|
|
2610
|
+
});
|
|
2611
|
+
return result;
|
|
2612
|
+
}
|
|
2613
|
+
function handlePromiseSuccess(id, depth, data) {
|
|
2614
|
+
if (this.state.alive) {
|
|
2615
|
+
const parsed = parseWithError(this, depth, data);
|
|
2616
|
+
if (parsed) {
|
|
2617
|
+
onParse(this, createSerovalNode(23, id, NIL, NIL, NIL, NIL, NIL, [
|
|
2618
|
+
parseSpecialReference(this.base, 2),
|
|
2619
|
+
parsed
|
|
2620
|
+
], NIL, NIL, NIL, NIL));
|
|
2621
|
+
}
|
|
2622
|
+
popPendingState(this);
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
function handlePromiseFailure(id, depth, data) {
|
|
2626
|
+
if (this.state.alive) {
|
|
2627
|
+
const parsed = parseWithError(this, depth, data);
|
|
2628
|
+
if (parsed) {
|
|
2629
|
+
onParse(this, createSerovalNode(24, id, NIL, NIL, NIL, NIL, NIL, [
|
|
2630
|
+
parseSpecialReference(this.base, 3),
|
|
2631
|
+
parsed
|
|
2632
|
+
], NIL, NIL, NIL, NIL));
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
popPendingState(this);
|
|
2636
|
+
}
|
|
2637
|
+
function parsePromise2(ctx, depth, id, current) {
|
|
2638
|
+
const resolver = createIndexForValue(ctx.base, {});
|
|
2639
|
+
if (ctx.type === 2) {
|
|
2640
|
+
pushPendingState(ctx);
|
|
2641
|
+
current.then(handlePromiseSuccess.bind(ctx, resolver, depth), handlePromiseFailure.bind(ctx, resolver, depth));
|
|
2642
|
+
}
|
|
2643
|
+
return createPromiseConstructorNode(ctx.base, id, resolver);
|
|
2644
|
+
}
|
|
2645
|
+
function parsePluginSync(ctx, depth, id, current, currentPlugins) {
|
|
2646
|
+
for (let i = 0, len = currentPlugins.length;i < len; i++) {
|
|
2647
|
+
const plugin = currentPlugins[i];
|
|
2648
|
+
if (plugin.parse.sync && plugin.test(current)) {
|
|
2649
|
+
return createPluginNode(id, plugin.tag, plugin.parse.sync(current, new SyncParsePluginContext(ctx, depth), {
|
|
2650
|
+
id
|
|
2651
|
+
}));
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
return NIL;
|
|
2655
|
+
}
|
|
2656
|
+
function parsePluginStream(ctx, depth, id, current, currentPlugins) {
|
|
2657
|
+
for (let i = 0, len = currentPlugins.length;i < len; i++) {
|
|
2658
|
+
const plugin = currentPlugins[i];
|
|
2659
|
+
if (plugin.parse.stream && plugin.test(current)) {
|
|
2660
|
+
return createPluginNode(id, plugin.tag, plugin.parse.stream(current, new StreamParsePluginContext(ctx, depth), {
|
|
2661
|
+
id
|
|
2662
|
+
}));
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
return NIL;
|
|
2666
|
+
}
|
|
2667
|
+
function parsePlugin2(ctx, depth, id, current) {
|
|
2668
|
+
const currentPlugins = ctx.base.plugins;
|
|
2669
|
+
if (currentPlugins) {
|
|
2670
|
+
return ctx.type === 1 ? parsePluginSync(ctx, depth, id, current, currentPlugins) : parsePluginStream(ctx, depth, id, current, currentPlugins);
|
|
2671
|
+
}
|
|
2672
|
+
return NIL;
|
|
2673
|
+
}
|
|
2674
|
+
function parseSequence2(ctx, depth, id, current) {
|
|
2675
|
+
const nodes = [];
|
|
2676
|
+
for (let i = 0, len = current.v.length;i < len; i++) {
|
|
2677
|
+
nodes[i] = parseSOS(ctx, depth, current.v[i]);
|
|
2678
|
+
}
|
|
2679
|
+
return createSequenceNode(id, nodes, current.t, current.d);
|
|
2680
|
+
}
|
|
2681
|
+
function parseObjectPhase2(ctx, depth, id, current, currentClass) {
|
|
2682
|
+
switch (currentClass) {
|
|
2683
|
+
case Object:
|
|
2684
|
+
return parsePlainObject2(ctx, depth, id, current, false);
|
|
2685
|
+
case NIL:
|
|
2686
|
+
return parsePlainObject2(ctx, depth, id, current, true);
|
|
2687
|
+
case Date:
|
|
2688
|
+
return createDateNode(id, current);
|
|
2689
|
+
case Error:
|
|
2690
|
+
case EvalError:
|
|
2691
|
+
case RangeError:
|
|
2692
|
+
case ReferenceError:
|
|
2693
|
+
case SyntaxError:
|
|
2694
|
+
case TypeError:
|
|
2695
|
+
case URIError:
|
|
2696
|
+
return parseError2(ctx, depth, id, current);
|
|
2697
|
+
case Number:
|
|
2698
|
+
case Boolean:
|
|
2699
|
+
case String:
|
|
2700
|
+
case BigInt:
|
|
2701
|
+
return parseBoxed2(ctx, depth, id, current);
|
|
2702
|
+
case ArrayBuffer:
|
|
2703
|
+
return createArrayBufferNode(ctx.base, id, current);
|
|
2704
|
+
case Int8Array:
|
|
2705
|
+
case Int16Array:
|
|
2706
|
+
case Int32Array:
|
|
2707
|
+
case Uint8Array:
|
|
2708
|
+
case Uint16Array:
|
|
2709
|
+
case Uint32Array:
|
|
2710
|
+
case Uint8ClampedArray:
|
|
2711
|
+
case Float32Array:
|
|
2712
|
+
case Float64Array:
|
|
2713
|
+
return parseTypedArray2(ctx, depth, id, current);
|
|
2714
|
+
case DataView:
|
|
2715
|
+
return parseDataView2(ctx, depth, id, current);
|
|
2716
|
+
case Map:
|
|
2717
|
+
return parseMap2(ctx, depth, id, current);
|
|
2718
|
+
case Set:
|
|
2719
|
+
return parseSet2(ctx, depth, id, current);
|
|
2720
|
+
default:
|
|
2721
|
+
break;
|
|
2722
|
+
}
|
|
2723
|
+
if (currentClass === Promise || current instanceof Promise) {
|
|
2724
|
+
return parsePromise2(ctx, depth, id, current);
|
|
2725
|
+
}
|
|
2726
|
+
const currentFeatures = ctx.base.features;
|
|
2727
|
+
if (currentFeatures & 32 && currentClass === RegExp) {
|
|
2728
|
+
return createRegExpNode(id, current);
|
|
2729
|
+
}
|
|
2730
|
+
if (currentFeatures & 16) {
|
|
2731
|
+
switch (currentClass) {
|
|
2732
|
+
case BigInt64Array:
|
|
2733
|
+
case BigUint64Array:
|
|
2734
|
+
return parseBigIntTypedArray2(ctx, depth, id, current);
|
|
2735
|
+
default:
|
|
2736
|
+
break;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
if (currentFeatures & 1 && typeof AggregateError !== "undefined" && (currentClass === AggregateError || current instanceof AggregateError)) {
|
|
2740
|
+
return parseAggregateError2(ctx, depth, id, current);
|
|
2741
|
+
}
|
|
2742
|
+
if (current instanceof Error) {
|
|
2743
|
+
return parseError2(ctx, depth, id, current);
|
|
2744
|
+
}
|
|
2745
|
+
if (SYM_ITERATOR in current || SYM_ASYNC_ITERATOR in current) {
|
|
2746
|
+
return parsePlainObject2(ctx, depth, id, current, !!currentClass);
|
|
2747
|
+
}
|
|
2748
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
2749
|
+
}
|
|
2750
|
+
function parseObject(ctx, depth, id, current) {
|
|
2751
|
+
if (Array.isArray(current)) {
|
|
2752
|
+
return parseArray2(ctx, depth, id, current);
|
|
2753
|
+
}
|
|
2754
|
+
if (isStream(current)) {
|
|
2755
|
+
return parseStream2(ctx, depth, id, current);
|
|
2756
|
+
}
|
|
2757
|
+
if (isSequence(current)) {
|
|
2758
|
+
return parseSequence2(ctx, depth, id, current);
|
|
2759
|
+
}
|
|
2760
|
+
const currentClass = current.constructor;
|
|
2761
|
+
if (currentClass === OpaqueReference) {
|
|
2762
|
+
return parseSOS(ctx, depth, current.replacement);
|
|
2763
|
+
}
|
|
2764
|
+
const parsed = parsePlugin2(ctx, depth, id, current);
|
|
2765
|
+
if (parsed) {
|
|
2766
|
+
return parsed;
|
|
2767
|
+
}
|
|
2768
|
+
return parseObjectPhase2(ctx, depth, id, current, currentClass);
|
|
2769
|
+
}
|
|
2770
|
+
function parseFunction(ctx, depth, current) {
|
|
2771
|
+
const ref = getReferenceNode(ctx.base, current);
|
|
2772
|
+
if (ref.type !== 0) {
|
|
2773
|
+
return ref.value;
|
|
2774
|
+
}
|
|
2775
|
+
const plugin = parsePlugin2(ctx, depth, ref.value, current);
|
|
2776
|
+
if (plugin) {
|
|
2777
|
+
return plugin;
|
|
2778
|
+
}
|
|
2779
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
2780
|
+
}
|
|
2781
|
+
function parseSOS(ctx, depth, current) {
|
|
2782
|
+
if (depth >= ctx.base.depthLimit) {
|
|
2783
|
+
throw new SerovalDepthLimitError(ctx.base.depthLimit);
|
|
2784
|
+
}
|
|
2785
|
+
switch (typeof current) {
|
|
2786
|
+
case "boolean":
|
|
2787
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
2788
|
+
case "undefined":
|
|
2789
|
+
return UNDEFINED_NODE;
|
|
2790
|
+
case "string":
|
|
2791
|
+
return createStringNode(current);
|
|
2792
|
+
case "number":
|
|
2793
|
+
return createNumberNode(current);
|
|
2794
|
+
case "bigint":
|
|
2795
|
+
return createBigIntNode(current);
|
|
2796
|
+
case "object": {
|
|
2797
|
+
if (current) {
|
|
2798
|
+
const ref = getReferenceNode(ctx.base, current);
|
|
2799
|
+
return ref.type === 0 ? parseObject(ctx, depth + 1, ref.value, current) : ref.value;
|
|
2800
|
+
}
|
|
2801
|
+
return NULL_NODE;
|
|
2802
|
+
}
|
|
2803
|
+
case "symbol":
|
|
2804
|
+
return parseWellKnownSymbol(ctx.base, current);
|
|
2805
|
+
case "function": {
|
|
2806
|
+
return parseFunction(ctx, depth, current);
|
|
2807
|
+
}
|
|
2808
|
+
default:
|
|
2809
|
+
throw new SerovalUnsupportedTypeError(current);
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
function parseTop(ctx, current) {
|
|
2813
|
+
try {
|
|
2814
|
+
return parseSOS(ctx, 0, current);
|
|
2815
|
+
} catch (error) {
|
|
2816
|
+
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
function onParse(ctx, node) {
|
|
2820
|
+
if (ctx.state.initial) {
|
|
2821
|
+
ctx.state.buffer.push(node);
|
|
2822
|
+
} else {
|
|
2823
|
+
onParseInternal(ctx, node, false);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
function onError(ctx, error) {
|
|
2827
|
+
if (ctx.state.onError) {
|
|
2828
|
+
ctx.state.onError(error);
|
|
2829
|
+
} else {
|
|
2830
|
+
throw error instanceof SerovalParserError ? error : new SerovalParserError(error);
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
function onDone(ctx) {
|
|
2834
|
+
if (ctx.state.onDone) {
|
|
2835
|
+
ctx.state.onDone();
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
function onParseInternal(ctx, node, initial) {
|
|
2839
|
+
try {
|
|
2840
|
+
ctx.state.onParse(node, initial);
|
|
2841
|
+
} catch (error) {
|
|
2842
|
+
onError(ctx, error);
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
function pushPendingState(ctx) {
|
|
2846
|
+
ctx.state.pending++;
|
|
2847
|
+
}
|
|
2848
|
+
function popPendingState(ctx) {
|
|
2849
|
+
if (--ctx.state.pending <= 0) {
|
|
2850
|
+
onDone(ctx);
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
function parseWithError(ctx, depth, current) {
|
|
2854
|
+
try {
|
|
2855
|
+
return parseSOS(ctx, depth, current);
|
|
2856
|
+
} catch (err) {
|
|
2857
|
+
onError(ctx, err);
|
|
2858
|
+
return NIL;
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
function toCrossJSON(source, options = {}) {
|
|
2862
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2863
|
+
const ctx = createSyncParserContext(2, {
|
|
2864
|
+
plugins,
|
|
2865
|
+
disabledFeatures: options.disabledFeatures,
|
|
2866
|
+
refs: options.refs
|
|
2867
|
+
});
|
|
2868
|
+
return parseTop(ctx, source);
|
|
2869
|
+
}
|
|
2870
|
+
async function toCrossJSONAsync(source, options = {}) {
|
|
2871
|
+
const plugins = resolvePlugins(options.plugins);
|
|
2872
|
+
const ctx = createAsyncParserContext(2, {
|
|
2873
|
+
plugins,
|
|
2874
|
+
disabledFeatures: options.disabledFeatures,
|
|
2875
|
+
refs: options.refs
|
|
2876
|
+
});
|
|
2877
|
+
return await parseTopAsync(ctx, source);
|
|
2878
|
+
}
|
|
2879
|
+
var ALL_ENABLED, SYM_ASYNC_ITERATOR, SYM_HAS_INSTANCE, SYM_IS_CONCAT_SPREADABLE, SYM_ITERATOR, SYM_MATCH, SYM_MATCH_ALL, SYM_REPLACE, SYM_SEARCH, SYM_SPECIES, SYM_SPLIT, SYM_TO_PRIMITIVE, SYM_TO_STRING_TAG, SYM_UNSCOPABLES, INV_SYMBOL_REF, NIL = undefined, CONSTANT_VAL, ERROR_CONSTRUCTOR_STRING, TRUE_NODE, FALSE_NODE, UNDEFINED_NODE, NULL_NODE, NEG_ZERO_NODE, INFINITY_NODE, NEG_INFINITY_NODE, NAN_NODE, REFERENCES_KEY = "__SEROVAL_REFS__", GLOBAL_CONTEXT_REFERENCES = "$R", GLOBAL_CONTEXT_R, REFERENCE, INV_REFERENCE, objectToString, getErrorMessage = (type, cause) => getErrorMessageDev(type, cause), SerovalError, SerovalParserError, SerovalUnsupportedTypeError, SerovalMissingReferenceError, SerovalDepthLimitError, OpaqueReference = class {
|
|
2880
|
+
constructor(value, replacement) {
|
|
2881
|
+
this.value = value;
|
|
2882
|
+
this.replacement = replacement;
|
|
2883
|
+
}
|
|
2884
|
+
}, PROMISE_CONSTRUCTOR = () => {
|
|
2885
|
+
const resolver = {
|
|
2886
|
+
p: 0,
|
|
2887
|
+
s: 0,
|
|
2888
|
+
f: 0
|
|
2889
|
+
};
|
|
2890
|
+
resolver.p = new Promise((resolve, reject) => {
|
|
2891
|
+
resolver.s = resolve;
|
|
2892
|
+
resolver.f = reject;
|
|
2893
|
+
});
|
|
2894
|
+
return resolver;
|
|
2895
|
+
}, STREAM_CONSTRUCTOR = () => {
|
|
2896
|
+
const buffer = [];
|
|
2897
|
+
const listeners = [];
|
|
2898
|
+
let alive = true;
|
|
2899
|
+
let success = false;
|
|
2900
|
+
let count = 0;
|
|
2901
|
+
const flush = (value, mode, x) => {
|
|
2902
|
+
for (x = 0;x < count; x++) {
|
|
2903
|
+
if (listeners[x]) {
|
|
2904
|
+
listeners[x][mode](value);
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
};
|
|
2908
|
+
const up = (listener, x, z, current) => {
|
|
2909
|
+
for (x = 0, z = buffer.length;x < z; x++) {
|
|
2910
|
+
current = buffer[x];
|
|
2911
|
+
if (!alive && x === z - 1) {
|
|
2912
|
+
listener[success ? "return" : "throw"](current);
|
|
2913
|
+
} else {
|
|
2914
|
+
listener.next(current);
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
};
|
|
2918
|
+
const on = (listener, temp) => {
|
|
2919
|
+
if (alive) {
|
|
2920
|
+
temp = count++;
|
|
2921
|
+
listeners[temp] = listener;
|
|
2922
|
+
}
|
|
2923
|
+
up(listener);
|
|
2924
|
+
return () => {
|
|
2925
|
+
if (alive) {
|
|
2926
|
+
listeners[temp] = listeners[count];
|
|
2927
|
+
listeners[count--] = undefined;
|
|
2928
|
+
}
|
|
2929
|
+
};
|
|
2930
|
+
};
|
|
2931
|
+
return {
|
|
2932
|
+
__SEROVAL_STREAM__: true,
|
|
2933
|
+
on: (listener) => on(listener),
|
|
2934
|
+
next: (value) => {
|
|
2935
|
+
if (alive) {
|
|
2936
|
+
buffer.push(value);
|
|
2937
|
+
flush(value, "next");
|
|
2938
|
+
}
|
|
2939
|
+
},
|
|
2940
|
+
throw: (value) => {
|
|
2941
|
+
if (alive) {
|
|
2942
|
+
buffer.push(value);
|
|
2943
|
+
flush(value, "throw");
|
|
2944
|
+
alive = false;
|
|
2945
|
+
success = false;
|
|
2946
|
+
listeners.length = 0;
|
|
2947
|
+
}
|
|
2948
|
+
},
|
|
2949
|
+
return: (value) => {
|
|
2950
|
+
if (alive) {
|
|
2951
|
+
buffer.push(value);
|
|
2952
|
+
flush(value, "return");
|
|
2953
|
+
alive = false;
|
|
2954
|
+
success = true;
|
|
2955
|
+
listeners.length = 0;
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
};
|
|
2959
|
+
}, ITERATOR_CONSTRUCTOR = (symbol) => (sequence) => () => {
|
|
2960
|
+
let index = 0;
|
|
2961
|
+
const instance = {
|
|
2962
|
+
[symbol]: () => instance,
|
|
2963
|
+
next: () => {
|
|
2964
|
+
if (index > sequence.d) {
|
|
2965
|
+
return {
|
|
2966
|
+
done: true,
|
|
2967
|
+
value: undefined
|
|
2968
|
+
};
|
|
2969
|
+
}
|
|
2970
|
+
const currentIndex = index++;
|
|
2971
|
+
const data = sequence.v[currentIndex];
|
|
2972
|
+
if (currentIndex === sequence.t) {
|
|
2973
|
+
throw data;
|
|
2974
|
+
}
|
|
2975
|
+
return {
|
|
2976
|
+
done: currentIndex === sequence.d,
|
|
2977
|
+
value: data
|
|
2978
|
+
};
|
|
2979
|
+
}
|
|
2980
|
+
};
|
|
2981
|
+
return instance;
|
|
2982
|
+
}, ASYNC_ITERATOR_CONSTRUCTOR = (symbol, createPromise) => (stream) => () => {
|
|
2983
|
+
let count = 0;
|
|
2984
|
+
let doneAt = -1;
|
|
2985
|
+
let isThrow = false;
|
|
2986
|
+
const buffer = [];
|
|
2987
|
+
const pending = [];
|
|
2988
|
+
const finalize = (i = 0, len = pending.length) => {
|
|
2989
|
+
for (;i < len; i++) {
|
|
2990
|
+
pending[i].s({
|
|
2991
|
+
done: true,
|
|
2992
|
+
value: undefined
|
|
2993
|
+
});
|
|
2994
|
+
}
|
|
2995
|
+
};
|
|
2996
|
+
stream.on({
|
|
2997
|
+
next: (value) => {
|
|
2998
|
+
const temp = pending.shift();
|
|
2999
|
+
if (temp) {
|
|
3000
|
+
temp.s({ done: false, value });
|
|
3001
|
+
}
|
|
3002
|
+
buffer.push(value);
|
|
3003
|
+
},
|
|
3004
|
+
throw: (value) => {
|
|
3005
|
+
const temp = pending.shift();
|
|
3006
|
+
if (temp) {
|
|
3007
|
+
temp.f(value);
|
|
3008
|
+
}
|
|
3009
|
+
finalize();
|
|
3010
|
+
doneAt = buffer.length;
|
|
3011
|
+
isThrow = true;
|
|
3012
|
+
buffer.push(value);
|
|
3013
|
+
},
|
|
3014
|
+
return: (value) => {
|
|
3015
|
+
const temp = pending.shift();
|
|
3016
|
+
if (temp) {
|
|
3017
|
+
temp.s({ done: true, value });
|
|
3018
|
+
}
|
|
3019
|
+
finalize();
|
|
3020
|
+
doneAt = buffer.length;
|
|
3021
|
+
buffer.push(value);
|
|
3022
|
+
}
|
|
3023
|
+
});
|
|
3024
|
+
const instance = {
|
|
3025
|
+
[symbol]: () => instance,
|
|
3026
|
+
next: () => {
|
|
3027
|
+
if (doneAt === -1) {
|
|
3028
|
+
const index2 = count++;
|
|
3029
|
+
if (index2 >= buffer.length) {
|
|
3030
|
+
const temp = createPromise();
|
|
3031
|
+
pending.push(temp);
|
|
3032
|
+
return temp.p;
|
|
3033
|
+
}
|
|
3034
|
+
return {
|
|
3035
|
+
done: false,
|
|
3036
|
+
value: buffer[index2]
|
|
3037
|
+
};
|
|
3038
|
+
}
|
|
3039
|
+
if (count > doneAt) {
|
|
3040
|
+
return {
|
|
3041
|
+
done: true,
|
|
3042
|
+
value: undefined
|
|
3043
|
+
};
|
|
3044
|
+
}
|
|
3045
|
+
const index = count++;
|
|
3046
|
+
const value = buffer[index];
|
|
3047
|
+
if (index !== doneAt) {
|
|
3048
|
+
return {
|
|
3049
|
+
done: false,
|
|
3050
|
+
value
|
|
3051
|
+
};
|
|
3052
|
+
}
|
|
3053
|
+
if (isThrow) {
|
|
3054
|
+
throw value;
|
|
3055
|
+
}
|
|
3056
|
+
return {
|
|
3057
|
+
done: true,
|
|
3058
|
+
value
|
|
3059
|
+
};
|
|
3060
|
+
}
|
|
3061
|
+
};
|
|
3062
|
+
return instance;
|
|
3063
|
+
}, createIterator, ITERATOR, ASYNC_ITERATOR, SPECIAL_REFS, createAsyncIterable, AsyncParsePluginContext = class {
|
|
3064
|
+
constructor(_p, depth) {
|
|
3065
|
+
this._p = _p;
|
|
3066
|
+
this.depth = depth;
|
|
3067
|
+
}
|
|
3068
|
+
parse(current) {
|
|
3069
|
+
return parseAsync(this._p, this.depth, current);
|
|
3070
|
+
}
|
|
3071
|
+
}, REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_", REF_START_CHARS_LEN, REF_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_", REF_CHARS_LEN, SyncParsePluginContext = class {
|
|
3072
|
+
constructor(_p, depth) {
|
|
3073
|
+
this._p = _p;
|
|
3074
|
+
this.depth = depth;
|
|
3075
|
+
}
|
|
3076
|
+
parse(current) {
|
|
3077
|
+
return parseSOS(this._p, this.depth, current);
|
|
3078
|
+
}
|
|
3079
|
+
}, StreamParsePluginContext = class {
|
|
3080
|
+
constructor(_p, depth) {
|
|
3081
|
+
this._p = _p;
|
|
3082
|
+
this.depth = depth;
|
|
3083
|
+
}
|
|
3084
|
+
parse(current) {
|
|
3085
|
+
return parseSOS(this._p, this.depth, current);
|
|
3086
|
+
}
|
|
3087
|
+
parseWithError(current) {
|
|
3088
|
+
return parseWithError(this._p, this.depth, current);
|
|
3089
|
+
}
|
|
3090
|
+
isAlive() {
|
|
3091
|
+
return this._p.state.alive;
|
|
3092
|
+
}
|
|
3093
|
+
pushPendingState() {
|
|
3094
|
+
pushPendingState(this._p);
|
|
3095
|
+
}
|
|
3096
|
+
popPendingState() {
|
|
3097
|
+
popPendingState(this._p);
|
|
3098
|
+
}
|
|
3099
|
+
onParse(node) {
|
|
3100
|
+
onParse(this._p, node);
|
|
3101
|
+
}
|
|
3102
|
+
onError(error) {
|
|
3103
|
+
onError(this._p, error);
|
|
3104
|
+
}
|
|
3105
|
+
};
|
|
3106
|
+
var init_development = __esm(() => {
|
|
3107
|
+
ALL_ENABLED = 1 | 2 | 4 | 8 | 16 | 32;
|
|
3108
|
+
SYM_ASYNC_ITERATOR = Symbol.asyncIterator;
|
|
3109
|
+
SYM_HAS_INSTANCE = Symbol.hasInstance;
|
|
3110
|
+
SYM_IS_CONCAT_SPREADABLE = Symbol.isConcatSpreadable;
|
|
3111
|
+
SYM_ITERATOR = Symbol.iterator;
|
|
3112
|
+
SYM_MATCH = Symbol.match;
|
|
3113
|
+
SYM_MATCH_ALL = Symbol.matchAll;
|
|
3114
|
+
SYM_REPLACE = Symbol.replace;
|
|
3115
|
+
SYM_SEARCH = Symbol.search;
|
|
3116
|
+
SYM_SPECIES = Symbol.species;
|
|
3117
|
+
SYM_SPLIT = Symbol.split;
|
|
3118
|
+
SYM_TO_PRIMITIVE = Symbol.toPrimitive;
|
|
3119
|
+
SYM_TO_STRING_TAG = Symbol.toStringTag;
|
|
3120
|
+
SYM_UNSCOPABLES = Symbol.unscopables;
|
|
3121
|
+
INV_SYMBOL_REF = {
|
|
3122
|
+
[SYM_ASYNC_ITERATOR]: 0,
|
|
3123
|
+
[SYM_HAS_INSTANCE]: 1,
|
|
3124
|
+
[SYM_IS_CONCAT_SPREADABLE]: 2,
|
|
3125
|
+
[SYM_ITERATOR]: 3,
|
|
3126
|
+
[SYM_MATCH]: 4,
|
|
3127
|
+
[SYM_MATCH_ALL]: 5,
|
|
3128
|
+
[SYM_REPLACE]: 6,
|
|
3129
|
+
[SYM_SEARCH]: 7,
|
|
3130
|
+
[SYM_SPECIES]: 8,
|
|
3131
|
+
[SYM_SPLIT]: 9,
|
|
3132
|
+
[SYM_TO_PRIMITIVE]: 10,
|
|
3133
|
+
[SYM_TO_STRING_TAG]: 11,
|
|
3134
|
+
[SYM_UNSCOPABLES]: 12
|
|
3135
|
+
};
|
|
3136
|
+
CONSTANT_VAL = {
|
|
3137
|
+
[2]: true,
|
|
3138
|
+
[3]: false,
|
|
3139
|
+
[1]: NIL,
|
|
3140
|
+
[0]: null,
|
|
3141
|
+
[4]: -0,
|
|
3142
|
+
[5]: Number.POSITIVE_INFINITY,
|
|
3143
|
+
[6]: Number.NEGATIVE_INFINITY,
|
|
3144
|
+
[7]: Number.NaN
|
|
3145
|
+
};
|
|
3146
|
+
ERROR_CONSTRUCTOR_STRING = {
|
|
3147
|
+
[0]: "Error",
|
|
3148
|
+
[1]: "EvalError",
|
|
3149
|
+
[2]: "RangeError",
|
|
3150
|
+
[3]: "ReferenceError",
|
|
3151
|
+
[4]: "SyntaxError",
|
|
3152
|
+
[5]: "TypeError",
|
|
3153
|
+
[6]: "URIError"
|
|
3154
|
+
};
|
|
3155
|
+
TRUE_NODE = /* @__PURE__ */ createConstantNode(2);
|
|
3156
|
+
FALSE_NODE = /* @__PURE__ */ createConstantNode(3);
|
|
3157
|
+
UNDEFINED_NODE = /* @__PURE__ */ createConstantNode(1);
|
|
3158
|
+
NULL_NODE = /* @__PURE__ */ createConstantNode(0);
|
|
3159
|
+
NEG_ZERO_NODE = /* @__PURE__ */ createConstantNode(4);
|
|
3160
|
+
INFINITY_NODE = /* @__PURE__ */ createConstantNode(5);
|
|
3161
|
+
NEG_INFINITY_NODE = /* @__PURE__ */ createConstantNode(6);
|
|
3162
|
+
NAN_NODE = /* @__PURE__ */ createConstantNode(7);
|
|
3163
|
+
GLOBAL_CONTEXT_R = `self.${GLOBAL_CONTEXT_REFERENCES}`;
|
|
3164
|
+
REFERENCE = /* @__PURE__ */ new Map;
|
|
3165
|
+
INV_REFERENCE = /* @__PURE__ */ new Map;
|
|
3166
|
+
if (typeof globalThis !== "undefined") {
|
|
3167
|
+
Object.defineProperty(globalThis, REFERENCES_KEY, {
|
|
3168
|
+
value: INV_REFERENCE,
|
|
3169
|
+
configurable: true,
|
|
3170
|
+
writable: false,
|
|
3171
|
+
enumerable: false
|
|
3172
|
+
});
|
|
3173
|
+
} else if (typeof window !== "undefined") {
|
|
3174
|
+
Object.defineProperty(window, REFERENCES_KEY, {
|
|
3175
|
+
value: INV_REFERENCE,
|
|
3176
|
+
configurable: true,
|
|
3177
|
+
writable: false,
|
|
3178
|
+
enumerable: false
|
|
3179
|
+
});
|
|
3180
|
+
} else if (typeof self !== "undefined") {
|
|
3181
|
+
Object.defineProperty(self, REFERENCES_KEY, {
|
|
3182
|
+
value: INV_REFERENCE,
|
|
3183
|
+
configurable: true,
|
|
3184
|
+
writable: false,
|
|
3185
|
+
enumerable: false
|
|
3186
|
+
});
|
|
3187
|
+
} else if (typeof global !== "undefined") {
|
|
3188
|
+
Object.defineProperty(global, REFERENCES_KEY, {
|
|
3189
|
+
value: INV_REFERENCE,
|
|
3190
|
+
configurable: true,
|
|
3191
|
+
writable: false,
|
|
3192
|
+
enumerable: false
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
({ toString: objectToString } = Object.prototype);
|
|
3196
|
+
SerovalError = class extends Error {
|
|
3197
|
+
constructor(type, cause) {
|
|
3198
|
+
super(getErrorMessage(type, cause));
|
|
3199
|
+
this.cause = cause;
|
|
3200
|
+
}
|
|
3201
|
+
};
|
|
3202
|
+
SerovalParserError = class extends SerovalError {
|
|
3203
|
+
constructor(cause) {
|
|
3204
|
+
super("parsing", cause);
|
|
3205
|
+
}
|
|
3206
|
+
};
|
|
3207
|
+
SerovalUnsupportedTypeError = class extends Error {
|
|
3208
|
+
constructor(value) {
|
|
3209
|
+
super(`The value ${objectToString.call(value)} of type "${typeof value}" cannot be parsed/serialized.
|
|
3210
|
+
|
|
3211
|
+
There are few workarounds for this problem:
|
|
3212
|
+
- Transform the value in a way that it can be serialized.
|
|
3213
|
+
- If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.`);
|
|
3214
|
+
this.value = value;
|
|
3215
|
+
}
|
|
3216
|
+
};
|
|
3217
|
+
SerovalMissingReferenceError = class extends Error {
|
|
3218
|
+
constructor(value) {
|
|
3219
|
+
super('Missing reference for the value "' + objectToString.call(value) + '" of type "' + typeof value + '"');
|
|
3220
|
+
this.value = value;
|
|
3221
|
+
}
|
|
3222
|
+
};
|
|
3223
|
+
SerovalDepthLimitError = class extends Error {
|
|
3224
|
+
constructor(limit) {
|
|
3225
|
+
super("Depth limit of " + limit + " reached");
|
|
3226
|
+
}
|
|
3227
|
+
};
|
|
3228
|
+
createIterator = ITERATOR_CONSTRUCTOR(SYM_ITERATOR);
|
|
3229
|
+
ITERATOR = {};
|
|
3230
|
+
ASYNC_ITERATOR = {};
|
|
3231
|
+
SPECIAL_REFS = {
|
|
3232
|
+
[0]: {},
|
|
3233
|
+
[1]: {},
|
|
3234
|
+
[2]: {},
|
|
3235
|
+
[3]: {},
|
|
3236
|
+
[4]: {},
|
|
3237
|
+
[5]: {}
|
|
3238
|
+
};
|
|
3239
|
+
createAsyncIterable = ASYNC_ITERATOR_CONSTRUCTOR(SYM_ASYNC_ITERATOR, PROMISE_CONSTRUCTOR);
|
|
3240
|
+
REF_START_CHARS_LEN = REF_START_CHARS.length;
|
|
3241
|
+
REF_CHARS_LEN = REF_CHARS.length;
|
|
3242
|
+
});
|
|
3243
|
+
|
|
3244
|
+
// src/not-found.ts
|
|
3245
|
+
function notFound(options) {
|
|
3246
|
+
throw new FurinNotFoundError(options);
|
|
3247
|
+
}
|
|
3248
|
+
function isNotFoundError(err) {
|
|
3249
|
+
return err instanceof FurinNotFoundError || typeof err === "object" && err !== null && err.__furinBrand === NOT_FOUND_BRAND;
|
|
3250
|
+
}
|
|
3251
|
+
var NOT_FOUND_BRAND = "FURIN_NOT_FOUND", FurinNotFoundError;
|
|
3252
|
+
var init_not_found = __esm(() => {
|
|
3253
|
+
FurinNotFoundError = class FurinNotFoundError extends Error {
|
|
3254
|
+
__furinBrand = NOT_FOUND_BRAND;
|
|
3255
|
+
data;
|
|
3256
|
+
constructor(options) {
|
|
3257
|
+
super(options?.message ?? "");
|
|
3258
|
+
this.data = options?.data;
|
|
3259
|
+
}
|
|
3260
|
+
};
|
|
3261
|
+
});
|
|
3262
|
+
|
|
3263
|
+
// src/error.ts
|
|
3264
|
+
function getPublicErrorMessage(error) {
|
|
3265
|
+
const branded = error;
|
|
3266
|
+
if (branded?.__furinBrand === "FURIN_NOT_FOUND" || branded?.__furinBrand === "FURIN_SERVER_ERROR") {
|
|
3267
|
+
return error.message;
|
|
3268
|
+
}
|
|
3269
|
+
return "Something went wrong";
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
// src/server-error.ts
|
|
3273
|
+
function isFurinServerError(err) {
|
|
3274
|
+
return err instanceof FurinServerError || typeof err === "object" && err !== null && err.__furinBrand === SERVER_ERROR_BRAND;
|
|
3275
|
+
}
|
|
3276
|
+
var SERVER_ERROR_BRAND = "FURIN_SERVER_ERROR", FurinServerError;
|
|
3277
|
+
var init_server_error = __esm(() => {
|
|
3278
|
+
FurinServerError = class FurinServerError extends Error {
|
|
3279
|
+
__furinBrand = SERVER_ERROR_BRAND;
|
|
3280
|
+
digest;
|
|
3281
|
+
status;
|
|
3282
|
+
constructor(args) {
|
|
3283
|
+
super(args.message);
|
|
3284
|
+
this.status = args.status;
|
|
3285
|
+
this.digest = args.digest;
|
|
3286
|
+
}
|
|
3287
|
+
};
|
|
3288
|
+
});
|
|
3289
|
+
|
|
3290
|
+
// src/link.tsx
|
|
3291
|
+
import { createElement, useCallback, useEffect, useRef } from "react";
|
|
3292
|
+
function computeLinkView({
|
|
3293
|
+
to,
|
|
3294
|
+
search,
|
|
3295
|
+
hash,
|
|
3296
|
+
children,
|
|
3297
|
+
activeProps,
|
|
3298
|
+
inactiveProps
|
|
3299
|
+
}, router) {
|
|
3300
|
+
const logicalHref = buildHref(to, search, hash);
|
|
3301
|
+
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
3302
|
+
const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
|
|
3303
|
+
const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
|
|
3304
|
+
const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
|
|
3305
|
+
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
3306
|
+
const extraProps = {
|
|
3307
|
+
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
3308
|
+
...activeProps ? activeProps({ isActive }) : {}
|
|
3309
|
+
};
|
|
3310
|
+
return { logicalHref, href, isActive, resolvedChildren, extraProps };
|
|
3311
|
+
}
|
|
3312
|
+
function LinkInteractive({
|
|
3313
|
+
to,
|
|
3314
|
+
search,
|
|
3315
|
+
hash,
|
|
3316
|
+
preload,
|
|
3317
|
+
preloadDelay,
|
|
3318
|
+
preloadStaleTime,
|
|
3319
|
+
replace,
|
|
3320
|
+
disabled,
|
|
3321
|
+
resetScroll,
|
|
3322
|
+
activeProps,
|
|
3323
|
+
inactiveProps,
|
|
3324
|
+
onClick,
|
|
3325
|
+
onMouseEnter,
|
|
3326
|
+
onMouseLeave,
|
|
3327
|
+
onFocus,
|
|
3328
|
+
children,
|
|
3329
|
+
href: _href,
|
|
3330
|
+
...anchorProps
|
|
3331
|
+
}) {
|
|
3332
|
+
const router = useRouter();
|
|
3333
|
+
const anchorRef = useRef(null);
|
|
3334
|
+
const intentTimerRef = useRef(null);
|
|
3335
|
+
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
|
|
3336
|
+
const effectivePreload = preload ?? router.defaultPreload;
|
|
1549
3337
|
const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
|
|
1550
3338
|
const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
|
|
3339
|
+
const { prefetch } = router;
|
|
1551
3340
|
const triggerPrefetch = useCallback(() => {
|
|
1552
|
-
|
|
1553
|
-
}, [
|
|
3341
|
+
prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
3342
|
+
}, [prefetch, logicalHref, effectiveStaleTime]);
|
|
1554
3343
|
useEffect(() => {
|
|
1555
3344
|
if (effectivePreload === "render") {
|
|
1556
3345
|
triggerPrefetch();
|
|
@@ -1601,6 +3390,10 @@ function LinkInteractive({
|
|
|
1601
3390
|
return;
|
|
1602
3391
|
}
|
|
1603
3392
|
e.preventDefault();
|
|
3393
|
+
if (typeof window !== "undefined" && router.navigate === SSR_FALLBACK_ROUTER.navigate) {
|
|
3394
|
+
window.location.href = href;
|
|
3395
|
+
return;
|
|
3396
|
+
}
|
|
1604
3397
|
router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
|
|
1605
3398
|
};
|
|
1606
3399
|
const handleMouseEnter = (e) => {
|
|
@@ -1678,6 +3471,7 @@ function Link(props) {
|
|
|
1678
3471
|
var SSR_FALLBACK_ROUTER;
|
|
1679
3472
|
var init_link = __esm(() => {
|
|
1680
3473
|
init_router_provider();
|
|
3474
|
+
init_development();
|
|
1681
3475
|
init_router_provider();
|
|
1682
3476
|
SSR_FALLBACK_ROUTER = {
|
|
1683
3477
|
basePath: "",
|
|
@@ -1715,7 +3509,7 @@ function ScreenFrame({ badge, children }) {
|
|
|
1715
3509
|
style: PAGE_STYLE,
|
|
1716
3510
|
children: [
|
|
1717
3511
|
/* @__PURE__ */ jsxDEV("style", {
|
|
1718
|
-
|
|
3512
|
+
children: RESET_CSS
|
|
1719
3513
|
}, undefined, false, undefined, this),
|
|
1720
3514
|
/* @__PURE__ */ jsxDEV("div", {
|
|
1721
3515
|
style: FRAME_STYLE,
|
|
@@ -1796,7 +3590,7 @@ function DefaultErrorScreen({ message, digest, reset }) {
|
|
|
1796
3590
|
function DefaultNotFoundScreen({ message }) {
|
|
1797
3591
|
return /* @__PURE__ */ jsxDEV(ScreenFrame, {
|
|
1798
3592
|
badge: /* @__PURE__ */ jsxDEV("div", {
|
|
1799
|
-
style:
|
|
3593
|
+
style: BADGE_STYLE,
|
|
1800
3594
|
children: "404 \u2014 NOT FOUND"
|
|
1801
3595
|
}, undefined, false, undefined, this),
|
|
1802
3596
|
children: [
|
|
@@ -1819,7 +3613,7 @@ function DefaultNotFoundScreen({ message }) {
|
|
|
1819
3613
|
]
|
|
1820
3614
|
}, undefined, true, undefined, this);
|
|
1821
3615
|
}
|
|
1822
|
-
var FONT_SANS = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif', FONT_MONO = 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace', COLOR_BG = "#000000", COLOR_TEXT = "#ffffff", COLOR_TEXT_DIM = "rgba(255, 255, 255, 0.7)", COLOR_TEXT_MUTED = "rgba(255, 255, 255, 0.45)", COLOR_GRID = "rgba(255, 255, 255, 0.04)", COLOR_BRACKET = "rgba(255, 255, 255, 0.55)", COLOR_DANGER_DIM = "rgba(239, 68, 68, 0.6)", PAGE_STYLE, FRAME_STYLE, BRACKET_BASE, CARD_STYLE, BADGE_STYLE,
|
|
3616
|
+
var FONT_SANS = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif', FONT_MONO = 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace', COLOR_BG = "#000000", COLOR_TEXT = "#ffffff", COLOR_TEXT_DIM = "rgba(255, 255, 255, 0.7)", COLOR_TEXT_MUTED = "rgba(255, 255, 255, 0.45)", COLOR_GRID = "rgba(255, 255, 255, 0.04)", COLOR_BRACKET = "rgba(255, 255, 255, 0.55)", COLOR_DANGER_DIM = "rgba(239, 68, 68, 0.6)", PAGE_STYLE, FRAME_STYLE, BRACKET_BASE, CARD_STYLE, BADGE_STYLE, HEADING_STYLE, CODE_BOX_STYLE, CODE_LABEL_STYLE, DESCRIPTION_WRAPPER_STYLE, ACTIONS_STYLE, BUTTON_BASE, BUTTON_PRIMARY, BUTTON_SECONDARY, DIVIDER_STYLE, RESET_CSS;
|
|
1823
3617
|
var init_default_screens = __esm(() => {
|
|
1824
3618
|
init_link();
|
|
1825
3619
|
PAGE_STYLE = {
|
|
@@ -1871,11 +3665,6 @@ var init_default_screens = __esm(() => {
|
|
|
1871
3665
|
marginBottom: "16px",
|
|
1872
3666
|
padding: "12px 36px"
|
|
1873
3667
|
};
|
|
1874
|
-
NOT_FOUND_BADGE_STYLE = {
|
|
1875
|
-
...BADGE_STYLE,
|
|
1876
|
-
border: 0,
|
|
1877
|
-
padding: 0
|
|
1878
|
-
};
|
|
1879
3668
|
HEADING_STYLE = {
|
|
1880
3669
|
color: COLOR_TEXT,
|
|
1881
3670
|
fontFamily: FONT_SANS,
|
|
@@ -2002,11 +3791,12 @@ var DefaultErrorFallback = ({ error, reset }) => /* @__PURE__ */ jsxDEV2(Default
|
|
|
2002
3791
|
digest: error.digest,
|
|
2003
3792
|
message: error.message,
|
|
2004
3793
|
reset
|
|
2005
|
-
}, undefined, false, undefined, this), DefaultNotFoundFallback = ({ error }) => /* @__PURE__ */ jsxDEV2(DefaultNotFoundScreen, {
|
|
3794
|
+
}, undefined, false, undefined, this), DEFAULT_ERROR_STATUS = 500, DefaultNotFoundFallback = ({ error }) => /* @__PURE__ */ jsxDEV2(DefaultNotFoundScreen, {
|
|
2006
3795
|
message: error.message
|
|
2007
3796
|
}, undefined, false, undefined, this), SERVER_RESET_NOOP = () => {}, FurinErrorBoundary, FurinNotFoundBoundary;
|
|
2008
3797
|
var init_boundaries = __esm(() => {
|
|
2009
3798
|
init_not_found();
|
|
3799
|
+
init_server_error();
|
|
2010
3800
|
init_default_screens();
|
|
2011
3801
|
FurinErrorBoundary = class FurinErrorBoundary extends Component {
|
|
2012
3802
|
state = {
|
|
@@ -2034,10 +3824,12 @@ var init_boundaries = __esm(() => {
|
|
|
2034
3824
|
throw error;
|
|
2035
3825
|
}
|
|
2036
3826
|
const Fallback = this.props.fallback ?? DefaultErrorFallback;
|
|
2037
|
-
const
|
|
3827
|
+
const serverDigest = isFurinServerError(error) ? error.digest : undefined;
|
|
3828
|
+
const finalDigest = serverDigest ?? digest ?? this.props.digest ?? computeErrorDigest(error);
|
|
2038
3829
|
const message = this.props.fallback ? error.message : getPublicErrorMessage(error);
|
|
3830
|
+
const status = isFurinServerError(error) ? error.status : DEFAULT_ERROR_STATUS;
|
|
2039
3831
|
return /* @__PURE__ */ jsxDEV2(Fallback, {
|
|
2040
|
-
error: { message, digest: finalDigest },
|
|
3832
|
+
error: { message, digest: finalDigest, status },
|
|
2041
3833
|
reset: typeof window === "undefined" ? SERVER_RESET_NOOP : this.reset
|
|
2042
3834
|
}, undefined, false, undefined, this);
|
|
2043
3835
|
}
|
|
@@ -2140,6 +3932,65 @@ var init_router_provider = __esm(() => {
|
|
|
2140
3932
|
RouterContext = createContext(null);
|
|
2141
3933
|
});
|
|
2142
3934
|
|
|
3935
|
+
// src/utils.ts
|
|
3936
|
+
function isFurinPage(value) {
|
|
3937
|
+
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_PAGE";
|
|
3938
|
+
}
|
|
3939
|
+
function isFurinRoute(value) {
|
|
3940
|
+
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_ROUTE";
|
|
3941
|
+
}
|
|
3942
|
+
function collectRouteChainFromRoute(route) {
|
|
3943
|
+
const chain = [];
|
|
3944
|
+
let current = route;
|
|
3945
|
+
while (current) {
|
|
3946
|
+
chain.unshift(current);
|
|
3947
|
+
current = current.parent;
|
|
3948
|
+
}
|
|
3949
|
+
return chain;
|
|
3950
|
+
}
|
|
3951
|
+
function hasCycle(route) {
|
|
3952
|
+
const visited = new Set;
|
|
3953
|
+
let current = route;
|
|
3954
|
+
while (current) {
|
|
3955
|
+
if (visited.has(current)) {
|
|
3956
|
+
return true;
|
|
3957
|
+
}
|
|
3958
|
+
visited.add(current);
|
|
3959
|
+
current = current.parent;
|
|
3960
|
+
}
|
|
3961
|
+
return false;
|
|
3962
|
+
}
|
|
3963
|
+
async function mapWithConcurrency(items, concurrency, fn) {
|
|
3964
|
+
if (items.length === 0) {
|
|
3965
|
+
return [];
|
|
3966
|
+
}
|
|
3967
|
+
const results = new Array(items.length);
|
|
3968
|
+
let cursor = 0;
|
|
3969
|
+
const workerCount = Math.min(Math.max(concurrency, 1), items.length);
|
|
3970
|
+
await Promise.all(Array.from({ length: workerCount }, async () => {
|
|
3971
|
+
while (true) {
|
|
3972
|
+
const index = cursor++;
|
|
3973
|
+
if (index >= items.length) {
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
results[index] = await fn(items[index], index);
|
|
3977
|
+
}
|
|
3978
|
+
}));
|
|
3979
|
+
return results;
|
|
3980
|
+
}
|
|
3981
|
+
function validateRouteChain(chain, root, pagePath) {
|
|
3982
|
+
const hasRoot = chain.some((r) => r === root);
|
|
3983
|
+
if (!hasRoot) {
|
|
3984
|
+
const location = pagePath ? `in ${pagePath}` : "";
|
|
3985
|
+
throw new Error(`[furin] Page ${location} must inherit from root route. ` + 'Add: import { route } from "./root"; and use route.page() or set parent: route');
|
|
3986
|
+
}
|
|
3987
|
+
for (const route of chain) {
|
|
3988
|
+
if (hasCycle(route)) {
|
|
3989
|
+
throw new Error("[furin] Cycle detected in route chain. A route cannot be its own ancestor.");
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
|
|
2143
3994
|
// src/render/shell.ts
|
|
2144
3995
|
function extractTitle(meta) {
|
|
2145
3996
|
if (!meta) {
|
|
@@ -2162,7 +4013,13 @@ function safeJson(value) {
|
|
|
2162
4013
|
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
2163
4014
|
}
|
|
2164
4015
|
function renderAttrs(obj) {
|
|
2165
|
-
|
|
4016
|
+
const parts = [];
|
|
4017
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
4018
|
+
if (v !== undefined) {
|
|
4019
|
+
parts.push(`${k}="${escapeHtml(String(v))}"`);
|
|
4020
|
+
}
|
|
4021
|
+
}
|
|
4022
|
+
return parts.join(" ");
|
|
2166
4023
|
}
|
|
2167
4024
|
function buildMetaParts(meta) {
|
|
2168
4025
|
const parts = [];
|
|
@@ -2240,6 +4097,34 @@ var init_shell = __esm(() => {
|
|
|
2240
4097
|
});
|
|
2241
4098
|
|
|
2242
4099
|
// src/render/assemble.ts
|
|
4100
|
+
function buildDeferredScript(deferredKeys) {
|
|
4101
|
+
const keysJson = safeJson(deferredKeys);
|
|
4102
|
+
return `<script id="${FURIN_DEFERRED_GLOBAL}">
|
|
4103
|
+
window.${FURIN_DEFERRED_GLOBAL} = {
|
|
4104
|
+
_deferredKeys: ${keysJson},
|
|
4105
|
+
_chunks: {},
|
|
4106
|
+
_resolvers: {},
|
|
4107
|
+
resolve(key, chunk) {
|
|
4108
|
+
this._chunks[key] = { a: 0, v: chunk };
|
|
4109
|
+
},
|
|
4110
|
+
reject(key, chunk) {
|
|
4111
|
+
this._chunks[key] = { a: 1, v: chunk };
|
|
4112
|
+
},
|
|
4113
|
+
getPromise(key) {
|
|
4114
|
+
if (!this._resolvers[key]) {
|
|
4115
|
+
var res, rej;
|
|
4116
|
+
var p = new Promise(function(resolve, reject) { res = resolve; rej = reject; });
|
|
4117
|
+
this._resolvers[key] = { resolve: res, reject: rej, promise: p };
|
|
4118
|
+
}
|
|
4119
|
+
return this._resolvers[key].promise;
|
|
4120
|
+
}
|
|
4121
|
+
};
|
|
4122
|
+
</script>`;
|
|
4123
|
+
}
|
|
4124
|
+
function buildDeferredResolution(key, chunk, action) {
|
|
4125
|
+
const chunkJson = safeJson(chunk);
|
|
4126
|
+
return `<script>window.${FURIN_DEFERRED_GLOBAL}.${action}(${safeJson(key)},${chunkJson})</script>`;
|
|
4127
|
+
}
|
|
2243
4128
|
function resolvePath(pattern, params) {
|
|
2244
4129
|
let path = pattern;
|
|
2245
4130
|
for (const [key, val] of Object.entries(params ?? {})) {
|
|
@@ -2275,6 +4160,7 @@ function assembleHTML(template, headData, reactHtml, data) {
|
|
|
2275
4160
|
}
|
|
2276
4161
|
return headPre + headData + bodyPre + reactHtml + injectedBodyPost;
|
|
2277
4162
|
}
|
|
4163
|
+
var FURIN_DEFERRED_GLOBAL = "__FURIN_DEFERRED__";
|
|
2278
4164
|
var init_assemble = __esm(() => {
|
|
2279
4165
|
init_shell();
|
|
2280
4166
|
});
|
|
@@ -2345,11 +4231,16 @@ function errorMessageOf(err) {
|
|
|
2345
4231
|
}
|
|
2346
4232
|
return "";
|
|
2347
4233
|
}
|
|
2348
|
-
function buildErrorElement(component, error, digest) {
|
|
4234
|
+
function buildErrorElement(component, error, digest, messageOverride, status) {
|
|
2349
4235
|
const ErrorView = component ?? DefaultErrorComponent;
|
|
2350
|
-
|
|
4236
|
+
let message;
|
|
4237
|
+
if (component) {
|
|
4238
|
+
message = messageOverride ?? errorMessageOf(error);
|
|
4239
|
+
} else {
|
|
4240
|
+
message = "An unexpected error occurred.";
|
|
4241
|
+
}
|
|
2351
4242
|
return /* @__PURE__ */ jsxDEV4(ErrorView, {
|
|
2352
|
-
error: { message, digest },
|
|
4243
|
+
error: { message, digest, status },
|
|
2353
4244
|
reset: SERVER_RESET_NOOP2
|
|
2354
4245
|
}, undefined, false, undefined, this);
|
|
2355
4246
|
}
|
|
@@ -2365,7 +4256,85 @@ var init_element = __esm(() => {
|
|
|
2365
4256
|
init_default_screens();
|
|
2366
4257
|
});
|
|
2367
4258
|
|
|
4259
|
+
// src/await.tsx
|
|
4260
|
+
import { Component as Component2, createContext as createContext2, createElement as createElement3, use } from "react";
|
|
4261
|
+
function useAsyncError() {
|
|
4262
|
+
return use(AsyncErrorContext);
|
|
4263
|
+
}
|
|
4264
|
+
function useAsyncValue() {
|
|
4265
|
+
const ctx = use(AwaitValueContext);
|
|
4266
|
+
if (!ctx) {
|
|
4267
|
+
throw new Error("useAsyncValue must be used inside <Await> children");
|
|
4268
|
+
}
|
|
4269
|
+
return use(ctx.promise);
|
|
4270
|
+
}
|
|
4271
|
+
function Await({ resolve, errorElement, children }) {
|
|
4272
|
+
return createElement3(AsyncErrorBoundary, { errorElement, resolve }, createElement3(AwaitInner, { resolve, children }));
|
|
4273
|
+
}
|
|
4274
|
+
function AwaitInner({ resolve, children }) {
|
|
4275
|
+
const value = use(resolve);
|
|
4276
|
+
return createElement3(AwaitValueContext.Provider, { value: { promise: resolve } }, children ? children(value) : null);
|
|
4277
|
+
}
|
|
4278
|
+
var AsyncErrorContext, AwaitValueContext, AsyncErrorBoundary;
|
|
4279
|
+
var init_await = __esm(() => {
|
|
4280
|
+
AsyncErrorContext = createContext2(undefined);
|
|
4281
|
+
AwaitValueContext = createContext2(undefined);
|
|
4282
|
+
AsyncErrorBoundary = class AsyncErrorBoundary extends Component2 {
|
|
4283
|
+
constructor(props) {
|
|
4284
|
+
super(props);
|
|
4285
|
+
this.state = { hasError: false, error: undefined, resolve: props.resolve };
|
|
4286
|
+
}
|
|
4287
|
+
static getDerivedStateFromProps(props, state) {
|
|
4288
|
+
if (props.resolve !== state.resolve) {
|
|
4289
|
+
return { hasError: false, error: undefined, resolve: props.resolve };
|
|
4290
|
+
}
|
|
4291
|
+
return null;
|
|
4292
|
+
}
|
|
4293
|
+
static getDerivedStateFromError(error) {
|
|
4294
|
+
return { hasError: true, error };
|
|
4295
|
+
}
|
|
4296
|
+
render() {
|
|
4297
|
+
const { hasError, error } = this.state;
|
|
4298
|
+
const { children, errorElement } = this.props;
|
|
4299
|
+
if (hasError) {
|
|
4300
|
+
if (errorElement === undefined) {
|
|
4301
|
+
throw error;
|
|
4302
|
+
}
|
|
4303
|
+
return createElement3(AsyncErrorContext.Provider, { value: error }, errorElement);
|
|
4304
|
+
}
|
|
4305
|
+
return children;
|
|
4306
|
+
}
|
|
4307
|
+
};
|
|
4308
|
+
});
|
|
4309
|
+
|
|
4310
|
+
// src/client.ts
|
|
4311
|
+
function defer(data) {
|
|
4312
|
+
if (Object.hasOwn(data, DEFERRED_BRAND)) {
|
|
4313
|
+
throw new Error(`[furin] defer() received an object with a reserved key "${DEFERRED_BRAND}". Rename this field to avoid conflicts with the deferred-data runtime.`);
|
|
4314
|
+
}
|
|
4315
|
+
return { ...data, [DEFERRED_BRAND]: true };
|
|
4316
|
+
}
|
|
4317
|
+
function isDeferred(v) {
|
|
4318
|
+
return typeof v === "object" && v !== null && Object.hasOwn(v, DEFERRED_BRAND) && v[DEFERRED_BRAND] === true;
|
|
4319
|
+
}
|
|
4320
|
+
var DEFERRED_BRAND = "__isDeferred";
|
|
4321
|
+
var init_client = () => {};
|
|
4322
|
+
|
|
2368
4323
|
// src/render/loaders.ts
|
|
4324
|
+
function isHttpRedirect(res) {
|
|
4325
|
+
return REDIRECT_STATUSES.has(res.status) && res.headers.has("location");
|
|
4326
|
+
}
|
|
4327
|
+
async function readResponseMessage(res) {
|
|
4328
|
+
if (res.body === null) {
|
|
4329
|
+
return res.statusText;
|
|
4330
|
+
}
|
|
4331
|
+
try {
|
|
4332
|
+
const body = await res.text();
|
|
4333
|
+
return body || res.statusText;
|
|
4334
|
+
} catch {
|
|
4335
|
+
return res.statusText;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
2369
4338
|
function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
2370
4339
|
const cache = new Map;
|
|
2371
4340
|
return new Proxy(ctx, {
|
|
@@ -2388,9 +4357,61 @@ function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
|
2388
4357
|
}
|
|
2389
4358
|
});
|
|
2390
4359
|
}
|
|
2391
|
-
|
|
4360
|
+
function splitOneLoaderResult(result) {
|
|
4361
|
+
const sync = {};
|
|
4362
|
+
const deferred = {};
|
|
4363
|
+
const isDef = isDeferred(result);
|
|
4364
|
+
for (const [key, value] of Object.entries(result)) {
|
|
4365
|
+
if (key === "__isDeferred") {
|
|
4366
|
+
continue;
|
|
4367
|
+
}
|
|
4368
|
+
if (isDef && isPromiseLike(value)) {
|
|
4369
|
+
deferred[key] = Promise.resolve(value);
|
|
4370
|
+
} else {
|
|
4371
|
+
sync[key] = value;
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
return { sync, deferred };
|
|
4375
|
+
}
|
|
4376
|
+
function isPromiseLike(value) {
|
|
4377
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
4378
|
+
}
|
|
4379
|
+
function mergeLoaderResults(results) {
|
|
4380
|
+
const allSync = {};
|
|
4381
|
+
const allDeferred = {};
|
|
4382
|
+
for (const result of results) {
|
|
4383
|
+
const { sync, deferred } = splitOneLoaderResult(result);
|
|
4384
|
+
for (const k of Object.keys(sync)) {
|
|
4385
|
+
delete allDeferred[k];
|
|
4386
|
+
}
|
|
4387
|
+
for (const k of Object.keys(deferred)) {
|
|
4388
|
+
delete allSync[k];
|
|
4389
|
+
}
|
|
4390
|
+
Object.assign(allSync, sync);
|
|
4391
|
+
Object.assign(allDeferred, deferred);
|
|
4392
|
+
}
|
|
4393
|
+
return { allSync, allDeferred };
|
|
4394
|
+
}
|
|
4395
|
+
async function serializeDeferredRejection(err) {
|
|
4396
|
+
if (isNotFoundError(err)) {
|
|
4397
|
+
const wrapped = new Error(err.message);
|
|
4398
|
+
Object.assign(wrapped, { __furinBrand: "FURIN_NOT_FOUND", data: err.data });
|
|
4399
|
+
return wrapped;
|
|
4400
|
+
}
|
|
4401
|
+
if (err instanceof Response) {
|
|
4402
|
+
const body = await readResponseMessage(err);
|
|
4403
|
+
const wrapped = new Error(body || err.statusText || "Something went wrong");
|
|
4404
|
+
Object.assign(wrapped, { __furinStatus: err.status });
|
|
4405
|
+
return wrapped;
|
|
4406
|
+
}
|
|
4407
|
+
if (err instanceof Error) {
|
|
4408
|
+
return err;
|
|
4409
|
+
}
|
|
4410
|
+
return new Error(String(err));
|
|
4411
|
+
}
|
|
4412
|
+
async function runLoaders(route, ctx) {
|
|
2392
4413
|
try {
|
|
2393
|
-
const ctxRecord = { ...ctx, log:
|
|
4414
|
+
const ctxRecord = { ...ctx, log: useLogger2() };
|
|
2394
4415
|
const loaderMap = new Map;
|
|
2395
4416
|
let accumulatedParentPromise = Promise.resolve({});
|
|
2396
4417
|
for (const r of route.routeChain) {
|
|
@@ -2409,27 +4430,47 @@ async function runLoaders(route, ctx, _rootLayout) {
|
|
|
2409
4430
|
const pageCtx = createLoaderCtx(ctxRecord, accumulatedParentPromise);
|
|
2410
4431
|
const pagePromise = route.page?.loader ? Promise.resolve(route.page.loader(pageCtx)).then((r) => r ?? {}) : Promise.resolve({});
|
|
2411
4432
|
const results = await Promise.all([...loaderMap.values(), pagePromise]);
|
|
2412
|
-
const data = Object.assign({}, ...results);
|
|
2413
4433
|
const headers = {};
|
|
2414
4434
|
Object.assign(headers, ctx.set.headers);
|
|
2415
|
-
|
|
4435
|
+
const { allSync, allDeferred } = mergeLoaderResults(results);
|
|
4436
|
+
const routeCtx = { params: ctx.params, query: ctx.query, path: ctx.path };
|
|
4437
|
+
return {
|
|
4438
|
+
type: "data",
|
|
4439
|
+
syncData: { ...allSync, ...routeCtx },
|
|
4440
|
+
deferredPromises: Object.keys(allDeferred).length > 0 ? allDeferred : undefined,
|
|
4441
|
+
headers
|
|
4442
|
+
};
|
|
2416
4443
|
} catch (err) {
|
|
4444
|
+
const headers = {};
|
|
4445
|
+
Object.assign(headers, ctx.set.headers);
|
|
2417
4446
|
if (isNotFoundError(err)) {
|
|
2418
|
-
|
|
2419
|
-
Object.assign(headers2, ctx.set.headers);
|
|
2420
|
-
return { type: "not-found", error: err, headers: headers2 };
|
|
4447
|
+
return { type: "not-found", error: err, headers };
|
|
2421
4448
|
}
|
|
2422
4449
|
if (err instanceof Response) {
|
|
2423
|
-
|
|
4450
|
+
if (isHttpRedirect(err)) {
|
|
4451
|
+
return { type: "redirect", response: err };
|
|
4452
|
+
}
|
|
4453
|
+
const isMalformedRedirect = REDIRECT_STATUSES.has(err.status);
|
|
4454
|
+
const status = isMalformedRedirect ? 500 : err.status;
|
|
4455
|
+
const body = await readResponseMessage(err);
|
|
4456
|
+
const message = body || "Something went wrong";
|
|
4457
|
+
return { type: "error", error: err, status, message, headers };
|
|
2424
4458
|
}
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
4459
|
+
return {
|
|
4460
|
+
type: "error",
|
|
4461
|
+
error: err,
|
|
4462
|
+
status: 500,
|
|
4463
|
+
message: "Something went wrong",
|
|
4464
|
+
headers
|
|
4465
|
+
};
|
|
2428
4466
|
}
|
|
2429
4467
|
}
|
|
4468
|
+
var REDIRECT_STATUSES;
|
|
2430
4469
|
var init_loaders = __esm(() => {
|
|
4470
|
+
init_client();
|
|
2431
4471
|
init_context_logger();
|
|
2432
4472
|
init_not_found();
|
|
4473
|
+
REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
2433
4474
|
});
|
|
2434
4475
|
|
|
2435
4476
|
// src/render/template.ts
|
|
@@ -2475,14 +4516,19 @@ var init_template = () => {};
|
|
|
2475
4516
|
var IS_DEV = true;
|
|
2476
4517
|
|
|
2477
4518
|
// src/render/index.ts
|
|
2478
|
-
import { createElement as
|
|
4519
|
+
import { createElement as createElement4 } from "react";
|
|
2479
4520
|
import { renderToReadableStream } from "react-dom/server";
|
|
2480
4521
|
function withSSRRouterContext(element, contextValue) {
|
|
2481
|
-
return
|
|
4522
|
+
return createElement4(RouterContext.Provider, { value: contextValue }, element);
|
|
4523
|
+
}
|
|
4524
|
+
function assertDeferredModeAllowed(route, deferredPromises) {
|
|
4525
|
+
if (deferredPromises !== undefined && route.mode !== "ssr") {
|
|
4526
|
+
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.");
|
|
4527
|
+
}
|
|
2482
4528
|
}
|
|
2483
4529
|
async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult) {
|
|
2484
4530
|
const loaderStart = Date.now();
|
|
2485
|
-
const loaderResult = precomputedLoaderResult ?? await runLoaders(route, ctx
|
|
4531
|
+
const loaderResult = precomputedLoaderResult ?? await runLoaders(route, ctx);
|
|
2486
4532
|
const loader_ms = Date.now() - loaderStart;
|
|
2487
4533
|
if (loaderResult.type === "redirect") {
|
|
2488
4534
|
return loaderResult.response;
|
|
@@ -2493,10 +4539,13 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
2493
4539
|
const isNotFound = loaderResult.type === "not-found";
|
|
2494
4540
|
const isError = loaderResult.type === "error";
|
|
2495
4541
|
const isFallback = isNotFound || isError;
|
|
2496
|
-
const
|
|
4542
|
+
const syncData = isFallback ? {} : loaderResult.syncData;
|
|
4543
|
+
const deferredPromises = !isFallback && loaderResult.type === "data" ? loaderResult.deferredPromises : undefined;
|
|
4544
|
+
assertDeferredModeAllowed(route, deferredPromises);
|
|
2497
4545
|
const headers = loaderResult.headers;
|
|
2498
4546
|
const componentProps = {
|
|
2499
|
-
...
|
|
4547
|
+
...syncData,
|
|
4548
|
+
...deferredPromises ?? {},
|
|
2500
4549
|
params: ctx.params,
|
|
2501
4550
|
query: ctx.query,
|
|
2502
4551
|
path: ctx.path
|
|
@@ -2514,8 +4563,8 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
2514
4563
|
notFoundError = { message: loaderResult.error.message, data: loaderResult.error.data };
|
|
2515
4564
|
} else if (loaderResult.type === "error") {
|
|
2516
4565
|
errorDigest = computeErrorDigest(loaderResult.error);
|
|
2517
|
-
element = buildErrorElement(route.error ?? root.error, loaderResult.error, errorDigest);
|
|
2518
|
-
status =
|
|
4566
|
+
element = buildErrorElement(route.error ?? root.error, loaderResult.error, errorDigest, loaderResult.message, loaderResult.status);
|
|
4567
|
+
status = loaderResult.status;
|
|
2519
4568
|
} else {
|
|
2520
4569
|
element = buildElement(route, componentProps, root.route);
|
|
2521
4570
|
}
|
|
@@ -2534,12 +4583,14 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
2534
4583
|
element = withSSRRouterContext(element, ssrContext);
|
|
2535
4584
|
return {
|
|
2536
4585
|
componentProps,
|
|
4586
|
+
deferredPromises,
|
|
2537
4587
|
element,
|
|
2538
4588
|
errorDigest,
|
|
2539
4589
|
headData,
|
|
2540
4590
|
headers,
|
|
2541
4591
|
loader_ms,
|
|
2542
4592
|
notFoundError,
|
|
4593
|
+
syncData,
|
|
2543
4594
|
ssrContext,
|
|
2544
4595
|
status,
|
|
2545
4596
|
template
|
|
@@ -2562,7 +4613,7 @@ function renderForPath(route, params, root, origin, mode, basePath) {
|
|
|
2562
4613
|
if (prepared instanceof Response) {
|
|
2563
4614
|
return prepared;
|
|
2564
4615
|
}
|
|
2565
|
-
|
|
4616
|
+
useLogger2().set({
|
|
2566
4617
|
furin: {
|
|
2567
4618
|
render: mode,
|
|
2568
4619
|
route: route.pattern,
|
|
@@ -2571,17 +4622,27 @@ function renderForPath(route, params, root, origin, mode, basePath) {
|
|
|
2571
4622
|
...prepared.errorDigest ? { digest: prepared.errorDigest } : {}
|
|
2572
4623
|
}
|
|
2573
4624
|
});
|
|
2574
|
-
const {
|
|
4625
|
+
const { deferredPromises, element, headData, headers, status, syncData, template } = prepared;
|
|
2575
4626
|
const stream = await renderToReadableStream(element);
|
|
2576
4627
|
await stream.allReady;
|
|
2577
4628
|
const reactHtml = await streamToString(stream);
|
|
2578
4629
|
return {
|
|
2579
|
-
html: assembleHTML(template, headData, reactHtml,
|
|
4630
|
+
html: assembleHTML(template, headData, reactHtml, syncData),
|
|
2580
4631
|
headers,
|
|
4632
|
+
ndjson: await serializeLoaderDataNdjson(syncData, deferredPromises),
|
|
2581
4633
|
status
|
|
2582
4634
|
};
|
|
2583
4635
|
}, { route: route.pattern, render: mode });
|
|
2584
4636
|
}
|
|
4637
|
+
async function serializeLoaderDataNdjson(syncData, deferredPromises) {
|
|
4638
|
+
const payload = {
|
|
4639
|
+
...syncData,
|
|
4640
|
+
...deferredPromises ?? {}
|
|
4641
|
+
};
|
|
4642
|
+
const serialized = await toCrossJSONAsync(payload);
|
|
4643
|
+
return `${JSON.stringify(serialized)}
|
|
4644
|
+
`;
|
|
4645
|
+
}
|
|
2585
4646
|
async function prerenderSSG(route, params, root, origin, basePath) {
|
|
2586
4647
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
2587
4648
|
const cached = getSSGCache(resolvedPath);
|
|
@@ -2593,8 +4654,14 @@ async function prerenderSSG(route, params, root, origin, basePath) {
|
|
|
2593
4654
|
return renderResult;
|
|
2594
4655
|
}
|
|
2595
4656
|
const result = renderResult;
|
|
2596
|
-
const entry = {
|
|
4657
|
+
const entry = {
|
|
4658
|
+
cachedAt: Date.now(),
|
|
4659
|
+
html: result.html,
|
|
4660
|
+
ndjson: result.ndjson,
|
|
4661
|
+
status: result.status
|
|
4662
|
+
};
|
|
2597
4663
|
setSSGCache(resolvedPath, entry);
|
|
4664
|
+
autoInvalidateRegistry.registerLoaderTags(resolvedPath, route.tags);
|
|
2598
4665
|
return entry;
|
|
2599
4666
|
}
|
|
2600
4667
|
async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
@@ -2602,7 +4669,7 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
2602
4669
|
if (prepared instanceof Response) {
|
|
2603
4670
|
return prepared;
|
|
2604
4671
|
}
|
|
2605
|
-
|
|
4672
|
+
useLogger2().set({
|
|
2606
4673
|
furin: {
|
|
2607
4674
|
render: route.mode,
|
|
2608
4675
|
route: route.pattern,
|
|
@@ -2610,7 +4677,7 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
2610
4677
|
...prepared.errorDigest ? { digest: prepared.errorDigest } : {}
|
|
2611
4678
|
}
|
|
2612
4679
|
});
|
|
2613
|
-
const {
|
|
4680
|
+
const { deferredPromises, element, headData, headers, syncData, template } = prepared;
|
|
2614
4681
|
const { headPre, bodyPre, bodyPost } = splitTemplate(template);
|
|
2615
4682
|
let reactStream;
|
|
2616
4683
|
let status = prepared.status;
|
|
@@ -2622,18 +4689,18 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
2622
4689
|
shellErrored = true;
|
|
2623
4690
|
status = 500;
|
|
2624
4691
|
finalDigest = computeErrorDigest(shellError);
|
|
2625
|
-
|
|
4692
|
+
useLogger2().set({
|
|
2626
4693
|
furin: { render: route.mode, route: route.pattern, digest: finalDigest, phase: "shell" }
|
|
2627
4694
|
});
|
|
2628
4695
|
try {
|
|
2629
|
-
reactStream = await renderToReadableStream(withSSRRouterContext(buildErrorElement(route.error ?? root.error, shellError, finalDigest), prepared.ssrContext));
|
|
4696
|
+
reactStream = await renderToReadableStream(withSSRRouterContext(buildErrorElement(route.error ?? root.error, shellError, finalDigest, undefined, 500), prepared.ssrContext));
|
|
2630
4697
|
} catch {
|
|
2631
|
-
reactStream = await renderToReadableStream(withSSRRouterContext(buildErrorElement(undefined, shellError, finalDigest), prepared.ssrContext));
|
|
4698
|
+
reactStream = await renderToReadableStream(withSSRRouterContext(buildErrorElement(undefined, shellError, finalDigest, undefined, 500), prepared.ssrContext));
|
|
2632
4699
|
}
|
|
2633
4700
|
}
|
|
2634
|
-
const dataPayload = shellErrored ? {} : { ...
|
|
4701
|
+
const dataPayload = shellErrored ? {} : { ...syncData };
|
|
2635
4702
|
if (finalDigest) {
|
|
2636
|
-
dataPayload.__furinError = { digest: finalDigest };
|
|
4703
|
+
dataPayload.__furinError = { digest: finalDigest, status };
|
|
2637
4704
|
}
|
|
2638
4705
|
if (status === 404 && !shellErrored) {
|
|
2639
4706
|
dataPayload.__furinStatus = 404;
|
|
@@ -2641,12 +4708,18 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
2641
4708
|
dataPayload.__furinNotFound = prepared.notFoundError;
|
|
2642
4709
|
}
|
|
2643
4710
|
}
|
|
4711
|
+
if (dataPayload.__furinError !== undefined && dataPayload.__furinNotFound !== undefined) {
|
|
4712
|
+
throw new Error("[furin] internal invariant violated: __furinError and __furinNotFound were both set on the same SSR payload. Open a bug \u2014 these signals are mutually exclusive.");
|
|
4713
|
+
}
|
|
4714
|
+
const hasDeferred = !shellErrored && deferredPromises !== undefined;
|
|
4715
|
+
const deferredKeys = hasDeferred ? Object.keys(deferredPromises) : [];
|
|
4716
|
+
const deferredSetupScript = hasDeferred ? buildDeferredScript(deferredKeys) : "";
|
|
2644
4717
|
const dataScript = `<script id="__FURIN_DATA__" type="application/json">${safeJson(dataPayload)}</script>`;
|
|
2645
4718
|
const { readable, writable } = new TransformStream;
|
|
2646
4719
|
const writer = writable.getWriter();
|
|
2647
4720
|
const enc = new TextEncoder;
|
|
2648
4721
|
(async () => {
|
|
2649
|
-
await writer.write(enc.encode(headPre + headData + bodyPre));
|
|
4722
|
+
await writer.write(enc.encode(headPre + headData + deferredSetupScript + bodyPre));
|
|
2650
4723
|
const reader = reactStream.getReader();
|
|
2651
4724
|
for (;; ) {
|
|
2652
4725
|
const { done, value } = await reader.read();
|
|
@@ -2655,7 +4728,22 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
2655
4728
|
}
|
|
2656
4729
|
await writer.write(value);
|
|
2657
4730
|
}
|
|
2658
|
-
|
|
4731
|
+
const [earlyBodyPost, finalBodyPost] = hasDeferred ? splitBeforeBodyClose(bodyPost) : ["", bodyPost];
|
|
4732
|
+
await writer.write(enc.encode(dataScript + earlyBodyPost));
|
|
4733
|
+
if (hasDeferred) {
|
|
4734
|
+
await Promise.all(Object.entries(deferredPromises).map(async ([key, promise]) => {
|
|
4735
|
+
try {
|
|
4736
|
+
const resolvedValue = await promise;
|
|
4737
|
+
const chunk = toCrossJSON(resolvedValue);
|
|
4738
|
+
await writer.write(enc.encode(buildDeferredResolution(key, chunk, "resolve")));
|
|
4739
|
+
} catch (err) {
|
|
4740
|
+
const normalized = await serializeDeferredRejection(err);
|
|
4741
|
+
const chunk = toCrossJSON(normalized);
|
|
4742
|
+
await writer.write(enc.encode(buildDeferredResolution(key, chunk, "reject")));
|
|
4743
|
+
}
|
|
4744
|
+
}));
|
|
4745
|
+
}
|
|
4746
|
+
await writer.write(enc.encode(finalBodyPost));
|
|
2659
4747
|
await writer.close();
|
|
2660
4748
|
})().catch((err) => writer.abort(err));
|
|
2661
4749
|
return new Response(readable, {
|
|
@@ -2667,6 +4755,13 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
2667
4755
|
}
|
|
2668
4756
|
});
|
|
2669
4757
|
}
|
|
4758
|
+
function splitBeforeBodyClose(bodyPost) {
|
|
4759
|
+
const index = bodyPost.toLowerCase().lastIndexOf("</body>");
|
|
4760
|
+
if (index === -1) {
|
|
4761
|
+
return [bodyPost, ""];
|
|
4762
|
+
}
|
|
4763
|
+
return [bodyPost.slice(0, index), bodyPost.slice(index)];
|
|
4764
|
+
}
|
|
2670
4765
|
async function renderRootNotFound(root, request) {
|
|
2671
4766
|
const prodTemplate = getProductionTemplate();
|
|
2672
4767
|
let template;
|
|
@@ -2676,7 +4771,7 @@ async function renderRootNotFound(root, request) {
|
|
|
2676
4771
|
try {
|
|
2677
4772
|
template = await getDevTemplate(new URL(request.url).origin);
|
|
2678
4773
|
} catch (devTemplateErr) {
|
|
2679
|
-
|
|
4774
|
+
useLogger2().set({
|
|
2680
4775
|
furin: {
|
|
2681
4776
|
render: "not-found",
|
|
2682
4777
|
action: "dev_template_fallback",
|
|
@@ -2701,7 +4796,7 @@ async function renderRootNotFound(root, request) {
|
|
|
2701
4796
|
defaultPreloadDelay: 50,
|
|
2702
4797
|
defaultPreloadStaleTime: 30000
|
|
2703
4798
|
};
|
|
2704
|
-
|
|
4799
|
+
useLogger2().set({
|
|
2705
4800
|
furin: {
|
|
2706
4801
|
render: "not-found",
|
|
2707
4802
|
action: "catch_all",
|
|
@@ -2743,7 +4838,7 @@ function serveISRCacheHit(cached, ctx, route, params, cacheKey, revalidate, root
|
|
|
2743
4838
|
if (etag) {
|
|
2744
4839
|
ctx.set.headers.etag = etag;
|
|
2745
4840
|
}
|
|
2746
|
-
|
|
4841
|
+
useLogger2().set({
|
|
2747
4842
|
furin: { render: "isr", route: route.pattern, cache: isFresh ? "hit" : "stale" }
|
|
2748
4843
|
});
|
|
2749
4844
|
return cached.html;
|
|
@@ -2765,7 +4860,7 @@ async function renderISRNon200(prepared, route, ctx, root, errorDigest, renderSt
|
|
|
2765
4860
|
} catch (shellError) {
|
|
2766
4861
|
finalStatus = 500;
|
|
2767
4862
|
finalDigest = computeErrorDigest(shellError);
|
|
2768
|
-
|
|
4863
|
+
useLogger2().set({
|
|
2769
4864
|
furin: {
|
|
2770
4865
|
render: "isr",
|
|
2771
4866
|
route: route.pattern,
|
|
@@ -2774,23 +4869,23 @@ async function renderISRNon200(prepared, route, ctx, root, errorDigest, renderSt
|
|
|
2774
4869
|
phase: "shell"
|
|
2775
4870
|
}
|
|
2776
4871
|
});
|
|
2777
|
-
fallbackProps.__furinError = { digest: finalDigest };
|
|
4872
|
+
fallbackProps.__furinError = { digest: finalDigest, status: finalStatus };
|
|
2778
4873
|
fallbackProps.__furinStatus = 500;
|
|
2779
4874
|
try {
|
|
2780
|
-
reactStream = await renderToReadableStream(withSSRRouterContext(buildErrorElement(route.error ?? root.error, shellError, finalDigest), prepared.ssrContext));
|
|
4875
|
+
reactStream = await renderToReadableStream(withSSRRouterContext(buildErrorElement(route.error ?? root.error, shellError, finalDigest, undefined, 500), prepared.ssrContext));
|
|
2781
4876
|
} catch {
|
|
2782
|
-
reactStream = await renderToReadableStream(withSSRRouterContext(buildErrorElement(undefined, shellError, finalDigest), prepared.ssrContext));
|
|
4877
|
+
reactStream = await renderToReadableStream(withSSRRouterContext(buildErrorElement(undefined, shellError, finalDigest, undefined, 500), prepared.ssrContext));
|
|
2783
4878
|
}
|
|
2784
4879
|
}
|
|
2785
4880
|
if (!fallbackProps.__furinError && errorDigest) {
|
|
2786
|
-
fallbackProps.__furinError = { digest: errorDigest };
|
|
4881
|
+
fallbackProps.__furinError = { digest: errorDigest, status };
|
|
2787
4882
|
}
|
|
2788
4883
|
await reactStream.allReady;
|
|
2789
4884
|
const reactHtml = await streamToString(reactStream);
|
|
2790
4885
|
const html = assembleHTML(template, headData, reactHtml, fallbackProps);
|
|
2791
4886
|
const generatedAt = Date.now();
|
|
2792
4887
|
const renderMs = generatedAt - renderStart;
|
|
2793
|
-
|
|
4888
|
+
useLogger2().set({
|
|
2794
4889
|
furin: {
|
|
2795
4890
|
render: "isr",
|
|
2796
4891
|
route: route.pattern,
|
|
@@ -2822,16 +4917,16 @@ async function handleISR(route, ctx, root, buildId = "") {
|
|
|
2822
4917
|
if (prepared instanceof Response) {
|
|
2823
4918
|
return prepared;
|
|
2824
4919
|
}
|
|
2825
|
-
const {
|
|
4920
|
+
const { element, headData, syncData, template, status, errorDigest } = prepared;
|
|
2826
4921
|
if (status !== 200) {
|
|
2827
4922
|
return renderISRNon200(prepared, route, ctx, root, errorDigest, renderStart, buildId);
|
|
2828
4923
|
}
|
|
2829
4924
|
const stream = await renderToReadableStream(element);
|
|
2830
4925
|
await stream.allReady;
|
|
2831
4926
|
const reactHtml = await streamToString(stream);
|
|
2832
|
-
const html = assembleHTML(template, headData, reactHtml,
|
|
4927
|
+
const html = assembleHTML(template, headData, reactHtml, syncData);
|
|
2833
4928
|
const generatedAt = Date.now();
|
|
2834
|
-
|
|
4929
|
+
useLogger2().set({
|
|
2835
4930
|
furin: {
|
|
2836
4931
|
render: "isr",
|
|
2837
4932
|
route: route.pattern,
|
|
@@ -2840,6 +4935,7 @@ async function handleISR(route, ctx, root, buildId = "") {
|
|
|
2840
4935
|
}
|
|
2841
4936
|
});
|
|
2842
4937
|
setISRCache(cacheKey, { html, generatedAt, revalidate });
|
|
4938
|
+
autoInvalidateRegistry.registerLoaderTags(cacheKey, route.tags);
|
|
2843
4939
|
const etag = buildId ? `"${buildId}:${generatedAt}"` : null;
|
|
2844
4940
|
ctx.set.headers["content-type"] = "text/html; charset=utf-8";
|
|
2845
4941
|
ctx.set.headers["cache-control"] = isrCacheControl(true, revalidate);
|
|
@@ -2859,12 +4955,31 @@ async function warmSSGCache(routes, root, origin) {
|
|
|
2859
4955
|
}
|
|
2860
4956
|
});
|
|
2861
4957
|
warmupLogger.emit();
|
|
2862
|
-
const
|
|
2863
|
-
for (const route of targets) {
|
|
2864
|
-
let paramSets;
|
|
4958
|
+
const staticParamsResults = await mapWithConcurrency(targets, SSG_WARM_CONCURRENCY, async (route) => {
|
|
2865
4959
|
try {
|
|
2866
|
-
paramSets = await route.page.staticParams?.() ?? [];
|
|
4960
|
+
const paramSets = await route.page.staticParams?.() ?? [];
|
|
4961
|
+
return { route, paramSets };
|
|
2867
4962
|
} catch (err) {
|
|
4963
|
+
return { error: err, route };
|
|
4964
|
+
}
|
|
4965
|
+
});
|
|
4966
|
+
const tasks = [];
|
|
4967
|
+
for (const result of staticParamsResults) {
|
|
4968
|
+
if ("error" in result) {
|
|
4969
|
+
const errorLogger = createLogger({});
|
|
4970
|
+
errorLogger.set({
|
|
4971
|
+
furin: {
|
|
4972
|
+
render: "ssg",
|
|
4973
|
+
action: "warmup_failed",
|
|
4974
|
+
route: result.route.pattern
|
|
4975
|
+
}
|
|
4976
|
+
});
|
|
4977
|
+
errorLogger.error(result.error instanceof Error ? result.error : new Error(String(result.error)));
|
|
4978
|
+
errorLogger.emit();
|
|
4979
|
+
continue;
|
|
4980
|
+
}
|
|
4981
|
+
const { route, paramSets } = result;
|
|
4982
|
+
if (!Array.isArray(paramSets)) {
|
|
2868
4983
|
const errorLogger = createLogger({});
|
|
2869
4984
|
errorLogger.set({
|
|
2870
4985
|
furin: {
|
|
@@ -2873,7 +4988,7 @@ async function warmSSGCache(routes, root, origin) {
|
|
|
2873
4988
|
route: route.pattern
|
|
2874
4989
|
}
|
|
2875
4990
|
});
|
|
2876
|
-
errorLogger.error(
|
|
4991
|
+
errorLogger.error(new Error(`staticParams() for "${route.pattern}" returned a non-array value`));
|
|
2877
4992
|
errorLogger.emit();
|
|
2878
4993
|
continue;
|
|
2879
4994
|
}
|
|
@@ -2948,6 +5063,7 @@ function revalidateInBackground(route, params, cacheKey, revalidate, root, origi
|
|
|
2948
5063
|
}
|
|
2949
5064
|
var SSG_WARM_CONCURRENCY = 4, pendingRevalidations;
|
|
2950
5065
|
var init_render = __esm(() => {
|
|
5066
|
+
init_development();
|
|
2951
5067
|
init_not_found();
|
|
2952
5068
|
init_router_provider();
|
|
2953
5069
|
init_assemble();
|
|
@@ -2957,6 +5073,7 @@ var init_render = __esm(() => {
|
|
|
2957
5073
|
init_shell();
|
|
2958
5074
|
init_template();
|
|
2959
5075
|
init_loaders();
|
|
5076
|
+
init_registry();
|
|
2960
5077
|
init_context_logger();
|
|
2961
5078
|
init_shell();
|
|
2962
5079
|
pendingRevalidations = new Set;
|
|
@@ -2991,6 +5108,10 @@ function createDevLoaderCache(name) {
|
|
|
2991
5108
|
name,
|
|
2992
5109
|
onDelete: (key, entry) => {
|
|
2993
5110
|
unindexEntryDependencies(key, entry.dependencies);
|
|
5111
|
+
const urlPath = urlPathFromCacheKey(key);
|
|
5112
|
+
if (urlPath) {
|
|
5113
|
+
autoInvalidateRegistry.unregisterPath(urlPath);
|
|
5114
|
+
}
|
|
2994
5115
|
},
|
|
2995
5116
|
onSet: (key, entry, previous) => {
|
|
2996
5117
|
if (previous) {
|
|
@@ -3077,6 +5198,7 @@ function getAllDevSSGLoaderEntries() {
|
|
|
3077
5198
|
}
|
|
3078
5199
|
var sourceFileToCacheKeys, devISRLoaderCache, devSSGLoaderCache, isrHandle, ssgHandle;
|
|
3079
5200
|
var init_dev_cache = __esm(() => {
|
|
5201
|
+
init_registry();
|
|
3080
5202
|
init_cache();
|
|
3081
5203
|
sourceFileToCacheKeys = new Map;
|
|
3082
5204
|
devISRLoaderCache = createDevLoaderCache("render:dev-isr-loader");
|
|
@@ -3087,47 +5209,6 @@ var init_dev_cache = __esm(() => {
|
|
|
3087
5209
|
registerCacheInvalidator(devSSGLoaderCache);
|
|
3088
5210
|
});
|
|
3089
5211
|
|
|
3090
|
-
// src/utils.ts
|
|
3091
|
-
function isFurinPage(value) {
|
|
3092
|
-
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_PAGE";
|
|
3093
|
-
}
|
|
3094
|
-
function isFurinRoute(value) {
|
|
3095
|
-
return typeof value === "object" && value !== null && "__type" in value && value.__type === "FURIN_ROUTE";
|
|
3096
|
-
}
|
|
3097
|
-
function collectRouteChainFromRoute(route) {
|
|
3098
|
-
const chain = [];
|
|
3099
|
-
let current = route;
|
|
3100
|
-
while (current) {
|
|
3101
|
-
chain.unshift(current);
|
|
3102
|
-
current = current.parent;
|
|
3103
|
-
}
|
|
3104
|
-
return chain;
|
|
3105
|
-
}
|
|
3106
|
-
function hasCycle(route) {
|
|
3107
|
-
const visited = new Set;
|
|
3108
|
-
let current = route;
|
|
3109
|
-
while (current) {
|
|
3110
|
-
if (visited.has(current)) {
|
|
3111
|
-
return true;
|
|
3112
|
-
}
|
|
3113
|
-
visited.add(current);
|
|
3114
|
-
current = current.parent;
|
|
3115
|
-
}
|
|
3116
|
-
return false;
|
|
3117
|
-
}
|
|
3118
|
-
function validateRouteChain(chain, root, pagePath) {
|
|
3119
|
-
const hasRoot = chain.some((r) => r === root);
|
|
3120
|
-
if (!hasRoot) {
|
|
3121
|
-
const location = pagePath ? `in ${pagePath}` : "";
|
|
3122
|
-
throw new Error(`[furin] Page ${location} must inherit from root route. ` + 'Add: import { route } from "./root"; and use route.page() or set parent: route');
|
|
3123
|
-
}
|
|
3124
|
-
for (const route of chain) {
|
|
3125
|
-
if (hasCycle(route)) {
|
|
3126
|
-
throw new Error("[furin] Cycle detected in route chain. A route cannot be its own ancestor.");
|
|
3127
|
-
}
|
|
3128
|
-
}
|
|
3129
|
-
}
|
|
3130
|
-
|
|
3131
5212
|
// src/router.ts
|
|
3132
5213
|
var exports_router = {};
|
|
3133
5214
|
__export(exports_router, {
|
|
@@ -3135,12 +5216,17 @@ __export(exports_router, {
|
|
|
3135
5216
|
scanPages: () => scanPages,
|
|
3136
5217
|
resolveMode: () => resolveMode,
|
|
3137
5218
|
refreshLayoutChain: () => refreshLayoutChain,
|
|
5219
|
+
rebuildDevRoute: () => rebuildDevRoute,
|
|
3138
5220
|
queryDefaultRedirectHook: () => queryDefaultRedirectHook,
|
|
5221
|
+
parseDataEndpointPath: () => parseDataEndpointPath,
|
|
3139
5222
|
mergeRouteSchemas: () => mergeRouteSchemas,
|
|
3140
5223
|
loadProdRoutes: () => loadProdRoutes,
|
|
3141
5224
|
filePathToPattern: () => filePathToPattern,
|
|
5225
|
+
detectQueryDefaultRedirect: () => detectQueryDefaultRedirect,
|
|
3142
5226
|
createRoutePlugin: () => createRoutePlugin,
|
|
3143
|
-
|
|
5227
|
+
createDataEndpoint: () => createDataEndpoint,
|
|
5228
|
+
computeRouteDependencies: () => computeRouteDependencies,
|
|
5229
|
+
collectRouteTags: () => collectRouteTags
|
|
3144
5230
|
});
|
|
3145
5231
|
import { existsSync } from "fs";
|
|
3146
5232
|
import { readdir } from "fs/promises";
|
|
@@ -3154,6 +5240,18 @@ function isModuleNotFoundError(err) {
|
|
|
3154
5240
|
const code = typeof err === "string" ? undefined : err.code;
|
|
3155
5241
|
return code === "ENOENT" || code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || msg.includes("cannot find module") || msg.includes("module not found") || msg.includes("no such file or directory");
|
|
3156
5242
|
}
|
|
5243
|
+
function collectRouteTags(routeChain, page) {
|
|
5244
|
+
const tags = new Set;
|
|
5245
|
+
for (const route of routeChain) {
|
|
5246
|
+
for (const tag of route.tags ?? []) {
|
|
5247
|
+
tags.add(tag);
|
|
5248
|
+
}
|
|
5249
|
+
}
|
|
5250
|
+
for (const tag of page?.tags ?? []) {
|
|
5251
|
+
tags.add(tag);
|
|
5252
|
+
}
|
|
5253
|
+
return tags.size > 0 ? [...tags] : undefined;
|
|
5254
|
+
}
|
|
3157
5255
|
function loadProdRoutes(ctx) {
|
|
3158
5256
|
const rootMod = ctx.modules[ctx.rootPath];
|
|
3159
5257
|
const rootExport = rootMod.route ?? rootMod.default;
|
|
@@ -3198,7 +5296,8 @@ function loadProdRoutes(ctx) {
|
|
|
3198
5296
|
mode,
|
|
3199
5297
|
segmentBoundaries: boundaries,
|
|
3200
5298
|
error,
|
|
3201
|
-
notFound: notFound2
|
|
5299
|
+
notFound: notFound2,
|
|
5300
|
+
tags: collectRouteTags(routeChain, page)
|
|
3202
5301
|
});
|
|
3203
5302
|
}
|
|
3204
5303
|
return { root, routes };
|
|
@@ -3222,8 +5321,10 @@ async function scanRootLayout(pagesDir) {
|
|
|
3222
5321
|
if (!rootExport.layout) {
|
|
3223
5322
|
throw new Error("[furin] root.tsx: createRoute() has no layout.");
|
|
3224
5323
|
}
|
|
3225
|
-
const notFoundEntry = await
|
|
3226
|
-
|
|
5324
|
+
const [notFoundEntry, errorEntry] = await Promise.all([
|
|
5325
|
+
loadConventionComponent(pagesDir, "not-found"),
|
|
5326
|
+
loadConventionComponent(pagesDir, "error")
|
|
5327
|
+
]);
|
|
3227
5328
|
return {
|
|
3228
5329
|
path: rootPath,
|
|
3229
5330
|
route: rootExport,
|
|
@@ -3264,9 +5365,11 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
3264
5365
|
if (fileName.startsWith("_") || fileName === "root" || isConventionFileName(fileName)) {
|
|
3265
5366
|
continue;
|
|
3266
5367
|
}
|
|
3267
|
-
const notFound2
|
|
3268
|
-
|
|
3269
|
-
|
|
5368
|
+
const [notFound2, errorComponent, segmentBoundaries] = await Promise.all([
|
|
5369
|
+
resolveNearestConvention(absolutePath, pagesDir, "not-found", notFoundCache, root.notFound),
|
|
5370
|
+
resolveNearestConvention(absolutePath, pagesDir, "error", errorCache, root.error),
|
|
5371
|
+
collectSegmentBoundaries(absolutePath, pagesDir, notFoundCache, errorCache)
|
|
5372
|
+
]);
|
|
3270
5373
|
if (IS_DEV) {
|
|
3271
5374
|
const devRoute = await buildDevRoute(absolutePath, relativePath, root);
|
|
3272
5375
|
devRoute.notFound = notFound2;
|
|
@@ -3291,7 +5394,8 @@ async function scanPageFiles(pagesDir, root) {
|
|
|
3291
5394
|
mode: resolveMode(page, routeChain),
|
|
3292
5395
|
notFound: notFound2,
|
|
3293
5396
|
error: errorComponent,
|
|
3294
|
-
segmentBoundaries
|
|
5397
|
+
segmentBoundaries,
|
|
5398
|
+
tags: collectRouteTags(routeChain, page)
|
|
3295
5399
|
});
|
|
3296
5400
|
}
|
|
3297
5401
|
return routes;
|
|
@@ -3311,14 +5415,16 @@ async function collectSegmentBoundaries(pageAbsolutePath, pagesDir, notFoundCach
|
|
|
3311
5415
|
const boundaries = [];
|
|
3312
5416
|
for (let depth = 0;depth < dirs.length; depth++) {
|
|
3313
5417
|
const dir = dirs[depth];
|
|
3314
|
-
|
|
3315
|
-
errorCache.
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
5418
|
+
const [errorEntry, notFoundEntry] = await Promise.all([
|
|
5419
|
+
errorCache.has(dir) ? Promise.resolve(errorCache.get(dir)) : loadConventionComponent(dir, "error").then((r) => {
|
|
5420
|
+
errorCache.set(dir, r);
|
|
5421
|
+
return r;
|
|
5422
|
+
}),
|
|
5423
|
+
notFoundCache.has(dir) ? Promise.resolve(notFoundCache.get(dir)) : loadConventionComponent(dir, "not-found").then((r) => {
|
|
5424
|
+
notFoundCache.set(dir, r);
|
|
5425
|
+
return r;
|
|
5426
|
+
})
|
|
5427
|
+
]);
|
|
3322
5428
|
if (errorEntry || notFoundEntry) {
|
|
3323
5429
|
boundaries.push({
|
|
3324
5430
|
path: dir,
|
|
@@ -3371,11 +5477,11 @@ async function buildDevRoute(absolutePath, relativePath, root) {
|
|
|
3371
5477
|
mode: page ? resolveMode(page, routeChain) : "ssr",
|
|
3372
5478
|
page: page ?? devStubPage,
|
|
3373
5479
|
routeChain,
|
|
5480
|
+
tags: collectRouteTags(routeChain, page),
|
|
3374
5481
|
segmentBoundaries: []
|
|
3375
5482
|
};
|
|
3376
5483
|
}
|
|
3377
|
-
function
|
|
3378
|
-
const resolvedQuery = query;
|
|
5484
|
+
function detectQueryDefaultRedirect(request, resolvedQuery) {
|
|
3379
5485
|
const queryKeys = Object.keys(resolvedQuery);
|
|
3380
5486
|
if (queryKeys.length === 0) {
|
|
3381
5487
|
return;
|
|
@@ -3397,7 +5503,29 @@ function queryDefaultRedirectHook({ request, query, status, set }) {
|
|
|
3397
5503
|
url.searchParams.set(k, String(v));
|
|
3398
5504
|
}
|
|
3399
5505
|
}
|
|
3400
|
-
|
|
5506
|
+
return url.pathname + url.search;
|
|
5507
|
+
}
|
|
5508
|
+
function parseDataEndpointPath(rawPath) {
|
|
5509
|
+
if (rawPath.includes("://") || rawPath.startsWith("//")) {
|
|
5510
|
+
return;
|
|
5511
|
+
}
|
|
5512
|
+
let url;
|
|
5513
|
+
try {
|
|
5514
|
+
url = new URL(rawPath, "http://localhost");
|
|
5515
|
+
} catch {
|
|
5516
|
+
return;
|
|
5517
|
+
}
|
|
5518
|
+
if (url.origin !== "http://localhost") {
|
|
5519
|
+
return;
|
|
5520
|
+
}
|
|
5521
|
+
return { url, pathname: url.pathname };
|
|
5522
|
+
}
|
|
5523
|
+
function queryDefaultRedirectHook({ request, query, status, set }) {
|
|
5524
|
+
const location = detectQueryDefaultRedirect(request, query);
|
|
5525
|
+
if (!location) {
|
|
5526
|
+
return;
|
|
5527
|
+
}
|
|
5528
|
+
set.headers.location = location;
|
|
3401
5529
|
return status("Found");
|
|
3402
5530
|
}
|
|
3403
5531
|
function collectIntermediateLayoutDirs(pagePath, rootPath) {
|
|
@@ -3454,12 +5582,12 @@ async function refreshLayoutChain(chain, pagePath, rootPath, importFn) {
|
|
|
3454
5582
|
const ctx = getCompileContext();
|
|
3455
5583
|
const timestamp = Date.now();
|
|
3456
5584
|
const layoutDirs = collectIntermediateLayoutDirs(pagePath, rootPath);
|
|
5585
|
+
const freshMods = await Promise.all(layoutDirs.map((layoutDir) => importFreshLayoutRouteModule(layoutDir, timestamp, resolveImport, ctx)));
|
|
3457
5586
|
let chainIdx = 1;
|
|
3458
|
-
for (const
|
|
5587
|
+
for (const freshMod of freshMods) {
|
|
3459
5588
|
if (chainIdx >= chain.length) {
|
|
3460
5589
|
break;
|
|
3461
5590
|
}
|
|
3462
|
-
const freshMod = await importFreshLayoutRouteModule(layoutDir, timestamp, resolveImport, ctx);
|
|
3463
5591
|
if (!freshMod) {
|
|
3464
5592
|
continue;
|
|
3465
5593
|
}
|
|
@@ -3467,6 +5595,15 @@ async function refreshLayoutChain(chain, pagePath, rootPath, importFn) {
|
|
|
3467
5595
|
chainIdx++;
|
|
3468
5596
|
}
|
|
3469
5597
|
}
|
|
5598
|
+
function rebuildDevRoute(base, page, chain) {
|
|
5599
|
+
return {
|
|
5600
|
+
...base,
|
|
5601
|
+
page,
|
|
5602
|
+
routeChain: chain,
|
|
5603
|
+
mode: resolveMode(page, chain),
|
|
5604
|
+
tags: collectRouteTags(chain, page)
|
|
5605
|
+
};
|
|
5606
|
+
}
|
|
3470
5607
|
async function handleDevRequest(route, ctx, root) {
|
|
3471
5608
|
try {
|
|
3472
5609
|
let currentRoot = root;
|
|
@@ -3484,7 +5621,7 @@ async function handleDevRequest(route, ctx, root) {
|
|
|
3484
5621
|
chain[0].layout = currentRoot.route.layout;
|
|
3485
5622
|
chain[0].loader = currentRoot.route.loader;
|
|
3486
5623
|
}
|
|
3487
|
-
const refreshedRoute =
|
|
5624
|
+
const refreshedRoute = rebuildDevRoute(route, page, chain);
|
|
3488
5625
|
if (refreshedRoute.mode === "isr") {
|
|
3489
5626
|
return renderDevISRWithLoaderCache(refreshedRoute, ctx, currentRoot);
|
|
3490
5627
|
}
|
|
@@ -3504,23 +5641,25 @@ async function renderDevISRWithLoaderCache(route, ctx, root) {
|
|
|
3504
5641
|
if (cached && isDevLoaderCacheValid(cached)) {
|
|
3505
5642
|
const precomputed = {
|
|
3506
5643
|
type: "data",
|
|
3507
|
-
|
|
5644
|
+
syncData: cached.loaderData,
|
|
5645
|
+
deferredPromises: undefined,
|
|
3508
5646
|
headers: cached.headers
|
|
3509
5647
|
};
|
|
3510
5648
|
return renderSSR(route, ctx, root, precomputed);
|
|
3511
5649
|
}
|
|
3512
|
-
const result = await runLoaders(route, ctx
|
|
5650
|
+
const result = await runLoaders(route, ctx);
|
|
3513
5651
|
if (result.type === "data") {
|
|
3514
5652
|
const revalidate = route.page._route.revalidate ?? 60;
|
|
3515
5653
|
const entry = {
|
|
3516
5654
|
dependencies: computeRouteDependencies(route.path, root.path),
|
|
3517
5655
|
generatedAt: Date.now(),
|
|
3518
5656
|
headers: result.headers,
|
|
3519
|
-
loaderData: result.
|
|
5657
|
+
loaderData: result.syncData,
|
|
3520
5658
|
mode: "isr",
|
|
3521
5659
|
revalidate
|
|
3522
5660
|
};
|
|
3523
5661
|
setDevISRLoaderCache(cacheKey, entry);
|
|
5662
|
+
autoInvalidateRegistry.registerLoaderTags(resolvePath(route.pattern, ctx.params ?? {}), route.tags);
|
|
3524
5663
|
}
|
|
3525
5664
|
return renderSSR(route, ctx, root, result);
|
|
3526
5665
|
}
|
|
@@ -3530,22 +5669,24 @@ async function renderDevSSGWithLoaderCache(route, ctx, root) {
|
|
|
3530
5669
|
if (cached && isDevLoaderCacheValid(cached)) {
|
|
3531
5670
|
const precomputed = {
|
|
3532
5671
|
type: "data",
|
|
3533
|
-
|
|
5672
|
+
syncData: cached.loaderData,
|
|
5673
|
+
deferredPromises: undefined,
|
|
3534
5674
|
headers: cached.headers
|
|
3535
5675
|
};
|
|
3536
5676
|
return renderSSR(route, ctx, root, precomputed);
|
|
3537
5677
|
}
|
|
3538
|
-
const result = await runLoaders(route, ctx
|
|
5678
|
+
const result = await runLoaders(route, ctx);
|
|
3539
5679
|
if (result.type === "data") {
|
|
3540
5680
|
const entry = {
|
|
3541
5681
|
dependencies: computeRouteDependencies(route.path, root.path),
|
|
3542
5682
|
generatedAt: Date.now(),
|
|
3543
5683
|
headers: result.headers,
|
|
3544
|
-
loaderData: result.
|
|
5684
|
+
loaderData: result.syncData,
|
|
3545
5685
|
mode: "ssg",
|
|
3546
5686
|
revalidate: Number.POSITIVE_INFINITY
|
|
3547
5687
|
};
|
|
3548
5688
|
setDevSSGLoaderCache(cacheKey, entry);
|
|
5689
|
+
autoInvalidateRegistry.registerLoaderTags(resolvePath(route.pattern, ctx.params ?? {}), route.tags);
|
|
3549
5690
|
}
|
|
3550
5691
|
return renderSSR(route, ctx, root, result);
|
|
3551
5692
|
}
|
|
@@ -3581,7 +5722,7 @@ async function handleSSGRequest(route, ctx, root, buildId) {
|
|
|
3581
5722
|
return entry.html;
|
|
3582
5723
|
}
|
|
3583
5724
|
function mergeRouteSchemas(routeChain, key) {
|
|
3584
|
-
const schemas = routeChain.
|
|
5725
|
+
const schemas = routeChain.flatMap((r) => r[key] ? [r[key]] : []);
|
|
3585
5726
|
if (schemas.length === 0) {
|
|
3586
5727
|
return;
|
|
3587
5728
|
}
|
|
@@ -3628,15 +5769,18 @@ function createRoutePlugin(route, root, buildId = "") {
|
|
|
3628
5769
|
async function collectPageFilePaths(dir) {
|
|
3629
5770
|
const files = [];
|
|
3630
5771
|
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name));
|
|
3631
|
-
|
|
5772
|
+
const resolved = await mapWithConcurrency(entries, DIR_SCAN_CONCURRENCY, async (entry) => {
|
|
3632
5773
|
const absolutePath = join(dir, entry.name);
|
|
3633
5774
|
if (entry.isDirectory()) {
|
|
3634
|
-
|
|
3635
|
-
continue;
|
|
5775
|
+
return await collectPageFilePaths(absolutePath);
|
|
3636
5776
|
}
|
|
3637
5777
|
if (entry.isFile()) {
|
|
3638
|
-
|
|
5778
|
+
return [absolutePath];
|
|
3639
5779
|
}
|
|
5780
|
+
return [];
|
|
5781
|
+
});
|
|
5782
|
+
for (const chunk of resolved) {
|
|
5783
|
+
files.push(...chunk);
|
|
3640
5784
|
}
|
|
3641
5785
|
return files;
|
|
3642
5786
|
}
|
|
@@ -3677,14 +5821,250 @@ function filePathToPattern(path) {
|
|
|
3677
5821
|
}
|
|
3678
5822
|
return `/${segments.join("/")}`;
|
|
3679
5823
|
}
|
|
3680
|
-
|
|
5824
|
+
function escapeRegExpChar(ch) {
|
|
5825
|
+
return REGEX_META_CHARS_RE.test(ch) ? `\\${ch}` : ch;
|
|
5826
|
+
}
|
|
5827
|
+
function routeSpecificity(pattern) {
|
|
5828
|
+
let score = 0;
|
|
5829
|
+
for (const segment of pattern.split("/")) {
|
|
5830
|
+
if (segment.length === 0) {
|
|
5831
|
+
continue;
|
|
5832
|
+
}
|
|
5833
|
+
if (segment === "*") {
|
|
5834
|
+
score += 1;
|
|
5835
|
+
} else if (segment.startsWith(":")) {
|
|
5836
|
+
score += 2;
|
|
5837
|
+
} else {
|
|
5838
|
+
score += 3;
|
|
5839
|
+
}
|
|
5840
|
+
}
|
|
5841
|
+
return score;
|
|
5842
|
+
}
|
|
5843
|
+
function buildRouteRegex(pattern) {
|
|
5844
|
+
const paramNames = [];
|
|
5845
|
+
let source = "";
|
|
5846
|
+
let i = 0;
|
|
5847
|
+
while (i < pattern.length) {
|
|
5848
|
+
if (pattern[i] === ":") {
|
|
5849
|
+
const start = ++i;
|
|
5850
|
+
while (i < pattern.length && pattern[i] !== "/") {
|
|
5851
|
+
i++;
|
|
5852
|
+
}
|
|
5853
|
+
paramNames.push(pattern.slice(start, i));
|
|
5854
|
+
source += "([^/]+)";
|
|
5855
|
+
} else if (pattern[i] === "*") {
|
|
5856
|
+
paramNames.push("*");
|
|
5857
|
+
source += "(.*)";
|
|
5858
|
+
i++;
|
|
5859
|
+
} else {
|
|
5860
|
+
const ch = pattern[i];
|
|
5861
|
+
if (ch !== undefined) {
|
|
5862
|
+
source += escapeRegExpChar(ch);
|
|
5863
|
+
}
|
|
5864
|
+
i++;
|
|
5865
|
+
}
|
|
5866
|
+
}
|
|
5867
|
+
return { regex: new RegExp(`^${source}$`), paramNames };
|
|
5868
|
+
}
|
|
5869
|
+
function applySchemaDefaults(schema, values) {
|
|
5870
|
+
if (!schema || typeof schema !== "object") {
|
|
5871
|
+
return values;
|
|
5872
|
+
}
|
|
5873
|
+
const s = schema;
|
|
5874
|
+
if (s.type !== "object" || !s.properties || typeof s.properties !== "object") {
|
|
5875
|
+
return values;
|
|
5876
|
+
}
|
|
5877
|
+
const result = { ...values };
|
|
5878
|
+
const properties = s.properties;
|
|
5879
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
5880
|
+
if (!(key in result) && propSchema && typeof propSchema === "object" && "default" in propSchema) {
|
|
5881
|
+
result[key] = propSchema.default;
|
|
5882
|
+
}
|
|
5883
|
+
}
|
|
5884
|
+
return result;
|
|
5885
|
+
}
|
|
5886
|
+
function createDataEndpoint(routes) {
|
|
5887
|
+
const plugin = new Elysia2;
|
|
5888
|
+
plugin.get("/_furin/data", async (ctx) => {
|
|
5889
|
+
const rawPath = ctx.query.path;
|
|
5890
|
+
if (!rawPath || typeof rawPath !== "string") {
|
|
5891
|
+
return new Response("Missing required query param: path", { status: 400 });
|
|
5892
|
+
}
|
|
5893
|
+
const parsed = parseDataEndpointPath(rawPath);
|
|
5894
|
+
if (!parsed) {
|
|
5895
|
+
return new Response("Invalid path", { status: 400 });
|
|
5896
|
+
}
|
|
5897
|
+
const { url, pathname } = parsed;
|
|
5898
|
+
const wideEventLog = useLogger2();
|
|
5899
|
+
wideEventLog.set({ path: rawPath });
|
|
5900
|
+
const matched = routes.reduce((acc, route) => {
|
|
5901
|
+
const { regex, paramNames } = buildRouteRegex(route.pattern);
|
|
5902
|
+
const m = regex.exec(pathname);
|
|
5903
|
+
if (!m) {
|
|
5904
|
+
return acc;
|
|
5905
|
+
}
|
|
5906
|
+
const score = routeSpecificity(route.pattern);
|
|
5907
|
+
if (acc && acc.score >= score) {
|
|
5908
|
+
return acc;
|
|
5909
|
+
}
|
|
5910
|
+
const params = {};
|
|
5911
|
+
for (let i = 0;i < paramNames.length; i++) {
|
|
5912
|
+
const name = paramNames[i];
|
|
5913
|
+
if (name !== undefined) {
|
|
5914
|
+
params[name] = m[i + 1] ?? "";
|
|
5915
|
+
}
|
|
5916
|
+
}
|
|
5917
|
+
return { route, params, score };
|
|
5918
|
+
}, null);
|
|
5919
|
+
if (!matched) {
|
|
5920
|
+
return new Response("Route not found", { status: 404 });
|
|
5921
|
+
}
|
|
5922
|
+
wideEventLog.set({ routePattern: matched.route.pattern });
|
|
5923
|
+
const syntheticRequest = new Request(new URL(pathname + url.search, ctx.request.url));
|
|
5924
|
+
const syntheticSet = { headers: {}, status: 200 };
|
|
5925
|
+
const syntheticCtx = {
|
|
5926
|
+
request: syntheticRequest,
|
|
5927
|
+
params: matched.params,
|
|
5928
|
+
query: Object.fromEntries(url.searchParams),
|
|
5929
|
+
set: syntheticSet,
|
|
5930
|
+
headers: ctx.headers,
|
|
5931
|
+
cookie: ctx.cookie,
|
|
5932
|
+
path: pathname,
|
|
5933
|
+
redirect: (location, status) => new Response(null, { status: status ?? 302, headers: { location } }),
|
|
5934
|
+
status: (code) => new Response(null, { status: code })
|
|
5935
|
+
};
|
|
5936
|
+
const mergedParams = mergeRouteSchemas(matched.route.routeChain, "params");
|
|
5937
|
+
const mergedQuery = mergeRouteSchemas(matched.route.routeChain, "query");
|
|
5938
|
+
syntheticCtx.params = applySchemaDefaults(mergedParams, syntheticCtx.params);
|
|
5939
|
+
syntheticCtx.query = applySchemaDefaults(mergedQuery, syntheticCtx.query);
|
|
5940
|
+
if (mergedQuery) {
|
|
5941
|
+
const redirectLocation = detectQueryDefaultRedirect(syntheticRequest, syntheticCtx.query);
|
|
5942
|
+
if (redirectLocation) {
|
|
5943
|
+
const serialized2 = await toCrossJSONAsync({ __furinRedirect: redirectLocation });
|
|
5944
|
+
return new Response(`${JSON.stringify(serialized2)}
|
|
5945
|
+
`, {
|
|
5946
|
+
headers: { "content-type": "application/x-ndjson" }
|
|
5947
|
+
});
|
|
5948
|
+
}
|
|
5949
|
+
}
|
|
5950
|
+
const result = await runLoaders(matched.route, syntheticCtx);
|
|
5951
|
+
if (result.type === "data") {
|
|
5952
|
+
autoInvalidateRegistry.registerLoaderTags(pathname, matched.route.tags);
|
|
5953
|
+
}
|
|
5954
|
+
if (result.type === "redirect") {
|
|
5955
|
+
const redirectUrl = new URL(result.response.headers.get("location") ?? "/", ctx.request.url);
|
|
5956
|
+
const serialized2 = await toCrossJSONAsync({
|
|
5957
|
+
__furinRedirect: redirectUrl.pathname + redirectUrl.search
|
|
5958
|
+
});
|
|
5959
|
+
return new Response(`${JSON.stringify(serialized2)}
|
|
5960
|
+
`, {
|
|
5961
|
+
headers: { "content-type": "application/x-ndjson" }
|
|
5962
|
+
});
|
|
5963
|
+
}
|
|
5964
|
+
if (result.type === "not-found") {
|
|
5965
|
+
const serialized2 = await toCrossJSONAsync({
|
|
5966
|
+
__furinStatus: 404,
|
|
5967
|
+
__furinNotFound: { message: result.error.message, data: result.error.data }
|
|
5968
|
+
});
|
|
5969
|
+
return new Response(`${JSON.stringify(serialized2)}
|
|
5970
|
+
`, {
|
|
5971
|
+
status: 200,
|
|
5972
|
+
headers: { "content-type": "application/x-ndjson" }
|
|
5973
|
+
});
|
|
5974
|
+
}
|
|
5975
|
+
if (result.type === "error") {
|
|
5976
|
+
const digest = computeErrorDigest(result.error);
|
|
5977
|
+
const serialized2 = await toCrossJSONAsync({
|
|
5978
|
+
__furinError: {
|
|
5979
|
+
digest,
|
|
5980
|
+
message: result.message,
|
|
5981
|
+
status: result.status
|
|
5982
|
+
}
|
|
5983
|
+
});
|
|
5984
|
+
return new Response(`${JSON.stringify(serialized2)}
|
|
5985
|
+
`, {
|
|
5986
|
+
status: result.status,
|
|
5987
|
+
headers: { "content-type": "application/x-ndjson" }
|
|
5988
|
+
});
|
|
5989
|
+
}
|
|
5990
|
+
const syncDataWithTitle = withResolvedTitle(matched.route, result.syncData);
|
|
5991
|
+
if (result.deferredPromises) {
|
|
5992
|
+
return new Response(createDeferredNdjsonStream(syncDataWithTitle, result.deferredPromises), {
|
|
5993
|
+
headers: {
|
|
5994
|
+
"content-type": "application/x-ndjson",
|
|
5995
|
+
...result.headers
|
|
5996
|
+
}
|
|
5997
|
+
});
|
|
5998
|
+
}
|
|
5999
|
+
const serialized = await toCrossJSONAsync(syncDataWithTitle);
|
|
6000
|
+
return new Response(`${JSON.stringify(serialized)}
|
|
6001
|
+
`, {
|
|
6002
|
+
headers: {
|
|
6003
|
+
"content-type": "application/x-ndjson",
|
|
6004
|
+
...result.headers
|
|
6005
|
+
}
|
|
6006
|
+
});
|
|
6007
|
+
}, {
|
|
6008
|
+
query: t.Object({ path: t.Optional(t.String()) })
|
|
6009
|
+
});
|
|
6010
|
+
return plugin;
|
|
6011
|
+
}
|
|
6012
|
+
function withResolvedTitle(route, syncData) {
|
|
6013
|
+
const head = route.page.head;
|
|
6014
|
+
if (!head) {
|
|
6015
|
+
return syncData;
|
|
6016
|
+
}
|
|
6017
|
+
let title;
|
|
6018
|
+
try {
|
|
6019
|
+
title = extractTitle(head(syncData).meta);
|
|
6020
|
+
} catch {
|
|
6021
|
+
return syncData;
|
|
6022
|
+
}
|
|
6023
|
+
if (title === undefined) {
|
|
6024
|
+
return syncData;
|
|
6025
|
+
}
|
|
6026
|
+
return { ...syncData, __furinTitle: title };
|
|
6027
|
+
}
|
|
6028
|
+
function createDeferredNdjsonStream(syncData, deferredPromises) {
|
|
6029
|
+
const enc = new TextEncoder;
|
|
6030
|
+
const entries = Object.entries(deferredPromises);
|
|
6031
|
+
return new ReadableStream({
|
|
6032
|
+
async start(controller) {
|
|
6033
|
+
const initial = toCrossJSON({
|
|
6034
|
+
...syncData,
|
|
6035
|
+
__furinDeferredKeys: entries.map(([key]) => key)
|
|
6036
|
+
});
|
|
6037
|
+
controller.enqueue(enc.encode(`${JSON.stringify(initial)}
|
|
6038
|
+
`));
|
|
6039
|
+
await Promise.all(entries.map(async ([key, promise]) => {
|
|
6040
|
+
try {
|
|
6041
|
+
const value = await promise;
|
|
6042
|
+
controller.enqueue(enc.encode(`${JSON.stringify({ key, action: "resolve", value: toCrossJSON(value) })}
|
|
6043
|
+
`));
|
|
6044
|
+
} catch (err) {
|
|
6045
|
+
const normalized = await serializeDeferredRejection(err);
|
|
6046
|
+
const value = toCrossJSON(normalized);
|
|
6047
|
+
controller.enqueue(enc.encode(`${JSON.stringify({ key, action: "reject", value })}
|
|
6048
|
+
`));
|
|
6049
|
+
}
|
|
6050
|
+
}));
|
|
6051
|
+
controller.close();
|
|
6052
|
+
}
|
|
6053
|
+
});
|
|
6054
|
+
}
|
|
6055
|
+
var CONVENTION_FILE_NAMES, SOURCE_MODULE_EXTENSIONS, TOBJECT_STRUCTURAL_KEYS, DIR_SCAN_CONCURRENCY = 8, REGEX_META_CHARS_RE;
|
|
3681
6056
|
var init_router = __esm(() => {
|
|
6057
|
+
init_development();
|
|
6058
|
+
init_registry();
|
|
6059
|
+
init_context_logger();
|
|
3682
6060
|
init_assemble();
|
|
3683
6061
|
init_dev_cache();
|
|
3684
6062
|
init_render();
|
|
6063
|
+
init_shell();
|
|
3685
6064
|
CONVENTION_FILE_NAMES = ["not-found", "error"];
|
|
3686
6065
|
SOURCE_MODULE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
3687
6066
|
TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
|
|
6067
|
+
REGEX_META_CHARS_RE = /[.*+?^${}()|[\]\\]/;
|
|
3688
6068
|
});
|
|
3689
6069
|
|
|
3690
6070
|
// src/dev-page-plugin.ts
|
|
@@ -3907,7 +6287,7 @@ var exports_dev_inspector = {};
|
|
|
3907
6287
|
__export(exports_dev_inspector, {
|
|
3908
6288
|
createDevInspectorPlugin: () => createDevInspectorPlugin
|
|
3909
6289
|
});
|
|
3910
|
-
import { Elysia as
|
|
6290
|
+
import { Elysia as Elysia4 } from "elysia";
|
|
3911
6291
|
function projectEntry(key, entry) {
|
|
3912
6292
|
const revalidate = Number.isFinite(entry.revalidate) ? entry.revalidate : -1;
|
|
3913
6293
|
return {
|
|
@@ -3921,7 +6301,7 @@ function projectEntry(key, entry) {
|
|
|
3921
6301
|
};
|
|
3922
6302
|
}
|
|
3923
6303
|
function createDevInspectorPlugin() {
|
|
3924
|
-
return new
|
|
6304
|
+
return new Elysia4({ name: "furin-dev-inspector" }).get("/__furin/_inspect/isr", () => getAllDevISRLoaderEntries().map(([key, entry]) => projectEntry(key, entry))).get("/__furin/_inspect/ssg", () => getAllDevSSGLoaderEntries().map(([key, entry]) => projectEntry(key, entry)));
|
|
3925
6305
|
}
|
|
3926
6306
|
var init_dev_inspector = __esm(() => {
|
|
3927
6307
|
init_dev_cache();
|
|
@@ -3940,7 +6320,12 @@ function schemaToTypeString(schema) {
|
|
|
3940
6320
|
}
|
|
3941
6321
|
const s = schema;
|
|
3942
6322
|
if (s.anyOf && Array.isArray(s.anyOf)) {
|
|
3943
|
-
const parts =
|
|
6323
|
+
const parts = [];
|
|
6324
|
+
for (const item of s.anyOf) {
|
|
6325
|
+
const t2 = schemaToTypeString(item);
|
|
6326
|
+
if (t2 !== "null")
|
|
6327
|
+
parts.push(t2);
|
|
6328
|
+
}
|
|
3944
6329
|
return parts.join(" | ") || "unknown";
|
|
3945
6330
|
}
|
|
3946
6331
|
switch (s.type) {
|
|
@@ -3965,14 +6350,31 @@ function schemaToTypeString(schema) {
|
|
|
3965
6350
|
return "unknown";
|
|
3966
6351
|
}
|
|
3967
6352
|
}
|
|
6353
|
+
function tagKeyToPropertyName(tag) {
|
|
6354
|
+
return /^[$A-Z_a-z][$\w]*$/.test(tag) ? tag : JSON.stringify(tag);
|
|
6355
|
+
}
|
|
6356
|
+
function tagToStringLiteral(tag) {
|
|
6357
|
+
const json = JSON.stringify(tag);
|
|
6358
|
+
return `'${json.slice(1, -1).replaceAll("'", "\\'")}'`;
|
|
6359
|
+
}
|
|
3968
6360
|
function writeRouteTypes(routes, projectRoot) {
|
|
3969
|
-
const
|
|
6361
|
+
const sortedRoutes = [...routes].sort((a, b) => a.pattern.localeCompare(b.pattern));
|
|
6362
|
+
const entries = sortedRoutes.map((r) => {
|
|
3970
6363
|
const typeKey = patternToTypeString(r.pattern);
|
|
3971
6364
|
const isDynamic = typeKey.startsWith("`");
|
|
3972
6365
|
const querySchema = r.routeChain?.find((rt) => rt.query)?.query;
|
|
3973
6366
|
const searchType = querySchema ? schemaToTypeString(querySchema) : "never";
|
|
3974
6367
|
return isDynamic ? ` [key: ${typeKey}]: { search?: ${searchType} }` : ` ${typeKey}: { search?: ${searchType} }`;
|
|
3975
6368
|
});
|
|
6369
|
+
const sortedTags = [...new Set(routes.flatMap((route) => route.tags ?? []))].sort();
|
|
6370
|
+
const tagBlock = sortedTags.length > 0 ? `
|
|
6371
|
+
|
|
6372
|
+
declare module "@teyik0/furin" {
|
|
6373
|
+
interface FurinCacheTags {
|
|
6374
|
+
${sortedTags.map((tag) => ` ${tagKeyToPropertyName(tag)}: ${tagToStringLiteral(tag)};`).join(`
|
|
6375
|
+
`)}
|
|
6376
|
+
}
|
|
6377
|
+
}` : "";
|
|
3976
6378
|
const content = `// Auto-generated by Furin. Do not edit manually.
|
|
3977
6379
|
/// <reference types="@teyik0/furin/env" />
|
|
3978
6380
|
import "@teyik0/furin/link";
|
|
@@ -3982,7 +6384,7 @@ declare module "@teyik0/furin/link" {
|
|
|
3982
6384
|
${entries.join(`;
|
|
3983
6385
|
`)};
|
|
3984
6386
|
}
|
|
3985
|
-
}
|
|
6387
|
+
}${tagBlock}
|
|
3986
6388
|
`;
|
|
3987
6389
|
const typesPath = join2(projectRoot, "furin-env.d.ts");
|
|
3988
6390
|
const existing = existsSync2(typesPath) ? readFileSync2(typesPath, "utf8") : "";
|
|
@@ -4056,6 +6458,8 @@ import { createElement } from "react";
|
|
|
4056
6458
|
import { initLogger, log } from "evlog";
|
|
4057
6459
|
import { createHttpLogDrain } from "evlog/http";
|
|
4058
6460
|
import { RouterProvider } from "@teyik0/furin/link";
|
|
6461
|
+
import { fromCrossJSON } from "@teyik0/furin/link";
|
|
6462
|
+
import type { SerovalNode } from "seroval";
|
|
4059
6463
|
import { route as root } from "${rootLayout.replace(/\\/g, "/")}";${conventionImportsBlock}
|
|
4060
6464
|
|
|
4061
6465
|
initLogger({ drain: createHttpLogDrain({ drain: { endpoint: ${logEndpoint} } }) });
|
|
@@ -4077,6 +6481,70 @@ const _match = routes.find((r) => r.regex.test(pathname));
|
|
|
4077
6481
|
// former does not \u2014 so the two cases fork on _match below.
|
|
4078
6482
|
const dataEl = document.getElementById("__FURIN_DATA__");
|
|
4079
6483
|
const loaderData = dataEl ? JSON.parse(dataEl.textContent || "{}") : {};
|
|
6484
|
+
|
|
6485
|
+
// \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
|
|
6486
|
+
// window.__FURIN_DEFERRED__ is injected by the server when a loader returns
|
|
6487
|
+
// defer(). It carries:
|
|
6488
|
+
// - _chunks: raw CrossJSON chunks keyed by field name (from late <script> tags)
|
|
6489
|
+
// We deserialise each chunk with fromCrossJSON and create a Promise so <Await>
|
|
6490
|
+
// components receive a proper resolved Promise instead of the raw CrossJSON node.
|
|
6491
|
+
// Sync loader fields live exclusively in __FURIN_DATA__ (read above).
|
|
6492
|
+
interface FurinDeferredRegistry {
|
|
6493
|
+
_chunks: Record<string, { a: 0 | 1; v: SerovalNode }>;
|
|
6494
|
+
_deferredKeys: string[];
|
|
6495
|
+
_resolvers: Record<string, {
|
|
6496
|
+
promise: Promise<unknown>;
|
|
6497
|
+
reject: (reason: unknown) => void;
|
|
6498
|
+
resolve: (value: unknown) => void;
|
|
6499
|
+
}>;
|
|
6500
|
+
getPromise: (key: string) => Promise<unknown>;
|
|
6501
|
+
reject: (key: string, chunk: SerovalNode) => void;
|
|
6502
|
+
resolve: (key: string, chunk: SerovalNode) => void;
|
|
6503
|
+
}
|
|
6504
|
+
const __deferred = (window as unknown as { __FURIN_DEFERRED__?: FurinDeferredRegistry })
|
|
6505
|
+
.__FURIN_DEFERRED__;
|
|
6506
|
+
const deferredData: Record<string, Promise<unknown>> = {};
|
|
6507
|
+
if (__deferred && __deferred._chunks) {
|
|
6508
|
+
// Patch resolve/reject so any chunks that arrive AFTER this entry has run
|
|
6509
|
+
// settle immediately. The previous version stored late chunks in _chunks
|
|
6510
|
+
// when no resolver was registered yet, but the drain loop below only runs
|
|
6511
|
+
// ONCE at hydrate time \u2014 so any chunk landing after the drain would stay
|
|
6512
|
+
// orphaned and the corresponding Await would hang forever. Eagerly creating
|
|
6513
|
+
// the resolver via getPromise() fixes the race.
|
|
6514
|
+
__deferred.resolve = (key: string, chunk: SerovalNode) => {
|
|
6515
|
+
__deferred.getPromise(key);
|
|
6516
|
+
__deferred._resolvers[key].resolve(fromCrossJSON(chunk, {}));
|
|
6517
|
+
};
|
|
6518
|
+
__deferred.reject = (key: string, chunk: SerovalNode) => {
|
|
6519
|
+
__deferred.getPromise(key);
|
|
6520
|
+
__deferred._resolvers[key].reject(fromCrossJSON(chunk, {}));
|
|
6521
|
+
};
|
|
6522
|
+
for (const key of Object.keys(__deferred._chunks)) {
|
|
6523
|
+
const entry = __deferred._chunks[key] as { a: 0 | 1; v: SerovalNode };
|
|
6524
|
+
const p = __deferred.getPromise(key) as Promise<unknown>;
|
|
6525
|
+
const resolver = __deferred._resolvers[key];
|
|
6526
|
+
const value = fromCrossJSON(entry.v, {});
|
|
6527
|
+
if (entry.a === 0) {
|
|
6528
|
+
resolver.resolve(value);
|
|
6529
|
+
} else {
|
|
6530
|
+
resolver.reject(value);
|
|
6531
|
+
}
|
|
6532
|
+
deferredData[key] = p;
|
|
6533
|
+
}
|
|
6534
|
+
for (const key of __deferred._deferredKeys ?? []) {
|
|
6535
|
+
if (!(key in deferredData)) {
|
|
6536
|
+
deferredData[key] = __deferred.getPromise(key) as Promise<unknown>;
|
|
6537
|
+
}
|
|
6538
|
+
}
|
|
6539
|
+
// Keys that have a resolver (getPromise was called by <Await>) but no
|
|
6540
|
+
// chunk yet (the late <script> hasn't arrived) still need a Promise entry
|
|
6541
|
+
// so the hydration data record is complete.
|
|
6542
|
+
for (const key of Object.keys(__deferred._resolvers ?? {})) {
|
|
6543
|
+
if (!(key in deferredData)) {
|
|
6544
|
+
deferredData[key] = __deferred.getPromise(key) as Promise<unknown>;
|
|
6545
|
+
}
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
4080
6548
|
const rootEl = document.getElementById("root") as HTMLElement;
|
|
4081
6549
|
|
|
4082
6550
|
// Eagerly load only the current page module for initial hydration.
|
|
@@ -4095,7 +6563,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
4095
6563
|
routes,
|
|
4096
6564
|
root,
|
|
4097
6565
|
initialMatch: match,
|
|
4098
|
-
initialData: loaderData,
|
|
6566
|
+
initialData: { ...loaderData, ...deferredData },
|
|
4099
6567
|
initialDigest: loaderData.__furinError?.digest,
|
|
4100
6568
|
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${routerProviderDefaults}
|
|
4101
6569
|
} as any);
|
|
@@ -4195,14 +6663,148 @@ init_cache();
|
|
|
4195
6663
|
init_render();
|
|
4196
6664
|
init_template();
|
|
4197
6665
|
init_router();
|
|
4198
|
-
init_not_found();
|
|
4199
|
-
init_cache();
|
|
4200
|
-
init_render();
|
|
4201
6666
|
import { existsSync as existsSync4 } from "fs";
|
|
4202
6667
|
import { basename, dirname as dirname2, join as join4, resolve as resolve2 } from "path";
|
|
4203
6668
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
4204
6669
|
import { staticPlugin } from "@elysiajs/static";
|
|
4205
|
-
import { Elysia as
|
|
6670
|
+
import { Elysia as Elysia5, file } from "elysia";
|
|
6671
|
+
|
|
6672
|
+
// src/auto-invalidate/plugin.ts
|
|
6673
|
+
import { Elysia as Elysia3 } from "elysia";
|
|
6674
|
+
|
|
6675
|
+
// src/auto-invalidate/runtime.ts
|
|
6676
|
+
init_cache();
|
|
6677
|
+
init_registry();
|
|
6678
|
+
function toRules(input) {
|
|
6679
|
+
return Array.isArray(input) ? input : [input];
|
|
6680
|
+
}
|
|
6681
|
+
function statusFromResponseValue(responseValue) {
|
|
6682
|
+
if (responseValue instanceof Response) {
|
|
6683
|
+
return responseValue.status;
|
|
6684
|
+
}
|
|
6685
|
+
if (responseValue && typeof responseValue === "object" && "status" in responseValue) {
|
|
6686
|
+
const status = responseValue.status;
|
|
6687
|
+
if (typeof status === "number") {
|
|
6688
|
+
return status;
|
|
6689
|
+
}
|
|
6690
|
+
}
|
|
6691
|
+
if (responseValue && typeof responseValue === "object" && "code" in responseValue) {
|
|
6692
|
+
const code = responseValue.code;
|
|
6693
|
+
if (typeof code === "number") {
|
|
6694
|
+
return code;
|
|
6695
|
+
}
|
|
6696
|
+
}
|
|
6697
|
+
return;
|
|
6698
|
+
}
|
|
6699
|
+
function isSuccessfulMutationResponse(ctx) {
|
|
6700
|
+
const responseStatus = statusFromResponseValue(ctx.responseValue) ?? statusFromResponseValue(ctx.response);
|
|
6701
|
+
if (responseStatus !== undefined) {
|
|
6702
|
+
return responseStatus >= 200 && responseStatus < 400;
|
|
6703
|
+
}
|
|
6704
|
+
const setStatus = ctx.set.status;
|
|
6705
|
+
if (typeof setStatus === "number") {
|
|
6706
|
+
return setStatus >= 200 && setStatus < 400;
|
|
6707
|
+
}
|
|
6708
|
+
if (typeof setStatus === "string") {
|
|
6709
|
+
const errorStatusTexts = new Set([
|
|
6710
|
+
"Bad Request",
|
|
6711
|
+
"Unauthorized",
|
|
6712
|
+
"Payment Required",
|
|
6713
|
+
"Forbidden",
|
|
6714
|
+
"Not Found",
|
|
6715
|
+
"Method Not Allowed",
|
|
6716
|
+
"Not Acceptable",
|
|
6717
|
+
"Proxy Authentication Required",
|
|
6718
|
+
"Request Timeout",
|
|
6719
|
+
"Conflict",
|
|
6720
|
+
"Gone",
|
|
6721
|
+
"Length Required",
|
|
6722
|
+
"Precondition Failed",
|
|
6723
|
+
"Payload Too Large",
|
|
6724
|
+
"URI Too Long",
|
|
6725
|
+
"Unsupported Media Type",
|
|
6726
|
+
"Range Not Satisfiable",
|
|
6727
|
+
"Expectation Failed",
|
|
6728
|
+
"I'm a teapot",
|
|
6729
|
+
"Misdirected Request",
|
|
6730
|
+
"Unprocessable Content",
|
|
6731
|
+
"Locked",
|
|
6732
|
+
"Failed Dependency",
|
|
6733
|
+
"Too Early",
|
|
6734
|
+
"Upgrade Required",
|
|
6735
|
+
"Precondition Required",
|
|
6736
|
+
"Too Many Requests",
|
|
6737
|
+
"Enhance Your Calm",
|
|
6738
|
+
"Request Header Fields Too Large",
|
|
6739
|
+
"Unavailable For Legal Reasons",
|
|
6740
|
+
"Internal Server Error",
|
|
6741
|
+
"Not Implemented",
|
|
6742
|
+
"Bad Gateway",
|
|
6743
|
+
"Service Unavailable",
|
|
6744
|
+
"Gateway Timeout",
|
|
6745
|
+
"HTTP Version Not Supported",
|
|
6746
|
+
"Variant Also Negotiates",
|
|
6747
|
+
"Insufficient Storage",
|
|
6748
|
+
"Loop Detected",
|
|
6749
|
+
"Not Extended",
|
|
6750
|
+
"Network Authentication Required"
|
|
6751
|
+
]);
|
|
6752
|
+
return !errorStatusTexts.has(setStatus);
|
|
6753
|
+
}
|
|
6754
|
+
return true;
|
|
6755
|
+
}
|
|
6756
|
+
function appendPendingInvalidationHeader(set) {
|
|
6757
|
+
const pending = consumePendingInvalidations();
|
|
6758
|
+
if (pending.length === 0) {
|
|
6759
|
+
return;
|
|
6760
|
+
}
|
|
6761
|
+
const headerName = "x-furin-revalidate";
|
|
6762
|
+
const existing = set.headers[headerName];
|
|
6763
|
+
set.headers[headerName] = typeof existing === "string" && existing.length > 0 ? `${existing},${pending.join(",")}` : pending.join(",");
|
|
6764
|
+
}
|
|
6765
|
+
function revalidateTag(tags) {
|
|
6766
|
+
const tagList = typeof tags === "string" ? [tags] : [...tags];
|
|
6767
|
+
let deleted = false;
|
|
6768
|
+
for (const path of autoInvalidateRegistry.pathsForTags(tagList)) {
|
|
6769
|
+
deleted = revalidatePath(path, "page") || deleted;
|
|
6770
|
+
}
|
|
6771
|
+
return deleted;
|
|
6772
|
+
}
|
|
6773
|
+
function runInvalidationRules(input) {
|
|
6774
|
+
let deleted = false;
|
|
6775
|
+
for (const rule of toRules(input)) {
|
|
6776
|
+
if ("path" in rule && rule.path) {
|
|
6777
|
+
deleted = revalidatePath(rule.path, rule.type) || deleted;
|
|
6778
|
+
}
|
|
6779
|
+
if (rule.tags && rule.tags.length > 0) {
|
|
6780
|
+
deleted = revalidateTag(rule.tags) || deleted;
|
|
6781
|
+
}
|
|
6782
|
+
}
|
|
6783
|
+
return deleted;
|
|
6784
|
+
}
|
|
6785
|
+
|
|
6786
|
+
// src/auto-invalidate/plugin.ts
|
|
6787
|
+
function furinInvalidate() {
|
|
6788
|
+
return new Elysia3({ name: "furin-invalidate" }).macro({
|
|
6789
|
+
invalidate(rules) {
|
|
6790
|
+
return {
|
|
6791
|
+
afterHandle(ctx) {
|
|
6792
|
+
if (!isSuccessfulMutationResponse(ctx)) {
|
|
6793
|
+
return;
|
|
6794
|
+
}
|
|
6795
|
+
runInvalidationRules(rules);
|
|
6796
|
+
appendPendingInvalidationHeader(ctx.set);
|
|
6797
|
+
}
|
|
6798
|
+
};
|
|
6799
|
+
}
|
|
6800
|
+
});
|
|
6801
|
+
}
|
|
6802
|
+
// src/furin.ts
|
|
6803
|
+
init_await();
|
|
6804
|
+
init_client();
|
|
6805
|
+
init_not_found();
|
|
6806
|
+
init_cache();
|
|
6807
|
+
init_render();
|
|
4206
6808
|
function resolveClientDirFromArgv() {
|
|
4207
6809
|
return resolveClientDirFromEnv() ?? resolveClientDirFromModuleUrl() ?? resolveClientDirFromProcessArgs() ?? resolveFallbackClientDir();
|
|
4208
6810
|
}
|
|
@@ -4303,13 +6905,12 @@ async function furin({
|
|
|
4303
6905
|
}) {
|
|
4304
6906
|
const { exclude: userExclude, ...evlogOptions } = logger ?? {};
|
|
4305
6907
|
initLogger({ env: { service: "furin" } });
|
|
4306
|
-
const loggerPlugin = new
|
|
6908
|
+
const loggerPlugin = new Elysia5().use(evlog({
|
|
4307
6909
|
...evlogOptions,
|
|
4308
6910
|
exclude: [
|
|
4309
6911
|
"/_client/**",
|
|
4310
6912
|
"/public/**",
|
|
4311
6913
|
"/favicon.ico",
|
|
4312
|
-
"/_furin/!(ingest)",
|
|
4313
6914
|
"/_bun_hmr_entry/**",
|
|
4314
6915
|
...userExclude ?? []
|
|
4315
6916
|
]
|
|
@@ -4353,7 +6954,7 @@ async function furin({
|
|
|
4353
6954
|
writeDevFiles2(routes2, { outDir: furinDir, rootLayout: root2.path, basePath: "", publicPath: "/_client/" }, cwd);
|
|
4354
6955
|
const publicDir = resolve2(cwd, "public");
|
|
4355
6956
|
const publicExists = existsSync4(publicDir);
|
|
4356
|
-
const devApp = new
|
|
6957
|
+
const devApp = new Elysia5({ name: instanceName, seed: resolvedPagesDir }).use(loggerPlugin).onError({ as: "global" }, async ({ code, request }) => {
|
|
4357
6958
|
if (code === "NOT_FOUND") {
|
|
4358
6959
|
return await renderRootNotFound(root2, request);
|
|
4359
6960
|
}
|
|
@@ -4362,7 +6963,7 @@ async function furin({
|
|
|
4362
6963
|
if (pending.length > 0) {
|
|
4363
6964
|
set.headers["x-furin-revalidate"] = pending.join(",");
|
|
4364
6965
|
}
|
|
4365
|
-
}).use(await staticPlugin({ assets: furinDir, prefix: "/_bun_hmr_entry", bunFullstack: true })).use(publicExists ? await staticPlugin({ assets: publicDir, prefix: "/public" }) : new
|
|
6966
|
+
}).use(await staticPlugin({ assets: furinDir, prefix: "/_bun_hmr_entry", bunFullstack: true })).use(publicExists ? await staticPlugin({ assets: publicDir, prefix: "/public" }) : new Elysia5).get("/favicon.ico", publicExists ? file(join4(publicDir, "favicon.ico")) : () => new Response(null, { status: 404 })).use(createDevInspectorPlugin2()).use(createDataEndpoint(routes2)).use((app) => {
|
|
4366
6967
|
for (const route of routes2) {
|
|
4367
6968
|
app.use(createRoutePlugin(route, root2));
|
|
4368
6969
|
}
|
|
@@ -4379,7 +6980,7 @@ async function furin({
|
|
|
4379
6980
|
const embedded = ctx?.embedded;
|
|
4380
6981
|
const clientDir = embedded ? "" : resolveClientDirFromArgv();
|
|
4381
6982
|
await setupProdTemplate(embedded, clientDir);
|
|
4382
|
-
const prodApp = new
|
|
6983
|
+
const prodApp = new Elysia5({ name: instanceName, seed: resolvedPagesDir }).use(loggerPlugin).onError({ as: "global" }, async ({ code, request }) => {
|
|
4383
6984
|
if (code === "NOT_FOUND") {
|
|
4384
6985
|
return await renderRootNotFound(root, request);
|
|
4385
6986
|
}
|
|
@@ -4400,7 +7001,7 @@ async function furin({
|
|
|
4400
7001
|
await warmSSGCache(routes, root, origin);
|
|
4401
7002
|
}).use(await (async () => {
|
|
4402
7003
|
if (embedded) {
|
|
4403
|
-
return new
|
|
7004
|
+
return new Elysia5().get("/favicon.ico", ({ status }) => {
|
|
4404
7005
|
const asset = embedded.assets["/public/favicon.ico"];
|
|
4405
7006
|
if (!asset) {
|
|
4406
7007
|
return status("Not Found");
|
|
@@ -4421,13 +7022,13 @@ async function furin({
|
|
|
4421
7022
|
});
|
|
4422
7023
|
}
|
|
4423
7024
|
const publicDir = join4(dirname2(clientDir), "public");
|
|
4424
|
-
const app = new
|
|
7025
|
+
const app = new Elysia5;
|
|
4425
7026
|
if (existsSync4(publicDir)) {
|
|
4426
7027
|
app.get("/favicon.ico", file(join4(publicDir, "favicon.ico"))).use(await staticPlugin({ assets: publicDir, prefix: "/public" }));
|
|
4427
7028
|
}
|
|
4428
7029
|
app.use(await staticPlugin({ assets: clientDir, prefix: "/_client" }));
|
|
4429
7030
|
return app;
|
|
4430
|
-
})()).use((app) => {
|
|
7031
|
+
})()).use(createDataEndpoint(routes)).use((app) => {
|
|
4431
7032
|
for (const route of routes) {
|
|
4432
7033
|
app.use(createRoutePlugin(route, root, prodBuildId));
|
|
4433
7034
|
}
|
|
@@ -4436,10 +7037,17 @@ async function furin({
|
|
|
4436
7037
|
return wrapWithRequestScope(prodApp);
|
|
4437
7038
|
}
|
|
4438
7039
|
export {
|
|
7040
|
+
useAsyncValue,
|
|
7041
|
+
useAsyncError,
|
|
4439
7042
|
setCachePurger,
|
|
7043
|
+
revalidateTag,
|
|
4440
7044
|
revalidatePath,
|
|
4441
7045
|
renderRootNotFound,
|
|
4442
7046
|
notFound,
|
|
4443
7047
|
isNotFoundError,
|
|
4444
|
-
|
|
7048
|
+
isDeferred,
|
|
7049
|
+
furinInvalidate,
|
|
7050
|
+
furin,
|
|
7051
|
+
defer,
|
|
7052
|
+
Await
|
|
4445
7053
|
};
|