vinext 0.0.43 → 0.0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/google-fonts/build-url.d.ts +10 -0
- package/dist/build/google-fonts/build-url.js +30 -0
- package/dist/build/google-fonts/build-url.js.map +1 -0
- package/dist/build/google-fonts/font-data.js +24985 -0
- package/dist/build/google-fonts/font-data.js.map +1 -0
- package/dist/build/google-fonts/font-metadata.d.ts +17 -0
- package/dist/build/google-fonts/font-metadata.js +7 -0
- package/dist/build/google-fonts/font-metadata.js.map +1 -0
- package/dist/build/google-fonts/get-axes.d.ts +7 -0
- package/dist/build/google-fonts/get-axes.js +39 -0
- package/dist/build/google-fonts/get-axes.js.map +1 -0
- package/dist/build/google-fonts/sort-variants.d.ts +5 -0
- package/dist/build/google-fonts/sort-variants.js +14 -0
- package/dist/build/google-fonts/sort-variants.js.map +1 -0
- package/dist/build/google-fonts/validate.d.ts +28 -0
- package/dist/build/google-fonts/validate.js +56 -0
- package/dist/build/google-fonts/validate.js.map +1 -0
- package/dist/build/layout-classification.d.ts +1 -1
- package/dist/build/layout-classification.js.map +1 -1
- package/dist/build/nitro-route-rules.d.ts +1 -1
- package/dist/build/nitro-route-rules.js.map +1 -1
- package/dist/build/precompress.d.ts +1 -1
- package/dist/build/precompress.js.map +1 -1
- package/dist/build/prerender.d.ts +1 -7
- package/dist/build/prerender.js +7 -3
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/run-prerender.d.ts +1 -13
- package/dist/build/run-prerender.js +5 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/standalone.d.ts +1 -1
- package/dist/build/standalone.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +1 -3
- package/dist/cloudflare/kv-cache-handler.d.ts +5 -0
- package/dist/cloudflare/kv-cache-handler.js +56 -35
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.d.ts +1 -16
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/dotenv.d.ts +1 -1
- package/dist/config/dotenv.js.map +1 -1
- package/dist/deploy.d.ts +1 -1
- package/dist/deploy.js +21 -4
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.js +93 -15
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.js.map +1 -1
- package/dist/plugins/async-hooks-stub.d.ts +1 -2
- package/dist/plugins/async-hooks-stub.js +2 -2
- package/dist/plugins/async-hooks-stub.js.map +1 -1
- package/dist/plugins/fonts.d.ts +1 -20
- package/dist/plugins/fonts.js +42 -21
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/server-externals-manifest.d.ts +1 -11
- package/dist/plugins/server-externals-manifest.js +1 -1
- package/dist/plugins/server-externals-manifest.js.map +1 -1
- package/dist/routing/app-router.d.ts +2 -1
- package/dist/routing/app-router.js +12 -6
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +1 -3
- package/dist/routing/file-matcher.js +1 -1
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/utils.d.ts +1 -29
- package/dist/routing/utils.js +1 -1
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/app-browser-entry.js +183 -99
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-state.d.ts +1 -1
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-stream.d.ts +1 -1
- package/dist/server/app-browser-stream.js.map +1 -1
- package/dist/server/app-elements.d.ts +1 -2
- package/dist/server/app-elements.js +1 -1
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-page-boundary-render.d.ts +3 -1
- package/dist/server/app-page-boundary-render.js +2 -0
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.d.ts +2 -1
- package/dist/server/app-page-boundary.js +10 -5
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +4 -2
- package/dist/server/app-page-execution.js +19 -4
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-probe.d.ts +1 -1
- package/dist/server/app-page-probe.js.map +1 -1
- package/dist/server/app-page-render.d.ts +2 -2
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +1 -1
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-response.d.ts +1 -1
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +2 -8
- package/dist/server/app-page-route-wiring.js +13 -3
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +2 -1
- package/dist/server/app-page-stream.js +5 -3
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-route-handler-cache.d.ts +1 -1
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +1 -1
- package/dist/server/app-route-handler-execution.js +9 -4
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-policy.d.ts +6 -2
- package/dist/server/app-route-handler-policy.js +8 -3
- package/dist/server/app-route-handler-policy.js.map +1 -1
- package/dist/server/app-route-handler-response.d.ts +1 -1
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-route-handler-runtime.d.ts +1 -1
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-handler-runtime.js.map +1 -1
- package/dist/server/app-router-entry.js +8 -1
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-server-action-execution.d.ts +35 -0
- package/dist/server/app-server-action-execution.js +105 -0
- package/dist/server/app-server-action-execution.js.map +1 -0
- package/dist/server/app-ssr-entry.js +2 -1
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +1 -1
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/csp.d.ts +1 -2
- package/dist/server/csp.js +1 -1
- package/dist/server/csp.js.map +1 -1
- package/dist/server/dev-module-runner.d.ts +1 -1
- package/dist/server/dev-module-runner.js.map +1 -1
- package/dist/server/middleware-request-headers.d.ts +1 -3
- package/dist/server/middleware-request-headers.js +4 -4
- package/dist/server/middleware-request-headers.js.map +1 -1
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +1 -1
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-i18n.d.ts +2 -3
- package/dist/server/pages-i18n.js +1 -1
- package/dist/server/pages-i18n.js.map +1 -1
- package/dist/server/pages-node-compat.d.ts +1 -2
- package/dist/server/pages-node-compat.js +1 -1
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +1 -1
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +1 -1
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prod-server.js +18 -13
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +33 -1
- package/dist/server/request-pipeline.js +44 -2
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/socket-error-backstop.d.ts +17 -0
- package/dist/server/socket-error-backstop.js +129 -0
- package/dist/server/socket-error-backstop.js.map +1 -0
- package/dist/server/static-file-cache.d.ts +1 -1
- package/dist/server/static-file-cache.js.map +1 -1
- package/dist/shims/cache-runtime.js +16 -3
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +3 -1
- package/dist/shims/cache.js +83 -22
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +1 -1
- package/dist/shims/fetch-cache.d.ts +10 -1
- package/dist/shims/fetch-cache.js +24 -4
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/font-google-base.d.ts +16 -18
- package/dist/shims/font-google-base.js +25 -16
- package/dist/shims/font-google-base.js.map +1 -1
- package/dist/shims/form.js +1 -1
- package/dist/shims/link.js +1 -1
- package/dist/shims/navigation.d.ts +7 -3
- package/dist/shims/navigation.js +28 -5
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/server.d.ts +2 -0
- package/dist/shims/server.js +18 -5
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/shims/url-safety.d.ts +3 -1
- package/dist/shims/url-safety.js +5 -1
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/utils/error-cause.d.ts +5 -0
- package/dist/utils/error-cause.js +97 -0
- package/dist/utils/error-cause.js.map +1 -0
- package/dist/utils/lazy-chunks.d.ts +1 -1
- package/dist/utils/lazy-chunks.js.map +1 -1
- package/package.json +1 -1
- package/dist/client/entry.d.ts +0 -1
- package/dist/client/entry.js +0 -60
- package/dist/client/entry.js.map +0 -1
package/dist/shims/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":[],"sources":["../../src/shims/server.ts"],"sourcesContent":["/**\n * next/server shim\n *\n * Provides NextRequest, NextResponse, and related types that work with\n * standard Web APIs (Request/Response). This means they work on Node,\n * Cloudflare Workers, Deno, and any WinterCG-compatible runtime.\n *\n * This is a pragmatic subset — we implement the most commonly used APIs\n * rather than bug-for-bug parity with Next.js internals.\n */\n\nimport { encodeMiddlewareRequestHeaders } from \"../server/middleware-request-headers.js\";\nimport { parseCookieHeader } from \"./internal/parse-cookie-header.js\";\nimport { getRequestExecutionContext } from \"./request-context.js\";\n\n// ---------------------------------------------------------------------------\n// Inlined cache-scope guard for after()\n//\n// We cannot statically import throwIfInsideCacheScope from headers.ts here\n// because headers.ts contains the \"use cache\" directive string in its error\n// message, which causes Vite's use-cache transform to include it in the module\n// graph. If headers.ts is pulled in via static import from server.ts, the\n// transform fires on it in Pages Router fixtures that lack @vitejs/plugin-rsc.\n//\n// The connection() function in this file avoids the same problem by using\n// `await import(\"./headers.js\")` (dynamic import, async function). after()\n// must remain synchronous, so we inline the check using the same Symbol.for\n// keys that cache-runtime.ts and cache.ts register their ALS instances with.\n// ---------------------------------------------------------------------------\n\nconst _USE_CACHE_ALS_KEY = Symbol.for(\"vinext.cacheRuntime.contextAls\");\nconst _UNSTABLE_CACHE_ALS_KEY = Symbol.for(\"vinext.unstableCache.als\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\n\nfunction _throwIfInsideCacheScope(apiName: string): void {\n const cacheAls = _g[_USE_CACHE_ALS_KEY] as { getStore(): unknown } | undefined;\n if (cacheAls?.getStore() != null) {\n throw new Error(\n `\\`${apiName}\\` cannot be called inside \"use cache\". ` +\n `If you need this data inside a cached function, call \\`${apiName}\\` ` +\n \"outside and pass the required data as an argument.\",\n );\n }\n const unstableAls = _g[_UNSTABLE_CACHE_ALS_KEY] as { getStore(): unknown } | undefined;\n if (unstableAls?.getStore() === true) {\n throw new Error(\n `\\`${apiName}\\` cannot be called inside a function cached with \\`unstable_cache()\\`. ` +\n `If you need this data inside a cached function, call \\`${apiName}\\` ` +\n \"outside and pass the required data as an argument.\",\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextRequest\n// ---------------------------------------------------------------------------\n\nexport class NextRequest extends Request {\n private _nextUrl: NextURL;\n private _cookies: RequestCookies;\n\n constructor(\n input: URL | RequestInfo,\n init?: RequestInit & {\n nextConfig?: {\n basePath?: string;\n i18n?: { locales: string[]; defaultLocale: string };\n };\n },\n ) {\n // Strip nextConfig before passing to super() — it's vinext-internal,\n // not a valid RequestInit property.\n const { nextConfig: _nextConfig, ...requestInit } = init ?? {};\n // Handle the case where input is a Request object - we need to extract URL and init\n // to avoid Node.js undici issues with passing Request objects directly to super()\n if (input instanceof Request) {\n const req = input;\n super(req.url, {\n method: req.method,\n headers: req.headers,\n body: req.body,\n // @ts-expect-error - duplex is not in RequestInit type but needed for streams\n duplex: req.body ? \"half\" : undefined,\n ...requestInit,\n });\n } else {\n super(input, requestInit);\n }\n const url =\n typeof input === \"string\"\n ? new URL(input, \"http://localhost\")\n : input instanceof URL\n ? input\n : new URL(input.url, \"http://localhost\");\n const urlConfig: NextURLConfig | undefined = _nextConfig\n ? { basePath: _nextConfig.basePath, nextConfig: { i18n: _nextConfig.i18n } }\n : undefined;\n this._nextUrl = new NextURL(url, undefined, urlConfig);\n this._cookies = new RequestCookies(this.headers);\n }\n\n get nextUrl(): NextURL {\n return this._nextUrl;\n }\n\n get cookies(): RequestCookies {\n return this._cookies;\n }\n\n /**\n * Client IP address. Prefers Cloudflare's trusted CF-Connecting-IP header\n * over the spoofable X-Forwarded-For. Returns undefined if unavailable.\n */\n get ip(): string | undefined {\n return (\n this.headers.get(\"cf-connecting-ip\") ??\n this.headers.get(\"x-real-ip\") ??\n this.headers.get(\"x-forwarded-for\")?.split(\",\")[0]?.trim() ??\n undefined\n );\n }\n\n /**\n * Geolocation data. Platform-dependent (e.g., Cloudflare, Vercel).\n * Returns undefined if not available.\n */\n get geo():\n | { city?: string; country?: string; region?: string; latitude?: string; longitude?: string }\n | undefined {\n // Check Cloudflare-style headers, Vercel-style headers\n const country =\n this.headers.get(\"cf-ipcountry\") ?? this.headers.get(\"x-vercel-ip-country\") ?? undefined;\n if (!country) return undefined;\n return {\n country,\n city: this.headers.get(\"cf-ipcity\") ?? this.headers.get(\"x-vercel-ip-city\") ?? undefined,\n region:\n this.headers.get(\"cf-region\") ??\n this.headers.get(\"x-vercel-ip-country-region\") ??\n undefined,\n latitude:\n this.headers.get(\"cf-iplatitude\") ?? this.headers.get(\"x-vercel-ip-latitude\") ?? undefined,\n longitude:\n this.headers.get(\"cf-iplongitude\") ??\n this.headers.get(\"x-vercel-ip-longitude\") ??\n undefined,\n };\n }\n\n /**\n * The build ID of the Next.js application.\n * Delegates to `nextUrl.buildId` to match Next.js API surface.\n * Can be used in middleware to detect deployment skew between client and server.\n */\n get buildId(): string | undefined {\n return this._nextUrl.buildId;\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextResponse\n// ---------------------------------------------------------------------------\n\n/** Valid HTTP redirect status codes, matching Next.js's REDIRECTS set. */\nconst REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\nexport class NextResponse<_Body = unknown> extends Response {\n private _cookies: ResponseCookies;\n\n constructor(body?: BodyInit | null, init?: ResponseInit) {\n super(body, init);\n this._cookies = new ResponseCookies(this.headers);\n }\n\n get cookies(): ResponseCookies {\n return this._cookies;\n }\n\n /**\n * Create a JSON response.\n */\n static json<JsonBody>(body: JsonBody, init?: ResponseInit): NextResponse<JsonBody> {\n const headers = new Headers(init?.headers);\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n return new NextResponse(JSON.stringify(body), {\n ...init,\n headers,\n }) as NextResponse<JsonBody>;\n }\n\n /**\n * Create a redirect response.\n */\n static redirect(url: string | URL, init?: number | ResponseInit): NextResponse {\n const status = typeof init === \"number\" ? init : (init?.status ?? 307);\n if (!REDIRECT_STATUSES.has(status)) {\n throw new RangeError(`Failed to execute \"redirect\" on \"response\": Invalid status code`);\n }\n const destination = typeof url === \"string\" ? url : url.toString();\n const headers = new Headers(typeof init === \"object\" ? init?.headers : undefined);\n headers.set(\"Location\", destination);\n return new NextResponse(null, { status, headers });\n }\n\n /**\n * Create a rewrite response (middleware pattern).\n * Sets the x-middleware-rewrite header.\n */\n static rewrite(destination: string | URL, init?: MiddlewareResponseInit): NextResponse {\n const url = typeof destination === \"string\" ? destination : destination.toString();\n const headers = new Headers(init?.headers);\n headers.set(\"x-middleware-rewrite\", url);\n if (init?.request?.headers) {\n encodeMiddlewareRequestHeaders(headers, init.request.headers);\n }\n return new NextResponse(null, { ...init, headers });\n }\n\n /**\n * Continue to the next handler (middleware pattern).\n * Sets the x-middleware-next header.\n */\n static next(init?: MiddlewareResponseInit): NextResponse {\n const headers = new Headers(init?.headers);\n headers.set(\"x-middleware-next\", \"1\");\n if (init?.request?.headers) {\n encodeMiddlewareRequestHeaders(headers, init.request.headers);\n }\n return new NextResponse(null, { ...init, headers });\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextURL — lightweight URL wrapper with pathname helpers\n// ---------------------------------------------------------------------------\n\nexport type NextURLConfig = {\n basePath?: string;\n nextConfig?: {\n i18n?: {\n locales: string[];\n defaultLocale: string;\n };\n };\n};\n\nexport class NextURL {\n /** Internal URL stores the pathname WITHOUT basePath or locale prefix. */\n private _url: URL;\n private _basePath: string;\n private _locale: string | undefined;\n private _defaultLocale: string | undefined;\n private _locales: string[] | undefined;\n\n constructor(input: string | URL, base?: string | URL, config?: NextURLConfig) {\n this._url = new URL(input.toString(), base);\n this._basePath = config?.basePath ?? \"\";\n this._stripBasePath();\n const i18n = config?.nextConfig?.i18n;\n if (i18n) {\n this._locales = [...i18n.locales];\n this._defaultLocale = i18n.defaultLocale;\n this._analyzeLocale(this._locales);\n }\n }\n\n /** Strip basePath prefix from the internal pathname. */\n private _stripBasePath(): void {\n if (!this._basePath) return;\n const { pathname } = this._url;\n if (pathname === this._basePath || pathname.startsWith(this._basePath + \"/\")) {\n this._url.pathname = pathname.slice(this._basePath.length) || \"/\";\n }\n }\n\n /** Extract locale from pathname, stripping it from the internal URL. */\n private _analyzeLocale(locales: string[]): void {\n const segments = this._url.pathname.split(\"/\");\n const candidate = segments[1]?.toLowerCase();\n const match = locales.find((l) => l.toLowerCase() === candidate);\n if (match) {\n this._locale = match;\n this._url.pathname = \"/\" + segments.slice(2).join(\"/\");\n } else {\n this._locale = this._defaultLocale;\n }\n }\n\n /**\n * Reconstruct the full pathname with basePath + locale prefix.\n * Mirrors Next.js's internal formatPathname().\n */\n private _formatPathname(): string {\n // Build prefix: basePath + locale (skip defaultLocale — Next.js omits it)\n let prefix = this._basePath;\n if (this._locale && this._locale !== this._defaultLocale) {\n prefix += \"/\" + this._locale;\n }\n if (!prefix) return this._url.pathname;\n const inner = this._url.pathname;\n return inner === \"/\" ? prefix : prefix + inner;\n }\n\n get href(): string {\n const formatted = this._formatPathname();\n if (formatted === this._url.pathname) return this._url.href;\n // Replace pathname in href via string slicing — avoids URL allocation.\n // URL.href is always <origin+auth><pathname><search><hash>.\n const { href, pathname, search, hash } = this._url;\n const baseEnd = href.length - pathname.length - search.length - hash.length;\n return href.slice(0, baseEnd) + formatted + search + hash;\n }\n set href(value: string) {\n this._url.href = value;\n this._stripBasePath();\n if (this._locales) this._analyzeLocale(this._locales);\n }\n\n get origin(): string {\n return this._url.origin;\n }\n\n get protocol(): string {\n return this._url.protocol;\n }\n set protocol(value: string) {\n this._url.protocol = value;\n }\n\n get username(): string {\n return this._url.username;\n }\n set username(value: string) {\n this._url.username = value;\n }\n\n get password(): string {\n return this._url.password;\n }\n set password(value: string) {\n this._url.password = value;\n }\n\n get host(): string {\n return this._url.host;\n }\n set host(value: string) {\n this._url.host = value;\n }\n\n get hostname(): string {\n return this._url.hostname;\n }\n set hostname(value: string) {\n this._url.hostname = value;\n }\n\n get port(): string {\n return this._url.port;\n }\n set port(value: string) {\n this._url.port = value;\n }\n\n /** Returns the pathname WITHOUT basePath or locale prefix. */\n get pathname(): string {\n return this._url.pathname;\n }\n set pathname(value: string) {\n this._url.pathname = value;\n }\n\n get search(): string {\n return this._url.search;\n }\n set search(value: string) {\n this._url.search = value;\n }\n\n get searchParams(): URLSearchParams {\n return this._url.searchParams;\n }\n\n get hash(): string {\n return this._url.hash;\n }\n set hash(value: string) {\n this._url.hash = value;\n }\n\n get basePath(): string {\n return this._basePath;\n }\n set basePath(value: string) {\n this._basePath = value === \"\" ? \"\" : value.startsWith(\"/\") ? value : \"/\" + value;\n }\n\n get locale(): string {\n return this._locale ?? \"\";\n }\n set locale(value: string | undefined) {\n if (this._locales) {\n if (!value) {\n this._locale = this._defaultLocale;\n return;\n }\n if (!this._locales.includes(value)) {\n throw new TypeError(\n `The locale \"${value}\" is not in the configured locales: ${this._locales.join(\", \")}`,\n );\n }\n }\n this._locale = this._locales ? value : this._locale;\n }\n\n get defaultLocale(): string | undefined {\n return this._defaultLocale;\n }\n\n get locales(): string[] | undefined {\n return this._locales ? [...this._locales] : undefined;\n }\n\n clone(): NextURL {\n const config: NextURLConfig = {\n basePath: this._basePath,\n nextConfig: this._locales\n ? { i18n: { locales: [...this._locales], defaultLocale: this._defaultLocale! } }\n : undefined,\n };\n // Pass the full href (with locale/basePath re-added) so the constructor\n // can re-analyze and extract locale correctly.\n return new NextURL(this.href, undefined, config);\n }\n\n toString(): string {\n return this.href;\n }\n\n /**\n * The build ID of the Next.js application.\n * Set from `generateBuildId` in next.config.js, or a random UUID if not configured.\n * Can be used in middleware to detect deployment skew between client and server.\n * Matches the Next.js API: `request.nextUrl.buildId`.\n */\n get buildId(): string | undefined {\n return process.env.__VINEXT_BUILD_ID ?? undefined;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cookie helpers (minimal implementations)\n// ---------------------------------------------------------------------------\n\ntype CookieEntry = {\n name: string;\n value: string;\n};\n\nexport class RequestCookies {\n private _headers: Headers;\n private _parsed: Map<string, string>;\n\n constructor(headers: Headers) {\n this._headers = headers;\n this._parsed = parseCookieHeader(headers.get(\"cookie\") ?? \"\");\n }\n\n get(name: string): CookieEntry | undefined {\n const value = this._parsed.get(name);\n return value !== undefined ? { name, value } : undefined;\n }\n\n getAll(nameOrOptions?: string | CookieEntry): CookieEntry[] {\n const name = typeof nameOrOptions === \"string\" ? nameOrOptions : nameOrOptions?.name;\n return [...this._parsed.entries()]\n .filter(([cookieName]) => name === undefined || cookieName === name)\n .map(([cookieName, value]) => ({ name: cookieName, value }));\n }\n\n has(name: string): boolean {\n return this._parsed.has(name);\n }\n\n set(nameOrOptions: string | CookieEntry, value?: string): this {\n let cookieName: string;\n let cookieValue: string;\n if (typeof nameOrOptions === \"string\") {\n cookieName = nameOrOptions;\n cookieValue = value ?? \"\";\n } else {\n cookieName = nameOrOptions.name;\n cookieValue = nameOrOptions.value;\n }\n validateCookieName(cookieName);\n this._parsed.set(cookieName, cookieValue);\n this._syncHeader();\n return this;\n }\n\n delete(names: string | string[]): boolean | boolean[] {\n if (Array.isArray(names)) {\n const results = names.map((name) => {\n validateCookieName(name);\n return this._parsed.delete(name);\n });\n this._syncHeader();\n return results;\n }\n validateCookieName(names);\n const result = this._parsed.delete(names);\n this._syncHeader();\n return result;\n }\n\n clear(): this {\n this._parsed.clear();\n this._syncHeader();\n return this;\n }\n\n get size(): number {\n return this._parsed.size;\n }\n\n toString(): string {\n return this._serialize();\n }\n\n private _serialize(): string {\n return [...this._parsed.entries()].map(([n, v]) => `${n}=${encodeURIComponent(v)}`).join(\"; \");\n }\n\n private _syncHeader(): void {\n if (this._parsed.size === 0) {\n this._headers.delete(\"cookie\");\n } else {\n this._headers.set(\"cookie\", this._serialize());\n }\n }\n\n [Symbol.iterator](): IterableIterator<[string, CookieEntry]> {\n const entries = this.getAll().map((c) => [c.name, c] as [string, CookieEntry]);\n return entries[Symbol.iterator]();\n }\n}\n\n/**\n * RFC 6265 §4.1.1: cookie-name is a token (RFC 2616 §2.2).\n * Allowed: any visible ASCII (0x21-0x7E) except separators: ()<>@,;:\\\"/[]?={}\n */\nconst VALID_COOKIE_NAME_RE =\n /^[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2E\\x30-\\x39\\x41-\\x5A\\x5E-\\x7A\\x7C\\x7E]+$/;\n\nfunction validateCookieName(name: string): void {\n if (!name || !VALID_COOKIE_NAME_RE.test(name)) {\n throw new Error(`Invalid cookie name: ${JSON.stringify(name)}`);\n }\n}\n\nfunction validateCookieAttributeValue(value: string, attributeName: string): void {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code <= 0x1f || code === 0x7f || value[i] === \";\") {\n throw new Error(`Invalid cookie ${attributeName} value: ${JSON.stringify(value)}`);\n }\n }\n}\n\nexport class ResponseCookies {\n private _headers: Headers;\n /** Internal map keyed by cookie name — single source of truth. */\n private _parsed: Map<string, { serialized: string; entry: CookieEntry }> = new Map();\n\n constructor(headers: Headers) {\n this._headers = headers;\n\n // Hydrate internal map from any existing Set-Cookie headers\n for (const header of headers.getSetCookie()) {\n const eq = header.indexOf(\"=\");\n if (eq === -1) continue;\n const cookieName = header.slice(0, eq);\n const semi = header.indexOf(\";\", eq);\n const raw = header.slice(eq + 1, semi === -1 ? undefined : semi);\n let value: string;\n try {\n value = decodeURIComponent(raw);\n } catch {\n value = raw;\n }\n this._parsed.set(cookieName, { serialized: header, entry: { name: cookieName, value } });\n }\n }\n\n set(\n ...args:\n | [name: string, value: string, options?: CookieOptions]\n | [options: CookieOptions & { name: string; value: string }]\n ): this {\n const [name, value, opts] = parseCookieSetArgs(args);\n validateCookieName(name);\n\n const parts = [`${name}=${encodeURIComponent(value)}`];\n const path = opts?.path ?? \"/\";\n validateCookieAttributeValue(path, \"Path\");\n parts.push(`Path=${path}`);\n if (opts?.domain) {\n validateCookieAttributeValue(opts.domain, \"Domain\");\n parts.push(`Domain=${opts.domain}`);\n }\n if (opts?.maxAge !== undefined) parts.push(`Max-Age=${opts.maxAge}`);\n if (opts?.expires) parts.push(`Expires=${opts.expires.toUTCString()}`);\n if (opts?.httpOnly) parts.push(\"HttpOnly\");\n if (opts?.secure) parts.push(\"Secure\");\n if (opts?.sameSite) parts.push(`SameSite=${opts.sameSite}`);\n\n this._parsed.set(name, { serialized: parts.join(\"; \"), entry: { name, value } });\n this._syncHeaders();\n return this;\n }\n\n get(...args: [name: string] | [options: { name: string }]): CookieEntry | undefined {\n const key = typeof args[0] === \"string\" ? args[0] : args[0].name;\n return this._parsed.get(key)?.entry;\n }\n\n has(name: string): boolean {\n return this._parsed.has(name);\n }\n\n getAll(...args: [name: string] | [options: { name: string }] | []): CookieEntry[] {\n const all = [...this._parsed.values()].map((v) => v.entry);\n if (args.length === 0) return all;\n const key = typeof args[0] === \"string\" ? args[0] : args[0].name;\n return all.filter((c) => c.name === key);\n }\n\n delete(\n ...args:\n | [name: string]\n | [options: Omit<CookieOptions & { name: string }, \"maxAge\" | \"expires\">]\n ): this {\n const [name, opts] =\n typeof args[0] === \"string\" ? [args[0], undefined] : [args[0].name, args[0]];\n return this.set({\n name,\n value: \"\",\n expires: new Date(0),\n path: opts?.path,\n domain: opts?.domain,\n httpOnly: opts?.httpOnly,\n secure: opts?.secure,\n sameSite: opts?.sameSite,\n });\n }\n\n [Symbol.iterator](): IterableIterator<[string, CookieEntry]> {\n const entries: [string, CookieEntry][] = [...this._parsed.values()].map((v) => [\n v.entry.name,\n v.entry,\n ]);\n return entries[Symbol.iterator]();\n }\n\n /** Delete all Set-Cookie headers and re-append from the internal map. */\n private _syncHeaders(): void {\n this._headers.delete(\"Set-Cookie\");\n for (const { serialized } of this._parsed.values()) {\n this._headers.append(\"Set-Cookie\", serialized);\n }\n }\n}\n\ntype CookieOptions = {\n path?: string;\n domain?: string;\n maxAge?: number;\n expires?: Date;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n};\n\n/**\n * Parse the overloaded arguments for ResponseCookies.set():\n * - (name, value, options?) — positional form\n * - ({ name, value, ...options }) — object form\n */\nfunction parseCookieSetArgs(\n args:\n | [name: string, value: string, options?: CookieOptions]\n | [options: CookieOptions & { name: string; value: string }],\n): [string, string, CookieOptions | undefined] {\n if (typeof args[0] === \"string\") {\n return [args[0], args[1] as string, args[2] as CookieOptions | undefined];\n }\n const { name, value, ...opts } = args[0];\n return [name, value, opts as CookieOptions];\n}\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport type MiddlewareResponseInit = {\n request?: {\n headers?: Headers;\n };\n} & ResponseInit;\n\nexport type NextMiddlewareResult = NextResponse | Response | null | undefined | void;\n\nexport type NextMiddleware = (\n request: NextRequest,\n event: NextFetchEvent,\n) => NextMiddlewareResult | Promise<NextMiddlewareResult>;\n\n/**\n * Minimal NextFetchEvent — extends FetchEvent where available,\n * otherwise provides the waitUntil pattern standalone.\n */\nexport class NextFetchEvent {\n sourcePage: string;\n private _waitUntilPromises: Promise<unknown>[] = [];\n\n constructor(params: { page: string }) {\n this.sourcePage = params.page;\n }\n\n waitUntil(promise: Promise<unknown>): void {\n this._waitUntilPromises.push(promise);\n }\n\n get waitUntilPromises(): Promise<unknown>[] {\n return this._waitUntilPromises;\n }\n\n /** Drain all waitUntil promises. Returns a single promise that settles when all are done. */\n drainWaitUntil(): Promise<PromiseSettledResult<unknown>[]> {\n return Promise.allSettled(this._waitUntilPromises);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Utility exports\n// ---------------------------------------------------------------------------\n\n/**\n * Parse user agent string. Minimal implementation — for full UA parsing,\n * apps should use a dedicated library like `ua-parser-js`.\n */\nexport function userAgentFromString(ua: string | undefined): UserAgent {\n const input = ua ?? \"\";\n return {\n isBot: /bot|crawler|spider|crawling/i.test(input),\n ua: input,\n browser: {},\n device: {},\n engine: {},\n os: {},\n cpu: {},\n };\n}\n\nexport function userAgent({ headers }: { headers: Headers }): UserAgent {\n return userAgentFromString(headers.get(\"user-agent\") ?? undefined);\n}\n\nexport type UserAgent = {\n isBot: boolean;\n ua: string;\n browser: { name?: string; version?: string; major?: string };\n device: { model?: string; type?: string; vendor?: string };\n engine: { name?: string; version?: string };\n os: { name?: string; version?: string };\n cpu: { architecture?: string };\n};\n\n/**\n * after() — schedule work after the response is sent.\n *\n * Uses the platform's `waitUntil` (via the per-request ExecutionContext) when\n * available so the task survives past the response on Cloudflare Workers.\n * Falls back to a fire-and-forget microtask on runtimes without an execution\n * context (e.g. Node.js dev server).\n *\n * Throws when called inside a cached scope — request-specific\n * side-effects must not leak into cached results.\n */\nexport function after<T>(task: Promise<T> | (() => T | Promise<T>)): void {\n _throwIfInsideCacheScope(\"after()\");\n\n const promise = typeof task === \"function\" ? Promise.resolve().then(task) : task;\n // NOTE: vinext runs function tasks concurrently with response streaming (next microtask),\n // whereas Next.js queues them to run strictly after the response is sent via onClose.\n // This is a known simplification — function tasks here are not guaranteed to run\n // after the response completes, only after the current synchronous execution.\n //\n // `.catch()` is attached synchronously in the same tick as `promise` is created, so\n // there is no window where a pre-rejected `task` promise could trigger an\n // `unhandledrejection` event before the handler is in place.\n const guarded = promise.catch((err) => {\n console.error(\"[vinext] after() task failed:\", err);\n });\n\n // TODO: Next.js throws when after() is called outside a request context or when\n // waitUntil is unavailable, preventing silent task loss. vinext falls back to\n // fire-and-forget here, which is correct for the Node.js dev server (where\n // getRequestExecutionContext() always returns null). On Workers, a misconfigured\n // entry that omits runWithExecutionContext would silently drop tasks — consider\n // a one-time console.warn on the fallback path, gated to production only (e.g.\n // `process.env.NODE_ENV === 'production'` or `typeof caches !== 'undefined'` for\n // a Workers runtime check) with a module-level `let _warned = false` guard so it\n // fires at most once and doesn't spam the dev-server console.\n getRequestExecutionContext()?.waitUntil(guarded);\n}\n\n/**\n * connection() — signals that the response requires a live connection\n * (not a static/cached response). Opts the page out of ISR caching\n * and sets Cache-Control: no-store on the response.\n */\nexport async function connection(): Promise<void> {\n const { markDynamicUsage, throwIfInsideCacheScope } = await import(\"./headers.js\");\n throwIfInsideCacheScope(\"connection()\");\n markDynamicUsage();\n}\n\n/**\n * URLPattern re-export — used in middleware for route matching.\n * Available natively in Node 20+, Cloudflare Workers, Deno.\n * Falls back to urlpattern-polyfill if the global is not available.\n */\nexport const URLPattern: typeof globalThis.URLPattern =\n globalThis.URLPattern ??\n (() => {\n throw new Error(\n \"URLPattern is not available in this runtime. \" +\n \"Install the `urlpattern-polyfill` package or upgrade to Node 20+.\",\n );\n });\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAM,qBAAqB,OAAO,IAAI,iCAAiC;AACvE,MAAM,0BAA0B,OAAO,IAAI,2BAA2B;AACtE,MAAM,KAAK;AAEX,SAAS,yBAAyB,SAAuB;AAEvD,KADiB,GAAG,qBACN,UAAU,IAAI,KAC1B,OAAM,IAAI,MACR,KAAK,QAAQ,iGAC+C,QAAQ,uDAErE;AAGH,KADoB,GAAG,0BACN,UAAU,KAAK,KAC9B,OAAM,IAA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;;CAId,iBAA2D;AACzD,SAAO,QAAQ,WAAW,KAAK,mBAAmB;;;;;;;AAYtD,SAAgB,oBAAoB,IAAmC;CACrE,MAAM,QAAQ,MAAM;AACpB,QAAO;EACL,OAAO,+BAA+B,KAAK,MAAM;EACjD,IAAI;EACJ,SAAS,EAAE;EACX,QAAQ,EAAE;EACV,QAAQ,EAAE;EACV,IAAI,EAAE;EACN,KAAK,EAAE;EACR;;AAGH,SAAgB,UAAU,EAAE,WAA4C;AACtE,QAAO,oBAAoB,QAAQ,IAAI,aAAa,IAAI,KAAA,EAAU;;;;;;;;;;;;;AAwBpE,SAAgB,MAAS,MAAiD;AACxE,0BAAyB,UAAU;CAWnC,MAAM,WATU,OAAO,SAAS,aAAa,QAAQ,SAAS,CAAC,KAAK,KAAK,GAAG,MASpD,OAAO,QAAQ;AACrC,UAAQ,MAAM,iCAAiC,IAAI;GACnD;AAWF,6BAA4B,EAAE,UAAU,QAAQ;;;;;;;AAQlD,eAAsB,aAA4B;CAChD,MAAM,EAAE,kBAAkB,4BAA4B,MAAM,OAAO;AACnE,yBAAwB,eAAe;AACvC,mBAAkB;;;;;;;AAQpB,MAAa,aACX,WAAW,qBACJ;AACL,OAAM,IAAI,MACR,iHAED"}
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../../src/shims/server.ts"],"sourcesContent":["/**\n * next/server shim\n *\n * Provides NextRequest, NextResponse, and related types that work with\n * standard Web APIs (Request/Response). This means they work on Node,\n * Cloudflare Workers, Deno, and any WinterCG-compatible runtime.\n *\n * This is a pragmatic subset — we implement the most commonly used APIs\n * rather than bug-for-bug parity with Next.js internals.\n */\n\nimport { encodeMiddlewareRequestHeaders } from \"../server/middleware-request-headers.js\";\nimport { parseCookieHeader } from \"./internal/parse-cookie-header.js\";\nimport { getRequestExecutionContext } from \"./request-context.js\";\nimport { assertSafeNavigationUrl } from \"./url-safety.js\";\n\n// ---------------------------------------------------------------------------\n// Inlined cache-scope guard for after()\n//\n// We cannot statically import throwIfInsideCacheScope from headers.ts here\n// because headers.ts contains the \"use cache\" directive string in its error\n// message, which causes Vite's use-cache transform to include it in the module\n// graph. If headers.ts is pulled in via static import from server.ts, the\n// transform fires on it in Pages Router fixtures that lack @vitejs/plugin-rsc.\n//\n// The connection() function in this file avoids the same problem by using\n// `await import(\"./headers.js\")` (dynamic import, async function). after()\n// must remain synchronous, so we inline the check using the same Symbol.for\n// keys that cache-runtime.ts and cache.ts register their ALS instances with.\n// ---------------------------------------------------------------------------\n\nconst _USE_CACHE_ALS_KEY = Symbol.for(\"vinext.cacheRuntime.contextAls\");\nconst _UNSTABLE_CACHE_ALS_KEY = Symbol.for(\"vinext.unstableCache.als\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\n\nfunction _throwIfInsideCacheScope(apiName: string): void {\n const cacheAls = _g[_USE_CACHE_ALS_KEY] as { getStore(): unknown } | undefined;\n if (cacheAls?.getStore() != null) {\n throw new Error(\n `\\`${apiName}\\` cannot be called inside \"use cache\". ` +\n `If you need this data inside a cached function, call \\`${apiName}\\` ` +\n \"outside and pass the required data as an argument.\",\n );\n }\n const unstableAls = _g[_UNSTABLE_CACHE_ALS_KEY] as { getStore(): unknown } | undefined;\n if (unstableAls?.getStore() === true) {\n throw new Error(\n `\\`${apiName}\\` cannot be called inside a function cached with \\`unstable_cache()\\`. ` +\n `If you need this data inside a cached function, call \\`${apiName}\\` ` +\n \"outside and pass the required data as an argument.\",\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextRequest\n// ---------------------------------------------------------------------------\n\nexport class NextRequest extends Request {\n private _nextUrl: NextURL;\n private _url: string;\n private _cookies: RequestCookies;\n\n constructor(\n input: URL | RequestInfo,\n init?: RequestInit & {\n nextConfig?: {\n basePath?: string;\n i18n?: { locales: string[]; defaultLocale: string };\n };\n },\n ) {\n // Strip nextConfig before passing to super() — it's vinext-internal,\n // not a valid RequestInit property.\n const { nextConfig: _nextConfig, ...requestInit } = init ?? {};\n // Handle the case where input is a Request object - we need to extract URL and init\n // to avoid Node.js undici issues with passing Request objects directly to super()\n if (input instanceof Request) {\n const req = input;\n super(req.url, {\n method: req.method,\n headers: req.headers,\n body: req.body,\n // @ts-expect-error - duplex is not in RequestInit type but needed for streams\n duplex: req.body ? \"half\" : undefined,\n ...requestInit,\n });\n } else {\n super(input, requestInit);\n }\n const url =\n typeof input === \"string\"\n ? new URL(input, \"http://localhost\")\n : input instanceof URL\n ? input\n : new URL(input.url, \"http://localhost\");\n const urlConfig: NextURLConfig | undefined = _nextConfig\n ? { basePath: _nextConfig.basePath, nextConfig: { i18n: _nextConfig.i18n } }\n : undefined;\n this._nextUrl = new NextURL(url, undefined, urlConfig);\n this._url = process.env.__NEXT_NO_MIDDLEWARE_URL_NORMALIZE\n ? url.toString()\n : this._nextUrl.toString();\n this._cookies = new RequestCookies(this.headers);\n }\n\n get nextUrl(): NextURL {\n return this._nextUrl;\n }\n\n get url(): string {\n return this._url;\n }\n\n get cookies(): RequestCookies {\n return this._cookies;\n }\n\n /**\n * Client IP address. Prefers Cloudflare's trusted CF-Connecting-IP header\n * over the spoofable X-Forwarded-For. Returns undefined if unavailable.\n */\n get ip(): string | undefined {\n return (\n this.headers.get(\"cf-connecting-ip\") ??\n this.headers.get(\"x-real-ip\") ??\n this.headers.get(\"x-forwarded-for\")?.split(\",\")[0]?.trim() ??\n undefined\n );\n }\n\n /**\n * Geolocation data. Platform-dependent (e.g., Cloudflare, Vercel).\n * Returns undefined if not available.\n */\n get geo():\n | { city?: string; country?: string; region?: string; latitude?: string; longitude?: string }\n | undefined {\n // Check Cloudflare-style headers, Vercel-style headers\n const country =\n this.headers.get(\"cf-ipcountry\") ?? this.headers.get(\"x-vercel-ip-country\") ?? undefined;\n if (!country) return undefined;\n return {\n country,\n city: this.headers.get(\"cf-ipcity\") ?? this.headers.get(\"x-vercel-ip-city\") ?? undefined,\n region:\n this.headers.get(\"cf-region\") ??\n this.headers.get(\"x-vercel-ip-country-region\") ??\n undefined,\n latitude:\n this.headers.get(\"cf-iplatitude\") ?? this.headers.get(\"x-vercel-ip-latitude\") ?? undefined,\n longitude:\n this.headers.get(\"cf-iplongitude\") ??\n this.headers.get(\"x-vercel-ip-longitude\") ??\n undefined,\n };\n }\n\n /**\n * The build ID of the Next.js application.\n * Delegates to `nextUrl.buildId` to match Next.js API surface.\n * Can be used in middleware to detect deployment skew between client and server.\n */\n get buildId(): string | undefined {\n return this._nextUrl.buildId;\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextResponse\n// ---------------------------------------------------------------------------\n\n/** Valid HTTP redirect status codes, matching Next.js's REDIRECTS set. */\nconst REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\nfunction validateURL(url: string | URL): string {\n assertSafeNavigationUrl(String(url));\n try {\n return String(new URL(String(url)));\n } catch (error) {\n throw new Error(\n `URL is malformed \"${String(\n url,\n )}\". Please use only absolute URLs - https://nextjs.org/docs/messages/middleware-relative-urls`,\n { cause: error },\n );\n }\n}\n\nexport class NextResponse<_Body = unknown> extends Response {\n private _cookies: ResponseCookies;\n\n constructor(body?: BodyInit | null, init?: ResponseInit) {\n super(body, init);\n this._cookies = new ResponseCookies(this.headers);\n }\n\n get cookies(): ResponseCookies {\n return this._cookies;\n }\n\n /**\n * Create a JSON response.\n */\n static json<JsonBody>(body: JsonBody, init?: ResponseInit): NextResponse<JsonBody> {\n const headers = new Headers(init?.headers);\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n return new NextResponse(JSON.stringify(body), {\n ...init,\n headers,\n }) as NextResponse<JsonBody>;\n }\n\n /**\n * Create a redirect response.\n */\n static redirect(url: string | URL, init?: number | ResponseInit): NextResponse {\n const status = typeof init === \"number\" ? init : (init?.status ?? 307);\n if (!REDIRECT_STATUSES.has(status)) {\n throw new RangeError(`Failed to execute \"redirect\" on \"response\": Invalid status code`);\n }\n const headers = new Headers(typeof init === \"object\" ? init?.headers : undefined);\n headers.set(\"Location\", validateURL(url));\n return new NextResponse(null, { status, headers });\n }\n\n /**\n * Create a rewrite response (middleware pattern).\n * Sets the x-middleware-rewrite header.\n */\n static rewrite(destination: string | URL, init?: MiddlewareResponseInit): NextResponse {\n const headers = new Headers(init?.headers);\n headers.set(\"x-middleware-rewrite\", validateURL(destination));\n if (init?.request?.headers) {\n encodeMiddlewareRequestHeaders(headers, init.request.headers);\n }\n return new NextResponse(null, { ...init, headers });\n }\n\n /**\n * Continue to the next handler (middleware pattern).\n * Sets the x-middleware-next header.\n */\n static next(init?: MiddlewareResponseInit): NextResponse {\n const headers = new Headers(init?.headers);\n headers.set(\"x-middleware-next\", \"1\");\n if (init?.request?.headers) {\n encodeMiddlewareRequestHeaders(headers, init.request.headers);\n }\n return new NextResponse(null, { ...init, headers });\n }\n}\n\n// ---------------------------------------------------------------------------\n// NextURL — lightweight URL wrapper with pathname helpers\n// ---------------------------------------------------------------------------\n\nexport type NextURLConfig = {\n basePath?: string;\n nextConfig?: {\n i18n?: {\n locales: string[];\n defaultLocale: string;\n };\n };\n};\n\nexport class NextURL {\n /** Internal URL stores the pathname WITHOUT basePath or locale prefix. */\n private _url: URL;\n private _basePath: string;\n private _locale: string | undefined;\n private _defaultLocale: string | undefined;\n private _locales: string[] | undefined;\n\n constructor(input: string | URL, base?: string | URL, config?: NextURLConfig) {\n this._url = new URL(input.toString(), base);\n this._basePath = config?.basePath ?? \"\";\n this._stripBasePath();\n const i18n = config?.nextConfig?.i18n;\n if (i18n) {\n this._locales = [...i18n.locales];\n this._defaultLocale = i18n.defaultLocale;\n this._analyzeLocale(this._locales);\n }\n }\n\n /** Strip basePath prefix from the internal pathname. */\n private _stripBasePath(): void {\n if (!this._basePath) return;\n const { pathname } = this._url;\n if (pathname === this._basePath || pathname.startsWith(this._basePath + \"/\")) {\n this._url.pathname = pathname.slice(this._basePath.length) || \"/\";\n }\n }\n\n /** Extract locale from pathname, stripping it from the internal URL. */\n private _analyzeLocale(locales: string[]): void {\n const segments = this._url.pathname.split(\"/\");\n const candidate = segments[1]?.toLowerCase();\n const match = locales.find((l) => l.toLowerCase() === candidate);\n if (match) {\n this._locale = match;\n this._url.pathname = \"/\" + segments.slice(2).join(\"/\");\n } else {\n this._locale = this._defaultLocale;\n }\n }\n\n /**\n * Reconstruct the full pathname with basePath + locale prefix.\n * Mirrors Next.js's internal formatPathname().\n */\n private _formatPathname(): string {\n // Build prefix: basePath + locale (skip defaultLocale — Next.js omits it)\n let prefix = this._basePath;\n if (this._locale && this._locale !== this._defaultLocale) {\n prefix += \"/\" + this._locale;\n }\n if (!prefix) return this._url.pathname;\n const inner = this._url.pathname;\n return inner === \"/\" ? prefix : prefix + inner;\n }\n\n get href(): string {\n const formatted = this._formatPathname();\n if (formatted === this._url.pathname) return this._url.href;\n // Replace pathname in href via string slicing — avoids URL allocation.\n // URL.href is always <origin+auth><pathname><search><hash>.\n const { href, pathname, search, hash } = this._url;\n const baseEnd = href.length - pathname.length - search.length - hash.length;\n return href.slice(0, baseEnd) + formatted + search + hash;\n }\n set href(value: string) {\n this._url.href = value;\n this._stripBasePath();\n if (this._locales) this._analyzeLocale(this._locales);\n }\n\n get origin(): string {\n return this._url.origin;\n }\n\n get protocol(): string {\n return this._url.protocol;\n }\n set protocol(value: string) {\n this._url.protocol = value;\n }\n\n get username(): string {\n return this._url.username;\n }\n set username(value: string) {\n this._url.username = value;\n }\n\n get password(): string {\n return this._url.password;\n }\n set password(value: string) {\n this._url.password = value;\n }\n\n get host(): string {\n return this._url.host;\n }\n set host(value: string) {\n this._url.host = value;\n }\n\n get hostname(): string {\n return this._url.hostname;\n }\n set hostname(value: string) {\n this._url.hostname = value;\n }\n\n get port(): string {\n return this._url.port;\n }\n set port(value: string) {\n this._url.port = value;\n }\n\n /** Returns the pathname WITHOUT basePath or locale prefix. */\n get pathname(): string {\n return this._url.pathname;\n }\n set pathname(value: string) {\n this._url.pathname = value;\n }\n\n get search(): string {\n return this._url.search;\n }\n set search(value: string) {\n this._url.search = value;\n }\n\n get searchParams(): URLSearchParams {\n return this._url.searchParams;\n }\n\n get hash(): string {\n return this._url.hash;\n }\n set hash(value: string) {\n this._url.hash = value;\n }\n\n get basePath(): string {\n return this._basePath;\n }\n set basePath(value: string) {\n this._basePath = value === \"\" ? \"\" : value.startsWith(\"/\") ? value : \"/\" + value;\n }\n\n get locale(): string {\n return this._locale ?? \"\";\n }\n set locale(value: string | undefined) {\n if (this._locales) {\n if (!value) {\n this._locale = this._defaultLocale;\n return;\n }\n if (!this._locales.includes(value)) {\n throw new TypeError(\n `The locale \"${value}\" is not in the configured locales: ${this._locales.join(\", \")}`,\n );\n }\n }\n this._locale = this._locales ? value : this._locale;\n }\n\n get defaultLocale(): string | undefined {\n return this._defaultLocale;\n }\n\n get locales(): string[] | undefined {\n return this._locales ? [...this._locales] : undefined;\n }\n\n clone(): NextURL {\n const config: NextURLConfig = {\n basePath: this._basePath,\n nextConfig: this._locales\n ? { i18n: { locales: [...this._locales], defaultLocale: this._defaultLocale! } }\n : undefined,\n };\n // Pass the full href (with locale/basePath re-added) so the constructor\n // can re-analyze and extract locale correctly.\n return new NextURL(this.href, undefined, config);\n }\n\n toString(): string {\n return this.href;\n }\n\n /**\n * The build ID of the Next.js application.\n * Set from `generateBuildId` in next.config.js, or a random UUID if not configured.\n * Can be used in middleware to detect deployment skew between client and server.\n * Matches the Next.js API: `request.nextUrl.buildId`.\n */\n get buildId(): string | undefined {\n return process.env.__VINEXT_BUILD_ID ?? undefined;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Cookie helpers (minimal implementations)\n// ---------------------------------------------------------------------------\n\ntype CookieEntry = {\n name: string;\n value: string;\n};\n\nexport class RequestCookies {\n private _headers: Headers;\n private _parsed: Map<string, string>;\n\n constructor(headers: Headers) {\n this._headers = headers;\n this._parsed = parseCookieHeader(headers.get(\"cookie\") ?? \"\");\n }\n\n get(name: string): CookieEntry | undefined {\n const value = this._parsed.get(name);\n return value !== undefined ? { name, value } : undefined;\n }\n\n getAll(nameOrOptions?: string | CookieEntry): CookieEntry[] {\n const name = typeof nameOrOptions === \"string\" ? nameOrOptions : nameOrOptions?.name;\n return [...this._parsed.entries()]\n .filter(([cookieName]) => name === undefined || cookieName === name)\n .map(([cookieName, value]) => ({ name: cookieName, value }));\n }\n\n has(name: string): boolean {\n return this._parsed.has(name);\n }\n\n set(nameOrOptions: string | CookieEntry, value?: string): this {\n let cookieName: string;\n let cookieValue: string;\n if (typeof nameOrOptions === \"string\") {\n cookieName = nameOrOptions;\n cookieValue = value ?? \"\";\n } else {\n cookieName = nameOrOptions.name;\n cookieValue = nameOrOptions.value;\n }\n validateCookieName(cookieName);\n this._parsed.set(cookieName, cookieValue);\n this._syncHeader();\n return this;\n }\n\n delete(names: string | string[]): boolean | boolean[] {\n if (Array.isArray(names)) {\n const results = names.map((name) => {\n validateCookieName(name);\n return this._parsed.delete(name);\n });\n this._syncHeader();\n return results;\n }\n validateCookieName(names);\n const result = this._parsed.delete(names);\n this._syncHeader();\n return result;\n }\n\n clear(): this {\n this._parsed.clear();\n this._syncHeader();\n return this;\n }\n\n get size(): number {\n return this._parsed.size;\n }\n\n toString(): string {\n return this._serialize();\n }\n\n private _serialize(): string {\n return [...this._parsed.entries()].map(([n, v]) => `${n}=${encodeURIComponent(v)}`).join(\"; \");\n }\n\n private _syncHeader(): void {\n if (this._parsed.size === 0) {\n this._headers.delete(\"cookie\");\n } else {\n this._headers.set(\"cookie\", this._serialize());\n }\n }\n\n [Symbol.iterator](): IterableIterator<[string, CookieEntry]> {\n const entries = this.getAll().map((c) => [c.name, c] as [string, CookieEntry]);\n return entries[Symbol.iterator]();\n }\n}\n\n/**\n * RFC 6265 §4.1.1: cookie-name is a token (RFC 2616 §2.2).\n * Allowed: any visible ASCII (0x21-0x7E) except separators: ()<>@,;:\\\"/[]?={}\n */\nconst VALID_COOKIE_NAME_RE =\n /^[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2E\\x30-\\x39\\x41-\\x5A\\x5E-\\x7A\\x7C\\x7E]+$/;\n\nfunction validateCookieName(name: string): void {\n if (!name || !VALID_COOKIE_NAME_RE.test(name)) {\n throw new Error(`Invalid cookie name: ${JSON.stringify(name)}`);\n }\n}\n\nfunction validateCookieAttributeValue(value: string, attributeName: string): void {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code <= 0x1f || code === 0x7f || value[i] === \";\") {\n throw new Error(`Invalid cookie ${attributeName} value: ${JSON.stringify(value)}`);\n }\n }\n}\n\nexport class ResponseCookies {\n private _headers: Headers;\n /** Internal map keyed by cookie name — single source of truth. */\n private _parsed: Map<string, { serialized: string; entry: CookieEntry }> = new Map();\n\n constructor(headers: Headers) {\n this._headers = headers;\n\n // Hydrate internal map from any existing Set-Cookie headers\n for (const header of headers.getSetCookie()) {\n const eq = header.indexOf(\"=\");\n if (eq === -1) continue;\n const cookieName = header.slice(0, eq);\n const semi = header.indexOf(\";\", eq);\n const raw = header.slice(eq + 1, semi === -1 ? undefined : semi);\n let value: string;\n try {\n value = decodeURIComponent(raw);\n } catch {\n value = raw;\n }\n this._parsed.set(cookieName, { serialized: header, entry: { name: cookieName, value } });\n }\n }\n\n set(\n ...args:\n | [name: string, value: string, options?: CookieOptions]\n | [options: CookieOptions & { name: string; value: string }]\n ): this {\n const [name, value, opts] = parseCookieSetArgs(args);\n validateCookieName(name);\n\n const parts = [`${name}=${encodeURIComponent(value)}`];\n const path = opts?.path ?? \"/\";\n validateCookieAttributeValue(path, \"Path\");\n parts.push(`Path=${path}`);\n if (opts?.domain) {\n validateCookieAttributeValue(opts.domain, \"Domain\");\n parts.push(`Domain=${opts.domain}`);\n }\n if (opts?.maxAge !== undefined) parts.push(`Max-Age=${opts.maxAge}`);\n if (opts?.expires) parts.push(`Expires=${opts.expires.toUTCString()}`);\n if (opts?.httpOnly) parts.push(\"HttpOnly\");\n if (opts?.secure) parts.push(\"Secure\");\n if (opts?.sameSite) parts.push(`SameSite=${opts.sameSite}`);\n\n this._parsed.set(name, { serialized: parts.join(\"; \"), entry: { name, value } });\n this._syncHeaders();\n return this;\n }\n\n get(...args: [name: string] | [options: { name: string }]): CookieEntry | undefined {\n const key = typeof args[0] === \"string\" ? args[0] : args[0].name;\n return this._parsed.get(key)?.entry;\n }\n\n has(name: string): boolean {\n return this._parsed.has(name);\n }\n\n getAll(...args: [name: string] | [options: { name: string }] | []): CookieEntry[] {\n const all = [...this._parsed.values()].map((v) => v.entry);\n if (args.length === 0) return all;\n const key = typeof args[0] === \"string\" ? args[0] : args[0].name;\n return all.filter((c) => c.name === key);\n }\n\n delete(\n ...args:\n | [name: string]\n | [options: Omit<CookieOptions & { name: string }, \"maxAge\" | \"expires\">]\n ): this {\n const [name, opts] =\n typeof args[0] === \"string\" ? [args[0], undefined] : [args[0].name, args[0]];\n return this.set({\n name,\n value: \"\",\n expires: new Date(0),\n path: opts?.path,\n domain: opts?.domain,\n httpOnly: opts?.httpOnly,\n secure: opts?.secure,\n sameSite: opts?.sameSite,\n });\n }\n\n [Symbol.iterator](): IterableIterator<[string, CookieEntry]> {\n const entries: [string, CookieEntry][] = [...this._parsed.values()].map((v) => [\n v.entry.name,\n v.entry,\n ]);\n return entries[Symbol.iterator]();\n }\n\n /** Delete all Set-Cookie headers and re-append from the internal map. */\n private _syncHeaders(): void {\n this._headers.delete(\"Set-Cookie\");\n for (const { serialized } of this._parsed.values()) {\n this._headers.append(\"Set-Cookie\", serialized);\n }\n }\n}\n\ntype CookieOptions = {\n path?: string;\n domain?: string;\n maxAge?: number;\n expires?: Date;\n httpOnly?: boolean;\n secure?: boolean;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n};\n\n/**\n * Parse the overloaded arguments for ResponseCookies.set():\n * - (name, value, options?) — positional form\n * - ({ name, value, ...options }) — object form\n */\nfunction parseCookieSetArgs(\n args:\n | [name: string, value: string, options?: CookieOptions]\n | [options: CookieOptions & { name: string; value: string }],\n): [string, string, CookieOptions | undefined] {\n if (typeof args[0] === \"string\") {\n return [args[0], args[1] as string, args[2] as CookieOptions | undefined];\n }\n const { name, value, ...opts } = args[0];\n return [name, value, opts as CookieOptions];\n}\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport type MiddlewareResponseInit = {\n request?: {\n headers?: Headers;\n };\n} & ResponseInit;\n\nexport type NextMiddlewareResult = NextResponse | Response | null | undefined | void;\n\nexport type NextMiddleware = (\n request: NextRequest,\n event: NextFetchEvent,\n) => NextMiddlewareResult | Promise<NextMiddlewareResult>;\n\n/**\n * Minimal NextFetchEvent — extends FetchEvent where available,\n * otherwise provides the waitUntil pattern standalone.\n */\nexport class NextFetchEvent {\n sourcePage: string;\n private _waitUntilPromises: Promise<unknown>[] = [];\n\n constructor(params: { page: string }) {\n this.sourcePage = params.page;\n }\n\n waitUntil(promise: Promise<unknown>): void {\n this._waitUntilPromises.push(promise);\n }\n\n get waitUntilPromises(): Promise<unknown>[] {\n return this._waitUntilPromises;\n }\n\n /** Drain all waitUntil promises. Returns a single promise that settles when all are done. */\n drainWaitUntil(): Promise<PromiseSettledResult<unknown>[]> {\n return Promise.allSettled(this._waitUntilPromises);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Utility exports\n// ---------------------------------------------------------------------------\n\n/**\n * Parse user agent string. Minimal implementation — for full UA parsing,\n * apps should use a dedicated library like `ua-parser-js`.\n */\nexport function userAgentFromString(ua: string | undefined): UserAgent {\n const input = ua ?? \"\";\n return {\n isBot: /bot|crawler|spider|crawling/i.test(input),\n ua: input,\n browser: {},\n device: {},\n engine: {},\n os: {},\n cpu: {},\n };\n}\n\nexport function userAgent({ headers }: { headers: Headers }): UserAgent {\n return userAgentFromString(headers.get(\"user-agent\") ?? undefined);\n}\n\nexport type UserAgent = {\n isBot: boolean;\n ua: string;\n browser: { name?: string; version?: string; major?: string };\n device: { model?: string; type?: string; vendor?: string };\n engine: { name?: string; version?: string };\n os: { name?: string; version?: string };\n cpu: { architecture?: string };\n};\n\n/**\n * after() — schedule work after the response is sent.\n *\n * Uses the platform's `waitUntil` (via the per-request ExecutionContext) when\n * available so the task survives past the response on Cloudflare Workers.\n * Falls back to a fire-and-forget microtask on runtimes without an execution\n * context (e.g. Node.js dev server).\n *\n * Throws when called inside a cached scope — request-specific\n * side-effects must not leak into cached results.\n */\nexport function after<T>(task: Promise<T> | (() => T | Promise<T>)): void {\n _throwIfInsideCacheScope(\"after()\");\n\n const promise = typeof task === \"function\" ? Promise.resolve().then(task) : task;\n // NOTE: vinext runs function tasks concurrently with response streaming (next microtask),\n // whereas Next.js queues them to run strictly after the response is sent via onClose.\n // This is a known simplification — function tasks here are not guaranteed to run\n // after the response completes, only after the current synchronous execution.\n //\n // `.catch()` is attached synchronously in the same tick as `promise` is created, so\n // there is no window where a pre-rejected `task` promise could trigger an\n // `unhandledrejection` event before the handler is in place.\n const guarded = promise.catch((err) => {\n console.error(\"[vinext] after() task failed:\", err);\n });\n\n // TODO: Next.js throws when after() is called outside a request context or when\n // waitUntil is unavailable, preventing silent task loss. vinext falls back to\n // fire-and-forget here, which is correct for the Node.js dev server (where\n // getRequestExecutionContext() always returns null). On Workers, a misconfigured\n // entry that omits runWithExecutionContext would silently drop tasks — consider\n // a one-time console.warn on the fallback path, gated to production only (e.g.\n // `process.env.NODE_ENV === 'production'` or `typeof caches !== 'undefined'` for\n // a Workers runtime check) with a module-level `let _warned = false` guard so it\n // fires at most once and doesn't spam the dev-server console.\n getRequestExecutionContext()?.waitUntil(guarded);\n}\n\n/**\n * connection() — signals that the response requires a live connection\n * (not a static/cached response). Opts the page out of ISR caching\n * and sets Cache-Control: no-store on the response.\n */\nexport async function connection(): Promise<void> {\n const { markDynamicUsage, throwIfInsideCacheScope } = await import(\"./headers.js\");\n throwIfInsideCacheScope(\"connection()\");\n markDynamicUsage();\n}\n\n/**\n * URLPattern re-export — used in middleware for route matching.\n * Available natively in Node 20+, Cloudflare Workers, Deno.\n * Falls back to urlpattern-polyfill if the global is not available.\n */\nexport const URLPattern: typeof globalThis.URLPattern =\n globalThis.URLPattern ??\n (() => {\n throw new Error(\n \"URLPattern is not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QlD,eAAsB,aAA4B;CAChD,MAAM,EAAE,kBAAkB,4BAA4B,MAAM,OAAO;AACnE,yBAAwB,eAAe;AACvC,mBAAkB;;;;;;;AAQpB,MAAa,aACX,WAAW,qBACJ;AACL,OAAM,IAAI,MACR,iHAED"}
|
|
@@ -35,8 +35,10 @@ function createRequestContext(opts) {
|
|
|
35
35
|
serverContext: null,
|
|
36
36
|
serverInsertedHTMLCallbacks: [],
|
|
37
37
|
requestScopedCacheLife: null,
|
|
38
|
+
unstableCacheRevalidation: "foreground",
|
|
38
39
|
_privateCache: null,
|
|
39
40
|
currentRequestTags: [],
|
|
41
|
+
currentFetchSoftTags: [],
|
|
40
42
|
executionContext: _getInheritedExecutionContext(),
|
|
41
43
|
requestCache: /* @__PURE__ */ new WeakMap(),
|
|
42
44
|
ssrContext: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified-request-context.js","names":[],"sources":["../../src/shims/unified-request-context.ts"],"sourcesContent":["/**\n * Unified per-request context backed by a single AsyncLocalStorage.\n *\n * Consolidates the 5–6 nested ALS scopes that previously wrapped every\n * App Router request (headers, navigation, cache-state, private-cache,\n * fetch-cache, execution-context) into one flat store.\n *\n * Each shim module checks `isInsideUnifiedScope()` and reads its sub-fields\n * from the unified store, falling back to its own standalone ALS when\n * outside (SSR environment, Pages Router, tests).\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type {\n CacheState,\n ExecutionContextLike,\n FetchCacheState,\n HeadState,\n I18nState,\n NavigationState,\n PrivateCacheState,\n RouterState,\n VinextHeadersShimState,\n} from \"./request-state-types.js\";\n\n// ---------------------------------------------------------------------------\n// Unified context shape\n// ---------------------------------------------------------------------------\n\n/**\n * Flat union of all per-request state previously spread across\n * VinextHeadersShimState, NavigationState, CacheState, PrivateCacheState,\n * FetchCacheState, and ExecutionContextLike.\n *\n * Each field group is documented with its source shim module.\n */\nexport type UnifiedRequestContext = {\n // ── request-context.ts ─────────────────────────────────────────────\n /** Cloudflare Workers ExecutionContext, or null on Node.js dev. */\n executionContext: ExecutionContextLike | null;\n\n // ── cache-for-request.ts ──────────────────────────────────────────\n /** Per-request cache for cacheForRequest(). Keyed by factory function reference. */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n requestCache: WeakMap<(...args: any[]) => any, unknown>;\n} & VinextHeadersShimState &\n I18nState &\n NavigationState &\n CacheState &\n PrivateCacheState &\n FetchCacheState &\n RouterState &\n HeadState;\n\n// ---------------------------------------------------------------------------\n// ALS setup — stored on globalThis via Symbol.for so all Vite environments\n// (RSC/SSR/client) share the same instance.\n// ---------------------------------------------------------------------------\n\nconst _ALS_KEY = Symbol.for(\"vinext.unifiedRequestContext.als\");\nconst _REQUEST_CONTEXT_ALS_KEY = Symbol.for(\"vinext.requestContext.als\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = (_g[_ALS_KEY] ??=\n new AsyncLocalStorage<UnifiedRequestContext>()) as AsyncLocalStorage<UnifiedRequestContext>;\n\nfunction _getInheritedExecutionContext(): ExecutionContextLike | null {\n const unifiedStore = _als.getStore();\n if (unifiedStore) return unifiedStore.executionContext;\n\n const executionContextAls = _g[_REQUEST_CONTEXT_ALS_KEY] as\n | AsyncLocalStorage<ExecutionContextLike | null>\n | undefined;\n return executionContextAls?.getStore() ?? null;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Create a fresh `UnifiedRequestContext` with defaults for all fields.\n * Pass partial overrides for the fields you need to pre-populate.\n */\nexport function createRequestContext(opts?: Partial<UnifiedRequestContext>): UnifiedRequestContext {\n return {\n headersContext: null,\n dynamicUsageDetected: false,\n pendingSetCookies: [],\n draftModeCookieHeader: null,\n phase: \"render\",\n i18nContext: null,\n serverContext: null,\n serverInsertedHTMLCallbacks: [],\n requestScopedCacheLife: null,\n _privateCache: null,\n currentRequestTags: [],\n executionContext: _getInheritedExecutionContext(), // inherits from standalone ALS if present\n requestCache: new WeakMap(),\n ssrContext: null,\n ssrHeadChildren: [],\n ...opts,\n };\n}\n\n/**\n * Run `fn` within a unified request context scope.\n * All shim modules will read/write their state from `ctx` for the\n * duration of the call, including async continuations.\n */\nexport function runWithRequestContext<T>(\n ctx: UnifiedRequestContext,\n fn: () => Promise<T>,\n): Promise<T>;\nexport function runWithRequestContext<T>(\n ctx: UnifiedRequestContext,\n fn: () => T | Promise<T>,\n): T | Promise<T>;\nexport function runWithRequestContext<T>(\n ctx: UnifiedRequestContext,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n return _als.run(ctx, fn);\n}\n\n/**\n * Run `fn` in a nested unified scope derived from the current request context.\n * Used by legacy runWith* wrappers to reset or override one sub-state while\n * preserving proper async isolation for continuations created inside `fn`.\n * The child scope is a shallow clone of the parent store, so untouched fields\n * keep sharing their existing references while overridden slices can be reset.\n *\n * @internal\n */\nexport function runWithUnifiedStateMutation<T>(\n mutate: (ctx: UnifiedRequestContext) => void,\n fn: () => Promise<T>,\n): Promise<T>;\nexport function runWithUnifiedStateMutation<T>(\n mutate: (ctx: UnifiedRequestContext) => void,\n fn: () => T | Promise<T>,\n): T | Promise<T>;\nexport function runWithUnifiedStateMutation<T>(\n mutate: (ctx: UnifiedRequestContext) => void,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n const parentCtx = _als.getStore();\n if (!parentCtx) return fn();\n\n const childCtx = { ...parentCtx };\n // NOTE: This is a shallow clone. Array fields (pendingSetCookies,\n // serverInsertedHTMLCallbacks, currentRequestTags, ssrHeadChildren), the\n // _privateCache Map, requestCache WeakMap, and object fields (headersContext,\n // i18nContext, serverContext, ssrContext, executionContext,\n // requestScopedCacheLife) still share references with the parent until\n // replaced. requestCache is intentionally shared — nested scopes within\n // the same request should see the same cached values. The mutate\n // callback must replace those reference-typed slices (for example\n // `ctx.currentRequestTags = []`) rather than mutating them in-place (for\n // example `ctx.currentRequestTags.push(...)`) or the parent scope will\n // observe those changes too. Keep this enumeration in sync with\n // UnifiedRequestContext: when adding a new reference-typed field, add it\n // here too and verify callers still follow the replace-not-mutate rule.\n mutate(childCtx);\n return _als.run(childCtx, fn);\n}\n\n/**\n * Get the current unified request context.\n * Returns the ALS store when inside a `runWithRequestContext()` scope,\n * or a fresh detached context otherwise. Unlike the legacy per-shim fallback\n * singletons, this detached value is ephemeral — mutations do not persist\n * across calls. This is intentional to prevent state leakage outside request\n * scopes.\n *\n * Only direct callers observe this detached fallback. Shim `_getState()`\n * helpers should continue to gate on `isInsideUnifiedScope()` and fall back\n * to their standalone ALS/fallback singletons outside the unified scope.\n * If called inside a standalone `runWithExecutionContext()` scope, the\n * detached context still reflects that inherited `executionContext`.\n */\nexport function getRequestContext(): UnifiedRequestContext {\n return _als.getStore() ?? createRequestContext();\n}\n\n/**\n * Check whether the current execution is inside a `runWithRequestContext()` scope.\n * Shim modules use this to decide whether to read from the unified store\n * or fall back to their own standalone ALS.\n */\nexport function isInsideUnifiedScope(): boolean {\n return _als.getStore() != null;\n}\n"],"mappings":";;;;;;;;;;;;;AA2DA,MAAM,WAAW,OAAO,IAAI,mCAAmC;AAC/D,MAAM,2BAA2B,OAAO,IAAI,4BAA4B;AACxE,MAAM,KAAK;AACX,MAAM,OAAQ,GAAG,cACf,IAAI,mBAA0C;AAEhD,SAAS,gCAA6D;CACpE,MAAM,eAAe,KAAK,UAAU;AACpC,KAAI,aAAc,QAAO,aAAa;AAKtC,QAH4B,GAAG,2BAGH,UAAU,IAAI;;;;;;AAW5C,SAAgB,qBAAqB,MAA8D;AACjG,QAAO;EACL,gBAAgB;EAChB,sBAAsB;EACtB,mBAAmB,EAAE;EACrB,uBAAuB;EACvB,OAAO;EACP,aAAa;EACb,eAAe;EACf,6BAA6B,EAAE;EAC/B,wBAAwB;EACxB,eAAe;EACf,oBAAoB,EAAE;EACtB,kBAAkB,+BAA+B;EACjD,8BAAc,IAAI,SAAS;EAC3B,YAAY;EACZ,iBAAiB,EAAE;EACnB,GAAG;EACJ;;AAgBH,SAAgB,sBACd,KACA,IACgB;AAChB,QAAO,KAAK,IAAI,KAAK,GAAG;;AAoB1B,SAAgB,4BACd,QACA,IACgB;CAChB,MAAM,YAAY,KAAK,UAAU;AACjC,KAAI,CAAC,UAAW,QAAO,IAAI;CAE3B,MAAM,WAAW,EAAE,GAAG,WAAW;AAcjC,QAAO,SAAS;AAChB,QAAO,KAAK,IAAI,UAAU,GAAG;;;;;;;;;;;;;;;;AAiB/B,SAAgB,oBAA2C;AACzD,QAAO,KAAK,UAAU,IAAI,sBAAsB;;;;;;;AAQlD,SAAgB,uBAAgC;AAC9C,QAAO,KAAK,UAAU,IAAI"}
|
|
1
|
+
{"version":3,"file":"unified-request-context.js","names":[],"sources":["../../src/shims/unified-request-context.ts"],"sourcesContent":["/**\n * Unified per-request context backed by a single AsyncLocalStorage.\n *\n * Consolidates the 5–6 nested ALS scopes that previously wrapped every\n * App Router request (headers, navigation, cache-state, private-cache,\n * fetch-cache, execution-context) into one flat store.\n *\n * Each shim module checks `isInsideUnifiedScope()` and reads its sub-fields\n * from the unified store, falling back to its own standalone ALS when\n * outside (SSR environment, Pages Router, tests).\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type {\n CacheState,\n ExecutionContextLike,\n FetchCacheState,\n HeadState,\n I18nState,\n NavigationState,\n PrivateCacheState,\n RouterState,\n VinextHeadersShimState,\n} from \"./request-state-types.js\";\n\n// ---------------------------------------------------------------------------\n// Unified context shape\n// ---------------------------------------------------------------------------\n\n/**\n * Flat union of all per-request state previously spread across\n * VinextHeadersShimState, NavigationState, CacheState, PrivateCacheState,\n * FetchCacheState, and ExecutionContextLike.\n *\n * Each field group is documented with its source shim module.\n */\nexport type UnifiedRequestContext = {\n // ── request-context.ts ─────────────────────────────────────────────\n /** Cloudflare Workers ExecutionContext, or null on Node.js dev. */\n executionContext: ExecutionContextLike | null;\n\n // ── cache-for-request.ts ──────────────────────────────────────────\n /** Per-request cache for cacheForRequest(). Keyed by factory function reference. */\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n requestCache: WeakMap<(...args: any[]) => any, unknown>;\n} & VinextHeadersShimState &\n I18nState &\n NavigationState &\n CacheState &\n PrivateCacheState &\n FetchCacheState &\n RouterState &\n HeadState;\n\n// ---------------------------------------------------------------------------\n// ALS setup — stored on globalThis via Symbol.for so all Vite environments\n// (RSC/SSR/client) share the same instance.\n// ---------------------------------------------------------------------------\n\nconst _ALS_KEY = Symbol.for(\"vinext.unifiedRequestContext.als\");\nconst _REQUEST_CONTEXT_ALS_KEY = Symbol.for(\"vinext.requestContext.als\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = (_g[_ALS_KEY] ??=\n new AsyncLocalStorage<UnifiedRequestContext>()) as AsyncLocalStorage<UnifiedRequestContext>;\n\nfunction _getInheritedExecutionContext(): ExecutionContextLike | null {\n const unifiedStore = _als.getStore();\n if (unifiedStore) return unifiedStore.executionContext;\n\n const executionContextAls = _g[_REQUEST_CONTEXT_ALS_KEY] as\n | AsyncLocalStorage<ExecutionContextLike | null>\n | undefined;\n return executionContextAls?.getStore() ?? null;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Create a fresh `UnifiedRequestContext` with defaults for all fields.\n * Pass partial overrides for the fields you need to pre-populate.\n */\nexport function createRequestContext(opts?: Partial<UnifiedRequestContext>): UnifiedRequestContext {\n return {\n headersContext: null,\n dynamicUsageDetected: false,\n pendingSetCookies: [],\n draftModeCookieHeader: null,\n phase: \"render\",\n i18nContext: null,\n serverContext: null,\n serverInsertedHTMLCallbacks: [],\n requestScopedCacheLife: null,\n unstableCacheRevalidation: \"foreground\",\n _privateCache: null,\n currentRequestTags: [],\n currentFetchSoftTags: [],\n executionContext: _getInheritedExecutionContext(), // inherits from standalone ALS if present\n requestCache: new WeakMap(),\n ssrContext: null,\n ssrHeadChildren: [],\n ...opts,\n };\n}\n\n/**\n * Run `fn` within a unified request context scope.\n * All shim modules will read/write their state from `ctx` for the\n * duration of the call, including async continuations.\n */\nexport function runWithRequestContext<T>(\n ctx: UnifiedRequestContext,\n fn: () => Promise<T>,\n): Promise<T>;\nexport function runWithRequestContext<T>(\n ctx: UnifiedRequestContext,\n fn: () => T | Promise<T>,\n): T | Promise<T>;\nexport function runWithRequestContext<T>(\n ctx: UnifiedRequestContext,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n return _als.run(ctx, fn);\n}\n\n/**\n * Run `fn` in a nested unified scope derived from the current request context.\n * Used by legacy runWith* wrappers to reset or override one sub-state while\n * preserving proper async isolation for continuations created inside `fn`.\n * The child scope is a shallow clone of the parent store, so untouched fields\n * keep sharing their existing references while overridden slices can be reset.\n *\n * @internal\n */\nexport function runWithUnifiedStateMutation<T>(\n mutate: (ctx: UnifiedRequestContext) => void,\n fn: () => Promise<T>,\n): Promise<T>;\nexport function runWithUnifiedStateMutation<T>(\n mutate: (ctx: UnifiedRequestContext) => void,\n fn: () => T | Promise<T>,\n): T | Promise<T>;\nexport function runWithUnifiedStateMutation<T>(\n mutate: (ctx: UnifiedRequestContext) => void,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n const parentCtx = _als.getStore();\n if (!parentCtx) return fn();\n\n const childCtx = { ...parentCtx };\n // NOTE: This is a shallow clone. Array fields (pendingSetCookies,\n // serverInsertedHTMLCallbacks, currentRequestTags, ssrHeadChildren), the\n // _privateCache Map, requestCache WeakMap, and object fields (headersContext,\n // i18nContext, serverContext, ssrContext, executionContext,\n // requestScopedCacheLife) still share references with the parent until\n // replaced. requestCache is intentionally shared — nested scopes within\n // the same request should see the same cached values. The mutate\n // callback must replace those reference-typed slices (for example\n // `ctx.currentRequestTags = []`) rather than mutating them in-place (for\n // example `ctx.currentRequestTags.push(...)`) or the parent scope will\n // observe those changes too. Keep this enumeration in sync with\n // UnifiedRequestContext: when adding a new reference-typed field, add it\n // here too and verify callers still follow the replace-not-mutate rule.\n mutate(childCtx);\n return _als.run(childCtx, fn);\n}\n\n/**\n * Get the current unified request context.\n * Returns the ALS store when inside a `runWithRequestContext()` scope,\n * or a fresh detached context otherwise. Unlike the legacy per-shim fallback\n * singletons, this detached value is ephemeral — mutations do not persist\n * across calls. This is intentional to prevent state leakage outside request\n * scopes.\n *\n * Only direct callers observe this detached fallback. Shim `_getState()`\n * helpers should continue to gate on `isInsideUnifiedScope()` and fall back\n * to their standalone ALS/fallback singletons outside the unified scope.\n * If called inside a standalone `runWithExecutionContext()` scope, the\n * detached context still reflects that inherited `executionContext`.\n */\nexport function getRequestContext(): UnifiedRequestContext {\n return _als.getStore() ?? createRequestContext();\n}\n\n/**\n * Check whether the current execution is inside a `runWithRequestContext()` scope.\n * Shim modules use this to decide whether to read from the unified store\n * or fall back to their own standalone ALS.\n */\nexport function isInsideUnifiedScope(): boolean {\n return _als.getStore() != null;\n}\n"],"mappings":";;;;;;;;;;;;;AA2DA,MAAM,WAAW,OAAO,IAAI,mCAAmC;AAC/D,MAAM,2BAA2B,OAAO,IAAI,4BAA4B;AACxE,MAAM,KAAK;AACX,MAAM,OAAQ,GAAG,cACf,IAAI,mBAA0C;AAEhD,SAAS,gCAA6D;CACpE,MAAM,eAAe,KAAK,UAAU;AACpC,KAAI,aAAc,QAAO,aAAa;AAKtC,QAH4B,GAAG,2BAGH,UAAU,IAAI;;;;;;AAW5C,SAAgB,qBAAqB,MAA8D;AACjG,QAAO;EACL,gBAAgB;EAChB,sBAAsB;EACtB,mBAAmB,EAAE;EACrB,uBAAuB;EACvB,OAAO;EACP,aAAa;EACb,eAAe;EACf,6BAA6B,EAAE;EAC/B,wBAAwB;EACxB,2BAA2B;EAC3B,eAAe;EACf,oBAAoB,EAAE;EACtB,sBAAsB,EAAE;EACxB,kBAAkB,+BAA+B;EACjD,8BAAc,IAAI,SAAS;EAC3B,YAAY;EACZ,iBAAiB,EAAE;EACnB,GAAG;EACJ;;AAgBH,SAAgB,sBACd,KACA,IACgB;AAChB,QAAO,KAAK,IAAI,KAAK,GAAG;;AAoB1B,SAAgB,4BACd,QACA,IACgB;CAChB,MAAM,YAAY,KAAK,UAAU;AACjC,KAAI,CAAC,UAAW,QAAO,IAAI;CAE3B,MAAM,WAAW,EAAE,GAAG,WAAW;AAcjC,QAAO,SAAS;AAChB,QAAO,KAAK,IAAI,UAAU,GAAG;;;;;;;;;;;;;;;;AAiB/B,SAAgB,oBAA2C;AACzD,QAAO,KAAK,UAAU,IAAI,sBAAsB;;;;;;;AAQlD,SAAgB,uBAAgC;AAC9C,QAAO,KAAK,UAAU,IAAI"}
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* Centralizes dangerous URI scheme detection so all components and
|
|
6
6
|
* navigation functions use the same validation logic.
|
|
7
7
|
*/
|
|
8
|
+
declare const DANGEROUS_URL_BLOCK_MESSAGE = "Next.js has blocked a javascript: URL as a security precaution.";
|
|
8
9
|
declare function isDangerousScheme(url: string): boolean;
|
|
10
|
+
declare function assertSafeNavigationUrl(url: string): void;
|
|
9
11
|
//#endregion
|
|
10
|
-
export { isDangerousScheme };
|
|
12
|
+
export { DANGEROUS_URL_BLOCK_MESSAGE, assertSafeNavigationUrl, isDangerousScheme };
|
|
11
13
|
//# sourceMappingURL=url-safety.d.ts.map
|
package/dist/shims/url-safety.js
CHANGED
|
@@ -31,11 +31,15 @@ const DANGEROUS_SCHEME_RES = [
|
|
|
31
31
|
buildDangerousSchemeRegex("data"),
|
|
32
32
|
buildDangerousSchemeRegex("vbscript")
|
|
33
33
|
];
|
|
34
|
+
const DANGEROUS_URL_BLOCK_MESSAGE = "Next.js has blocked a javascript: URL as a security precaution.";
|
|
34
35
|
function isDangerousScheme(url) {
|
|
35
36
|
const str = "" + url;
|
|
36
37
|
return DANGEROUS_SCHEME_RES.some((re) => re.test(str));
|
|
37
38
|
}
|
|
39
|
+
function assertSafeNavigationUrl(url) {
|
|
40
|
+
if (isDangerousScheme(url)) throw new Error(DANGEROUS_URL_BLOCK_MESSAGE);
|
|
41
|
+
}
|
|
38
42
|
//#endregion
|
|
39
|
-
export { isDangerousScheme };
|
|
43
|
+
export { DANGEROUS_URL_BLOCK_MESSAGE, assertSafeNavigationUrl, isDangerousScheme };
|
|
40
44
|
|
|
41
45
|
//# sourceMappingURL=url-safety.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-safety.js","names":[],"sources":["../../src/shims/url-safety.ts"],"sourcesContent":["/**\n * Shared URL safety utilities for Link, Form, and navigation shims.\n *\n * Centralizes dangerous URI scheme detection so all components and\n * navigation functions use the same validation logic.\n */\n\n/**\n * Detect dangerous URI schemes that should never be navigated to.\n *\n * Adapted from Next.js's javascript URL detector:\n * packages/next/src/client/lib/javascript-url.ts\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/lib/javascript-url.ts\n *\n * URL parsing ignores leading C0 control characters / spaces, and treats\n * embedded tab/newline characters in the scheme as insignificant. We mirror\n * that behavior here so obfuscated values like `java\\nscript:` and\n * `\\x00javascript:` are still blocked.\n *\n * Vinext intentionally extends this handling to `data:` and `vbscript:` too,\n * since both are also dangerous navigation targets.\n */\nconst LEADING_IGNORED = \"[\\\\u0000-\\\\u001F \\\\u200B\\\\uFEFF]*\";\nconst SCHEME_IGNORED = \"[\\\\r\\\\n\\\\t]*\";\n\nfunction buildDangerousSchemeRegex(scheme: string): RegExp {\n const chars = scheme.split(\"\").join(SCHEME_IGNORED);\n return new RegExp(`^${LEADING_IGNORED}${chars}${SCHEME_IGNORED}:`, \"i\");\n}\n\nconst DANGEROUS_SCHEME_RES = [\n buildDangerousSchemeRegex(\"javascript\"),\n buildDangerousSchemeRegex(\"data\"),\n buildDangerousSchemeRegex(\"vbscript\"),\n];\n\nexport function isDangerousScheme(url: string): boolean {\n const str = \"\" + (url as unknown as string);\n return DANGEROUS_SCHEME_RES.some((re) => re.test(str));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,SAAS,0BAA0B,QAAwB;CACzD,MAAM,QAAQ,OAAO,MAAM,GAAG,CAAC,KAAK,eAAe;AACnD,QAAO,IAAI,OAAO,IAAI,kBAAkB,QAAQ,eAAe,IAAI,IAAI;;AAGzE,MAAM,uBAAuB;CAC3B,0BAA0B,aAAa;CACvC,0BAA0B,OAAO;CACjC,0BAA0B,WAAW;CACtC;AAED,SAAgB,kBAAkB,KAAsB;CACtD,MAAM,MAAM,KAAM;AAClB,QAAO,qBAAqB,MAAM,OAAO,GAAG,KAAK,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"url-safety.js","names":[],"sources":["../../src/shims/url-safety.ts"],"sourcesContent":["/**\n * Shared URL safety utilities for Link, Form, and navigation shims.\n *\n * Centralizes dangerous URI scheme detection so all components and\n * navigation functions use the same validation logic.\n */\n\n/**\n * Detect dangerous URI schemes that should never be navigated to.\n *\n * Adapted from Next.js's javascript URL detector:\n * packages/next/src/client/lib/javascript-url.ts\n * https://github.com/vercel/next.js/blob/canary/packages/next/src/client/lib/javascript-url.ts\n *\n * URL parsing ignores leading C0 control characters / spaces, and treats\n * embedded tab/newline characters in the scheme as insignificant. We mirror\n * that behavior here so obfuscated values like `java\\nscript:` and\n * `\\x00javascript:` are still blocked.\n *\n * Vinext intentionally extends this handling to `data:` and `vbscript:` too,\n * since both are also dangerous navigation targets.\n */\nconst LEADING_IGNORED = \"[\\\\u0000-\\\\u001F \\\\u200B\\\\uFEFF]*\";\nconst SCHEME_IGNORED = \"[\\\\r\\\\n\\\\t]*\";\n\nfunction buildDangerousSchemeRegex(scheme: string): RegExp {\n const chars = scheme.split(\"\").join(SCHEME_IGNORED);\n return new RegExp(`^${LEADING_IGNORED}${chars}${SCHEME_IGNORED}:`, \"i\");\n}\n\nconst DANGEROUS_SCHEME_RES = [\n buildDangerousSchemeRegex(\"javascript\"),\n buildDangerousSchemeRegex(\"data\"),\n buildDangerousSchemeRegex(\"vbscript\"),\n];\n\nexport const DANGEROUS_URL_BLOCK_MESSAGE =\n \"Next.js has blocked a javascript: URL as a security precaution.\";\n\nexport function isDangerousScheme(url: string): boolean {\n const str = \"\" + (url as unknown as string);\n return DANGEROUS_SCHEME_RES.some((re) => re.test(str));\n}\n\nexport function assertSafeNavigationUrl(url: string): void {\n if (isDangerousScheme(url)) {\n throw new Error(DANGEROUS_URL_BLOCK_MESSAGE);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,SAAS,0BAA0B,QAAwB;CACzD,MAAM,QAAQ,OAAO,MAAM,GAAG,CAAC,KAAK,eAAe;AACnD,QAAO,IAAI,OAAO,IAAI,kBAAkB,QAAQ,eAAe,IAAI,IAAI;;AAGzE,MAAM,uBAAuB;CAC3B,0BAA0B,aAAa;CACvC,0BAA0B,OAAO;CACjC,0BAA0B,WAAW;CACtC;AAED,MAAa,8BACX;AAEF,SAAgB,kBAAkB,KAAsB;CACtD,MAAM,MAAM,KAAM;AAClB,QAAO,qBAAqB,MAAM,OAAO,GAAG,KAAK,IAAI,CAAC;;AAGxD,SAAgB,wBAAwB,KAAmB;AACzD,KAAI,kBAAkB,IAAI,CACxB,OAAM,IAAI,MAAM,4BAA4B"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//#region src/utils/error-cause.ts
|
|
2
|
+
/**
|
|
3
|
+
* Embed an Error's `.cause` chain into its own `.message` and `.stack` so
|
|
4
|
+
* single-pass formatters (Vite's "Internal server error: ${err.message}\n${err.stack}"
|
|
5
|
+
* dev-server logger, anything that just prints message + stack) reveal the
|
|
6
|
+
* underlying root cause instead of silently dropping it.
|
|
7
|
+
*
|
|
8
|
+
* Without this, a wrapper like `new Error("Failed query", { cause: pgError })`
|
|
9
|
+
* shows up in the Vite dev console as just "Failed query" — the actual
|
|
10
|
+
* ECONNREFUSED / role-missing / socket-error in `.cause` is lost.
|
|
11
|
+
*
|
|
12
|
+
* Intended for **dev-server use only**. Production loggers (Node's
|
|
13
|
+
* `console.error` → `util.inspect`, workerd's runtime logger) already render
|
|
14
|
+
* `.cause` natively, so calling this in prod would double-print the cause —
|
|
15
|
+
* once in the synthesized message, once in util.inspect's `[cause]:` block.
|
|
16
|
+
* Callers should gate on `process.env.NODE_ENV !== "production"` (Vite
|
|
17
|
+
* build-time-replaces this, so the prod bundle gets a no-op).
|
|
18
|
+
*
|
|
19
|
+
* - Best-effort: never throws. Frozen / non-extensible errors are left untouched.
|
|
20
|
+
* - Idempotent (repeat calls are no-ops via a non-enumerable module-private symbol).
|
|
21
|
+
* - Cycle-safe and depth-capped (10) for pathological cause graphs.
|
|
22
|
+
* - Cause stack frames are appended as `at` lines so stack-cleaning regexes
|
|
23
|
+
* like Vite's `/^\s*at/` filter preserve them.
|
|
24
|
+
*/
|
|
25
|
+
const FLATTENED_MARKER = Symbol("vinext.errorCausesFlattened");
|
|
26
|
+
const MAX_CAUSE_DEPTH = 10;
|
|
27
|
+
function stringifyNonError(value) {
|
|
28
|
+
if (typeof value === "string") return value;
|
|
29
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return String(value);
|
|
30
|
+
if (value === null || value === void 0) return String(value);
|
|
31
|
+
try {
|
|
32
|
+
return JSON.stringify(value) ?? Object.prototype.toString.call(value);
|
|
33
|
+
} catch {
|
|
34
|
+
return Object.prototype.toString.call(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function flattenErrorCauses(err) {
|
|
38
|
+
if (!(err instanceof Error)) return;
|
|
39
|
+
const marked = err;
|
|
40
|
+
if (marked[FLATTENED_MARKER]) return;
|
|
41
|
+
try {
|
|
42
|
+
Object.defineProperty(marked, FLATTENED_MARKER, {
|
|
43
|
+
value: true,
|
|
44
|
+
enumerable: false,
|
|
45
|
+
configurable: false,
|
|
46
|
+
writable: false
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const seen = new WeakSet([err]);
|
|
52
|
+
const causes = [];
|
|
53
|
+
let cur = err.cause;
|
|
54
|
+
let depth = 0;
|
|
55
|
+
while (cur != null && depth < MAX_CAUSE_DEPTH) {
|
|
56
|
+
if (typeof cur === "object") {
|
|
57
|
+
if (seen.has(cur)) break;
|
|
58
|
+
seen.add(cur);
|
|
59
|
+
}
|
|
60
|
+
if (cur instanceof Error) {
|
|
61
|
+
causes.push({
|
|
62
|
+
message: cur.message,
|
|
63
|
+
stack: cur.stack
|
|
64
|
+
});
|
|
65
|
+
cur = cur.cause;
|
|
66
|
+
} else {
|
|
67
|
+
causes.push({ message: stringifyNonError(cur) });
|
|
68
|
+
cur = null;
|
|
69
|
+
}
|
|
70
|
+
depth++;
|
|
71
|
+
}
|
|
72
|
+
if (causes.length === 0) return;
|
|
73
|
+
const messageSuffix = causes.map((c) => ` [cause]: ${c.message}`).join("\n");
|
|
74
|
+
try {
|
|
75
|
+
err.message = `${err.message}\n${messageSuffix}`;
|
|
76
|
+
} catch {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (typeof err.stack === "string") {
|
|
80
|
+
let stackSuffix = "";
|
|
81
|
+
for (const c of causes) {
|
|
82
|
+
const headline = c.message.split("\n", 1)[0];
|
|
83
|
+
stackSuffix += `\n at [cause: ${headline}]`;
|
|
84
|
+
if (c.stack) {
|
|
85
|
+
const frames = c.stack.split("\n").filter((l) => /^\s*at\s/.test(l)).join("\n");
|
|
86
|
+
if (frames) stackSuffix += `\n${frames}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
err.stack = `${err.stack}${stackSuffix}`;
|
|
91
|
+
} catch {}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { flattenErrorCauses };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=error-cause.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-cause.js","names":[],"sources":["../../src/utils/error-cause.ts"],"sourcesContent":["/**\n * Embed an Error's `.cause` chain into its own `.message` and `.stack` so\n * single-pass formatters (Vite's \"Internal server error: ${err.message}\\n${err.stack}\"\n * dev-server logger, anything that just prints message + stack) reveal the\n * underlying root cause instead of silently dropping it.\n *\n * Without this, a wrapper like `new Error(\"Failed query\", { cause: pgError })`\n * shows up in the Vite dev console as just \"Failed query\" — the actual\n * ECONNREFUSED / role-missing / socket-error in `.cause` is lost.\n *\n * Intended for **dev-server use only**. Production loggers (Node's\n * `console.error` → `util.inspect`, workerd's runtime logger) already render\n * `.cause` natively, so calling this in prod would double-print the cause —\n * once in the synthesized message, once in util.inspect's `[cause]:` block.\n * Callers should gate on `process.env.NODE_ENV !== \"production\"` (Vite\n * build-time-replaces this, so the prod bundle gets a no-op).\n *\n * - Best-effort: never throws. Frozen / non-extensible errors are left untouched.\n * - Idempotent (repeat calls are no-ops via a non-enumerable module-private symbol).\n * - Cycle-safe and depth-capped (10) for pathological cause graphs.\n * - Cause stack frames are appended as `at` lines so stack-cleaning regexes\n * like Vite's `/^\\s*at/` filter preserve them.\n */\nconst FLATTENED_MARKER = Symbol(\"vinext.errorCausesFlattened\");\nconst MAX_CAUSE_DEPTH = 10;\n\nfunction stringifyNonError(value: unknown): string {\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"boolean\" || typeof value === \"bigint\") {\n return String(value);\n }\n if (value === null || value === undefined) return String(value);\n try {\n return JSON.stringify(value) ?? Object.prototype.toString.call(value);\n } catch {\n return Object.prototype.toString.call(value);\n }\n}\n\nexport function flattenErrorCauses(err: unknown): void {\n if (!(err instanceof Error)) return;\n const marked = err as Error & { [FLATTENED_MARKER]?: true };\n if (marked[FLATTENED_MARKER]) return;\n // defineProperty throws on frozen errors; mutations below also throw.\n // Wrap each step so this function honours its \"never throw\" contract —\n // a thrown TypeError here would propagate from the caller's catch block\n // and replace the user's real error with our enrichment failure.\n try {\n Object.defineProperty(marked, FLATTENED_MARKER, {\n value: true,\n enumerable: false,\n configurable: false,\n writable: false,\n });\n } catch {\n return;\n }\n\n const seen = new WeakSet<object>([err]);\n const causes: Array<{ message: string; stack?: string }> = [];\n let cur: unknown = (err as { cause?: unknown }).cause;\n let depth = 0;\n while (cur != null && depth < MAX_CAUSE_DEPTH) {\n if (typeof cur === \"object\") {\n if (seen.has(cur as object)) break;\n seen.add(cur as object);\n }\n if (cur instanceof Error) {\n causes.push({ message: cur.message, stack: cur.stack });\n cur = (cur as { cause?: unknown }).cause;\n } else {\n causes.push({ message: stringifyNonError(cur) });\n cur = null;\n }\n depth++;\n }\n if (causes.length === 0) return;\n\n const messageSuffix = causes.map((c) => ` [cause]: ${c.message}`).join(\"\\n\");\n try {\n err.message = `${err.message}\\n${messageSuffix}`;\n } catch {\n // Frozen / non-writable .message — leave the rest untouched too,\n // since a partial write would be misleading.\n return;\n }\n\n if (typeof err.stack === \"string\") {\n let stackSuffix = \"\";\n for (const c of causes) {\n const headline = c.message.split(\"\\n\", 1)[0];\n stackSuffix += `\\n at [cause: ${headline}]`;\n if (c.stack) {\n const frames = c.stack\n .split(\"\\n\")\n .filter((l) => /^\\s*at\\s/.test(l))\n .join(\"\\n\");\n if (frames) stackSuffix += `\\n${frames}`;\n }\n }\n try {\n err.stack = `${err.stack}${stackSuffix}`;\n } catch {\n // Stack is read-only on some hosts; message enrichment still holds.\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,mBAAmB,OAAO,8BAA8B;AAC9D,MAAM,kBAAkB;AAExB,SAAS,kBAAkB,OAAwB;AACjD,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,KAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa,OAAO,UAAU,SAC9E,QAAO,OAAO,MAAM;AAEtB,KAAI,UAAU,QAAQ,UAAU,KAAA,EAAW,QAAO,OAAO,MAAM;AAC/D,KAAI;AACF,SAAO,KAAK,UAAU,MAAM,IAAI,OAAO,UAAU,SAAS,KAAK,MAAM;SAC/D;AACN,SAAO,OAAO,UAAU,SAAS,KAAK,MAAM;;;AAIhD,SAAgB,mBAAmB,KAAoB;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ildManifestChunk = {
|
|
|
30
30
|
*/
|
|
31
31
|
declare function computeLazyChunks(buildManifest: Record<string, BuildManifestChunk>): string[];
|
|
32
32
|
//#endregion
|
|
33
|
-
export {
|
|
33
|
+
export { computeLazyChunks };
|
|
34
34
|
//# sourceMappingURL=lazy-chunks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-chunks.js","names":[],"sources":["../../src/utils/lazy-chunks.ts"],"sourcesContent":["/**\n * Build-manifest chunk metadata used to compute lazy chunks.\n */\
|
|
1
|
+
{"version":3,"file":"lazy-chunks.js","names":[],"sources":["../../src/utils/lazy-chunks.ts"],"sourcesContent":["/**\n * Build-manifest chunk metadata used to compute lazy chunks.\n */\ntype BuildManifestChunk = {\n file: string;\n isEntry?: boolean;\n isDynamicEntry?: boolean;\n imports?: string[];\n dynamicImports?: string[];\n css?: string[];\n assets?: string[];\n};\n\n/**\n * Compute the set of chunk filenames that are ONLY reachable through dynamic\n * imports (i.e. behind React.lazy(), next/dynamic, or manual import()).\n *\n * These chunks should NOT be modulepreloaded in the HTML — they will be\n * fetched on demand when the dynamic import executes.\n *\n * Algorithm: Starting from all entry chunks in the build manifest, walk the\n * static `imports` tree (breadth-first). Any chunk file NOT reached by this\n * walk is only reachable through `dynamicImports` and is therefore \"lazy\".\n *\n * @param buildManifest - Vite's build manifest (manifest.json), which is a\n * Record<string, ManifestChunk> where each chunk has `file`, `imports`,\n * `dynamicImports`, `isEntry`, and `isDynamicEntry` fields.\n * @returns Array of chunk filenames (e.g. \"assets/mermaid-NOHMQCX5.js\") that\n * should be excluded from modulepreload hints.\n */\nexport function computeLazyChunks(buildManifest: Record<string, BuildManifestChunk>): string[] {\n // Collect all chunk files that are statically reachable from entries\n const eagerFiles = new Set<string>();\n const visited = new Set<string>();\n const queue: string[] = [];\n\n // Start BFS from all entry chunks\n for (const key of Object.keys(buildManifest)) {\n const chunk = buildManifest[key];\n if (chunk.isEntry) {\n queue.push(key);\n }\n }\n\n while (queue.length > 0) {\n const key = queue.shift();\n if (!key || visited.has(key)) continue;\n visited.add(key);\n\n const chunk = buildManifest[key];\n if (!chunk) continue;\n\n // Mark this chunk's file as eager\n eagerFiles.add(chunk.file);\n\n // Also mark its CSS as eager (CSS should always be preloaded to avoid FOUC)\n if (chunk.css) {\n for (const cssFile of chunk.css) {\n eagerFiles.add(cssFile);\n }\n }\n\n // Follow only static imports — NOT dynamicImports\n if (chunk.imports) {\n for (const imp of chunk.imports) {\n if (!visited.has(imp)) {\n queue.push(imp);\n }\n }\n }\n }\n\n // Any JS file in the manifest that's NOT in eagerFiles is a lazy chunk\n const lazyChunks: string[] = [];\n const allFiles = new Set<string>();\n for (const key of Object.keys(buildManifest)) {\n const chunk = buildManifest[key];\n if (chunk.file && !allFiles.has(chunk.file)) {\n allFiles.add(chunk.file);\n if (!eagerFiles.has(chunk.file) && chunk.file.endsWith(\".js\")) {\n lazyChunks.push(chunk.file);\n }\n }\n }\n\n return lazyChunks;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8BA,SAAgB,kBAAkB,eAA6D;CAE7F,MAAM,6BAAa,IAAI,KAAa;CACpC,MAAM,0BAAU,IAAI,KAAa;CACjC,MAAM,QAAkB,EAAE;AAG1B,MAAK,MAAM,OAAO,OAAO,KAAK,cAAc,CAE1C,KADc,cAAc,KAClB,QACR,OAAM,KAAK,IAAI;AAInB,QAAO,MAAM,SAAS,GAAG;EACvB,MAAM,MAAM,MAAM,OAAO;AACzB,MAAI,CAAC,OAAO,QAAQ,IAAI,IAAI,CAAE;AAC9B,UAAQ,IAAI,IAAI;EAEhB,MAAM,QAAQ,cAAc;AAC5B,MAAI,CAAC,MAAO;AAGZ,aAAW,IAAI,MAAM,KAAK;AAG1B,MAAI,MAAM,IACR,MAAK,MAAM,WAAW,MAAM,IAC1B,YAAW,IAAI,QAAQ;AAK3B,MAAI,MAAM;QACH,MAAM,OAAO,MAAM,QACtB,KAAI,CAAC,QAAQ,IAAI,IAAI,CACnB,OAAM,KAAK,IAAI;;;CAOvB,MAAM,aAAuB,EAAE;CAC/B,MAAM,2BAAW,IAAI,KAAa;AAClC,MAAK,MAAM,OAAO,OAAO,KAAK,cAAc,EAAE;EAC5C,MAAM,QAAQ,cAAc;AAC5B,MAAI,MAAM,QAAQ,CAAC,SAAS,IAAI,MAAM,KAAK,EAAE;AAC3C,YAAS,IAAI,MAAM,KAAK;AACxB,OAAI,CAAC,WAAW,IAAI,MAAM,KAAK,IAAI,MAAM,KAAK,SAAS,MAAM,CAC3D,YAAW,KAAK,MAAM,KAAK;;;AAKjC,QAAO"}
|
package/package.json
CHANGED
package/dist/client/entry.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/client/entry.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { isValidModulePath } from "./validate-module-path.js";
|
|
2
|
-
import "./instrumentation-client.js";
|
|
3
|
-
import React from "react";
|
|
4
|
-
import { hydrateRoot } from "react-dom/client";
|
|
5
|
-
import "next/router.js";
|
|
6
|
-
//#region src/client/entry.ts
|
|
7
|
-
/**
|
|
8
|
-
* Client-side hydration entry point.
|
|
9
|
-
*
|
|
10
|
-
* This module is injected as a <script type="module"> in the SSR HTML.
|
|
11
|
-
* It reads __NEXT_DATA__ from the window, dynamically imports the page
|
|
12
|
-
* component, and hydrates it onto #__next.
|
|
13
|
-
*
|
|
14
|
-
* The actual page import path is injected at serve-time by the plugin
|
|
15
|
-
* via a virtual module or inline script.
|
|
16
|
-
*/
|
|
17
|
-
const nextData = window.__NEXT_DATA__;
|
|
18
|
-
const pageProps = nextData?.props.pageProps ?? {};
|
|
19
|
-
const pageModulePath = nextData?.__pageModule;
|
|
20
|
-
const appModulePath = nextData?.__appModule;
|
|
21
|
-
async function hydrate() {
|
|
22
|
-
if (!isValidModulePath(pageModulePath)) {
|
|
23
|
-
console.error("[vinext] Invalid or missing __pageModule in __NEXT_DATA__");
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const PageComponent = (await import(
|
|
27
|
-
/* @vite-ignore */
|
|
28
|
-
pageModulePath
|
|
29
|
-
)).default;
|
|
30
|
-
if (!PageComponent) {
|
|
31
|
-
console.error("[vinext] Page module has no default export");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
let element;
|
|
35
|
-
if (appModulePath) if (!isValidModulePath(appModulePath)) console.error("[vinext] Invalid __appModule in __NEXT_DATA__");
|
|
36
|
-
else try {
|
|
37
|
-
const AppComponent = (await import(
|
|
38
|
-
/* @vite-ignore */
|
|
39
|
-
appModulePath
|
|
40
|
-
)).default;
|
|
41
|
-
element = React.createElement(AppComponent, {
|
|
42
|
-
Component: PageComponent,
|
|
43
|
-
pageProps
|
|
44
|
-
});
|
|
45
|
-
} catch {}
|
|
46
|
-
if (!element) element = React.createElement(PageComponent, pageProps);
|
|
47
|
-
const container = document.getElementById("__next");
|
|
48
|
-
if (!container) {
|
|
49
|
-
console.error("[vinext] No #__next element found");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const root = hydrateRoot(container, element);
|
|
53
|
-
window.__VINEXT_ROOT__ = root;
|
|
54
|
-
window.__VINEXT_HYDRATED_AT = performance.now();
|
|
55
|
-
}
|
|
56
|
-
hydrate();
|
|
57
|
-
//#endregion
|
|
58
|
-
export {};
|
|
59
|
-
|
|
60
|
-
//# sourceMappingURL=entry.js.map
|
package/dist/client/entry.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","names":[],"sources":["../../src/client/entry.ts"],"sourcesContent":["/**\n * Client-side hydration entry point.\n *\n * This module is injected as a <script type=\"module\"> in the SSR HTML.\n * It reads __NEXT_DATA__ from the window, dynamically imports the page\n * component, and hydrates it onto #__next.\n *\n * The actual page import path is injected at serve-time by the plugin\n * via a virtual module or inline script.\n */\nimport React from \"react\";\nimport { hydrateRoot } from \"react-dom/client\";\nimport \"./instrumentation-client.js\";\n// Eagerly import the router shim so its module-level popstate listener is\n// registered. Without this, browser back/forward buttons do nothing because\n// navigateClient() is never invoked on history changes.\nimport \"next/router\";\nimport { isValidModulePath } from \"./validate-module-path.js\";\nimport type { VinextNextData } from \"./vinext-next-data.js\";\n\n// Read the SSR data injected by the server\nconst nextData = window.__NEXT_DATA__ as VinextNextData | undefined;\nconst pageProps = (nextData?.props.pageProps ?? {}) as Record<string, unknown>;\nconst pageModulePath = nextData?.__pageModule;\nconst appModulePath = nextData?.__appModule;\n\nasync function hydrate() {\n if (!isValidModulePath(pageModulePath)) {\n console.error(\"[vinext] Invalid or missing __pageModule in __NEXT_DATA__\");\n return;\n }\n\n // Dynamically import the page module\n const pageModule = await import(/* @vite-ignore */ pageModulePath);\n const PageComponent = pageModule.default;\n\n if (!PageComponent) {\n console.error(\"[vinext] Page module has no default export\");\n return;\n }\n\n let element: React.ReactElement;\n\n // If there's a custom _app, wrap the page with it\n if (appModulePath) {\n if (!isValidModulePath(appModulePath)) {\n console.error(\"[vinext] Invalid __appModule in __NEXT_DATA__\");\n } else {\n try {\n const appModule = await import(/* @vite-ignore */ appModulePath);\n const AppComponent = appModule.default;\n element = React.createElement(AppComponent, {\n Component: PageComponent,\n pageProps,\n });\n } catch {\n // No _app, render page directly\n }\n }\n }\n\n // @ts-expect-error -- element is assigned in the _app branch above, or falls through here\n if (!element) {\n element = React.createElement(PageComponent, pageProps);\n }\n\n const container = document.getElementById(\"__next\");\n if (!container) {\n console.error(\"[vinext] No #__next element found\");\n return;\n }\n\n const root = hydrateRoot(container, element);\n\n // Expose root on window so the router shim (a separate module) can\n // re-render the tree during client-side navigation. import.meta.hot.data\n // is module-scoped and cannot be read across module boundaries.\n window.__VINEXT_ROOT__ = root;\n window.__VINEXT_HYDRATED_AT = performance.now();\n}\n\nvoid hydrate();\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAM,WAAW,OAAO;AACxB,MAAM,YAAa,UAAU,MAAM,aAAa,EAAE;AAClD,MAAM,iBAAiB,UAAU;AACjC,MAAM,gBAAgB,UAAU;AAEhC,eAAe,UAAU;AACvB,KAAI,CAAC,kBAAkB,eAAe,EAAE;AACtC,UAAQ,MAAM,4DAA4D;AAC1E;;CAKF,MAAM,iBADa,MAAM;;EAA0B;GAClB;AAEjC,KAAI,CAAC,eAAe;AAClB,UAAQ,MAAM,6CAA6C;AAC3D;;CAGF,IAAI;AAGJ,KAAI,cACF,KAAI,CAAC,kBAAkB,cAAc,CACnC,SAAQ,MAAM,gDAAgD;KAE9D,KAAI;EAEF,MAAM,gBADY,MAAM;;GAA0B;GACnB;AAC/B,YAAU,MAAM,cAAc,cAAc;GAC1C,WAAW;GACX;GACD,CAAC;SACI;AAOZ,KAAI,CAAC,QACH,WAAU,MAAM,cAAc,eAAe,UAAU;CAGzD,MAAM,YAAY,SAAS,eAAe,SAAS;AACnD,KAAI,CAAC,WAAW;AACd,UAAQ,MAAM,oCAAoC;AAClD;;CAGF,MAAM,OAAO,YAAY,WAAW,QAAQ;AAK5C,QAAO,kBAAkB;AACzB,QAAO,uBAAuB,YAAY,KAAK;;AAG5C,SAAS"}
|