@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/build/index.js
CHANGED
|
@@ -1468,11 +1468,13 @@ function generateIndexHtml() {
|
|
|
1468
1468
|
</html>
|
|
1469
1469
|
`;
|
|
1470
1470
|
}
|
|
1471
|
-
function generateProdIndexHtml(entryChunk, cssChunks, buildId) {
|
|
1471
|
+
function generateProdIndexHtml(entryChunk, cssChunks, buildId, faviconHref) {
|
|
1472
1472
|
const cssLinks = cssChunks.map((c) => ` <link rel="stylesheet" crossorigin href="${c}">`).join(`
|
|
1473
1473
|
`);
|
|
1474
1474
|
const scriptTag = `<script type="module" crossorigin src="${entryChunk}"></script>`;
|
|
1475
1475
|
const buildIdMeta = buildId ? ` <meta name="furin-build-id" content="${escapeHtml(buildId)}">
|
|
1476
|
+
` : "";
|
|
1477
|
+
const faviconLink = faviconHref ? ` <link rel="icon" href="${escapeHtml(faviconHref)}">
|
|
1476
1478
|
` : "";
|
|
1477
1479
|
return `<!DOCTYPE html>
|
|
1478
1480
|
<html lang="en">
|
|
@@ -1480,7 +1482,7 @@ function generateProdIndexHtml(entryChunk, cssChunks, buildId) {
|
|
|
1480
1482
|
<meta charset="UTF-8">
|
|
1481
1483
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1482
1484
|
${THEME_INIT_SCRIPT}
|
|
1483
|
-
${buildIdMeta}${cssLinks ? `${cssLinks}
|
|
1485
|
+
${buildIdMeta}${faviconLink}${cssLinks ? `${cssLinks}
|
|
1484
1486
|
` : ""} <!--ssr-head-->
|
|
1485
1487
|
</head>
|
|
1486
1488
|
<body>
|
|
@@ -2098,7 +2100,800 @@ function assembleHTML(template, headData, reactHtml, data) {
|
|
|
2098
2100
|
// src/render/index.ts
|
|
2099
2101
|
import { createElement as createElement2 } from "react";
|
|
2100
2102
|
import { renderToReadableStream } from "react-dom/server";
|
|
2103
|
+
// ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/utils.mjs
|
|
2104
|
+
function formatDuration(ms) {
|
|
2105
|
+
if (ms < 1000)
|
|
2106
|
+
return `${Math.round(ms)}ms`;
|
|
2107
|
+
return `${(ms / 1000).toFixed(2)}s`;
|
|
2108
|
+
}
|
|
2109
|
+
function isClient() {
|
|
2110
|
+
return typeof window !== "undefined";
|
|
2111
|
+
}
|
|
2112
|
+
function isDev() {
|
|
2113
|
+
if (typeof process !== "undefined")
|
|
2114
|
+
return true;
|
|
2115
|
+
if (typeof window !== "undefined")
|
|
2116
|
+
return true;
|
|
2117
|
+
return false;
|
|
2118
|
+
}
|
|
2119
|
+
function detectEnvironment() {
|
|
2120
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
2121
|
+
const defaultEnvironment = isDev() ? "development" : "production";
|
|
2122
|
+
return {
|
|
2123
|
+
environment: env.NODE_ENV || defaultEnvironment,
|
|
2124
|
+
service: env.SERVICE_NAME || "app",
|
|
2125
|
+
version: env.APP_VERSION,
|
|
2126
|
+
commitHash: env.COMMIT_SHA || env.GITHUB_SHA || env.VERCEL_GIT_COMMIT_SHA || env.CF_PAGES_COMMIT_SHA,
|
|
2127
|
+
region: env.VERCEL_REGION || env.AWS_REGION || env.FLY_REGION || env.CF_REGION
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2130
|
+
var LEVEL_ORDER = {
|
|
2131
|
+
debug: 0,
|
|
2132
|
+
info: 1,
|
|
2133
|
+
warn: 2,
|
|
2134
|
+
error: 3
|
|
2135
|
+
};
|
|
2136
|
+
function isLevelEnabled(level, minLevel) {
|
|
2137
|
+
return LEVEL_ORDER[level] >= LEVEL_ORDER[minLevel];
|
|
2138
|
+
}
|
|
2139
|
+
function getConsoleMethod(level) {
|
|
2140
|
+
return level;
|
|
2141
|
+
}
|
|
2142
|
+
var colors = {
|
|
2143
|
+
reset: "\x1B[0m",
|
|
2144
|
+
bold: "\x1B[1m",
|
|
2145
|
+
dim: "\x1B[2m",
|
|
2146
|
+
red: "\x1B[31m",
|
|
2147
|
+
green: "\x1B[32m",
|
|
2148
|
+
yellow: "\x1B[33m",
|
|
2149
|
+
blue: "\x1B[34m",
|
|
2150
|
+
magenta: "\x1B[35m",
|
|
2151
|
+
cyan: "\x1B[36m",
|
|
2152
|
+
white: "\x1B[37m",
|
|
2153
|
+
gray: "\x1B[90m"
|
|
2154
|
+
};
|
|
2155
|
+
var levelColorMap = {
|
|
2156
|
+
error: colors.red,
|
|
2157
|
+
warn: colors.yellow,
|
|
2158
|
+
info: colors.cyan,
|
|
2159
|
+
debug: colors.gray
|
|
2160
|
+
};
|
|
2161
|
+
function getLevelColor(level) {
|
|
2162
|
+
return levelColorMap[level] ?? colors.white;
|
|
2163
|
+
}
|
|
2164
|
+
var cssColors = {
|
|
2165
|
+
dim: "color: #6b7280",
|
|
2166
|
+
red: "color: #ef4444; font-weight: bold",
|
|
2167
|
+
green: "color: #22c55e",
|
|
2168
|
+
yellow: "color: #f59e0b; font-weight: bold",
|
|
2169
|
+
cyan: "color: #06b6d4; font-weight: bold",
|
|
2170
|
+
gray: "color: #6b7280; font-weight: bold",
|
|
2171
|
+
reset: "color: inherit; font-weight: normal"
|
|
2172
|
+
};
|
|
2173
|
+
var cssLevelColorMap = {
|
|
2174
|
+
error: cssColors.red,
|
|
2175
|
+
warn: cssColors.yellow,
|
|
2176
|
+
info: cssColors.cyan,
|
|
2177
|
+
debug: cssColors.gray
|
|
2178
|
+
};
|
|
2179
|
+
function getCssLevelColor(level) {
|
|
2180
|
+
return cssLevelColorMap[level] ?? cssColors.reset;
|
|
2181
|
+
}
|
|
2182
|
+
function escapeFormatString(str) {
|
|
2183
|
+
return str.replace(/%/g, "%%");
|
|
2184
|
+
}
|
|
2185
|
+
var patternCache = /* @__PURE__ */ new Map;
|
|
2186
|
+
function matchesPattern(path, pattern) {
|
|
2187
|
+
let regex = patternCache.get(pattern);
|
|
2188
|
+
if (!regex) {
|
|
2189
|
+
const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "{{GLOBSTAR}}").replace(/\*/g, "[^/]*").replace(/{{GLOBSTAR}}/g, ".*").replace(/\?/g, "[^/]");
|
|
2190
|
+
regex = new RegExp(`^${regexPattern}$`);
|
|
2191
|
+
patternCache.set(pattern, regex);
|
|
2192
|
+
}
|
|
2193
|
+
return regex.test(path);
|
|
2194
|
+
}
|
|
2101
2195
|
|
|
2196
|
+
// ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/logger-DnobymUQ.mjs
|
|
2197
|
+
var DEFAULT_REPLACEMENT = "[REDACTED]";
|
|
2198
|
+
var builtinPatterns = {
|
|
2199
|
+
creditCard: {
|
|
2200
|
+
pattern: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,
|
|
2201
|
+
mask: (m) => `****${m.replace(/[\s-]/g, "").slice(-4)}`
|
|
2202
|
+
},
|
|
2203
|
+
email: {
|
|
2204
|
+
pattern: /[\w.+-]+@[\w-]+\.[\w.]+/g,
|
|
2205
|
+
mask: (m) => {
|
|
2206
|
+
if (m.indexOf("@") < 1)
|
|
2207
|
+
return "***@***";
|
|
2208
|
+
const tld = m.slice(m.lastIndexOf("."));
|
|
2209
|
+
return `${m[0]}***@***${tld}`;
|
|
2210
|
+
}
|
|
2211
|
+
},
|
|
2212
|
+
ipv4: {
|
|
2213
|
+
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,
|
|
2214
|
+
mask: (m) => `***.***.***.${m.split(".").pop()}`
|
|
2215
|
+
},
|
|
2216
|
+
phone: {
|
|
2217
|
+
pattern: /(?:\+\d{1,3}[\s.-]?)?\(?\d{1,4}\)?[\s.-]?\d{2,4}[\s.-]?\d{2,4}[\s.-]?\d{2,4}\b/g,
|
|
2218
|
+
mask: (m) => {
|
|
2219
|
+
const digits = m.replace(/[^\d]/g, "");
|
|
2220
|
+
if (m.startsWith("+") && digits.length > 4) {
|
|
2221
|
+
const ccMatch = m.match(/^\+\d{1,3}/);
|
|
2222
|
+
return `${ccMatch ? ccMatch[0] : "+"}******${digits.slice(-2)}`;
|
|
2223
|
+
}
|
|
2224
|
+
if (digits.length > 2)
|
|
2225
|
+
return `${"*".repeat(digits.length - 2)}${digits.slice(-2)}`;
|
|
2226
|
+
return "***";
|
|
2227
|
+
}
|
|
2228
|
+
},
|
|
2229
|
+
jwt: {
|
|
2230
|
+
pattern: /\beyJ[\w-]*\.[\w-]*\.[\w-]*\b/g,
|
|
2231
|
+
mask: () => "eyJ***.***"
|
|
2232
|
+
},
|
|
2233
|
+
bearer: {
|
|
2234
|
+
pattern: /\bBearer\s+[\w\-.~+/]{8,}=*/gi,
|
|
2235
|
+
mask: () => "Bearer ***"
|
|
2236
|
+
},
|
|
2237
|
+
iban: {
|
|
2238
|
+
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,
|
|
2239
|
+
mask: (m) => {
|
|
2240
|
+
const clean = m.replace(/[\s-]/g, "");
|
|
2241
|
+
return `${clean.slice(0, 4)}****${clean.slice(-3)}`;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2245
|
+
function resolveRedactConfig(input) {
|
|
2246
|
+
if (input === undefined || input === false)
|
|
2247
|
+
return;
|
|
2248
|
+
if (input === true)
|
|
2249
|
+
return { _maskers: allBuiltinMaskers() };
|
|
2250
|
+
if (input.builtins === false)
|
|
2251
|
+
return input;
|
|
2252
|
+
const maskers = Array.isArray(input.builtins) ? input.builtins.map((name) => builtinPatterns[name]).filter(Boolean).map((b) => [cloneRegex(b.pattern), b.mask]) : allBuiltinMaskers();
|
|
2253
|
+
return {
|
|
2254
|
+
...input,
|
|
2255
|
+
_maskers: maskers
|
|
2256
|
+
};
|
|
2257
|
+
}
|
|
2258
|
+
function allBuiltinMaskers() {
|
|
2259
|
+
return Object.values(builtinPatterns).map((b) => [cloneRegex(b.pattern), b.mask]);
|
|
2260
|
+
}
|
|
2261
|
+
function cloneRegex(re) {
|
|
2262
|
+
return new RegExp(re.source, re.flags);
|
|
2263
|
+
}
|
|
2264
|
+
function redactEvent(event, config) {
|
|
2265
|
+
const replacement = config.replacement ?? DEFAULT_REPLACEMENT;
|
|
2266
|
+
if (config.paths?.length)
|
|
2267
|
+
for (const path of config.paths)
|
|
2268
|
+
redactPath(event, path.split("."), replacement);
|
|
2269
|
+
if (config._maskers?.length)
|
|
2270
|
+
applyMaskersToTree(event, config._maskers);
|
|
2271
|
+
if (config.patterns?.length)
|
|
2272
|
+
redactPatterns(event, config.patterns, replacement);
|
|
2273
|
+
}
|
|
2274
|
+
function redactPath(obj, segments, replacement) {
|
|
2275
|
+
let current = obj;
|
|
2276
|
+
for (let i = 0;i < segments.length - 1; i++) {
|
|
2277
|
+
if (current === null || current === undefined || typeof current !== "object")
|
|
2278
|
+
return;
|
|
2279
|
+
current = current[segments[i]];
|
|
2280
|
+
}
|
|
2281
|
+
if (current === null || current === undefined || typeof current !== "object")
|
|
2282
|
+
return;
|
|
2283
|
+
const leaf = segments[segments.length - 1];
|
|
2284
|
+
if (leaf in current)
|
|
2285
|
+
current[leaf] = replacement;
|
|
2286
|
+
}
|
|
2287
|
+
function redactPatterns(obj, patterns, replacement) {
|
|
2288
|
+
if (obj === null || obj === undefined)
|
|
2289
|
+
return;
|
|
2290
|
+
if (Array.isArray(obj)) {
|
|
2291
|
+
for (let i = 0;i < obj.length; i++)
|
|
2292
|
+
if (typeof obj[i] === "string")
|
|
2293
|
+
obj[i] = applyPatterns(obj[i], patterns, replacement);
|
|
2294
|
+
else if (typeof obj[i] === "object")
|
|
2295
|
+
redactPatterns(obj[i], patterns, replacement);
|
|
2296
|
+
return;
|
|
2297
|
+
}
|
|
2298
|
+
if (typeof obj === "object") {
|
|
2299
|
+
const record = obj;
|
|
2300
|
+
for (const key in record) {
|
|
2301
|
+
const val = record[key];
|
|
2302
|
+
if (typeof val === "string")
|
|
2303
|
+
record[key] = applyPatterns(val, patterns, replacement);
|
|
2304
|
+
else if (typeof val === "object")
|
|
2305
|
+
redactPatterns(val, patterns, replacement);
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
function applyPatterns(value, patterns, replacement) {
|
|
2310
|
+
let result = value;
|
|
2311
|
+
for (const pattern of patterns) {
|
|
2312
|
+
pattern.lastIndex = 0;
|
|
2313
|
+
result = result.replace(pattern, replacement);
|
|
2314
|
+
}
|
|
2315
|
+
return result;
|
|
2316
|
+
}
|
|
2317
|
+
function applyMaskersToTree(obj, maskers) {
|
|
2318
|
+
if (obj === null || obj === undefined)
|
|
2319
|
+
return;
|
|
2320
|
+
if (Array.isArray(obj)) {
|
|
2321
|
+
for (let i = 0;i < obj.length; i++)
|
|
2322
|
+
if (typeof obj[i] === "string")
|
|
2323
|
+
obj[i] = applyMaskers(obj[i], maskers);
|
|
2324
|
+
else if (typeof obj[i] === "object")
|
|
2325
|
+
applyMaskersToTree(obj[i], maskers);
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
if (typeof obj === "object") {
|
|
2329
|
+
const record = obj;
|
|
2330
|
+
for (const key in record) {
|
|
2331
|
+
const val = record[key];
|
|
2332
|
+
if (typeof val === "string")
|
|
2333
|
+
record[key] = applyMaskers(val, maskers);
|
|
2334
|
+
else if (typeof val === "object")
|
|
2335
|
+
applyMaskersToTree(val, maskers);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
function applyMaskers(value, maskers) {
|
|
2340
|
+
let result = value;
|
|
2341
|
+
for (const [pattern, mask] of maskers) {
|
|
2342
|
+
pattern.lastIndex = 0;
|
|
2343
|
+
result = result.replace(pattern, mask);
|
|
2344
|
+
}
|
|
2345
|
+
return result;
|
|
2346
|
+
}
|
|
2347
|
+
function isPlainObject(val) {
|
|
2348
|
+
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
2349
|
+
}
|
|
2350
|
+
var _tsDate = /* @__PURE__ */ new Date;
|
|
2351
|
+
function isoNow() {
|
|
2352
|
+
_tsDate.setTime(Date.now());
|
|
2353
|
+
return _tsDate.toISOString();
|
|
2354
|
+
}
|
|
2355
|
+
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).";
|
|
2356
|
+
function warnPostEmit(method, detail) {
|
|
2357
|
+
console.warn(`[evlog] ${method} called after the wide event was emitted \u2014 ${detail} This data will not appear in observability. ${POST_EMIT_FORK_HINT}`);
|
|
2358
|
+
}
|
|
2359
|
+
function mergeInto(target, source) {
|
|
2360
|
+
for (const key in source) {
|
|
2361
|
+
const sourceVal = source[key];
|
|
2362
|
+
if (sourceVal === undefined || sourceVal === null)
|
|
2363
|
+
continue;
|
|
2364
|
+
const targetVal = target[key];
|
|
2365
|
+
if (isPlainObject(sourceVal) && isPlainObject(targetVal))
|
|
2366
|
+
mergeInto(targetVal, sourceVal);
|
|
2367
|
+
else if (Array.isArray(targetVal) && Array.isArray(sourceVal))
|
|
2368
|
+
target[key] = [...targetVal, ...sourceVal];
|
|
2369
|
+
else
|
|
2370
|
+
target[key] = sourceVal;
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
var globalEnv = {
|
|
2374
|
+
service: "app",
|
|
2375
|
+
environment: "development"
|
|
2376
|
+
};
|
|
2377
|
+
var globalPretty = isDev();
|
|
2378
|
+
var globalSampling = {};
|
|
2379
|
+
var globalStringify = true;
|
|
2380
|
+
var globalDrain;
|
|
2381
|
+
var globalRedact;
|
|
2382
|
+
var globalEnabled = true;
|
|
2383
|
+
var globalSilent = false;
|
|
2384
|
+
var globalMinLevel = "debug";
|
|
2385
|
+
function initLogger(config = {}) {
|
|
2386
|
+
globalEnabled = config.enabled ?? true;
|
|
2387
|
+
const detected = detectEnvironment();
|
|
2388
|
+
globalEnv = {
|
|
2389
|
+
service: config.env?.service ?? detected.service ?? "app",
|
|
2390
|
+
environment: config.env?.environment ?? detected.environment ?? "development",
|
|
2391
|
+
version: config.env?.version ?? detected.version,
|
|
2392
|
+
commitHash: config.env?.commitHash ?? detected.commitHash,
|
|
2393
|
+
region: config.env?.region ?? detected.region
|
|
2394
|
+
};
|
|
2395
|
+
globalPretty = config.pretty ?? isDev();
|
|
2396
|
+
globalSampling = config.sampling ?? {};
|
|
2397
|
+
globalStringify = config.stringify ?? true;
|
|
2398
|
+
globalDrain = config.drain;
|
|
2399
|
+
globalRedact = resolveRedactConfig(config.redact ?? !isDev());
|
|
2400
|
+
globalSilent = config.silent ?? false;
|
|
2401
|
+
globalMinLevel = config.minLevel ?? "debug";
|
|
2402
|
+
if (globalSilent && !globalDrain && !config._suppressDrainWarning)
|
|
2403
|
+
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).");
|
|
2404
|
+
}
|
|
2405
|
+
function shouldSample(level) {
|
|
2406
|
+
const { rates } = globalSampling;
|
|
2407
|
+
if (!rates)
|
|
2408
|
+
return true;
|
|
2409
|
+
const percentage = level === "error" && rates.error === undefined ? 100 : rates[level] ?? 100;
|
|
2410
|
+
if (percentage <= 0)
|
|
2411
|
+
return false;
|
|
2412
|
+
if (percentage >= 100)
|
|
2413
|
+
return true;
|
|
2414
|
+
return Math.random() * 100 < percentage;
|
|
2415
|
+
}
|
|
2416
|
+
function shouldKeep(ctx) {
|
|
2417
|
+
const { keep } = globalSampling;
|
|
2418
|
+
if (!keep?.length)
|
|
2419
|
+
return false;
|
|
2420
|
+
return keep.some((condition) => {
|
|
2421
|
+
if (condition.status !== undefined && ctx.status !== undefined && ctx.status >= condition.status)
|
|
2422
|
+
return true;
|
|
2423
|
+
if (condition.duration !== undefined && ctx.duration !== undefined && ctx.duration >= condition.duration)
|
|
2424
|
+
return true;
|
|
2425
|
+
if (condition.path && ctx.path && matchesPattern(ctx.path, condition.path))
|
|
2426
|
+
return true;
|
|
2427
|
+
return false;
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
function emitWideEvent(level, event, deferDrain = false, ownsEvent = false) {
|
|
2431
|
+
if (!globalEnabled)
|
|
2432
|
+
return null;
|
|
2433
|
+
if (!ownsEvent) {
|
|
2434
|
+
if (!isLevelEnabled(level, globalMinLevel))
|
|
2435
|
+
return null;
|
|
2436
|
+
if (!shouldSample(level))
|
|
2437
|
+
return null;
|
|
2438
|
+
}
|
|
2439
|
+
let formatted;
|
|
2440
|
+
if (ownsEvent) {
|
|
2441
|
+
event.timestamp = isoNow();
|
|
2442
|
+
event.level = level;
|
|
2443
|
+
if (event.service === undefined)
|
|
2444
|
+
event.service = globalEnv.service;
|
|
2445
|
+
if (event.environment === undefined)
|
|
2446
|
+
event.environment = globalEnv.environment;
|
|
2447
|
+
if (globalEnv.version !== undefined && event.version === undefined)
|
|
2448
|
+
event.version = globalEnv.version;
|
|
2449
|
+
if (globalEnv.commitHash !== undefined && event.commitHash === undefined)
|
|
2450
|
+
event.commitHash = globalEnv.commitHash;
|
|
2451
|
+
if (globalEnv.region !== undefined && event.region === undefined)
|
|
2452
|
+
event.region = globalEnv.region;
|
|
2453
|
+
formatted = event;
|
|
2454
|
+
} else
|
|
2455
|
+
formatted = {
|
|
2456
|
+
timestamp: isoNow(),
|
|
2457
|
+
level,
|
|
2458
|
+
...globalEnv,
|
|
2459
|
+
...event
|
|
2460
|
+
};
|
|
2461
|
+
if (globalRedact)
|
|
2462
|
+
redactEvent(formatted, globalRedact);
|
|
2463
|
+
if (!globalSilent)
|
|
2464
|
+
if (globalPretty)
|
|
2465
|
+
prettyPrintWideEvent(formatted);
|
|
2466
|
+
else if (globalStringify)
|
|
2467
|
+
console[getConsoleMethod(level)](JSON.stringify(formatted));
|
|
2468
|
+
else
|
|
2469
|
+
console[getConsoleMethod(level)](formatted);
|
|
2470
|
+
if (globalDrain && !deferDrain)
|
|
2471
|
+
Promise.resolve(globalDrain({ event: formatted })).catch((err) => {
|
|
2472
|
+
console.error("[evlog] drain failed:", err);
|
|
2473
|
+
});
|
|
2474
|
+
return formatted;
|
|
2475
|
+
}
|
|
2476
|
+
function emitTaggedLog(level, tag, message) {
|
|
2477
|
+
if (!globalEnabled)
|
|
2478
|
+
return;
|
|
2479
|
+
if (globalPretty && !globalSilent) {
|
|
2480
|
+
if (!isLevelEnabled(level, globalMinLevel))
|
|
2481
|
+
return;
|
|
2482
|
+
if (!shouldSample(level))
|
|
2483
|
+
return;
|
|
2484
|
+
if (isClient()) {
|
|
2485
|
+
const levelColor = getCssLevelColor(level);
|
|
2486
|
+
const timestamp = isoNow().slice(11, 23);
|
|
2487
|
+
console.log(`%c${timestamp}%c %c[${escapeFormatString(tag)}]%c ${escapeFormatString(message)}`, cssColors.dim, cssColors.reset, levelColor, cssColors.reset);
|
|
2488
|
+
} else {
|
|
2489
|
+
const color = getLevelColor(level);
|
|
2490
|
+
const timestamp = isoNow().slice(11, 23);
|
|
2491
|
+
console.log(`${colors.dim}${timestamp}${colors.reset} ${color}[${tag}]${colors.reset} ${message}`);
|
|
2492
|
+
}
|
|
2493
|
+
return;
|
|
2494
|
+
}
|
|
2495
|
+
emitWideEvent(level, {
|
|
2496
|
+
tag,
|
|
2497
|
+
message
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
function formatValue(value) {
|
|
2501
|
+
if (value === null || value === undefined)
|
|
2502
|
+
return String(value);
|
|
2503
|
+
if (typeof value === "object") {
|
|
2504
|
+
const pairs = [];
|
|
2505
|
+
for (const [k, v] of Object.entries(value))
|
|
2506
|
+
if (v !== undefined && v !== null)
|
|
2507
|
+
if (typeof v === "object")
|
|
2508
|
+
pairs.push(`${k}=${JSON.stringify(v)}`);
|
|
2509
|
+
else
|
|
2510
|
+
pairs.push(`${k}=${v}`);
|
|
2511
|
+
return pairs.join(" ");
|
|
2512
|
+
}
|
|
2513
|
+
return String(value);
|
|
2514
|
+
}
|
|
2515
|
+
function formatCost(cost) {
|
|
2516
|
+
if (cost < 0.01)
|
|
2517
|
+
return `$${cost.toFixed(6)}`;
|
|
2518
|
+
if (cost < 1)
|
|
2519
|
+
return `$${cost.toFixed(4)}`;
|
|
2520
|
+
return `$${cost.toFixed(2)}`;
|
|
2521
|
+
}
|
|
2522
|
+
function buildAIEntries(ai) {
|
|
2523
|
+
const entries = [];
|
|
2524
|
+
const headerParts = [];
|
|
2525
|
+
if (ai.model) {
|
|
2526
|
+
let m = String(ai.model);
|
|
2527
|
+
if (ai.provider)
|
|
2528
|
+
m += ` (${ai.provider})`;
|
|
2529
|
+
headerParts.push(m);
|
|
2530
|
+
}
|
|
2531
|
+
if (ai.calls)
|
|
2532
|
+
headerParts.push(`${ai.calls} call${ai.calls > 1 ? "s" : ""}`);
|
|
2533
|
+
if (ai.steps && ai.steps > 1)
|
|
2534
|
+
headerParts.push(`${ai.steps} steps`);
|
|
2535
|
+
entries.push({
|
|
2536
|
+
key: "ai",
|
|
2537
|
+
value: headerParts.join(" \xB7 ")
|
|
2538
|
+
});
|
|
2539
|
+
const inputTokens = ai.inputTokens;
|
|
2540
|
+
const outputTokens = ai.outputTokens;
|
|
2541
|
+
const totalTokens = ai.totalTokens;
|
|
2542
|
+
if (inputTokens !== undefined && outputTokens !== undefined) {
|
|
2543
|
+
let tokLine = `${inputTokens} in \u2192 ${outputTokens} out`;
|
|
2544
|
+
if (totalTokens)
|
|
2545
|
+
tokLine += ` (${totalTokens} total)`;
|
|
2546
|
+
const extras = [];
|
|
2547
|
+
if (ai.cacheReadTokens)
|
|
2548
|
+
extras.push(`${ai.cacheReadTokens} cache read`);
|
|
2549
|
+
if (ai.cacheWriteTokens)
|
|
2550
|
+
extras.push(`${ai.cacheWriteTokens} cache write`);
|
|
2551
|
+
if (ai.reasoningTokens)
|
|
2552
|
+
extras.push(`${ai.reasoningTokens} reasoning`);
|
|
2553
|
+
if (extras.length)
|
|
2554
|
+
tokLine += ` \xB7 ${extras.join(" \xB7 ")}`;
|
|
2555
|
+
entries.push({
|
|
2556
|
+
key: "ai.tokens",
|
|
2557
|
+
value: tokLine
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
const msFirst = ai.msToFirstChunk;
|
|
2561
|
+
const msFinish = ai.msToFinish;
|
|
2562
|
+
const tps = ai.tokensPerSecond;
|
|
2563
|
+
if (msFirst !== undefined || msFinish !== undefined) {
|
|
2564
|
+
const parts = [];
|
|
2565
|
+
if (msFirst !== undefined)
|
|
2566
|
+
parts.push(`${formatDuration(msFirst)} to first chunk`);
|
|
2567
|
+
if (msFinish !== undefined)
|
|
2568
|
+
parts.push(`${formatDuration(msFinish)} total`);
|
|
2569
|
+
let streamLine = parts.join(" \u2192 ");
|
|
2570
|
+
if (tps)
|
|
2571
|
+
streamLine += ` \xB7 ${tps} tok/s`;
|
|
2572
|
+
entries.push({
|
|
2573
|
+
key: "ai.streaming",
|
|
2574
|
+
value: streamLine
|
|
2575
|
+
});
|
|
2576
|
+
}
|
|
2577
|
+
if (ai.estimatedCost !== undefined)
|
|
2578
|
+
entries.push({
|
|
2579
|
+
key: "ai.cost",
|
|
2580
|
+
value: formatCost(ai.estimatedCost)
|
|
2581
|
+
});
|
|
2582
|
+
if (ai.totalDurationMs !== undefined)
|
|
2583
|
+
entries.push({
|
|
2584
|
+
key: "ai.totalDuration",
|
|
2585
|
+
value: formatDuration(ai.totalDurationMs)
|
|
2586
|
+
});
|
|
2587
|
+
const toolCalls = ai.toolCalls;
|
|
2588
|
+
const tools = ai.tools;
|
|
2589
|
+
const hasInputs = toolCalls?.length ? typeof toolCalls[0] === "object" : false;
|
|
2590
|
+
if (tools?.length) {
|
|
2591
|
+
const children = tools.map((t, idx) => {
|
|
2592
|
+
const mark = t.success ? "\u2713" : "\u2717";
|
|
2593
|
+
let line = `${t.name} ${formatDuration(t.durationMs)} ${mark}`;
|
|
2594
|
+
if (t.error)
|
|
2595
|
+
line += ` ${t.error}`;
|
|
2596
|
+
if (hasInputs && toolCalls && idx < toolCalls.length) {
|
|
2597
|
+
const tc = toolCalls[idx];
|
|
2598
|
+
const inputStr = typeof tc.input === "string" ? tc.input : JSON.stringify(tc.input);
|
|
2599
|
+
const truncated = inputStr.length > 100 ? `${inputStr.slice(0, 100)}\u2026` : inputStr;
|
|
2600
|
+
line += ` ${truncated}`;
|
|
2601
|
+
}
|
|
2602
|
+
return line;
|
|
2603
|
+
});
|
|
2604
|
+
entries.push({
|
|
2605
|
+
key: "ai.tools",
|
|
2606
|
+
value: "",
|
|
2607
|
+
children
|
|
2608
|
+
});
|
|
2609
|
+
} else if (toolCalls?.length)
|
|
2610
|
+
if (hasInputs) {
|
|
2611
|
+
const children = toolCalls.map((tc) => {
|
|
2612
|
+
const inputStr = typeof tc.input === "string" ? tc.input : JSON.stringify(tc.input);
|
|
2613
|
+
const truncated = inputStr.length > 100 ? `${inputStr.slice(0, 100)}\u2026` : inputStr;
|
|
2614
|
+
return `${tc.name}(${truncated})`;
|
|
2615
|
+
});
|
|
2616
|
+
entries.push({
|
|
2617
|
+
key: "ai.tools",
|
|
2618
|
+
value: "",
|
|
2619
|
+
children
|
|
2620
|
+
});
|
|
2621
|
+
} else
|
|
2622
|
+
entries.push({
|
|
2623
|
+
key: "ai.tools",
|
|
2624
|
+
value: toolCalls.join(", ")
|
|
2625
|
+
});
|
|
2626
|
+
const stepsUsage = ai.stepsUsage;
|
|
2627
|
+
if (stepsUsage?.length) {
|
|
2628
|
+
const allSameModel = stepsUsage.every((s) => s.model === stepsUsage[0].model);
|
|
2629
|
+
const children = stepsUsage.map((s) => {
|
|
2630
|
+
let line = `${allSameModel ? "" : `${s.model} `}${s.inputTokens} in \u2192 ${s.outputTokens} out`;
|
|
2631
|
+
const stepTools = s.toolCalls;
|
|
2632
|
+
if (stepTools?.length)
|
|
2633
|
+
line += ` [${stepTools.join(", ")}]`;
|
|
2634
|
+
return line;
|
|
2635
|
+
});
|
|
2636
|
+
entries.push({
|
|
2637
|
+
key: "ai.steps",
|
|
2638
|
+
value: "",
|
|
2639
|
+
children
|
|
2640
|
+
});
|
|
2641
|
+
} else if (ai.steps && ai.steps > 1)
|
|
2642
|
+
entries.push({
|
|
2643
|
+
key: "ai.steps",
|
|
2644
|
+
value: String(ai.steps)
|
|
2645
|
+
});
|
|
2646
|
+
const embedding = ai.embedding;
|
|
2647
|
+
if (embedding) {
|
|
2648
|
+
const parts = [];
|
|
2649
|
+
if (embedding.model)
|
|
2650
|
+
parts.push(String(embedding.model));
|
|
2651
|
+
parts.push(`${embedding.tokens} tokens`);
|
|
2652
|
+
if (embedding.dimensions)
|
|
2653
|
+
parts.push(`${embedding.dimensions}d`);
|
|
2654
|
+
if (embedding.count)
|
|
2655
|
+
parts.push(`${embedding.count} items`);
|
|
2656
|
+
entries.push({
|
|
2657
|
+
key: "ai.embedding",
|
|
2658
|
+
value: parts.join(" \xB7 ")
|
|
2659
|
+
});
|
|
2660
|
+
}
|
|
2661
|
+
if (ai.finishReason)
|
|
2662
|
+
entries.push({
|
|
2663
|
+
key: "ai.finishReason",
|
|
2664
|
+
value: String(ai.finishReason)
|
|
2665
|
+
});
|
|
2666
|
+
if (ai.error)
|
|
2667
|
+
entries.push({
|
|
2668
|
+
key: "ai.error",
|
|
2669
|
+
value: String(ai.error)
|
|
2670
|
+
});
|
|
2671
|
+
if (ai.responseId)
|
|
2672
|
+
entries.push({
|
|
2673
|
+
key: "ai.responseId",
|
|
2674
|
+
value: String(ai.responseId)
|
|
2675
|
+
});
|
|
2676
|
+
return entries;
|
|
2677
|
+
}
|
|
2678
|
+
function prettyPrintWideEvent(event) {
|
|
2679
|
+
const { timestamp, level, service, environment, version, ...rest } = event;
|
|
2680
|
+
const ts = timestamp.slice(11, 23);
|
|
2681
|
+
const browser = isClient();
|
|
2682
|
+
const parts = [];
|
|
2683
|
+
const styles = [];
|
|
2684
|
+
if (browser) {
|
|
2685
|
+
const lc = getCssLevelColor(level);
|
|
2686
|
+
parts.push(`%c${ts}%c %c${level.toUpperCase()}%c %c[${escapeFormatString(String(service))}]%c`);
|
|
2687
|
+
styles.push(cssColors.dim, cssColors.reset, lc, cssColors.reset, cssColors.cyan, cssColors.reset);
|
|
2688
|
+
} else {
|
|
2689
|
+
const lc = getLevelColor(level);
|
|
2690
|
+
parts.push(`${colors.dim}${ts}${colors.reset} ${lc}${level.toUpperCase()}${colors.reset} ${colors.cyan}[${service}]${colors.reset}`);
|
|
2691
|
+
}
|
|
2692
|
+
if (rest.method && rest.path) {
|
|
2693
|
+
parts.push(browser ? ` ${escapeFormatString(String(rest.method))} ${escapeFormatString(String(rest.path))}` : ` ${rest.method} ${rest.path}`);
|
|
2694
|
+
delete rest.method;
|
|
2695
|
+
delete rest.path;
|
|
2696
|
+
}
|
|
2697
|
+
if (rest.status) {
|
|
2698
|
+
const sc = browser ? rest.status >= 400 ? cssColors.red : cssColors.green : rest.status >= 400 ? colors.red : colors.green;
|
|
2699
|
+
if (browser) {
|
|
2700
|
+
parts.push(` %c${rest.status}%c`);
|
|
2701
|
+
styles.push(sc, cssColors.reset);
|
|
2702
|
+
} else
|
|
2703
|
+
parts.push(` ${sc}${rest.status}${colors.reset}`);
|
|
2704
|
+
delete rest.status;
|
|
2705
|
+
}
|
|
2706
|
+
if (rest.duration) {
|
|
2707
|
+
if (browser) {
|
|
2708
|
+
parts.push(` %c${escapeFormatString(`in ${rest.duration}`)}%c`);
|
|
2709
|
+
styles.push(cssColors.dim, cssColors.reset);
|
|
2710
|
+
} else
|
|
2711
|
+
parts.push(` ${colors.dim}in ${rest.duration}${colors.reset}`);
|
|
2712
|
+
delete rest.duration;
|
|
2713
|
+
}
|
|
2714
|
+
console.log(parts.join(""), ...styles);
|
|
2715
|
+
const aiData = rest.ai;
|
|
2716
|
+
if (aiData && typeof aiData === "object")
|
|
2717
|
+
delete rest.ai;
|
|
2718
|
+
const restEntries = Object.entries(rest).filter(([_, v]) => v !== undefined);
|
|
2719
|
+
const aiEntries = aiData ? buildAIEntries(aiData) : [];
|
|
2720
|
+
const allEntries = [...restEntries.map(([key, value]) => ({
|
|
2721
|
+
key,
|
|
2722
|
+
value: formatValue(value)
|
|
2723
|
+
})), ...aiEntries];
|
|
2724
|
+
for (let i = 0;i < allEntries.length; i++) {
|
|
2725
|
+
const entry = allEntries[i];
|
|
2726
|
+
const hasChildren = entry.children && entry.children.length > 0;
|
|
2727
|
+
const prefix = i === allEntries.length - 1 && !hasChildren ? "\u2514\u2500" : "\u251C\u2500";
|
|
2728
|
+
if (browser) {
|
|
2729
|
+
const val = entry.value ? ` ${escapeFormatString(entry.value)}` : "";
|
|
2730
|
+
console.log(` %c${prefix}%c %c${escapeFormatString(entry.key)}:%c${val}`, cssColors.dim, cssColors.reset, cssColors.cyan, cssColors.reset);
|
|
2731
|
+
} else {
|
|
2732
|
+
const val = entry.value ? ` ${entry.value}` : "";
|
|
2733
|
+
console.log(` ${colors.dim}${prefix}${colors.reset} ${colors.cyan}${entry.key}:${colors.reset}${val}`);
|
|
2734
|
+
}
|
|
2735
|
+
if (hasChildren) {
|
|
2736
|
+
const connector = i === allEntries.length - 1 ? " " : "\u2502";
|
|
2737
|
+
for (let j = 0;j < entry.children.length; j++) {
|
|
2738
|
+
const child = entry.children[j];
|
|
2739
|
+
const childPrefix = j === entry.children.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
2740
|
+
if (browser)
|
|
2741
|
+
console.log(` %c${connector} ${childPrefix}%c ${escapeFormatString(child)}`, cssColors.dim, cssColors.reset);
|
|
2742
|
+
else
|
|
2743
|
+
console.log(` ${colors.dim}${connector} ${childPrefix}${colors.reset} ${child}`);
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
function createLogMethod(level) {
|
|
2749
|
+
return function logMethod(tagOrEvent, message) {
|
|
2750
|
+
if (typeof tagOrEvent === "string" && message !== undefined)
|
|
2751
|
+
emitTaggedLog(level, tagOrEvent, message);
|
|
2752
|
+
else if (typeof tagOrEvent === "object")
|
|
2753
|
+
emitWideEvent(level, tagOrEvent);
|
|
2754
|
+
else
|
|
2755
|
+
emitTaggedLog(level, "log", String(tagOrEvent));
|
|
2756
|
+
};
|
|
2757
|
+
}
|
|
2758
|
+
var _log = {
|
|
2759
|
+
info: createLogMethod("info"),
|
|
2760
|
+
error: createLogMethod("error"),
|
|
2761
|
+
warn: createLogMethod("warn"),
|
|
2762
|
+
debug: createLogMethod("debug")
|
|
2763
|
+
};
|
|
2764
|
+
var noopLogger = {
|
|
2765
|
+
set() {},
|
|
2766
|
+
error() {},
|
|
2767
|
+
info() {},
|
|
2768
|
+
warn() {},
|
|
2769
|
+
emit() {
|
|
2770
|
+
return null;
|
|
2771
|
+
},
|
|
2772
|
+
getContext() {
|
|
2773
|
+
return {};
|
|
2774
|
+
}
|
|
2775
|
+
};
|
|
2776
|
+
function createLogger(initialContext = {}, internalOptions) {
|
|
2777
|
+
if (!globalEnabled)
|
|
2778
|
+
return noopLogger;
|
|
2779
|
+
const deferDrain = internalOptions?._deferDrain ?? false;
|
|
2780
|
+
const startTime = Date.now();
|
|
2781
|
+
const context = { ...initialContext };
|
|
2782
|
+
let hasError = false;
|
|
2783
|
+
let hasWarn = false;
|
|
2784
|
+
let emitted = false;
|
|
2785
|
+
function addLog(level, message) {
|
|
2786
|
+
if (!Array.isArray(context.requestLogs))
|
|
2787
|
+
context.requestLogs = [];
|
|
2788
|
+
context.requestLogs.push({
|
|
2789
|
+
level,
|
|
2790
|
+
message,
|
|
2791
|
+
timestamp: isoNow()
|
|
2792
|
+
});
|
|
2793
|
+
}
|
|
2794
|
+
return {
|
|
2795
|
+
set(data) {
|
|
2796
|
+
if (emitted) {
|
|
2797
|
+
const keys = Object.keys(data);
|
|
2798
|
+
warnPostEmit("log.set()", `Keys dropped: ${keys.length ? keys.join(", ") : "(empty)"}.`);
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2801
|
+
mergeInto(context, data);
|
|
2802
|
+
},
|
|
2803
|
+
error(error, errorContext) {
|
|
2804
|
+
if (emitted) {
|
|
2805
|
+
warnPostEmit("log.error()", `Keys dropped: ${(errorContext ? [...Object.keys(errorContext), "error"] : ["error"]).join(", ")}.`);
|
|
2806
|
+
return;
|
|
2807
|
+
}
|
|
2808
|
+
hasError = true;
|
|
2809
|
+
const err = typeof error === "string" ? new Error(error) : error;
|
|
2810
|
+
if (errorContext)
|
|
2811
|
+
mergeInto(context, errorContext);
|
|
2812
|
+
const errorObj = {
|
|
2813
|
+
name: err.name,
|
|
2814
|
+
message: err.message,
|
|
2815
|
+
stack: err.stack
|
|
2816
|
+
};
|
|
2817
|
+
const errRecord = err;
|
|
2818
|
+
for (const k of [
|
|
2819
|
+
"status",
|
|
2820
|
+
"statusText",
|
|
2821
|
+
"statusCode",
|
|
2822
|
+
"statusMessage",
|
|
2823
|
+
"data",
|
|
2824
|
+
"cause",
|
|
2825
|
+
"internal"
|
|
2826
|
+
])
|
|
2827
|
+
if (k in err)
|
|
2828
|
+
errorObj[k] = errRecord[k];
|
|
2829
|
+
if (isPlainObject(context.error))
|
|
2830
|
+
mergeInto(context.error, errorObj);
|
|
2831
|
+
else
|
|
2832
|
+
context.error = errorObj;
|
|
2833
|
+
},
|
|
2834
|
+
info(message, infoContext) {
|
|
2835
|
+
if (emitted) {
|
|
2836
|
+
warnPostEmit("log.info()", `Keys dropped: ${(infoContext ? ["message", ...Object.keys(infoContext).filter((k) => k !== "requestLogs")] : ["message"]).join(", ")}.`);
|
|
2837
|
+
return;
|
|
2838
|
+
}
|
|
2839
|
+
addLog("info", message);
|
|
2840
|
+
if (infoContext) {
|
|
2841
|
+
const { requestLogs: _, ...rest } = infoContext;
|
|
2842
|
+
mergeInto(context, rest);
|
|
2843
|
+
}
|
|
2844
|
+
},
|
|
2845
|
+
warn(message, warnContext) {
|
|
2846
|
+
if (emitted) {
|
|
2847
|
+
warnPostEmit("log.warn()", `Keys dropped: ${(warnContext ? ["message", ...Object.keys(warnContext).filter((k) => k !== "requestLogs")] : ["message"]).join(", ")}.`);
|
|
2848
|
+
return;
|
|
2849
|
+
}
|
|
2850
|
+
hasWarn = true;
|
|
2851
|
+
addLog("warn", message);
|
|
2852
|
+
if (warnContext) {
|
|
2853
|
+
const { requestLogs: _, ...rest } = warnContext;
|
|
2854
|
+
mergeInto(context, rest);
|
|
2855
|
+
}
|
|
2856
|
+
},
|
|
2857
|
+
emit(overrides) {
|
|
2858
|
+
if (emitted) {
|
|
2859
|
+
warnPostEmit("log.emit()", "Ignoring duplicate emit.");
|
|
2860
|
+
return null;
|
|
2861
|
+
}
|
|
2862
|
+
const durationMs = Date.now() - startTime;
|
|
2863
|
+
const level = hasError ? "error" : hasWarn ? "warn" : "info";
|
|
2864
|
+
let forceKeep = false;
|
|
2865
|
+
if (overrides?._forceKeep)
|
|
2866
|
+
forceKeep = true;
|
|
2867
|
+
else if (globalSampling.keep?.length)
|
|
2868
|
+
forceKeep = shouldKeep({
|
|
2869
|
+
status: overrides?.status ?? context.status,
|
|
2870
|
+
duration: durationMs,
|
|
2871
|
+
path: context.path,
|
|
2872
|
+
method: context.method,
|
|
2873
|
+
context
|
|
2874
|
+
});
|
|
2875
|
+
if (!forceKeep && !shouldSample(level)) {
|
|
2876
|
+
emitted = true;
|
|
2877
|
+
return null;
|
|
2878
|
+
}
|
|
2879
|
+
if (overrides) {
|
|
2880
|
+
const obj = overrides;
|
|
2881
|
+
for (const key in obj)
|
|
2882
|
+
if (key !== "_forceKeep")
|
|
2883
|
+
context[key] = obj[key];
|
|
2884
|
+
}
|
|
2885
|
+
context.duration = formatDuration(durationMs);
|
|
2886
|
+
const wide = emitWideEvent(level, context, deferDrain, true);
|
|
2887
|
+
emitted = true;
|
|
2888
|
+
return wide;
|
|
2889
|
+
},
|
|
2890
|
+
getContext() {
|
|
2891
|
+
return { ...context };
|
|
2892
|
+
}
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
if (typeof __EVLOG_CONFIG__ !== "undefined")
|
|
2896
|
+
initLogger(__EVLOG_CONFIG__);
|
|
2102
2897
|
// src/link.tsx
|
|
2103
2898
|
import {
|
|
2104
2899
|
createContext,
|
|
@@ -2167,6 +2962,52 @@ function buildElement(route, data, rootLayout) {
|
|
|
2167
2962
|
return element;
|
|
2168
2963
|
}
|
|
2169
2964
|
|
|
2965
|
+
// src/context-logger.ts
|
|
2966
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
2967
|
+
|
|
2968
|
+
// ../../node_modules/.bun/evlog@2.13.0+449e6d239244fccb/node_modules/evlog/dist/elysia/index.mjs
|
|
2969
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
2970
|
+
import { Elysia } from "elysia";
|
|
2971
|
+
var storage = new AsyncLocalStorage2;
|
|
2972
|
+
var activeLoggers = /* @__PURE__ */ new WeakSet;
|
|
2973
|
+
function useLogger2() {
|
|
2974
|
+
const logger = storage.getStore();
|
|
2975
|
+
if (!logger || !activeLoggers.has(logger))
|
|
2976
|
+
throw new Error("[evlog] useLogger() was called outside of an evlog plugin context. Make sure app.use(evlog()) is registered before your routes.");
|
|
2977
|
+
return logger;
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
// src/context-logger.ts
|
|
2981
|
+
var noopLogger2 = {
|
|
2982
|
+
set: () => {},
|
|
2983
|
+
error: () => {},
|
|
2984
|
+
info: () => {},
|
|
2985
|
+
warn: () => {},
|
|
2986
|
+
emit: () => null,
|
|
2987
|
+
getContext: () => ({}),
|
|
2988
|
+
fork: (_label, fn) => fn()
|
|
2989
|
+
};
|
|
2990
|
+
var syntheticRenderStorage = new AsyncLocalStorage3;
|
|
2991
|
+
function useLogger3() {
|
|
2992
|
+
try {
|
|
2993
|
+
return useLogger2();
|
|
2994
|
+
} catch {
|
|
2995
|
+
return syntheticRenderStorage.getStore() ?? noopLogger2;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
async function runInSyntheticRenderScope(fn, initialContext) {
|
|
2999
|
+
const logger = createLogger(initialContext);
|
|
3000
|
+
try {
|
|
3001
|
+
const result = await syntheticRenderStorage.run(logger, () => Promise.resolve(fn()));
|
|
3002
|
+
logger.emit();
|
|
3003
|
+
return result;
|
|
3004
|
+
} catch (err) {
|
|
3005
|
+
logger.error(err instanceof Error ? err : new Error(String(err)));
|
|
3006
|
+
logger.emit();
|
|
3007
|
+
throw err;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
|
|
2170
3011
|
// src/render/loaders.ts
|
|
2171
3012
|
function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
2172
3013
|
const cache = new Map;
|
|
@@ -2192,7 +3033,7 @@ function createLoaderCtx(ctx, accumulatedParentPromise) {
|
|
|
2192
3033
|
}
|
|
2193
3034
|
async function runLoaders(route, ctx, _rootLayout) {
|
|
2194
3035
|
try {
|
|
2195
|
-
const ctxRecord = ctx;
|
|
3036
|
+
const ctxRecord = { ...ctx, log: useLogger3() };
|
|
2196
3037
|
const loaderMap = new Map;
|
|
2197
3038
|
let accumulatedParentPromise = Promise.resolve({});
|
|
2198
3039
|
for (const r of route.routeChain) {
|
|
@@ -2310,7 +3151,7 @@ async function renderForPath(route, params, root, origin, basePath) {
|
|
|
2310
3151
|
set: { headers: {} },
|
|
2311
3152
|
path: resolvedPath
|
|
2312
3153
|
};
|
|
2313
|
-
const prepared = await prepareRender(route, ctx, root, basePath);
|
|
3154
|
+
const prepared = await runInSyntheticRenderScope(() => prepareRender(route, ctx, root, basePath), { route: route.pattern });
|
|
2314
3155
|
if (prepared instanceof Response) {
|
|
2315
3156
|
throw prepared;
|
|
2316
3157
|
}
|
|
@@ -2475,7 +3316,9 @@ async function buildStaticTarget(routes, rootDir, buildRoot, root, options) {
|
|
|
2475
3316
|
publicPath,
|
|
2476
3317
|
basePath
|
|
2477
3318
|
});
|
|
2478
|
-
const
|
|
3319
|
+
const publicFavicon = join8(rootDir, "public", "favicon.ico");
|
|
3320
|
+
const faviconHref = existsSync7(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
3321
|
+
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref);
|
|
2479
3322
|
setProductionTemplateContent(shellHtml);
|
|
2480
3323
|
const publicSrcDir = join8(rootDir, "public");
|
|
2481
3324
|
if (existsSync7(publicSrcDir)) {
|
|
@@ -2533,7 +3376,7 @@ var configSchema = t.Object({
|
|
|
2533
3376
|
import { existsSync as existsSync8 } from "fs";
|
|
2534
3377
|
import { readdir } from "fs/promises";
|
|
2535
3378
|
import { join as join9, parse } from "path";
|
|
2536
|
-
import { Elysia } from "elysia";
|
|
3379
|
+
import { Elysia as Elysia2, t as t2 } from "elysia";
|
|
2537
3380
|
|
|
2538
3381
|
// src/internal.ts
|
|
2539
3382
|
var _compileCtx = null;
|
|
@@ -2661,6 +3504,7 @@ async function buildDevRoute(absolutePath, relativePath, root) {
|
|
|
2661
3504
|
routeChain
|
|
2662
3505
|
};
|
|
2663
3506
|
}
|
|
3507
|
+
var TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
|
|
2664
3508
|
async function collectPageFilePaths(dir) {
|
|
2665
3509
|
const files = [];
|
|
2666
3510
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|