@teyik0/furin 0.2.0-alpha.1 → 0.2.0-alpha.3
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/LICENSE +21 -21
- package/README.md +33 -33
- package/dist/adapter/static.d.ts +1 -1
- package/dist/build/compile-entry.ts +109 -109
- package/dist/build/entry-template.ts +156 -156
- package/dist/build/index.js +1724 -687
- package/dist/build/route-types.d.ts +3 -1
- package/dist/build/server-routes-entry.ts +36 -36
- package/dist/build/shared.d.ts +1 -0
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/cli/index.js +1673 -658
- package/dist/client/link.js +883 -89
- package/dist/client/router/index.d.ts +4 -0
- package/dist/client/router/link-utils.d.ts +3 -1
- package/dist/client/router/navigation.d.ts +10 -0
- package/dist/client/router/provider.d.ts +1 -1
- package/dist/client/router/search/index.d.ts +18 -0
- package/dist/client/router/search-store.d.ts +21 -0
- package/dist/client/router/types.d.ts +14 -1
- package/dist/client/sync.d.ts +25 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +44 -0
- package/dist/furin.d.ts +9 -1
- package/dist/furin.js +1578 -258
- package/dist/server/auto-invalidate/runtime.d.ts +1 -1
- package/dist/server/dev-page-plugin.d.ts +3 -0
- package/dist/server/render/assemble.d.ts +2 -0
- package/dist/server/render/isr.d.ts +2 -1
- package/dist/server/render/ssg.d.ts +3 -2
- package/dist/server/render/ssr.d.ts +5 -4
- package/dist/server/router/hmr.d.ts +4 -3
- package/dist/server/router/index.d.ts +1 -1
- package/dist/server/router/index.js +1 -2
- package/dist/server/router/index.ts +1 -2
- package/dist/server/router/plugin.d.ts +2 -1
- package/dist/server/router/schemas.d.ts +25 -17
- package/dist/server/sync/config.d.ts +6 -0
- package/dist/server/sync/index.d.ts +4 -0
- package/dist/server/sync/plugin.d.ts +369 -0
- package/dist/server/sync/stream.d.ts +47 -0
- package/dist/shared/search-params.d.ts +17 -0
- package/package.json +10 -5
- package/src/adapter/README.md +13 -13
- package/src/adapter/static.ts +23 -6
- package/src/build/client.ts +152 -149
- package/src/build/compile-entry.ts +109 -109
- package/src/build/entry-template.ts +156 -156
- package/src/build/hydrate.ts +340 -331
- package/src/build/index.ts +152 -152
- package/src/build/route-types.ts +145 -115
- package/src/build/scan-server.ts +95 -95
- package/src/build/server-routes-entry.ts +36 -36
- package/src/build/shared.ts +80 -78
- package/src/build/ssg-cache.ts +32 -31
- package/src/build/types.ts +89 -89
- package/src/client/link.tsx +13 -4
- package/src/client/router/context.ts +2 -0
- package/src/client/router/index.ts +9 -0
- package/src/client/router/link-utils.ts +184 -180
- package/src/client/router/navigation.ts +61 -0
- package/src/client/router/provider.tsx +804 -723
- package/src/client/router/search/index.ts +99 -0
- package/src/client/router/search-store.ts +86 -0
- package/src/client/router/types.ts +276 -263
- package/src/client/sync.ts +98 -0
- package/src/client.ts +369 -355
- package/src/furin.ts +465 -437
- package/src/server/auto-invalidate/runtime.ts +134 -133
- package/src/server/dev-page-plugin.ts +454 -449
- package/src/server/render/assemble.ts +160 -133
- package/src/server/render/isr.ts +323 -295
- package/src/server/render/not-found.ts +2 -0
- package/src/server/render/ssg.ts +15 -4
- package/src/server/render/ssr.ts +585 -545
- package/src/server/router/hmr.ts +14 -10
- package/src/server/router/index.ts +1 -2
- package/src/server/router/patterns.ts +5 -0
- package/src/server/router/plugin.ts +384 -401
- package/src/server/router/schemas.ts +172 -57
- package/src/server/sync/config.ts +29 -0
- package/src/server/sync/index.ts +14 -0
- package/src/server/sync/plugin.ts +108 -0
- package/src/server/sync/stream.ts +144 -0
- package/src/shared/search-params.ts +182 -0
package/dist/furin.js
CHANGED
|
@@ -15,12 +15,15 @@ var __export = (target, all) => {
|
|
|
15
15
|
};
|
|
16
16
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
17
|
|
|
18
|
-
// ../../node_modules/.bun/evlog@2.
|
|
18
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/utils.mjs
|
|
19
19
|
function formatDuration(ms) {
|
|
20
20
|
if (ms < 1000)
|
|
21
21
|
return `${Math.round(ms)}ms`;
|
|
22
22
|
return `${(ms / 1000).toFixed(2)}s`;
|
|
23
23
|
}
|
|
24
|
+
function isServer() {
|
|
25
|
+
return typeof window === "undefined";
|
|
26
|
+
}
|
|
24
27
|
function isBrowser() {
|
|
25
28
|
if (typeof window === "undefined")
|
|
26
29
|
return false;
|
|
@@ -66,20 +69,26 @@ function escapeFormatString(str) {
|
|
|
66
69
|
function filterSafeHeaders(headers) {
|
|
67
70
|
const safeHeaders = {};
|
|
68
71
|
for (const [key, value] of Object.entries(headers))
|
|
69
|
-
if (value !== undefined && !
|
|
72
|
+
if (value !== undefined && !SENSITIVE_HEADER_SET.has(key.toLowerCase()))
|
|
70
73
|
safeHeaders[key] = value;
|
|
71
74
|
return safeHeaders;
|
|
72
75
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
76
|
+
function globToRegExp(pattern, separator = "/") {
|
|
77
|
+
const cacheKey = `${separator}:${pattern}`;
|
|
78
|
+
let regex = patternCache.get(cacheKey);
|
|
75
79
|
if (!regex) {
|
|
76
|
-
const
|
|
80
|
+
const segment = separator === "/" ? "[^/]*" : "[^.]*";
|
|
81
|
+
const char = separator === "/" ? "[^/]" : "[^.]";
|
|
82
|
+
const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "{{GLOBSTAR}}").replace(/\*/g, segment).replace(/{{GLOBSTAR}}/g, ".*").replace(/\?/g, char);
|
|
77
83
|
regex = new RegExp(`^${regexPattern}$`);
|
|
78
|
-
patternCache.set(
|
|
84
|
+
patternCache.set(cacheKey, regex);
|
|
79
85
|
}
|
|
80
|
-
return regex
|
|
86
|
+
return regex;
|
|
87
|
+
}
|
|
88
|
+
function matchesPattern(path, pattern) {
|
|
89
|
+
return globToRegExp(pattern, "/").test(path);
|
|
81
90
|
}
|
|
82
|
-
var LEVEL_ORDER, colors, levelColorMap, cssColors, cssLevelColorMap, SENSITIVE_HEADERS, patternCache;
|
|
91
|
+
var LEVEL_ORDER, colors, levelColorMap, cssColors, cssLevelColorMap, SENSITIVE_HEADERS, SENSITIVE_HEADER_SET, patternCache;
|
|
83
92
|
var init_utils = __esm(() => {
|
|
84
93
|
LEVEL_ORDER = {
|
|
85
94
|
debug: 0,
|
|
@@ -129,10 +138,455 @@ var init_utils = __esm(() => {
|
|
|
129
138
|
"x-auth-token",
|
|
130
139
|
"proxy-authorization"
|
|
131
140
|
];
|
|
141
|
+
SENSITIVE_HEADER_SET = new Set(SENSITIVE_HEADERS);
|
|
132
142
|
patternCache = /* @__PURE__ */ new Map;
|
|
133
143
|
});
|
|
134
144
|
|
|
135
|
-
// ../../node_modules/.bun/evlog@2.
|
|
145
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/pretty-error-THg0U0w9.mjs
|
|
146
|
+
function pushTreeSpacer(children) {
|
|
147
|
+
children.push(PRETTY_ERROR_TREE_SPACER);
|
|
148
|
+
}
|
|
149
|
+
function isPlainObject(val) {
|
|
150
|
+
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
151
|
+
}
|
|
152
|
+
function pickString(obj, key) {
|
|
153
|
+
const val = obj[key];
|
|
154
|
+
return typeof val === "string" && val.length > 0 ? val : undefined;
|
|
155
|
+
}
|
|
156
|
+
function pickNumber(obj, key) {
|
|
157
|
+
const val = obj[key];
|
|
158
|
+
return typeof val === "number" ? val : undefined;
|
|
159
|
+
}
|
|
160
|
+
function extractGuidance(data) {
|
|
161
|
+
return {
|
|
162
|
+
code: pickString(data, "code"),
|
|
163
|
+
why: pickString(data, "why"),
|
|
164
|
+
fix: pickString(data, "fix"),
|
|
165
|
+
link: pickString(data, "link")
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function normalizeErrorContext(error) {
|
|
169
|
+
if (error === null || error === undefined)
|
|
170
|
+
return null;
|
|
171
|
+
if (typeof error === "string")
|
|
172
|
+
return { message: error };
|
|
173
|
+
if (!isPlainObject(error))
|
|
174
|
+
return { message: String(error) };
|
|
175
|
+
const result = {
|
|
176
|
+
message: pickString(error, "message") ?? pickString(error, "statusText") ?? pickString(error, "statusMessage") ?? "Unknown error",
|
|
177
|
+
name: pickString(error, "name"),
|
|
178
|
+
code: pickString(error, "code"),
|
|
179
|
+
why: pickString(error, "why"),
|
|
180
|
+
fix: pickString(error, "fix"),
|
|
181
|
+
link: pickString(error, "link"),
|
|
182
|
+
status: pickNumber(error, "status") ?? pickNumber(error, "statusCode"),
|
|
183
|
+
stack: pickString(error, "stack")
|
|
184
|
+
};
|
|
185
|
+
const { data, cause } = error;
|
|
186
|
+
if (isPlainObject(data)) {
|
|
187
|
+
const guidance = extractGuidance(data);
|
|
188
|
+
if (!result.code)
|
|
189
|
+
result.code = guidance.code;
|
|
190
|
+
if (!result.why)
|
|
191
|
+
result.why = guidance.why;
|
|
192
|
+
if (!result.fix)
|
|
193
|
+
result.fix = guidance.fix;
|
|
194
|
+
if (!result.link)
|
|
195
|
+
result.link = guidance.link;
|
|
196
|
+
}
|
|
197
|
+
if (cause instanceof Error)
|
|
198
|
+
result.cause = cause.message;
|
|
199
|
+
else if (isPlainObject(cause) && pickString(cause, "message"))
|
|
200
|
+
result.cause = pickString(cause, "message");
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
function decodeFileUrl(file) {
|
|
204
|
+
if (file.startsWith("file://"))
|
|
205
|
+
try {
|
|
206
|
+
return decodeURIComponent(new URL(file).pathname);
|
|
207
|
+
} catch {
|
|
208
|
+
return file.slice(7);
|
|
209
|
+
}
|
|
210
|
+
return file;
|
|
211
|
+
}
|
|
212
|
+
function isAppPath(file) {
|
|
213
|
+
const normalized = decodeFileUrl(file).replace(/\\/g, "/");
|
|
214
|
+
if (normalized.startsWith("node:"))
|
|
215
|
+
return false;
|
|
216
|
+
if (SKIP_PATH_RE.test(normalized))
|
|
217
|
+
return false;
|
|
218
|
+
if (normalized.includes("/node_modules/"))
|
|
219
|
+
return false;
|
|
220
|
+
if (isFrameworkRuntimePath(normalized))
|
|
221
|
+
return false;
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
function formatDisplayPath(file, cwd) {
|
|
225
|
+
const decoded = decodeFileUrl(file).replace(/\\/g, "/");
|
|
226
|
+
const cwdNorm = cwd.replace(/\\/g, "/").replace(/\/$/, "");
|
|
227
|
+
if (cwdNorm && decoded.startsWith(`${cwdNorm}/`)) {
|
|
228
|
+
const rel = decoded.slice(cwdNorm.length + 1);
|
|
229
|
+
return rel.startsWith("./") ? rel.slice(2) : rel;
|
|
230
|
+
}
|
|
231
|
+
const serverIdx = decoded.indexOf("/server/");
|
|
232
|
+
if (serverIdx >= 0)
|
|
233
|
+
return decoded.slice(serverIdx + 1);
|
|
234
|
+
const srcIdx = decoded.indexOf("/src/");
|
|
235
|
+
if (srcIdx >= 0)
|
|
236
|
+
return decoded.slice(srcIdx + 1);
|
|
237
|
+
return decoded;
|
|
238
|
+
}
|
|
239
|
+
function compactStackForStorage(stack, maxFrames = 5) {
|
|
240
|
+
if (!stack)
|
|
241
|
+
return;
|
|
242
|
+
const head = stack.split(`
|
|
243
|
+
`)[0] ?? "";
|
|
244
|
+
const useful = parseStackFrames(stack).filter((f) => f.file && f.line && f.isApp && !isInternalErrorFrame(f)).slice(0, maxFrames);
|
|
245
|
+
if (useful.length === 0)
|
|
246
|
+
return stack;
|
|
247
|
+
return [head, ...useful.map((f) => f.raw)].join(`
|
|
248
|
+
`);
|
|
249
|
+
}
|
|
250
|
+
function parseStackFrames(stack) {
|
|
251
|
+
if (!stack)
|
|
252
|
+
return [];
|
|
253
|
+
const lines = stack.split(`
|
|
254
|
+
`);
|
|
255
|
+
const frames = [];
|
|
256
|
+
for (const line of lines) {
|
|
257
|
+
const trimmed = line.trim();
|
|
258
|
+
if (!trimmed.startsWith("at "))
|
|
259
|
+
continue;
|
|
260
|
+
const withFn = trimmed.match(/^at (.+?) \((.+):(\d+):(\d+)\)$/);
|
|
261
|
+
if (withFn) {
|
|
262
|
+
const [, fn, file, lineStr, colStr] = withFn;
|
|
263
|
+
frames.push({
|
|
264
|
+
raw: trimmed,
|
|
265
|
+
fn,
|
|
266
|
+
file,
|
|
267
|
+
line: Number(lineStr),
|
|
268
|
+
column: Number(colStr),
|
|
269
|
+
isApp: isAppPath(file)
|
|
270
|
+
});
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const withoutFn = trimmed.match(/^at (.+):(\d+):(\d+)$/);
|
|
274
|
+
if (withoutFn) {
|
|
275
|
+
const [, file, lineStr, colStr] = withoutFn;
|
|
276
|
+
frames.push({
|
|
277
|
+
raw: trimmed,
|
|
278
|
+
file,
|
|
279
|
+
line: Number(lineStr),
|
|
280
|
+
column: Number(colStr),
|
|
281
|
+
isApp: isAppPath(file)
|
|
282
|
+
});
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const asyncFn = trimmed.match(/^at async (.+?) \((.+):(\d+):(\d+)\)$/);
|
|
286
|
+
if (asyncFn) {
|
|
287
|
+
const [, fn, file, lineStr, colStr] = asyncFn;
|
|
288
|
+
frames.push({
|
|
289
|
+
raw: trimmed,
|
|
290
|
+
fn: `async ${fn}`,
|
|
291
|
+
file,
|
|
292
|
+
line: Number(lineStr),
|
|
293
|
+
column: Number(colStr),
|
|
294
|
+
isApp: isAppPath(file)
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return frames;
|
|
299
|
+
}
|
|
300
|
+
function isFrameworkRuntimePath(path) {
|
|
301
|
+
const normalized = path.replace(/\\/g, "/");
|
|
302
|
+
return normalized.includes("route-modules/") || normalized.includes("webpack://next/") || normalized.includes("/next/dist/") || normalized.includes("/compiled/next-server/");
|
|
303
|
+
}
|
|
304
|
+
function isFrameworkRuntimeFrame(frame) {
|
|
305
|
+
if (!frame.file)
|
|
306
|
+
return false;
|
|
307
|
+
return isFrameworkRuntimePath(decodeFileUrl(frame.file));
|
|
308
|
+
}
|
|
309
|
+
function isInternalErrorFrame(frame) {
|
|
310
|
+
if (isFrameworkRuntimeFrame(frame))
|
|
311
|
+
return true;
|
|
312
|
+
if (frame.fn) {
|
|
313
|
+
const fn = frame.fn.replace(/^async /, "");
|
|
314
|
+
if (SKIP_FRAME_FN_RE.test(fn))
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
if (!frame.file)
|
|
318
|
+
return true;
|
|
319
|
+
const path = decodeFileUrl(frame.file).replace(/\\/g, "/");
|
|
320
|
+
if (SKIP_FRAME_PATH_RE.test(path))
|
|
321
|
+
return true;
|
|
322
|
+
if (path.includes(".nuxt/"))
|
|
323
|
+
return true;
|
|
324
|
+
if (path.includes(".next/"))
|
|
325
|
+
return true;
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
function pickPrimaryFrame(frames) {
|
|
329
|
+
for (const frame of frames)
|
|
330
|
+
if (frame.isApp && frame.file && frame.line && !isInternalErrorFrame(frame))
|
|
331
|
+
return frame;
|
|
332
|
+
}
|
|
333
|
+
function readCodeSnippet(file, line, contextLines = 2) {
|
|
334
|
+
if (!isDev() || isBrowser() || !snippetReader)
|
|
335
|
+
return null;
|
|
336
|
+
const path = decodeFileUrl(file).replace(/\\/g, "/");
|
|
337
|
+
if (path.includes(".next/") || path.includes(".nuxt/") || path.includes(".output/"))
|
|
338
|
+
return null;
|
|
339
|
+
return snippetReader(file, line, contextLines);
|
|
340
|
+
}
|
|
341
|
+
function formatSnippetLines(snippet) {
|
|
342
|
+
const width = String(snippet[snippet.length - 1]?.line ?? 0).length;
|
|
343
|
+
return snippet.map(({ line, content, isErrorLine }) => {
|
|
344
|
+
const marker = isErrorLine ? `${colors.red}\u276F${colors.reset}` : `${colors.dim} ${colors.reset}`;
|
|
345
|
+
const numColor = isErrorLine ? colors.red : colors.gray;
|
|
346
|
+
const trimmed = content.length > 120 ? `${content.slice(0, 117)}\u2026` : content;
|
|
347
|
+
return `${marker} ${numColor}${String(line).padStart(width, " ")}${colors.reset} ${colors.dim}\u2503${colors.reset} ${colors.dim}${trimmed}${colors.reset}`;
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
function formatFrameLocation(frame, cwd) {
|
|
351
|
+
const file = frame.file ? formatDisplayPath(frame.file, cwd) : "unknown";
|
|
352
|
+
const loc = frame.line ? `${file}:${frame.line}` : file;
|
|
353
|
+
const fn = frame.fn && frame.fn !== "<unknown>" ? frame.fn : undefined;
|
|
354
|
+
return fn ? `at ${fn} (${loc})` : `at ${loc}`;
|
|
355
|
+
}
|
|
356
|
+
function formatCollapsedFrame(frame, cwd) {
|
|
357
|
+
const file = frame.file ? formatDisplayPath(frame.file, cwd) : "unknown";
|
|
358
|
+
const loc = frame.line ? `${file}:${frame.line}` : file;
|
|
359
|
+
const prefix = frame.fn?.startsWith("async") ? "at async " : "at ";
|
|
360
|
+
const fn = frame.fn?.replace(/^async /, "");
|
|
361
|
+
if (fn && fn !== "<unknown>" && fn !== loc)
|
|
362
|
+
return `${prefix}${fn} (${loc})`;
|
|
363
|
+
return `${prefix}${loc}`;
|
|
364
|
+
}
|
|
365
|
+
function formatGuidanceLine(label, text, labelColor) {
|
|
366
|
+
const prefix = `${labelColor}${label}:${colors.reset} `;
|
|
367
|
+
const lines = [];
|
|
368
|
+
let remaining = text.trim();
|
|
369
|
+
let first = true;
|
|
370
|
+
while (remaining.length > 0) {
|
|
371
|
+
const budget = first ? Math.max(24, GUIDANCE_WRAP_WIDTH - prefix.length) : Math.max(24, GUIDANCE_WRAP_WIDTH - 5);
|
|
372
|
+
if (remaining.length <= budget) {
|
|
373
|
+
lines.push(first ? `${prefix}${remaining}` : `${GUIDANCE_CONTINUATION}${remaining}`);
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
let split = remaining.lastIndexOf(" ", budget);
|
|
377
|
+
if (split <= 0)
|
|
378
|
+
split = budget;
|
|
379
|
+
const chunk = remaining.slice(0, split).trimEnd();
|
|
380
|
+
lines.push(first ? `${prefix}${chunk}` : `${GUIDANCE_CONTINUATION}${chunk}`);
|
|
381
|
+
remaining = remaining.slice(split).trimStart();
|
|
382
|
+
first = false;
|
|
383
|
+
}
|
|
384
|
+
return lines;
|
|
385
|
+
}
|
|
386
|
+
function buildErrorEntries(error, options = {}) {
|
|
387
|
+
const normalized = normalizeErrorContext(error);
|
|
388
|
+
if (!normalized)
|
|
389
|
+
return [];
|
|
390
|
+
const cwd = options.cwd ?? (typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".");
|
|
391
|
+
const compact = options.compact ?? isDev();
|
|
392
|
+
const guidanceOnly = (options.detail ?? "full") === "guidance";
|
|
393
|
+
const showFrames = !guidanceOnly && !isBrowser() && (options.snippet ?? isDev());
|
|
394
|
+
const stackDepth = guidanceOnly ? 0 : options.stackDepth ?? (compact ? 2 : 3);
|
|
395
|
+
const snippetContextLines = compact ? 1 : 2;
|
|
396
|
+
const children = [];
|
|
397
|
+
const frames = guidanceOnly ? [] : parseStackFrames(normalized.stack);
|
|
398
|
+
const primary = guidanceOnly ? undefined : pickPrimaryFrame(frames);
|
|
399
|
+
if (!guidanceOnly && primary?.file && primary.line) {
|
|
400
|
+
pushTreeSpacer(children);
|
|
401
|
+
if (showFrames) {
|
|
402
|
+
const snippet = readCodeSnippet(primary.file, primary.line, snippetContextLines);
|
|
403
|
+
children.push(`${colors.dim} ${formatFrameLocation(primary, cwd)}${colors.reset}`);
|
|
404
|
+
if (snippet)
|
|
405
|
+
children.push(...formatSnippetLines(snippet));
|
|
406
|
+
} else
|
|
407
|
+
children.push(`${colors.dim} ${formatFrameLocation(primary, cwd)}${colors.reset}`);
|
|
408
|
+
}
|
|
409
|
+
if (normalized.code)
|
|
410
|
+
children.push(`${colors.dim}Code:${colors.reset} ${normalized.code}`);
|
|
411
|
+
if (Boolean(normalized.why || normalized.fix || normalized.link))
|
|
412
|
+
pushTreeSpacer(children);
|
|
413
|
+
if (normalized.why)
|
|
414
|
+
children.push(...formatGuidanceLine("Why", normalized.why, colors.yellow));
|
|
415
|
+
if (normalized.fix)
|
|
416
|
+
children.push(...formatGuidanceLine("Fix", normalized.fix, colors.cyan));
|
|
417
|
+
if (normalized.link)
|
|
418
|
+
children.push(`${colors.dim}More:${colors.reset} ${normalized.link}`);
|
|
419
|
+
if (normalized.cause && normalized.cause !== normalized.message)
|
|
420
|
+
children.push(`${colors.dim}Caused by:${colors.reset} ${normalized.cause}`);
|
|
421
|
+
const hiddenCount = guidanceOnly ? 0 : frames.filter((f) => !f.isApp || isInternalErrorFrame(f)).length;
|
|
422
|
+
const tailFrames = stackDepth > 0 ? frames.filter((f) => f !== primary && !isInternalErrorFrame(f)).slice(0, stackDepth) : [];
|
|
423
|
+
if (!guidanceOnly && (hiddenCount > 0 || tailFrames.length > 0)) {
|
|
424
|
+
pushTreeSpacer(children);
|
|
425
|
+
if (hiddenCount > 0)
|
|
426
|
+
children.push(`${colors.gray}stack (${hiddenCount} frame${hiddenCount === 1 ? "" : "s"} hidden in node_modules)${colors.reset}`);
|
|
427
|
+
else
|
|
428
|
+
children.push(`${colors.gray}stack${colors.reset}`);
|
|
429
|
+
for (const frame of tailFrames)
|
|
430
|
+
children.push(`${colors.gray} ${formatCollapsedFrame(frame, cwd)}${colors.reset}`);
|
|
431
|
+
}
|
|
432
|
+
return [{
|
|
433
|
+
key: "error",
|
|
434
|
+
value: `${colors.red}${colors.bold}${normalized.message}${colors.reset}`,
|
|
435
|
+
children: children.length > 0 ? children : undefined
|
|
436
|
+
}];
|
|
437
|
+
}
|
|
438
|
+
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 = " ";
|
|
439
|
+
var init_pretty_error_THg0U0w9 = __esm(() => {
|
|
440
|
+
init_utils();
|
|
441
|
+
SKIP_PATH_RE = /(?:^|[/\\])(?:node_modules|\.nuxt|\.next|\.output)(?:[/\\]|$)/;
|
|
442
|
+
SKIP_FRAME_PATH_RE = /(?:^|[/\\])(?:packages[/\\]evlog|evlog[/\\](?:dist|src))(?:[/\\]|$)/;
|
|
443
|
+
SKIP_FRAME_FN_RE = /^(?:createError|EvlogError|new EvlogError)$/;
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/dev-terminal-D4UaEm17.mjs
|
|
447
|
+
function finalizePrettyError(partial, frameworkOverlay, pretty, inDev) {
|
|
448
|
+
const compact = partial.compact ?? (inDev && pretty);
|
|
449
|
+
const detail = partial.detail ?? (frameworkOverlay ? "guidance" : "full");
|
|
450
|
+
const stackDepth = detail === "guidance" ? 0 : partial.stackDepth ?? (compact ? 2 : 3);
|
|
451
|
+
return {
|
|
452
|
+
snippet: partial.snippet ?? (detail === "full" && pretty && inDev),
|
|
453
|
+
stackDepth,
|
|
454
|
+
compact,
|
|
455
|
+
detail
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function resolveDevTerminal(input = {}) {
|
|
459
|
+
const pretty = input.pretty ?? isDev();
|
|
460
|
+
const inDev = isDev();
|
|
461
|
+
let frameworkOverlay;
|
|
462
|
+
let prettyError = {};
|
|
463
|
+
if (typeof input.dev === "string" && input.dev in DEV_PRESETS) {
|
|
464
|
+
const { frameworkOverlay: presetOverlay, detail } = DEV_PRESETS[input.dev];
|
|
465
|
+
frameworkOverlay = presetOverlay;
|
|
466
|
+
prettyError = { detail };
|
|
467
|
+
} else if (input.dev && typeof input.dev === "object") {
|
|
468
|
+
const { frameworkOverlay: devOverlay, prettyError: devPrettyError } = input.dev;
|
|
469
|
+
frameworkOverlay = devOverlay;
|
|
470
|
+
if (devPrettyError)
|
|
471
|
+
prettyError = devPrettyError;
|
|
472
|
+
}
|
|
473
|
+
if (frameworkOverlay === undefined)
|
|
474
|
+
frameworkOverlay = !(pretty && inDev);
|
|
475
|
+
return {
|
|
476
|
+
frameworkOverlay,
|
|
477
|
+
prettyError: finalizePrettyError(prettyError, frameworkOverlay, pretty, inDev)
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
var DEV_PRESETS;
|
|
481
|
+
var init_dev_terminal_D4UaEm17 = __esm(() => {
|
|
482
|
+
init_utils();
|
|
483
|
+
DEV_PRESETS = {
|
|
484
|
+
evlog: {
|
|
485
|
+
frameworkOverlay: false,
|
|
486
|
+
detail: "full"
|
|
487
|
+
},
|
|
488
|
+
nitro: {
|
|
489
|
+
frameworkOverlay: true,
|
|
490
|
+
detail: "guidance"
|
|
491
|
+
},
|
|
492
|
+
both: {
|
|
493
|
+
frameworkOverlay: true,
|
|
494
|
+
detail: "full"
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/error.mjs
|
|
500
|
+
var evlogErrorInternalKey, EvlogError;
|
|
501
|
+
var init_error = __esm(() => {
|
|
502
|
+
init_utils();
|
|
503
|
+
evlogErrorInternalKey = Symbol.for("evlog.error.internal");
|
|
504
|
+
EvlogError = class EvlogError2 extends Error {
|
|
505
|
+
code;
|
|
506
|
+
status;
|
|
507
|
+
why;
|
|
508
|
+
fix;
|
|
509
|
+
link;
|
|
510
|
+
get internal() {
|
|
511
|
+
return this[evlogErrorInternalKey];
|
|
512
|
+
}
|
|
513
|
+
constructor(options) {
|
|
514
|
+
const opts = typeof options === "string" ? { message: options } : options;
|
|
515
|
+
super(opts.message, { cause: opts.cause });
|
|
516
|
+
this.name = "EvlogError";
|
|
517
|
+
this.code = opts.code;
|
|
518
|
+
this.status = opts.status ?? 500;
|
|
519
|
+
this.why = opts.why;
|
|
520
|
+
this.fix = opts.fix;
|
|
521
|
+
this.link = opts.link;
|
|
522
|
+
if (opts.internal !== undefined)
|
|
523
|
+
Object.defineProperty(this, evlogErrorInternalKey, {
|
|
524
|
+
value: opts.internal,
|
|
525
|
+
enumerable: false,
|
|
526
|
+
writable: false,
|
|
527
|
+
configurable: true
|
|
528
|
+
});
|
|
529
|
+
if (Error.captureStackTrace)
|
|
530
|
+
Error.captureStackTrace(this, EvlogError2);
|
|
531
|
+
}
|
|
532
|
+
get statusText() {
|
|
533
|
+
return this.message;
|
|
534
|
+
}
|
|
535
|
+
get statusCode() {
|
|
536
|
+
return this.status;
|
|
537
|
+
}
|
|
538
|
+
get statusMessage() {
|
|
539
|
+
return this.message;
|
|
540
|
+
}
|
|
541
|
+
get data() {
|
|
542
|
+
if (this.code || this.why || this.fix || this.link)
|
|
543
|
+
return {
|
|
544
|
+
code: this.code,
|
|
545
|
+
why: this.why,
|
|
546
|
+
fix: this.fix,
|
|
547
|
+
link: this.link
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
toString() {
|
|
551
|
+
const useColors = isServer();
|
|
552
|
+
const red = useColors ? colors.red : "";
|
|
553
|
+
const yellow = useColors ? colors.yellow : "";
|
|
554
|
+
const cyan = useColors ? colors.cyan : "";
|
|
555
|
+
const dim = useColors ? colors.dim : "";
|
|
556
|
+
const reset = useColors ? colors.reset : "";
|
|
557
|
+
const bold = useColors ? colors.bold : "";
|
|
558
|
+
const lines = [];
|
|
559
|
+
lines.push(`${red}${bold}Error:${reset} ${this.message}`);
|
|
560
|
+
if (this.code)
|
|
561
|
+
lines.push(`${dim}Code:${reset} ${this.code}`);
|
|
562
|
+
if (this.why)
|
|
563
|
+
lines.push(`${yellow}Why:${reset} ${this.why}`);
|
|
564
|
+
if (this.fix)
|
|
565
|
+
lines.push(`${cyan}Fix:${reset} ${this.fix}`);
|
|
566
|
+
if (this.link)
|
|
567
|
+
lines.push(`${dim}More info:${reset} ${this.link}`);
|
|
568
|
+
if (this.cause)
|
|
569
|
+
lines.push(`${dim}Caused by:${reset} ${this.cause.message}`);
|
|
570
|
+
return lines.join(`
|
|
571
|
+
`);
|
|
572
|
+
}
|
|
573
|
+
toJSON() {
|
|
574
|
+
const { data } = this;
|
|
575
|
+
return {
|
|
576
|
+
name: this.name,
|
|
577
|
+
message: this.message,
|
|
578
|
+
status: this.status,
|
|
579
|
+
...data && { data },
|
|
580
|
+
...this.cause instanceof Error && { cause: {
|
|
581
|
+
name: this.cause.name,
|
|
582
|
+
message: this.cause.message
|
|
583
|
+
} }
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/headers-VtmnWcfn.mjs
|
|
136
590
|
function extractSafeHeaders(headers) {
|
|
137
591
|
const raw = {};
|
|
138
592
|
headers.forEach((value, key) => {
|
|
@@ -149,22 +603,107 @@ function extractSafeNodeHeaders(headers) {
|
|
|
149
603
|
}
|
|
150
604
|
return filterSafeHeaders(raw);
|
|
151
605
|
}
|
|
152
|
-
var
|
|
606
|
+
var init_headers_VtmnWcfn = __esm(() => {
|
|
153
607
|
init_utils();
|
|
154
608
|
});
|
|
155
609
|
|
|
156
|
-
// ../../node_modules/.bun/evlog@2.
|
|
610
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/audit-CL0q7GJU.mjs
|
|
611
|
+
function normalizeRedactPathPattern(pattern) {
|
|
612
|
+
if (!pattern.includes("*") && !pattern.includes("."))
|
|
613
|
+
return `**.${pattern}`;
|
|
614
|
+
return pattern;
|
|
615
|
+
}
|
|
616
|
+
function compileRedactPathMatchers(patterns) {
|
|
617
|
+
if (!patterns?.length)
|
|
618
|
+
return;
|
|
619
|
+
const exactPaths = /* @__PURE__ */ new Set;
|
|
620
|
+
const pathGlobs = [];
|
|
621
|
+
const keyGlobs = [];
|
|
622
|
+
const caseInsensitiveLeaves = /* @__PURE__ */ new Set;
|
|
623
|
+
for (const raw of patterns) {
|
|
624
|
+
if (!raw.includes("*")) {
|
|
625
|
+
if (raw.includes("."))
|
|
626
|
+
exactPaths.add(raw);
|
|
627
|
+
else
|
|
628
|
+
addPathGlobPattern(normalizeRedactPathPattern(raw), exactPaths, pathGlobs, caseInsensitiveLeaves);
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
if (!raw.includes("."))
|
|
632
|
+
keyGlobs.push(globToRegExp(raw, "."));
|
|
633
|
+
else
|
|
634
|
+
addPathGlobPattern(raw, exactPaths, pathGlobs, caseInsensitiveLeaves);
|
|
635
|
+
}
|
|
636
|
+
if (exactPaths.size === 0 && pathGlobs.length === 0 && keyGlobs.length === 0 && caseInsensitiveLeaves.size === 0)
|
|
637
|
+
return;
|
|
638
|
+
return {
|
|
639
|
+
exactPaths,
|
|
640
|
+
pathGlobs,
|
|
641
|
+
keyGlobs,
|
|
642
|
+
caseInsensitiveLeaves
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
function addPathGlobPattern(pattern, exactPaths, pathGlobs, caseInsensitiveLeaves) {
|
|
646
|
+
pathGlobs.push(globToRegExp(pattern, "."));
|
|
647
|
+
const leaf = pattern.match(/^\*\*\.([^.?*]+)$/);
|
|
648
|
+
if (leaf) {
|
|
649
|
+
exactPaths.add(leaf[1]);
|
|
650
|
+
caseInsensitiveLeaves.add(leaf[1].toLowerCase());
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
function matchesRedactPath(fullPath, leafKey, matchers) {
|
|
654
|
+
if (matchers.exactPaths.has(fullPath))
|
|
655
|
+
return true;
|
|
656
|
+
if (matchers.caseInsensitiveLeaves.has(leafKey.toLowerCase()))
|
|
657
|
+
return true;
|
|
658
|
+
for (const glob of matchers.pathGlobs) {
|
|
659
|
+
glob.lastIndex = 0;
|
|
660
|
+
if (glob.test(fullPath))
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
for (const glob of matchers.keyGlobs) {
|
|
664
|
+
glob.lastIndex = 0;
|
|
665
|
+
if (glob.test(leafKey))
|
|
666
|
+
return true;
|
|
667
|
+
}
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
function redactPathsInTree(obj, matchers, replacement, prefix = "") {
|
|
671
|
+
if (obj === null || obj === undefined)
|
|
672
|
+
return;
|
|
673
|
+
if (Array.isArray(obj)) {
|
|
674
|
+
for (let i = 0;i < obj.length; i++) {
|
|
675
|
+
const segment = String(i);
|
|
676
|
+
const fullPath = prefix ? `${prefix}.${segment}` : segment;
|
|
677
|
+
redactPathsInTree(obj[i], matchers, replacement, fullPath);
|
|
678
|
+
}
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
if (typeof obj === "object") {
|
|
682
|
+
const record = obj;
|
|
683
|
+
for (const key in record) {
|
|
684
|
+
const fullPath = prefix ? `${prefix}.${key}` : key;
|
|
685
|
+
if (matchesRedactPath(fullPath, key, matchers))
|
|
686
|
+
record[key] = replacement;
|
|
687
|
+
else
|
|
688
|
+
redactPathsInTree(record[key], matchers, replacement, fullPath);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
157
692
|
function resolveRedactConfig(input) {
|
|
158
693
|
if (input === undefined || input === false)
|
|
159
694
|
return;
|
|
160
695
|
if (input === true)
|
|
161
696
|
return { _maskers: allBuiltinMaskers() };
|
|
162
697
|
if (input.builtins === false)
|
|
163
|
-
return
|
|
698
|
+
return {
|
|
699
|
+
...input,
|
|
700
|
+
_pathMatchers: compileRedactPathMatchers(input.paths)
|
|
701
|
+
};
|
|
164
702
|
const maskers = Array.isArray(input.builtins) ? input.builtins.map((name) => builtinPatterns[name]).filter(Boolean).map((b) => [cloneRegex(b.pattern), b.mask]) : allBuiltinMaskers();
|
|
165
703
|
return {
|
|
166
704
|
...input,
|
|
167
|
-
_maskers: maskers
|
|
705
|
+
_maskers: maskers,
|
|
706
|
+
_pathMatchers: compileRedactPathMatchers(input.paths)
|
|
168
707
|
};
|
|
169
708
|
}
|
|
170
709
|
function allBuiltinMaskers() {
|
|
@@ -173,28 +712,39 @@ function allBuiltinMaskers() {
|
|
|
173
712
|
function cloneRegex(re) {
|
|
174
713
|
return new RegExp(re.source, re.flags);
|
|
175
714
|
}
|
|
715
|
+
function markGloballyRedacted(event) {
|
|
716
|
+
Object.defineProperty(event, globallyRedacted, {
|
|
717
|
+
value: true,
|
|
718
|
+
enumerable: false,
|
|
719
|
+
configurable: true
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
function isGloballyRedacted(event) {
|
|
723
|
+
return Reflect.has(event, globallyRedacted);
|
|
724
|
+
}
|
|
725
|
+
function cloneForRedaction(event) {
|
|
726
|
+
try {
|
|
727
|
+
return structuredClone(event);
|
|
728
|
+
} catch {
|
|
729
|
+
try {
|
|
730
|
+
return JSON.parse(JSON.stringify(event));
|
|
731
|
+
} catch {
|
|
732
|
+
console.warn("[cloneForRedaction] Shallow clone used \u2014 nested objects may be mutated by redactPath, redactPatterns, and applyMaskersToTree");
|
|
733
|
+
return { ...event };
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
176
737
|
function redactEvent(event, config) {
|
|
738
|
+
const clone = cloneForRedaction(event);
|
|
177
739
|
const replacement = config.replacement ?? DEFAULT_REPLACEMENT;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
740
|
+
const pathMatchers = config._pathMatchers ?? compileRedactPathMatchers(config.paths);
|
|
741
|
+
if (pathMatchers)
|
|
742
|
+
redactPathsInTree(clone, pathMatchers, replacement);
|
|
181
743
|
if (config._maskers?.length)
|
|
182
|
-
applyMaskersToTree(
|
|
744
|
+
applyMaskersToTree(clone, config._maskers);
|
|
183
745
|
if (config.patterns?.length)
|
|
184
|
-
redactPatterns(
|
|
185
|
-
|
|
186
|
-
function redactPath(obj, segments, replacement) {
|
|
187
|
-
let current = obj;
|
|
188
|
-
for (let i = 0;i < segments.length - 1; i++) {
|
|
189
|
-
if (current === null || current === undefined || typeof current !== "object")
|
|
190
|
-
return;
|
|
191
|
-
current = current[segments[i]];
|
|
192
|
-
}
|
|
193
|
-
if (current === null || current === undefined || typeof current !== "object")
|
|
194
|
-
return;
|
|
195
|
-
const leaf = segments[segments.length - 1];
|
|
196
|
-
if (leaf in current)
|
|
197
|
-
current[leaf] = replacement;
|
|
746
|
+
redactPatterns(clone, config.patterns, replacement);
|
|
747
|
+
return clone;
|
|
198
748
|
}
|
|
199
749
|
function redactPatterns(obj, patterns, replacement) {
|
|
200
750
|
if (obj === null || obj === undefined)
|
|
@@ -220,10 +770,8 @@ function redactPatterns(obj, patterns, replacement) {
|
|
|
220
770
|
}
|
|
221
771
|
function applyPatterns(value, patterns, replacement) {
|
|
222
772
|
let result = value;
|
|
223
|
-
for (const pattern of patterns)
|
|
224
|
-
pattern.lastIndex = 0;
|
|
773
|
+
for (const pattern of patterns)
|
|
225
774
|
result = result.replace(pattern, replacement);
|
|
226
|
-
}
|
|
227
775
|
return result;
|
|
228
776
|
}
|
|
229
777
|
function applyMaskersToTree(obj, maskers) {
|
|
@@ -250,10 +798,8 @@ function applyMaskersToTree(obj, maskers) {
|
|
|
250
798
|
}
|
|
251
799
|
function applyMaskers(value, maskers) {
|
|
252
800
|
let result = value;
|
|
253
|
-
for (const [pattern, mask] of maskers)
|
|
254
|
-
pattern.lastIndex = 0;
|
|
801
|
+
for (const [pattern, mask] of maskers)
|
|
255
802
|
result = result.replace(pattern, mask);
|
|
256
|
-
}
|
|
257
803
|
return result;
|
|
258
804
|
}
|
|
259
805
|
function logPluginError(name, hook, err) {
|
|
@@ -366,6 +912,9 @@ function createPluginRunner(plugins = []) {
|
|
|
366
912
|
function getEmptyPluginRunner() {
|
|
367
913
|
return emptyRunner;
|
|
368
914
|
}
|
|
915
|
+
function writePrettyStdout(text) {
|
|
916
|
+
(globalThis.__evlogNativeStdoutWrite ?? nativeStdoutWrite)?.(text);
|
|
917
|
+
}
|
|
369
918
|
function isPlainObject$1(val) {
|
|
370
919
|
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
371
920
|
}
|
|
@@ -390,6 +939,17 @@ function mergeInto(target, source) {
|
|
|
390
939
|
target[key] = sourceVal;
|
|
391
940
|
}
|
|
392
941
|
}
|
|
942
|
+
function isAiOnlyFieldUpdate(data) {
|
|
943
|
+
const keys = Object.keys(data);
|
|
944
|
+
return keys.length === 1 && keys[0] === "ai";
|
|
945
|
+
}
|
|
946
|
+
function markWideEventDrainStarted(event) {
|
|
947
|
+
if (!event)
|
|
948
|
+
return;
|
|
949
|
+
const state = pendingDrainState.get(event);
|
|
950
|
+
if (state)
|
|
951
|
+
state.drainStarted = true;
|
|
952
|
+
}
|
|
393
953
|
function initLogger(config = {}) {
|
|
394
954
|
globalEnabled = config.enabled ?? true;
|
|
395
955
|
const detected = detectEnvironment();
|
|
@@ -401,6 +961,7 @@ function initLogger(config = {}) {
|
|
|
401
961
|
region: config.env?.region ?? detected.region
|
|
402
962
|
};
|
|
403
963
|
globalPretty = config.pretty ?? isDev();
|
|
964
|
+
globalPrettyError = resolveDevTerminal(config).prettyError;
|
|
404
965
|
globalSampling = config.sampling ?? {};
|
|
405
966
|
globalStringify = config.stringify ?? true;
|
|
406
967
|
globalDrain = config.drain;
|
|
@@ -481,8 +1042,10 @@ function emitWideEvent(level, event, options = {}) {
|
|
|
481
1042
|
...event
|
|
482
1043
|
};
|
|
483
1044
|
finalizeAudit(formatted);
|
|
484
|
-
if (globalRedact)
|
|
485
|
-
redactEvent(formatted, globalRedact);
|
|
1045
|
+
if (globalRedact) {
|
|
1046
|
+
formatted = redactEvent(formatted, globalRedact);
|
|
1047
|
+
markGloballyRedacted(formatted);
|
|
1048
|
+
}
|
|
486
1049
|
if (!globalSilent)
|
|
487
1050
|
if (globalPretty)
|
|
488
1051
|
prettyPrintWideEvent(formatted);
|
|
@@ -763,11 +1326,34 @@ function buildAIEntries(ai) {
|
|
|
763
1326
|
});
|
|
764
1327
|
return entries;
|
|
765
1328
|
}
|
|
1329
|
+
function flushPrettyLines(lines) {
|
|
1330
|
+
if (lines.length === 0)
|
|
1331
|
+
return;
|
|
1332
|
+
const text = `${lines.join(`
|
|
1333
|
+
`)}
|
|
1334
|
+
`;
|
|
1335
|
+
if (nativeStdoutWrite && !isBrowser() && process.env.VITEST !== "true") {
|
|
1336
|
+
writePrettyStdout(text);
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
console.log(lines.join(`
|
|
1340
|
+
`));
|
|
1341
|
+
}
|
|
766
1342
|
function prettyPrintWideEvent(event) {
|
|
767
1343
|
const { timestamp, level, service, environment, version, ...rest } = event;
|
|
768
1344
|
const ts = typeof timestamp === "string" ? timestamp.slice(11, 23) : "";
|
|
769
1345
|
const levelLabel = typeof level === "string" ? level : "info";
|
|
770
1346
|
const browser = isBrowser();
|
|
1347
|
+
const lines = [];
|
|
1348
|
+
const writeLine = (...args) => {
|
|
1349
|
+
if (browser) {
|
|
1350
|
+
console.log(...args);
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
const [line] = args;
|
|
1354
|
+
if (typeof line === "string")
|
|
1355
|
+
lines.push(line);
|
|
1356
|
+
};
|
|
771
1357
|
const parts = [];
|
|
772
1358
|
const styles = [];
|
|
773
1359
|
if (browser) {
|
|
@@ -776,7 +1362,10 @@ function prettyPrintWideEvent(event) {
|
|
|
776
1362
|
styles.push(cssColors.dim, cssColors.reset, lc, cssColors.reset, cssColors.cyan, cssColors.reset);
|
|
777
1363
|
} else {
|
|
778
1364
|
const lc = getLevelColor(levelLabel);
|
|
779
|
-
|
|
1365
|
+
if (isDev())
|
|
1366
|
+
parts.push(`${lc}${levelLabel.toUpperCase()}${colors.reset} ${colors.cyan}[${service}]${colors.reset}`);
|
|
1367
|
+
else
|
|
1368
|
+
parts.push(`${colors.dim}${ts}${colors.reset} ${lc}${levelLabel.toUpperCase()}${colors.reset} ${colors.cyan}[${service}]${colors.reset}`);
|
|
780
1369
|
}
|
|
781
1370
|
if (rest.method && rest.path) {
|
|
782
1371
|
parts.push(browser ? ` ${escapeFormatString(String(rest.method))} ${escapeFormatString(String(rest.path))}` : ` ${rest.method} ${rest.path}`);
|
|
@@ -801,16 +1390,21 @@ function prettyPrintWideEvent(event) {
|
|
|
801
1390
|
parts.push(` ${colors.dim}in ${rest.duration}${colors.reset}`);
|
|
802
1391
|
delete rest.duration;
|
|
803
1392
|
}
|
|
804
|
-
|
|
1393
|
+
writeLine(parts.join(""), ...styles);
|
|
805
1394
|
const aiData = isPlainObject$1(rest.ai) ? rest.ai : undefined;
|
|
806
1395
|
if (aiData)
|
|
807
1396
|
delete rest.ai;
|
|
1397
|
+
const errorData = rest.error;
|
|
1398
|
+
if (errorData !== undefined)
|
|
1399
|
+
delete rest.error;
|
|
808
1400
|
const restEntries = Object.entries(rest).filter(([_, v]) => v !== undefined);
|
|
809
1401
|
const aiEntries = aiData ? buildAIEntries(aiData) : [];
|
|
810
|
-
const
|
|
1402
|
+
const errorEntries = errorData !== undefined ? buildErrorEntries(errorData, globalPrettyError) : [];
|
|
1403
|
+
const contextEntries = [...restEntries.map(([key, value]) => ({
|
|
811
1404
|
key,
|
|
812
1405
|
value: formatValue(value)
|
|
813
1406
|
})), ...aiEntries];
|
|
1407
|
+
const allEntries = errorEntries.length > 0 ? [...errorEntries, ...contextEntries] : contextEntries;
|
|
814
1408
|
for (let i = 0;i < allEntries.length; i++) {
|
|
815
1409
|
const entry = allEntries[i];
|
|
816
1410
|
if (!entry)
|
|
@@ -820,10 +1414,10 @@ function prettyPrintWideEvent(event) {
|
|
|
820
1414
|
const prefix = i === allEntries.length - 1 && !hasChildren ? "\u2514\u2500" : "\u251C\u2500";
|
|
821
1415
|
if (browser) {
|
|
822
1416
|
const val = entry.value ? ` ${escapeFormatString(entry.value)}` : "";
|
|
823
|
-
|
|
1417
|
+
writeLine(` %c${prefix}%c %c${escapeFormatString(entry.key)}:%c${val}`, cssColors.dim, cssColors.reset, cssColors.cyan, cssColors.reset);
|
|
824
1418
|
} else {
|
|
825
1419
|
const val = entry.value ? ` ${entry.value}` : "";
|
|
826
|
-
|
|
1420
|
+
writeLine(` ${colors.dim}${prefix}${colors.reset} ${colors.cyan}${entry.key}:${colors.reset}${val}`);
|
|
827
1421
|
}
|
|
828
1422
|
if (hasChildren && children) {
|
|
829
1423
|
const connector = i === allEntries.length - 1 ? " " : "\u2502";
|
|
@@ -831,14 +1425,26 @@ function prettyPrintWideEvent(event) {
|
|
|
831
1425
|
const child = children[j];
|
|
832
1426
|
if (child === undefined)
|
|
833
1427
|
continue;
|
|
1428
|
+
if (child === "__EVLOG_TREE_SPACER__") {
|
|
1429
|
+
writeLine(` ${colors.dim}${connector}${colors.reset}`);
|
|
1430
|
+
continue;
|
|
1431
|
+
}
|
|
834
1432
|
const childPrefix = j === children.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
1433
|
+
if (child === "") {
|
|
1434
|
+
writeLine("");
|
|
1435
|
+
continue;
|
|
1436
|
+
}
|
|
835
1437
|
if (browser)
|
|
836
|
-
|
|
1438
|
+
writeLine(` %c${connector} ${childPrefix}%c ${escapeFormatString(child)}`, cssColors.dim, cssColors.reset);
|
|
1439
|
+
else if (child.startsWith(" ") || child.startsWith("\x1B"))
|
|
1440
|
+
writeLine(` ${colors.dim}${connector}${colors.reset}${child}`);
|
|
837
1441
|
else
|
|
838
|
-
|
|
1442
|
+
writeLine(` ${colors.dim}${connector} ${childPrefix}${colors.reset} ${child}`);
|
|
839
1443
|
}
|
|
840
1444
|
}
|
|
841
1445
|
}
|
|
1446
|
+
if (!browser && lines.length > 0)
|
|
1447
|
+
flushPrettyLines(lines);
|
|
842
1448
|
}
|
|
843
1449
|
function createLogMethod(level) {
|
|
844
1450
|
return function logMethod(tagOrEvent, message) {
|
|
@@ -861,6 +1467,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
861
1467
|
let hasWarn = false;
|
|
862
1468
|
let manualLevel;
|
|
863
1469
|
let emitted = false;
|
|
1470
|
+
let pendingWideEvent = null;
|
|
864
1471
|
function addLog(level, message) {
|
|
865
1472
|
if (!Array.isArray(context.requestLogs))
|
|
866
1473
|
context.requestLogs = [];
|
|
@@ -893,7 +1500,13 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
893
1500
|
audit: auditMethod,
|
|
894
1501
|
set(data) {
|
|
895
1502
|
if (emitted) {
|
|
896
|
-
const
|
|
1503
|
+
const record = data;
|
|
1504
|
+
const pendingState = pendingWideEvent ? pendingDrainState.get(pendingWideEvent) : undefined;
|
|
1505
|
+
if (pendingWideEvent && pendingState && !pendingState.drainStarted && isAiOnlyFieldUpdate(record)) {
|
|
1506
|
+
mergeInto(pendingWideEvent, record);
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
const keys = Object.keys(record);
|
|
897
1510
|
warnPostEmit("log.set()", `Keys dropped: ${keys.length ? keys.join(", ") : "(empty)"}.`);
|
|
898
1511
|
return;
|
|
899
1512
|
}
|
|
@@ -918,7 +1531,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
918
1531
|
const errorObj = {
|
|
919
1532
|
name: err.name,
|
|
920
1533
|
message: err.message,
|
|
921
|
-
stack: err.stack
|
|
1534
|
+
stack: isDev() ? compactStackForStorage(err.stack) : err.stack
|
|
922
1535
|
};
|
|
923
1536
|
const errRecord = err;
|
|
924
1537
|
for (const k of [
|
|
@@ -933,6 +1546,18 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
933
1546
|
])
|
|
934
1547
|
if (k in err)
|
|
935
1548
|
errorObj[k] = errRecord[k];
|
|
1549
|
+
if (err instanceof EvlogError) {
|
|
1550
|
+
if (err.code)
|
|
1551
|
+
errorObj.code = err.code;
|
|
1552
|
+
if (err.why)
|
|
1553
|
+
errorObj.why = err.why;
|
|
1554
|
+
if (err.fix)
|
|
1555
|
+
errorObj.fix = err.fix;
|
|
1556
|
+
if (err.link)
|
|
1557
|
+
errorObj.link = err.link;
|
|
1558
|
+
if (err.status)
|
|
1559
|
+
errorObj.status = err.status;
|
|
1560
|
+
}
|
|
936
1561
|
if (isPlainObject$1(context.error))
|
|
937
1562
|
mergeInto(context.error, errorObj);
|
|
938
1563
|
else
|
|
@@ -983,6 +1608,7 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
983
1608
|
});
|
|
984
1609
|
if (!forceKeep && !shouldSample(level)) {
|
|
985
1610
|
emitted = true;
|
|
1611
|
+
pendingWideEvent = null;
|
|
986
1612
|
return null;
|
|
987
1613
|
}
|
|
988
1614
|
if (overrides) {
|
|
@@ -998,6 +1624,9 @@ function createLogger(initialContext = {}, internalOptions) {
|
|
|
998
1624
|
waitUntil
|
|
999
1625
|
});
|
|
1000
1626
|
emitted = true;
|
|
1627
|
+
pendingWideEvent = wide;
|
|
1628
|
+
if (wide)
|
|
1629
|
+
pendingDrainState.set(wide, { drainStarted: !deferDrain });
|
|
1001
1630
|
return wide;
|
|
1002
1631
|
},
|
|
1003
1632
|
getContext() {
|
|
@@ -1019,21 +1648,24 @@ function createRequestLogger(options = {}, internalOptions) {
|
|
|
1019
1648
|
waitUntil: internalOptions?.waitUntil ?? optionsWaitUntil
|
|
1020
1649
|
});
|
|
1021
1650
|
}
|
|
1022
|
-
function
|
|
1651
|
+
function isPlainObject2(value) {
|
|
1023
1652
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
1024
1653
|
return false;
|
|
1025
1654
|
if (Object.prototype.toString.call(value) !== "[object Object]")
|
|
1026
1655
|
return false;
|
|
1027
1656
|
return Object.getPrototypeOf(value) === Object.prototype || value.constructor === Object;
|
|
1028
1657
|
}
|
|
1029
|
-
function stableStringify(value) {
|
|
1658
|
+
function stableStringify(value, ancestors = /* @__PURE__ */ new WeakSet) {
|
|
1030
1659
|
if (value === null || typeof value !== "object")
|
|
1031
1660
|
return JSON.stringify(value);
|
|
1032
|
-
if (
|
|
1033
|
-
return
|
|
1034
|
-
if (!
|
|
1661
|
+
if (ancestors.has(value))
|
|
1662
|
+
return '"[Circular]"';
|
|
1663
|
+
if (!Array.isArray(value) && !isPlainObject2(value))
|
|
1035
1664
|
return JSON.stringify(value);
|
|
1036
|
-
|
|
1665
|
+
ancestors.add(value);
|
|
1666
|
+
const out = Array.isArray(value) ? `[${value.map((v) => stableStringify(v, ancestors)).join(",")}]` : `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stableStringify(value[k], ancestors)}`).join(",")}}`;
|
|
1667
|
+
ancestors.delete(value);
|
|
1668
|
+
return out;
|
|
1037
1669
|
}
|
|
1038
1670
|
function fnv1a32(input, seed) {
|
|
1039
1671
|
let h = seed >>> 0;
|
|
@@ -1098,11 +1730,16 @@ function finalizeAudit(event) {
|
|
|
1098
1730
|
const a = event.audit;
|
|
1099
1731
|
if (!a)
|
|
1100
1732
|
return;
|
|
1101
|
-
|
|
1733
|
+
const decorated = decorateAudit(a, String(event.timestamp));
|
|
1734
|
+
event.audit = decorated;
|
|
1735
|
+
_testCollector?.(decorated, event);
|
|
1102
1736
|
}
|
|
1103
|
-
var DEFAULT_REPLACEMENT = "[REDACTED]", builtinPatterns, emptyRunner, _tsDate, POST_EMIT_FORK_HINT = "For intentional background work tied to this request, use log.fork('label', fn) when your integration supports it (see https://evlog.dev).", globalEnv, globalPretty, globalSampling, globalStringify = true, globalDrain, globalRedact, globalEnabled = true, globalSilent = false, globalMinLevel = "debug", globalPluginRunner, _log, noopLogger;
|
|
1104
|
-
var
|
|
1737
|
+
var DEFAULT_REPLACEMENT = "[REDACTED]", builtinPatterns, globallyRedacted, emptyRunner, nativeStdoutWrite, _tsDate, POST_EMIT_FORK_HINT = "For intentional background work tied to this request, use log.fork('label', fn) when your integration supports it (see https://evlog.dev).", pendingDrainState, globalEnv, globalPretty, globalPrettyError, globalSampling, globalStringify = true, globalDrain, globalRedact, globalEnabled = true, globalSilent = false, globalMinLevel = "debug", globalPluginRunner, _log, noopLogger, _testCollector = null;
|
|
1738
|
+
var init_audit_CL0q7GJU = __esm(() => {
|
|
1105
1739
|
init_utils();
|
|
1740
|
+
init_pretty_error_THg0U0w9();
|
|
1741
|
+
init_dev_terminal_D4UaEm17();
|
|
1742
|
+
init_error();
|
|
1106
1743
|
builtinPatterns = {
|
|
1107
1744
|
creditCard: {
|
|
1108
1745
|
pattern: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,
|
|
@@ -1150,13 +1787,22 @@ var init_audit_BUI3af4w = __esm(() => {
|
|
|
1150
1787
|
}
|
|
1151
1788
|
}
|
|
1152
1789
|
};
|
|
1790
|
+
globallyRedacted = Symbol.for("evlog.globallyRedacted");
|
|
1153
1791
|
emptyRunner = createPluginRunner([]);
|
|
1792
|
+
nativeStdoutWrite = typeof process !== "undefined" && typeof process.stdout?.write === "function" ? process.stdout.write.bind(process.stdout) : undefined;
|
|
1154
1793
|
_tsDate = /* @__PURE__ */ new Date;
|
|
1794
|
+
pendingDrainState = /* @__PURE__ */ new WeakMap;
|
|
1155
1795
|
globalEnv = {
|
|
1156
1796
|
service: "app",
|
|
1157
1797
|
environment: "development"
|
|
1158
1798
|
};
|
|
1159
1799
|
globalPretty = isDev();
|
|
1800
|
+
globalPrettyError = {
|
|
1801
|
+
snippet: isDev(),
|
|
1802
|
+
stackDepth: 2,
|
|
1803
|
+
compact: isDev(),
|
|
1804
|
+
detail: "full"
|
|
1805
|
+
};
|
|
1160
1806
|
globalSampling = {};
|
|
1161
1807
|
globalPluginRunner = getEmptyPluginRunner();
|
|
1162
1808
|
_log = {
|
|
@@ -1183,7 +1829,12 @@ var init_audit_BUI3af4w = __esm(() => {
|
|
|
1183
1829
|
initLogger(__EVLOG_CONFIG__);
|
|
1184
1830
|
});
|
|
1185
1831
|
|
|
1186
|
-
// ../../node_modules/.bun/evlog@2.
|
|
1832
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/index.mjs
|
|
1833
|
+
var init_dist = __esm(() => {
|
|
1834
|
+
init_audit_CL0q7GJU();
|
|
1835
|
+
});
|
|
1836
|
+
|
|
1837
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/errors-DA0cyr8q.mjs
|
|
1187
1838
|
function extractErrorStatus(error) {
|
|
1188
1839
|
if (error === null || typeof error !== "object")
|
|
1189
1840
|
return 500;
|
|
@@ -1191,14 +1842,9 @@ function extractErrorStatus(error) {
|
|
|
1191
1842
|
const status = Number(raw);
|
|
1192
1843
|
return Number.isFinite(status) ? status : 500;
|
|
1193
1844
|
}
|
|
1194
|
-
var
|
|
1195
|
-
|
|
1196
|
-
// ../../node_modules/.bun/evlog@2.18.1+21e9b0bb4450b609/node_modules/evlog/dist/index.mjs
|
|
1197
|
-
var init_dist = __esm(() => {
|
|
1198
|
-
init_audit_BUI3af4w();
|
|
1199
|
-
});
|
|
1845
|
+
var init_errors_DA0cyr8q = () => {};
|
|
1200
1846
|
|
|
1201
|
-
// ../../node_modules/.bun/evlog@2.
|
|
1847
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/routes-4rMzRyTk.mjs
|
|
1202
1848
|
function shouldLog(path, include, exclude) {
|
|
1203
1849
|
if (exclude && exclude.length > 0) {
|
|
1204
1850
|
if (exclude.some((pattern) => matchesPattern(path, pattern)))
|
|
@@ -1215,11 +1861,91 @@ function getServiceForPath(path, routes) {
|
|
|
1215
1861
|
if (matchesPattern(path, pattern))
|
|
1216
1862
|
return config.service;
|
|
1217
1863
|
}
|
|
1218
|
-
var
|
|
1864
|
+
var init_routes_4rMzRyTk = __esm(() => {
|
|
1219
1865
|
init_utils();
|
|
1220
1866
|
});
|
|
1221
1867
|
|
|
1222
|
-
// ../../node_modules/.bun/evlog@2.
|
|
1868
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/streamResponse-CmQ3qUbF.mjs
|
|
1869
|
+
function shouldDeferEmitForResponse(response) {
|
|
1870
|
+
if (!response.body)
|
|
1871
|
+
return false;
|
|
1872
|
+
const contentType = (response.headers.get("content-type") ?? "").toLowerCase();
|
|
1873
|
+
if (contentType.includes("text/event-stream"))
|
|
1874
|
+
return true;
|
|
1875
|
+
if (contentType.includes("application/x-ndjson"))
|
|
1876
|
+
return true;
|
|
1877
|
+
if (response.headers.has("x-vercel-ai-ui-message-stream"))
|
|
1878
|
+
return true;
|
|
1879
|
+
if (response.headers.get("transfer-encoding")?.toLowerCase().includes("chunked"))
|
|
1880
|
+
return true;
|
|
1881
|
+
return false;
|
|
1882
|
+
}
|
|
1883
|
+
function toError(value) {
|
|
1884
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
1885
|
+
}
|
|
1886
|
+
function createObservedBody(body, onDone, onError) {
|
|
1887
|
+
if (body.locked) {
|
|
1888
|
+
Promise.resolve(onError(/* @__PURE__ */ new TypeError("stream is already locked"))).catch((err) => {
|
|
1889
|
+
console.error("[evlog] stream error handling failed:", err);
|
|
1890
|
+
});
|
|
1891
|
+
return null;
|
|
1892
|
+
}
|
|
1893
|
+
const reader = body.getReader();
|
|
1894
|
+
let settled = false;
|
|
1895
|
+
const settle = (fn) => {
|
|
1896
|
+
if (settled)
|
|
1897
|
+
return;
|
|
1898
|
+
settled = true;
|
|
1899
|
+
Promise.resolve(fn()).catch((err) => {
|
|
1900
|
+
console.error("[evlog] stream completion handling failed:", err);
|
|
1901
|
+
});
|
|
1902
|
+
};
|
|
1903
|
+
return new ReadableStream({
|
|
1904
|
+
async pull(controller) {
|
|
1905
|
+
try {
|
|
1906
|
+
const { done, value } = await reader.read();
|
|
1907
|
+
if (done) {
|
|
1908
|
+
settle(onDone);
|
|
1909
|
+
controller.close();
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1912
|
+
controller.enqueue(value);
|
|
1913
|
+
} catch (err) {
|
|
1914
|
+
settle(() => onError(err));
|
|
1915
|
+
controller.error(err);
|
|
1916
|
+
}
|
|
1917
|
+
},
|
|
1918
|
+
async cancel(reason) {
|
|
1919
|
+
try {
|
|
1920
|
+
await reader.cancel(reason);
|
|
1921
|
+
} finally {
|
|
1922
|
+
settle(onDone);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
1927
|
+
function bindStreamingResponseLifecycle(response, onComplete) {
|
|
1928
|
+
if (!response.body) {
|
|
1929
|
+
Promise.resolve(onComplete({ status: response.status })).catch((err) => {
|
|
1930
|
+
console.error("[evlog] stream completion handling failed:", err);
|
|
1931
|
+
});
|
|
1932
|
+
return response;
|
|
1933
|
+
}
|
|
1934
|
+
const body = createObservedBody(response.body, () => onComplete({ status: response.status }), (err) => onComplete({
|
|
1935
|
+
status: response.status,
|
|
1936
|
+
error: toError(err)
|
|
1937
|
+
}));
|
|
1938
|
+
if (!body)
|
|
1939
|
+
return response;
|
|
1940
|
+
return new Response(body, {
|
|
1941
|
+
status: response.status,
|
|
1942
|
+
statusText: response.statusText,
|
|
1943
|
+
headers: response.headers
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
var init_streamResponse_CmQ3qUbF = () => {};
|
|
1947
|
+
|
|
1948
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/fork-Di44utlp.mjs
|
|
1223
1949
|
function resolveMiddlewarePluginRunner(options) {
|
|
1224
1950
|
const global2 = getGlobalPluginRunner();
|
|
1225
1951
|
const local = options.plugins;
|
|
@@ -1242,11 +1968,17 @@ function resolveMiddlewarePluginRunner(options) {
|
|
|
1242
1968
|
});
|
|
1243
1969
|
return runner;
|
|
1244
1970
|
}
|
|
1971
|
+
function assignRedactedEvent(target, redacted) {
|
|
1972
|
+
for (const key of Object.keys(target))
|
|
1973
|
+
if (!(key in redacted))
|
|
1974
|
+
delete target[key];
|
|
1975
|
+
Object.assign(target, redacted);
|
|
1976
|
+
}
|
|
1245
1977
|
async function runEnrichAndDrain(emittedEvent, options, requestInfo, responseStatus, plugins) {
|
|
1246
1978
|
const runner = plugins ?? resolveMiddlewarePluginRunner(options);
|
|
1247
1979
|
const resolvedRedact = resolveRedactConfig(options.redact);
|
|
1248
|
-
if (resolvedRedact)
|
|
1249
|
-
redactEvent(emittedEvent, resolvedRedact);
|
|
1980
|
+
if (resolvedRedact && !isGloballyRedacted(emittedEvent))
|
|
1981
|
+
assignRedactedEvent(emittedEvent, redactEvent(emittedEvent, resolvedRedact));
|
|
1250
1982
|
if (options.enrich || runner.hasEnrich) {
|
|
1251
1983
|
const enrichCtx = {
|
|
1252
1984
|
event: emittedEvent,
|
|
@@ -1263,6 +1995,7 @@ async function runEnrichAndDrain(emittedEvent, options, requestInfo, responseSta
|
|
|
1263
1995
|
if (runner.hasEnrich)
|
|
1264
1996
|
await runner.runEnrich(enrichCtx);
|
|
1265
1997
|
}
|
|
1998
|
+
markWideEventDrainStarted(emittedEvent);
|
|
1266
1999
|
const drain = options.drain ?? getGlobalDrain();
|
|
1267
2000
|
const hasUserDrain = !!drain;
|
|
1268
2001
|
const hasPluginDrain = runner.hasDrain;
|
|
@@ -1316,22 +2049,38 @@ function createMiddlewareLogger(options) {
|
|
|
1316
2049
|
request: requestInfo,
|
|
1317
2050
|
headers: options.headers
|
|
1318
2051
|
});
|
|
1319
|
-
const finish =
|
|
2052
|
+
const finish = (opts) => {
|
|
2053
|
+
return performFinish(logger, opts);
|
|
2054
|
+
};
|
|
2055
|
+
const finishResponse = async (response, opts) => {
|
|
2056
|
+
const status = opts?.status ?? response.status;
|
|
2057
|
+
if (!shouldDeferEmitForResponse(response)) {
|
|
2058
|
+
await performFinish(logger, { status });
|
|
2059
|
+
return response;
|
|
2060
|
+
}
|
|
2061
|
+
return bindStreamingResponseLifecycle(response, async (meta) => {
|
|
2062
|
+
await performFinish(logger, {
|
|
2063
|
+
status: meta.status ?? status,
|
|
2064
|
+
error: meta.error
|
|
2065
|
+
});
|
|
2066
|
+
});
|
|
2067
|
+
};
|
|
2068
|
+
async function performFinish(requestLogger, opts) {
|
|
1320
2069
|
const { status, error } = opts ?? {};
|
|
1321
2070
|
if (error) {
|
|
1322
|
-
|
|
2071
|
+
requestLogger.error(error);
|
|
1323
2072
|
const errorStatus = extractErrorStatus(error);
|
|
1324
|
-
|
|
2073
|
+
requestLogger.set({ status: errorStatus });
|
|
1325
2074
|
} else if (status !== undefined)
|
|
1326
|
-
|
|
2075
|
+
requestLogger.set({ status });
|
|
1327
2076
|
const durationMs = Date.now() - startTime;
|
|
1328
|
-
const resolvedStatus = error ? extractErrorStatus(error) : status ??
|
|
2077
|
+
const resolvedStatus = error ? extractErrorStatus(error) : status ?? requestLogger.getContext().status;
|
|
1329
2078
|
const tailCtx = {
|
|
1330
2079
|
status: resolvedStatus,
|
|
1331
2080
|
duration: durationMs,
|
|
1332
2081
|
path,
|
|
1333
2082
|
method,
|
|
1334
|
-
context:
|
|
2083
|
+
context: requestLogger.getContext(),
|
|
1335
2084
|
shouldKeep: false
|
|
1336
2085
|
};
|
|
1337
2086
|
if (keep)
|
|
@@ -1339,12 +2088,12 @@ function createMiddlewareLogger(options) {
|
|
|
1339
2088
|
if (pluginRunner.hasKeep)
|
|
1340
2089
|
await pluginRunner.runKeep(tailCtx);
|
|
1341
2090
|
const forceKeep = tailCtx.shouldKeep || shouldKeep(tailCtx);
|
|
1342
|
-
const emittedEvent =
|
|
2091
|
+
const emittedEvent = requestLogger.emit({ _forceKeep: forceKeep });
|
|
1343
2092
|
if (emittedEvent && (options.enrich || options.drain || pluginRunner.hasEnrich || pluginRunner.hasDrain || getGlobalDrain()))
|
|
1344
2093
|
await runEnrichAndDrain(emittedEvent, options, requestInfo, resolvedStatus, pluginRunner);
|
|
1345
2094
|
if (pluginRunner.hasRequestLifecycle)
|
|
1346
2095
|
pluginRunner.runOnRequestFinish({
|
|
1347
|
-
logger,
|
|
2096
|
+
logger: requestLogger,
|
|
1348
2097
|
request: requestInfo,
|
|
1349
2098
|
headers: options.headers,
|
|
1350
2099
|
event: emittedEvent,
|
|
@@ -1353,10 +2102,11 @@ function createMiddlewareLogger(options) {
|
|
|
1353
2102
|
error
|
|
1354
2103
|
});
|
|
1355
2104
|
return emittedEvent;
|
|
1356
|
-
}
|
|
2105
|
+
}
|
|
1357
2106
|
return {
|
|
1358
2107
|
logger,
|
|
1359
2108
|
finish,
|
|
2109
|
+
finishResponse,
|
|
1360
2110
|
skipped: false
|
|
1361
2111
|
};
|
|
1362
2112
|
}
|
|
@@ -1417,10 +2167,11 @@ function forkBackgroundLogger(options) {
|
|
|
1417
2167
|
});
|
|
1418
2168
|
}
|
|
1419
2169
|
var noopResult, runnerCache;
|
|
1420
|
-
var
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
2170
|
+
var init_fork_Di44utlp = __esm(() => {
|
|
2171
|
+
init_audit_CL0q7GJU();
|
|
2172
|
+
init_errors_DA0cyr8q();
|
|
2173
|
+
init_routes_4rMzRyTk();
|
|
2174
|
+
init_streamResponse_CmQ3qUbF();
|
|
1424
2175
|
noopResult = {
|
|
1425
2176
|
logger: {
|
|
1426
2177
|
set() {},
|
|
@@ -1436,12 +2187,13 @@ var init_fork_Bga8x_X4 = __esm(() => {
|
|
|
1436
2187
|
}
|
|
1437
2188
|
},
|
|
1438
2189
|
finish: () => Promise.resolve(null),
|
|
2190
|
+
finishResponse: (response) => Promise.resolve(response),
|
|
1439
2191
|
skipped: true
|
|
1440
2192
|
};
|
|
1441
2193
|
runnerCache = /* @__PURE__ */ new WeakMap;
|
|
1442
2194
|
});
|
|
1443
2195
|
|
|
1444
|
-
// ../../node_modules/.bun/evlog@2.
|
|
2196
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/integration-2PpI-bCm.mjs
|
|
1445
2197
|
function normalizeHeaders(headers) {
|
|
1446
2198
|
if (!headers)
|
|
1447
2199
|
return;
|
|
@@ -1479,15 +2231,15 @@ function defineFrameworkIntegration(spec) {
|
|
|
1479
2231
|
};
|
|
1480
2232
|
} };
|
|
1481
2233
|
}
|
|
1482
|
-
var
|
|
1483
|
-
|
|
1484
|
-
|
|
2234
|
+
var init_integration_2PpI_bCm = __esm(() => {
|
|
2235
|
+
init_headers_VtmnWcfn();
|
|
2236
|
+
init_fork_Di44utlp();
|
|
1485
2237
|
});
|
|
1486
2238
|
|
|
1487
|
-
// ../../node_modules/.bun/evlog@2.
|
|
2239
|
+
// ../../node_modules/.bun/evlog@2.19.2+7724ce3de6b3bca4/node_modules/evlog/dist/elysia/index.mjs
|
|
1488
2240
|
import { AsyncLocalStorage } from "async_hooks";
|
|
1489
2241
|
import { Elysia } from "elysia";
|
|
1490
|
-
function
|
|
2242
|
+
function useLogger2() {
|
|
1491
2243
|
const logger = storage.getStore();
|
|
1492
2244
|
if (!logger || !activeLoggers.has(logger))
|
|
1493
2245
|
throw new Error("[evlog] useLogger() was called outside of an evlog plugin context. Make sure app.use(evlog()) is registered before your routes.");
|
|
@@ -1496,10 +2248,12 @@ function useLogger() {
|
|
|
1496
2248
|
function evlog(options = {}) {
|
|
1497
2249
|
const emitted = /* @__PURE__ */ new WeakSet;
|
|
1498
2250
|
const requestState = /* @__PURE__ */ new WeakMap;
|
|
1499
|
-
return new Elysia({ name: "evlog" }).
|
|
2251
|
+
return new Elysia({ name: "evlog" }).onRequest(({ request }) => {
|
|
2252
|
+
const url = new URL(request.url);
|
|
2253
|
+
const headers = request.headers.toJSON?.() ?? Object.fromEntries(request.headers.entries());
|
|
1500
2254
|
const ctx = {
|
|
1501
2255
|
request,
|
|
1502
|
-
path,
|
|
2256
|
+
path: url.pathname,
|
|
1503
2257
|
headers
|
|
1504
2258
|
};
|
|
1505
2259
|
const { logger, finish, skipped } = integration.start(ctx, options);
|
|
@@ -1509,7 +2263,8 @@ function evlog(options = {}) {
|
|
|
1509
2263
|
skipped,
|
|
1510
2264
|
logger
|
|
1511
2265
|
});
|
|
1512
|
-
|
|
2266
|
+
}).derive({ as: "global" }, ({ request }) => {
|
|
2267
|
+
return { log: requestState.get(request)?.logger };
|
|
1513
2268
|
}).onAfterResponse({ as: "global" }, async ({ request, set }) => {
|
|
1514
2269
|
const state = requestState.get(request);
|
|
1515
2270
|
if (!state || state.skipped || emitted.has(request))
|
|
@@ -1532,8 +2287,8 @@ function evlog(options = {}) {
|
|
|
1532
2287
|
}
|
|
1533
2288
|
var storage, activeLoggers, integration;
|
|
1534
2289
|
var init_elysia = __esm(() => {
|
|
1535
|
-
|
|
1536
|
-
|
|
2290
|
+
init_fork_Di44utlp();
|
|
2291
|
+
init_integration_2PpI_bCm();
|
|
1537
2292
|
storage = new AsyncLocalStorage;
|
|
1538
2293
|
activeLoggers = /* @__PURE__ */ new WeakSet;
|
|
1539
2294
|
integration = defineFrameworkIntegration({
|
|
@@ -1564,9 +2319,9 @@ var init_elysia = __esm(() => {
|
|
|
1564
2319
|
|
|
1565
2320
|
// src/server/context-logger.ts
|
|
1566
2321
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
1567
|
-
function
|
|
2322
|
+
function useLogger3() {
|
|
1568
2323
|
try {
|
|
1569
|
-
return
|
|
2324
|
+
return useLogger2();
|
|
1570
2325
|
} catch {
|
|
1571
2326
|
return syntheticRenderStorage.getStore() ?? noopLogger2;
|
|
1572
2327
|
}
|
|
@@ -2019,6 +2774,144 @@ var init_not_found = __esm(() => {
|
|
|
2019
2774
|
};
|
|
2020
2775
|
});
|
|
2021
2776
|
|
|
2777
|
+
// src/shared/search-params.ts
|
|
2778
|
+
function routeSegmentSpecificity(segment) {
|
|
2779
|
+
if (segment === "*") {
|
|
2780
|
+
return 1;
|
|
2781
|
+
}
|
|
2782
|
+
if (segment.startsWith(":")) {
|
|
2783
|
+
return 2;
|
|
2784
|
+
}
|
|
2785
|
+
return 3;
|
|
2786
|
+
}
|
|
2787
|
+
function compareSearchRouteSpecificity(a, b) {
|
|
2788
|
+
const aSegments = a.split("/").filter((segment) => segment.length > 0);
|
|
2789
|
+
const bSegments = b.split("/").filter((segment) => segment.length > 0);
|
|
2790
|
+
const length = Math.max(aSegments.length, bSegments.length);
|
|
2791
|
+
for (let i = 0;i < length; i++) {
|
|
2792
|
+
const aSegment = aSegments[i];
|
|
2793
|
+
const bSegment = bSegments[i];
|
|
2794
|
+
if (aSegment === undefined) {
|
|
2795
|
+
return -1;
|
|
2796
|
+
}
|
|
2797
|
+
if (bSegment === undefined) {
|
|
2798
|
+
return 1;
|
|
2799
|
+
}
|
|
2800
|
+
const diff = routeSegmentSpecificity(aSegment) - routeSegmentSpecificity(bSegment);
|
|
2801
|
+
if (diff !== 0) {
|
|
2802
|
+
return diff;
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
return 0;
|
|
2806
|
+
}
|
|
2807
|
+
function isObject(value) {
|
|
2808
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
2809
|
+
}
|
|
2810
|
+
function arraysDeepEqual(a, b) {
|
|
2811
|
+
if (a.length !== b.length) {
|
|
2812
|
+
return false;
|
|
2813
|
+
}
|
|
2814
|
+
for (let i = 0;i < a.length; i++) {
|
|
2815
|
+
if (!deepEqual(a[i], b[i])) {
|
|
2816
|
+
return false;
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
return true;
|
|
2820
|
+
}
|
|
2821
|
+
function objectsDeepEqual(a, b) {
|
|
2822
|
+
const aKeys = Object.keys(a);
|
|
2823
|
+
if (aKeys.length !== Object.keys(b).length) {
|
|
2824
|
+
return false;
|
|
2825
|
+
}
|
|
2826
|
+
for (const key of aKeys) {
|
|
2827
|
+
if (!(Object.hasOwn(b, key) && deepEqual(a[key], b[key]))) {
|
|
2828
|
+
return false;
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
return true;
|
|
2832
|
+
}
|
|
2833
|
+
function deepEqual(a, b) {
|
|
2834
|
+
if (Object.is(a, b)) {
|
|
2835
|
+
return true;
|
|
2836
|
+
}
|
|
2837
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
2838
|
+
return arraysDeepEqual(a, b);
|
|
2839
|
+
}
|
|
2840
|
+
if (isObject(a) && isObject(b)) {
|
|
2841
|
+
return objectsDeepEqual(a, b);
|
|
2842
|
+
}
|
|
2843
|
+
return false;
|
|
2844
|
+
}
|
|
2845
|
+
function stripSearchDefaults(search, defaults) {
|
|
2846
|
+
if (!defaults) {
|
|
2847
|
+
return search;
|
|
2848
|
+
}
|
|
2849
|
+
const stripped = {};
|
|
2850
|
+
for (const [key, value] of Object.entries(search)) {
|
|
2851
|
+
if (Object.hasOwn(defaults, key) && deepEqual(value, defaults[key])) {
|
|
2852
|
+
continue;
|
|
2853
|
+
}
|
|
2854
|
+
stripped[key] = value;
|
|
2855
|
+
}
|
|
2856
|
+
return stripped;
|
|
2857
|
+
}
|
|
2858
|
+
function appendSearchParamValue(params, key, value) {
|
|
2859
|
+
if (value == null) {
|
|
2860
|
+
return;
|
|
2861
|
+
}
|
|
2862
|
+
if (Array.isArray(value)) {
|
|
2863
|
+
for (const item of value) {
|
|
2864
|
+
if (item != null) {
|
|
2865
|
+
params.append(key, typeof item === "object" ? JSON.stringify(item) : String(item));
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
return;
|
|
2869
|
+
}
|
|
2870
|
+
params.set(key, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
2871
|
+
}
|
|
2872
|
+
function buildSearchParams(search, defaults) {
|
|
2873
|
+
const params = new URLSearchParams;
|
|
2874
|
+
for (const [key, value] of Object.entries(stripSearchDefaults(search, defaults))) {
|
|
2875
|
+
appendSearchParamValue(params, key, value);
|
|
2876
|
+
}
|
|
2877
|
+
return params;
|
|
2878
|
+
}
|
|
2879
|
+
function collectSearchDefaults(schema) {
|
|
2880
|
+
if (!(isObject(schema) && isObject(schema.properties))) {
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
const defaults = {};
|
|
2884
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
2885
|
+
if (isObject(value) && Object.hasOwn(value, "default") && value.default != null) {
|
|
2886
|
+
defaults[key] = value.default;
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
return Object.keys(defaults).length > 0 ? defaults : undefined;
|
|
2890
|
+
}
|
|
2891
|
+
function findSearchDefaults(pathname, routes) {
|
|
2892
|
+
let match;
|
|
2893
|
+
for (const route of routes) {
|
|
2894
|
+
if (!route.regex.test(pathname)) {
|
|
2895
|
+
continue;
|
|
2896
|
+
}
|
|
2897
|
+
if (!match || compareSearchRouteSpecificity(route.pattern, match.pattern) > 0) {
|
|
2898
|
+
match = route;
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
return match?.searchDefaults;
|
|
2902
|
+
}
|
|
2903
|
+
function findSearchDefaultsForRouteTarget(to, routes) {
|
|
2904
|
+
if (to.startsWith("http://") || to.startsWith("https://") || to.startsWith("//")) {
|
|
2905
|
+
return;
|
|
2906
|
+
}
|
|
2907
|
+
try {
|
|
2908
|
+
const pathname = new URL(to, "http://furin.local").pathname;
|
|
2909
|
+
return findSearchDefaults(pathname, routes);
|
|
2910
|
+
} catch {
|
|
2911
|
+
return;
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2022
2915
|
// src/client/router/context.ts
|
|
2023
2916
|
import { createContext, useContext } from "react";
|
|
2024
2917
|
function useRouter() {
|
|
@@ -2031,6 +2924,8 @@ var init_context = __esm(() => {
|
|
|
2031
2924
|
CLIENT_FALLBACK_ROUTER = {
|
|
2032
2925
|
basePath: "",
|
|
2033
2926
|
currentHref: "/",
|
|
2927
|
+
search: {},
|
|
2928
|
+
searchRoutes: [],
|
|
2034
2929
|
navigate: (href, _opts) => {
|
|
2035
2930
|
window.location.href = href;
|
|
2036
2931
|
return Promise.resolve();
|
|
@@ -2049,15 +2944,10 @@ var init_context = __esm(() => {
|
|
|
2049
2944
|
});
|
|
2050
2945
|
|
|
2051
2946
|
// src/client/router/link-utils.ts
|
|
2052
|
-
function buildHref(to, search, hash) {
|
|
2947
|
+
function buildHref(to, search, hash, searchDefaults) {
|
|
2053
2948
|
let url = to;
|
|
2054
2949
|
if (search && Object.keys(search).length > 0) {
|
|
2055
|
-
const params =
|
|
2056
|
-
for (const [k, v] of Object.entries(search)) {
|
|
2057
|
-
if (v != null) {
|
|
2058
|
-
params.set(k, String(v));
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2950
|
+
const params = buildSearchParams(search, searchDefaults);
|
|
2061
2951
|
const qs = params.toString();
|
|
2062
2952
|
if (qs) {
|
|
2063
2953
|
url += `?${qs}`;
|
|
@@ -2078,10 +2968,72 @@ function normalizeHref(href) {
|
|
|
2078
2968
|
}
|
|
2079
2969
|
var init_link_utils = () => {};
|
|
2080
2970
|
|
|
2971
|
+
// src/client/router/search-store.ts
|
|
2972
|
+
import { createContext as createContext2 } from "react";
|
|
2973
|
+
function searchSnapshotChanged(a, b) {
|
|
2974
|
+
return a.currentHref !== b.currentHref || a.navigate !== b.navigate || a.search !== b.search || a.searchRoutes !== b.searchRoutes;
|
|
2975
|
+
}
|
|
2976
|
+
function createSearchStore(initialSnapshot) {
|
|
2977
|
+
let snapshot = initialSnapshot;
|
|
2978
|
+
let version = 0;
|
|
2979
|
+
let flushedVersion = 0;
|
|
2980
|
+
const listeners = new Set;
|
|
2981
|
+
return {
|
|
2982
|
+
flush: () => {
|
|
2983
|
+
if (flushedVersion === version) {
|
|
2984
|
+
return;
|
|
2985
|
+
}
|
|
2986
|
+
flushedVersion = version;
|
|
2987
|
+
for (const listener of [...listeners]) {
|
|
2988
|
+
listener();
|
|
2989
|
+
}
|
|
2990
|
+
},
|
|
2991
|
+
getServerSnapshot: () => snapshot,
|
|
2992
|
+
getSnapshot: () => snapshot,
|
|
2993
|
+
setSnapshot: (next) => {
|
|
2994
|
+
if (!searchSnapshotChanged(snapshot, next)) {
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
snapshot = next;
|
|
2998
|
+
version++;
|
|
2999
|
+
},
|
|
3000
|
+
subscribe: (listener) => {
|
|
3001
|
+
listeners.add(listener);
|
|
3002
|
+
return () => {
|
|
3003
|
+
listeners.delete(listener);
|
|
3004
|
+
};
|
|
3005
|
+
}
|
|
3006
|
+
};
|
|
3007
|
+
}
|
|
3008
|
+
function searchSnapshotFromRouterContext(context) {
|
|
3009
|
+
return {
|
|
3010
|
+
currentHref: context.currentHref,
|
|
3011
|
+
navigate: context.navigate,
|
|
3012
|
+
search: context.search,
|
|
3013
|
+
searchRoutes: context.searchRoutes
|
|
3014
|
+
};
|
|
3015
|
+
}
|
|
3016
|
+
var FALLBACK_SEARCH_STORE, SearchStoreContext;
|
|
3017
|
+
var init_search_store = __esm(() => {
|
|
3018
|
+
FALLBACK_SEARCH_STORE = createSearchStore({
|
|
3019
|
+
currentHref: "/",
|
|
3020
|
+
navigate: (href, _opts) => {
|
|
3021
|
+
if (typeof window !== "undefined") {
|
|
3022
|
+
window.location.href = href;
|
|
3023
|
+
}
|
|
3024
|
+
return Promise.resolve();
|
|
3025
|
+
},
|
|
3026
|
+
search: {},
|
|
3027
|
+
searchRoutes: []
|
|
3028
|
+
});
|
|
3029
|
+
SearchStoreContext = createContext2(null);
|
|
3030
|
+
});
|
|
3031
|
+
|
|
2081
3032
|
// src/client/router/index.ts
|
|
2082
3033
|
var init_router = __esm(() => {
|
|
2083
3034
|
init_context();
|
|
2084
3035
|
init_link_utils();
|
|
3036
|
+
init_search_store();
|
|
2085
3037
|
});
|
|
2086
3038
|
|
|
2087
3039
|
// ../../node_modules/.bun/seroval@1.5.4/node_modules/seroval/dist/esm/development/index.mjs
|
|
@@ -2544,7 +3496,7 @@ async function parseBigIntTypedArray(ctx, depth, id, current) {
|
|
|
2544
3496
|
async function parseDataView(ctx, depth, id, current) {
|
|
2545
3497
|
return createDataViewNode(id, current, await parseAsync(ctx, depth, current.buffer));
|
|
2546
3498
|
}
|
|
2547
|
-
async function
|
|
3499
|
+
async function parseError2(ctx, depth, id, current) {
|
|
2548
3500
|
const options = getErrorOptions(current, ctx.base.features);
|
|
2549
3501
|
return createErrorNode(id, current, options ? await parseProperties(ctx, depth, options) : NIL);
|
|
2550
3502
|
}
|
|
@@ -2664,7 +3616,7 @@ async function parseObjectAsync(ctx, depth, id, current) {
|
|
|
2664
3616
|
case SyntaxError:
|
|
2665
3617
|
case TypeError:
|
|
2666
3618
|
case URIError:
|
|
2667
|
-
return
|
|
3619
|
+
return parseError2(ctx, depth, id, current);
|
|
2668
3620
|
case Number:
|
|
2669
3621
|
case Boolean:
|
|
2670
3622
|
case String:
|
|
@@ -2711,7 +3663,7 @@ async function parseObjectAsync(ctx, depth, id, current) {
|
|
|
2711
3663
|
return parseAggregateError(ctx, depth, id, current);
|
|
2712
3664
|
}
|
|
2713
3665
|
if (current instanceof Error) {
|
|
2714
|
-
return
|
|
3666
|
+
return parseError2(ctx, depth, id, current);
|
|
2715
3667
|
}
|
|
2716
3668
|
if (SYM_ITERATOR in current || SYM_ASYNC_ITERATOR in current) {
|
|
2717
3669
|
return parsePlainObject(ctx, depth, id, current, !!currentClass);
|
|
@@ -2847,7 +3799,7 @@ function parseBigIntTypedArray2(ctx, depth, id, current) {
|
|
|
2847
3799
|
function parseDataView2(ctx, depth, id, current) {
|
|
2848
3800
|
return createDataViewNode(id, current, parseSOS(ctx, depth, current.buffer));
|
|
2849
3801
|
}
|
|
2850
|
-
function
|
|
3802
|
+
function parseError22(ctx, depth, id, current) {
|
|
2851
3803
|
const options = getErrorOptions(current, ctx.base.features);
|
|
2852
3804
|
return createErrorNode(id, current, options ? parseProperties2(ctx, depth, options) : NIL);
|
|
2853
3805
|
}
|
|
@@ -2990,7 +3942,7 @@ function parseObjectPhase2(ctx, depth, id, current, currentClass) {
|
|
|
2990
3942
|
case SyntaxError:
|
|
2991
3943
|
case TypeError:
|
|
2992
3944
|
case URIError:
|
|
2993
|
-
return
|
|
3945
|
+
return parseError22(ctx, depth, id, current);
|
|
2994
3946
|
case Number:
|
|
2995
3947
|
case Boolean:
|
|
2996
3948
|
case String:
|
|
@@ -3037,7 +3989,7 @@ function parseObjectPhase2(ctx, depth, id, current, currentClass) {
|
|
|
3037
3989
|
return parseAggregateError2(ctx, depth, id, current);
|
|
3038
3990
|
}
|
|
3039
3991
|
if (current instanceof Error) {
|
|
3040
|
-
return
|
|
3992
|
+
return parseError22(ctx, depth, id, current);
|
|
3041
3993
|
}
|
|
3042
3994
|
if (SYM_ITERATOR in current || SYM_ASYNC_ITERATOR in current) {
|
|
3043
3995
|
return parsePlainObject2(ctx, depth, id, current, !!currentClass);
|
|
@@ -3548,8 +4500,9 @@ function computeLinkView({
|
|
|
3548
4500
|
activeProps,
|
|
3549
4501
|
inactiveProps
|
|
3550
4502
|
}, router2) {
|
|
3551
|
-
const
|
|
3552
|
-
const
|
|
4503
|
+
const searchDefaults = findSearchDefaultsForRouteTarget(to, router2.searchRoutes);
|
|
4504
|
+
const logicalHref = buildHref(to, search, hash, searchDefaults);
|
|
4505
|
+
const logicalHrefWithoutHash = buildHref(to, search, undefined, searchDefaults);
|
|
3553
4506
|
const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
|
|
3554
4507
|
const href = isAbsolute ? logicalHref : router2.basePath + logicalHref;
|
|
3555
4508
|
const isActive = !isAbsolute && router2.currentHref === normalizeHref(logicalHrefWithoutHash);
|
|
@@ -3727,6 +4680,8 @@ var init_link = __esm(() => {
|
|
|
3727
4680
|
SSR_FALLBACK_ROUTER = {
|
|
3728
4681
|
basePath: "",
|
|
3729
4682
|
currentHref: "/",
|
|
4683
|
+
search: {},
|
|
4684
|
+
searchRoutes: [],
|
|
3730
4685
|
navigate: (_href, _opts) => Promise.resolve(),
|
|
3731
4686
|
prefetch: (_href, _opts) => {},
|
|
3732
4687
|
invalidatePrefetch: (_path, _type) => {},
|
|
@@ -4193,6 +5148,28 @@ var init_element = __esm(() => {
|
|
|
4193
5148
|
init_default_screens();
|
|
4194
5149
|
});
|
|
4195
5150
|
|
|
5151
|
+
// src/server/sync/config.ts
|
|
5152
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
|
|
5153
|
+
function resolveSyncStreamPath(sync) {
|
|
5154
|
+
if (!sync) {
|
|
5155
|
+
return;
|
|
5156
|
+
}
|
|
5157
|
+
if (sync === true) {
|
|
5158
|
+
return SYNC_STREAM_DEFAULT_PATH;
|
|
5159
|
+
}
|
|
5160
|
+
return sync.streamPath ?? SYNC_STREAM_DEFAULT_PATH;
|
|
5161
|
+
}
|
|
5162
|
+
function getSyncStreamPath() {
|
|
5163
|
+
return requestSyncStreamPath.getStore();
|
|
5164
|
+
}
|
|
5165
|
+
function runWithSyncStreamPath(path, fn) {
|
|
5166
|
+
return requestSyncStreamPath.run(path, fn);
|
|
5167
|
+
}
|
|
5168
|
+
var SYNC_STREAM_DEFAULT_PATH = "/_furin/sync", requestSyncStreamPath;
|
|
5169
|
+
var init_config = __esm(() => {
|
|
5170
|
+
requestSyncStreamPath = new AsyncLocalStorage4;
|
|
5171
|
+
});
|
|
5172
|
+
|
|
4196
5173
|
// src/server/render/shell.ts
|
|
4197
5174
|
function extractTitle(meta) {
|
|
4198
5175
|
if (!meta) {
|
|
@@ -4356,19 +5333,39 @@ function splitTemplate(template) {
|
|
|
4356
5333
|
function assembleHTML(template, headData, reactHtml, data) {
|
|
4357
5334
|
const { headPre, bodyPre, bodyPost } = splitTemplate(template);
|
|
4358
5335
|
const dataScript = data ? `<script id="__FURIN_DATA__" type="application/json">${safeJson(data)}</script>` : "";
|
|
5336
|
+
const syncScript = buildSyncRuntimeScript();
|
|
5337
|
+
const runtimeScripts = `${syncScript}${dataScript}`;
|
|
4359
5338
|
let injectedBodyPost = bodyPost;
|
|
4360
|
-
if (
|
|
4361
|
-
injectedBodyPost = bodyPost.includes("</body>") ? bodyPost.replace("</body>", `${
|
|
5339
|
+
if (runtimeScripts) {
|
|
5340
|
+
injectedBodyPost = bodyPost.includes("</body>") ? bodyPost.replace("</body>", `${runtimeScripts}</body>`) : bodyPost + runtimeScripts;
|
|
4362
5341
|
}
|
|
4363
5342
|
return headPre + headData + bodyPre + reactHtml + injectedBodyPost;
|
|
4364
5343
|
}
|
|
5344
|
+
function buildSyncRuntimeScript() {
|
|
5345
|
+
const syncStreamPath = getSyncStreamPath();
|
|
5346
|
+
if (!syncStreamPath) {
|
|
5347
|
+
return "";
|
|
5348
|
+
}
|
|
5349
|
+
return `<script id="__FURIN_SYNC__" type="application/json">${safeJson({ stream: syncStreamPath })}</script>`;
|
|
5350
|
+
}
|
|
5351
|
+
function injectSyncRuntimeScript(html) {
|
|
5352
|
+
if (html.includes('id="__FURIN_SYNC__"')) {
|
|
5353
|
+
return html;
|
|
5354
|
+
}
|
|
5355
|
+
const syncScript = buildSyncRuntimeScript();
|
|
5356
|
+
if (!syncScript) {
|
|
5357
|
+
return html;
|
|
5358
|
+
}
|
|
5359
|
+
return html.includes("</body>") ? html.replace("</body>", `${syncScript}</body>`) : html + syncScript;
|
|
5360
|
+
}
|
|
4365
5361
|
var FURIN_DEFERRED_GLOBAL = "__FURIN_DEFERRED__";
|
|
4366
5362
|
var init_assemble = __esm(() => {
|
|
5363
|
+
init_config();
|
|
4367
5364
|
init_shell();
|
|
4368
5365
|
});
|
|
4369
5366
|
|
|
4370
5367
|
// src/shared/await.tsx
|
|
4371
|
-
import { Component as Component2, createContext as
|
|
5368
|
+
import { Component as Component2, createContext as createContext3, createElement as createElement2, use, useMemo } from "react";
|
|
4372
5369
|
function useAsyncError() {
|
|
4373
5370
|
return use(AsyncErrorContext);
|
|
4374
5371
|
}
|
|
@@ -4400,8 +5397,8 @@ function AwaitInner({ resolve, children }) {
|
|
|
4400
5397
|
}
|
|
4401
5398
|
var AsyncErrorContext, AwaitValueContext, AsyncErrorBoundary;
|
|
4402
5399
|
var init_await = __esm(() => {
|
|
4403
|
-
AsyncErrorContext =
|
|
4404
|
-
AwaitValueContext =
|
|
5400
|
+
AsyncErrorContext = createContext3(undefined);
|
|
5401
|
+
AwaitValueContext = createContext3(undefined);
|
|
4405
5402
|
AsyncErrorBoundary = class AsyncErrorBoundary extends Component2 {
|
|
4406
5403
|
constructor(props) {
|
|
4407
5404
|
super(props);
|
|
@@ -4534,7 +5531,7 @@ async function serializeDeferredRejection(err) {
|
|
|
4534
5531
|
}
|
|
4535
5532
|
async function runLoaders(route, ctx) {
|
|
4536
5533
|
try {
|
|
4537
|
-
const ctxRecord = { ...ctx, log:
|
|
5534
|
+
const ctxRecord = { ...ctx, log: useLogger3() };
|
|
4538
5535
|
const loaderMap = new Map;
|
|
4539
5536
|
let accumulatedParentPromise = Promise.resolve({});
|
|
4540
5537
|
for (const r of route.routeChain) {
|
|
@@ -4639,7 +5636,7 @@ var init_template = () => {};
|
|
|
4639
5636
|
import { createElement as createElement3 } from "react";
|
|
4640
5637
|
import { renderToReadableStream } from "react-dom/server";
|
|
4641
5638
|
function withSSRRouterContext(element, contextValue) {
|
|
4642
|
-
return createElement3(RouterContext.Provider, { value: contextValue }, element);
|
|
5639
|
+
return createElement3(SearchStoreContext.Provider, { value: createSearchStore(searchSnapshotFromRouterContext(contextValue)) }, createElement3(RouterContext.Provider, { value: contextValue }, element));
|
|
4643
5640
|
}
|
|
4644
5641
|
async function renderElementWithShellFallback(element, errorComponent, ssrContext) {
|
|
4645
5642
|
try {
|
|
@@ -4660,6 +5657,11 @@ function assertDeferredModeAllowed(route, deferredPromises) {
|
|
|
4660
5657
|
throw new Error(`[furin] page "${route.pattern}" returned defer() but the route is rendered in "${route.mode}" mode. ` + "defer() streams data progressively and is only supported in SSR. " + "Return the data directly (await it inside the loader) or switch the route to SSR mode.");
|
|
4661
5658
|
}
|
|
4662
5659
|
}
|
|
5660
|
+
function currentHrefFromContext(ctx) {
|
|
5661
|
+
const pathUrl = new URL(ctx.path, "http://furin.local");
|
|
5662
|
+
const requestUrl = new URL(ctx.request.url);
|
|
5663
|
+
return normalizeHref(pathUrl.pathname) + (pathUrl.search || requestUrl.search);
|
|
5664
|
+
}
|
|
4663
5665
|
function buildSuccessRender(route, root, componentProps, throwOnFailure) {
|
|
4664
5666
|
try {
|
|
4665
5667
|
const headData = buildHeadInjection(route.page?.head?.(componentProps));
|
|
@@ -4674,7 +5676,7 @@ function buildSuccessRender(route, root, componentProps, throwOnFailure) {
|
|
|
4674
5676
|
return { element, headData: "", errorDigest, status: 500 };
|
|
4675
5677
|
}
|
|
4676
5678
|
}
|
|
4677
|
-
async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult) {
|
|
5679
|
+
async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult, searchRoutes) {
|
|
4678
5680
|
const loaderStart = Date.now();
|
|
4679
5681
|
const loaderResult = precomputedLoaderResult ?? await runLoaders(route, ctx);
|
|
4680
5682
|
const loader_ms = Date.now() - loaderStart;
|
|
@@ -4722,7 +5724,9 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4722
5724
|
}
|
|
4723
5725
|
const ssrContext = {
|
|
4724
5726
|
basePath: basePath ?? "",
|
|
4725
|
-
currentHref:
|
|
5727
|
+
currentHref: currentHrefFromContext(ctx),
|
|
5728
|
+
search: ctx.query ?? {},
|
|
5729
|
+
searchRoutes: searchRoutes ?? [],
|
|
4726
5730
|
navigate: (_href, _opts) => Promise.resolve(),
|
|
4727
5731
|
prefetch: (_href, _opts) => {},
|
|
4728
5732
|
invalidatePrefetch: (_path, _type) => {},
|
|
@@ -4748,7 +5752,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
|
|
|
4748
5752
|
template
|
|
4749
5753
|
};
|
|
4750
5754
|
}
|
|
4751
|
-
function renderForPath(route, params, root, origin, mode, basePath) {
|
|
5755
|
+
function renderForPath(route, params, root, origin, mode, basePath, searchRoutes) {
|
|
4752
5756
|
return runInSyntheticRenderScope(async () => {
|
|
4753
5757
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
4754
5758
|
const ctx = {
|
|
@@ -4761,11 +5765,11 @@ function renderForPath(route, params, root, origin, mode, basePath) {
|
|
|
4761
5765
|
set: { headers: {} },
|
|
4762
5766
|
path: resolvedPath
|
|
4763
5767
|
};
|
|
4764
|
-
const prepared = await prepareRender(route, ctx, root, basePath, true, undefined);
|
|
5768
|
+
const prepared = await prepareRender(route, ctx, root, basePath, true, undefined, searchRoutes);
|
|
4765
5769
|
if (prepared instanceof Response) {
|
|
4766
5770
|
return prepared;
|
|
4767
5771
|
}
|
|
4768
|
-
|
|
5772
|
+
useLogger3().set({
|
|
4769
5773
|
furin: {
|
|
4770
5774
|
render: mode,
|
|
4771
5775
|
route: route.pattern,
|
|
@@ -4795,12 +5799,12 @@ async function serializeLoaderDataNdjson(syncData, deferredPromises) {
|
|
|
4795
5799
|
return `${JSON.stringify(serialized)}
|
|
4796
5800
|
`;
|
|
4797
5801
|
}
|
|
4798
|
-
async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
4799
|
-
const prepared = await prepareRender(route, ctx, root, undefined, false, precomputedLoaderResult);
|
|
5802
|
+
async function renderSSR(route, ctx, root, precomputedLoaderResult, searchRoutes) {
|
|
5803
|
+
const prepared = await prepareRender(route, ctx, root, undefined, false, precomputedLoaderResult, searchRoutes);
|
|
4800
5804
|
if (prepared instanceof Response) {
|
|
4801
5805
|
return prepared;
|
|
4802
5806
|
}
|
|
4803
|
-
|
|
5807
|
+
useLogger3().set({
|
|
4804
5808
|
furin: {
|
|
4805
5809
|
render: route.mode,
|
|
4806
5810
|
route: route.pattern,
|
|
@@ -4817,7 +5821,7 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
4817
5821
|
if (shellError) {
|
|
4818
5822
|
status = 500;
|
|
4819
5823
|
finalDigest = shellError.digest;
|
|
4820
|
-
|
|
5824
|
+
useLogger3().set({
|
|
4821
5825
|
furin: { render: route.mode, route: route.pattern, digest: finalDigest, phase: "shell" }
|
|
4822
5826
|
});
|
|
4823
5827
|
}
|
|
@@ -4838,6 +5842,7 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
4838
5842
|
const deferredKeys = hasDeferred ? Object.keys(deferredPromises) : [];
|
|
4839
5843
|
const deferredSetupScript = hasDeferred ? buildDeferredScript(deferredKeys) : "";
|
|
4840
5844
|
const dataScript = `<script id="__FURIN_DATA__" type="application/json">${safeJson(dataPayload)}</script>`;
|
|
5845
|
+
const runtimeScripts = `${buildSyncRuntimeScript()}${dataScript}`;
|
|
4841
5846
|
const { readable, writable } = new TransformStream;
|
|
4842
5847
|
const writer = writable.getWriter();
|
|
4843
5848
|
const enc = new TextEncoder;
|
|
@@ -4852,7 +5857,7 @@ async function renderSSR(route, ctx, root, precomputedLoaderResult) {
|
|
|
4852
5857
|
await writer.write(value);
|
|
4853
5858
|
}
|
|
4854
5859
|
const [earlyBodyPost, finalBodyPost] = hasDeferred ? splitBeforeBodyClose(bodyPost) : ["", bodyPost];
|
|
4855
|
-
await writer.write(enc.encode(
|
|
5860
|
+
await writer.write(enc.encode(runtimeScripts + earlyBodyPost));
|
|
4856
5861
|
if (hasDeferred) {
|
|
4857
5862
|
await Promise.all(Object.entries(deferredPromises).map(async ([key, promise]) => {
|
|
4858
5863
|
try {
|
|
@@ -4888,6 +5893,7 @@ function splitBeforeBodyClose(bodyPost) {
|
|
|
4888
5893
|
var init_ssr = __esm(() => {
|
|
4889
5894
|
init_development();
|
|
4890
5895
|
init_router();
|
|
5896
|
+
init_search_store();
|
|
4891
5897
|
init_context_logger();
|
|
4892
5898
|
init_assemble();
|
|
4893
5899
|
init_element();
|
|
@@ -4905,10 +5911,10 @@ function isrCacheControl(isFresh, revalidate) {
|
|
|
4905
5911
|
function isrEtag(buildId, generatedAt) {
|
|
4906
5912
|
return buildId ? `"${buildId}:${generatedAt}"` : null;
|
|
4907
5913
|
}
|
|
4908
|
-
function serveISRCacheHit(cached, ctx, route, params, cacheKey, revalidate, root, buildId) {
|
|
5914
|
+
function serveISRCacheHit(cached, ctx, route, params, cacheKey, revalidate, root, buildId, searchRoutes) {
|
|
4909
5915
|
const isFresh = Date.now() - cached.generatedAt < revalidate * 1000;
|
|
4910
5916
|
if (!isFresh) {
|
|
4911
|
-
revalidateInBackground(route, params, cacheKey, revalidate, root, ctx);
|
|
5917
|
+
revalidateInBackground(route, params, cacheKey, revalidate, root, ctx, searchRoutes);
|
|
4912
5918
|
}
|
|
4913
5919
|
const etag = isrEtag(buildId, cached.generatedAt);
|
|
4914
5920
|
if (etag && ctx.request.headers.get("if-none-match") === etag) {
|
|
@@ -4922,10 +5928,10 @@ function serveISRCacheHit(cached, ctx, route, params, cacheKey, revalidate, root
|
|
|
4922
5928
|
if (etag) {
|
|
4923
5929
|
ctx.set.headers.etag = etag;
|
|
4924
5930
|
}
|
|
4925
|
-
|
|
5931
|
+
useLogger3().set({
|
|
4926
5932
|
furin: { render: "isr", route: route.pattern, cache: isFresh ? "hit" : "stale" }
|
|
4927
5933
|
});
|
|
4928
|
-
return cached.html;
|
|
5934
|
+
return injectSyncRuntimeScript(cached.html);
|
|
4929
5935
|
}
|
|
4930
5936
|
async function renderISRNon200(prepared, route, ctx, root, errorDigest, renderStart, buildId) {
|
|
4931
5937
|
const { componentProps, element, headData, headers, template, status, notFoundError } = prepared;
|
|
@@ -4942,7 +5948,7 @@ async function renderISRNon200(prepared, route, ctx, root, errorDigest, renderSt
|
|
|
4942
5948
|
if (shellError) {
|
|
4943
5949
|
finalStatus = 500;
|
|
4944
5950
|
finalDigest = shellError.digest;
|
|
4945
|
-
|
|
5951
|
+
useLogger3().set({
|
|
4946
5952
|
furin: {
|
|
4947
5953
|
render: "isr",
|
|
4948
5954
|
route: route.pattern,
|
|
@@ -4962,7 +5968,7 @@ async function renderISRNon200(prepared, route, ctx, root, errorDigest, renderSt
|
|
|
4962
5968
|
const html = assembleHTML(template, headData, reactHtml, fallbackProps);
|
|
4963
5969
|
const generatedAt = Date.now();
|
|
4964
5970
|
const renderMs = generatedAt - renderStart;
|
|
4965
|
-
|
|
5971
|
+
useLogger3().set({
|
|
4966
5972
|
furin: {
|
|
4967
5973
|
render: "isr",
|
|
4968
5974
|
route: route.pattern,
|
|
@@ -4984,16 +5990,16 @@ async function renderISRNon200(prepared, route, ctx, root, errorDigest, renderSt
|
|
|
4984
5990
|
ctx.set.status = finalStatus;
|
|
4985
5991
|
return html;
|
|
4986
5992
|
}
|
|
4987
|
-
async function handleISR(route, ctx, root, buildId) {
|
|
5993
|
+
async function handleISR(route, ctx, root, buildId, searchRoutes) {
|
|
4988
5994
|
const revalidate = route.page._route.revalidate ?? 60;
|
|
4989
5995
|
const params = ctx.params ?? {};
|
|
4990
5996
|
const cacheKey = resolvePath(route.pattern, params);
|
|
4991
5997
|
const cached = getISRCache(cacheKey);
|
|
4992
5998
|
if (cached) {
|
|
4993
|
-
return serveISRCacheHit(cached, ctx, route, params, cacheKey, revalidate, root, buildId);
|
|
5999
|
+
return serveISRCacheHit(cached, ctx, route, params, cacheKey, revalidate, root, buildId, searchRoutes);
|
|
4994
6000
|
}
|
|
4995
6001
|
const renderStart = Date.now();
|
|
4996
|
-
const prepared = await prepareRender(route, ctx, root, undefined, false, undefined);
|
|
6002
|
+
const prepared = await prepareRender(route, ctx, root, undefined, false, undefined, searchRoutes);
|
|
4997
6003
|
if (prepared instanceof Response) {
|
|
4998
6004
|
return prepared;
|
|
4999
6005
|
}
|
|
@@ -5006,7 +6012,7 @@ async function handleISR(route, ctx, root, buildId) {
|
|
|
5006
6012
|
const reactHtml = await streamToString(stream);
|
|
5007
6013
|
const html = assembleHTML(template, headData, reactHtml, syncData);
|
|
5008
6014
|
const generatedAt = Date.now();
|
|
5009
|
-
|
|
6015
|
+
useLogger3().set({
|
|
5010
6016
|
furin: {
|
|
5011
6017
|
render: "isr",
|
|
5012
6018
|
route: route.pattern,
|
|
@@ -5027,7 +6033,7 @@ async function handleISR(route, ctx, root, buildId) {
|
|
|
5027
6033
|
}
|
|
5028
6034
|
return html;
|
|
5029
6035
|
}
|
|
5030
|
-
function revalidateInBackground(route, params, cacheKey, revalidate, root, originalCtx) {
|
|
6036
|
+
function revalidateInBackground(route, params, cacheKey, revalidate, root, originalCtx, searchRoutes) {
|
|
5031
6037
|
if (pendingRevalidations.has(cacheKey)) {
|
|
5032
6038
|
const logger = createLogger({});
|
|
5033
6039
|
logger.set({
|
|
@@ -5042,7 +6048,7 @@ function revalidateInBackground(route, params, cacheKey, revalidate, root, origi
|
|
|
5042
6048
|
return;
|
|
5043
6049
|
}
|
|
5044
6050
|
pendingRevalidations.add(cacheKey);
|
|
5045
|
-
renderForPath(route, params, root, new URL(originalCtx.request.url).origin, "isr", undefined).then((result) => {
|
|
6051
|
+
renderForPath(route, params, root, new URL(originalCtx.request.url).origin, "isr", undefined, searchRoutes).then((result) => {
|
|
5046
6052
|
if (result instanceof Response) {
|
|
5047
6053
|
return;
|
|
5048
6054
|
}
|
|
@@ -5115,7 +6121,7 @@ async function renderRootNotFound(root, request) {
|
|
|
5115
6121
|
try {
|
|
5116
6122
|
template = await getDevTemplate(new URL(request.url).origin);
|
|
5117
6123
|
} catch (devTemplateErr) {
|
|
5118
|
-
|
|
6124
|
+
useLogger3().set({
|
|
5119
6125
|
furin: {
|
|
5120
6126
|
render: "not-found",
|
|
5121
6127
|
action: "dev_template_fallback",
|
|
@@ -5131,6 +6137,8 @@ async function renderRootNotFound(root, request) {
|
|
|
5131
6137
|
const notFoundContext = {
|
|
5132
6138
|
basePath: "",
|
|
5133
6139
|
currentHref: request ? normalizeHref(new URL(request.url).pathname) : "/",
|
|
6140
|
+
search: {},
|
|
6141
|
+
searchRoutes: [],
|
|
5134
6142
|
navigate: (_href, _opts) => Promise.resolve(),
|
|
5135
6143
|
prefetch: (_href, _opts) => {},
|
|
5136
6144
|
invalidatePrefetch: (_path, _type) => {},
|
|
@@ -5140,7 +6148,7 @@ async function renderRootNotFound(root, request) {
|
|
|
5140
6148
|
defaultPreloadDelay: 50,
|
|
5141
6149
|
defaultPreloadStaleTime: 30000
|
|
5142
6150
|
};
|
|
5143
|
-
|
|
6151
|
+
useLogger3().set({
|
|
5144
6152
|
furin: {
|
|
5145
6153
|
render: "not-found",
|
|
5146
6154
|
action: "catch_all",
|
|
@@ -5151,7 +6159,7 @@ async function renderRootNotFound(root, request) {
|
|
|
5151
6159
|
try {
|
|
5152
6160
|
reactStream = await renderToReadableStream3(withSSRRouterContext(buildNotFoundElement(root.notFound, notFoundError), notFoundContext));
|
|
5153
6161
|
} catch (renderError) {
|
|
5154
|
-
|
|
6162
|
+
useLogger3().set({
|
|
5155
6163
|
furin: {
|
|
5156
6164
|
render: "not-found",
|
|
5157
6165
|
action: "component_render_failed",
|
|
@@ -5239,7 +6247,7 @@ function validateRouteChain(chain, root, pagePath) {
|
|
|
5239
6247
|
}
|
|
5240
6248
|
|
|
5241
6249
|
// src/server/render/ssg.ts
|
|
5242
|
-
async function prerenderSSG(route, params, root, origin, basePath) {
|
|
6250
|
+
async function prerenderSSG(route, params, root, origin, basePath, searchRoutes) {
|
|
5243
6251
|
const resolvedPath = resolvePath(route.pattern, params);
|
|
5244
6252
|
const cached = getSSGCache(resolvedPath);
|
|
5245
6253
|
if (cached) {
|
|
@@ -5250,7 +6258,7 @@ async function prerenderSSG(route, params, root, origin, basePath) {
|
|
|
5250
6258
|
setSSGCache(resolvedPath, taggedEntry);
|
|
5251
6259
|
return taggedEntry;
|
|
5252
6260
|
}
|
|
5253
|
-
const renderResult = await renderForPath(route, params, root, origin, "ssg", basePath);
|
|
6261
|
+
const renderResult = await renderForPath(route, params, root, origin, "ssg", basePath, searchRoutes);
|
|
5254
6262
|
if (renderResult instanceof Response) {
|
|
5255
6263
|
return renderResult;
|
|
5256
6264
|
}
|
|
@@ -5271,7 +6279,7 @@ function logSsgError(furin, error) {
|
|
|
5271
6279
|
logger.error(error instanceof Error ? error : new Error(String(error)));
|
|
5272
6280
|
logger.emit();
|
|
5273
6281
|
}
|
|
5274
|
-
async function warmSSGCache(routes, root, origin) {
|
|
6282
|
+
async function warmSSGCache(routes, root, origin, searchRoutes) {
|
|
5275
6283
|
const targets = routes.filter((r) => r.mode === "ssg" && r.page.staticParams);
|
|
5276
6284
|
const warmupLogger = createLogger({});
|
|
5277
6285
|
warmupLogger.set({
|
|
@@ -5304,7 +6312,7 @@ async function warmSSGCache(routes, root, origin) {
|
|
|
5304
6312
|
for (const params of paramSets) {
|
|
5305
6313
|
tasks.push(async () => {
|
|
5306
6314
|
try {
|
|
5307
|
-
await prerenderSSG(route, params, root, origin, undefined);
|
|
6315
|
+
await prerenderSSG(route, params, root, origin, undefined, searchRoutes);
|
|
5308
6316
|
} catch (err) {
|
|
5309
6317
|
logSsgError({ render: "ssg", action: "prerender_failed", route: route.pattern }, err);
|
|
5310
6318
|
}
|
|
@@ -5361,6 +6369,10 @@ function resolveMode(page, routeChain) {
|
|
|
5361
6369
|
return mode;
|
|
5362
6370
|
}
|
|
5363
6371
|
const hasLoader = routeChain.some((r) => r.loader) || !!page.loader;
|
|
6372
|
+
const hasQuery = routeChain.some((r) => r.query);
|
|
6373
|
+
if (hasQuery) {
|
|
6374
|
+
return "ssr";
|
|
6375
|
+
}
|
|
5364
6376
|
if (!hasLoader) {
|
|
5365
6377
|
return "ssg";
|
|
5366
6378
|
}
|
|
@@ -5836,7 +6848,7 @@ function rebuildDevRoute(base, page, chain) {
|
|
|
5836
6848
|
tags: collectRouteTags(chain, page)
|
|
5837
6849
|
};
|
|
5838
6850
|
}
|
|
5839
|
-
async function handleDevRequest(route, ctx, root) {
|
|
6851
|
+
async function handleDevRequest(route, ctx, root, searchRoutes) {
|
|
5840
6852
|
try {
|
|
5841
6853
|
let currentRoot = root;
|
|
5842
6854
|
const rootMod = await import(`${root.path}?furin-server&t=${Date.now()}`);
|
|
@@ -5855,19 +6867,19 @@ async function handleDevRequest(route, ctx, root) {
|
|
|
5855
6867
|
}
|
|
5856
6868
|
const refreshedRoute = rebuildDevRoute(route, page, chain);
|
|
5857
6869
|
if (refreshedRoute.mode === "isr") {
|
|
5858
|
-
return renderDevISRWithLoaderCache(refreshedRoute, ctx, currentRoot);
|
|
6870
|
+
return renderDevISRWithLoaderCache(refreshedRoute, ctx, currentRoot, searchRoutes);
|
|
5859
6871
|
}
|
|
5860
6872
|
if (refreshedRoute.mode === "ssg") {
|
|
5861
|
-
return renderDevSSGWithLoaderCache(refreshedRoute, ctx, currentRoot);
|
|
6873
|
+
return renderDevSSGWithLoaderCache(refreshedRoute, ctx, currentRoot, searchRoutes);
|
|
5862
6874
|
}
|
|
5863
|
-
return renderSSR(refreshedRoute, ctx, currentRoot, undefined);
|
|
6875
|
+
return renderSSR(refreshedRoute, ctx, currentRoot, undefined, searchRoutes);
|
|
5864
6876
|
}
|
|
5865
6877
|
} catch (err) {
|
|
5866
6878
|
console.error(`[furin] Dev page load error for ${route.path}:`, err);
|
|
5867
6879
|
}
|
|
5868
6880
|
return new Response(`<!doctype html><html><body><h1>Page load error</h1><p>Could not load ${route.path}. Check the server console for details.</p></body></html>`, { status: 500, headers: { "Content-Type": "text/html; charset=utf-8" } });
|
|
5869
6881
|
}
|
|
5870
|
-
async function renderDevISRWithLoaderCache(route, ctx, root) {
|
|
6882
|
+
async function renderDevISRWithLoaderCache(route, ctx, root, searchRoutes) {
|
|
5871
6883
|
const cacheKey = `${root.path}:${resolvePath(route.pattern, ctx.params ?? {})}`;
|
|
5872
6884
|
const cached = getDevISRLoaderCache(cacheKey);
|
|
5873
6885
|
if (cached && isDevLoaderCacheValid(cached)) {
|
|
@@ -5877,7 +6889,7 @@ async function renderDevISRWithLoaderCache(route, ctx, root) {
|
|
|
5877
6889
|
deferredPromises: undefined,
|
|
5878
6890
|
headers: cached.headers
|
|
5879
6891
|
};
|
|
5880
|
-
return renderSSR(route, ctx, root, precomputed);
|
|
6892
|
+
return renderSSR(route, ctx, root, precomputed, searchRoutes);
|
|
5881
6893
|
}
|
|
5882
6894
|
const result = await runLoaders(route, ctx);
|
|
5883
6895
|
if (result.type === "data") {
|
|
@@ -5893,9 +6905,9 @@ async function renderDevISRWithLoaderCache(route, ctx, root) {
|
|
|
5893
6905
|
setDevISRLoaderCache(cacheKey, entry);
|
|
5894
6906
|
autoInvalidateRegistry.registerLoaderTags(resolvePath(route.pattern, ctx.params ?? {}), route.tags);
|
|
5895
6907
|
}
|
|
5896
|
-
return renderSSR(route, ctx, root, result);
|
|
6908
|
+
return renderSSR(route, ctx, root, result, searchRoutes);
|
|
5897
6909
|
}
|
|
5898
|
-
async function renderDevSSGWithLoaderCache(route, ctx, root) {
|
|
6910
|
+
async function renderDevSSGWithLoaderCache(route, ctx, root, searchRoutes) {
|
|
5899
6911
|
const cacheKey = `${root.path}:${resolvePath(route.pattern, ctx.params ?? {})}`;
|
|
5900
6912
|
const cached = getDevSSGLoaderCache(cacheKey);
|
|
5901
6913
|
if (cached && isDevLoaderCacheValid(cached)) {
|
|
@@ -5905,7 +6917,7 @@ async function renderDevSSGWithLoaderCache(route, ctx, root) {
|
|
|
5905
6917
|
deferredPromises: undefined,
|
|
5906
6918
|
headers: cached.headers
|
|
5907
6919
|
};
|
|
5908
|
-
return renderSSR(route, ctx, root, precomputed);
|
|
6920
|
+
return renderSSR(route, ctx, root, precomputed, searchRoutes);
|
|
5909
6921
|
}
|
|
5910
6922
|
const result = await runLoaders(route, ctx);
|
|
5911
6923
|
if (result.type === "data") {
|
|
@@ -5920,7 +6932,7 @@ async function renderDevSSGWithLoaderCache(route, ctx, root) {
|
|
|
5920
6932
|
setDevSSGLoaderCache(cacheKey, entry);
|
|
5921
6933
|
autoInvalidateRegistry.registerLoaderTags(resolvePath(route.pattern, ctx.params ?? {}), route.tags);
|
|
5922
6934
|
}
|
|
5923
|
-
return renderSSR(route, ctx, root, result);
|
|
6935
|
+
return renderSSR(route, ctx, root, result, searchRoutes);
|
|
5924
6936
|
}
|
|
5925
6937
|
function computeRouteDependencies(pagePath, rootPath) {
|
|
5926
6938
|
const deps = [pagePath, rootPath];
|
|
@@ -5944,30 +6956,8 @@ var init_hmr = __esm(() => {
|
|
|
5944
6956
|
|
|
5945
6957
|
// src/server/router/schemas.ts
|
|
5946
6958
|
import { t } from "elysia";
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
if (queryKeys.length === 0) {
|
|
5950
|
-
return;
|
|
5951
|
-
}
|
|
5952
|
-
const rawParams = new URL(request.url).searchParams;
|
|
5953
|
-
let needsRedirect = false;
|
|
5954
|
-
for (const key of queryKeys) {
|
|
5955
|
-
if (!rawParams.has(key) && resolvedQuery[key] != null) {
|
|
5956
|
-
needsRedirect = true;
|
|
5957
|
-
break;
|
|
5958
|
-
}
|
|
5959
|
-
}
|
|
5960
|
-
if (!needsRedirect) {
|
|
5961
|
-
return;
|
|
5962
|
-
}
|
|
5963
|
-
const url = new URL(request.url);
|
|
5964
|
-
for (const [k, v] of Object.entries(resolvedQuery)) {
|
|
5965
|
-
if (v != null) {
|
|
5966
|
-
url.searchParams.set(k, String(v));
|
|
5967
|
-
}
|
|
5968
|
-
}
|
|
5969
|
-
return url.pathname + url.search;
|
|
5970
|
-
}
|
|
6959
|
+
import { parseQueryFromURL, parseQueryStandardSchema } from "elysia/parse-query";
|
|
6960
|
+
import { getSchemaValidator } from "elysia/schema";
|
|
5971
6961
|
function parseDataEndpointPath(rawPath) {
|
|
5972
6962
|
if (rawPath.includes("://") || rawPath.startsWith("//")) {
|
|
5973
6963
|
return;
|
|
@@ -5983,13 +6973,95 @@ function parseDataEndpointPath(rawPath) {
|
|
|
5983
6973
|
}
|
|
5984
6974
|
return { url, pathname: url.pathname };
|
|
5985
6975
|
}
|
|
5986
|
-
function
|
|
5987
|
-
|
|
5988
|
-
|
|
6976
|
+
function isObjectSchema(schema) {
|
|
6977
|
+
return !!schema && typeof schema === "object";
|
|
6978
|
+
}
|
|
6979
|
+
function isStandardSchema(schema) {
|
|
6980
|
+
return isObjectSchema(schema) && "~standard" in schema;
|
|
6981
|
+
}
|
|
6982
|
+
function collectQueryArrayKeys(schema) {
|
|
6983
|
+
if (!(isObjectSchema(schema) && isObjectSchema(schema.properties))) {
|
|
6984
|
+
return;
|
|
6985
|
+
}
|
|
6986
|
+
const keys = {};
|
|
6987
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
6988
|
+
const effectiveSchema = findEffectiveAnyOfMember(value, "array") ?? value;
|
|
6989
|
+
if (isObjectSchema(effectiveSchema) && effectiveSchema.type === "array") {
|
|
6990
|
+
keys[key] = 1;
|
|
6991
|
+
}
|
|
6992
|
+
}
|
|
6993
|
+
return Object.keys(keys).length > 0 ? keys : undefined;
|
|
6994
|
+
}
|
|
6995
|
+
function collectQueryObjectKeys(schema) {
|
|
6996
|
+
if (!(isObjectSchema(schema) && isObjectSchema(schema.properties))) {
|
|
5989
6997
|
return;
|
|
5990
6998
|
}
|
|
5991
|
-
|
|
5992
|
-
|
|
6999
|
+
const keys = {};
|
|
7000
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
7001
|
+
const effectiveSchema = findEffectiveAnyOfMember(value, "object") ?? value;
|
|
7002
|
+
if (isObjectSchema(effectiveSchema) && effectiveSchema.type === "object") {
|
|
7003
|
+
keys[key] = 1;
|
|
7004
|
+
}
|
|
7005
|
+
}
|
|
7006
|
+
return Object.keys(keys).length > 0 ? keys : undefined;
|
|
7007
|
+
}
|
|
7008
|
+
function findEffectiveAnyOfMember(schema, type) {
|
|
7009
|
+
if (!(isObjectSchema(schema) && Array.isArray(schema.anyOf))) {
|
|
7010
|
+
return;
|
|
7011
|
+
}
|
|
7012
|
+
for (const member of schema.anyOf) {
|
|
7013
|
+
if (isObjectSchema(member) && member.type === type) {
|
|
7014
|
+
return member;
|
|
7015
|
+
}
|
|
7016
|
+
}
|
|
7017
|
+
}
|
|
7018
|
+
function parseJsonQueryObjects(query, objectKeys) {
|
|
7019
|
+
if (!objectKeys) {
|
|
7020
|
+
return query;
|
|
7021
|
+
}
|
|
7022
|
+
const parsed = { ...query };
|
|
7023
|
+
for (const key of Object.keys(objectKeys)) {
|
|
7024
|
+
const value = parsed[key];
|
|
7025
|
+
if (typeof value !== "string") {
|
|
7026
|
+
continue;
|
|
7027
|
+
}
|
|
7028
|
+
try {
|
|
7029
|
+
parsed[key] = JSON.parse(value);
|
|
7030
|
+
} catch {
|
|
7031
|
+
parsed[key] = value;
|
|
7032
|
+
}
|
|
7033
|
+
}
|
|
7034
|
+
return parsed;
|
|
7035
|
+
}
|
|
7036
|
+
async function parseRouteQuery(url, schema) {
|
|
7037
|
+
if (!schema) {
|
|
7038
|
+
return { ok: true, query: parseQueryFromURL(url.search, 1) };
|
|
7039
|
+
}
|
|
7040
|
+
if (isStandardSchema(schema)) {
|
|
7041
|
+
const rawQuery2 = parseQueryStandardSchema(url.search, 1);
|
|
7042
|
+
const validator2 = getSchemaValidator(schema, { dynamic: true });
|
|
7043
|
+
const checked = await validator2?.Check(rawQuery2);
|
|
7044
|
+
if (checked && typeof checked === "object" && "issues" in checked) {
|
|
7045
|
+
return { errors: checked.issues, ok: false };
|
|
7046
|
+
}
|
|
7047
|
+
if (checked && typeof checked === "object" && "value" in checked) {
|
|
7048
|
+
return { ok: true, query: checked.value };
|
|
7049
|
+
}
|
|
7050
|
+
return { ok: true, query: rawQuery2 };
|
|
7051
|
+
}
|
|
7052
|
+
const rawQuery = parseJsonQueryObjects(parseQueryFromURL(url.search, 1, collectQueryArrayKeys(schema)), collectQueryObjectKeys(schema));
|
|
7053
|
+
const queryWithDefaults = applySchemaDefaults(schema, rawQuery);
|
|
7054
|
+
const validator = getSchemaValidator(schema, { coerce: true, dynamic: true });
|
|
7055
|
+
if (validator?.Check(queryWithDefaults) === false) {
|
|
7056
|
+
return { errors: [...validator?.Errors(queryWithDefaults) ?? []], ok: false };
|
|
7057
|
+
}
|
|
7058
|
+
return {
|
|
7059
|
+
ok: true,
|
|
7060
|
+
query: validator?.parse(queryWithDefaults) ?? queryWithDefaults
|
|
7061
|
+
};
|
|
7062
|
+
}
|
|
7063
|
+
function isTypeBoxObjectSchema(schema) {
|
|
7064
|
+
return isObjectSchema(schema) && schema[TYPEBOX_KIND] === "Object";
|
|
5993
7065
|
}
|
|
5994
7066
|
function mergeRouteSchemas(routeChain, key) {
|
|
5995
7067
|
const schemas = routeChain.flatMap((r) => r[key] ? [r[key]] : []);
|
|
@@ -5999,10 +7071,28 @@ function mergeRouteSchemas(routeChain, key) {
|
|
|
5999
7071
|
if (schemas.length === 1) {
|
|
6000
7072
|
return schemas[0];
|
|
6001
7073
|
}
|
|
7074
|
+
if (schemas.some((s) => !isTypeBoxObjectSchema(s))) {
|
|
7075
|
+
throw new Error(`[furin] Merging ${key} schemas across the route chain requires TypeBox in V1. Use TypeBox for parent/child ${key}, or define ${key} only on leaf routes.`);
|
|
7076
|
+
}
|
|
6002
7077
|
const mergedProperties = Object.assign({}, ...schemas.map((s) => s.properties ?? {}));
|
|
6003
7078
|
const mergedOptions = Object.assign({}, ...schemas.map((s) => Object.fromEntries(Object.entries(s).filter(([k]) => !TOBJECT_STRUCTURAL_KEYS.has(k)))));
|
|
6004
7079
|
return t.Object(mergedProperties, mergedOptions);
|
|
6005
7080
|
}
|
|
7081
|
+
function createSearchRouteMetadata(routes) {
|
|
7082
|
+
const metadata = [];
|
|
7083
|
+
for (const route of routes) {
|
|
7084
|
+
const searchDefaults = collectSearchDefaults(mergeRouteSchemas(route.routeChain, "query"));
|
|
7085
|
+
if (!searchDefaults) {
|
|
7086
|
+
continue;
|
|
7087
|
+
}
|
|
7088
|
+
metadata.push({
|
|
7089
|
+
pattern: route.pattern,
|
|
7090
|
+
regex: buildRouteRegex(route.pattern).regex,
|
|
7091
|
+
searchDefaults
|
|
7092
|
+
});
|
|
7093
|
+
}
|
|
7094
|
+
return metadata;
|
|
7095
|
+
}
|
|
6006
7096
|
function applySchemaDefaults(schema, values) {
|
|
6007
7097
|
if (!schema || typeof schema !== "object") {
|
|
6008
7098
|
return values;
|
|
@@ -6020,16 +7110,18 @@ function applySchemaDefaults(schema, values) {
|
|
|
6020
7110
|
}
|
|
6021
7111
|
return result;
|
|
6022
7112
|
}
|
|
6023
|
-
var TOBJECT_STRUCTURAL_KEYS;
|
|
7113
|
+
var TOBJECT_STRUCTURAL_KEYS, TYPEBOX_KIND;
|
|
6024
7114
|
var init_schemas = __esm(() => {
|
|
7115
|
+
init_patterns();
|
|
6025
7116
|
TOBJECT_STRUCTURAL_KEYS = new Set(["type", "properties", "required"]);
|
|
7117
|
+
TYPEBOX_KIND = Symbol.for("TypeBox.Kind");
|
|
6026
7118
|
});
|
|
6027
7119
|
|
|
6028
7120
|
// src/server/router/plugin.ts
|
|
6029
7121
|
import { Elysia as Elysia2, t as t2 } from "elysia";
|
|
6030
|
-
async function handleSSGRequest(route, ctx, root, buildId) {
|
|
7122
|
+
async function handleSSGRequest(route, ctx, root, buildId, searchRoutes) {
|
|
6031
7123
|
const origin = new URL(ctx.request.url).origin;
|
|
6032
|
-
const entry = await prerenderSSG(route, ctx.params, root, origin, undefined);
|
|
7124
|
+
const entry = await prerenderSSG(route, ctx.params, root, origin, undefined, searchRoutes);
|
|
6033
7125
|
if (entry instanceof Response) {
|
|
6034
7126
|
return entry;
|
|
6035
7127
|
}
|
|
@@ -6045,14 +7137,13 @@ async function handleSSGRequest(route, ctx, root, buildId) {
|
|
|
6045
7137
|
ctx.set.headers.etag = etag;
|
|
6046
7138
|
}
|
|
6047
7139
|
ctx.set.headers["cache-tag"] = resolvedPath;
|
|
6048
|
-
return entry.html;
|
|
7140
|
+
return injectSyncRuntimeScript(entry.html);
|
|
6049
7141
|
}
|
|
6050
|
-
function createRoutePlugin(route, root, buildId) {
|
|
7142
|
+
function createRoutePlugin(route, root, buildId, searchRoutes) {
|
|
6051
7143
|
const resolvedBuildId = buildId ?? "";
|
|
6052
7144
|
const { pattern, routeChain } = route;
|
|
6053
7145
|
const allParams = mergeRouteSchemas(routeChain, "params");
|
|
6054
7146
|
const allQuery = mergeRouteSchemas(routeChain, "query");
|
|
6055
|
-
const hasQuerySchema = !!allQuery;
|
|
6056
7147
|
const plugin = new Elysia2;
|
|
6057
7148
|
if (allParams || allQuery) {
|
|
6058
7149
|
plugin.guard({
|
|
@@ -6061,23 +7152,17 @@ function createRoutePlugin(route, root, buildId) {
|
|
|
6061
7152
|
});
|
|
6062
7153
|
}
|
|
6063
7154
|
plugin.get(pattern, (ctx) => {
|
|
6064
|
-
if (hasQuerySchema) {
|
|
6065
|
-
const redirect = queryDefaultRedirectHook(ctx);
|
|
6066
|
-
if (redirect) {
|
|
6067
|
-
return redirect;
|
|
6068
|
-
}
|
|
6069
|
-
}
|
|
6070
7155
|
if (IS_DEV) {
|
|
6071
|
-
return handleDevRequest(route, ctx, root);
|
|
7156
|
+
return handleDevRequest(route, ctx, root, searchRoutes);
|
|
6072
7157
|
}
|
|
6073
7158
|
if (route.mode === "ssg") {
|
|
6074
|
-
return handleSSGRequest(route, ctx, root, resolvedBuildId);
|
|
7159
|
+
return handleSSGRequest(route, ctx, root, resolvedBuildId, searchRoutes);
|
|
6075
7160
|
}
|
|
6076
7161
|
if (route.mode === "isr") {
|
|
6077
7162
|
ctx.set.headers["cache-tag"] = resolvePath(route.pattern, ctx.params ?? {});
|
|
6078
|
-
return handleISR(route, ctx, root, resolvedBuildId);
|
|
7163
|
+
return handleISR(route, ctx, root, resolvedBuildId, searchRoutes);
|
|
6079
7164
|
}
|
|
6080
|
-
return renderSSR(route, ctx, root, undefined);
|
|
7165
|
+
return renderSSR(route, ctx, root, undefined, searchRoutes);
|
|
6081
7166
|
});
|
|
6082
7167
|
return plugin;
|
|
6083
7168
|
}
|
|
@@ -6094,7 +7179,7 @@ function createDataEndpoint(routes) {
|
|
|
6094
7179
|
return new Response("Invalid path", { status: 400 });
|
|
6095
7180
|
}
|
|
6096
7181
|
const { url, pathname } = parsed;
|
|
6097
|
-
const wideEventLog =
|
|
7182
|
+
const wideEventLog = useLogger3();
|
|
6098
7183
|
wideEventLog.set({ path: rawPath });
|
|
6099
7184
|
const matched = matchRoute(pathname);
|
|
6100
7185
|
if (!matched) {
|
|
@@ -6116,18 +7201,12 @@ function createDataEndpoint(routes) {
|
|
|
6116
7201
|
};
|
|
6117
7202
|
const mergedParams = mergeRouteSchemas(matched.route.routeChain, "params");
|
|
6118
7203
|
const mergedQuery = mergeRouteSchemas(matched.route.routeChain, "query");
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
const redirectLocation = detectQueryDefaultRedirect(syntheticRequest, syntheticCtx.query);
|
|
6123
|
-
if (redirectLocation) {
|
|
6124
|
-
const serialized2 = await toCrossJSONAsync({ __furinRedirect: redirectLocation });
|
|
6125
|
-
return new Response(`${JSON.stringify(serialized2)}
|
|
6126
|
-
`, {
|
|
6127
|
-
headers: { "content-type": "application/x-ndjson" }
|
|
6128
|
-
});
|
|
6129
|
-
}
|
|
7204
|
+
const parsedQuery = await parseRouteQuery(url, mergedQuery);
|
|
7205
|
+
if (!parsedQuery.ok) {
|
|
7206
|
+
return Response.json({ errors: parsedQuery.errors, message: "Invalid query", type: "validation" }, { status: 422 });
|
|
6130
7207
|
}
|
|
7208
|
+
syntheticCtx.params = applySchemaDefaults(mergedParams, syntheticCtx.params);
|
|
7209
|
+
syntheticCtx.query = parsedQuery.query;
|
|
6131
7210
|
const result = await runLoaders(matched.route, syntheticCtx);
|
|
6132
7211
|
if (result.type === "data") {
|
|
6133
7212
|
autoInvalidateRegistry.registerLoaderTags(pathname, matched.route.tags);
|
|
@@ -6256,14 +7335,13 @@ __export(exports_router, {
|
|
|
6256
7335
|
renderDevISRWithLoaderCache: () => renderDevISRWithLoaderCache,
|
|
6257
7336
|
refreshLayoutChain: () => refreshLayoutChain,
|
|
6258
7337
|
rebuildDevRoute: () => rebuildDevRoute,
|
|
6259
|
-
queryDefaultRedirectHook: () => queryDefaultRedirectHook,
|
|
6260
7338
|
parseDataEndpointPath: () => parseDataEndpointPath,
|
|
6261
7339
|
mergeRouteSchemas: () => mergeRouteSchemas,
|
|
6262
7340
|
loadProdRoutes: () => loadProdRoutes,
|
|
6263
7341
|
importFreshRouteModuleCandidate: () => importFreshRouteModuleCandidate,
|
|
6264
7342
|
filePathToPattern: () => filePathToPattern,
|
|
6265
7343
|
escapeRegExpChar: () => escapeRegExpChar,
|
|
6266
|
-
|
|
7344
|
+
createSearchRouteMetadata: () => createSearchRouteMetadata,
|
|
6267
7345
|
createRoutePlugin: () => createRoutePlugin,
|
|
6268
7346
|
createDataEndpoint: () => createDataEndpoint,
|
|
6269
7347
|
computeRouteDependencies: () => computeRouteDependencies,
|
|
@@ -6285,14 +7363,19 @@ var init_router2 = __esm(() => {
|
|
|
6285
7363
|
// src/server/dev-page-plugin.ts
|
|
6286
7364
|
var exports_dev_page_plugin = {};
|
|
6287
7365
|
__export(exports_dev_page_plugin, {
|
|
7366
|
+
toImportSpecifier: () => toImportSpecifier,
|
|
6288
7367
|
rewriteSingletonImports: () => rewriteSingletonImports,
|
|
6289
7368
|
rewriteRelativeImports: () => rewriteRelativeImports,
|
|
6290
7369
|
rewriteBareImports: () => rewriteBareImports,
|
|
6291
7370
|
registerDevPagePlugin: () => registerDevPagePlugin,
|
|
6292
|
-
injectJsxHelperImports: () => injectJsxHelperImports
|
|
7371
|
+
injectJsxHelperImports: () => injectJsxHelperImports,
|
|
7372
|
+
WORKSPACE_SOURCE_FILTER: () => WORKSPACE_SOURCE_FILTER
|
|
6293
7373
|
});
|
|
6294
7374
|
import { dirname, resolve } from "path";
|
|
6295
7375
|
import { fileURLToPath } from "url";
|
|
7376
|
+
function toImportSpecifier(filePath) {
|
|
7377
|
+
return filePath.replaceAll("\\", "/");
|
|
7378
|
+
}
|
|
6296
7379
|
function escapeRegExp(s) {
|
|
6297
7380
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6298
7381
|
}
|
|
@@ -6300,7 +7383,7 @@ function rewriteSingletonImports(source) {
|
|
|
6300
7383
|
let result = source;
|
|
6301
7384
|
for (const [pkg, absPath] of SINGLETON_PATHS) {
|
|
6302
7385
|
const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(pkg)}["']`, "g");
|
|
6303
|
-
result = result.replace(re, (_, g1) => `${g1}
|
|
7386
|
+
result = result.replace(re, (_, g1) => `${g1}${JSON.stringify(absPath)}`);
|
|
6304
7387
|
}
|
|
6305
7388
|
return result;
|
|
6306
7389
|
}
|
|
@@ -6324,14 +7407,14 @@ function injectJsxHelperImports(transpiled) {
|
|
|
6324
7407
|
const absPath = SINGLETON_PATHS.get("react/jsx-dev-runtime");
|
|
6325
7408
|
if (absPath) {
|
|
6326
7409
|
const specifiers = [...devRuntime.entries()].map(([varName, exportName]) => `${exportName} as ${varName}`).join(", ");
|
|
6327
|
-
lines.push(`import { ${specifiers} } from
|
|
7410
|
+
lines.push(`import { ${specifiers} } from ${JSON.stringify(absPath)};`);
|
|
6328
7411
|
}
|
|
6329
7412
|
}
|
|
6330
7413
|
if (prodRuntime.size > 0) {
|
|
6331
7414
|
const absPath = SINGLETON_PATHS.get("react/jsx-runtime");
|
|
6332
7415
|
if (absPath) {
|
|
6333
7416
|
const specifiers = [...prodRuntime.entries()].map(([varName, exportName]) => `${exportName} as ${varName}`).join(", ");
|
|
6334
|
-
lines.push(`import { ${specifiers} } from
|
|
7417
|
+
lines.push(`import { ${specifiers} } from ${JSON.stringify(absPath)};`);
|
|
6335
7418
|
}
|
|
6336
7419
|
}
|
|
6337
7420
|
if (lines.length === 0) {
|
|
@@ -6349,9 +7432,9 @@ function rewriteRelativeImports(source, dir) {
|
|
|
6349
7432
|
if (linePrefix.startsWith("//") || linePrefix.startsWith("*")) {
|
|
6350
7433
|
return match;
|
|
6351
7434
|
}
|
|
6352
|
-
const absPath = resolve(dir, relPath);
|
|
7435
|
+
const absPath = toImportSpecifier(resolve(dir, relPath));
|
|
6353
7436
|
const keyword = match.startsWith("import") ? "import" : "from";
|
|
6354
|
-
return `${keyword}
|
|
7437
|
+
return `${keyword} ${JSON.stringify(absPath)}`;
|
|
6355
7438
|
});
|
|
6356
7439
|
}
|
|
6357
7440
|
function rewriteBareImports(source, transpiled, dir) {
|
|
@@ -6376,12 +7459,12 @@ function rewriteBareImports(source, transpiled, dir) {
|
|
|
6376
7459
|
}
|
|
6377
7460
|
let resolved;
|
|
6378
7461
|
try {
|
|
6379
|
-
resolved = Bun.resolveSync(spec, dir);
|
|
7462
|
+
resolved = toImportSpecifier(Bun.resolveSync(spec, dir));
|
|
6380
7463
|
} catch {
|
|
6381
7464
|
continue;
|
|
6382
7465
|
}
|
|
6383
7466
|
const re = new RegExp(`((?:from|import(?:\\s+type)?)\\s+)["']${escapeRegExp(spec)}["']`, "g");
|
|
6384
|
-
result = result.replace(re, (_, g1) => `${g1}
|
|
7467
|
+
result = result.replace(re, (_, g1) => `${g1}${JSON.stringify(resolved)}`);
|
|
6385
7468
|
}
|
|
6386
7469
|
return result;
|
|
6387
7470
|
}
|
|
@@ -6476,7 +7559,7 @@ var init_dev_page_plugin = __esm(() => {
|
|
|
6476
7559
|
init_dev_loader();
|
|
6477
7560
|
FURIN_SERVER_FILTER = /\?furin-server(?:&t=\d+)?$/;
|
|
6478
7561
|
ANY_FILTER = /.*/;
|
|
6479
|
-
WORKSPACE_SOURCE_FILTER = /^(?!.*(
|
|
7562
|
+
WORKSPACE_SOURCE_FILTER = /^(?!.*(?:[\\/]node_modules[\\/]|[\\/]\.bun[\\/]))(?!.*\.(?:test|spec)\.[jt]sx?$).*\.[jt]sx?$/;
|
|
6480
7563
|
T_PARAM_RE = /&t=(\d+)/;
|
|
6481
7564
|
STRIP_FURIN_SERVER_RE = /\?furin-server.*$/;
|
|
6482
7565
|
STRIP_T_PARAM_RE = /\?t=\d+$/;
|
|
@@ -6491,7 +7574,7 @@ var init_dev_page_plugin = __esm(() => {
|
|
|
6491
7574
|
SINGLETON_PATHS = new Map;
|
|
6492
7575
|
for (const pkg of SINGLETON_PKGS) {
|
|
6493
7576
|
try {
|
|
6494
|
-
SINGLETON_PATHS.set(pkg, fileURLToPath(import.meta.resolve(pkg)));
|
|
7577
|
+
SINGLETON_PATHS.set(pkg, toImportSpecifier(fileURLToPath(import.meta.resolve(pkg))));
|
|
6495
7578
|
} catch {}
|
|
6496
7579
|
}
|
|
6497
7580
|
RELATIVE_SPECIFIER_RE = /(?:from|import)\s+["'](\.\.?\/[^"']+)["']/g;
|
|
@@ -6502,7 +7585,7 @@ var exports_dev_inspector = {};
|
|
|
6502
7585
|
__export(exports_dev_inspector, {
|
|
6503
7586
|
createDevInspectorPlugin: () => createDevInspectorPlugin
|
|
6504
7587
|
});
|
|
6505
|
-
import { Elysia as
|
|
7588
|
+
import { Elysia as Elysia6 } from "elysia";
|
|
6506
7589
|
function projectEntry(key, entry) {
|
|
6507
7590
|
const revalidate = Number.isFinite(entry.revalidate) ? entry.revalidate : -1;
|
|
6508
7591
|
return {
|
|
@@ -6516,7 +7599,7 @@ function projectEntry(key, entry) {
|
|
|
6516
7599
|
};
|
|
6517
7600
|
}
|
|
6518
7601
|
function createDevInspectorPlugin() {
|
|
6519
|
-
return new
|
|
7602
|
+
return new Elysia6({ name: "furin-dev-inspector" }).get("/__furin/_inspect/isr", () => getAllDevISRLoaderEntries().map(([key, entry]) => projectEntry(key, entry))).get("/__furin/_inspect/ssg", () => getAllDevSSGLoaderEntries().map(([key, entry]) => projectEntry(key, entry)));
|
|
6520
7603
|
}
|
|
6521
7604
|
var init_dev_inspector = __esm(() => {
|
|
6522
7605
|
init_dev_loader();
|
|
@@ -6530,6 +7613,9 @@ function patternToTypeString(pattern) {
|
|
|
6530
7613
|
return t3.includes("${") ? `\`${t3}\`` : `"${t3}"`;
|
|
6531
7614
|
}
|
|
6532
7615
|
function schemaToTypeString(schema) {
|
|
7616
|
+
return schemaToTypeStringWithDefaults(schema, true);
|
|
7617
|
+
}
|
|
7618
|
+
function schemaToTypeStringWithDefaults(schema, defaultsAreRequired) {
|
|
6533
7619
|
if (!schema || typeof schema !== "object") {
|
|
6534
7620
|
return "unknown";
|
|
6535
7621
|
}
|
|
@@ -6537,7 +7623,7 @@ function schemaToTypeString(schema) {
|
|
|
6537
7623
|
if (s.anyOf && Array.isArray(s.anyOf)) {
|
|
6538
7624
|
const parts = [];
|
|
6539
7625
|
for (const item of s.anyOf) {
|
|
6540
|
-
const t3 =
|
|
7626
|
+
const t3 = schemaToTypeStringWithDefaults(item, defaultsAreRequired);
|
|
6541
7627
|
if (t3 !== "null")
|
|
6542
7628
|
parts.push(t3);
|
|
6543
7629
|
}
|
|
@@ -6553,18 +7639,35 @@ function schemaToTypeString(schema) {
|
|
|
6553
7639
|
return "boolean";
|
|
6554
7640
|
case "null":
|
|
6555
7641
|
return "null";
|
|
7642
|
+
case "array": {
|
|
7643
|
+
const inner = schemaToTypeStringWithDefaults(s.items, defaultsAreRequired);
|
|
7644
|
+
return inner.includes("|") || inner.includes("&") ? `(${inner})[]` : `${inner}[]`;
|
|
7645
|
+
}
|
|
6556
7646
|
case "object": {
|
|
6557
7647
|
if (!s.properties || typeof s.properties !== "object") {
|
|
6558
7648
|
return "Record<string, unknown>";
|
|
6559
7649
|
}
|
|
6560
7650
|
const required = new Set(Array.isArray(s.required) ? s.required : []);
|
|
6561
|
-
const props = Object.entries(s.properties).map(([k, v]) =>
|
|
7651
|
+
const props = Object.entries(s.properties).map(([k, v]) => {
|
|
7652
|
+
const isPresent = required.has(k) || defaultsAreRequired && hasNonNullSchemaDefault(v);
|
|
7653
|
+
return `${k}${isPresent ? "" : "?"}: ${schemaToTypeStringWithDefaults(v, defaultsAreRequired)}`;
|
|
7654
|
+
}).join("; ");
|
|
6562
7655
|
return `{ ${props} }`;
|
|
6563
7656
|
}
|
|
6564
7657
|
default:
|
|
6565
7658
|
return "unknown";
|
|
6566
7659
|
}
|
|
6567
7660
|
}
|
|
7661
|
+
function schemaToInputTypeString(schema) {
|
|
7662
|
+
return schemaToTypeStringWithDefaults(schema, false);
|
|
7663
|
+
}
|
|
7664
|
+
function hasNonNullSchemaDefault(schema) {
|
|
7665
|
+
if (!schema || typeof schema !== "object") {
|
|
7666
|
+
return false;
|
|
7667
|
+
}
|
|
7668
|
+
const s = schema;
|
|
7669
|
+
return "default" in s && s.default != null;
|
|
7670
|
+
}
|
|
6568
7671
|
function tagKeyToPropertyName(tag) {
|
|
6569
7672
|
return /^[$A-Z_a-z][$\w]*$/.test(tag) ? tag : JSON.stringify(tag);
|
|
6570
7673
|
}
|
|
@@ -6577,10 +7680,13 @@ function writeRouteTypes(routes, projectRoot) {
|
|
|
6577
7680
|
const entries = sortedRoutes.map((r) => {
|
|
6578
7681
|
const typeKey = patternToTypeString(r.pattern);
|
|
6579
7682
|
const isDynamic = typeKey.startsWith("`");
|
|
6580
|
-
const querySchema = r.routeChain
|
|
7683
|
+
const querySchema = mergeRouteSchemas(r.routeChain ?? [], "query");
|
|
6581
7684
|
const searchType = querySchema ? schemaToTypeString(querySchema) : "never";
|
|
6582
|
-
|
|
7685
|
+
const searchInputType = querySchema ? schemaToInputTypeString(querySchema) : "never";
|
|
7686
|
+
return isDynamic ? ` [key: ${typeKey}]: { search?: ${searchType}; searchInput?: ${searchInputType} }` : ` ${typeKey}: { search?: ${searchType}; searchInput?: ${searchInputType} }`;
|
|
6583
7687
|
});
|
|
7688
|
+
const routeManifestEntries = entries.join(`;
|
|
7689
|
+
`);
|
|
6584
7690
|
const sortedTags = [...new Set(routes.flatMap((route) => route.tags ?? []))].sort();
|
|
6585
7691
|
const tagBlock = sortedTags.length > 0 ? `
|
|
6586
7692
|
|
|
@@ -6596,8 +7702,7 @@ import "@teyik0/furin/link";
|
|
|
6596
7702
|
|
|
6597
7703
|
declare module "@teyik0/furin/link" {
|
|
6598
7704
|
interface RouteManifest {
|
|
6599
|
-
${
|
|
6600
|
-
`)};
|
|
7705
|
+
${routeManifestEntries};
|
|
6601
7706
|
}
|
|
6602
7707
|
}${tagBlock}
|
|
6603
7708
|
`;
|
|
@@ -6607,7 +7712,9 @@ ${entries.join(`;
|
|
|
6607
7712
|
writeFileSync(typesPath, content);
|
|
6608
7713
|
}
|
|
6609
7714
|
}
|
|
6610
|
-
var init_route_types = () => {
|
|
7715
|
+
var init_route_types = __esm(() => {
|
|
7716
|
+
init_router2();
|
|
7717
|
+
});
|
|
6611
7718
|
|
|
6612
7719
|
// src/build/hydrate.ts
|
|
6613
7720
|
var exports_hydrate = {};
|
|
@@ -6634,6 +7741,7 @@ function generateHydrateEntry(routes, rootLayout, basePath, clientLogging) {
|
|
|
6634
7741
|
for (const route of routes) {
|
|
6635
7742
|
const resolvedPage = route.path.replace(/\\/g, "/");
|
|
6636
7743
|
const regexPattern = buildRouteRegex(route.pattern).regex.source;
|
|
7744
|
+
const searchDefaults = collectSearchDefaults(mergeRouteSchemas(route.routeChain ?? [], "query"));
|
|
6637
7745
|
const boundaryIdents = new Map;
|
|
6638
7746
|
const boundaryLiterals = [];
|
|
6639
7747
|
for (const seg of route.segmentBoundaries ?? []) {
|
|
@@ -6658,7 +7766,8 @@ function generateHydrateEntry(routes, rootLayout, basePath, clientLogging) {
|
|
|
6658
7766
|
const loadBody = boundaryLiterals.length > 0 ? `Promise.all([${lazyImports.join(", ")}]).then(([__furin_page, ${[
|
|
6659
7767
|
...boundaryIdents.values()
|
|
6660
7768
|
].join(", ")}]) => ({ default: __furin_page.default, segmentBoundaries: [${boundaryLiterals.join(", ")}] }))` : `import("${resolvedPage}")`;
|
|
6661
|
-
|
|
7769
|
+
const searchDefaultsEntry = searchDefaults ? `, searchDefaults: ${JSON.stringify(searchDefaults)}` : "";
|
|
7770
|
+
routeEntries.push(` { pattern: "${route.pattern}", regex: new RegExp(${JSON.stringify(regexPattern)}), load: () => ${loadBody}${searchDefaultsEntry} }`);
|
|
6662
7771
|
}
|
|
6663
7772
|
const basePathLiteral = JSON.stringify(basePath);
|
|
6664
7773
|
const pathnameExpr = basePath ? `(() => { const p = window.location.pathname; const b = ${basePathLiteral}; const stripped = (p.startsWith(b) && (p.length === b.length || p[b.length] === "/")) ? p.slice(b.length) || "/" : p; return stripped === "/" ? "/" : stripped.replace(/\\/+$/, ""); })()` : `window.location.pathname.replace(/\\/+$/, "") || "/"`;
|
|
@@ -6673,7 +7782,8 @@ import { createHttpLogDrain } from "evlog/http";
|
|
|
6673
7782
|
defaultPreload: "intent",
|
|
6674
7783
|
defaultPreloadDelay: 50,
|
|
6675
7784
|
defaultPreloadStaleTime: 30000,
|
|
6676
|
-
prefetchCacheSize: 50
|
|
7785
|
+
prefetchCacheSize: 50,
|
|
7786
|
+
syncStream,`;
|
|
6677
7787
|
return `import { hydrateRoot, createRoot } from "react-dom/client";
|
|
6678
7788
|
import { createElement } from "react";
|
|
6679
7789
|
${loggingImports}import { RouterProvider } from "@teyik0/furin/link";
|
|
@@ -6700,6 +7810,9 @@ const _match = routes.find((r) => r.regex.test(pathname));
|
|
|
6700
7810
|
// former does not \u2014 so the two cases fork on _match below.
|
|
6701
7811
|
const dataEl = document.getElementById("__FURIN_DATA__");
|
|
6702
7812
|
const loaderData = dataEl ? JSON.parse(dataEl.textContent || "{}") : {};
|
|
7813
|
+
const syncEl = document.getElementById("__FURIN_SYNC__");
|
|
7814
|
+
const syncConfig = syncEl ? JSON.parse(syncEl.textContent || "{}") : {};
|
|
7815
|
+
const syncStream = typeof syncConfig.stream === "string" ? syncConfig.stream : undefined;
|
|
6703
7816
|
|
|
6704
7817
|
// \u2500\u2500 Deferred data hydration \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
6705
7818
|
// window.__FURIN_DEFERRED__ is injected by the server when a loader returns
|
|
@@ -6877,6 +7990,7 @@ function writeDevFiles(routes, { outDir, rootLayout, basePath, clientLogging },
|
|
|
6877
7990
|
}
|
|
6878
7991
|
var init_hydrate = __esm(() => {
|
|
6879
7992
|
init_shell();
|
|
7993
|
+
init_router2();
|
|
6880
7994
|
init_patterns();
|
|
6881
7995
|
init_route_types();
|
|
6882
7996
|
});
|
|
@@ -6888,7 +8002,7 @@ import { existsSync as existsSync5 } from "fs";
|
|
|
6888
8002
|
import { basename, dirname as dirname2, join as join4, resolve as resolve2 } from "path";
|
|
6889
8003
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
6890
8004
|
import { staticPlugin } from "@elysiajs/static";
|
|
6891
|
-
import { Elysia as
|
|
8005
|
+
import { Elysia as Elysia7, file } from "elysia";
|
|
6892
8006
|
|
|
6893
8007
|
// src/server/cache/invalidation.ts
|
|
6894
8008
|
init_context_logger();
|
|
@@ -6966,11 +8080,12 @@ init_ssg();
|
|
|
6966
8080
|
init_render();
|
|
6967
8081
|
init_template();
|
|
6968
8082
|
init_router2();
|
|
6969
|
-
init_boundaries();
|
|
6970
|
-
init_client();
|
|
6971
8083
|
|
|
6972
|
-
// src/server/
|
|
6973
|
-
|
|
8084
|
+
// src/server/sync/index.ts
|
|
8085
|
+
init_config();
|
|
8086
|
+
|
|
8087
|
+
// src/server/sync/plugin.ts
|
|
8088
|
+
import { Elysia as Elysia4 } from "elysia";
|
|
6974
8089
|
|
|
6975
8090
|
// src/server/auto-invalidate/runtime.ts
|
|
6976
8091
|
init_registry();
|
|
@@ -7055,11 +8170,12 @@ function isSuccessfulMutationResponse(ctx) {
|
|
|
7055
8170
|
function appendPendingInvalidationHeader(set) {
|
|
7056
8171
|
const pending = consumePendingInvalidations();
|
|
7057
8172
|
if (pending.length === 0) {
|
|
7058
|
-
return;
|
|
8173
|
+
return [];
|
|
7059
8174
|
}
|
|
7060
8175
|
const headerName = "x-furin-revalidate";
|
|
7061
8176
|
const existing = set.headers[headerName];
|
|
7062
8177
|
set.headers[headerName] = typeof existing === "string" && existing.length > 0 ? `${existing},${pending.join(",")}` : pending.join(",");
|
|
8178
|
+
return pending;
|
|
7063
8179
|
}
|
|
7064
8180
|
function revalidateTag(tags) {
|
|
7065
8181
|
const tagList = typeof tags === "string" ? [tags] : [...tags];
|
|
@@ -7082,9 +8198,207 @@ function runInvalidationRules(input) {
|
|
|
7082
8198
|
return deleted;
|
|
7083
8199
|
}
|
|
7084
8200
|
|
|
8201
|
+
// src/server/sync/stream.ts
|
|
8202
|
+
init_config();
|
|
8203
|
+
import { Elysia as Elysia3 } from "elysia";
|
|
8204
|
+
var encoder = new TextEncoder;
|
|
8205
|
+
var defaultStreamPath = "/_furin/sync";
|
|
8206
|
+
var streams = new Map;
|
|
8207
|
+
function getStreamState(path) {
|
|
8208
|
+
const existing = streams.get(path);
|
|
8209
|
+
if (existing) {
|
|
8210
|
+
return existing;
|
|
8211
|
+
}
|
|
8212
|
+
const state = {
|
|
8213
|
+
clients: new Set,
|
|
8214
|
+
heartbeats: new Set,
|
|
8215
|
+
history: [],
|
|
8216
|
+
nextEventId: 1
|
|
8217
|
+
};
|
|
8218
|
+
streams.set(path, state);
|
|
8219
|
+
return state;
|
|
8220
|
+
}
|
|
8221
|
+
function encodeSseEvent(id, event, data) {
|
|
8222
|
+
return encoder.encode(`id: ${id}
|
|
8223
|
+
event: ${event}
|
|
8224
|
+
retry: 3000
|
|
8225
|
+
data: ${JSON.stringify(data)}
|
|
8226
|
+
|
|
8227
|
+
`);
|
|
8228
|
+
}
|
|
8229
|
+
function publishSyncInvalidation(invalidations) {
|
|
8230
|
+
if (invalidations.length === 0) {
|
|
8231
|
+
return;
|
|
8232
|
+
}
|
|
8233
|
+
const state = getStreamState(getSyncStreamPath() ?? defaultStreamPath);
|
|
8234
|
+
const id = state.nextEventId++;
|
|
8235
|
+
const chunk = encodeSseEvent(id, "furin.invalidate", {
|
|
8236
|
+
invalidations
|
|
8237
|
+
});
|
|
8238
|
+
state.history.push({ chunk, id });
|
|
8239
|
+
if (state.history.length > 100) {
|
|
8240
|
+
state.history.shift();
|
|
8241
|
+
}
|
|
8242
|
+
for (const client of [...state.clients]) {
|
|
8243
|
+
try {
|
|
8244
|
+
client.enqueue(chunk);
|
|
8245
|
+
} catch {
|
|
8246
|
+
state.clients.delete(client);
|
|
8247
|
+
}
|
|
8248
|
+
}
|
|
8249
|
+
}
|
|
8250
|
+
function createSyncStreamPlugin(path) {
|
|
8251
|
+
const streamPath = path ?? defaultStreamPath;
|
|
8252
|
+
return new Elysia3({ name: `furin-sync-stream-${streamPath}` }).get(streamPath, ({ request }) => {
|
|
8253
|
+
const state = getStreamState(streamPath);
|
|
8254
|
+
let controllerRef;
|
|
8255
|
+
let heartbeat;
|
|
8256
|
+
const stream = new ReadableStream({
|
|
8257
|
+
start(controller) {
|
|
8258
|
+
controllerRef = controller;
|
|
8259
|
+
state.clients.add(controller);
|
|
8260
|
+
const lastEventId = Number.parseInt(request.headers.get("Last-Event-ID") ?? "", 10);
|
|
8261
|
+
const oldestEventId = state.history[0]?.id;
|
|
8262
|
+
const hasReplayGap = !Number.isNaN(lastEventId) && oldestEventId !== undefined && lastEventId < oldestEventId - 1;
|
|
8263
|
+
const replay = Number.isNaN(lastEventId) ? [] : state.history.filter((entry) => entry.id > lastEventId);
|
|
8264
|
+
if (hasReplayGap) {
|
|
8265
|
+
controller.enqueue(encodeSseEvent(state.nextEventId - 1, "furin.invalidate", {
|
|
8266
|
+
invalidations: ["/:layout"]
|
|
8267
|
+
}));
|
|
8268
|
+
} else if (replay.length > 0) {
|
|
8269
|
+
for (const entry of replay) {
|
|
8270
|
+
controller.enqueue(entry.chunk);
|
|
8271
|
+
}
|
|
8272
|
+
} else {
|
|
8273
|
+
controller.enqueue(encoder.encode(`: connected
|
|
8274
|
+
retry: 3000
|
|
8275
|
+
|
|
8276
|
+
`));
|
|
8277
|
+
}
|
|
8278
|
+
heartbeat = setInterval(() => {
|
|
8279
|
+
try {
|
|
8280
|
+
controller.enqueue(encoder.encode(`: heartbeat
|
|
8281
|
+
|
|
8282
|
+
`));
|
|
8283
|
+
} catch {
|
|
8284
|
+
state.clients.delete(controller);
|
|
8285
|
+
if (heartbeat) {
|
|
8286
|
+
clearInterval(heartbeat);
|
|
8287
|
+
state.heartbeats.delete(heartbeat);
|
|
8288
|
+
}
|
|
8289
|
+
}
|
|
8290
|
+
}, 15000);
|
|
8291
|
+
state.heartbeats.add(heartbeat);
|
|
8292
|
+
},
|
|
8293
|
+
cancel() {
|
|
8294
|
+
if (controllerRef) {
|
|
8295
|
+
state.clients.delete(controllerRef);
|
|
8296
|
+
}
|
|
8297
|
+
if (heartbeat) {
|
|
8298
|
+
clearInterval(heartbeat);
|
|
8299
|
+
state.heartbeats.delete(heartbeat);
|
|
8300
|
+
}
|
|
8301
|
+
}
|
|
8302
|
+
});
|
|
8303
|
+
return new Response(stream, {
|
|
8304
|
+
headers: {
|
|
8305
|
+
"cache-control": "no-cache, no-transform",
|
|
8306
|
+
connection: "keep-alive",
|
|
8307
|
+
"content-type": "text/event-stream; charset=utf-8"
|
|
8308
|
+
}
|
|
8309
|
+
});
|
|
8310
|
+
});
|
|
8311
|
+
}
|
|
8312
|
+
|
|
8313
|
+
// src/server/sync/plugin.ts
|
|
8314
|
+
function invalidationInputFromSync(input) {
|
|
8315
|
+
if (input && typeof input === "object" && "invalidate" in input) {
|
|
8316
|
+
return input.invalidate;
|
|
8317
|
+
}
|
|
8318
|
+
return input;
|
|
8319
|
+
}
|
|
8320
|
+
function isMutationMethod(method) {
|
|
8321
|
+
return method !== "GET" && method !== "HEAD" && method !== "OPTIONS";
|
|
8322
|
+
}
|
|
8323
|
+
function getIdempotencyKey(ctx) {
|
|
8324
|
+
const fromCtxHeaders = ctx.headers["idempotency-key"];
|
|
8325
|
+
if (typeof fromCtxHeaders === "string" && fromCtxHeaders.length > 0) {
|
|
8326
|
+
return fromCtxHeaders;
|
|
8327
|
+
}
|
|
8328
|
+
const fromRequest = ctx.request.headers.get("Idempotency-Key");
|
|
8329
|
+
return fromRequest || undefined;
|
|
8330
|
+
}
|
|
8331
|
+
function furinSync() {
|
|
8332
|
+
const idempotencyKeys = new Set;
|
|
8333
|
+
const requestKeys = new WeakMap;
|
|
8334
|
+
return new Elysia4({ name: "furin-sync" }).macro({
|
|
8335
|
+
sync(input) {
|
|
8336
|
+
const invalidate = invalidationInputFromSync(input);
|
|
8337
|
+
return {
|
|
8338
|
+
beforeHandle(ctx) {
|
|
8339
|
+
if (!isMutationMethod(ctx.request.method)) {
|
|
8340
|
+
return;
|
|
8341
|
+
}
|
|
8342
|
+
const key = getIdempotencyKey(ctx);
|
|
8343
|
+
if (!key) {
|
|
8344
|
+
return new Response("Missing Idempotency-Key header", {
|
|
8345
|
+
status: 428,
|
|
8346
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
8347
|
+
});
|
|
8348
|
+
}
|
|
8349
|
+
const requestKey = `${ctx.request.method}:${new URL(ctx.request.url).pathname}:${key}`;
|
|
8350
|
+
if (idempotencyKeys.has(requestKey)) {
|
|
8351
|
+
return new Response("Duplicate Idempotency-Key header", {
|
|
8352
|
+
status: 409,
|
|
8353
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
8354
|
+
});
|
|
8355
|
+
}
|
|
8356
|
+
idempotencyKeys.add(requestKey);
|
|
8357
|
+
requestKeys.set(ctx.request, requestKey);
|
|
8358
|
+
if (idempotencyKeys.size > 1000) {
|
|
8359
|
+
const oldest = idempotencyKeys.values().next().value;
|
|
8360
|
+
if (typeof oldest === "string") {
|
|
8361
|
+
idempotencyKeys.delete(oldest);
|
|
8362
|
+
}
|
|
8363
|
+
}
|
|
8364
|
+
},
|
|
8365
|
+
afterHandle(ctx) {
|
|
8366
|
+
if (!isSuccessfulMutationResponse(ctx)) {
|
|
8367
|
+
const requestKey = requestKeys.get(ctx.request);
|
|
8368
|
+
if (requestKey) {
|
|
8369
|
+
idempotencyKeys.delete(requestKey);
|
|
8370
|
+
requestKeys.delete(ctx.request);
|
|
8371
|
+
}
|
|
8372
|
+
return;
|
|
8373
|
+
}
|
|
8374
|
+
requestKeys.delete(ctx.request);
|
|
8375
|
+
runInvalidationRules(invalidate);
|
|
8376
|
+
const pending = appendPendingInvalidationHeader(ctx.set);
|
|
8377
|
+
if (pending.length === 0) {
|
|
8378
|
+
return;
|
|
8379
|
+
}
|
|
8380
|
+
ctx.set.headers["x-furin-sync"] = "1";
|
|
8381
|
+
publishSyncInvalidation(pending);
|
|
8382
|
+
},
|
|
8383
|
+
error({ request }) {
|
|
8384
|
+
const requestKey = requestKeys.get(request);
|
|
8385
|
+
if (requestKey) {
|
|
8386
|
+
idempotencyKeys.delete(requestKey);
|
|
8387
|
+
requestKeys.delete(request);
|
|
8388
|
+
}
|
|
8389
|
+
}
|
|
8390
|
+
};
|
|
8391
|
+
}
|
|
8392
|
+
});
|
|
8393
|
+
}
|
|
8394
|
+
// src/furin.ts
|
|
8395
|
+
init_boundaries();
|
|
8396
|
+
init_client();
|
|
8397
|
+
|
|
7085
8398
|
// src/server/auto-invalidate/plugin.ts
|
|
8399
|
+
import { Elysia as Elysia5 } from "elysia";
|
|
7086
8400
|
function furinInvalidate() {
|
|
7087
|
-
return new
|
|
8401
|
+
return new Elysia5({ name: "furin-invalidate" }).macro({
|
|
7088
8402
|
invalidate(rules) {
|
|
7089
8403
|
return {
|
|
7090
8404
|
afterHandle(ctx) {
|
|
@@ -7193,8 +8507,8 @@ async function setupProdTemplate(embedded, clientDir) {
|
|
|
7193
8507
|
}
|
|
7194
8508
|
setProductionTemplatePath(templatePath);
|
|
7195
8509
|
}
|
|
7196
|
-
function wrapWithRequestScope(app) {
|
|
7197
|
-
return app.wrap((handler, _request) => (ctx) => _runWithRequestInvalidationScope(() => handler(ctx)));
|
|
8510
|
+
function wrapWithRequestScope(app, syncStreamPath) {
|
|
8511
|
+
return app.wrap((handler, _request) => (ctx) => runWithSyncStreamPath(syncStreamPath, () => _runWithRequestInvalidationScope(() => handler(ctx))));
|
|
7198
8512
|
}
|
|
7199
8513
|
function hydrateSSGCacheFromCompileContext(ctx) {
|
|
7200
8514
|
if (!ctx.ssgCache) {
|
|
@@ -7207,17 +8521,20 @@ function hydrateSSGCacheFromCompileContext(ctx) {
|
|
|
7207
8521
|
async function furin({
|
|
7208
8522
|
pagesDir,
|
|
7209
8523
|
logger,
|
|
7210
|
-
clientLogging
|
|
8524
|
+
clientLogging,
|
|
8525
|
+
sync
|
|
7211
8526
|
}) {
|
|
8527
|
+
const syncStreamPath = resolveSyncStreamPath(sync);
|
|
7212
8528
|
const { exclude: userExclude, ...evlogOptions } = logger ?? {};
|
|
7213
8529
|
initLogger({ env: { service: "furin" } });
|
|
7214
|
-
const loggerPlugin = new
|
|
8530
|
+
const loggerPlugin = new Elysia7().use(evlog({
|
|
7215
8531
|
...evlogOptions,
|
|
7216
8532
|
exclude: [
|
|
7217
8533
|
"/_client/**",
|
|
7218
8534
|
"/public/**",
|
|
7219
8535
|
"/favicon.ico",
|
|
7220
8536
|
"/_bun_hmr_entry/**",
|
|
8537
|
+
...syncStreamPath ? [syncStreamPath] : [],
|
|
7221
8538
|
...userExclude ?? []
|
|
7222
8539
|
]
|
|
7223
8540
|
})).post("/_furin/ingest", ({ body, log, status }) => {
|
|
@@ -7256,6 +8573,7 @@ async function furin({
|
|
|
7256
8573
|
const { createDevInspectorPlugin: createDevInspectorPlugin2 } = await Promise.resolve().then(() => (init_dev_inspector(), exports_dev_inspector));
|
|
7257
8574
|
const { scanPages: scanPages2 } = await Promise.resolve().then(() => (init_router2(), exports_router));
|
|
7258
8575
|
const { root: root2, routes: routes2 } = await scanPages2(resolvedPagesDir);
|
|
8576
|
+
const searchRoutes2 = createSearchRouteMetadata(routes2);
|
|
7259
8577
|
const { writeDevFiles: writeDevFiles2 } = await Promise.resolve().then(() => (init_hydrate(), exports_hydrate));
|
|
7260
8578
|
writeDevFiles2(routes2, {
|
|
7261
8579
|
outDir: furinDir,
|
|
@@ -7266,7 +8584,7 @@ async function furin({
|
|
|
7266
8584
|
}, cwd);
|
|
7267
8585
|
const publicDir = resolve2(cwd, "public");
|
|
7268
8586
|
const publicExists = existsSync5(publicDir);
|
|
7269
|
-
const devApp = new
|
|
8587
|
+
const devApp = new Elysia7({ name: instanceName, seed: resolvedPagesDir }).use(loggerPlugin).onError({ as: "global" }, async ({ code, request }) => {
|
|
7270
8588
|
if (code === "NOT_FOUND") {
|
|
7271
8589
|
return await renderRootNotFound(root2, request);
|
|
7272
8590
|
}
|
|
@@ -7275,25 +8593,26 @@ async function furin({
|
|
|
7275
8593
|
if (pending.length > 0) {
|
|
7276
8594
|
set.headers["x-furin-revalidate"] = pending.join(",");
|
|
7277
8595
|
}
|
|
7278
|
-
}).use(await staticPlugin({ assets: furinDir, prefix: "/_bun_hmr_entry", bunFullstack: true })).use(publicExists ? await staticPlugin({ assets: publicDir, prefix: "/public" }) : new
|
|
8596
|
+
}).use(await staticPlugin({ assets: furinDir, prefix: "/_bun_hmr_entry", bunFullstack: true })).use(publicExists ? await staticPlugin({ assets: publicDir, prefix: "/public" }) : new Elysia7).get("/favicon.ico", publicExists ? file(join4(publicDir, "favicon.ico")) : () => new Response(null, { status: 404 })).use(createDevInspectorPlugin2()).use(syncStreamPath ? createSyncStreamPlugin(syncStreamPath) : new Elysia7).use(createDataEndpoint(routes2)).use((app) => {
|
|
7279
8597
|
for (const route of routes2) {
|
|
7280
|
-
app.use(createRoutePlugin(route, root2));
|
|
8598
|
+
app.use(createRoutePlugin(route, root2, undefined, searchRoutes2));
|
|
7281
8599
|
}
|
|
7282
8600
|
return app;
|
|
7283
8601
|
});
|
|
7284
|
-
return wrapWithRequestScope(devApp);
|
|
8602
|
+
return wrapWithRequestScope(devApp, syncStreamPath);
|
|
7285
8603
|
}
|
|
7286
8604
|
if (!ctx) {
|
|
7287
8605
|
throw new Error("[furin] No pre-built assets found. Run `bunx furin build` first.");
|
|
7288
8606
|
}
|
|
7289
8607
|
const { root, routes } = loadProdRoutes(ctx);
|
|
8608
|
+
const searchRoutes = createSearchRouteMetadata(routes);
|
|
7290
8609
|
const prodBuildId = ctx.buildId ?? "";
|
|
7291
8610
|
setBuildId(prodBuildId);
|
|
7292
8611
|
hydrateSSGCacheFromCompileContext(ctx);
|
|
7293
8612
|
const embedded = ctx?.embedded;
|
|
7294
8613
|
const clientDir = embedded ? "" : resolveClientDirFromArgv();
|
|
7295
8614
|
await setupProdTemplate(embedded, clientDir);
|
|
7296
|
-
const prodApp = new
|
|
8615
|
+
const prodApp = new Elysia7({ name: instanceName, seed: resolvedPagesDir }).use(loggerPlugin).onError({ as: "global" }, async ({ code, request }) => {
|
|
7297
8616
|
if (code === "NOT_FOUND") {
|
|
7298
8617
|
return await renderRootNotFound(root, request);
|
|
7299
8618
|
}
|
|
@@ -7314,10 +8633,10 @@ async function furin({
|
|
|
7314
8633
|
return;
|
|
7315
8634
|
}
|
|
7316
8635
|
const origin = server?.url?.origin ?? "http://localhost:3000";
|
|
7317
|
-
await warmSSGCache(routes, root, origin);
|
|
8636
|
+
await warmSSGCache(routes, root, origin, searchRoutes);
|
|
7318
8637
|
}).use(await (async () => {
|
|
7319
8638
|
if (embedded) {
|
|
7320
|
-
return new
|
|
8639
|
+
return new Elysia7().get("/favicon.ico", ({ status }) => {
|
|
7321
8640
|
const asset = embedded.assets["/public/favicon.ico"];
|
|
7322
8641
|
if (!asset) {
|
|
7323
8642
|
return status("Not Found");
|
|
@@ -7338,19 +8657,19 @@ async function furin({
|
|
|
7338
8657
|
});
|
|
7339
8658
|
}
|
|
7340
8659
|
const publicDir = join4(dirname2(clientDir), "public");
|
|
7341
|
-
const app = new
|
|
8660
|
+
const app = new Elysia7;
|
|
7342
8661
|
if (existsSync5(publicDir)) {
|
|
7343
8662
|
app.get("/favicon.ico", file(join4(publicDir, "favicon.ico"))).use(await staticPlugin({ assets: publicDir, prefix: "/public" }));
|
|
7344
8663
|
}
|
|
7345
8664
|
app.use(await staticPlugin({ assets: clientDir, prefix: "/_client" }));
|
|
7346
8665
|
return app;
|
|
7347
|
-
})()).use(createDataEndpoint(routes)).use((app) => {
|
|
8666
|
+
})()).use(syncStreamPath ? createSyncStreamPlugin(syncStreamPath) : new Elysia7).use(createDataEndpoint(routes)).use((app) => {
|
|
7348
8667
|
for (const route of routes) {
|
|
7349
|
-
app.use(createRoutePlugin(route, root, prodBuildId));
|
|
8668
|
+
app.use(createRoutePlugin(route, root, prodBuildId, searchRoutes));
|
|
7350
8669
|
}
|
|
7351
8670
|
return app;
|
|
7352
8671
|
});
|
|
7353
|
-
return wrapWithRequestScope(prodApp);
|
|
8672
|
+
return wrapWithRequestScope(prodApp, syncStreamPath);
|
|
7354
8673
|
}
|
|
7355
8674
|
export {
|
|
7356
8675
|
useAsyncValue,
|
|
@@ -7362,6 +8681,7 @@ export {
|
|
|
7362
8681
|
notFound,
|
|
7363
8682
|
isNotFoundError,
|
|
7364
8683
|
isDeferred,
|
|
8684
|
+
furinSync,
|
|
7365
8685
|
furinInvalidate,
|
|
7366
8686
|
furin,
|
|
7367
8687
|
defer,
|