@teyik0/furin 0.1.0-alpha.8 → 0.1.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/index.js +850 -6
- package/dist/cli/index.js +850 -6
- package/dist/client.d.ts +3 -0
- package/dist/context-logger.d.ts +26 -0
- package/dist/furin.js +66 -8
- package/dist/link.js +63 -4
- package/dist/render/assemble.d.ts +4 -2
- package/dist/render/shell.d.ts +4 -1
- package/dist/router.d.ts +11 -0
- package/dist/router.js +861 -20
- package/package.json +1 -1
- package/src/adapter/static.ts +5 -1
- package/src/client.ts +3 -0
- package/src/context-logger.ts +71 -0
- package/src/link.tsx +90 -5
- package/src/render/assemble.ts +4 -2
- package/src/render/index.ts +5 -1
- package/src/render/loaders.ts +6 -2
- package/src/render/shell.ts +9 -2
- package/src/router.ts +44 -5
package/dist/cli/index.js
CHANGED
|
@@ -1471,11 +1471,13 @@ function generateIndexHtml() {
|
|
|
1471
1471
|
</html>
|
|
1472
1472
|
`;
|
|
1473
1473
|
}
|
|
1474
|
-
function generateProdIndexHtml(entryChunk, cssChunks, buildId) {
|
|
1474
|
+
function generateProdIndexHtml(entryChunk, cssChunks, buildId, faviconHref) {
|
|
1475
1475
|
const cssLinks = cssChunks.map((c) => ` <link rel="stylesheet" crossorigin href="${c}">`).join(`
|
|
1476
1476
|
`);
|
|
1477
1477
|
const scriptTag = `<script type="module" crossorigin src="${entryChunk}"></script>`;
|
|
1478
1478
|
const buildIdMeta = buildId ? ` <meta name="furin-build-id" content="${escapeHtml(buildId)}">
|
|
1479
|
+
` : "";
|
|
1480
|
+
const faviconLink = faviconHref ? ` <link rel="icon" href="${escapeHtml(faviconHref)}">
|
|
1479
1481
|
` : "";
|
|
1480
1482
|
return `<!DOCTYPE html>
|
|
1481
1483
|
<html lang="en">
|
|
@@ -1483,7 +1485,7 @@ function generateProdIndexHtml(entryChunk, cssChunks, buildId) {
|
|
|
1483
1485
|
<meta charset="UTF-8">
|
|
1484
1486
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1485
1487
|
${THEME_INIT_SCRIPT}
|
|
1486
|
-
${buildIdMeta}${cssLinks ? `${cssLinks}
|
|
1488
|
+
${buildIdMeta}${faviconLink}${cssLinks ? `${cssLinks}
|
|
1487
1489
|
` : ""} <!--ssr-head-->
|
|
1488
1490
|
</head>
|
|
1489
1491
|
<body>
|
|
@@ -2018,7 +2020,800 @@ function assembleHTML(template, headData, reactHtml, data) {
|
|
|
2018
2020
|
// src/render/index.ts
|
|
2019
2021
|
import { createElement as createElement2 } from "react";
|
|
2020
2022
|
import { renderToReadableStream } from "react-dom/server";
|
|
2023
|
+
// ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/utils.mjs
|
|
2024
|
+
function formatDuration(ms) {
|
|
2025
|
+
if (ms < 1000)
|
|
2026
|
+
return `${Math.round(ms)}ms`;
|
|
2027
|
+
return `${(ms / 1000).toFixed(2)}s`;
|
|
2028
|
+
}
|
|
2029
|
+
function isClient() {
|
|
2030
|
+
return typeof window !== "undefined";
|
|
2031
|
+
}
|
|
2032
|
+
function isDev() {
|
|
2033
|
+
if (typeof process !== "undefined")
|
|
2034
|
+
return true;
|
|
2035
|
+
if (typeof window !== "undefined")
|
|
2036
|
+
return true;
|
|
2037
|
+
return false;
|
|
2038
|
+
}
|
|
2039
|
+
function detectEnvironment() {
|
|
2040
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
2041
|
+
const defaultEnvironment = isDev() ? "development" : "production";
|
|
2042
|
+
return {
|
|
2043
|
+
environment: env.NODE_ENV || defaultEnvironment,
|
|
2044
|
+
service: env.SERVICE_NAME || "app",
|
|
2045
|
+
version: env.APP_VERSION,
|
|
2046
|
+
commitHash: env.COMMIT_SHA || env.GITHUB_SHA || env.VERCEL_GIT_COMMIT_SHA || env.CF_PAGES_COMMIT_SHA,
|
|
2047
|
+
region: env.VERCEL_REGION || env.AWS_REGION || env.FLY_REGION || env.CF_REGION
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
var LEVEL_ORDER = {
|
|
2051
|
+
debug: 0,
|
|
2052
|
+
info: 1,
|
|
2053
|
+
warn: 2,
|
|
2054
|
+
error: 3
|
|
2055
|
+
};
|
|
2056
|
+
function isLevelEnabled(level, minLevel) {
|
|
2057
|
+
return LEVEL_ORDER[level] >= LEVEL_ORDER[minLevel];
|
|
2058
|
+
}
|
|
2059
|
+
function getConsoleMethod(level) {
|
|
2060
|
+
return level;
|
|
2061
|
+
}
|
|
2062
|
+
var colors = {
|
|
2063
|
+
reset: "\x1B[0m",
|
|
2064
|
+
bold: "\x1B[1m",
|
|
2065
|
+
dim: "\x1B[2m",
|
|
2066
|
+
red: "\x1B[31m",
|
|
2067
|
+
green: "\x1B[32m",
|
|
2068
|
+
yellow: "\x1B[33m",
|
|
2069
|
+
blue: "\x1B[34m",
|
|
2070
|
+
magenta: "\x1B[35m",
|
|
2071
|
+
cyan: "\x1B[36m",
|
|
2072
|
+
white: "\x1B[37m",
|
|
2073
|
+
gray: "\x1B[90m"
|
|
2074
|
+
};
|
|
2075
|
+
var levelColorMap = {
|
|
2076
|
+
error: colors.red,
|
|
2077
|
+
warn: colors.yellow,
|
|
2078
|
+
info: colors.cyan,
|
|
2079
|
+
debug: colors.gray
|
|
2080
|
+
};
|
|
2081
|
+
function getLevelColor(level) {
|
|
2082
|
+
return levelColorMap[level] ?? colors.white;
|
|
2083
|
+
}
|
|
2084
|
+
var cssColors = {
|
|
2085
|
+
dim: "color: #6b7280",
|
|
2086
|
+
red: "color: #ef4444; font-weight: bold",
|
|
2087
|
+
green: "color: #22c55e",
|
|
2088
|
+
yellow: "color: #f59e0b; font-weight: bold",
|
|
2089
|
+
cyan: "color: #06b6d4; font-weight: bold",
|
|
2090
|
+
gray: "color: #6b7280; font-weight: bold",
|
|
2091
|
+
reset: "color: inherit; font-weight: normal"
|
|
2092
|
+
};
|
|
2093
|
+
var cssLevelColorMap = {
|
|
2094
|
+
error: cssColors.red,
|
|
2095
|
+
warn: cssColors.yellow,
|
|
2096
|
+
info: cssColors.cyan,
|
|
2097
|
+
debug: cssColors.gray
|
|
2098
|
+
};
|
|
2099
|
+
function getCssLevelColor(level) {
|
|
2100
|
+
return cssLevelColorMap[level] ?? cssColors.reset;
|
|
2101
|
+
}
|
|
2102
|
+
function escapeFormatString(str) {
|
|
2103
|
+
return str.replace(/%/g, "%%");
|
|
2104
|
+
}
|
|
2105
|
+
var patternCache = /* @__PURE__ */ new Map;
|
|
2106
|
+
function matchesPattern(path, pattern) {
|
|
2107
|
+
let regex = patternCache.get(pattern);
|
|
2108
|
+
if (!regex) {
|
|
2109
|
+
const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "{{GLOBSTAR}}").replace(/\*/g, "[^/]*").replace(/{{GLOBSTAR}}/g, ".*").replace(/\?/g, "[^/]");
|
|
2110
|
+
regex = new RegExp(`^${regexPattern}$`);
|
|
2111
|
+
patternCache.set(pattern, regex);
|
|
2112
|
+
}
|
|
2113
|
+
return regex.test(path);
|
|
2114
|
+
}
|
|
2021
2115
|
|
|
2116
|
+
// ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/logger-DnobymUQ.mjs
|
|
2117
|
+
var DEFAULT_REPLACEMENT = "[REDACTED]";
|
|
2118
|
+
var builtinPatterns = {
|
|
2119
|
+
creditCard: {
|
|
2120
|
+
pattern: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,
|
|
2121
|
+
mask: (m) => `****${m.replace(/[\s-]/g, "").slice(-4)}`
|
|
2122
|
+
},
|
|
2123
|
+
email: {
|
|
2124
|
+
pattern: /[\w.+-]+@[\w-]+\.[\w.]+/g,
|
|
2125
|
+
mask: (m) => {
|
|
2126
|
+
if (m.indexOf("@") < 1)
|
|
2127
|
+
return "***@***";
|
|
2128
|
+
const tld = m.slice(m.lastIndexOf("."));
|
|
2129
|
+
return `${m[0]}***@***${tld}`;
|
|
2130
|
+
}
|
|
2131
|
+
},
|
|
2132
|
+
ipv4: {
|
|
2133
|
+
pattern: /\b(?!0\.0\.0\.0\b)(?!127\.0\.0\.1\b)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g,
|
|
2134
|
+
mask: (m) => `***.***.***.${m.split(".").pop()}`
|
|
2135
|
+
},
|
|
2136
|
+
phone: {
|
|
2137
|
+
pattern: /(?:\+\d{1,3}[\s.-]?)?\(?\d{1,4}\)?[\s.-]?\d{2,4}[\s.-]?\d{2,4}[\s.-]?\d{2,4}\b/g,
|
|
2138
|
+
mask: (m) => {
|
|
2139
|
+
const digits = m.replace(/[^\d]/g, "");
|
|
2140
|
+
if (m.startsWith("+") && digits.length > 4) {
|
|
2141
|
+
const ccMatch = m.match(/^\+\d{1,3}/);
|
|
2142
|
+
return `${ccMatch ? ccMatch[0] : "+"}******${digits.slice(-2)}`;
|
|
2143
|
+
}
|
|
2144
|
+
if (digits.length > 2)
|
|
2145
|
+
return `${"*".repeat(digits.length - 2)}${digits.slice(-2)}`;
|
|
2146
|
+
return "***";
|
|
2147
|
+
}
|
|
2148
|
+
},
|
|
2149
|
+
jwt: {
|
|
2150
|
+
pattern: /\beyJ[\w-]*\.[\w-]*\.[\w-]*\b/g,
|
|
2151
|
+
mask: () => "eyJ***.***"
|
|
2152
|
+
},
|
|
2153
|
+
bearer: {
|
|
2154
|
+
pattern: /\bBearer\s+[\w\-.~+/]{8,}=*/gi,
|
|
2155
|
+
mask: () => "Bearer ***"
|
|
2156
|
+
},
|
|
2157
|
+
iban: {
|
|
2158
|
+
pattern: /\b[A-Z]{2}\d{2}[\s-]?[\dA-Z]{4}[\s-]?[\dA-Z]{4}[\s-]?[\dA-Z]{4}[\s-]?[\dA-Z]{0,4}[\s-]?[\dA-Z]{0,4}[\s-]?[\dA-Z]{0,4}\b/g,
|
|
2159
|
+
mask: (m) => {
|
|
2160
|
+
const clean = m.replace(/[\s-]/g, "");
|
|
2161
|
+
return `${clean.slice(0, 4)}****${clean.slice(-3)}`;
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
};
|
|
2165
|
+
function resolveRedactConfig(input) {
|
|
2166
|
+
if (input === undefined || input === false)
|
|
2167
|
+
return;
|
|
2168
|
+
if (input === true)
|
|
2169
|
+
return { _maskers: allBuiltinMaskers() };
|
|
2170
|
+
if (input.builtins === false)
|
|
2171
|
+
return input;
|
|
2172
|
+
const maskers = Array.isArray(input.builtins) ? input.builtins.map((name) => builtinPatterns[name]).filter(Boolean).map((b) => [cloneRegex(b.pattern), b.mask]) : allBuiltinMaskers();
|
|
2173
|
+
return {
|
|
2174
|
+
...input,
|
|
2175
|
+
_maskers: maskers
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
function allBuiltinMaskers() {
|
|
2179
|
+
return Object.values(builtinPatterns).map((b) => [cloneRegex(b.pattern), b.mask]);
|
|
2180
|
+
}
|
|
2181
|
+
function cloneRegex(re) {
|
|
2182
|
+
return new RegExp(re.source, re.flags);
|
|
2183
|
+
}
|
|
2184
|
+
function redactEvent(event, config) {
|
|
2185
|
+
const replacement = config.replacement ?? DEFAULT_REPLACEMENT;
|
|
2186
|
+
if (config.paths?.length)
|
|
2187
|
+
for (const path of config.paths)
|
|
2188
|
+
redactPath(event, path.split("."), replacement);
|
|
2189
|
+
if (config._maskers?.length)
|
|
2190
|
+
applyMaskersToTree(event, config._maskers);
|
|
2191
|
+
if (config.patterns?.length)
|
|
2192
|
+
redactPatterns(event, config.patterns, replacement);
|
|
2193
|
+
}
|
|
2194
|
+
function redactPath(obj, segments, replacement) {
|
|
2195
|
+
let current = obj;
|
|
2196
|
+
for (let i = 0;i < segments.length - 1; i++) {
|
|
2197
|
+
if (current === null || current === undefined || typeof current !== "object")
|
|
2198
|
+
return;
|
|
2199
|
+
current = current[segments[i]];
|
|
2200
|
+
}
|
|
2201
|
+
if (current === null || current === undefined || typeof current !== "object")
|
|
2202
|
+
return;
|
|
2203
|
+
const leaf = segments[segments.length - 1];
|
|
2204
|
+
if (leaf in current)
|
|
2205
|
+
current[leaf] = replacement;
|
|
2206
|
+
}
|
|
2207
|
+
function redactPatterns(obj, patterns, replacement) {
|
|
2208
|
+
if (obj === null || obj === undefined)
|
|
2209
|
+
return;
|
|
2210
|
+
if (Array.isArray(obj)) {
|
|
2211
|
+
for (let i = 0;i < obj.length; i++)
|
|
2212
|
+
if (typeof obj[i] === "string")
|
|
2213
|
+
obj[i] = applyPatterns(obj[i], patterns, replacement);
|
|
2214
|
+
else if (typeof obj[i] === "object")
|
|
2215
|
+
redactPatterns(obj[i], patterns, replacement);
|
|
2216
|
+
return;
|
|
2217
|
+
}
|
|
2218
|
+
if (typeof obj === "object") {
|
|
2219
|
+
const record = obj;
|
|
2220
|
+
for (const key in record) {
|
|
2221
|
+
const val = record[key];
|
|
2222
|
+
if (typeof val === "string")
|
|
2223
|
+
record[key] = applyPatterns(val, patterns, replacement);
|
|
2224
|
+
else if (typeof val === "object")
|
|
2225
|
+
redactPatterns(val, patterns, replacement);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
function applyPatterns(value, patterns, replacement) {
|
|
2230
|
+
let result = value;
|
|
2231
|
+
for (const pattern of patterns) {
|
|
2232
|
+
pattern.lastIndex = 0;
|
|
2233
|
+
result = result.replace(pattern, replacement);
|
|
2234
|
+
}
|
|
2235
|
+
return result;
|
|
2236
|
+
}
|
|
2237
|
+
function applyMaskersToTree(obj, maskers) {
|
|
2238
|
+
if (obj === null || obj === undefined)
|
|
2239
|
+
return;
|
|
2240
|
+
if (Array.isArray(obj)) {
|
|
2241
|
+
for (let i = 0;i < obj.length; i++)
|
|
2242
|
+
if (typeof obj[i] === "string")
|
|
2243
|
+
obj[i] = applyMaskers(obj[i], maskers);
|
|
2244
|
+
else if (typeof obj[i] === "object")
|
|
2245
|
+
applyMaskersToTree(obj[i], maskers);
|
|
2246
|
+
return;
|
|
2247
|
+
}
|
|
2248
|
+
if (typeof obj === "object") {
|
|
2249
|
+
const record = obj;
|
|
2250
|
+
for (const key in record) {
|
|
2251
|
+
const val = record[key];
|
|
2252
|
+
if (typeof val === "string")
|
|
2253
|
+
record[key] = applyMaskers(val, maskers);
|
|
2254
|
+
else if (typeof val === "object")
|
|
2255
|
+
applyMaskersToTree(val, maskers);
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
function applyMaskers(value, maskers) {
|
|
2260
|
+
let result = value;
|
|
2261
|
+
for (const [pattern, mask] of maskers) {
|
|
2262
|
+
pattern.lastIndex = 0;
|
|
2263
|
+
result = result.replace(pattern, mask);
|
|
2264
|
+
}
|
|
2265
|
+
return result;
|
|
2266
|
+
}
|
|
2267
|
+
function isPlainObject(val) {
|
|
2268
|
+
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
2269
|
+
}
|
|
2270
|
+
var _tsDate = /* @__PURE__ */ new Date;
|
|
2271
|
+
function isoNow() {
|
|
2272
|
+
_tsDate.setTime(Date.now());
|
|
2273
|
+
return _tsDate.toISOString();
|
|
2274
|
+
}
|
|
2275
|
+
var 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).";
|
|
2276
|
+
function warnPostEmit(method, detail) {
|
|
2277
|
+
console.warn(`[evlog] ${method} called after the wide event was emitted \u2014 ${detail} This data will not appear in observability. ${POST_EMIT_FORK_HINT}`);
|
|
2278
|
+
}
|
|
2279
|
+
function mergeInto(target, source) {
|
|
2280
|
+
for (const key in source) {
|
|
2281
|
+
const sourceVal = source[key];
|
|
2282
|
+
if (sourceVal === undefined || sourceVal === null)
|
|
2283
|
+
continue;
|
|
2284
|
+
const targetVal = target[key];
|
|
2285
|
+
if (isPlainObject(sourceVal) && isPlainObject(targetVal))
|
|
2286
|
+
mergeInto(targetVal, sourceVal);
|
|
2287
|
+
else if (Array.isArray(targetVal) && Array.isArray(sourceVal))
|
|
2288
|
+
target[key] = [...targetVal, ...sourceVal];
|
|
2289
|
+
else
|
|
2290
|
+
target[key] = sourceVal;
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
var globalEnv = {
|
|
2294
|
+
service: "app",
|
|
2295
|
+
environment: "development"
|
|
2296
|
+
};
|
|
2297
|
+
var globalPretty = isDev();
|
|
2298
|
+
var globalSampling = {};
|
|
2299
|
+
var globalStringify = true;
|
|
2300
|
+
var globalDrain;
|
|
2301
|
+
var globalRedact;
|
|
2302
|
+
var globalEnabled = true;
|
|
2303
|
+
var globalSilent = false;
|
|
2304
|
+
var globalMinLevel = "debug";
|
|
2305
|
+
function initLogger(config = {}) {
|
|
2306
|
+
globalEnabled = config.enabled ?? true;
|
|
2307
|
+
const detected = detectEnvironment();
|
|
2308
|
+
globalEnv = {
|
|
2309
|
+
service: config.env?.service ?? detected.service ?? "app",
|
|
2310
|
+
environment: config.env?.environment ?? detected.environment ?? "development",
|
|
2311
|
+
version: config.env?.version ?? detected.version,
|
|
2312
|
+
commitHash: config.env?.commitHash ?? detected.commitHash,
|
|
2313
|
+
region: config.env?.region ?? detected.region
|
|
2314
|
+
};
|
|
2315
|
+
globalPretty = config.pretty ?? isDev();
|
|
2316
|
+
globalSampling = config.sampling ?? {};
|
|
2317
|
+
globalStringify = config.stringify ?? true;
|
|
2318
|
+
globalDrain = config.drain;
|
|
2319
|
+
globalRedact = resolveRedactConfig(config.redact ?? !isDev());
|
|
2320
|
+
globalSilent = config.silent ?? false;
|
|
2321
|
+
globalMinLevel = config.minLevel ?? "debug";
|
|
2322
|
+
if (globalSilent && !globalDrain && !config._suppressDrainWarning)
|
|
2323
|
+
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).");
|
|
2324
|
+
}
|
|
2325
|
+
function shouldSample(level) {
|
|
2326
|
+
const { rates } = globalSampling;
|
|
2327
|
+
if (!rates)
|
|
2328
|
+
return true;
|
|
2329
|
+
const percentage = level === "error" && rates.error === undefined ? 100 : rates[level] ?? 100;
|
|
2330
|
+
if (percentage <= 0)
|
|
2331
|
+
return false;
|
|
2332
|
+
if (percentage >= 100)
|
|
2333
|
+
return true;
|
|
2334
|
+
return Math.random() * 100 < percentage;
|
|
2335
|
+
}
|
|
2336
|
+
function shouldKeep(ctx) {
|
|
2337
|
+
const { keep } = globalSampling;
|
|
2338
|
+
if (!keep?.length)
|
|
2339
|
+
return false;
|
|
2340
|
+
return keep.some((condition) => {
|
|
2341
|
+
if (condition.status !== undefined && ctx.status !== undefined && ctx.status >= condition.status)
|
|
2342
|
+
return true;
|
|
2343
|
+
if (condition.duration !== undefined && ctx.duration !== undefined && ctx.duration >= condition.duration)
|
|
2344
|
+
return true;
|
|
2345
|
+
if (condition.path && ctx.path && matchesPattern(ctx.path, condition.path))
|
|
2346
|
+
return true;
|
|
2347
|
+
return false;
|
|
2348
|
+
});
|
|
2349
|
+
}
|
|
2350
|
+
function emitWideEvent(level, event, deferDrain = false, ownsEvent = false) {
|
|
2351
|
+
if (!globalEnabled)
|
|
2352
|
+
return null;
|
|
2353
|
+
if (!ownsEvent) {
|
|
2354
|
+
if (!isLevelEnabled(level, globalMinLevel))
|
|
2355
|
+
return null;
|
|
2356
|
+
if (!shouldSample(level))
|
|
2357
|
+
return null;
|
|
2358
|
+
}
|
|
2359
|
+
let formatted;
|
|
2360
|
+
if (ownsEvent) {
|
|
2361
|
+
event.timestamp = isoNow();
|
|
2362
|
+
event.level = level;
|
|
2363
|
+
if (event.service === undefined)
|
|
2364
|
+
event.service = globalEnv.service;
|
|
2365
|
+
if (event.environment === undefined)
|
|
2366
|
+
event.environment = globalEnv.environment;
|
|
2367
|
+
if (globalEnv.version !== undefined && event.version === undefined)
|
|
2368
|
+
event.version = globalEnv.version;
|
|
2369
|
+
if (globalEnv.commitHash !== undefined && event.commitHash === undefined)
|
|
2370
|
+
event.commitHash = globalEnv.commitHash;
|
|
2371
|
+
if (globalEnv.region !== undefined && event.region === undefined)
|
|
2372
|
+
event.region = globalEnv.region;
|
|
2373
|
+
formatted = event;
|
|
2374
|
+
} else
|
|
2375
|
+
formatted = {
|
|
2376
|
+
timestamp: isoNow(),
|
|
2377
|
+
level,
|
|
2378
|
+
...globalEnv,
|
|
2379
|
+
...event
|
|
2380
|
+
};
|
|
2381
|
+
if (globalRedact)
|
|
2382
|
+
redactEvent(formatted, globalRedact);
|
|
2383
|
+
if (!globalSilent)
|
|
2384
|
+
if (globalPretty)
|
|
2385
|
+
prettyPrintWideEvent(formatted);
|
|
2386
|
+
else if (globalStringify)
|
|
2387
|
+
console[getConsoleMethod(level)](JSON.stringify(formatted));
|
|
2388
|
+
else
|
|
2389
|
+
console[getConsoleMethod(level)](formatted);
|
|
2390
|
+
if (globalDrain && !deferDrain)
|
|
2391
|
+
Promise.resolve(globalDrain({ event: formatted })).catch((err) => {
|
|
2392
|
+
console.error("[evlog] drain failed:", err);
|
|
2393
|
+
});
|
|
2394
|
+
return formatted;
|
|
2395
|
+
}
|
|
2396
|
+
function emitTaggedLog(level, tag, message) {
|
|
2397
|
+
if (!globalEnabled)
|
|
2398
|
+
return;
|
|
2399
|
+
if (globalPretty && !globalSilent) {
|
|
2400
|
+
if (!isLevelEnabled(level, globalMinLevel))
|
|
2401
|
+
return;
|
|
2402
|
+
if (!shouldSample(level))
|
|
2403
|
+
return;
|
|
2404
|
+
if (isClient()) {
|
|
2405
|
+
const levelColor = getCssLevelColor(level);
|
|
2406
|
+
const timestamp = isoNow().slice(11, 23);
|
|
2407
|
+
console.log(`%c${timestamp}%c %c[${escapeFormatString(tag)}]%c ${escapeFormatString(message)}`, cssColors.dim, cssColors.reset, levelColor, cssColors.reset);
|
|
2408
|
+
} else {
|
|
2409
|
+
const color = getLevelColor(level);
|
|
2410
|
+
const timestamp = isoNow().slice(11, 23);
|
|
2411
|
+
console.log(`${colors.dim}${timestamp}${colors.reset} ${color}[${tag}]${colors.reset} ${message}`);
|
|
2412
|
+
}
|
|
2413
|
+
return;
|
|
2414
|
+
}
|
|
2415
|
+
emitWideEvent(level, {
|
|
2416
|
+
tag,
|
|
2417
|
+
message
|
|
2418
|
+
});
|
|
2419
|
+
}
|
|
2420
|
+
function formatValue(value) {
|
|
2421
|
+
if (value === null || value === undefined)
|
|
2422
|
+
return String(value);
|
|
2423
|
+
if (typeof value === "object") {
|
|
2424
|
+
const pairs = [];
|
|
2425
|
+
for (const [k, v] of Object.entries(value))
|
|
2426
|
+
if (v !== undefined && v !== null)
|
|
2427
|
+
if (typeof v === "object")
|
|
2428
|
+
pairs.push(`${k}=${JSON.stringify(v)}`);
|
|
2429
|
+
else
|
|
2430
|
+
pairs.push(`${k}=${v}`);
|
|
2431
|
+
return pairs.join(" ");
|
|
2432
|
+
}
|
|
2433
|
+
return String(value);
|
|
2434
|
+
}
|
|
2435
|
+
function formatCost(cost) {
|
|
2436
|
+
if (cost < 0.01)
|
|
2437
|
+
return `$${cost.toFixed(6)}`;
|
|
2438
|
+
if (cost < 1)
|
|
2439
|
+
return `$${cost.toFixed(4)}`;
|
|
2440
|
+
return `$${cost.toFixed(2)}`;
|
|
2441
|
+
}
|
|
2442
|
+
function buildAIEntries(ai) {
|
|
2443
|
+
const entries = [];
|
|
2444
|
+
const headerParts = [];
|
|
2445
|
+
if (ai.model) {
|
|
2446
|
+
let m = String(ai.model);
|
|
2447
|
+
if (ai.provider)
|
|
2448
|
+
m += ` (${ai.provider})`;
|
|
2449
|
+
headerParts.push(m);
|
|
2450
|
+
}
|
|
2451
|
+
if (ai.calls)
|
|
2452
|
+
headerParts.push(`${ai.calls} call${ai.calls > 1 ? "s" : ""}`);
|
|
2453
|
+
if (ai.steps && ai.steps > 1)
|
|
2454
|
+
headerParts.push(`${ai.steps} steps`);
|
|
2455
|
+
entries.push({
|
|
2456
|
+
key: "ai",
|
|
2457
|
+
value: headerParts.join(" \xB7 ")
|
|
2458
|
+
});
|
|
2459
|
+
const inputTokens = ai.inputTokens;
|
|
2460
|
+
const outputTokens = ai.outputTokens;
|
|
2461
|
+
const totalTokens = ai.totalTokens;
|
|
2462
|
+
if (inputTokens !== undefined && outputTokens !== undefined) {
|
|
2463
|
+
let tokLine = `${inputTokens} in \u2192 ${outputTokens} out`;
|
|
2464
|
+
if (totalTokens)
|
|
2465
|
+
tokLine += ` (${totalTokens} total)`;
|
|
2466
|
+
const extras = [];
|
|
2467
|
+
if (ai.cacheReadTokens)
|
|
2468
|
+
extras.push(`${ai.cacheReadTokens} cache read`);
|
|
2469
|
+
if (ai.cacheWriteTokens)
|
|
2470
|
+
extras.push(`${ai.cacheWriteTokens} cache write`);
|
|
2471
|
+
if (ai.reasoningTokens)
|
|
2472
|
+
extras.push(`${ai.reasoningTokens} reasoning`);
|
|
2473
|
+
if (extras.length)
|
|
2474
|
+
tokLine += ` \xB7 ${extras.join(" \xB7 ")}`;
|
|
2475
|
+
entries.push({
|
|
2476
|
+
key: "ai.tokens",
|
|
2477
|
+
value: tokLine
|
|
2478
|
+
});
|
|
2479
|
+
}
|
|
2480
|
+
const msFirst = ai.msToFirstChunk;
|
|
2481
|
+
const msFinish = ai.msToFinish;
|
|
2482
|
+
const tps = ai.tokensPerSecond;
|
|
2483
|
+
if (msFirst !== undefined || msFinish !== undefined) {
|
|
2484
|
+
const parts = [];
|
|
2485
|
+
if (msFirst !== undefined)
|
|
2486
|
+
parts.push(`${formatDuration(msFirst)} to first chunk`);
|
|
2487
|
+
if (msFinish !== undefined)
|
|
2488
|
+
parts.push(`${formatDuration(msFinish)} total`);
|
|
2489
|
+
let streamLine = parts.join(" \u2192 ");
|
|
2490
|
+
if (tps)
|
|
2491
|
+
streamLine += ` \xB7 ${tps} tok/s`;
|
|
2492
|
+
entries.push({
|
|
2493
|
+
key: "ai.streaming",
|
|
2494
|
+
value: streamLine
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
if (ai.estimatedCost !== undefined)
|
|
2498
|
+
entries.push({
|
|
2499
|
+
key: "ai.cost",
|
|
2500
|
+
value: formatCost(ai.estimatedCost)
|
|
2501
|
+
});
|
|
2502
|
+
if (ai.totalDurationMs !== undefined)
|
|
2503
|
+
entries.push({
|
|
2504
|
+
key: "ai.totalDuration",
|
|
2505
|
+
value: formatDuration(ai.totalDurationMs)
|
|
2506
|
+
});
|
|
2507
|
+
const toolCalls = ai.toolCalls;
|
|
2508
|
+
const tools = ai.tools;
|
|
2509
|
+
const hasInputs = toolCalls?.length ? typeof toolCalls[0] === "object" : false;
|
|
2510
|
+
if (tools?.length) {
|
|
2511
|
+
const children = tools.map((t, idx) => {
|
|
2512
|
+
const mark = t.success ? "\u2713" : "\u2717";
|
|
2513
|
+
let line = `${t.name} ${formatDuration(t.durationMs)} ${mark}`;
|
|
2514
|
+
if (t.error)
|
|
2515
|
+
line += ` ${t.error}`;
|
|
2516
|
+
if (hasInputs && toolCalls && idx < toolCalls.length) {
|
|
2517
|
+
const tc = toolCalls[idx];
|
|
2518
|
+
const inputStr = typeof tc.input === "string" ? tc.input : JSON.stringify(tc.input);
|
|
2519
|
+
const truncated = inputStr.length > 100 ? `${inputStr.slice(0, 100)}\u2026` : inputStr;
|
|
2520
|
+
line += ` ${truncated}`;
|
|
2521
|
+
}
|
|
2522
|
+
return line;
|
|
2523
|
+
});
|
|
2524
|
+
entries.push({
|
|
2525
|
+
key: "ai.tools",
|
|
2526
|
+
value: "",
|
|
2527
|
+
children
|
|
2528
|
+
});
|
|
2529
|
+
} else if (toolCalls?.length)
|
|
2530
|
+
if (hasInputs) {
|
|
2531
|
+
const children = toolCalls.map((tc) => {
|
|
2532
|
+
const inputStr = typeof tc.input === "string" ? tc.input : JSON.stringify(tc.input);
|
|
2533
|
+
const truncated = inputStr.length > 100 ? `${inputStr.slice(0, 100)}\u2026` : inputStr;
|
|
2534
|
+
return `${tc.name}(${truncated})`;
|
|
2535
|
+
});
|
|
2536
|
+
entries.push({
|
|
2537
|
+
key: "ai.tools",
|
|
2538
|
+
value: "",
|
|
2539
|
+
children
|
|
2540
|
+
});
|
|
2541
|
+
} else
|
|
2542
|
+
entries.push({
|
|
2543
|
+
key: "ai.tools",
|
|
2544
|
+
value: toolCalls.join(", ")
|
|
2545
|
+
});
|
|
2546
|
+
const stepsUsage = ai.stepsUsage;
|
|
2547
|
+
if (stepsUsage?.length) {
|
|
2548
|
+
const allSameModel = stepsUsage.every((s) => s.model === stepsUsage[0].model);
|
|
2549
|
+
const children = stepsUsage.map((s) => {
|
|
2550
|
+
let line = `${allSameModel ? "" : `${s.model} `}${s.inputTokens} in \u2192 ${s.outputTokens} out`;
|
|
2551
|
+
const stepTools = s.toolCalls;
|
|
2552
|
+
if (stepTools?.length)
|
|
2553
|
+
line += ` [${stepTools.join(", ")}]`;
|
|
2554
|
+
return line;
|
|
2555
|
+
});
|
|
2556
|
+
entries.push({
|
|
2557
|
+
key: "ai.steps",
|
|
2558
|
+
value: "",
|
|
2559
|
+
children
|
|
2560
|
+
});
|
|
2561
|
+
} else if (ai.steps && ai.steps > 1)
|
|
2562
|
+
entries.push({
|
|
2563
|
+
key: "ai.steps",
|
|
2564
|
+
value: String(ai.steps)
|
|
2565
|
+
});
|
|
2566
|
+
const embedding = ai.embedding;
|
|
2567
|
+
if (embedding) {
|
|
2568
|
+
const parts = [];
|
|
2569
|
+
if (embedding.model)
|
|
2570
|
+
parts.push(String(embedding.model));
|
|
2571
|
+
parts.push(`${embedding.tokens} tokens`);
|
|
2572
|
+
if (embedding.dimensions)
|
|
2573
|
+
parts.push(`${embedding.dimensions}d`);
|
|
2574
|
+
if (embedding.count)
|
|
2575
|
+
parts.push(`${embedding.count} items`);
|
|
2576
|
+
entries.push({
|
|
2577
|
+
key: "ai.embedding",
|
|
2578
|
+
value: parts.join(" \xB7 ")
|
|
2579
|
+
});
|
|
2580
|
+
}
|
|
2581
|
+
if (ai.finishReason)
|
|
2582
|
+
entries.push({
|
|
2583
|
+
key: "ai.finishReason",
|
|
2584
|
+
value: String(ai.finishReason)
|
|
2585
|
+
});
|
|
2586
|
+
if (ai.error)
|
|
2587
|
+
entries.push({
|
|
2588
|
+
key: "ai.error",
|
|
2589
|
+
value: String(ai.error)
|
|
2590
|
+
});
|
|
2591
|
+
if (ai.responseId)
|
|
2592
|
+
entries.push({
|
|
2593
|
+
key: "ai.responseId",
|
|
2594
|
+
value: String(ai.responseId)
|
|
2595
|
+
});
|
|
2596
|
+
return entries;
|
|
2597
|
+
}
|
|
2598
|
+
function prettyPrintWideEvent(event) {
|
|
2599
|
+
const { timestamp, level, service, environment, version, ...rest } = event;
|
|
2600
|
+
const ts = timestamp.slice(11, 23);
|
|
2601
|
+
const browser = isClient();
|
|
2602
|
+
const parts = [];
|
|
2603
|
+
const styles = [];
|
|
2604
|
+
if (browser) {
|
|
2605
|
+
const lc = getCssLevelColor(level);
|
|
2606
|
+
parts.push(`%c${ts}%c %c${level.toUpperCase()}%c %c[${escapeFormatString(String(service))}]%c`);
|
|
2607
|
+
styles.push(cssColors.dim, cssColors.reset, lc, cssColors.reset, cssColors.cyan, cssColors.reset);
|
|
2608
|
+
} else {
|
|
2609
|
+
const lc = getLevelColor(level);
|
|
2610
|
+
parts.push(`${colors.dim}${ts}${colors.reset} ${lc}${level.toUpperCase()}${colors.reset} ${colors.cyan}[${service}]${colors.reset}`);
|
|
2611
|
+
}
|
|
2612
|
+
if (rest.method && rest.path) {
|
|
2613
|
+
parts.push(browser ? ` ${escapeFormatString(String(rest.method))} ${escapeFormatString(String(rest.path))}` : ` ${rest.method} ${rest.path}`);
|
|
2614
|
+
delete rest.method;
|
|
2615
|
+
delete rest.path;
|
|
2616
|
+
}
|
|
2617
|
+
if (rest.status) {
|
|
2618
|
+
const sc = browser ? rest.status >= 400 ? cssColors.red : cssColors.green : rest.status >= 400 ? colors.red : colors.green;
|
|
2619
|
+
if (browser) {
|
|
2620
|
+
parts.push(` %c${rest.status}%c`);
|
|
2621
|
+
styles.push(sc, cssColors.reset);
|
|
2622
|
+
} else
|
|
2623
|
+
parts.push(` ${sc}${rest.status}${colors.reset}`);
|
|
2624
|
+
delete rest.status;
|
|
2625
|
+
}
|
|
2626
|
+
if (rest.duration) {
|
|
2627
|
+
if (browser) {
|
|
2628
|
+
parts.push(` %c${escapeFormatString(`in ${rest.duration}`)}%c`);
|
|
2629
|
+
styles.push(cssColors.dim, cssColors.reset);
|
|
2630
|
+
} else
|
|
2631
|
+
parts.push(` ${colors.dim}in ${rest.duration}${colors.reset}`);
|
|
2632
|
+
delete rest.duration;
|
|
2633
|
+
}
|
|
2634
|
+
console.log(parts.join(""), ...styles);
|
|
2635
|
+
const aiData = rest.ai;
|
|
2636
|
+
if (aiData && typeof aiData === "object")
|
|
2637
|
+
delete rest.ai;
|
|
2638
|
+
const restEntries = Object.entries(rest).filter(([_, v]) => v !== undefined);
|
|
2639
|
+
const aiEntries = aiData ? buildAIEntries(aiData) : [];
|
|
2640
|
+
const allEntries = [...restEntries.map(([key, value]) => ({
|
|
2641
|
+
key,
|
|
2642
|
+
value: formatValue(value)
|
|
2643
|
+
})), ...aiEntries];
|
|
2644
|
+
for (let i = 0;i < allEntries.length; i++) {
|
|
2645
|
+
const entry = allEntries[i];
|
|
2646
|
+
const hasChildren = entry.children && entry.children.length > 0;
|
|
2647
|
+
const prefix = i === allEntries.length - 1 && !hasChildren ? "\u2514\u2500" : "\u251C\u2500";
|
|
2648
|
+
if (browser) {
|
|
2649
|
+
const val = entry.value ? ` ${escapeFormatString(entry.value)}` : "";
|
|
2650
|
+
console.log(` %c${prefix}%c %c${escapeFormatString(entry.key)}:%c${val}`, cssColors.dim, cssColors.reset, cssColors.cyan, cssColors.reset);
|
|
2651
|
+
} else {
|
|
2652
|
+
const val = entry.value ? ` ${entry.value}` : "";
|
|
2653
|
+
console.log(` ${colors.dim}${prefix}${colors.reset} ${colors.cyan}${entry.key}:${colors.reset}${val}`);
|
|
2654
|
+
}
|
|
2655
|
+
if (hasChildren) {
|
|
2656
|
+
const connector = i === allEntries.length - 1 ? " " : "\u2502";
|
|
2657
|
+
for (let j = 0;j < entry.children.length; j++) {
|
|
2658
|
+
const child = entry.children[j];
|
|
2659
|
+
const childPrefix = j === entry.children.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
2660
|
+
if (browser)
|
|
2661
|
+
console.log(` %c${connector} ${childPrefix}%c ${escapeFormatString(child)}`, cssColors.dim, cssColors.reset);
|
|
2662
|
+
else
|
|
2663
|
+
console.log(` ${colors.dim}${connector} ${childPrefix}${colors.reset} ${child}`);
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
function createLogMethod(level) {
|
|
2669
|
+
return function logMethod(tagOrEvent, message) {
|
|
2670
|
+
if (typeof tagOrEvent === "string" && message !== undefined)
|
|
2671
|
+
emitTaggedLog(level, tagOrEvent, message);
|
|
2672
|
+
else if (typeof tagOrEvent === "object")
|
|
2673
|
+
emitWideEvent(level, tagOrEvent);
|
|
2674
|
+
else
|
|
2675
|
+
emitTaggedLog(level, "log", String(tagOrEvent));
|
|
2676
|
+
};
|
|
2677
|
+
}
|
|
2678
|
+
var _log = {
|
|
2679
|
+
info: createLogMethod("info"),
|
|
2680
|
+
error: createLogMethod("error"),
|
|
2681
|
+
warn: createLogMethod("warn"),
|
|
2682
|
+
debug: createLogMethod("debug")
|
|
2683
|
+
};
|
|
2684
|
+
var noopLogger = {
|
|
2685
|
+
set() {},
|
|
2686
|
+
error() {},
|
|
2687
|
+
info() {},
|
|
2688
|
+
warn() {},
|
|
2689
|
+
emit() {
|
|
2690
|
+
return null;
|
|
2691
|
+
},
|
|
2692
|
+
getContext() {
|
|
2693
|
+
return {};
|
|
2694
|
+
}
|
|
2695
|
+
};
|
|
2696
|
+
function createLogger(initialContext = {}, internalOptions) {
|
|
2697
|
+
if (!globalEnabled)
|
|
2698
|
+
return noopLogger;
|
|
2699
|
+
const deferDrain = internalOptions?._deferDrain ?? false;
|
|
2700
|
+
const startTime = Date.now();
|
|
2701
|
+
const context = { ...initialContext };
|
|
2702
|
+
let hasError = false;
|
|
2703
|
+
let hasWarn = false;
|
|
2704
|
+
let emitted = false;
|
|
2705
|
+
function addLog(level, message) {
|
|
2706
|
+
if (!Array.isArray(context.requestLogs))
|
|
2707
|
+
context.requestLogs = [];
|
|
2708
|
+
context.requestLogs.push({
|
|
2709
|
+
level,
|
|
2710
|
+
message,
|
|
2711
|
+
timestamp: isoNow()
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
return {
|
|
2715
|
+
set(data) {
|
|
2716
|
+
if (emitted) {
|
|
2717
|
+
const keys = Object.keys(data);
|
|
2718
|
+
warnPostEmit("log.set()", `Keys dropped: ${keys.length ? keys.join(", ") : "(empty)"}.`);
|
|
2719
|
+
return;
|
|
2720
|
+
}
|
|
2721
|
+
mergeInto(context, data);
|
|
2722
|
+
},
|
|
2723
|
+
error(error, errorContext) {
|
|
2724
|
+
if (emitted) {
|
|
2725
|
+
warnPostEmit("log.error()", `Keys dropped: ${(errorContext ? [...Object.keys(errorContext), "error"] : ["error"]).join(", ")}.`);
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
hasError = true;
|
|
2729
|
+
const err = typeof error === "string" ? new Error(error) : error;
|
|
2730
|
+
if (errorContext)
|
|
2731
|
+
mergeInto(context, errorContext);
|
|
2732
|
+
const errorObj = {
|
|
2733
|
+
name: err.name,
|
|
2734
|
+
message: err.message,
|
|
2735
|
+
stack: err.stack
|
|
2736
|
+
};
|
|
2737
|
+
const errRecord = err;
|
|
2738
|
+
for (const k of [
|
|
2739
|
+
"status",
|
|
2740
|
+
"statusText",
|
|
2741
|
+
"statusCode",
|
|
2742
|
+
"statusMessage",
|
|
2743
|
+
"data",
|
|
2744
|
+
"cause",
|
|
2745
|
+
"internal"
|
|
2746
|
+
])
|
|
2747
|
+
if (k in err)
|
|
2748
|
+
errorObj[k] = errRecord[k];
|
|
2749
|
+
if (isPlainObject(context.error))
|
|
2750
|
+
mergeInto(context.error, errorObj);
|
|
2751
|
+
else
|
|
2752
|
+
context.error = errorObj;
|
|
2753
|
+
},
|
|
2754
|
+
info(message, infoContext) {
|
|
2755
|
+
if (emitted) {
|
|
2756
|
+
warnPostEmit("log.info()", `Keys dropped: ${(infoContext ? ["message", ...Object.keys(infoContext).filter((k) => k !== "requestLogs")] : ["message"]).join(", ")}.`);
|
|
2757
|
+
return;
|
|
2758
|
+
}
|
|
2759
|
+
addLog("info", message);
|
|
2760
|
+
if (infoContext) {
|
|
2761
|
+
const { requestLogs: _, ...rest } = infoContext;
|
|
2762
|
+
mergeInto(context, rest);
|
|
2763
|
+
}
|
|
2764
|
+
},
|
|
2765
|
+
warn(message, warnContext) {
|
|
2766
|
+
if (emitted) {
|
|
2767
|
+
warnPostEmit("log.warn()", `Keys dropped: ${(warnContext ? ["message", ...Object.keys(warnContext).filter((k) => k !== "requestLogs")] : ["message"]).join(", ")}.`);
|
|
2768
|
+
return;
|
|
2769
|
+
}
|
|
2770
|
+
hasWarn = true;
|
|
2771
|
+
addLog("warn", message);
|
|
2772
|
+
if (warnContext) {
|
|
2773
|
+
const { requestLogs: _, ...rest } = warnContext;
|
|
2774
|
+
mergeInto(context, rest);
|
|
2775
|
+
}
|
|
2776
|
+
},
|
|
2777
|
+
emit(overrides) {
|
|
2778
|
+
if (emitted) {
|
|
2779
|
+
warnPostEmit("log.emit()", "Ignoring duplicate emit.");
|
|
2780
|
+
return null;
|
|
2781
|
+
}
|
|
2782
|
+
const durationMs = Date.now() - startTime;
|
|
2783
|
+
const level = hasError ? "error" : hasWarn ? "warn" : "info";
|
|
2784
|
+
let forceKeep = false;
|
|
2785
|
+
if (overrides?._forceKeep)
|
|
2786
|
+
forceKeep = true;
|
|
2787
|
+
else if (globalSampling.keep?.length)
|
|
2788
|
+
forceKeep = shouldKeep({
|
|
2789
|
+
status: overrides?.status ?? context.status,
|
|
2790
|
+
duration: durationMs,
|
|
2791
|
+
path: context.path,
|
|
2792
|
+
method: context.method,
|
|
2793
|
+
context
|
|
2794
|
+
});
|
|
2795
|
+
if (!forceKeep && !shouldSample(level)) {
|
|
2796
|
+
emitted = true;
|
|
2797
|
+
return null;
|
|
2798
|
+
}
|
|
2799
|
+
if (overrides) {
|
|
2800
|
+
const obj = overrides;
|
|
2801
|
+
for (const key in obj)
|
|
2802
|
+
if (key !== "_forceKeep")
|
|
2803
|
+
context[key] = obj[key];
|
|
2804
|
+
}
|
|
2805
|
+
context.duration = formatDuration(durationMs);
|
|
2806
|
+
const wide = emitWideEvent(level, context, deferDrain, true);
|
|
2807
|
+
emitted = true;
|
|
2808
|
+
return wide;
|
|
2809
|
+
},
|
|
2810
|
+
getContext() {
|
|
2811
|
+
return { ...context };
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
}
|
|
2815
|
+
if (typeof __EVLOG_CONFIG__ !== "undefined")
|
|
2816
|
+
initLogger(__EVLOG_CONFIG__);
|
|
2022
2817
|
// src/link.tsx
|
|
2023
2818
|
import {
|
|
2024
2819
|
createContext,
|
|
@@ -2087,6 +2882,52 @@ function buildElement(route, data, rootLayout) {
|
|
|
2087
2882
|
return element;
|
|
2088
2883
|
}
|
|
2089
2884
|
|
|
2885
|
+
// src/context-logger.ts
|
|
2886
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
2887
|
+
|
|
2888
|
+
// ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/elysia/index.mjs
|
|
2889
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
2890
|
+
import { Elysia } from "elysia";
|
|
2891
|
+
var storage = new AsyncLocalStorage2;
|
|
2892
|
+
var activeLoggers = /* @__PURE__ */ new WeakSet;
|
|
2893
|
+
function useLogger2() {
|
|
2894
|
+
const logger = storage.getStore();
|
|
2895
|
+
if (!logger || !activeLoggers.has(logger))
|
|
2896
|
+
throw new Error("[evlog] useLogger() was called outside of an evlog plugin context. Make sure app.use(evlog()) is registered before your routes.");
|
|
2897
|
+
return logger;
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
// src/context-logger.ts
|
|
2901
|
+
var noopLogger2 = {
|
|
2902
|
+
set: () => {},
|
|
2903
|
+
error: () => {},
|
|
2904
|
+
info: () => {},
|
|
2905
|
+
warn: () => {},
|
|
2906
|
+
emit: () => null,
|
|
2907
|
+
getContext: () => ({}),
|
|
2908
|
+
fork: (_label, fn) => fn()
|
|
2909
|
+
};
|
|
2910
|
+
var syntheticRenderStorage = new AsyncLocalStorage3;
|
|
2911
|
+
function useLogger3() {
|
|
2912
|
+
try {
|
|
2913
|
+
return useLogger2();
|
|
2914
|
+
} catch {
|
|
2915
|
+
return syntheticRenderStorage.getStore() ?? noopLogger2;
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
async function runInSyntheticRenderScope(fn, initialContext) {
|
|
2919
|
+
const logger = createLogger(initialContext);
|
|
2920
|
+
try {
|
|
2921
|
+
const result = await syntheticRenderStorage.run(logger, () => Promise.resolve(fn()));
|
|
2922
|
+
logger.emit();
|
|
2923
|
+
return result;
|
|
2924
|
+
} catch (err) {
|
|
2925
|
+
logger.error(err instanceof Error ? err : new Error(String(err)));
|
|
2926
|
+
logger.emit();
|
|
2927
|
+
throw err;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2090
2931
|
// src/render/loaders.ts
|
|
2091
2932
|
function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
2092
2933
|
const cache = new Map;
|
|
@@ -2112,7 +2953,7 @@ function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
|
2112
2953
|
}
|
|
2113
2954
|
async function runLoaders(route, ctx, _rootLayout) {
|
|
2114
2955
|
try {
|
|
2115
|
-
const ctxRecord = ctx;
|
|
2956
|
+
const ctxRecord = { ...ctx, log: useLogger3() };
|
|
2116
2957
|
const loaderMap = new Map;
|
|
2117
2958
|
let accumulatedParentPromise = Promise.resolve({});
|
|
2118
2959
|
for (const r of route.routeChain) {
|
|
@@ -2230,7 +3071,7 @@ async function renderForPath(route, params, root, origin, basePath) {
|
|
|
2230
3071
|
set: { headers: {} },
|
|
2231
3072
|
path: resolvedPath
|
|
2232
3073
|
};
|
|
2233
|
-
const prepared = await prepareRender(route, ctx, root, basePath);
|
|
3074
|
+
const prepared = await runInSyntheticRenderScope(() => prepareRender(route, ctx, root, basePath), { route: route.pattern });
|
|
2234
3075
|
if (prepared instanceof Response) {
|
|
2235
3076
|
throw prepared;
|
|
2236
3077
|
}
|
|
@@ -2395,7 +3236,9 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
2395
3236
|
publicPath,
|
|
2396
3237
|
basePath
|
|
2397
3238
|
});
|
|
2398
|
-
const
|
|
3239
|
+
const publicFavicon = join6(rootDir, "public", "favicon.ico");
|
|
3240
|
+
const faviconHref = existsSync5(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
3241
|
+
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref);
|
|
2399
3242
|
setProductionTemplateContent(shellHtml);
|
|
2400
3243
|
const publicSrcDir = join6(rootDir, "public");
|
|
2401
3244
|
if (existsSync5(publicSrcDir)) {
|
|
@@ -2453,7 +3296,7 @@ var configSchema = t.Object({
|
|
|
2453
3296
|
import { existsSync as existsSync6 } from "fs";
|
|
2454
3297
|
import { readdir } from "fs/promises";
|
|
2455
3298
|
import { join as join7, parse } from "path";
|
|
2456
|
-
import { Elysia } from "elysia";
|
|
3299
|
+
import { Elysia as Elysia2, t as t2 } from "elysia";
|
|
2457
3300
|
|
|
2458
3301
|
// src/internal.ts
|
|
2459
3302
|
var _compileCtx = null;
|
|
@@ -2581,6 +3424,7 @@ async function buildDevRoute(absolutePath, relativePath, root) {
|
|
|
2581
3424
|
routeChain
|
|
2582
3425
|
};
|
|
2583
3426
|
}
|
|
3427
|
+
var TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
|
|
2584
3428
|
async function collectPageFilePaths(dir) {
|
|
2585
3429
|
const files = [];
|
|
2586
3430
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|