@teyik0/furin 0.3.0-alpha.1 → 0.4.0-alpha.2
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/adapter/bun.d.ts +2 -18
- package/dist/adapter/package.d.ts +2 -2
- package/dist/adapter/runtime-build.d.ts +33 -0
- package/dist/adapter/vercel.d.ts +3 -0
- package/dist/build/client.d.ts +2 -2
- package/dist/build/compile-entry.d.ts +4 -3
- package/dist/build/compile-entry.ts +24 -69
- package/dist/build/entry-template.d.ts +8 -2
- package/dist/build/entry-template.ts +48 -11
- package/dist/build/index.d.ts +2 -2
- package/dist/build/index.js +11720 -7840
- package/dist/build/route-types.d.ts +2 -22
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +14 -1
- package/dist/build/types.d.ts +26 -3
- package/dist/build/virtual-entry.d.ts +8 -0
- package/dist/cache.d.ts +5 -0
- package/dist/cache.js +97 -0
- package/dist/cli/index.js +11815 -7793
- package/dist/cli/preview.d.ts +7 -0
- package/dist/client/boundaries.d.ts +3 -0
- package/dist/client/browser-events-runtime.d.ts +2 -0
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/define-route.d.ts +36 -0
- package/dist/client/dev-error-overlay.d.ts +1 -0
- package/dist/client/dev-error-overlay.ts +201 -0
- package/dist/client/document.d.ts +27 -0
- package/dist/client/hmr.d.ts +12 -0
- package/dist/client/internal/runtime-types.d.ts +3 -1
- package/dist/client/link.js +1392 -940
- package/dist/client/router/index.d.ts +1 -1
- package/dist/client/router/link-utils.d.ts +9 -0
- package/dist/client/router/provider.d.ts +1 -1
- package/dist/client/router/search/index.d.ts +3 -7
- package/dist/client/router/sync-catch-up.d.ts +1 -1
- package/dist/client/router/types.d.ts +40 -34
- package/dist/client.d.ts +4 -159
- package/dist/client.js +197 -21
- package/dist/config.d.ts +25 -8
- package/dist/config.js +15 -7
- package/dist/define-route.d.ts +1358 -0
- package/dist/devtools/protocol.d.ts +2 -2
- package/dist/furin.d.ts +18 -34
- package/dist/furin.js +16038 -9395
- package/dist/plugin/index.js +1401 -223
- package/dist/plugin/route-config-autofix.d.ts +31 -0
- package/dist/plugin/routes.d.ts +28 -0
- package/dist/routes.d.ts +6 -0
- package/dist/routes.js +1 -0
- package/dist/rsc/build/index.d.ts +6 -2
- package/dist/rsc.js +3 -3
- package/dist/server/browser-events/plugin.d.ts +11 -0
- package/dist/server/browser-events/types.d.ts +9 -0
- package/dist/server/cache/invalidation.d.ts +1 -2
- package/dist/server/cache/isr.d.ts +1 -0
- package/dist/server/cache/purger.d.ts +7 -0
- package/dist/server/cache/runtime-cache.d.ts +21 -0
- package/dist/server/dev/browser-events.d.ts +4 -0
- package/dist/server/dev/diagnostics.d.ts +39 -0
- package/dist/server/dev/error.d.ts +17 -0
- package/dist/server/dev/graph.d.ts +86 -0
- package/dist/server/dev/plugin.d.ts +9 -0
- package/dist/server/dev/request-security.d.ts +1 -0
- package/dist/server/dev/rewrite-module-specifiers.d.ts +7 -0
- package/dist/server/dev/runtime.production.d.ts +5 -0
- package/dist/server/dev/symbolicate.d.ts +11 -0
- package/dist/server/dev/transform-failure.d.ts +4 -0
- package/dist/server/dev-page-plugin.d.ts +7 -5
- package/dist/server/dev-page-plugin.production.d.ts +1 -0
- package/dist/server/devtools/hub.d.ts +3 -2
- package/dist/server/devtools/instrumentation.d.ts +2 -2
- package/dist/server/devtools/instrumentation.production.d.ts +2 -2
- package/dist/server/devtools/plugin.d.ts +2 -2
- package/dist/server/external-prerender.d.ts +2 -0
- package/dist/server/instance.d.ts +2 -2
- package/dist/server/internal.d.ts +17 -2
- package/dist/server/internal.js +436 -1
- package/dist/server/logger.d.ts +4 -0
- package/dist/server/render/assemble.d.ts +0 -9
- package/dist/server/render/document.d.ts +4 -0
- package/dist/server/render/element.d.ts +3 -1
- package/dist/server/render/index.d.ts +2 -2
- package/dist/server/render/index.ts +1 -2
- package/dist/server/render/isr.d.ts +1 -1
- package/dist/server/render/loaders.d.ts +1 -1
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-document.d.ts +21 -0
- package/dist/server/render/ppr-request.d.ts +26 -0
- package/dist/server/render/ppr-route.d.ts +4 -2
- package/dist/server/render/shell.ts +0 -12
- package/dist/server/render/ssg.d.ts +3 -1
- package/dist/server/render/ssr.d.ts +23 -11
- package/dist/server/render/template.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +24 -0
- package/dist/server/router/hmr.d.ts +16 -8
- package/dist/server/router/hmr.production.d.ts +2 -0
- package/dist/server/router/patterns.d.ts +7 -0
- package/dist/server/router/plugin.d.ts +6 -3
- package/dist/server/router/schema-merge.d.ts +2 -2
- package/dist/server/router/schemas.d.ts +5 -5
- package/dist/server/router/source-version.d.ts +2 -0
- package/dist/server/router/types.d.ts +1 -0
- package/dist/server/sync/adapter.d.ts +13 -0
- package/dist/server/sync/config.d.ts +5 -5
- package/dist/server/sync/index.d.ts +6 -6
- package/dist/server/sync/index.js +1115 -985
- package/dist/server/sync/notifier.d.ts +1 -0
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +101 -6
- package/dist/server/sync/postgres/migrate.js +3 -2
- package/dist/server/sync/stream.d.ts +4 -13
- package/dist/shared/await.d.ts +4 -5
- package/dist/shared/browser-events.d.ts +22 -0
- package/dist/shared/compact-json.d.ts +8 -0
- package/dist/shared/deferred-ndjson.d.ts +6 -5
- package/dist/shared/dev-diagnostics.d.ts +36 -0
- package/dist/shared/elysia-contract.d.ts +41 -0
- package/dist/shared/prefix.d.ts +2 -0
- package/dist/shared/route-map.d.ts +5 -0
- package/dist/shared/utils/index.d.ts +1 -3
- package/package.json +55 -43
- package/src/adapter/README.md +45 -0
- package/src/adapter/bun.ts +62 -265
- package/src/adapter/package.ts +34 -22
- package/src/adapter/runtime-build.ts +375 -0
- package/src/adapter/static.ts +83 -5
- package/src/adapter/vercel.ts +857 -0
- package/src/build/client.ts +58 -16
- package/src/build/compile-entry.ts +24 -69
- package/src/build/entry-template.ts +48 -11
- package/src/build/hydrate.ts +147 -37
- package/src/build/index.ts +21 -7
- package/src/build/production-instrumentation.ts +56 -4
- package/src/build/route-types.ts +19 -114
- package/src/build/shared.ts +3 -2
- package/src/build/ssg-cache.ts +99 -16
- package/src/build/types.ts +32 -3
- package/src/build/virtual-entry.ts +27 -0
- package/src/cache.ts +14 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +62 -10
- package/src/cli/preview.ts +90 -0
- package/src/client/boundaries.tsx +19 -2
- package/src/client/browser-events-runtime.ts +204 -0
- package/src/client/browser-events.ts +22 -0
- package/src/client/define-route.ts +38 -0
- package/src/client/dev-error-overlay.ts +201 -0
- package/src/client/document.tsx +162 -0
- package/src/client/hmr.ts +63 -0
- package/src/client/internal/runtime-types.ts +3 -1
- package/src/client/link.tsx +21 -6
- package/src/client/router/boundary-tree.tsx +4 -4
- package/src/client/router/index.ts +1 -0
- package/src/client/router/link-utils.ts +26 -0
- package/src/client/router/provider.tsx +190 -65
- package/src/client/router/search/index.ts +4 -12
- package/src/client/router/sync-catch-up.ts +3 -4
- package/src/client/router/types.ts +56 -30
- package/src/client.ts +14 -316
- package/src/config.ts +35 -10
- package/src/define-route.ts +972 -0
- package/src/devtools/devtools-element.js +67 -87
- package/src/devtools/protocol.ts +2 -2
- package/src/furin.ts +431 -101
- package/src/plugin/route-config-autofix.ts +1140 -0
- package/src/plugin/routes.ts +1061 -0
- package/src/plugin/transform-client.ts +776 -228
- package/src/plugin/transform-isomorphic.ts +1 -1
- package/src/react-dom-edge.d.ts +6 -0
- package/src/routes.ts +6 -0
- package/src/rsc/build/index.ts +16 -4
- package/src/server/auto-invalidate/registry.ts +2 -2
- package/src/server/auto-invalidate/runtime.ts +5 -2
- package/src/server/browser-events/plugin.ts +168 -0
- package/src/server/browser-events/types.ts +11 -0
- package/src/server/cache/dev-loader.ts +30 -29
- package/src/server/cache/invalidation.ts +13 -22
- package/src/server/cache/isr.ts +9 -0
- package/src/server/cache/purger.ts +41 -0
- package/src/server/cache/runtime-cache.ts +137 -0
- package/src/server/dev/browser-events.ts +54 -0
- package/src/server/dev/diagnostics.ts +297 -0
- package/src/server/dev/error.ts +148 -0
- package/src/server/dev/graph.ts +438 -0
- package/src/server/dev/plugin.ts +130 -0
- package/src/server/dev/request-security.ts +38 -0
- package/src/server/dev/rewrite-module-specifiers.ts +81 -0
- package/src/server/dev/runtime.production.ts +24 -0
- package/src/server/dev/symbolicate.ts +135 -0
- package/src/server/dev/transform-failure.ts +8 -0
- package/src/server/dev-page-plugin.production.ts +3 -0
- package/src/server/dev-page-plugin.ts +110 -52
- package/src/server/devtools/hub.ts +6 -5
- package/src/server/devtools/instrumentation.production.ts +3 -3
- package/src/server/devtools/instrumentation.ts +14 -8
- package/src/server/devtools/plugin.ts +12 -153
- package/src/server/external-prerender.ts +10 -0
- package/src/server/instance.ts +5 -5
- package/src/server/internal.ts +42 -2
- package/src/server/logger.ts +21 -0
- package/src/server/render/assemble.ts +4 -45
- package/src/server/render/document.tsx +34 -0
- package/src/server/render/element.tsx +31 -15
- package/src/server/render/index.ts +1 -2
- package/src/server/render/isr.ts +70 -24
- package/src/server/render/loaders.ts +43 -8
- package/src/server/render/not-found.ts +77 -29
- package/src/server/render/ppr-document.ts +239 -0
- package/src/server/render/ppr-request.ts +104 -0
- package/src/server/render/ppr-route.ts +153 -32
- package/src/server/render/shell.ts +0 -12
- package/src/server/render/ssg.ts +39 -21
- package/src/server/render/ssr.ts +429 -143
- package/src/server/render/template.ts +128 -2
- package/src/server/router/defined-route.ts +78 -0
- package/src/server/router/discovery.ts +129 -29
- package/src/server/router/hmr.production.ts +7 -0
- package/src/server/router/hmr.ts +177 -67
- package/src/server/router/patterns.ts +45 -13
- package/src/server/router/plugin.ts +184 -78
- package/src/server/router/schema-merge.ts +4 -14
- package/src/server/router/schemas.ts +11 -8
- package/src/server/router/source-version.ts +9 -0
- package/src/server/router/types.ts +2 -0
- package/src/server/sync/adapter.ts +13 -0
- package/src/server/sync/config.ts +12 -12
- package/src/server/sync/index.ts +8 -8
- package/src/server/sync/notifier.ts +1 -0
- package/src/server/sync/plugin.ts +4 -1
- package/src/server/sync/postgres/index.ts +111 -5
- package/src/server/sync/postgres/migrate.ts +3 -2
- package/src/server/sync/response.ts +14 -10
- package/src/server/sync/runtime.ts +12 -0
- package/src/server/sync/stream.ts +78 -113
- package/src/shared/await.tsx +4 -5
- package/src/shared/browser-events.ts +28 -0
- package/src/shared/compact-json.ts +77 -0
- package/src/shared/deferred-ndjson.ts +20 -6
- package/src/shared/dev-diagnostics.ts +44 -0
- package/src/shared/elysia-contract.ts +63 -0
- package/src/shared/prefix.ts +8 -0
- package/src/shared/route-map.ts +46 -0
- package/src/shared/utils/index.ts +2 -20
- package/dist/build/server-routes-entry.d.ts +0 -13
- package/dist/build/server-routes-entry.ts +0 -30
- package/dist/server/router/index.d.ts +0 -7
- package/dist/server/router/index.js +0 -27
- package/dist/server/router/index.ts +0 -28
- package/src/build/server-routes-entry.ts +0 -30
- package/src/server/router/index.ts +0 -28
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
var __esm = (fn, res, err) => () => {
|
|
3
|
+
if (fn)
|
|
4
|
+
try {
|
|
5
|
+
res = fn(fn = 0);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
err = [e];
|
|
8
|
+
}
|
|
9
|
+
if (err)
|
|
10
|
+
throw err[0];
|
|
11
|
+
return res;
|
|
12
|
+
};
|
|
4
13
|
|
|
5
14
|
// src/server/instance.ts
|
|
6
15
|
import { AsyncLocalStorage } from "async_hooks";
|
|
7
|
-
var _requestScope = new AsyncLocalStorage;
|
|
8
|
-
var _instances = new Map;
|
|
9
|
-
var _defaultInstance = null;
|
|
10
16
|
function createInstance(prefix, pagesDir) {
|
|
11
17
|
return {
|
|
12
|
-
prefix,
|
|
13
|
-
pagesDir,
|
|
14
|
-
syncStreamPath: undefined,
|
|
15
18
|
buildId: "",
|
|
19
|
+
pagesDir,
|
|
20
|
+
prefix,
|
|
16
21
|
registrationEpoch: 0,
|
|
17
|
-
state: new Map
|
|
22
|
+
state: new Map,
|
|
23
|
+
syncPath: undefined
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
26
|
function defaultInstance() {
|
|
@@ -63,32 +69,42 @@ function instanceSlot(init) {
|
|
|
63
69
|
return value;
|
|
64
70
|
};
|
|
65
71
|
}
|
|
72
|
+
var _requestScope, _instances, _defaultInstance = null;
|
|
73
|
+
var init_instance = __esm(() => {
|
|
74
|
+
_requestScope = new AsyncLocalStorage;
|
|
75
|
+
_instances = new Map;
|
|
76
|
+
});
|
|
66
77
|
|
|
67
78
|
// src/server/sync/config.ts
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
function resolveSyncStreamPath(sync) {
|
|
79
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
80
|
+
function resolveSyncPath(sync) {
|
|
71
81
|
if (!sync) {
|
|
72
82
|
return;
|
|
73
83
|
}
|
|
74
|
-
return sync.
|
|
84
|
+
return sync.path ?? SYNC_DEFAULT_PATH;
|
|
75
85
|
}
|
|
76
|
-
function
|
|
77
|
-
const override =
|
|
86
|
+
function getSyncPath() {
|
|
87
|
+
const override = requestSyncPath.getStore();
|
|
78
88
|
if (override !== undefined) {
|
|
79
89
|
return override;
|
|
80
90
|
}
|
|
81
|
-
return currentInstance().
|
|
91
|
+
return currentInstance().syncPath;
|
|
82
92
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
93
|
+
function runWithSyncPath(path, fn) {
|
|
94
|
+
return requestSyncPath.run(path, fn);
|
|
85
95
|
}
|
|
86
96
|
function syncRuntimeOptions(sync) {
|
|
87
97
|
return { adapter: sync.adapter, notifier: sync.notifier, principal: sync.principal };
|
|
88
98
|
}
|
|
99
|
+
var SYNC_DEFAULT_PATH = "/_furin/sync", requestSyncPath;
|
|
100
|
+
var init_config = __esm(() => {
|
|
101
|
+
init_instance();
|
|
102
|
+
requestSyncPath = new AsyncLocalStorage2;
|
|
103
|
+
});
|
|
89
104
|
|
|
90
105
|
// src/server/sync/notifier.ts
|
|
91
106
|
class PollingSyncNotifier {
|
|
107
|
+
recovery = "self";
|
|
92
108
|
adapter;
|
|
93
109
|
intervalMs;
|
|
94
110
|
listeners = new Set;
|
|
@@ -178,12 +194,10 @@ class PollingSyncNotifier {
|
|
|
178
194
|
}
|
|
179
195
|
}
|
|
180
196
|
|
|
181
|
-
//
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
186
|
-
// ../../node_modules/.bun/evlog@2.22.3+6e5ab44a2bca2113/node_modules/evlog/dist/utils.mjs
|
|
197
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/utils.mjs
|
|
198
|
+
function elapsedMs(startTime) {
|
|
199
|
+
return Math.max(0, Date.now() - startTime);
|
|
200
|
+
}
|
|
187
201
|
function formatDuration(ms) {
|
|
188
202
|
if (ms < 1000)
|
|
189
203
|
return `${Math.round(ms)}ms`;
|
|
@@ -219,71 +233,21 @@ function detectEnvironment() {
|
|
|
219
233
|
region: env.VERCEL_REGION || env.AWS_REGION || env.FLY_REGION || env.CF_REGION
|
|
220
234
|
};
|
|
221
235
|
}
|
|
222
|
-
var LEVEL_ORDER = {
|
|
223
|
-
debug: 0,
|
|
224
|
-
info: 1,
|
|
225
|
-
warn: 2,
|
|
226
|
-
error: 3
|
|
227
|
-
};
|
|
228
236
|
function isLevelEnabled(level, minLevel) {
|
|
229
237
|
return LEVEL_ORDER[level] >= LEVEL_ORDER[minLevel];
|
|
230
238
|
}
|
|
231
239
|
function getConsoleMethod(level) {
|
|
232
240
|
return level;
|
|
233
241
|
}
|
|
234
|
-
var colors = {
|
|
235
|
-
reset: "\x1B[0m",
|
|
236
|
-
bold: "\x1B[1m",
|
|
237
|
-
dim: "\x1B[2m",
|
|
238
|
-
red: "\x1B[31m",
|
|
239
|
-
green: "\x1B[32m",
|
|
240
|
-
yellow: "\x1B[33m",
|
|
241
|
-
blue: "\x1B[34m",
|
|
242
|
-
magenta: "\x1B[35m",
|
|
243
|
-
cyan: "\x1B[36m",
|
|
244
|
-
white: "\x1B[37m",
|
|
245
|
-
gray: "\x1B[90m"
|
|
246
|
-
};
|
|
247
|
-
var levelColorMap = {
|
|
248
|
-
error: colors.red,
|
|
249
|
-
warn: colors.yellow,
|
|
250
|
-
info: colors.cyan,
|
|
251
|
-
debug: colors.gray
|
|
252
|
-
};
|
|
253
242
|
function getLevelColor(level) {
|
|
254
243
|
return levelColorMap[level] ?? colors.white;
|
|
255
244
|
}
|
|
256
|
-
var cssColors = {
|
|
257
|
-
dim: "color: #6b7280",
|
|
258
|
-
red: "color: #ef4444; font-weight: bold",
|
|
259
|
-
green: "color: #22c55e",
|
|
260
|
-
yellow: "color: #f59e0b; font-weight: bold",
|
|
261
|
-
cyan: "color: #06b6d4; font-weight: bold",
|
|
262
|
-
gray: "color: #6b7280; font-weight: bold",
|
|
263
|
-
reset: "color: inherit; font-weight: normal"
|
|
264
|
-
};
|
|
265
|
-
var cssLevelColorMap = {
|
|
266
|
-
error: cssColors.red,
|
|
267
|
-
warn: cssColors.yellow,
|
|
268
|
-
info: cssColors.cyan,
|
|
269
|
-
debug: cssColors.gray
|
|
270
|
-
};
|
|
271
245
|
function getCssLevelColor(level) {
|
|
272
246
|
return cssLevelColorMap[level] ?? cssColors.reset;
|
|
273
247
|
}
|
|
274
248
|
function escapeFormatString(str) {
|
|
275
249
|
return str.replace(/%/g, "%%");
|
|
276
250
|
}
|
|
277
|
-
var SENSITIVE_HEADERS = [
|
|
278
|
-
"authorization",
|
|
279
|
-
"cookie",
|
|
280
|
-
"set-cookie",
|
|
281
|
-
"x-api-key",
|
|
282
|
-
"x-auth-token",
|
|
283
|
-
"proxy-authorization"
|
|
284
|
-
];
|
|
285
|
-
var SENSITIVE_HEADER_SET = new Set(SENSITIVE_HEADERS);
|
|
286
|
-
var patternCache = /* @__PURE__ */ new Map;
|
|
287
251
|
function globToRegExp(pattern, separator = "/") {
|
|
288
252
|
const cacheKey = `${separator}:${pattern}`;
|
|
289
253
|
let regex = patternCache.get(cacheKey);
|
|
@@ -299,573 +263,187 @@ function globToRegExp(pattern, separator = "/") {
|
|
|
299
263
|
function matchesPattern(path, pattern) {
|
|
300
264
|
return globToRegExp(pattern, "/").test(path);
|
|
301
265
|
}
|
|
266
|
+
function isoNow() {
|
|
267
|
+
const now = Date.now();
|
|
268
|
+
const sec = Math.floor(now / 1000);
|
|
269
|
+
if (sec !== _isoCachedSecond) {
|
|
270
|
+
_isoCachedSecond = sec;
|
|
271
|
+
_isoDate.setTime(now);
|
|
272
|
+
_isoCachedPrefix = _isoDate.toISOString().slice(0, 19);
|
|
273
|
+
}
|
|
274
|
+
return `${_isoCachedPrefix}.${String(now % 1000).padStart(3, "0")}Z`;
|
|
275
|
+
}
|
|
276
|
+
var LEVEL_ORDER, colors, levelColorMap, cssColors, cssLevelColorMap, SENSITIVE_HEADERS, SENSITIVE_HEADER_SET, patternCache, _isoDate, _isoCachedSecond = -1, _isoCachedPrefix = "";
|
|
277
|
+
var init_utils = __esm(() => {
|
|
278
|
+
LEVEL_ORDER = {
|
|
279
|
+
debug: 0,
|
|
280
|
+
info: 1,
|
|
281
|
+
warn: 2,
|
|
282
|
+
error: 3
|
|
283
|
+
};
|
|
284
|
+
colors = {
|
|
285
|
+
reset: "\x1B[0m",
|
|
286
|
+
bold: "\x1B[1m",
|
|
287
|
+
dim: "\x1B[2m",
|
|
288
|
+
red: "\x1B[31m",
|
|
289
|
+
green: "\x1B[32m",
|
|
290
|
+
yellow: "\x1B[33m",
|
|
291
|
+
blue: "\x1B[34m",
|
|
292
|
+
magenta: "\x1B[35m",
|
|
293
|
+
cyan: "\x1B[36m",
|
|
294
|
+
white: "\x1B[37m",
|
|
295
|
+
gray: "\x1B[90m"
|
|
296
|
+
};
|
|
297
|
+
levelColorMap = {
|
|
298
|
+
error: colors.red,
|
|
299
|
+
warn: colors.yellow,
|
|
300
|
+
info: colors.cyan,
|
|
301
|
+
debug: colors.gray
|
|
302
|
+
};
|
|
303
|
+
cssColors = {
|
|
304
|
+
dim: "color: #6b7280",
|
|
305
|
+
red: "color: #ef4444; font-weight: bold",
|
|
306
|
+
green: "color: #22c55e",
|
|
307
|
+
yellow: "color: #f59e0b; font-weight: bold",
|
|
308
|
+
cyan: "color: #06b6d4; font-weight: bold",
|
|
309
|
+
gray: "color: #6b7280; font-weight: bold",
|
|
310
|
+
reset: "color: inherit; font-weight: normal"
|
|
311
|
+
};
|
|
312
|
+
cssLevelColorMap = {
|
|
313
|
+
error: cssColors.red,
|
|
314
|
+
warn: cssColors.yellow,
|
|
315
|
+
info: cssColors.cyan,
|
|
316
|
+
debug: cssColors.gray
|
|
317
|
+
};
|
|
318
|
+
SENSITIVE_HEADERS = [
|
|
319
|
+
"authorization",
|
|
320
|
+
"cookie",
|
|
321
|
+
"set-cookie",
|
|
322
|
+
"x-api-key",
|
|
323
|
+
"x-auth-token",
|
|
324
|
+
"proxy-authorization"
|
|
325
|
+
];
|
|
326
|
+
SENSITIVE_HEADER_SET = new Set(SENSITIVE_HEADERS);
|
|
327
|
+
patternCache = /* @__PURE__ */ new Map;
|
|
328
|
+
_isoDate = /* @__PURE__ */ new Date;
|
|
329
|
+
});
|
|
302
330
|
|
|
303
|
-
// ../../node_modules/.bun/evlog@2.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
var SKIP_PATH_RE = /(?:^|[/\\])(?:node_modules|\.nuxt|\.next|\.output)(?:[/\\]|$)/;
|
|
310
|
-
var SKIP_FRAME_PATH_RE = /(?:^|[/\\])(?:packages[/\\]evlog|evlog[/\\](?:dist|src))(?:[/\\]|$)/;
|
|
311
|
-
var SKIP_FRAME_FN_RE = /^(?:createError|EvlogError|new EvlogError)$/;
|
|
312
|
-
function isPlainObject(val) {
|
|
313
|
-
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
314
|
-
}
|
|
315
|
-
function pickString(obj, key) {
|
|
316
|
-
const val = obj[key];
|
|
317
|
-
return typeof val === "string" && val.length > 0 ? val : undefined;
|
|
318
|
-
}
|
|
319
|
-
function pickNumber(obj, key) {
|
|
320
|
-
const val = obj[key];
|
|
321
|
-
return typeof val === "number" ? val : undefined;
|
|
331
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/redact-C7FmdhwI.mjs
|
|
332
|
+
function normalizeRedactPathPattern(pattern) {
|
|
333
|
+
if (!pattern.includes("*") && !pattern.includes("."))
|
|
334
|
+
return `**.${pattern}`;
|
|
335
|
+
return pattern;
|
|
322
336
|
}
|
|
323
|
-
function
|
|
337
|
+
function compileRedactPathMatchers(patterns) {
|
|
338
|
+
if (!patterns?.length)
|
|
339
|
+
return;
|
|
340
|
+
const exactPaths = /* @__PURE__ */ new Set;
|
|
341
|
+
const pathGlobs = [];
|
|
342
|
+
const keyGlobs = [];
|
|
343
|
+
const caseInsensitiveLeaves = /* @__PURE__ */ new Set;
|
|
344
|
+
for (const raw of patterns) {
|
|
345
|
+
if (!raw.includes("*")) {
|
|
346
|
+
if (raw.includes("."))
|
|
347
|
+
exactPaths.add(raw);
|
|
348
|
+
else
|
|
349
|
+
addPathGlobPattern(normalizeRedactPathPattern(raw), exactPaths, pathGlobs, caseInsensitiveLeaves);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (!raw.includes("."))
|
|
353
|
+
keyGlobs.push(globToRegExp(raw, "."));
|
|
354
|
+
else
|
|
355
|
+
addPathGlobPattern(raw, exactPaths, pathGlobs, caseInsensitiveLeaves);
|
|
356
|
+
}
|
|
357
|
+
if (exactPaths.size === 0 && pathGlobs.length === 0 && keyGlobs.length === 0 && caseInsensitiveLeaves.size === 0)
|
|
358
|
+
return;
|
|
324
359
|
return {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
360
|
+
exactPaths,
|
|
361
|
+
pathGlobs,
|
|
362
|
+
keyGlobs,
|
|
363
|
+
caseInsensitiveLeaves
|
|
329
364
|
};
|
|
330
365
|
}
|
|
331
|
-
function
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return { message: String(error) };
|
|
338
|
-
const result = {
|
|
339
|
-
message: pickString(error, "message") ?? pickString(error, "statusText") ?? pickString(error, "statusMessage") ?? "Unknown error",
|
|
340
|
-
name: pickString(error, "name"),
|
|
341
|
-
code: pickString(error, "code"),
|
|
342
|
-
why: pickString(error, "why"),
|
|
343
|
-
fix: pickString(error, "fix"),
|
|
344
|
-
link: pickString(error, "link"),
|
|
345
|
-
status: pickNumber(error, "status") ?? pickNumber(error, "statusCode"),
|
|
346
|
-
stack: pickString(error, "stack")
|
|
347
|
-
};
|
|
348
|
-
const { data, cause } = error;
|
|
349
|
-
if (isPlainObject(data)) {
|
|
350
|
-
const guidance = extractGuidance(data);
|
|
351
|
-
if (!result.code)
|
|
352
|
-
result.code = guidance.code;
|
|
353
|
-
if (!result.why)
|
|
354
|
-
result.why = guidance.why;
|
|
355
|
-
if (!result.fix)
|
|
356
|
-
result.fix = guidance.fix;
|
|
357
|
-
if (!result.link)
|
|
358
|
-
result.link = guidance.link;
|
|
366
|
+
function addPathGlobPattern(pattern, exactPaths, pathGlobs, caseInsensitiveLeaves) {
|
|
367
|
+
pathGlobs.push(globToRegExp(pattern, "."));
|
|
368
|
+
const leaf = pattern.match(/^\*\*\.([^.?*]+)$/);
|
|
369
|
+
if (leaf) {
|
|
370
|
+
exactPaths.add(leaf[1]);
|
|
371
|
+
caseInsensitiveLeaves.add(leaf[1].toLowerCase());
|
|
359
372
|
}
|
|
360
|
-
if (cause instanceof Error)
|
|
361
|
-
result.cause = cause.message;
|
|
362
|
-
else if (isPlainObject(cause) && pickString(cause, "message"))
|
|
363
|
-
result.cause = pickString(cause, "message");
|
|
364
|
-
return result;
|
|
365
|
-
}
|
|
366
|
-
function decodeFileUrl(file) {
|
|
367
|
-
if (file.startsWith("file://"))
|
|
368
|
-
try {
|
|
369
|
-
return decodeURIComponent(new URL(file).pathname);
|
|
370
|
-
} catch {
|
|
371
|
-
return file.slice(7);
|
|
372
|
-
}
|
|
373
|
-
return file;
|
|
374
373
|
}
|
|
375
|
-
function
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
374
|
+
function matchesRedactPath(fullPath, leafKey, matchers) {
|
|
375
|
+
if (matchers.exactPaths.has(fullPath))
|
|
376
|
+
return true;
|
|
377
|
+
if (matchers.caseInsensitiveLeaves.has(leafKey.toLowerCase()))
|
|
378
|
+
return true;
|
|
379
|
+
for (const glob of matchers.pathGlobs) {
|
|
380
|
+
glob.lastIndex = 0;
|
|
381
|
+
if (glob.test(fullPath))
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
for (const glob of matchers.keyGlobs) {
|
|
385
|
+
glob.lastIndex = 0;
|
|
386
|
+
if (glob.test(leafKey))
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
return false;
|
|
386
390
|
}
|
|
387
|
-
function
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
|
|
391
|
+
function resolveReplacement(replacement, matched, ctx) {
|
|
392
|
+
if (typeof replacement === "string")
|
|
393
|
+
return replacement;
|
|
394
|
+
try {
|
|
395
|
+
const result = replacement(matched, ctx);
|
|
396
|
+
if (typeof result !== "string") {
|
|
397
|
+
console.error(`[evlog] redact replacement returned ${typeof result} for "${ctx.path}", expected string \u2014 using ${DEFAULT_REPLACEMENT}`);
|
|
398
|
+
return DEFAULT_REPLACEMENT;
|
|
399
|
+
}
|
|
400
|
+
return result;
|
|
401
|
+
} catch (err) {
|
|
402
|
+
console.error(`[evlog] redact replacement failed for "${ctx.path}":`, err);
|
|
403
|
+
return DEFAULT_REPLACEMENT;
|
|
393
404
|
}
|
|
394
|
-
const serverIdx = decoded.indexOf("/server/");
|
|
395
|
-
if (serverIdx >= 0)
|
|
396
|
-
return decoded.slice(serverIdx + 1);
|
|
397
|
-
const srcIdx = decoded.indexOf("/src/");
|
|
398
|
-
if (srcIdx >= 0)
|
|
399
|
-
return decoded.slice(srcIdx + 1);
|
|
400
|
-
return decoded;
|
|
401
405
|
}
|
|
402
|
-
function
|
|
403
|
-
if (
|
|
406
|
+
function redactPathsInTree(obj, matchers, replacement, prefix = "") {
|
|
407
|
+
if (obj === null || obj === undefined)
|
|
404
408
|
return;
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
return [head, ...useful.map((f) => f.raw)].join(`
|
|
411
|
-
`);
|
|
412
|
-
}
|
|
413
|
-
function parseStackFrames(stack) {
|
|
414
|
-
if (!stack)
|
|
415
|
-
return [];
|
|
416
|
-
const lines = stack.split(`
|
|
417
|
-
`);
|
|
418
|
-
const frames = [];
|
|
419
|
-
for (const line of lines) {
|
|
420
|
-
const trimmed = line.trim();
|
|
421
|
-
if (!trimmed.startsWith("at "))
|
|
422
|
-
continue;
|
|
423
|
-
const withFn = trimmed.match(/^at (.+?) \((.+):(\d+):(\d+)\)$/);
|
|
424
|
-
if (withFn) {
|
|
425
|
-
const [, fn, file, lineStr, colStr] = withFn;
|
|
426
|
-
frames.push({
|
|
427
|
-
raw: trimmed,
|
|
428
|
-
fn,
|
|
429
|
-
file,
|
|
430
|
-
line: Number(lineStr),
|
|
431
|
-
column: Number(colStr),
|
|
432
|
-
isApp: isAppPath(file)
|
|
433
|
-
});
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
const withoutFn = trimmed.match(/^at (.+):(\d+):(\d+)$/);
|
|
437
|
-
if (withoutFn) {
|
|
438
|
-
const [, file, lineStr, colStr] = withoutFn;
|
|
439
|
-
frames.push({
|
|
440
|
-
raw: trimmed,
|
|
441
|
-
file,
|
|
442
|
-
line: Number(lineStr),
|
|
443
|
-
column: Number(colStr),
|
|
444
|
-
isApp: isAppPath(file)
|
|
445
|
-
});
|
|
446
|
-
continue;
|
|
409
|
+
if (Array.isArray(obj)) {
|
|
410
|
+
for (let i = 0;i < obj.length; i++) {
|
|
411
|
+
const segment = String(i);
|
|
412
|
+
const fullPath = prefix ? `${prefix}.${segment}` : segment;
|
|
413
|
+
redactPathsInTree(obj[i], matchers, replacement, fullPath);
|
|
447
414
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (typeof obj === "object") {
|
|
418
|
+
const record = obj;
|
|
419
|
+
for (const key of redactableKeys(record)) {
|
|
420
|
+
const fullPath = prefix ? `${prefix}.${key}` : key;
|
|
421
|
+
if (matchesRedactPath(fullPath, key, matchers))
|
|
422
|
+
setRedacted(record, key, resolveReplacement(replacement, record[key], {
|
|
423
|
+
path: fullPath,
|
|
424
|
+
key
|
|
425
|
+
}), fullPath);
|
|
426
|
+
else
|
|
427
|
+
redactPathsInTree(record[key], matchers, replacement, fullPath);
|
|
459
428
|
}
|
|
460
429
|
}
|
|
461
|
-
return frames;
|
|
462
|
-
}
|
|
463
|
-
function isFrameworkRuntimePath(path) {
|
|
464
|
-
const normalized = path.replace(/\\/g, "/");
|
|
465
|
-
return normalized.includes("route-modules/") || normalized.includes("webpack://next/") || normalized.includes("/next/dist/") || normalized.includes("/compiled/next-server/");
|
|
466
430
|
}
|
|
467
|
-
function
|
|
468
|
-
|
|
469
|
-
return false;
|
|
470
|
-
return isFrameworkRuntimePath(decodeFileUrl(frame.file));
|
|
431
|
+
function redactableKeys(record) {
|
|
432
|
+
return Object.keys(record);
|
|
471
433
|
}
|
|
472
|
-
function
|
|
473
|
-
if (
|
|
474
|
-
return
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
return
|
|
482
|
-
const path = decodeFileUrl(frame.file).replace(/\\/g, "/");
|
|
483
|
-
if (SKIP_FRAME_PATH_RE.test(path))
|
|
484
|
-
return true;
|
|
485
|
-
if (path.includes(".nuxt/"))
|
|
486
|
-
return true;
|
|
487
|
-
if (path.includes(".next/"))
|
|
488
|
-
return true;
|
|
489
|
-
return false;
|
|
490
|
-
}
|
|
491
|
-
function pickPrimaryFrame(frames) {
|
|
492
|
-
for (const frame of frames)
|
|
493
|
-
if (frame.isApp && frame.file && frame.line && !isInternalErrorFrame(frame))
|
|
494
|
-
return frame;
|
|
495
|
-
}
|
|
496
|
-
function readCodeSnippet(file, line, contextLines = 2) {
|
|
497
|
-
if (!isDev() || isBrowser() || !snippetReader)
|
|
498
|
-
return null;
|
|
499
|
-
const path = decodeFileUrl(file).replace(/\\/g, "/");
|
|
500
|
-
if (path.includes(".next/") || path.includes(".nuxt/") || path.includes(".output/"))
|
|
501
|
-
return null;
|
|
502
|
-
return snippetReader(file, line, contextLines);
|
|
503
|
-
}
|
|
504
|
-
function formatSnippetLines(snippet) {
|
|
505
|
-
const width = String(snippet[snippet.length - 1]?.line ?? 0).length;
|
|
506
|
-
return snippet.map(({ line, content, isErrorLine }) => {
|
|
507
|
-
const marker = isErrorLine ? `${colors.red}\u276F${colors.reset}` : `${colors.dim} ${colors.reset}`;
|
|
508
|
-
const numColor = isErrorLine ? colors.red : colors.gray;
|
|
509
|
-
const trimmed = content.length > 120 ? `${content.slice(0, 117)}\u2026` : content;
|
|
510
|
-
return `${marker} ${numColor}${String(line).padStart(width, " ")}${colors.reset} ${colors.dim}\u2503${colors.reset} ${colors.dim}${trimmed}${colors.reset}`;
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
function formatFrameLocation(frame, cwd) {
|
|
514
|
-
const file = frame.file ? formatDisplayPath(frame.file, cwd) : "unknown";
|
|
515
|
-
const loc = frame.line ? `${file}:${frame.line}` : file;
|
|
516
|
-
const fn = frame.fn && frame.fn !== "<unknown>" ? frame.fn : undefined;
|
|
517
|
-
return fn ? `at ${fn} (${loc})` : `at ${loc}`;
|
|
518
|
-
}
|
|
519
|
-
function formatCollapsedFrame(frame, cwd) {
|
|
520
|
-
const file = frame.file ? formatDisplayPath(frame.file, cwd) : "unknown";
|
|
521
|
-
const loc = frame.line ? `${file}:${frame.line}` : file;
|
|
522
|
-
const prefix = frame.fn?.startsWith("async") ? "at async " : "at ";
|
|
523
|
-
const fn = frame.fn?.replace(/^async /, "");
|
|
524
|
-
if (fn && fn !== "<unknown>" && fn !== loc)
|
|
525
|
-
return `${prefix}${fn} (${loc})`;
|
|
526
|
-
return `${prefix}${loc}`;
|
|
527
|
-
}
|
|
528
|
-
var GUIDANCE_WRAP_WIDTH = 76;
|
|
529
|
-
var GUIDANCE_CONTINUATION = " ";
|
|
530
|
-
function formatGuidanceLine(label, text, labelColor) {
|
|
531
|
-
const prefix = `${labelColor}${label}:${colors.reset} `;
|
|
532
|
-
const lines = [];
|
|
533
|
-
let remaining = text.trim();
|
|
534
|
-
let first = true;
|
|
535
|
-
while (remaining.length > 0) {
|
|
536
|
-
const budget = first ? Math.max(24, GUIDANCE_WRAP_WIDTH - prefix.length) : Math.max(24, GUIDANCE_WRAP_WIDTH - 5);
|
|
537
|
-
if (remaining.length <= budget) {
|
|
538
|
-
lines.push(first ? `${prefix}${remaining}` : `${GUIDANCE_CONTINUATION}${remaining}`);
|
|
539
|
-
break;
|
|
540
|
-
}
|
|
541
|
-
let split = remaining.lastIndexOf(" ", budget);
|
|
542
|
-
if (split <= 0)
|
|
543
|
-
split = budget;
|
|
544
|
-
const chunk = remaining.slice(0, split).trimEnd();
|
|
545
|
-
lines.push(first ? `${prefix}${chunk}` : `${GUIDANCE_CONTINUATION}${chunk}`);
|
|
546
|
-
remaining = remaining.slice(split).trimStart();
|
|
547
|
-
first = false;
|
|
548
|
-
}
|
|
549
|
-
return lines;
|
|
550
|
-
}
|
|
551
|
-
function buildErrorEntries(error, options = {}) {
|
|
552
|
-
const normalized = normalizeErrorContext(error);
|
|
553
|
-
if (!normalized)
|
|
554
|
-
return [];
|
|
555
|
-
const cwd = options.cwd ?? (typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".");
|
|
556
|
-
const compact = options.compact ?? isDev();
|
|
557
|
-
const guidanceOnly = (options.detail ?? "full") === "guidance";
|
|
558
|
-
const showFrames = !guidanceOnly && !isBrowser() && (options.snippet ?? isDev());
|
|
559
|
-
const stackDepth = guidanceOnly ? 0 : options.stackDepth ?? (compact ? 2 : 3);
|
|
560
|
-
const snippetContextLines = compact ? 1 : 2;
|
|
561
|
-
const children = [];
|
|
562
|
-
const frames = guidanceOnly ? [] : parseStackFrames(normalized.stack);
|
|
563
|
-
const primary = guidanceOnly ? undefined : pickPrimaryFrame(frames);
|
|
564
|
-
if (!guidanceOnly && primary?.file && primary.line) {
|
|
565
|
-
pushTreeSpacer(children);
|
|
566
|
-
if (showFrames) {
|
|
567
|
-
const snippet = readCodeSnippet(primary.file, primary.line, snippetContextLines);
|
|
568
|
-
children.push(`${colors.dim} ${formatFrameLocation(primary, cwd)}${colors.reset}`);
|
|
569
|
-
if (snippet)
|
|
570
|
-
children.push(...formatSnippetLines(snippet));
|
|
571
|
-
} else
|
|
572
|
-
children.push(`${colors.dim} ${formatFrameLocation(primary, cwd)}${colors.reset}`);
|
|
573
|
-
}
|
|
574
|
-
if (normalized.code)
|
|
575
|
-
children.push(`${colors.dim}Code:${colors.reset} ${normalized.code}`);
|
|
576
|
-
if (Boolean(normalized.why || normalized.fix || normalized.link))
|
|
577
|
-
pushTreeSpacer(children);
|
|
578
|
-
if (normalized.why)
|
|
579
|
-
children.push(...formatGuidanceLine("Why", normalized.why, colors.yellow));
|
|
580
|
-
if (normalized.fix)
|
|
581
|
-
children.push(...formatGuidanceLine("Fix", normalized.fix, colors.cyan));
|
|
582
|
-
if (normalized.link)
|
|
583
|
-
children.push(`${colors.dim}More:${colors.reset} ${normalized.link}`);
|
|
584
|
-
if (normalized.cause && normalized.cause !== normalized.message)
|
|
585
|
-
children.push(`${colors.dim}Caused by:${colors.reset} ${normalized.cause}`);
|
|
586
|
-
const hiddenCount = guidanceOnly ? 0 : frames.filter((f) => !f.isApp || isInternalErrorFrame(f)).length;
|
|
587
|
-
const tailFrames = stackDepth > 0 ? frames.filter((f) => f !== primary && !isInternalErrorFrame(f)).slice(0, stackDepth) : [];
|
|
588
|
-
if (!guidanceOnly && (hiddenCount > 0 || tailFrames.length > 0)) {
|
|
589
|
-
pushTreeSpacer(children);
|
|
590
|
-
if (hiddenCount > 0)
|
|
591
|
-
children.push(`${colors.gray}stack (${hiddenCount} frame${hiddenCount === 1 ? "" : "s"} hidden in node_modules)${colors.reset}`);
|
|
592
|
-
else
|
|
593
|
-
children.push(`${colors.gray}stack${colors.reset}`);
|
|
594
|
-
for (const frame of tailFrames)
|
|
595
|
-
children.push(`${colors.gray} ${formatCollapsedFrame(frame, cwd)}${colors.reset}`);
|
|
596
|
-
}
|
|
597
|
-
return [{
|
|
598
|
-
key: "error",
|
|
599
|
-
value: `${colors.red}${colors.bold}${normalized.message}${colors.reset}`,
|
|
600
|
-
children: children.length > 0 ? children : undefined
|
|
601
|
-
}];
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// ../../node_modules/.bun/evlog@2.22.3+6e5ab44a2bca2113/node_modules/evlog/dist/dev-terminal-Brarc6vc.mjs
|
|
605
|
-
var DEV_PRESETS = {
|
|
606
|
-
evlog: {
|
|
607
|
-
frameworkOverlay: false,
|
|
608
|
-
detail: "full"
|
|
609
|
-
},
|
|
610
|
-
nitro: {
|
|
611
|
-
frameworkOverlay: true,
|
|
612
|
-
detail: "guidance"
|
|
613
|
-
},
|
|
614
|
-
both: {
|
|
615
|
-
frameworkOverlay: true,
|
|
616
|
-
detail: "full"
|
|
617
|
-
}
|
|
618
|
-
};
|
|
619
|
-
function finalizePrettyError(partial, frameworkOverlay, pretty, inDev) {
|
|
620
|
-
const compact = partial.compact ?? (inDev && pretty);
|
|
621
|
-
const detail = partial.detail ?? (frameworkOverlay ? "guidance" : "full");
|
|
622
|
-
const stackDepth = detail === "guidance" ? 0 : partial.stackDepth ?? (compact ? 2 : 3);
|
|
623
|
-
return {
|
|
624
|
-
snippet: partial.snippet ?? (detail === "full" && pretty && inDev),
|
|
625
|
-
stackDepth,
|
|
626
|
-
compact,
|
|
627
|
-
detail
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
function resolveDevTerminal(input = {}) {
|
|
631
|
-
const pretty = input.pretty ?? isDev();
|
|
632
|
-
const inDev = isDev();
|
|
633
|
-
let frameworkOverlay;
|
|
634
|
-
let prettyError = {};
|
|
635
|
-
if (typeof input.dev === "string" && input.dev in DEV_PRESETS) {
|
|
636
|
-
const { frameworkOverlay: presetOverlay, detail } = DEV_PRESETS[input.dev];
|
|
637
|
-
frameworkOverlay = presetOverlay;
|
|
638
|
-
prettyError = { detail };
|
|
639
|
-
} else if (input.dev && typeof input.dev === "object") {
|
|
640
|
-
const { frameworkOverlay: devOverlay, prettyError: devPrettyError } = input.dev;
|
|
641
|
-
frameworkOverlay = devOverlay;
|
|
642
|
-
if (devPrettyError)
|
|
643
|
-
prettyError = devPrettyError;
|
|
644
|
-
}
|
|
645
|
-
if (frameworkOverlay === undefined)
|
|
646
|
-
frameworkOverlay = !(pretty && inDev);
|
|
647
|
-
return {
|
|
648
|
-
frameworkOverlay,
|
|
649
|
-
prettyError: finalizePrettyError(prettyError, frameworkOverlay, pretty, inDev)
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
// ../../node_modules/.bun/evlog@2.22.3+6e5ab44a2bca2113/node_modules/evlog/dist/error.mjs
|
|
654
|
-
var evlogErrorInternalKey = Symbol.for("evlog.error.internal");
|
|
655
|
-
var EvlogError = class EvlogError2 extends Error {
|
|
656
|
-
code;
|
|
657
|
-
status;
|
|
658
|
-
why;
|
|
659
|
-
fix;
|
|
660
|
-
link;
|
|
661
|
-
get internal() {
|
|
662
|
-
return this[evlogErrorInternalKey];
|
|
663
|
-
}
|
|
664
|
-
constructor(options) {
|
|
665
|
-
const opts = typeof options === "string" ? { message: options } : options;
|
|
666
|
-
super(opts.message, { cause: opts.cause });
|
|
667
|
-
this.name = "EvlogError";
|
|
668
|
-
this.code = opts.code;
|
|
669
|
-
this.status = opts.status ?? 500;
|
|
670
|
-
this.why = opts.why;
|
|
671
|
-
this.fix = opts.fix;
|
|
672
|
-
this.link = opts.link;
|
|
673
|
-
if (opts.internal !== undefined)
|
|
674
|
-
Object.defineProperty(this, evlogErrorInternalKey, {
|
|
675
|
-
value: opts.internal,
|
|
676
|
-
enumerable: false,
|
|
677
|
-
writable: false,
|
|
678
|
-
configurable: true
|
|
679
|
-
});
|
|
680
|
-
if (Error.captureStackTrace)
|
|
681
|
-
Error.captureStackTrace(this, EvlogError2);
|
|
682
|
-
}
|
|
683
|
-
get statusText() {
|
|
684
|
-
return this.message;
|
|
685
|
-
}
|
|
686
|
-
get statusCode() {
|
|
687
|
-
return this.status;
|
|
688
|
-
}
|
|
689
|
-
get statusMessage() {
|
|
690
|
-
return this.message;
|
|
691
|
-
}
|
|
692
|
-
get data() {
|
|
693
|
-
if (this.code || this.why || this.fix || this.link)
|
|
694
|
-
return {
|
|
695
|
-
code: this.code,
|
|
696
|
-
why: this.why,
|
|
697
|
-
fix: this.fix,
|
|
698
|
-
link: this.link
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
toString() {
|
|
702
|
-
const useColors = isServer();
|
|
703
|
-
const red = useColors ? colors.red : "";
|
|
704
|
-
const yellow = useColors ? colors.yellow : "";
|
|
705
|
-
const cyan = useColors ? colors.cyan : "";
|
|
706
|
-
const dim = useColors ? colors.dim : "";
|
|
707
|
-
const reset = useColors ? colors.reset : "";
|
|
708
|
-
const bold = useColors ? colors.bold : "";
|
|
709
|
-
const lines = [];
|
|
710
|
-
lines.push(`${red}${bold}Error:${reset} ${this.message}`);
|
|
711
|
-
if (this.code)
|
|
712
|
-
lines.push(`${dim}Code:${reset} ${this.code}`);
|
|
713
|
-
if (this.why)
|
|
714
|
-
lines.push(`${yellow}Why:${reset} ${this.why}`);
|
|
715
|
-
if (this.fix)
|
|
716
|
-
lines.push(`${cyan}Fix:${reset} ${this.fix}`);
|
|
717
|
-
if (this.link)
|
|
718
|
-
lines.push(`${dim}More info:${reset} ${this.link}`);
|
|
719
|
-
if (this.cause)
|
|
720
|
-
lines.push(`${dim}Caused by:${reset} ${this.cause.message}`);
|
|
721
|
-
return lines.join(`
|
|
722
|
-
`);
|
|
723
|
-
}
|
|
724
|
-
toJSON() {
|
|
725
|
-
const { data } = this;
|
|
726
|
-
return {
|
|
727
|
-
name: this.name,
|
|
728
|
-
message: this.message,
|
|
729
|
-
status: this.status,
|
|
730
|
-
...data && { data },
|
|
731
|
-
...this.cause instanceof Error && { cause: {
|
|
732
|
-
name: this.cause.name,
|
|
733
|
-
message: this.cause.message
|
|
734
|
-
} }
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
|
|
739
|
-
// ../../node_modules/.bun/evlog@2.22.3+6e5ab44a2bca2113/node_modules/evlog/dist/audit-CPODPtOL.mjs
|
|
740
|
-
var DEFAULT_REPLACEMENT = "[REDACTED]";
|
|
741
|
-
function normalizeRedactPathPattern(pattern) {
|
|
742
|
-
if (!pattern.includes("*") && !pattern.includes("."))
|
|
743
|
-
return `**.${pattern}`;
|
|
744
|
-
return pattern;
|
|
745
|
-
}
|
|
746
|
-
function compileRedactPathMatchers(patterns) {
|
|
747
|
-
if (!patterns?.length)
|
|
748
|
-
return;
|
|
749
|
-
const exactPaths = /* @__PURE__ */ new Set;
|
|
750
|
-
const pathGlobs = [];
|
|
751
|
-
const keyGlobs = [];
|
|
752
|
-
const caseInsensitiveLeaves = /* @__PURE__ */ new Set;
|
|
753
|
-
for (const raw of patterns) {
|
|
754
|
-
if (!raw.includes("*")) {
|
|
755
|
-
if (raw.includes("."))
|
|
756
|
-
exactPaths.add(raw);
|
|
757
|
-
else
|
|
758
|
-
addPathGlobPattern(normalizeRedactPathPattern(raw), exactPaths, pathGlobs, caseInsensitiveLeaves);
|
|
759
|
-
continue;
|
|
760
|
-
}
|
|
761
|
-
if (!raw.includes("."))
|
|
762
|
-
keyGlobs.push(globToRegExp(raw, "."));
|
|
763
|
-
else
|
|
764
|
-
addPathGlobPattern(raw, exactPaths, pathGlobs, caseInsensitiveLeaves);
|
|
765
|
-
}
|
|
766
|
-
if (exactPaths.size === 0 && pathGlobs.length === 0 && keyGlobs.length === 0 && caseInsensitiveLeaves.size === 0)
|
|
767
|
-
return;
|
|
768
|
-
return {
|
|
769
|
-
exactPaths,
|
|
770
|
-
pathGlobs,
|
|
771
|
-
keyGlobs,
|
|
772
|
-
caseInsensitiveLeaves
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
function addPathGlobPattern(pattern, exactPaths, pathGlobs, caseInsensitiveLeaves) {
|
|
776
|
-
pathGlobs.push(globToRegExp(pattern, "."));
|
|
777
|
-
const leaf = pattern.match(/^\*\*\.([^.?*]+)$/);
|
|
778
|
-
if (leaf) {
|
|
779
|
-
exactPaths.add(leaf[1]);
|
|
780
|
-
caseInsensitiveLeaves.add(leaf[1].toLowerCase());
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
function matchesRedactPath(fullPath, leafKey, matchers) {
|
|
784
|
-
if (matchers.exactPaths.has(fullPath))
|
|
785
|
-
return true;
|
|
786
|
-
if (matchers.caseInsensitiveLeaves.has(leafKey.toLowerCase()))
|
|
787
|
-
return true;
|
|
788
|
-
for (const glob of matchers.pathGlobs) {
|
|
789
|
-
glob.lastIndex = 0;
|
|
790
|
-
if (glob.test(fullPath))
|
|
791
|
-
return true;
|
|
792
|
-
}
|
|
793
|
-
for (const glob of matchers.keyGlobs) {
|
|
794
|
-
glob.lastIndex = 0;
|
|
795
|
-
if (glob.test(leafKey))
|
|
796
|
-
return true;
|
|
797
|
-
}
|
|
798
|
-
return false;
|
|
799
|
-
}
|
|
800
|
-
function redactPathsInTree(obj, matchers, replacement, prefix = "") {
|
|
801
|
-
if (obj === null || obj === undefined)
|
|
802
|
-
return;
|
|
803
|
-
if (Array.isArray(obj)) {
|
|
804
|
-
for (let i = 0;i < obj.length; i++) {
|
|
805
|
-
const segment = String(i);
|
|
806
|
-
const fullPath = prefix ? `${prefix}.${segment}` : segment;
|
|
807
|
-
redactPathsInTree(obj[i], matchers, replacement, fullPath);
|
|
808
|
-
}
|
|
809
|
-
return;
|
|
810
|
-
}
|
|
811
|
-
if (typeof obj === "object") {
|
|
812
|
-
const record = obj;
|
|
813
|
-
for (const key in record) {
|
|
814
|
-
const fullPath = prefix ? `${prefix}.${key}` : key;
|
|
815
|
-
if (matchesRedactPath(fullPath, key, matchers))
|
|
816
|
-
record[key] = replacement;
|
|
817
|
-
else
|
|
818
|
-
redactPathsInTree(record[key], matchers, replacement, fullPath);
|
|
819
|
-
}
|
|
434
|
+
function setRedacted(record, key, value, path) {
|
|
435
|
+
if (Reflect.set(record, key, value))
|
|
436
|
+
return;
|
|
437
|
+
const desc = Object.getOwnPropertyDescriptor(record, key);
|
|
438
|
+
if (desc && "value" in desc && desc.configurable) {
|
|
439
|
+
Object.defineProperty(record, key, {
|
|
440
|
+
...desc,
|
|
441
|
+
value
|
|
442
|
+
});
|
|
443
|
+
return;
|
|
820
444
|
}
|
|
445
|
+
console.warn(`[evlog] redact could not rewrite read-only field "${path}" \u2014 value left as-is`);
|
|
821
446
|
}
|
|
822
|
-
var builtinPatterns = {
|
|
823
|
-
creditCard: {
|
|
824
|
-
pattern: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,
|
|
825
|
-
mask: (m) => `****${m.replace(/[\s-]/g, "").slice(-4)}`
|
|
826
|
-
},
|
|
827
|
-
email: {
|
|
828
|
-
pattern: /[\w.+-]+@[\w-]+\.[\w.]+/g,
|
|
829
|
-
mask: (m) => {
|
|
830
|
-
if (m.indexOf("@") < 1)
|
|
831
|
-
return "***@***";
|
|
832
|
-
const tld = m.slice(m.lastIndexOf("."));
|
|
833
|
-
return `${m[0]}***@***${tld}`;
|
|
834
|
-
}
|
|
835
|
-
},
|
|
836
|
-
ipv4: {
|
|
837
|
-
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,
|
|
838
|
-
mask: (m) => `***.***.***.${m.split(".").pop()}`
|
|
839
|
-
},
|
|
840
|
-
phone: {
|
|
841
|
-
pattern: /(?:\+\d{1,3}[\s.-]?\(?\d{1,4}\)?|\(\d{1,4}\))(?:[\s.-]?\d{2,4}){2,4}\b/g,
|
|
842
|
-
mask: (m) => {
|
|
843
|
-
const digits = m.replace(/[^\d]/g, "");
|
|
844
|
-
if (m.startsWith("+") && digits.length > 4) {
|
|
845
|
-
const ccMatch = m.match(/^\+\d{1,3}/);
|
|
846
|
-
return `${ccMatch ? ccMatch[0] : "+"}******${digits.slice(-2)}`;
|
|
847
|
-
}
|
|
848
|
-
if (digits.length > 2)
|
|
849
|
-
return `${"*".repeat(digits.length - 2)}${digits.slice(-2)}`;
|
|
850
|
-
return "***";
|
|
851
|
-
}
|
|
852
|
-
},
|
|
853
|
-
jwt: {
|
|
854
|
-
pattern: /\beyJ[\w-]*\.[\w-]*\.[\w-]*\b/g,
|
|
855
|
-
mask: () => "eyJ***.***"
|
|
856
|
-
},
|
|
857
|
-
bearer: {
|
|
858
|
-
pattern: /\bBearer\s+[\w\-.~+/]{8,}=*/gi,
|
|
859
|
-
mask: () => "Bearer ***"
|
|
860
|
-
},
|
|
861
|
-
iban: {
|
|
862
|
-
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,
|
|
863
|
-
mask: (m) => {
|
|
864
|
-
const clean = m.replace(/[\s-]/g, "");
|
|
865
|
-
return `${clean.slice(0, 4)}****${clean.slice(-3)}`;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
447
|
function resolveRedactConfig(input) {
|
|
870
448
|
if (input === undefined || input === false)
|
|
871
449
|
return;
|
|
@@ -889,7 +467,6 @@ function allBuiltinMaskers() {
|
|
|
889
467
|
function cloneRegex(re) {
|
|
890
468
|
return new RegExp(re.source, re.flags);
|
|
891
469
|
}
|
|
892
|
-
var globallyRedacted = Symbol.for("evlog.globallyRedacted");
|
|
893
470
|
function markGloballyRedacted(event) {
|
|
894
471
|
Object.defineProperty(event, globallyRedacted, {
|
|
895
472
|
value: true,
|
|
@@ -912,7 +489,13 @@ function cloneForRedaction(event) {
|
|
|
912
489
|
function redactEvent(event, config) {
|
|
913
490
|
const clone = cloneForRedaction(event);
|
|
914
491
|
const replacement = config.replacement ?? DEFAULT_REPLACEMENT;
|
|
915
|
-
|
|
492
|
+
if (config.transform)
|
|
493
|
+
try {
|
|
494
|
+
config.transform(clone);
|
|
495
|
+
} catch (err) {
|
|
496
|
+
console.error("[evlog] redact transform failed:", err);
|
|
497
|
+
}
|
|
498
|
+
const pathMatchers = config._pathMatchers ?? compileRedactPathMatchers(config.paths);
|
|
916
499
|
if (pathMatchers)
|
|
917
500
|
redactPathsInTree(clone, pathMatchers, replacement);
|
|
918
501
|
if (config._maskers?.length)
|
|
@@ -921,34 +504,55 @@ function redactEvent(event, config) {
|
|
|
921
504
|
redactPatterns(clone, config.patterns, replacement);
|
|
922
505
|
return clone;
|
|
923
506
|
}
|
|
924
|
-
function redactPatterns(obj, patterns, replacement) {
|
|
507
|
+
function redactPatterns(obj, patterns, replacement, prefix = "") {
|
|
925
508
|
if (obj === null || obj === undefined)
|
|
926
509
|
return;
|
|
927
510
|
if (Array.isArray(obj)) {
|
|
928
|
-
for (let i = 0;i < obj.length; i++)
|
|
511
|
+
for (let i = 0;i < obj.length; i++) {
|
|
512
|
+
const key = String(i);
|
|
513
|
+
const fullPath = prefix ? `${prefix}.${key}` : key;
|
|
929
514
|
if (typeof obj[i] === "string")
|
|
930
|
-
obj[i] = applyPatterns(obj[i], patterns, replacement);
|
|
515
|
+
obj[i] = applyPatterns(obj[i], patterns, replacement, fullPath, key);
|
|
931
516
|
else if (typeof obj[i] === "object")
|
|
932
|
-
redactPatterns(obj[i], patterns, replacement);
|
|
517
|
+
redactPatterns(obj[i], patterns, replacement, fullPath);
|
|
518
|
+
}
|
|
933
519
|
return;
|
|
934
520
|
}
|
|
935
521
|
if (typeof obj === "object") {
|
|
936
522
|
const record = obj;
|
|
937
|
-
for (const key
|
|
523
|
+
for (const key of redactableKeys(record)) {
|
|
938
524
|
const val = record[key];
|
|
525
|
+
const fullPath = prefix ? `${prefix}.${key}` : key;
|
|
939
526
|
if (typeof val === "string")
|
|
940
|
-
record
|
|
527
|
+
setRedacted(record, key, applyPatterns(val, patterns, replacement, fullPath, key), fullPath);
|
|
941
528
|
else if (typeof val === "object")
|
|
942
|
-
redactPatterns(val, patterns, replacement);
|
|
529
|
+
redactPatterns(val, patterns, replacement, fullPath);
|
|
943
530
|
}
|
|
944
531
|
}
|
|
945
532
|
}
|
|
946
|
-
function applyPatterns(value, patterns, replacement) {
|
|
533
|
+
function applyPatterns(value, patterns, replacement, path, key) {
|
|
947
534
|
let result = value;
|
|
948
|
-
for (const pattern of patterns)
|
|
949
|
-
|
|
535
|
+
for (const pattern of patterns) {
|
|
536
|
+
if (typeof replacement === "string") {
|
|
537
|
+
result = result.replace(pattern, replacement);
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
result = result.replace(pattern, (...args) => {
|
|
541
|
+
const match = args[0];
|
|
542
|
+
return resolveReplacement(replacement, match, {
|
|
543
|
+
path,
|
|
544
|
+
key,
|
|
545
|
+
groups: captureGroups(args)
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
}
|
|
950
549
|
return result;
|
|
951
550
|
}
|
|
551
|
+
function captureGroups(args) {
|
|
552
|
+
const last = args.at(-1);
|
|
553
|
+
const trailing = typeof last === "object" && last !== null ? 3 : 2;
|
|
554
|
+
return args.slice(1, Math.max(1, args.length - trailing));
|
|
555
|
+
}
|
|
952
556
|
function applyMaskersToTree(obj, maskers) {
|
|
953
557
|
if (obj === null || obj === undefined)
|
|
954
558
|
return;
|
|
@@ -962,10 +566,10 @@ function applyMaskersToTree(obj, maskers) {
|
|
|
962
566
|
}
|
|
963
567
|
if (typeof obj === "object") {
|
|
964
568
|
const record = obj;
|
|
965
|
-
for (const key
|
|
569
|
+
for (const key of redactableKeys(record)) {
|
|
966
570
|
const val = record[key];
|
|
967
571
|
if (typeof val === "string")
|
|
968
|
-
record
|
|
572
|
+
setRedacted(record, key, applyMaskers(val, maskers), key);
|
|
969
573
|
else if (typeof val === "object")
|
|
970
574
|
applyMaskersToTree(val, maskers);
|
|
971
575
|
}
|
|
@@ -977,6 +581,60 @@ function applyMaskers(value, maskers) {
|
|
|
977
581
|
result = result.replace(pattern, mask);
|
|
978
582
|
return result;
|
|
979
583
|
}
|
|
584
|
+
var DEFAULT_REPLACEMENT = "[REDACTED]", builtinPatterns, globallyRedacted;
|
|
585
|
+
var init_redact_C7FmdhwI = __esm(() => {
|
|
586
|
+
init_utils();
|
|
587
|
+
builtinPatterns = {
|
|
588
|
+
creditCard: {
|
|
589
|
+
pattern: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,
|
|
590
|
+
mask: (m) => `****${m.replace(/[\s-]/g, "").slice(-4)}`
|
|
591
|
+
},
|
|
592
|
+
email: {
|
|
593
|
+
pattern: /[\w.+-]+@[\w-]+\.[\w.]+/g,
|
|
594
|
+
mask: (m) => {
|
|
595
|
+
if (m.indexOf("@") < 1)
|
|
596
|
+
return "***@***";
|
|
597
|
+
const tld = m.slice(m.lastIndexOf("."));
|
|
598
|
+
return `${m[0]}***@***${tld}`;
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
ipv4: {
|
|
602
|
+
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,
|
|
603
|
+
mask: (m) => `***.***.***.${m.split(".").pop()}`
|
|
604
|
+
},
|
|
605
|
+
phone: {
|
|
606
|
+
pattern: /(?:\+\d{1,3}[\s.-]?\(?\d{1,4}\)?|\(\d{1,4}\))(?:[\s.-]?\d{2,4}){2,4}\b/g,
|
|
607
|
+
mask: (m) => {
|
|
608
|
+
const digits = m.replace(/[^\d]/g, "");
|
|
609
|
+
if (m.startsWith("+") && digits.length > 4) {
|
|
610
|
+
const ccMatch = m.match(/^\+\d{1,3}/);
|
|
611
|
+
return `${ccMatch ? ccMatch[0] : "+"}******${digits.slice(-2)}`;
|
|
612
|
+
}
|
|
613
|
+
if (digits.length > 2)
|
|
614
|
+
return `${"*".repeat(digits.length - 2)}${digits.slice(-2)}`;
|
|
615
|
+
return "***";
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
jwt: {
|
|
619
|
+
pattern: /\beyJ[\w-]*\.[\w-]*\.[\w-]*\b/g,
|
|
620
|
+
mask: () => "eyJ***.***"
|
|
621
|
+
},
|
|
622
|
+
bearer: {
|
|
623
|
+
pattern: /\bBearer\s+[\w\-.~+/]{8,}=*/gi,
|
|
624
|
+
mask: () => "Bearer ***"
|
|
625
|
+
},
|
|
626
|
+
iban: {
|
|
627
|
+
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,
|
|
628
|
+
mask: (m) => {
|
|
629
|
+
const clean = m.replace(/[\s-]/g, "");
|
|
630
|
+
return `${clean.slice(0, 4)}****${clean.slice(-3)}`;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
globallyRedacted = Symbol.for("evlog.globallyRedacted");
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/globalRegistry-Bh3bIGwA.mjs
|
|
980
638
|
function logPluginError(name, hook, err) {
|
|
981
639
|
console.error(`[evlog/${name}] ${hook} failed:`, err);
|
|
982
640
|
}
|
|
@@ -1071,36 +729,564 @@ function createPluginRunner(plugins = []) {
|
|
|
1071
729
|
}
|
|
1072
730
|
}
|
|
1073
731
|
},
|
|
1074
|
-
async runSetup(ctx) {
|
|
1075
|
-
for (const plugin of list) {
|
|
1076
|
-
if (!plugin.setup)
|
|
1077
|
-
continue;
|
|
1078
|
-
try {
|
|
1079
|
-
await plugin.setup(ctx);
|
|
1080
|
-
} catch (err) {
|
|
1081
|
-
logPluginError(plugin.name, "setup", err);
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
732
|
+
async runSetup(ctx) {
|
|
733
|
+
for (const plugin of list) {
|
|
734
|
+
if (!plugin.setup)
|
|
735
|
+
continue;
|
|
736
|
+
try {
|
|
737
|
+
await plugin.setup(ctx);
|
|
738
|
+
} catch (err) {
|
|
739
|
+
logPluginError(plugin.name, "setup", err);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
function getEmptyPluginRunner() {
|
|
746
|
+
return emptyRunner;
|
|
747
|
+
}
|
|
748
|
+
function createConfig() {
|
|
749
|
+
return {
|
|
750
|
+
env: {
|
|
751
|
+
service: "app",
|
|
752
|
+
environment: "development"
|
|
753
|
+
},
|
|
754
|
+
pretty: isDev(),
|
|
755
|
+
prettyError: {
|
|
756
|
+
snippet: isDev(),
|
|
757
|
+
stackDepth: 2,
|
|
758
|
+
compact: isDev(),
|
|
759
|
+
detail: "full"
|
|
760
|
+
},
|
|
761
|
+
sampling: {},
|
|
762
|
+
stringify: true,
|
|
763
|
+
drain: undefined,
|
|
764
|
+
redact: undefined,
|
|
765
|
+
enabled: true,
|
|
766
|
+
silent: false,
|
|
767
|
+
minLevel: "debug",
|
|
768
|
+
locked: false,
|
|
769
|
+
initialized: false,
|
|
770
|
+
pluginRunner: getEmptyPluginRunner()
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
function warnOnMultiMajor(host) {
|
|
774
|
+
const majors = host[MAJORS_KEY] ??= /* @__PURE__ */ new Set;
|
|
775
|
+
if (majors.has(EVLOG_MAJOR))
|
|
776
|
+
return;
|
|
777
|
+
majors.add(EVLOG_MAJOR);
|
|
778
|
+
if (majors.size > 1)
|
|
779
|
+
console.warn(`[evlog] Multiple major versions of evlog are loaded in this process (${[...majors].map((m) => `${m}.x`).join(", ")}). They cannot share request scope or logger configuration: events emitted through the other copy will be undrained and unredacted, and useLogger() may throw. Deduplicate evlog to a single major.`);
|
|
780
|
+
}
|
|
781
|
+
function getRegistry() {
|
|
782
|
+
const host = globalThis;
|
|
783
|
+
warnOnMultiMajor(host);
|
|
784
|
+
return host[REGISTRY_KEY] ??= {
|
|
785
|
+
config: createConfig(),
|
|
786
|
+
storages: /* @__PURE__ */ new Map
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
var emptyRunner, EVLOG_MAJOR = 2, REGISTRY_KEY, MAJORS_KEY, globalConfig;
|
|
790
|
+
var init_globalRegistry_Bh3bIGwA = __esm(() => {
|
|
791
|
+
init_utils();
|
|
792
|
+
emptyRunner = createPluginRunner([]);
|
|
793
|
+
REGISTRY_KEY = Symbol.for(`evlog.registry.v${EVLOG_MAJOR}`);
|
|
794
|
+
MAJORS_KEY = Symbol.for("evlog.majors");
|
|
795
|
+
globalConfig = getRegistry().config;
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/pretty-error-DTIHxnBN.mjs
|
|
799
|
+
function pushTreeSpacer(children) {
|
|
800
|
+
children.push(PRETTY_ERROR_TREE_SPACER);
|
|
801
|
+
}
|
|
802
|
+
function isPlainObject(val) {
|
|
803
|
+
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
804
|
+
}
|
|
805
|
+
function pickString(obj, key) {
|
|
806
|
+
const val = obj[key];
|
|
807
|
+
return typeof val === "string" && val.length > 0 ? val : undefined;
|
|
808
|
+
}
|
|
809
|
+
function pickNumber(obj, key) {
|
|
810
|
+
const val = obj[key];
|
|
811
|
+
return typeof val === "number" ? val : undefined;
|
|
812
|
+
}
|
|
813
|
+
function extractGuidance(data) {
|
|
814
|
+
return {
|
|
815
|
+
code: pickString(data, "code"),
|
|
816
|
+
why: pickString(data, "why"),
|
|
817
|
+
fix: pickString(data, "fix"),
|
|
818
|
+
link: pickString(data, "link")
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
function normalizeErrorContext(error) {
|
|
822
|
+
if (error === null || error === undefined)
|
|
823
|
+
return null;
|
|
824
|
+
if (typeof error === "string")
|
|
825
|
+
return { message: error };
|
|
826
|
+
if (!isPlainObject(error))
|
|
827
|
+
return { message: String(error) };
|
|
828
|
+
const result = {
|
|
829
|
+
message: pickString(error, "message") ?? pickString(error, "statusText") ?? pickString(error, "statusMessage") ?? "Unknown error",
|
|
830
|
+
name: pickString(error, "name"),
|
|
831
|
+
code: pickString(error, "code"),
|
|
832
|
+
why: pickString(error, "why"),
|
|
833
|
+
fix: pickString(error, "fix"),
|
|
834
|
+
link: pickString(error, "link"),
|
|
835
|
+
status: pickNumber(error, "status") ?? pickNumber(error, "statusCode"),
|
|
836
|
+
stack: pickString(error, "stack")
|
|
837
|
+
};
|
|
838
|
+
const { data, cause } = error;
|
|
839
|
+
if (isPlainObject(data)) {
|
|
840
|
+
const guidance = extractGuidance(data);
|
|
841
|
+
if (!result.code)
|
|
842
|
+
result.code = guidance.code;
|
|
843
|
+
if (!result.why)
|
|
844
|
+
result.why = guidance.why;
|
|
845
|
+
if (!result.fix)
|
|
846
|
+
result.fix = guidance.fix;
|
|
847
|
+
if (!result.link)
|
|
848
|
+
result.link = guidance.link;
|
|
849
|
+
}
|
|
850
|
+
if (cause instanceof Error)
|
|
851
|
+
result.cause = cause.message;
|
|
852
|
+
else if (isPlainObject(cause) && pickString(cause, "message"))
|
|
853
|
+
result.cause = pickString(cause, "message");
|
|
854
|
+
return result;
|
|
855
|
+
}
|
|
856
|
+
function decodeFileUrl(file) {
|
|
857
|
+
if (file.startsWith("file://"))
|
|
858
|
+
try {
|
|
859
|
+
return decodeURIComponent(new URL(file).pathname);
|
|
860
|
+
} catch {
|
|
861
|
+
return file.slice(7);
|
|
862
|
+
}
|
|
863
|
+
return file;
|
|
864
|
+
}
|
|
865
|
+
function isAppPath(file) {
|
|
866
|
+
const normalized = decodeFileUrl(file).replace(/\\/g, "/");
|
|
867
|
+
if (normalized.startsWith("node:"))
|
|
868
|
+
return false;
|
|
869
|
+
if (SKIP_PATH_RE.test(normalized))
|
|
870
|
+
return false;
|
|
871
|
+
if (normalized.includes("/node_modules/"))
|
|
872
|
+
return false;
|
|
873
|
+
if (isFrameworkRuntimePath(normalized))
|
|
874
|
+
return false;
|
|
875
|
+
return true;
|
|
876
|
+
}
|
|
877
|
+
function formatDisplayPath(file, cwd) {
|
|
878
|
+
const decoded = decodeFileUrl(file).replace(/\\/g, "/");
|
|
879
|
+
const cwdNorm = cwd.replace(/\\/g, "/").replace(/\/$/, "");
|
|
880
|
+
if (cwdNorm && decoded.startsWith(`${cwdNorm}/`)) {
|
|
881
|
+
const rel = decoded.slice(cwdNorm.length + 1);
|
|
882
|
+
return rel.startsWith("./") ? rel.slice(2) : rel;
|
|
883
|
+
}
|
|
884
|
+
const serverIdx = decoded.indexOf("/server/");
|
|
885
|
+
if (serverIdx >= 0)
|
|
886
|
+
return decoded.slice(serverIdx + 1);
|
|
887
|
+
const srcIdx = decoded.indexOf("/src/");
|
|
888
|
+
if (srcIdx >= 0)
|
|
889
|
+
return decoded.slice(srcIdx + 1);
|
|
890
|
+
return decoded;
|
|
891
|
+
}
|
|
892
|
+
function compactStackForStorage(stack, maxFrames = 5) {
|
|
893
|
+
if (!stack)
|
|
894
|
+
return;
|
|
895
|
+
const head = stack.split(`
|
|
896
|
+
`)[0] ?? "";
|
|
897
|
+
const useful = parseStackFrames(stack).filter((f) => f.file && f.line && f.isApp && !isInternalErrorFrame(f)).slice(0, maxFrames);
|
|
898
|
+
if (useful.length === 0)
|
|
899
|
+
return stack;
|
|
900
|
+
return [head, ...useful.map((f) => f.raw)].join(`
|
|
901
|
+
`);
|
|
902
|
+
}
|
|
903
|
+
function parseStackFrames(stack) {
|
|
904
|
+
if (!stack)
|
|
905
|
+
return [];
|
|
906
|
+
const lines = stack.split(`
|
|
907
|
+
`);
|
|
908
|
+
const frames = [];
|
|
909
|
+
for (const line of lines) {
|
|
910
|
+
const trimmed = line.trim();
|
|
911
|
+
if (!trimmed.startsWith("at "))
|
|
912
|
+
continue;
|
|
913
|
+
const withFn = trimmed.match(/^at (.+?) \((.+):(\d+):(\d+)\)$/);
|
|
914
|
+
if (withFn) {
|
|
915
|
+
const [, fn, file, lineStr, colStr] = withFn;
|
|
916
|
+
frames.push({
|
|
917
|
+
raw: trimmed,
|
|
918
|
+
fn,
|
|
919
|
+
file,
|
|
920
|
+
line: Number(lineStr),
|
|
921
|
+
column: Number(colStr),
|
|
922
|
+
isApp: isAppPath(file)
|
|
923
|
+
});
|
|
924
|
+
continue;
|
|
925
|
+
}
|
|
926
|
+
const withoutFn = trimmed.match(/^at (.+):(\d+):(\d+)$/);
|
|
927
|
+
if (withoutFn) {
|
|
928
|
+
const [, file, lineStr, colStr] = withoutFn;
|
|
929
|
+
frames.push({
|
|
930
|
+
raw: trimmed,
|
|
931
|
+
file,
|
|
932
|
+
line: Number(lineStr),
|
|
933
|
+
column: Number(colStr),
|
|
934
|
+
isApp: isAppPath(file)
|
|
935
|
+
});
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
const asyncFn = trimmed.match(/^at async (.+?) \((.+):(\d+):(\d+)\)$/);
|
|
939
|
+
if (asyncFn) {
|
|
940
|
+
const [, fn, file, lineStr, colStr] = asyncFn;
|
|
941
|
+
frames.push({
|
|
942
|
+
raw: trimmed,
|
|
943
|
+
fn: `async ${fn}`,
|
|
944
|
+
file,
|
|
945
|
+
line: Number(lineStr),
|
|
946
|
+
column: Number(colStr),
|
|
947
|
+
isApp: isAppPath(file)
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
return frames;
|
|
952
|
+
}
|
|
953
|
+
function isFrameworkRuntimePath(path) {
|
|
954
|
+
const normalized = path.replace(/\\/g, "/");
|
|
955
|
+
return normalized.includes("route-modules/") || normalized.includes("webpack://next/") || normalized.includes("/next/dist/") || normalized.includes("/compiled/next-server/");
|
|
956
|
+
}
|
|
957
|
+
function isFrameworkRuntimeFrame(frame) {
|
|
958
|
+
if (!frame.file)
|
|
959
|
+
return false;
|
|
960
|
+
return isFrameworkRuntimePath(decodeFileUrl(frame.file));
|
|
961
|
+
}
|
|
962
|
+
function isInternalErrorFrame(frame) {
|
|
963
|
+
if (isFrameworkRuntimeFrame(frame))
|
|
964
|
+
return true;
|
|
965
|
+
if (frame.fn) {
|
|
966
|
+
const fn = frame.fn.replace(/^async /, "");
|
|
967
|
+
if (SKIP_FRAME_FN_RE.test(fn))
|
|
968
|
+
return true;
|
|
969
|
+
}
|
|
970
|
+
if (!frame.file)
|
|
971
|
+
return true;
|
|
972
|
+
const path = decodeFileUrl(frame.file).replace(/\\/g, "/");
|
|
973
|
+
if (SKIP_FRAME_PATH_RE.test(path))
|
|
974
|
+
return true;
|
|
975
|
+
if (path.includes(".nuxt/"))
|
|
976
|
+
return true;
|
|
977
|
+
if (path.includes(".next/"))
|
|
978
|
+
return true;
|
|
979
|
+
return false;
|
|
980
|
+
}
|
|
981
|
+
function pickPrimaryFrame(frames) {
|
|
982
|
+
for (const frame of frames)
|
|
983
|
+
if (frame.isApp && frame.file && frame.line && !isInternalErrorFrame(frame))
|
|
984
|
+
return frame;
|
|
985
|
+
}
|
|
986
|
+
function readCodeSnippet(file, line, contextLines = 2) {
|
|
987
|
+
if (!isDev() || isBrowser() || !snippetReader)
|
|
988
|
+
return null;
|
|
989
|
+
const path = decodeFileUrl(file).replace(/\\/g, "/");
|
|
990
|
+
if (path.includes(".next/") || path.includes(".nuxt/") || path.includes(".output/"))
|
|
991
|
+
return null;
|
|
992
|
+
return snippetReader(file, line, contextLines);
|
|
993
|
+
}
|
|
994
|
+
function formatSnippetLines(snippet) {
|
|
995
|
+
const width = String(snippet[snippet.length - 1]?.line ?? 0).length;
|
|
996
|
+
return snippet.map(({ line, content, isErrorLine }) => {
|
|
997
|
+
const marker = isErrorLine ? `${colors.red}\u276F${colors.reset}` : `${colors.dim} ${colors.reset}`;
|
|
998
|
+
const numColor = isErrorLine ? colors.red : colors.gray;
|
|
999
|
+
const trimmed = content.length > 120 ? `${content.slice(0, 117)}\u2026` : content;
|
|
1000
|
+
return `${marker} ${numColor}${String(line).padStart(width, " ")}${colors.reset} ${colors.dim}\u2503${colors.reset} ${colors.dim}${trimmed}${colors.reset}`;
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
function formatFrameLocation(frame, cwd) {
|
|
1004
|
+
const file = frame.file ? formatDisplayPath(frame.file, cwd) : "unknown";
|
|
1005
|
+
const loc = frame.line ? `${file}:${frame.line}` : file;
|
|
1006
|
+
const fn = frame.fn && frame.fn !== "<unknown>" ? frame.fn : undefined;
|
|
1007
|
+
return fn ? `at ${fn} (${loc})` : `at ${loc}`;
|
|
1008
|
+
}
|
|
1009
|
+
function formatCollapsedFrame(frame, cwd) {
|
|
1010
|
+
const file = frame.file ? formatDisplayPath(frame.file, cwd) : "unknown";
|
|
1011
|
+
const loc = frame.line ? `${file}:${frame.line}` : file;
|
|
1012
|
+
const prefix = frame.fn?.startsWith("async") ? "at async " : "at ";
|
|
1013
|
+
const fn = frame.fn?.replace(/^async /, "");
|
|
1014
|
+
if (fn && fn !== "<unknown>" && fn !== loc)
|
|
1015
|
+
return `${prefix}${fn} (${loc})`;
|
|
1016
|
+
return `${prefix}${loc}`;
|
|
1017
|
+
}
|
|
1018
|
+
function formatGuidanceLine(label, text, labelColor) {
|
|
1019
|
+
const prefix = `${labelColor}${label}:${colors.reset} `;
|
|
1020
|
+
const lines = [];
|
|
1021
|
+
let remaining = text.trim();
|
|
1022
|
+
let first = true;
|
|
1023
|
+
while (remaining.length > 0) {
|
|
1024
|
+
const budget = first ? Math.max(24, GUIDANCE_WRAP_WIDTH - prefix.length) : Math.max(24, GUIDANCE_WRAP_WIDTH - 5);
|
|
1025
|
+
if (remaining.length <= budget) {
|
|
1026
|
+
lines.push(first ? `${prefix}${remaining}` : `${GUIDANCE_CONTINUATION}${remaining}`);
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
let split = remaining.lastIndexOf(" ", budget);
|
|
1030
|
+
if (split <= 0)
|
|
1031
|
+
split = budget;
|
|
1032
|
+
const chunk = remaining.slice(0, split).trimEnd();
|
|
1033
|
+
lines.push(first ? `${prefix}${chunk}` : `${GUIDANCE_CONTINUATION}${chunk}`);
|
|
1034
|
+
remaining = remaining.slice(split).trimStart();
|
|
1035
|
+
first = false;
|
|
1036
|
+
}
|
|
1037
|
+
return lines;
|
|
1038
|
+
}
|
|
1039
|
+
function buildErrorEntries(error, options = {}) {
|
|
1040
|
+
const normalized = normalizeErrorContext(error);
|
|
1041
|
+
if (!normalized)
|
|
1042
|
+
return [];
|
|
1043
|
+
const cwd = options.cwd ?? (typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".");
|
|
1044
|
+
const compact = options.compact ?? isDev();
|
|
1045
|
+
const guidanceOnly = (options.detail ?? "full") === "guidance";
|
|
1046
|
+
const showFrames = !guidanceOnly && !isBrowser() && (options.snippet ?? isDev());
|
|
1047
|
+
const stackDepth = guidanceOnly ? 0 : options.stackDepth ?? (compact ? 2 : 3);
|
|
1048
|
+
const snippetContextLines = compact ? 1 : 2;
|
|
1049
|
+
const children = [];
|
|
1050
|
+
const frames = guidanceOnly ? [] : parseStackFrames(normalized.stack);
|
|
1051
|
+
const primary = guidanceOnly ? undefined : pickPrimaryFrame(frames);
|
|
1052
|
+
if (!guidanceOnly && primary?.file && primary.line) {
|
|
1053
|
+
pushTreeSpacer(children);
|
|
1054
|
+
if (showFrames) {
|
|
1055
|
+
const snippet = readCodeSnippet(primary.file, primary.line, snippetContextLines);
|
|
1056
|
+
children.push(`${colors.dim} ${formatFrameLocation(primary, cwd)}${colors.reset}`);
|
|
1057
|
+
if (snippet)
|
|
1058
|
+
children.push(...formatSnippetLines(snippet));
|
|
1059
|
+
} else
|
|
1060
|
+
children.push(`${colors.dim} ${formatFrameLocation(primary, cwd)}${colors.reset}`);
|
|
1061
|
+
}
|
|
1062
|
+
if (normalized.code)
|
|
1063
|
+
children.push(`${colors.dim}Code:${colors.reset} ${normalized.code}`);
|
|
1064
|
+
if (Boolean(normalized.why || normalized.fix || normalized.link))
|
|
1065
|
+
pushTreeSpacer(children);
|
|
1066
|
+
if (normalized.why)
|
|
1067
|
+
children.push(...formatGuidanceLine("Why", normalized.why, colors.yellow));
|
|
1068
|
+
if (normalized.fix)
|
|
1069
|
+
children.push(...formatGuidanceLine("Fix", normalized.fix, colors.cyan));
|
|
1070
|
+
if (normalized.link)
|
|
1071
|
+
children.push(`${colors.dim}More:${colors.reset} ${normalized.link}`);
|
|
1072
|
+
if (normalized.cause && normalized.cause !== normalized.message)
|
|
1073
|
+
children.push(`${colors.dim}Caused by:${colors.reset} ${normalized.cause}`);
|
|
1074
|
+
const hiddenCount = guidanceOnly ? 0 : frames.filter((f) => !f.isApp || isInternalErrorFrame(f)).length;
|
|
1075
|
+
const tailFrames = stackDepth > 0 ? frames.filter((f) => f !== primary && !isInternalErrorFrame(f)).slice(0, stackDepth) : [];
|
|
1076
|
+
if (!guidanceOnly && (hiddenCount > 0 || tailFrames.length > 0)) {
|
|
1077
|
+
pushTreeSpacer(children);
|
|
1078
|
+
if (hiddenCount > 0)
|
|
1079
|
+
children.push(`${colors.gray}stack (${hiddenCount} frame${hiddenCount === 1 ? "" : "s"} hidden in node_modules)${colors.reset}`);
|
|
1080
|
+
else
|
|
1081
|
+
children.push(`${colors.gray}stack${colors.reset}`);
|
|
1082
|
+
for (const frame of tailFrames)
|
|
1083
|
+
children.push(`${colors.gray} ${formatCollapsedFrame(frame, cwd)}${colors.reset}`);
|
|
1084
|
+
}
|
|
1085
|
+
return [{
|
|
1086
|
+
key: "error",
|
|
1087
|
+
value: `${colors.red}${colors.bold}${normalized.message}${colors.reset}`,
|
|
1088
|
+
children: children.length > 0 ? children : undefined
|
|
1089
|
+
}];
|
|
1090
|
+
}
|
|
1091
|
+
var snippetReader = null, PRETTY_ERROR_TREE_SPACER = "__EVLOG_TREE_SPACER__", SKIP_PATH_RE, SKIP_FRAME_PATH_RE, SKIP_FRAME_FN_RE, GUIDANCE_WRAP_WIDTH = 76, GUIDANCE_CONTINUATION = " ";
|
|
1092
|
+
var init_pretty_error_DTIHxnBN = __esm(() => {
|
|
1093
|
+
init_utils();
|
|
1094
|
+
SKIP_PATH_RE = /(?:^|[/\\])(?:node_modules|\.nuxt|\.next|\.output)(?:[/\\]|$)/;
|
|
1095
|
+
SKIP_FRAME_PATH_RE = /(?:^|[/\\])(?:packages[/\\]evlog|evlog[/\\](?:dist|src))(?:[/\\]|$)/;
|
|
1096
|
+
SKIP_FRAME_FN_RE = /^(?:createError|EvlogError|new EvlogError)$/;
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1099
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/dev-terminal-Brarc6vc.mjs
|
|
1100
|
+
function finalizePrettyError(partial, frameworkOverlay, pretty, inDev) {
|
|
1101
|
+
const compact = partial.compact ?? (inDev && pretty);
|
|
1102
|
+
const detail = partial.detail ?? (frameworkOverlay ? "guidance" : "full");
|
|
1103
|
+
const stackDepth = detail === "guidance" ? 0 : partial.stackDepth ?? (compact ? 2 : 3);
|
|
1104
|
+
return {
|
|
1105
|
+
snippet: partial.snippet ?? (detail === "full" && pretty && inDev),
|
|
1106
|
+
stackDepth,
|
|
1107
|
+
compact,
|
|
1108
|
+
detail
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
function resolveDevTerminal(input = {}) {
|
|
1112
|
+
const pretty = input.pretty ?? isDev();
|
|
1113
|
+
const inDev = isDev();
|
|
1114
|
+
let frameworkOverlay;
|
|
1115
|
+
let prettyError = {};
|
|
1116
|
+
if (typeof input.dev === "string" && input.dev in DEV_PRESETS) {
|
|
1117
|
+
const { frameworkOverlay: presetOverlay, detail } = DEV_PRESETS[input.dev];
|
|
1118
|
+
frameworkOverlay = presetOverlay;
|
|
1119
|
+
prettyError = { detail };
|
|
1120
|
+
} else if (input.dev && typeof input.dev === "object") {
|
|
1121
|
+
const { frameworkOverlay: devOverlay, prettyError: devPrettyError } = input.dev;
|
|
1122
|
+
frameworkOverlay = devOverlay;
|
|
1123
|
+
if (devPrettyError)
|
|
1124
|
+
prettyError = devPrettyError;
|
|
1125
|
+
}
|
|
1126
|
+
if (frameworkOverlay === undefined)
|
|
1127
|
+
frameworkOverlay = !(pretty && inDev);
|
|
1128
|
+
return {
|
|
1129
|
+
frameworkOverlay,
|
|
1130
|
+
prettyError: finalizePrettyError(prettyError, frameworkOverlay, pretty, inDev)
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
var DEV_PRESETS;
|
|
1134
|
+
var init_dev_terminal_Brarc6vc = __esm(() => {
|
|
1135
|
+
init_utils();
|
|
1136
|
+
DEV_PRESETS = {
|
|
1137
|
+
evlog: {
|
|
1138
|
+
frameworkOverlay: false,
|
|
1139
|
+
detail: "full"
|
|
1140
|
+
},
|
|
1141
|
+
nitro: {
|
|
1142
|
+
frameworkOverlay: true,
|
|
1143
|
+
detail: "guidance"
|
|
1144
|
+
},
|
|
1145
|
+
both: {
|
|
1146
|
+
frameworkOverlay: true,
|
|
1147
|
+
detail: "full"
|
|
1084
1148
|
}
|
|
1085
1149
|
};
|
|
1150
|
+
});
|
|
1151
|
+
|
|
1152
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/wideEventChannel-BUDW48oP.mjs
|
|
1153
|
+
function publishWideEvent(event) {
|
|
1154
|
+
if (!publisher)
|
|
1155
|
+
return;
|
|
1156
|
+
try {
|
|
1157
|
+
publisher(event);
|
|
1158
|
+
} catch (err) {
|
|
1159
|
+
console.error("[evlog] diagnostics channel publish failed:", err);
|
|
1160
|
+
}
|
|
1086
1161
|
}
|
|
1087
|
-
var
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1162
|
+
var publisher = null;
|
|
1163
|
+
var init_wideEventChannel_BUDW48oP = () => {};
|
|
1164
|
+
|
|
1165
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/error-brand-D0-DCPvr.mjs
|
|
1166
|
+
function isEvlogError(error) {
|
|
1167
|
+
return typeof error === "object" && error !== null && error[evlogErrorBrand] === true;
|
|
1168
|
+
}
|
|
1169
|
+
var evlogErrorBrand;
|
|
1170
|
+
var init_error_brand_D0_DCPvr = __esm(() => {
|
|
1171
|
+
evlogErrorBrand = Symbol.for("evlog.error.brand");
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/error.mjs
|
|
1175
|
+
var evlogErrorInternalKey, evlogErrorDataKey, EvlogError;
|
|
1176
|
+
var init_error = __esm(() => {
|
|
1177
|
+
init_utils();
|
|
1178
|
+
init_error_brand_D0_DCPvr();
|
|
1179
|
+
evlogErrorInternalKey = Symbol.for("evlog.error.internal");
|
|
1180
|
+
evlogErrorDataKey = Symbol.for("evlog.error.data");
|
|
1181
|
+
EvlogError = class EvlogError extends Error {
|
|
1182
|
+
static isEvlogError(error) {
|
|
1183
|
+
return isEvlogError(error);
|
|
1184
|
+
}
|
|
1185
|
+
code;
|
|
1186
|
+
status;
|
|
1187
|
+
why;
|
|
1188
|
+
fix;
|
|
1189
|
+
link;
|
|
1190
|
+
get internal() {
|
|
1191
|
+
return this[evlogErrorInternalKey];
|
|
1192
|
+
}
|
|
1193
|
+
constructor(options) {
|
|
1194
|
+
const opts = typeof options === "string" ? { message: options } : options;
|
|
1195
|
+
super(opts.message, { cause: opts.cause });
|
|
1196
|
+
this.name = "EvlogError";
|
|
1197
|
+
this.code = opts.code;
|
|
1198
|
+
this.status = opts.status ?? 500;
|
|
1199
|
+
this.why = opts.why;
|
|
1200
|
+
this.fix = opts.fix;
|
|
1201
|
+
this.link = opts.link;
|
|
1202
|
+
if (opts.internal !== undefined)
|
|
1203
|
+
Object.defineProperty(this, evlogErrorInternalKey, {
|
|
1204
|
+
value: opts.internal,
|
|
1205
|
+
enumerable: false,
|
|
1206
|
+
writable: false,
|
|
1207
|
+
configurable: true
|
|
1208
|
+
});
|
|
1209
|
+
if (opts.data !== undefined)
|
|
1210
|
+
Object.defineProperty(this, evlogErrorDataKey, {
|
|
1211
|
+
value: opts.data,
|
|
1212
|
+
enumerable: false,
|
|
1213
|
+
writable: false,
|
|
1214
|
+
configurable: true
|
|
1215
|
+
});
|
|
1216
|
+
if (Error.captureStackTrace)
|
|
1217
|
+
Error.captureStackTrace(this, EvlogError);
|
|
1218
|
+
}
|
|
1219
|
+
get statusText() {
|
|
1220
|
+
return this.message;
|
|
1221
|
+
}
|
|
1222
|
+
get statusCode() {
|
|
1223
|
+
return this.status;
|
|
1224
|
+
}
|
|
1225
|
+
get statusMessage() {
|
|
1226
|
+
return this.message;
|
|
1227
|
+
}
|
|
1228
|
+
get data() {
|
|
1229
|
+
const extra = this[evlogErrorDataKey];
|
|
1230
|
+
if (!extra && !this.code && !this.why && !this.fix && !this.link)
|
|
1231
|
+
return;
|
|
1232
|
+
return {
|
|
1233
|
+
...extra,
|
|
1234
|
+
...this.code !== undefined && { code: this.code },
|
|
1235
|
+
...this.why !== undefined && { why: this.why },
|
|
1236
|
+
...this.fix !== undefined && { fix: this.fix },
|
|
1237
|
+
...this.link !== undefined && { link: this.link }
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
toString() {
|
|
1241
|
+
const useColors = isServer();
|
|
1242
|
+
const red = useColors ? colors.red : "";
|
|
1243
|
+
const yellow = useColors ? colors.yellow : "";
|
|
1244
|
+
const cyan = useColors ? colors.cyan : "";
|
|
1245
|
+
const dim = useColors ? colors.dim : "";
|
|
1246
|
+
const reset = useColors ? colors.reset : "";
|
|
1247
|
+
const bold = useColors ? colors.bold : "";
|
|
1248
|
+
const lines = [];
|
|
1249
|
+
lines.push(`${red}${bold}Error:${reset} ${this.message}`);
|
|
1250
|
+
if (this.code)
|
|
1251
|
+
lines.push(`${dim}Code:${reset} ${this.code}`);
|
|
1252
|
+
if (this.why)
|
|
1253
|
+
lines.push(`${yellow}Why:${reset} ${this.why}`);
|
|
1254
|
+
if (this.fix)
|
|
1255
|
+
lines.push(`${cyan}Fix:${reset} ${this.fix}`);
|
|
1256
|
+
if (this.link)
|
|
1257
|
+
lines.push(`${dim}More info:${reset} ${this.link}`);
|
|
1258
|
+
if (this.cause)
|
|
1259
|
+
lines.push(`${dim}Caused by:${reset} ${this.cause.message}`);
|
|
1260
|
+
return lines.join(`
|
|
1261
|
+
`);
|
|
1262
|
+
}
|
|
1263
|
+
toJSON() {
|
|
1264
|
+
const { data } = this;
|
|
1265
|
+
return {
|
|
1266
|
+
name: this.name,
|
|
1267
|
+
message: this.message,
|
|
1268
|
+
status: this.status,
|
|
1269
|
+
...data && { data },
|
|
1270
|
+
...this.cause instanceof Error && { cause: {
|
|
1271
|
+
name: this.cause.name,
|
|
1272
|
+
message: this.cause.message
|
|
1273
|
+
} }
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
Object.defineProperty(EvlogError.prototype, evlogErrorBrand, {
|
|
1278
|
+
value: true,
|
|
1279
|
+
enumerable: false
|
|
1280
|
+
});
|
|
1281
|
+
});
|
|
1282
|
+
|
|
1283
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/audit-CW8wdQDm.mjs
|
|
1092
1284
|
function writePrettyStdout(text) {
|
|
1093
1285
|
(globalThis.__evlogNativeStdoutWrite ?? nativeStdoutWrite)?.(text);
|
|
1094
1286
|
}
|
|
1095
1287
|
function isPlainObject$1(val) {
|
|
1096
1288
|
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
1097
1289
|
}
|
|
1098
|
-
var _tsDate = /* @__PURE__ */ new Date;
|
|
1099
|
-
function isoNow() {
|
|
1100
|
-
_tsDate.setTime(Date.now());
|
|
1101
|
-
return _tsDate.toISOString();
|
|
1102
|
-
}
|
|
1103
|
-
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).";
|
|
1104
1290
|
function warnPostEmit(method, detail) {
|
|
1105
1291
|
console.warn(`[evlog] ${method} called after the wide event was emitted \u2014 ${detail} This data will not appear in observability. ${POST_EMIT_FORK_HINT}`);
|
|
1106
1292
|
}
|
|
@@ -1110,67 +1296,48 @@ function mergeInto(target, source) {
|
|
|
1110
1296
|
if (sourceVal === undefined || sourceVal === null)
|
|
1111
1297
|
continue;
|
|
1112
1298
|
const targetVal = target[key];
|
|
1299
|
+
if (sourceVal === targetVal)
|
|
1300
|
+
continue;
|
|
1113
1301
|
if (isPlainObject$1(sourceVal) && isPlainObject$1(targetVal))
|
|
1114
1302
|
mergeInto(targetVal, sourceVal);
|
|
1115
1303
|
else if (Array.isArray(targetVal) && Array.isArray(sourceVal))
|
|
1116
1304
|
target[key] = [...targetVal, ...sourceVal];
|
|
1117
1305
|
else
|
|
1118
|
-
target
|
|
1306
|
+
Reflect.set(target, key, sourceVal);
|
|
1119
1307
|
}
|
|
1120
1308
|
}
|
|
1121
|
-
var pendingDrainState = /* @__PURE__ */ new WeakMap;
|
|
1122
1309
|
function isAiOnlyFieldUpdate(data) {
|
|
1123
1310
|
const keys = Object.keys(data);
|
|
1124
1311
|
return keys.length === 1 && keys[0] === "ai";
|
|
1125
1312
|
}
|
|
1126
|
-
var globalEnv = {
|
|
1127
|
-
service: "app",
|
|
1128
|
-
environment: "development"
|
|
1129
|
-
};
|
|
1130
|
-
var globalPretty = isDev();
|
|
1131
|
-
var globalPrettyError = {
|
|
1132
|
-
snippet: isDev(),
|
|
1133
|
-
stackDepth: 2,
|
|
1134
|
-
compact: isDev(),
|
|
1135
|
-
detail: "full"
|
|
1136
|
-
};
|
|
1137
|
-
var globalSampling = {};
|
|
1138
|
-
var globalStringify = true;
|
|
1139
|
-
var globalDrain;
|
|
1140
|
-
var globalRedact;
|
|
1141
|
-
var globalEnabled = true;
|
|
1142
|
-
var globalSilent = false;
|
|
1143
|
-
var globalMinLevel = "debug";
|
|
1144
|
-
var _loggerInitialized = false;
|
|
1145
|
-
var globalPluginRunner = getEmptyPluginRunner();
|
|
1146
1313
|
function initLogger(config = {}) {
|
|
1147
|
-
|
|
1314
|
+
state.enabled = config.enabled ?? true;
|
|
1148
1315
|
const detected = detectEnvironment();
|
|
1149
|
-
|
|
1316
|
+
state.env = {
|
|
1150
1317
|
service: config.env?.service ?? detected.service ?? "app",
|
|
1151
1318
|
environment: config.env?.environment ?? detected.environment ?? "development",
|
|
1152
1319
|
version: config.env?.version ?? detected.version,
|
|
1153
1320
|
commitHash: config.env?.commitHash ?? detected.commitHash,
|
|
1154
1321
|
region: config.env?.region ?? detected.region
|
|
1155
1322
|
};
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
if (
|
|
1166
|
-
|
|
1167
|
-
const hasAnyDrain = !!
|
|
1168
|
-
if (
|
|
1323
|
+
state.pretty = config.pretty ?? isDev();
|
|
1324
|
+
state.prettyError = resolveDevTerminal(config).prettyError;
|
|
1325
|
+
state.sampling = config.sampling ?? {};
|
|
1326
|
+
state.stringify = config.stringify ?? true;
|
|
1327
|
+
state.drain = config.drain;
|
|
1328
|
+
state.redact = resolveRedactConfig(config.redact ?? !isDev());
|
|
1329
|
+
state.silent = config.silent ?? false;
|
|
1330
|
+
state.minLevel = config.minLevel ?? "debug";
|
|
1331
|
+
state.pluginRunner = config.plugins?.length ? createPluginRunner(config.plugins) : getEmptyPluginRunner();
|
|
1332
|
+
if (state.pluginRunner.plugins.length > 0)
|
|
1333
|
+
state.pluginRunner.runSetup({ env: { ...state.env } });
|
|
1334
|
+
const hasAnyDrain = !!state.drain || state.pluginRunner.hasDrain;
|
|
1335
|
+
if (state.silent && !hasAnyDrain && !config._suppressDrainWarning)
|
|
1169
1336
|
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).");
|
|
1170
|
-
|
|
1337
|
+
state.initialized = true;
|
|
1171
1338
|
}
|
|
1172
1339
|
function shouldSample(level) {
|
|
1173
|
-
const { rates } =
|
|
1340
|
+
const { rates } = state.sampling;
|
|
1174
1341
|
if (!rates)
|
|
1175
1342
|
return true;
|
|
1176
1343
|
const percentage = level === "error" && rates.error === undefined ? 100 : rates[level] ?? 100;
|
|
@@ -1181,7 +1348,7 @@ function shouldSample(level) {
|
|
|
1181
1348
|
return Math.random() * 100 < percentage;
|
|
1182
1349
|
}
|
|
1183
1350
|
function shouldKeep(ctx) {
|
|
1184
|
-
const { keep } =
|
|
1351
|
+
const { keep } = state.sampling;
|
|
1185
1352
|
if (!keep?.length)
|
|
1186
1353
|
return false;
|
|
1187
1354
|
return keep.some((condition) => {
|
|
@@ -1196,10 +1363,10 @@ function shouldKeep(ctx) {
|
|
|
1196
1363
|
}
|
|
1197
1364
|
function emitWideEvent(level, event, options = {}) {
|
|
1198
1365
|
const { deferDrain = false, ownsEvent = false, waitUntil } = options;
|
|
1199
|
-
if (!
|
|
1366
|
+
if (!state.enabled)
|
|
1200
1367
|
return null;
|
|
1201
1368
|
if (!ownsEvent) {
|
|
1202
|
-
if (!isLevelEnabled(level,
|
|
1369
|
+
if (!isLevelEnabled(level, state.minLevel))
|
|
1203
1370
|
return null;
|
|
1204
1371
|
if (!shouldSample(level))
|
|
1205
1372
|
return null;
|
|
@@ -1209,57 +1376,58 @@ function emitWideEvent(level, event, options = {}) {
|
|
|
1209
1376
|
event.timestamp = isoNow();
|
|
1210
1377
|
event.level = level;
|
|
1211
1378
|
if (event.service === undefined)
|
|
1212
|
-
event.service =
|
|
1379
|
+
event.service = state.env.service;
|
|
1213
1380
|
if (event.environment === undefined)
|
|
1214
|
-
event.environment =
|
|
1215
|
-
if (
|
|
1216
|
-
event.version =
|
|
1217
|
-
if (
|
|
1218
|
-
event.commitHash =
|
|
1219
|
-
if (
|
|
1220
|
-
event.region =
|
|
1381
|
+
event.environment = state.env.environment;
|
|
1382
|
+
if (state.env.version !== undefined && event.version === undefined)
|
|
1383
|
+
event.version = state.env.version;
|
|
1384
|
+
if (state.env.commitHash !== undefined && event.commitHash === undefined)
|
|
1385
|
+
event.commitHash = state.env.commitHash;
|
|
1386
|
+
if (state.env.region !== undefined && event.region === undefined)
|
|
1387
|
+
event.region = state.env.region;
|
|
1221
1388
|
formatted = event;
|
|
1222
1389
|
} else
|
|
1223
1390
|
formatted = {
|
|
1224
1391
|
timestamp: isoNow(),
|
|
1225
1392
|
level,
|
|
1226
|
-
...
|
|
1393
|
+
...state.env,
|
|
1227
1394
|
...event
|
|
1228
1395
|
};
|
|
1229
1396
|
finalizeAudit(formatted);
|
|
1230
|
-
if (
|
|
1231
|
-
formatted = redactEvent(formatted,
|
|
1397
|
+
if (state.redact) {
|
|
1398
|
+
formatted = redactEvent(formatted, state.redact);
|
|
1232
1399
|
markGloballyRedacted(formatted);
|
|
1233
1400
|
}
|
|
1234
|
-
if (!
|
|
1235
|
-
if (
|
|
1401
|
+
if (!state.silent)
|
|
1402
|
+
if (state.pretty)
|
|
1236
1403
|
prettyPrintWideEvent(formatted);
|
|
1237
|
-
else if (
|
|
1404
|
+
else if (state.stringify)
|
|
1238
1405
|
console[getConsoleMethod(level)](JSON.stringify(formatted));
|
|
1239
1406
|
else
|
|
1240
1407
|
console[getConsoleMethod(level)](formatted);
|
|
1241
1408
|
if (!deferDrain) {
|
|
1409
|
+
publishWideEvent(formatted);
|
|
1242
1410
|
const drainPromises = [];
|
|
1243
|
-
if (
|
|
1411
|
+
if (state.drain)
|
|
1244
1412
|
drainPromises.push((async () => {
|
|
1245
1413
|
try {
|
|
1246
|
-
await
|
|
1414
|
+
await state.drain({ event: formatted });
|
|
1247
1415
|
} catch (err) {
|
|
1248
1416
|
console.error("[evlog] drain failed:", err);
|
|
1249
1417
|
}
|
|
1250
1418
|
})());
|
|
1251
|
-
if (
|
|
1252
|
-
drainPromises.push(
|
|
1419
|
+
if (state.pluginRunner.hasDrain)
|
|
1420
|
+
drainPromises.push(state.pluginRunner.runDrain({ event: formatted }));
|
|
1253
1421
|
if (drainPromises.length > 0 && waitUntil)
|
|
1254
1422
|
waitUntil(Promise.all(drainPromises));
|
|
1255
1423
|
}
|
|
1256
1424
|
return formatted;
|
|
1257
1425
|
}
|
|
1258
1426
|
function emitTaggedLog(level, tag, message) {
|
|
1259
|
-
if (!
|
|
1427
|
+
if (!state.enabled)
|
|
1260
1428
|
return;
|
|
1261
|
-
if (
|
|
1262
|
-
if (!isLevelEnabled(level,
|
|
1429
|
+
if (state.pretty && !state.silent) {
|
|
1430
|
+
if (!isLevelEnabled(level, state.minLevel))
|
|
1263
1431
|
return;
|
|
1264
1432
|
if (!shouldSample(level))
|
|
1265
1433
|
return;
|
|
@@ -1574,6 +1742,7 @@ function prettyPrintWideEvent(event) {
|
|
|
1574
1742
|
parts.push(` ${colors.dim}in ${rest.duration}${colors.reset}`);
|
|
1575
1743
|
delete rest.duration;
|
|
1576
1744
|
}
|
|
1745
|
+
delete rest.durationMs;
|
|
1577
1746
|
writeLine(parts.join(""), ...styles);
|
|
1578
1747
|
const aiData = isPlainObject$1(rest.ai) ? rest.ai : undefined;
|
|
1579
1748
|
if (aiData)
|
|
@@ -1583,7 +1752,7 @@ function prettyPrintWideEvent(event) {
|
|
|
1583
1752
|
delete rest.error;
|
|
1584
1753
|
const restEntries = Object.entries(rest).filter(([_, v]) => v !== undefined);
|
|
1585
1754
|
const aiEntries = aiData ? buildAIEntries(aiData) : [];
|
|
1586
|
-
const errorEntries = errorData !== undefined ? buildErrorEntries(errorData,
|
|
1755
|
+
const errorEntries = errorData !== undefined ? buildErrorEntries(errorData, state.prettyError) : [];
|
|
1587
1756
|
const contextEntries = [...restEntries.map(([key, value]) => ({
|
|
1588
1757
|
key,
|
|
1589
1758
|
value: formatValue(value)
|
|
@@ -1640,28 +1809,8 @@ function createLogMethod(level) {
|
|
|
1640
1809
|
emitTaggedLog(level, "log", String(tagOrEvent));
|
|
1641
1810
|
};
|
|
1642
1811
|
}
|
|
1643
|
-
var _log = {
|
|
1644
|
-
info: createLogMethod("info"),
|
|
1645
|
-
error: createLogMethod("error"),
|
|
1646
|
-
warn: createLogMethod("warn"),
|
|
1647
|
-
debug: createLogMethod("debug")
|
|
1648
|
-
};
|
|
1649
|
-
var noopLogger = {
|
|
1650
|
-
set() {},
|
|
1651
|
-
setLevel() {},
|
|
1652
|
-
error() {},
|
|
1653
|
-
info() {},
|
|
1654
|
-
warn() {},
|
|
1655
|
-
emit() {
|
|
1656
|
-
return null;
|
|
1657
|
-
},
|
|
1658
|
-
getContext() {
|
|
1659
|
-
return {};
|
|
1660
|
-
},
|
|
1661
|
-
audit: Object.assign(() => {}, { deny: () => {} })
|
|
1662
|
-
};
|
|
1663
1812
|
function createLogger(initialContext = {}, internalOptions) {
|
|
1664
|
-
if (!
|
|
1813
|
+
if (!state.enabled)
|
|
1665
1814
|
return noopLogger;
|
|
1666
1815
|
const deferDrain = internalOptions?._deferDrain ?? false;
|
|
1667
1816
|
const waitUntil = internalOptions?.waitUntil;
|
|
@@ -1750,7 +1899,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
1750
1899
|
])
|
|
1751
1900
|
if (k in err)
|
|
1752
1901
|
errorObj[k] = errRecord[k];
|
|
1753
|
-
if (err
|
|
1902
|
+
if (EvlogError.isEvlogError(err)) {
|
|
1754
1903
|
if (err.code)
|
|
1755
1904
|
errorObj.code = err.code;
|
|
1756
1905
|
if (err.why)
|
|
@@ -1795,7 +1944,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
1795
1944
|
warnPostEmit("log.emit()", "Ignoring duplicate emit.");
|
|
1796
1945
|
return null;
|
|
1797
1946
|
}
|
|
1798
|
-
const durationMs =
|
|
1947
|
+
const durationMs = elapsedMs(startTime);
|
|
1799
1948
|
const level = manualLevel ?? (hasError ? "error" : hasWarn ? "warn" : "info");
|
|
1800
1949
|
let forceKeep = false;
|
|
1801
1950
|
const auditForceKeep = consumeAuditForceKeep(context);
|
|
@@ -1803,7 +1952,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
1803
1952
|
forceKeep = true;
|
|
1804
1953
|
else if (auditForceKeep)
|
|
1805
1954
|
forceKeep = true;
|
|
1806
|
-
else if (
|
|
1955
|
+
else if (state.sampling.keep?.length)
|
|
1807
1956
|
forceKeep = shouldKeep({
|
|
1808
1957
|
status: overrides?.status ?? context.status,
|
|
1809
1958
|
duration: durationMs,
|
|
@@ -1822,6 +1971,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
1822
1971
|
if (key !== "_forceKeep")
|
|
1823
1972
|
context[key] = obj[key];
|
|
1824
1973
|
}
|
|
1974
|
+
context.durationMs = durationMs;
|
|
1825
1975
|
context.duration = formatDuration(durationMs);
|
|
1826
1976
|
const wide = emitWideEvent(level, context, {
|
|
1827
1977
|
deferDrain,
|
|
@@ -1839,8 +1989,6 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
1839
1989
|
}
|
|
1840
1990
|
};
|
|
1841
1991
|
}
|
|
1842
|
-
if (typeof __EVLOG_CONFIG__ !== "undefined")
|
|
1843
|
-
initLogger(__EVLOG_CONFIG__);
|
|
1844
1992
|
function isPlainObject2(value) {
|
|
1845
1993
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
1846
1994
|
return false;
|
|
@@ -1902,7 +2050,6 @@ function buildAuditFields(input) {
|
|
|
1902
2050
|
version: input.version ?? 1
|
|
1903
2051
|
};
|
|
1904
2052
|
}
|
|
1905
|
-
var _testCollector = null;
|
|
1906
2053
|
function decorateAudit(audit, timestamp) {
|
|
1907
2054
|
if (audit.idempotencyKey)
|
|
1908
2055
|
return audit;
|
|
@@ -1934,13 +2081,161 @@ function finalizeAudit(event) {
|
|
|
1934
2081
|
event.audit = decorated;
|
|
1935
2082
|
_testCollector?.(decorated, event);
|
|
1936
2083
|
}
|
|
2084
|
+
var nativeStdoutWrite, 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).", pendingDrainState, state, _log, noopLogger, _testCollector = null;
|
|
2085
|
+
var init_audit_CW8wdQDm = __esm(() => {
|
|
2086
|
+
init_utils();
|
|
2087
|
+
init_redact_C7FmdhwI();
|
|
2088
|
+
init_globalRegistry_Bh3bIGwA();
|
|
2089
|
+
init_pretty_error_DTIHxnBN();
|
|
2090
|
+
init_dev_terminal_Brarc6vc();
|
|
2091
|
+
init_wideEventChannel_BUDW48oP();
|
|
2092
|
+
init_error();
|
|
2093
|
+
nativeStdoutWrite = typeof process !== "undefined" && typeof process.stdout?.write === "function" ? process.stdout.write.bind(process.stdout) : undefined;
|
|
2094
|
+
pendingDrainState = /* @__PURE__ */ new WeakMap;
|
|
2095
|
+
state = globalConfig;
|
|
2096
|
+
_log = {
|
|
2097
|
+
info: createLogMethod("info"),
|
|
2098
|
+
error: createLogMethod("error"),
|
|
2099
|
+
warn: createLogMethod("warn"),
|
|
2100
|
+
debug: createLogMethod("debug")
|
|
2101
|
+
};
|
|
2102
|
+
noopLogger = {
|
|
2103
|
+
set() {},
|
|
2104
|
+
setLevel() {},
|
|
2105
|
+
error() {},
|
|
2106
|
+
info() {},
|
|
2107
|
+
warn() {},
|
|
2108
|
+
emit() {
|
|
2109
|
+
return null;
|
|
2110
|
+
},
|
|
2111
|
+
getContext() {
|
|
2112
|
+
return {};
|
|
2113
|
+
},
|
|
2114
|
+
audit: Object.assign(() => {}, { deny: () => {} })
|
|
2115
|
+
};
|
|
2116
|
+
if (typeof __EVLOG_CONFIG__ !== "undefined")
|
|
2117
|
+
initLogger(__EVLOG_CONFIG__);
|
|
2118
|
+
});
|
|
2119
|
+
|
|
2120
|
+
// ../../node_modules/.bun/evlog@2.28.1+70108eec0745116d/node_modules/evlog/dist/index.mjs
|
|
2121
|
+
var init_dist = __esm(() => {
|
|
2122
|
+
init_audit_CW8wdQDm();
|
|
2123
|
+
});
|
|
2124
|
+
|
|
1937
2125
|
// src/server/context-logger.ts
|
|
1938
|
-
|
|
2126
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
|
|
2127
|
+
var syntheticRenderStorage;
|
|
2128
|
+
var init_context_logger = __esm(() => {
|
|
2129
|
+
init_dist();
|
|
2130
|
+
syntheticRenderStorage = new AsyncLocalStorage4;
|
|
2131
|
+
});
|
|
2132
|
+
|
|
2133
|
+
// src/server/runtime-env.ts
|
|
2134
|
+
var IS_DEV = true;
|
|
2135
|
+
|
|
2136
|
+
// src/server/sync/runtime.ts
|
|
2137
|
+
function resolveSyncRuntime(options) {
|
|
2138
|
+
if (!IS_DEV && options.adapter.scope === "process-local") {
|
|
2139
|
+
throw new Error("[furin] Production sync cannot use a process-local SyncAdapter.");
|
|
2140
|
+
}
|
|
2141
|
+
if (options.notifier) {
|
|
2142
|
+
if (options.adapter.notificationChannel !== undefined && options.notifier.notificationChannel !== undefined && options.adapter.notificationChannel !== options.notifier.notificationChannel) {
|
|
2143
|
+
throw new Error("[furin] SyncAdapter and SyncNotifier notification channels do not match.");
|
|
2144
|
+
}
|
|
2145
|
+
return { adapter: options.adapter, notifier: options.notifier };
|
|
2146
|
+
}
|
|
2147
|
+
if (!IS_DEV && options.adapter.scope === "distributed") {
|
|
2148
|
+
throw new Error("[furin] Distributed production sync requires an explicit SyncNotifier. Configure the adapter notifier or pass PollingSyncNotifier as a compatibility fallback.");
|
|
2149
|
+
}
|
|
2150
|
+
const existing = pollingNotifiers.get(options.adapter);
|
|
2151
|
+
if (existing) {
|
|
2152
|
+
return { adapter: options.adapter, notifier: existing };
|
|
2153
|
+
}
|
|
2154
|
+
const notifier = new PollingSyncNotifier(options.adapter, POLL_INTERVAL_MS);
|
|
2155
|
+
pollingNotifiers.set(options.adapter, notifier);
|
|
2156
|
+
return { adapter: options.adapter, notifier };
|
|
2157
|
+
}
|
|
2158
|
+
var POLL_INTERVAL_MS = 250, pollingNotifiers;
|
|
2159
|
+
var init_runtime = __esm(() => {
|
|
2160
|
+
pollingNotifiers = new WeakMap;
|
|
2161
|
+
});
|
|
2162
|
+
|
|
2163
|
+
// src/server/sync/stream.ts
|
|
2164
|
+
import { Elysia } from "elysia";
|
|
2165
|
+
function parseChangeQuery(request) {
|
|
2166
|
+
const url = new URL(request.url);
|
|
2167
|
+
const after = url.searchParams.get("after") ?? undefined;
|
|
2168
|
+
if (after !== undefined && (after.length === 0 || after.length > MAX_CURSOR_LENGTH)) {
|
|
2169
|
+
return { error: Response.json({ code: "FURIN_INVALID_SYNC_CURSOR" }, { status: 400 }) };
|
|
2170
|
+
}
|
|
2171
|
+
const limitValue = url.searchParams.get("limit");
|
|
2172
|
+
if (limitValue !== null && !UNSIGNED_INTEGER_PATTERN.test(limitValue)) {
|
|
2173
|
+
return { error: Response.json({ code: "FURIN_INVALID_SYNC_LIMIT" }, { status: 400 }) };
|
|
2174
|
+
}
|
|
2175
|
+
const limit = limitValue === null ? DEFAULT_CHANGE_LIMIT : Number.parseInt(limitValue, 10);
|
|
2176
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > MAX_CHANGE_LIMIT) {
|
|
2177
|
+
return { error: Response.json({ code: "FURIN_INVALID_SYNC_LIMIT" }, { status: 400 }) };
|
|
2178
|
+
}
|
|
2179
|
+
return { after, limit };
|
|
2180
|
+
}
|
|
2181
|
+
function clientInvalidations(change) {
|
|
2182
|
+
const entries = new Set;
|
|
2183
|
+
for (const invalidation of change.invalidations) {
|
|
2184
|
+
if (invalidation.kind === "tags") {
|
|
2185
|
+
entries.add("/:layout");
|
|
2186
|
+
} else {
|
|
2187
|
+
entries.add(invalidation.type === "layout" ? `${invalidation.path}:layout` : invalidation.path);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
return [...entries];
|
|
2191
|
+
}
|
|
2192
|
+
function createSyncChangesPlugin(options) {
|
|
2193
|
+
const syncPath = options.path ?? defaultSyncPath;
|
|
2194
|
+
const runtime = resolveSyncRuntime(syncRuntimeOptions(options));
|
|
2195
|
+
return new Elysia({ name: `furin-sync-changes-${syncPath}` }).get(`${syncPath}/changes`, async ({ request, set }) => {
|
|
2196
|
+
set.headers["cache-control"] = "no-store";
|
|
2197
|
+
const query = parseChangeQuery(request);
|
|
2198
|
+
if ("error" in query) {
|
|
2199
|
+
return query.error;
|
|
2200
|
+
}
|
|
2201
|
+
const page = await runtime.adapter.readChanges(query);
|
|
2202
|
+
return {
|
|
2203
|
+
...page,
|
|
2204
|
+
changes: page.changes.map((change) => ({
|
|
2205
|
+
cursor: change.cursor,
|
|
2206
|
+
invalidations: clientInvalidations(change)
|
|
2207
|
+
}))
|
|
2208
|
+
};
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
var DEFAULT_CHANGE_LIMIT = 100, MAX_CHANGE_LIMIT = 500, MAX_CURSOR_LENGTH = 128, UNSIGNED_INTEGER_PATTERN, defaultSyncPath = "/_furin/sync", cursorStates, resolvedStates;
|
|
2212
|
+
var init_stream = __esm(() => {
|
|
2213
|
+
init_config();
|
|
2214
|
+
init_runtime();
|
|
2215
|
+
UNSIGNED_INTEGER_PATTERN = /^\d+$/;
|
|
2216
|
+
cursorStates = new Map;
|
|
2217
|
+
resolvedStates = new Set;
|
|
2218
|
+
});
|
|
2219
|
+
|
|
2220
|
+
// src/server/sync/index.ts
|
|
2221
|
+
init_config();
|
|
2222
|
+
|
|
2223
|
+
// src/server/sync/plugin.ts
|
|
2224
|
+
import { Elysia as Elysia2 } from "elysia";
|
|
2225
|
+
|
|
2226
|
+
// src/shared/prefix.ts
|
|
2227
|
+
function physicalPath(prefix, path) {
|
|
2228
|
+
if (prefix === "") {
|
|
2229
|
+
return path;
|
|
2230
|
+
}
|
|
2231
|
+
return path === "/" ? prefix : `${prefix}${path}`;
|
|
2232
|
+
}
|
|
1939
2233
|
|
|
1940
2234
|
// src/devtools/protocol.ts
|
|
1941
|
-
var DEVTOOLS_PROTOCOL_VERSION =
|
|
2235
|
+
var DEVTOOLS_PROTOCOL_VERSION = 2;
|
|
1942
2236
|
|
|
1943
2237
|
// src/server/devtools/hub.ts
|
|
2238
|
+
init_instance();
|
|
1944
2239
|
var EVENT_LIMIT = 1000;
|
|
1945
2240
|
var instanceDevtoolsHub = instanceSlot(() => ({ events: [], listeners: new Set, sequence: 0 }));
|
|
1946
2241
|
function devtoolsInstanceId() {
|
|
@@ -1967,6 +2262,8 @@ function appendDevtoolsEvent(event) {
|
|
|
1967
2262
|
}
|
|
1968
2263
|
|
|
1969
2264
|
// src/server/auto-invalidate/registry.ts
|
|
2265
|
+
init_instance();
|
|
2266
|
+
|
|
1970
2267
|
class AutoInvalidateRegistry {
|
|
1971
2268
|
pathToTags = new Map;
|
|
1972
2269
|
tagToPaths = new Map;
|
|
@@ -2024,6 +2321,7 @@ function getAutoInvalidateRegistry(instance) {
|
|
|
2024
2321
|
}
|
|
2025
2322
|
|
|
2026
2323
|
// src/server/cache/registry.ts
|
|
2324
|
+
init_instance();
|
|
2027
2325
|
var instanceInvalidators = instanceSlot(() => new Map);
|
|
2028
2326
|
function getCacheInvalidators(instance) {
|
|
2029
2327
|
return instanceInvalidators(instance).values();
|
|
@@ -2039,8 +2337,8 @@ function pathWithoutSearch(path) {
|
|
|
2039
2337
|
}
|
|
2040
2338
|
|
|
2041
2339
|
// src/server/devtools/request-context.ts
|
|
2042
|
-
import { AsyncLocalStorage as
|
|
2043
|
-
var requestContext = new
|
|
2340
|
+
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
2341
|
+
var requestContext = new AsyncLocalStorage3;
|
|
2044
2342
|
function currentDevtoolsRequest() {
|
|
2045
2343
|
return requestContext.getStore();
|
|
2046
2344
|
}
|
|
@@ -2053,8 +2351,29 @@ function currentInstrumentationRequest() {
|
|
|
2053
2351
|
return currentDevtoolsRequest();
|
|
2054
2352
|
}
|
|
2055
2353
|
|
|
2056
|
-
// src/server/
|
|
2057
|
-
|
|
2354
|
+
// src/server/cache/invalidation.ts
|
|
2355
|
+
init_instance();
|
|
2356
|
+
// src/server/cache/purger.ts
|
|
2357
|
+
var pathPurger;
|
|
2358
|
+
var tagPurger;
|
|
2359
|
+
function callCachePurger(paths) {
|
|
2360
|
+
dispatch(pathPurger, paths);
|
|
2361
|
+
}
|
|
2362
|
+
function callCacheTagPurger(tags) {
|
|
2363
|
+
dispatch(tagPurger, tags);
|
|
2364
|
+
}
|
|
2365
|
+
function dispatch(purger, keys) {
|
|
2366
|
+
if (!purger || keys.length === 0) {
|
|
2367
|
+
return;
|
|
2368
|
+
}
|
|
2369
|
+
Promise.resolve().then(() => purger(keys)).catch(async (error) => {
|
|
2370
|
+
await Promise.resolve().then(() => init_context_logger());
|
|
2371
|
+
const logger = createLogger({});
|
|
2372
|
+
logger.set({ furin: { action: "cdn_purge_failed", keys } });
|
|
2373
|
+
logger.error(error instanceof Error ? error : new Error(String(error)));
|
|
2374
|
+
logger.emit();
|
|
2375
|
+
});
|
|
2376
|
+
}
|
|
2058
2377
|
|
|
2059
2378
|
// src/server/cache/invalidation.ts
|
|
2060
2379
|
var _globalPendingInvalidations = new Set;
|
|
@@ -2073,22 +2392,8 @@ function consumePendingInvalidations() {
|
|
|
2073
2392
|
function peekPendingInvalidations() {
|
|
2074
2393
|
return [..._activeInvalidationSet()];
|
|
2075
2394
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
if (!_cachePurger || paths.length === 0) {
|
|
2079
|
-
return;
|
|
2080
|
-
}
|
|
2081
|
-
_cachePurger(paths).catch((err) => {
|
|
2082
|
-
const logger = createLogger({});
|
|
2083
|
-
logger.set({
|
|
2084
|
-
furin: {
|
|
2085
|
-
action: "cdn_purge_failed",
|
|
2086
|
-
paths
|
|
2087
|
-
}
|
|
2088
|
-
});
|
|
2089
|
-
logger.error(err instanceof Error ? err : new Error(String(err)));
|
|
2090
|
-
logger.emit();
|
|
2091
|
-
});
|
|
2395
|
+
function callCachePurger2(paths) {
|
|
2396
|
+
callCachePurger(paths);
|
|
2092
2397
|
}
|
|
2093
2398
|
function revalidatePath(path, type) {
|
|
2094
2399
|
let deleted = false;
|
|
@@ -2096,12 +2401,12 @@ function revalidatePath(path, type) {
|
|
|
2096
2401
|
for (const instance of allInstances()) {
|
|
2097
2402
|
const result = revalidatePathForInstance(instance, path, type);
|
|
2098
2403
|
deleted = result.deleted || deleted;
|
|
2099
|
-
purgedPaths.push(
|
|
2404
|
+
purgedPaths.push(physicalPath(instance.prefix, path));
|
|
2100
2405
|
for (const purged of result.purgedPaths) {
|
|
2101
|
-
purgedPaths.push(
|
|
2406
|
+
purgedPaths.push(physicalPath(instance.prefix, purged));
|
|
2102
2407
|
}
|
|
2103
2408
|
}
|
|
2104
|
-
|
|
2409
|
+
callCachePurger2(dedupePaths(purgedPaths));
|
|
2105
2410
|
return deleted;
|
|
2106
2411
|
}
|
|
2107
2412
|
function revalidatePathForInstance(instance, path, type, emitPathEvent) {
|
|
@@ -2135,6 +2440,7 @@ function dedupePaths(paths) {
|
|
|
2135
2440
|
}
|
|
2136
2441
|
|
|
2137
2442
|
// src/server/auto-invalidate/runtime.ts
|
|
2443
|
+
init_instance();
|
|
2138
2444
|
function toRules(input) {
|
|
2139
2445
|
return Array.isArray(input) ? input : [input];
|
|
2140
2446
|
}
|
|
@@ -2226,6 +2532,7 @@ function revalidateTag(tags) {
|
|
|
2226
2532
|
const tagList = typeof tags === "string" ? [tags] : [...tags];
|
|
2227
2533
|
let deleted = false;
|
|
2228
2534
|
const purgedPaths = new Set;
|
|
2535
|
+
callCacheTagPurger(tagList);
|
|
2229
2536
|
for (const instance of allInstances()) {
|
|
2230
2537
|
let instanceDeleted = false;
|
|
2231
2538
|
const instancePurgedPaths = new Set;
|
|
@@ -2234,10 +2541,10 @@ function revalidateTag(tags) {
|
|
|
2234
2541
|
const result = revalidatePathForInstance(instance, logicalPath, "page", false);
|
|
2235
2542
|
deleted = result.deleted || deleted;
|
|
2236
2543
|
instanceDeleted = result.deleted || instanceDeleted;
|
|
2237
|
-
purgedPaths.add(
|
|
2544
|
+
purgedPaths.add(physicalPath(instance.prefix, logicalPath));
|
|
2238
2545
|
instancePurgedPaths.add(logicalPath);
|
|
2239
2546
|
for (const purged of result.purgedPaths) {
|
|
2240
|
-
purgedPaths.add(
|
|
2547
|
+
purgedPaths.add(physicalPath(instance.prefix, purged));
|
|
2241
2548
|
instancePurgedPaths.add(purged);
|
|
2242
2549
|
}
|
|
2243
2550
|
}
|
|
@@ -2257,7 +2564,7 @@ function revalidateTag(tags) {
|
|
|
2257
2564
|
});
|
|
2258
2565
|
}
|
|
2259
2566
|
}
|
|
2260
|
-
|
|
2567
|
+
callCachePurger2([...purgedPaths]);
|
|
2261
2568
|
return deleted;
|
|
2262
2569
|
}
|
|
2263
2570
|
function runInvalidationRules(input) {
|
|
@@ -2415,7 +2722,13 @@ function unreplayable() {
|
|
|
2415
2722
|
};
|
|
2416
2723
|
}
|
|
2417
2724
|
function mergeStoredResponseHeaders(storedResponse, headers) {
|
|
2418
|
-
const
|
|
2725
|
+
const headerEntries = [];
|
|
2726
|
+
for (const [name, value] of storedResponse.headers) {
|
|
2727
|
+
if (!NON_REPLAYABLE_HEADERS.has(name.toLowerCase())) {
|
|
2728
|
+
headerEntries.push([name, value]);
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
const merged = new Headers(headerEntries);
|
|
2419
2732
|
for (const [name, value] of Object.entries(headers)) {
|
|
2420
2733
|
if (value !== undefined && !NON_REPLAYABLE_HEADERS.has(name.toLowerCase())) {
|
|
2421
2734
|
merged.delete(name);
|
|
@@ -2432,12 +2745,12 @@ function mergeStoredResponseHeaders(storedResponse, headers) {
|
|
|
2432
2745
|
async function storeResponse(responseValue, set) {
|
|
2433
2746
|
if (responseValue instanceof Response) {
|
|
2434
2747
|
const clone = responseValue.clone();
|
|
2435
|
-
const
|
|
2436
|
-
if (
|
|
2748
|
+
const body = await readBoundedResponseBody(clone);
|
|
2749
|
+
if (body === undefined) {
|
|
2437
2750
|
return unreplayable();
|
|
2438
2751
|
}
|
|
2439
|
-
const
|
|
2440
|
-
return storedResponseResult(
|
|
2752
|
+
const headers = new Headers([...clone.headers.entries()].filter(([name]) => !NON_REPLAYABLE_HEADERS.has(name.toLowerCase())));
|
|
2753
|
+
return storedResponseResult(headers, body, clone.status);
|
|
2441
2754
|
}
|
|
2442
2755
|
const headers = responseHeaders(set.headers);
|
|
2443
2756
|
const statusResponse = unwrapStatusResponse(responseValue);
|
|
@@ -2457,32 +2770,20 @@ async function storeResponse(responseValue, set) {
|
|
|
2457
2770
|
}
|
|
2458
2771
|
function replayResponse(stored) {
|
|
2459
2772
|
const body = stored.status === 204 || stored.status === 205 || stored.status === 304 ? null : stored.body.slice();
|
|
2773
|
+
const headerEntries = [];
|
|
2774
|
+
for (const [name, value] of stored.headers) {
|
|
2775
|
+
if (!NON_REPLAYABLE_HEADERS.has(name.toLowerCase())) {
|
|
2776
|
+
headerEntries.push([name, value]);
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2460
2779
|
return new Response(body, {
|
|
2461
|
-
headers: new Headers(
|
|
2780
|
+
headers: new Headers(headerEntries),
|
|
2462
2781
|
status: stored.status
|
|
2463
2782
|
});
|
|
2464
2783
|
}
|
|
2465
2784
|
|
|
2466
|
-
// src/server/sync/runtime.ts
|
|
2467
|
-
var POLL_INTERVAL_MS = 250;
|
|
2468
|
-
var pollingNotifiers = new WeakMap;
|
|
2469
|
-
function resolveSyncRuntime(options) {
|
|
2470
|
-
if (!IS_DEV && options.adapter.scope === "process-local") {
|
|
2471
|
-
throw new Error("[furin] Production sync cannot use a process-local SyncAdapter.");
|
|
2472
|
-
}
|
|
2473
|
-
if (options.notifier) {
|
|
2474
|
-
return { adapter: options.adapter, notifier: options.notifier };
|
|
2475
|
-
}
|
|
2476
|
-
const existing = pollingNotifiers.get(options.adapter);
|
|
2477
|
-
if (existing) {
|
|
2478
|
-
return { adapter: options.adapter, notifier: existing };
|
|
2479
|
-
}
|
|
2480
|
-
const notifier = new PollingSyncNotifier(options.adapter, POLL_INTERVAL_MS);
|
|
2481
|
-
pollingNotifiers.set(options.adapter, notifier);
|
|
2482
|
-
return { adapter: options.adapter, notifier };
|
|
2483
|
-
}
|
|
2484
|
-
|
|
2485
2785
|
// src/server/sync/plugin.ts
|
|
2786
|
+
init_runtime();
|
|
2486
2787
|
var routeMetadata = new WeakMap;
|
|
2487
2788
|
var activeMutations = new WeakMap;
|
|
2488
2789
|
function hideTransportResponse(hook) {
|
|
@@ -2633,7 +2934,8 @@ function furinSync(options) {
|
|
|
2633
2934
|
if (completion.kind === "lost") {
|
|
2634
2935
|
return leaseLostResponse();
|
|
2635
2936
|
}
|
|
2636
|
-
|
|
2937
|
+
const notificationAlreadyPublished = runtime.adapter.notificationChannel !== undefined && runtime.adapter.notificationChannel === runtime.notifier.notificationChannel;
|
|
2938
|
+
if (completion.cursor !== undefined && !notificationAlreadyPublished) {
|
|
2637
2939
|
runtime.notifier.publish(completion.cursor).catch(() => {
|
|
2638
2940
|
return;
|
|
2639
2941
|
});
|
|
@@ -2667,7 +2969,7 @@ function furinSync(options) {
|
|
|
2667
2969
|
}
|
|
2668
2970
|
const beginMutationHook = hideTransportResponse(beginMutation);
|
|
2669
2971
|
const finishMutationHook = hideTransportResponse(finishMutation);
|
|
2670
|
-
return new
|
|
2972
|
+
return new Elysia2({ name: "furin-sync" }).macro({
|
|
2671
2973
|
sync(input) {
|
|
2672
2974
|
return {
|
|
2673
2975
|
transform({ request }) {
|
|
@@ -2678,191 +2980,19 @@ function furinSync(options) {
|
|
|
2678
2980
|
}).onBeforeHandle({ as: "global" }, beginMutationHook).onAfterHandle({ as: "global" }, finishMutationHook).onError({ as: "global" }, ({ request }) => abortMutation(request));
|
|
2679
2981
|
}
|
|
2680
2982
|
|
|
2681
|
-
// src/server/sync/stream.ts
|
|
2682
|
-
import { Elysia as Elysia2 } from "elysia";
|
|
2683
|
-
var DEFAULT_CHANGE_LIMIT = 100;
|
|
2684
|
-
var MAX_CHANGE_LIMIT = 500;
|
|
2685
|
-
var MAX_STREAM_CLIENTS = 100;
|
|
2686
|
-
var MAX_CURSOR_LENGTH = 128;
|
|
2687
|
-
var SAFETY_POLL_INTERVAL_MS = IS_DEV ? 250 : 15000;
|
|
2688
|
-
var UNSIGNED_INTEGER_PATTERN = /^\d+$/;
|
|
2689
|
-
var defaultStreamPath = "/_furin/sync";
|
|
2690
|
-
var encoder = new TextEncoder;
|
|
2691
|
-
var noOpSubscription = {
|
|
2692
|
-
unsubscribe: () => Promise.resolve()
|
|
2693
|
-
};
|
|
2694
|
-
var streams = new Map;
|
|
2695
|
-
var resolvedStates = new Set;
|
|
2696
|
-
function encodeSseCursor(cursor) {
|
|
2697
|
-
return encoder.encode(`id: ${cursor}
|
|
2698
|
-
event: furin.sync
|
|
2699
|
-
retry: 3000
|
|
2700
|
-
data: ${JSON.stringify({ cursor })}
|
|
2701
|
-
|
|
2702
|
-
`);
|
|
2703
|
-
}
|
|
2704
|
-
function closeClient(state, client) {
|
|
2705
|
-
const heartbeat = state.clients.get(client);
|
|
2706
|
-
state.clients.delete(client);
|
|
2707
|
-
if (heartbeat) {
|
|
2708
|
-
clearInterval(heartbeat);
|
|
2709
|
-
}
|
|
2710
|
-
try {
|
|
2711
|
-
client.close();
|
|
2712
|
-
} catch {}
|
|
2713
|
-
}
|
|
2714
|
-
function notifyState(state, cursor) {
|
|
2715
|
-
if (state.cursor === cursor) {
|
|
2716
|
-
return;
|
|
2717
|
-
}
|
|
2718
|
-
state.cursor = cursor;
|
|
2719
|
-
const chunk = encodeSseCursor(cursor);
|
|
2720
|
-
for (const client of state.clients.keys()) {
|
|
2721
|
-
if (client.desiredSize === null || client.desiredSize <= 0) {
|
|
2722
|
-
closeClient(state, client);
|
|
2723
|
-
continue;
|
|
2724
|
-
}
|
|
2725
|
-
try {
|
|
2726
|
-
client.enqueue(chunk);
|
|
2727
|
-
} catch {
|
|
2728
|
-
closeClient(state, client);
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
}
|
|
2732
|
-
async function createStreamState(runtime) {
|
|
2733
|
-
const state = {};
|
|
2734
|
-
state.clients = new Map;
|
|
2735
|
-
state.cursor = await runtime.adapter.currentCursor();
|
|
2736
|
-
state.safetyPoll = setInterval(() => {
|
|
2737
|
-
runtime.adapter.currentCursor().then((cursor) => notifyState(state, cursor)).catch(() => {
|
|
2738
|
-
return;
|
|
2739
|
-
});
|
|
2740
|
-
}, SAFETY_POLL_INTERVAL_MS);
|
|
2741
|
-
state.safetyPoll.unref?.();
|
|
2742
|
-
state.subscription = await runtime.notifier.subscribe((cursor) => notifyState(state, cursor)).catch(() => noOpSubscription);
|
|
2743
|
-
resolvedStates.add(state);
|
|
2744
|
-
return state;
|
|
2745
|
-
}
|
|
2746
|
-
function getStreamState(runtime) {
|
|
2747
|
-
const existing = streams.get(runtime.adapter);
|
|
2748
|
-
if (existing) {
|
|
2749
|
-
return existing;
|
|
2750
|
-
}
|
|
2751
|
-
const state = createStreamState(runtime);
|
|
2752
|
-
streams.set(runtime.adapter, state);
|
|
2753
|
-
state.catch(() => {
|
|
2754
|
-
if (streams.get(runtime.adapter) === state) {
|
|
2755
|
-
streams.delete(runtime.adapter);
|
|
2756
|
-
}
|
|
2757
|
-
});
|
|
2758
|
-
return state;
|
|
2759
|
-
}
|
|
2760
|
-
function parseChangeQuery(request) {
|
|
2761
|
-
const url = new URL(request.url);
|
|
2762
|
-
const after = url.searchParams.get("after") ?? undefined;
|
|
2763
|
-
if (after !== undefined && (after.length === 0 || after.length > MAX_CURSOR_LENGTH)) {
|
|
2764
|
-
return { error: Response.json({ code: "FURIN_INVALID_SYNC_CURSOR" }, { status: 400 }) };
|
|
2765
|
-
}
|
|
2766
|
-
const limitValue = url.searchParams.get("limit");
|
|
2767
|
-
if (limitValue !== null && !UNSIGNED_INTEGER_PATTERN.test(limitValue)) {
|
|
2768
|
-
return { error: Response.json({ code: "FURIN_INVALID_SYNC_LIMIT" }, { status: 400 }) };
|
|
2769
|
-
}
|
|
2770
|
-
const limit = limitValue === null ? DEFAULT_CHANGE_LIMIT : Number.parseInt(limitValue, 10);
|
|
2771
|
-
if (!Number.isInteger(limit) || limit < 1 || limit > MAX_CHANGE_LIMIT) {
|
|
2772
|
-
return { error: Response.json({ code: "FURIN_INVALID_SYNC_LIMIT" }, { status: 400 }) };
|
|
2773
|
-
}
|
|
2774
|
-
return { after, limit };
|
|
2775
|
-
}
|
|
2776
|
-
function clientInvalidations(change) {
|
|
2777
|
-
const entries = new Set;
|
|
2778
|
-
for (const invalidation of change.invalidations) {
|
|
2779
|
-
if (invalidation.kind === "tags") {
|
|
2780
|
-
entries.add("/:layout");
|
|
2781
|
-
} else {
|
|
2782
|
-
entries.add(invalidation.type === "layout" ? `${invalidation.path}:layout` : invalidation.path);
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
return [...entries];
|
|
2786
|
-
}
|
|
2787
|
-
function createSyncStreamPlugin(options) {
|
|
2788
|
-
const streamPath = options.streamPath ?? defaultStreamPath;
|
|
2789
|
-
const runtime = resolveSyncRuntime(syncRuntimeOptions(options));
|
|
2790
|
-
return new Elysia2({ name: `furin-sync-stream-${streamPath}` }).get(`${streamPath}/changes`, async ({ request, set }) => {
|
|
2791
|
-
set.headers["cache-control"] = "no-store";
|
|
2792
|
-
const query = parseChangeQuery(request);
|
|
2793
|
-
if ("error" in query) {
|
|
2794
|
-
return query.error;
|
|
2795
|
-
}
|
|
2796
|
-
const page = await runtime.adapter.readChanges(query);
|
|
2797
|
-
return {
|
|
2798
|
-
...page,
|
|
2799
|
-
changes: page.changes.map((change) => ({
|
|
2800
|
-
cursor: change.cursor,
|
|
2801
|
-
invalidations: clientInvalidations(change)
|
|
2802
|
-
}))
|
|
2803
|
-
};
|
|
2804
|
-
}).get(streamPath, async () => {
|
|
2805
|
-
const state = await getStreamState(runtime);
|
|
2806
|
-
if (state.clients.size >= MAX_STREAM_CLIENTS) {
|
|
2807
|
-
return Response.json({ code: "FURIN_SYNC_STREAM_CAPACITY" }, { status: 503 });
|
|
2808
|
-
}
|
|
2809
|
-
let controllerRef;
|
|
2810
|
-
let heartbeat;
|
|
2811
|
-
const stream = new ReadableStream({
|
|
2812
|
-
cancel() {
|
|
2813
|
-
if (controllerRef) {
|
|
2814
|
-
closeClient(state, controllerRef);
|
|
2815
|
-
}
|
|
2816
|
-
if (heartbeat) {
|
|
2817
|
-
clearInterval(heartbeat);
|
|
2818
|
-
}
|
|
2819
|
-
},
|
|
2820
|
-
start(controller) {
|
|
2821
|
-
controllerRef = controller;
|
|
2822
|
-
controller.enqueue(encoder.encode(`: connected
|
|
2823
|
-
retry: 3000
|
|
2824
|
-
|
|
2825
|
-
`));
|
|
2826
|
-
state.clients.set(controller, undefined);
|
|
2827
|
-
heartbeat = setInterval(() => {
|
|
2828
|
-
if (controller.desiredSize === null || controller.desiredSize <= 0) {
|
|
2829
|
-
closeClient(state, controller);
|
|
2830
|
-
return;
|
|
2831
|
-
}
|
|
2832
|
-
try {
|
|
2833
|
-
controller.enqueue(encoder.encode(`: heartbeat
|
|
2834
|
-
|
|
2835
|
-
`));
|
|
2836
|
-
} catch {
|
|
2837
|
-
closeClient(state, controller);
|
|
2838
|
-
}
|
|
2839
|
-
}, 15000);
|
|
2840
|
-
heartbeat.unref?.();
|
|
2841
|
-
state.clients.set(controller, heartbeat);
|
|
2842
|
-
}
|
|
2843
|
-
});
|
|
2844
|
-
return new Response(stream, {
|
|
2845
|
-
headers: {
|
|
2846
|
-
"cache-control": "no-cache, no-transform",
|
|
2847
|
-
connection: "keep-alive",
|
|
2848
|
-
"content-type": "text/event-stream; charset=utf-8"
|
|
2849
|
-
}
|
|
2850
|
-
});
|
|
2851
|
-
});
|
|
2852
|
-
}
|
|
2853
|
-
|
|
2854
2983
|
// src/server/sync/index.ts
|
|
2855
|
-
|
|
2984
|
+
init_stream();
|
|
2985
|
+
var createSyncChangesPlugin2 = createSyncChangesPlugin;
|
|
2856
2986
|
var furinSync2 = furinSync;
|
|
2857
|
-
var
|
|
2987
|
+
var getSyncPath2 = getSyncPath;
|
|
2858
2988
|
var PollingSyncNotifier2 = PollingSyncNotifier;
|
|
2859
|
-
var
|
|
2860
|
-
var
|
|
2989
|
+
var resolveSyncPath2 = resolveSyncPath;
|
|
2990
|
+
var runWithSyncPath2 = runWithSyncPath;
|
|
2861
2991
|
export {
|
|
2862
2992
|
PollingSyncNotifier2 as PollingSyncNotifier,
|
|
2863
|
-
|
|
2993
|
+
createSyncChangesPlugin2 as createSyncChangesPlugin,
|
|
2864
2994
|
furinSync2 as furinSync,
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2995
|
+
getSyncPath2 as getSyncPath,
|
|
2996
|
+
resolveSyncPath2 as resolveSyncPath,
|
|
2997
|
+
runWithSyncPath2 as runWithSyncPath
|
|
2868
2998
|
};
|