@timber-js/app 0.2.0-alpha.204 → 0.2.0-alpha.205
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/_chunks/{actions-HUdJADAD.js → actions-jNrXdzgs.js} +4 -3
- package/dist/_chunks/{actions-HUdJADAD.js.map → actions-jNrXdzgs.js.map} +1 -1
- package/dist/_chunks/als-registry-C6kcfprT.js.map +1 -1
- package/dist/_chunks/{build-manifest-DWppEdLB.js → build-manifest-DTmSGLRz.js} +51 -2
- package/dist/_chunks/build-manifest-DTmSGLRz.js.map +1 -0
- package/dist/_chunks/{cache-api-CAPbZTga.js → cache-api-CUD9Ezaq.js} +3 -2
- package/dist/_chunks/{cache-api-CAPbZTga.js.map → cache-api-CUD9Ezaq.js.map} +1 -1
- package/dist/_chunks/{chains-C9Y7Oyno.js → chains-BjGKq9Je.js} +2 -2
- package/dist/_chunks/{chains-C9Y7Oyno.js.map → chains-BjGKq9Je.js.map} +1 -1
- package/dist/_chunks/{cli-check-BzMGuIH6.js → cli-check-3WE_GyoL.js} +3 -3
- package/dist/_chunks/{cli-check-BzMGuIH6.js.map → cli-check-3WE_GyoL.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-DnXqcIIj.js → cli-schema-sync-D3iIZjku.js} +2 -2
- package/dist/_chunks/{cli-schema-sync-DnXqcIIj.js.map → cli-schema-sync-D3iIZjku.js.map} +1 -1
- package/dist/_chunks/{cloudflare-DxX1SU0g.js → cloudflare-BFb__LYG.js} +3 -3
- package/dist/_chunks/{cloudflare-DxX1SU0g.js.map → cloudflare-BFb__LYG.js.map} +1 -1
- package/dist/_chunks/{convention-lint-DHOFvX5s.js → convention-lint-BnO5TyHD.js} +2 -2
- package/dist/_chunks/{convention-lint-DHOFvX5s.js.map → convention-lint-BnO5TyHD.js.map} +1 -1
- package/dist/_chunks/{dev-server-BV01iyUs.js → dev-server-Dbdgx2dD.js} +8 -195
- package/dist/_chunks/dev-server-Dbdgx2dD.js.map +1 -0
- package/dist/_chunks/{error-boundary-BQKxl6EX.js → error-boundary-BndF-3Td.js} +2 -2
- package/dist/_chunks/{error-boundary-BQKxl6EX.js.map → error-boundary-BndF-3Td.js.map} +1 -1
- package/dist/_chunks/{graph-cache-Cv3njEH8.js → graph-cache-CP4GEmf9.js} +2 -2
- package/dist/_chunks/{graph-cache-Cv3njEH8.js.map → graph-cache-CP4GEmf9.js.map} +1 -1
- package/dist/_chunks/{live-graph-DCLQzV6m.js → live-graph-BM2UbbNx.js} +3 -3
- package/dist/_chunks/{live-graph-DCLQzV6m.js.map → live-graph-BM2UbbNx.js.map} +1 -1
- package/dist/_chunks/logger-k2DQ4EUf.js +506 -0
- package/dist/_chunks/logger-k2DQ4EUf.js.map +1 -0
- package/dist/_chunks/{poison-scan-CX_NaNDi.js → poison-scan-g83aAXhs.js} +2 -2
- package/dist/_chunks/{poison-scan-CX_NaNDi.js.map → poison-scan-g83aAXhs.js.map} +1 -1
- package/dist/_chunks/{logger-DqJ2VoAY.js → primitives-DLAnvsrk.js} +17 -518
- package/dist/_chunks/primitives-DLAnvsrk.js.map +1 -0
- package/dist/_chunks/{scanner-B_tnqFcF.js → scanner-BhNruzv0.js} +3 -3
- package/dist/_chunks/{scanner-B_tnqFcF.js.map → scanner-BhNruzv0.js.map} +1 -1
- package/dist/_chunks/{walkers-Cm3PC5JT.js → walkers-BNsswm-h.js} +2 -2
- package/dist/_chunks/{walkers-Cm3PC5JT.js.map → walkers-BNsswm-h.js.map} +1 -1
- package/dist/adapters/cloudflare-dev.js +1 -1
- package/dist/adapters/cloudflare-kv-cache.js +1 -1
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/analyze/crawl-entry.js +2 -2
- package/dist/analyze/graph-command.js +3 -3
- package/dist/cache/index.js +1 -1
- package/dist/cli.js +3 -3
- package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/internal.js +1 -1
- package/dist/dev-tools/index.d.ts +1 -1
- package/dist/dev-tools/index.d.ts.map +1 -1
- package/dist/dev-tools/overlay.d.ts +1 -21
- package/dist/dev-tools/overlay.d.ts.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/plugins/dev-server.d.ts.map +1 -1
- package/dist/routing/index.js +2 -2
- package/dist/server/als-registry.d.ts +0 -7
- package/dist/server/als-registry.d.ts.map +1 -1
- package/dist/server/deny-renderer.d.ts +2 -6
- package/dist/server/deny-renderer.d.ts.map +1 -1
- package/dist/server/index.js +3 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/internal.js +180 -7
- package/dist/server/internal.js.map +1 -1
- package/dist/server/pipeline.d.ts +1 -13
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/rsc-entry/deny-fallback.d.ts.map +1 -1
- package/dist/server/rsc-entry/error-renderer.d.ts.map +1 -1
- package/dist/server/rsc-entry/helpers.d.ts +0 -38
- package/dist/server/rsc-entry/helpers.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts +0 -1
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts +1 -7
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/dist/server/rsc-entry/ssr-renderer.d.ts +0 -1
- package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
- package/dist/server/slot-resolver.d.ts.map +1 -1
- package/dist/server/slot-subtree-contain.d.ts +1 -1
- package/dist/server/slot-subtree-contain.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client/browser-entry/rsc-stream.ts +1 -82
- package/src/dev-tools/index.ts +0 -2
- package/src/dev-tools/overlay.ts +1 -65
- package/src/plugins/dev-server.ts +4 -45
- package/src/server/als-registry.ts +0 -8
- package/src/server/deny-renderer.ts +0 -7
- package/src/server/pipeline.ts +1 -14
- package/src/server/rsc-entry/deny-fallback.ts +1 -10
- package/src/server/rsc-entry/error-renderer.ts +1 -11
- package/src/server/rsc-entry/helpers.ts +0 -92
- package/src/server/rsc-entry/index.ts +1 -14
- package/src/server/rsc-entry/render-route.ts +2 -23
- package/src/server/rsc-entry/rsc-payload.ts +1 -2
- package/src/server/rsc-entry/rsc-stream.ts +3 -29
- package/src/server/rsc-entry/ssr-renderer.ts +2 -15
- package/src/server/slot-resolver.ts +7 -29
- package/src/server/slot-subtree-contain.ts +22 -14
- package/dist/_chunks/build-manifest-DWppEdLB.js.map +0 -1
- package/dist/_chunks/csp-nonce-hOGniaG4.js +0 -227
- package/dist/_chunks/csp-nonce-hOGniaG4.js.map +0 -1
- package/dist/_chunks/dev-server-BV01iyUs.js.map +0 -1
- package/dist/_chunks/logger-DqJ2VoAY.js.map +0 -1
- package/dist/dev-tools/debug-channel.d.ts +0 -55
- package/dist/dev-tools/debug-channel.d.ts.map +0 -1
- package/src/dev-tools/debug-channel.ts +0 -151
|
@@ -1,217 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as requestContextAls, s as waitUntilAls } from "./als-registry-C6kcfprT.js";
|
|
2
2
|
import { n as _setGetSegmentParamsFn, t as _setGetSearchParamsFn } from "./als-slots-BEEIPKYm.js";
|
|
3
3
|
import { a as assertValidCookieOptions, i as assertValidCookieName, n as parseSetCookie$1, o as assertValidCookieValue, r as stringifySetCookie, t as parseCookie } from "./dist-DtrJyBbw.js";
|
|
4
4
|
import { r as appVisibleSearch } from "./rsc-cache-key-ClUiXQnK.js";
|
|
5
5
|
import { a as mergePreservedSearchParams, o as resolveSegmentParams, r as validateExternalRedirectUrl, t as assertRelativeRedirectPath } from "./href-validation-BIrxavIy.js";
|
|
6
|
-
|
|
7
|
-
//#region src/server/tracing.ts
|
|
8
|
-
/**
|
|
9
|
-
* Tracing — per-request trace ID via AsyncLocalStorage, OTEL span helpers.
|
|
10
|
-
*
|
|
11
|
-
* getTraceId() is always available in server code (middleware, access, components, actions).
|
|
12
|
-
* Returns a 32-char lowercase hex string — the OTEL trace ID when an SDK is active,
|
|
13
|
-
* or a crypto.randomUUID()-derived fallback otherwise.
|
|
14
|
-
*
|
|
15
|
-
* See design/17-logging.md §"trace_id is Always Set"
|
|
16
|
-
*/
|
|
6
|
+
//#region src/server/waituntil-bridge.ts
|
|
17
7
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* With OTEL: the real OTEL trace ID (matches Jaeger/Honeycomb/Datadog).
|
|
21
|
-
* Without OTEL: crypto.randomUUID() with hyphens stripped.
|
|
8
|
+
* Per-request waitUntil bridge — ALS bridge for platform adapters.
|
|
22
9
|
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return store.traceId;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Returns the current OTEL span ID if available, undefined otherwise.
|
|
32
|
-
*/
|
|
33
|
-
function getSpanId() {
|
|
34
|
-
return traceAls.getStore()?.spanId;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Generate a 32-char lowercase hex ID from crypto.randomUUID().
|
|
38
|
-
* Same format as OTEL trace IDs — zero-friction upgrade path.
|
|
39
|
-
*/
|
|
40
|
-
function generateTraceId() {
|
|
41
|
-
return randomUUID().replace(/-/g, "");
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Run a callback within a trace context. Used by the pipeline to establish
|
|
45
|
-
* per-request ALS scope.
|
|
46
|
-
*/
|
|
47
|
-
function runWithTraceId(id, fn) {
|
|
48
|
-
return traceAls.run({ traceId: id }, fn);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Replace the trace ID in the current ALS store. Used when OTEL creates
|
|
52
|
-
* a root span and we want to switch from the UUID fallback to the real
|
|
53
|
-
* OTEL trace ID.
|
|
54
|
-
*/
|
|
55
|
-
function replaceTraceId(newTraceId, newSpanId) {
|
|
56
|
-
const store = traceAls.getStore();
|
|
57
|
-
if (store) {
|
|
58
|
-
store.traceId = newTraceId;
|
|
59
|
-
store.spanId = newSpanId;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Update the span ID in the current ALS store. Used when entering a new
|
|
64
|
-
* OTEL span to keep log–trace correlation accurate.
|
|
65
|
-
*/
|
|
66
|
-
function updateSpanId(newSpanId) {
|
|
67
|
-
const store = traceAls.getStore();
|
|
68
|
-
if (store) store.spanId = newSpanId;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get the current trace store, or undefined if outside a request context.
|
|
72
|
-
* Framework-internal — use getTraceId()/getSpanId() in user code.
|
|
73
|
-
*/
|
|
74
|
-
function getTraceStore() {
|
|
75
|
-
return traceAls.getStore();
|
|
76
|
-
}
|
|
77
|
-
var PLATFORM_TRACER_KEY = Symbol.for("timber:platform-tracer");
|
|
78
|
-
/** The registered native platform tracer, if any. */
|
|
79
|
-
function getPlatformTracer() {
|
|
80
|
-
return globalThis[PLATFORM_TRACER_KEY];
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Attempt to get the @opentelemetry/api tracer. Returns undefined if the
|
|
84
|
-
* package is not installed or no SDK is registered.
|
|
10
|
+
* The generated entry point (Nitro, Cloudflare) wraps the handler with
|
|
11
|
+
* `runWithWaitUntil`, binding the platform's lifecycle extension function
|
|
12
|
+
* (e.g., h3's `event.waitUntil()` or CF's `ctx.waitUntil()`) for the
|
|
13
|
+
* request duration. The `waitUntil()` primitive reads from this ALS to
|
|
14
|
+
* dispatch background work to the correct platform API.
|
|
85
15
|
*
|
|
86
|
-
*
|
|
87
|
-
* The API is a no-op by default — spans are only emitted when the developer
|
|
88
|
-
* initializes an SDK in register().
|
|
89
|
-
*/
|
|
90
|
-
var _otelApi;
|
|
91
|
-
async function getOtelApi() {
|
|
92
|
-
if (_otelApi === void 0) try {
|
|
93
|
-
_otelApi = await import("@opentelemetry/api");
|
|
94
|
-
} catch {
|
|
95
|
-
_otelApi = null;
|
|
96
|
-
}
|
|
97
|
-
return _otelApi;
|
|
98
|
-
}
|
|
99
|
-
/** OTEL tracer instance, lazily created. */
|
|
100
|
-
var _tracer;
|
|
101
|
-
/**
|
|
102
|
-
* Get the timber.js OTEL tracer. Returns null if @opentelemetry/api is not available.
|
|
103
|
-
*/
|
|
104
|
-
async function getTracer() {
|
|
105
|
-
if (_tracer === void 0) {
|
|
106
|
-
const api = await getOtelApi();
|
|
107
|
-
if (api) _tracer = api.trace.getTracer("timber.js");
|
|
108
|
-
else _tracer = null;
|
|
109
|
-
}
|
|
110
|
-
return _tracer;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Run a function within a framework span. Composes two emission channels:
|
|
114
|
-
*
|
|
115
|
-
* - **Native platform span** — when an adapter registered a PlatformTracer
|
|
116
|
-
* (Cloudflare Workers), the fn is wrapped in platformTracer.enterSpan()
|
|
117
|
-
* so it appears in the platform's native trace view.
|
|
118
|
-
* - **OTEL span** — when an OTEL SDK is active, the fn also runs inside an
|
|
119
|
-
* OTEL span (dual emission). No SDK and no platform tracer = zero overhead.
|
|
120
|
-
*
|
|
121
|
-
* Automatically:
|
|
122
|
-
* - Creates the span as a child of the current context
|
|
123
|
-
* - Updates the ALS span ID for log–trace correlation
|
|
124
|
-
* - Ends the span when the function completes
|
|
125
|
-
* - Records exceptions on error (OTEL channel)
|
|
126
|
-
*/
|
|
127
|
-
async function withSpan(name, attributes, fn) {
|
|
128
|
-
const platformTracer = getPlatformTracer();
|
|
129
|
-
if (!platformTracer) return runOtelSpan(name, attributes, fn);
|
|
130
|
-
return platformTracer.enterSpan(name, async (span) => {
|
|
131
|
-
for (const key of Object.keys(attributes)) span.setAttribute(key, attributes[key]);
|
|
132
|
-
const store = traceAls.getStore();
|
|
133
|
-
const prevPlatformSpan = store?.platformSpan;
|
|
134
|
-
if (store) store.platformSpan = span;
|
|
135
|
-
try {
|
|
136
|
-
return await runOtelSpan(name, attributes, fn);
|
|
137
|
-
} finally {
|
|
138
|
-
if (store) store.platformSpan = prevPlatformSpan;
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
/** The OTEL half of withSpan() — no-op passthrough when no SDK is active. */
|
|
143
|
-
async function runOtelSpan(name, attributes, fn) {
|
|
144
|
-
const tracer = await getTracer();
|
|
145
|
-
if (!tracer) return fn();
|
|
146
|
-
const api = await getOtelApi();
|
|
147
|
-
return tracer.startActiveSpan(name, { attributes }, async (span) => {
|
|
148
|
-
const prevSpanId = getSpanId();
|
|
149
|
-
updateSpanId(span.spanContext().spanId);
|
|
150
|
-
try {
|
|
151
|
-
const result = await fn();
|
|
152
|
-
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
153
|
-
return result;
|
|
154
|
-
} catch (error) {
|
|
155
|
-
span.setStatus({ code: api.SpanStatusCode.ERROR });
|
|
156
|
-
if (error instanceof Error) span.recordException(error);
|
|
157
|
-
throw error;
|
|
158
|
-
} finally {
|
|
159
|
-
span.end();
|
|
160
|
-
updateSpanId(prevSpanId);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Set an attribute on the current active span (if any).
|
|
166
|
-
* Used for setting span attributes after span creation (e.g. timber.result on access spans).
|
|
167
|
-
*/
|
|
168
|
-
async function setSpanAttribute(key, value) {
|
|
169
|
-
const platformSpan = traceAls.getStore()?.platformSpan;
|
|
170
|
-
if (platformSpan) platformSpan.setAttribute(key, value);
|
|
171
|
-
const api = await getOtelApi();
|
|
172
|
-
if (!api) return;
|
|
173
|
-
const activeSpan = api.trace.getActiveSpan();
|
|
174
|
-
if (activeSpan) activeSpan.setAttribute(key, value);
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Add a span event to the current active span (if any).
|
|
178
|
-
* Used for timber.cache HIT/MISS events — recorded as span events, not child spans.
|
|
16
|
+
* Design doc: design/11-platform.md §"waitUntil()"
|
|
179
17
|
*/
|
|
180
|
-
async function addSpanEvent(name, attributes) {
|
|
181
|
-
const api = await getOtelApi();
|
|
182
|
-
if (!api) return;
|
|
183
|
-
const activeSpan = api.trace.getActiveSpan();
|
|
184
|
-
if (activeSpan) activeSpan.addEvent(name, attributes);
|
|
185
|
-
}
|
|
186
18
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* Used on the cache hot path where awaiting addSpanEvent creates an
|
|
190
|
-
* unnecessary microtask per cache operation. If OTEL is not loaded yet,
|
|
191
|
-
* the event is silently dropped (acceptable for diagnostics).
|
|
19
|
+
* Get the current request's waitUntil function, if available.
|
|
192
20
|
*
|
|
193
|
-
*
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if (!_otelApi) return;
|
|
197
|
-
const activeSpan = _otelApi.trace.getActiveSpan();
|
|
198
|
-
if (activeSpan) activeSpan.addEvent(name, attributes);
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Try to extract the OTEL trace ID from the current active span context.
|
|
202
|
-
* Returns undefined if OTEL is not active or no span exists.
|
|
21
|
+
* Returns undefined when no platform adapter has installed a waitUntil
|
|
22
|
+
* handler for the current request (e.g., on platforms that don't support
|
|
23
|
+
* lifecycle extension, or outside a request context).
|
|
203
24
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (!api) return void 0;
|
|
207
|
-
const activeSpan = api.trace.getActiveSpan();
|
|
208
|
-
if (!activeSpan) return void 0;
|
|
209
|
-
const ctx = activeSpan.spanContext();
|
|
210
|
-
if (!ctx.traceId || ctx.traceId === "00000000000000000000000000000000") return;
|
|
211
|
-
return {
|
|
212
|
-
traceId: ctx.traceId,
|
|
213
|
-
spanId: ctx.spanId
|
|
214
|
-
};
|
|
25
|
+
function getWaitUntil() {
|
|
26
|
+
return waitUntilAls.getStore();
|
|
215
27
|
}
|
|
216
28
|
//#endregion
|
|
217
29
|
//#region src/server/debug.ts
|
|
@@ -319,211 +131,6 @@ function _readTimberDebugEnv() {
|
|
|
319
131
|
return false;
|
|
320
132
|
}
|
|
321
133
|
//#endregion
|
|
322
|
-
//#region src/server/error-formatter.ts
|
|
323
|
-
/**
|
|
324
|
-
* Error Formatter — rewrites SSR/RSC error messages to surface user code.
|
|
325
|
-
*
|
|
326
|
-
* When React or Vite throw errors during SSR, stack traces reference
|
|
327
|
-
* vendored dependency paths (e.g. `.vite/deps_ssr/@vitejs_plugin-rsc_vendor_...`)
|
|
328
|
-
* and mangled export names (`__vite_ssr_export_default__`). This module
|
|
329
|
-
* rewrites error messages and stack traces to point at user code instead.
|
|
330
|
-
*
|
|
331
|
-
* Dev-only — in production, errors go through the structured logger
|
|
332
|
-
* without formatting.
|
|
333
|
-
*/
|
|
334
|
-
/**
|
|
335
|
-
* Patterns that identify internal Vite/RSC vendor paths in stack traces.
|
|
336
|
-
* These are replaced with human-readable labels.
|
|
337
|
-
*/
|
|
338
|
-
var VENDOR_PATH_PATTERNS = [
|
|
339
|
-
{
|
|
340
|
-
pattern: /node_modules\/\.vite\/deps_ssr\/@vitejs_plugin-rsc_vendor_react-server-dom[^\s)]+/g,
|
|
341
|
-
replacement: "<react-server-dom>"
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
pattern: /node_modules\/\.vite\/deps_ssr\/@vitejs_plugin-rsc_vendor[^\s)]+/g,
|
|
345
|
-
replacement: "<rsc-vendor>"
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
pattern: /node_modules\/\.vite\/deps_ssr\/[^\s)]+/g,
|
|
349
|
-
replacement: "<vite-dep>"
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
pattern: /node_modules\/\.vite\/deps\/[^\s)]+/g,
|
|
353
|
-
replacement: "<vite-dep>"
|
|
354
|
-
}
|
|
355
|
-
];
|
|
356
|
-
/**
|
|
357
|
-
* Patterns that identify Vite-mangled export names in error messages.
|
|
358
|
-
*/
|
|
359
|
-
var MANGLED_NAME_PATTERNS = [{
|
|
360
|
-
pattern: /__vite_ssr_export_default__/g,
|
|
361
|
-
replacement: "<default export>"
|
|
362
|
-
}, {
|
|
363
|
-
pattern: /__vite_ssr_export_(\w+)__/g,
|
|
364
|
-
replacement: "<export $1>"
|
|
365
|
-
}];
|
|
366
|
-
/**
|
|
367
|
-
* Rewrite an error's message and stack to replace internal Vite paths
|
|
368
|
-
* and mangled names with human-readable labels.
|
|
369
|
-
*/
|
|
370
|
-
function formatSsrError(error) {
|
|
371
|
-
if (!(error instanceof Error)) return String(error);
|
|
372
|
-
let message = error.message;
|
|
373
|
-
let stack = error.stack ?? "";
|
|
374
|
-
for (const { pattern, replacement } of MANGLED_NAME_PATTERNS) message = message.replace(pattern, replacement);
|
|
375
|
-
for (const { pattern, replacement } of VENDOR_PATH_PATTERNS) stack = stack.replace(pattern, replacement);
|
|
376
|
-
for (const { pattern, replacement } of MANGLED_NAME_PATTERNS) stack = stack.replace(pattern, replacement);
|
|
377
|
-
const hint = extractErrorHint(error.message);
|
|
378
|
-
const parts = [];
|
|
379
|
-
parts.push(message);
|
|
380
|
-
if (hint) parts.push(` → ${hint}`);
|
|
381
|
-
const userFrames = extractUserFrames(stack);
|
|
382
|
-
if (userFrames.length > 0) {
|
|
383
|
-
parts.push("");
|
|
384
|
-
parts.push(" User code in stack:");
|
|
385
|
-
for (const frame of userFrames) parts.push(` ${frame}`);
|
|
386
|
-
}
|
|
387
|
-
return parts.join("\n");
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Extract a human-readable hint from common React/RSC error messages.
|
|
391
|
-
*
|
|
392
|
-
* React error messages contain useful information but the surrounding
|
|
393
|
-
* context (vendor paths, mangled names) obscures it. This extracts the
|
|
394
|
-
* actionable part as a one-line hint.
|
|
395
|
-
*/
|
|
396
|
-
function extractErrorHint(message) {
|
|
397
|
-
if (message.match(/Functions cannot be passed directly to Client Components/)) {
|
|
398
|
-
const propMatch = message.match(/<[^>]*?\s(\w+)=\{function/);
|
|
399
|
-
if (propMatch) return `Prop "${propMatch[1]}" is a function — mark it "use server" or call it before passing`;
|
|
400
|
-
return "A function prop was passed to a Client Component — mark it \"use server\" or call it before passing";
|
|
401
|
-
}
|
|
402
|
-
if (message.includes("Objects are not valid as a React child")) return "An object was rendered as JSX children — convert to string or extract the value";
|
|
403
|
-
const nullRefMatch = message.match(/Cannot read propert(?:y|ies) of (undefined|null) \(reading '(\w+)'\)/);
|
|
404
|
-
if (nullRefMatch) return `Accessed .${nullRefMatch[2]} on ${nullRefMatch[1]} — check that the value exists`;
|
|
405
|
-
const notFnMatch = message.match(/(\w+) is not a function/);
|
|
406
|
-
if (notFnMatch) return `"${notFnMatch[1]}" is not a function — check imports and exports`;
|
|
407
|
-
if (message.includes("Element type is invalid")) return "A component resolved to undefined/null — check default exports and import paths";
|
|
408
|
-
if (message.includes("Invalid hook call")) return "A hook was called outside of a React component render. If this is a 'use client' component, ensure the directive is at the very top of the file (before any imports) and that @vitejs/plugin-rsc is loaded correctly. Barrel re-exports from non-'use client' files do not propagate the directive.";
|
|
409
|
-
return null;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Extract stack frames that reference user code (not node_modules,
|
|
413
|
-
* not framework internals).
|
|
414
|
-
*
|
|
415
|
-
* Returns at most 5 frames to keep output concise.
|
|
416
|
-
*/
|
|
417
|
-
function extractUserFrames(stack) {
|
|
418
|
-
const lines = stack.split("\n");
|
|
419
|
-
const userFrames = [];
|
|
420
|
-
for (const line of lines) {
|
|
421
|
-
const trimmed = line.trim();
|
|
422
|
-
if (!trimmed.startsWith("at ")) continue;
|
|
423
|
-
if (trimmed.includes("node_modules") || trimmed.includes("<react-server-dom>") || trimmed.includes("<rsc-vendor>") || trimmed.includes("<vite-dep>") || trimmed.includes("node:internal")) continue;
|
|
424
|
-
userFrames.push(trimmed);
|
|
425
|
-
if (userFrames.length >= 5) break;
|
|
426
|
-
}
|
|
427
|
-
return userFrames;
|
|
428
|
-
}
|
|
429
|
-
//#endregion
|
|
430
|
-
//#region src/server/default-logger.ts
|
|
431
|
-
/**
|
|
432
|
-
* DefaultLogger — human-readable stderr logging when no custom logger is configured.
|
|
433
|
-
*
|
|
434
|
-
* Ships as the fallback so production deployments always have error visibility,
|
|
435
|
-
* even without an `instrumentation.ts` logger export. Output is one line per
|
|
436
|
-
* event, designed for `fly logs`, `kubectl logs`, Cloudflare dashboard tails, etc.
|
|
437
|
-
*
|
|
438
|
-
* Format:
|
|
439
|
-
* [timber] ERROR message key=value key=value trace_id=4bf92f35
|
|
440
|
-
* [timber] WARN message key=value key=value trace_id=4bf92f35
|
|
441
|
-
* [timber] INFO message method=GET path=/dashboard status=200 durationMs=43 trace_id=4bf92f35
|
|
442
|
-
*
|
|
443
|
-
* Behavior:
|
|
444
|
-
* - Suppressed entirely in dev mode (dev logging handles all output)
|
|
445
|
-
* - `debug` suppressed unless TIMBER_DEBUG is set
|
|
446
|
-
* - Replaced entirely when a custom logger is set via `setLogger()`
|
|
447
|
-
*
|
|
448
|
-
* See design/17-logging.md §"DefaultLogger"
|
|
449
|
-
*/
|
|
450
|
-
/**
|
|
451
|
-
* Format data fields as `key=value` pairs for human-readable output.
|
|
452
|
-
* - `error` key is serialized via formatSsrError for stack trace cleanup
|
|
453
|
-
* - `trace_id` is truncated to 8 chars for readability (full ID in OTEL)
|
|
454
|
-
* - Other values are stringified inline
|
|
455
|
-
*/
|
|
456
|
-
function formatDataFields(data) {
|
|
457
|
-
if (!data) return "";
|
|
458
|
-
const parts = [];
|
|
459
|
-
let traceId;
|
|
460
|
-
for (const [key, value] of Object.entries(data)) {
|
|
461
|
-
if (key === "trace_id") {
|
|
462
|
-
traceId = typeof value === "string" ? value : String(value);
|
|
463
|
-
continue;
|
|
464
|
-
}
|
|
465
|
-
if (key === "error") {
|
|
466
|
-
parts.push(`error=${formatSsrError(value)}`);
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
if (value === void 0 || value === null) continue;
|
|
470
|
-
parts.push(`${key}=${value}`);
|
|
471
|
-
}
|
|
472
|
-
if (traceId) parts.push(`trace_id=${traceId.slice(0, 8)}`);
|
|
473
|
-
return parts.length > 0 ? " " + parts.join(" ") : "";
|
|
474
|
-
}
|
|
475
|
-
/** Pad level string to fixed width for alignment. */
|
|
476
|
-
function padLevel(level) {
|
|
477
|
-
return level.padEnd(5);
|
|
478
|
-
}
|
|
479
|
-
function createDefaultLogger() {
|
|
480
|
-
return {
|
|
481
|
-
error(msg, data) {
|
|
482
|
-
const fields = formatDataFields(data);
|
|
483
|
-
process.stderr.write(`[timber] ${padLevel("ERROR")} ${msg}${fields}\n`);
|
|
484
|
-
},
|
|
485
|
-
warn(msg, data) {
|
|
486
|
-
const fields = formatDataFields(data);
|
|
487
|
-
process.stderr.write(`[timber] ${padLevel("WARN")} ${msg}${fields}\n`);
|
|
488
|
-
},
|
|
489
|
-
info(msg, data) {
|
|
490
|
-
if (isDevMode()) return;
|
|
491
|
-
if (!isDebug()) return;
|
|
492
|
-
const fields = formatDataFields(data);
|
|
493
|
-
process.stderr.write(`[timber] ${padLevel("INFO")} ${msg}${fields}\n`);
|
|
494
|
-
},
|
|
495
|
-
debug(msg, data) {
|
|
496
|
-
if (isDevMode()) return;
|
|
497
|
-
if (!isDebug()) return;
|
|
498
|
-
const fields = formatDataFields(data);
|
|
499
|
-
process.stderr.write(`[timber] ${padLevel("DEBUG")} ${msg}${fields}\n`);
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
//#endregion
|
|
504
|
-
//#region src/server/waituntil-bridge.ts
|
|
505
|
-
/**
|
|
506
|
-
* Per-request waitUntil bridge — ALS bridge for platform adapters.
|
|
507
|
-
*
|
|
508
|
-
* The generated entry point (Nitro, Cloudflare) wraps the handler with
|
|
509
|
-
* `runWithWaitUntil`, binding the platform's lifecycle extension function
|
|
510
|
-
* (e.g., h3's `event.waitUntil()` or CF's `ctx.waitUntil()`) for the
|
|
511
|
-
* request duration. The `waitUntil()` primitive reads from this ALS to
|
|
512
|
-
* dispatch background work to the correct platform API.
|
|
513
|
-
*
|
|
514
|
-
* Design doc: design/11-platform.md §"waitUntil()"
|
|
515
|
-
*/
|
|
516
|
-
/**
|
|
517
|
-
* Get the current request's waitUntil function, if available.
|
|
518
|
-
*
|
|
519
|
-
* Returns undefined when no platform adapter has installed a waitUntil
|
|
520
|
-
* handler for the current request (e.g., on platforms that don't support
|
|
521
|
-
* lifecycle extension, or outside a request context).
|
|
522
|
-
*/
|
|
523
|
-
function getWaitUntil() {
|
|
524
|
-
return waitUntilAls.getStore();
|
|
525
|
-
}
|
|
526
|
-
//#endregion
|
|
527
134
|
//#region src/server/cookie-parsing.ts
|
|
528
135
|
/**
|
|
529
136
|
* Cookie parsing and serialization helpers — pure string ↔ structure
|
|
@@ -1363,114 +970,6 @@ function waitUntil(promise) {
|
|
|
1363
970
|
}
|
|
1364
971
|
}
|
|
1365
972
|
//#endregion
|
|
1366
|
-
|
|
1367
|
-
/**
|
|
1368
|
-
* Logger — structured logging with environment-aware formatting.
|
|
1369
|
-
*
|
|
1370
|
-
* timber.js ships a DefaultLogger that writes human-readable lines to stderr
|
|
1371
|
-
* in production. Users can export a custom logger from instrumentation.ts to
|
|
1372
|
-
* replace it with pino, winston, or any TimberLogger-compatible object.
|
|
1373
|
-
*
|
|
1374
|
-
* See design/17-logging.md §"Production Logging"
|
|
1375
|
-
*/
|
|
1376
|
-
var _logger = createDefaultLogger();
|
|
1377
|
-
/**
|
|
1378
|
-
* Set the user-provided logger. Called by the instrumentation loader
|
|
1379
|
-
* when it finds a `logger` export in instrumentation.ts. Replaces
|
|
1380
|
-
* the DefaultLogger entirely.
|
|
1381
|
-
*/
|
|
1382
|
-
function setLogger(logger) {
|
|
1383
|
-
_logger = logger;
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* Get the current logger. Always non-null — returns DefaultLogger when
|
|
1387
|
-
* no custom logger is configured.
|
|
1388
|
-
*/
|
|
1389
|
-
function getLogger() {
|
|
1390
|
-
return _logger;
|
|
1391
|
-
}
|
|
1392
|
-
/**
|
|
1393
|
-
* Inject trace_id and span_id into log data for log–trace correlation.
|
|
1394
|
-
* Always injects trace_id (never undefined). Injects span_id only when OTEL is active.
|
|
1395
|
-
*/
|
|
1396
|
-
function withTraceContext(data) {
|
|
1397
|
-
const store = getTraceStore();
|
|
1398
|
-
const enriched = { ...data };
|
|
1399
|
-
if (store) {
|
|
1400
|
-
enriched.trace_id = store.traceId;
|
|
1401
|
-
if (store.spanId) enriched.span_id = store.spanId;
|
|
1402
|
-
}
|
|
1403
|
-
return enriched;
|
|
1404
|
-
}
|
|
1405
|
-
/** Log a completed request. Level: info. */
|
|
1406
|
-
function logRequestCompleted(data) {
|
|
1407
|
-
_logger.info("request completed", withTraceContext(data));
|
|
1408
|
-
}
|
|
1409
|
-
/** Log request received. Level: debug. */
|
|
1410
|
-
function logRequestReceived(data) {
|
|
1411
|
-
_logger.debug("request received", withTraceContext(data));
|
|
1412
|
-
}
|
|
1413
|
-
/** Log a slow request warning. Level: warn. */
|
|
1414
|
-
function logSlowRequest(data) {
|
|
1415
|
-
_logger.warn("slow request exceeded threshold", withTraceContext(data));
|
|
1416
|
-
}
|
|
1417
|
-
/** Log middleware short-circuit. Level: debug. */
|
|
1418
|
-
function logMiddlewareShortCircuit(data) {
|
|
1419
|
-
_logger.debug("middleware short-circuited", withTraceContext(data));
|
|
1420
|
-
}
|
|
1421
|
-
/** Log unhandled error in middleware phase. Level: error. */
|
|
1422
|
-
function logMiddlewareError(data) {
|
|
1423
|
-
if (isControlFlowSignal(data.error)) return;
|
|
1424
|
-
_logger.error("unhandled error in middleware phase", withTraceContext(data));
|
|
1425
|
-
}
|
|
1426
|
-
/** Log unhandled render-phase error. Level: error. */
|
|
1427
|
-
function logRenderError(data) {
|
|
1428
|
-
if (isControlFlowSignal(data.error)) return;
|
|
1429
|
-
_logger.error("unhandled render-phase error", withTraceContext(data));
|
|
1430
|
-
}
|
|
1431
|
-
/** Log proxy.ts uncaught error. Level: error. */
|
|
1432
|
-
function logProxyError(data) {
|
|
1433
|
-
_logger.error("proxy.ts threw uncaught error", withTraceContext(data));
|
|
1434
|
-
}
|
|
1435
|
-
/** Log unhandled error in route handler. Level: error. */
|
|
1436
|
-
function logRouteError(data) {
|
|
1437
|
-
if (isControlFlowSignal(data.error)) return;
|
|
1438
|
-
_logger.error("unhandled route handler error", withTraceContext(data));
|
|
1439
|
-
}
|
|
1440
|
-
/** Log waitUntil() adapter missing (once at startup). Level: warn. */
|
|
1441
|
-
function logWaitUntilUnsupported() {
|
|
1442
|
-
_logger.warn("adapter does not support waitUntil()");
|
|
1443
|
-
}
|
|
1444
|
-
/** Log waitUntil() promise rejection. Level: warn. */
|
|
1445
|
-
function logWaitUntilRejected(data) {
|
|
1446
|
-
_logger.warn("waitUntil() promise rejected", withTraceContext(data));
|
|
1447
|
-
}
|
|
1448
|
-
/** Log staleWhileRevalidate refetch failure. Level: warn. */
|
|
1449
|
-
function logSwrRefetchFailed(data) {
|
|
1450
|
-
_logger.warn("staleWhileRevalidate refetch failed", withTraceContext(data));
|
|
1451
|
-
}
|
|
1452
|
-
/** Log cache miss. Level: debug. */
|
|
1453
|
-
function logCacheMiss(data) {
|
|
1454
|
-
_logger.debug("timber.cache MISS", withTraceContext(data));
|
|
1455
|
-
}
|
|
1456
|
-
/**
|
|
1457
|
-
* Log an intentionally swallowed error. Provides observability into catch
|
|
1458
|
-
* blocks that are deliberately empty — the error is consumed, never rethrown.
|
|
1459
|
-
*
|
|
1460
|
-
* Default level: `warn` in dev (so the overlay surfaces patterns), `debug`
|
|
1461
|
-
* in production (low noise unless TIMBER_DEBUG is set). Pass `opts.level`
|
|
1462
|
-
* to override.
|
|
1463
|
-
*
|
|
1464
|
-
* **Infallible** — swallow() itself never throws, even if the logger is
|
|
1465
|
-
* broken. A thrown swallow would turn a benign catch into a crash.
|
|
1466
|
-
*/
|
|
1467
|
-
function swallow(err, reason, opts) {
|
|
1468
|
-
try {
|
|
1469
|
-
const level = opts?.level ?? (isDevMode() ? "warn" : "debug");
|
|
1470
|
-
_logger[level](`swallowed: ${reason}`, withTraceContext({ error: err }));
|
|
1471
|
-
} catch {}
|
|
1472
|
-
}
|
|
1473
|
-
//#endregion
|
|
1474
|
-
export { getSegmentParams as A, isDebug as B, redirect as C, getHeader as D, applyRequestHeaderOverlay as E, setSegmentParams as F, getOtelTraceId as G, addSpanEvent as H, getCookie as I, replaceTraceId as J, getSpanId as K, getCookieJar as L, runWithRequestContext as M, setMatchedSegmentPath as N, getHeaders as O, setMutableCookieContext as P, getSetCookieHeaders as R, isSsrStreamError as S, waitUntil as T, addSpanEventSync as U, isDevMode as V, generateTraceId as W, setSpanAttribute as X, runWithTraceId as Y, withSpan as Z, RedirectSignal as _, logProxyError as a, isDenySignal as b, logRequestReceived as c, logSwrRefetchFailed as d, logWaitUntilRejected as f, DenySignal as g, swallow as h, logMiddlewareShortCircuit as i, markResponseFlushed as j, getSearchParams as k, logRouteError as l, setLogger as m, logCacheMiss as n, logRenderError as o, logWaitUntilUnsupported as p, getTraceId as q, logMiddlewareError as r, logRequestCompleted as s, getLogger as t, logSlowRequest as u, RenderError as v, redirectExternal as w, isRedirectSignal as x, deny as y, getWaitUntil as z };
|
|
973
|
+
export { getCookieJar as C, getWaitUntil as D, isDevMode as E, getCookie as S, isDebug as T, markResponseFlushed as _, isControlFlowSignal as a, setMutableCookieContext as b, isSsrStreamError as c, waitUntil as d, applyRequestHeaderOverlay as f, getSegmentParams as g, getSearchParams as h, deny as i, redirect as l, getHeaders as m, RedirectSignal as n, isDenySignal as o, getHeader as p, RenderError as r, isRedirectSignal as s, DenySignal as t, redirectExternal as u, runWithRequestContext as v, getSetCookieHeaders as w, setSegmentParams as x, setMatchedSegmentPath as y };
|
|
1475
974
|
|
|
1476
|
-
//# sourceMappingURL=
|
|
975
|
+
//# sourceMappingURL=primitives-DLAnvsrk.js.map
|