feat(blog): add file-based blog with dynamic slugs, MDX content and layout shell

- Introduced blog routing using Next.js App Router
- Implemented dynamic [slug] pages for blog posts
- Added MDX-based content loading via lib/posts
- Integrated shared TopBar layout with navigation
- Established clear content, lib and component separation
This commit is contained in:
PascalSchattenburg
2026-01-22 14:14:15 +01:00
parent b717952234
commit d147843c76
10412 changed files with 2475583 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import type { AppDirModules } from '../../build/webpack/loaders/next-app-loader';
/**
* LoaderTree is generated in next-app-loader.
*/
export type LoaderTree = [
segment: string,
parallelRoutes: {
[parallelRouterKey: string]: LoaderTree;
},
modules: AppDirModules
];
export declare function getLayoutOrPageModule(loaderTree: LoaderTree): Promise<{
mod: any;
modType: "page" | "layout" | undefined;
filePath: string | undefined;
}>;
export declare function getComponentTypeModule(loaderTree: LoaderTree, moduleType: 'layout' | 'not-found' | 'forbidden' | 'unauthorized'): Promise<any>;

View File

@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
getComponentTypeModule: null,
getLayoutOrPageModule: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
getComponentTypeModule: function() {
return getComponentTypeModule;
},
getLayoutOrPageModule: function() {
return getLayoutOrPageModule;
}
});
const _segment = require("../../shared/lib/segment");
async function getLayoutOrPageModule(loaderTree) {
const { layout, page, defaultPage } = loaderTree[2];
const isLayout = typeof layout !== 'undefined';
const isPage = typeof page !== 'undefined';
const isDefaultPage = typeof defaultPage !== 'undefined' && loaderTree[0] === _segment.DEFAULT_SEGMENT_KEY;
let mod = undefined;
let modType = undefined;
let filePath = undefined;
if (isLayout) {
mod = await layout[0]();
modType = 'layout';
filePath = layout[1];
} else if (isPage) {
mod = await page[0]();
modType = 'page';
filePath = page[1];
} else if (isDefaultPage) {
mod = await defaultPage[0]();
modType = 'page';
filePath = defaultPage[1];
}
return {
mod,
modType,
filePath
};
}
async function getComponentTypeModule(loaderTree, moduleType) {
const { [moduleType]: module1 } = loaderTree[2];
if (typeof module1 !== 'undefined') {
return await module1[0]();
}
return undefined;
}
//# sourceMappingURL=app-dir-module.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/app-dir-module.ts"],"sourcesContent":["import type { AppDirModules } from '../../build/webpack/loaders/next-app-loader'\nimport { DEFAULT_SEGMENT_KEY } from '../../shared/lib/segment'\n\n/**\n * LoaderTree is generated in next-app-loader.\n */\nexport type LoaderTree = [\n segment: string,\n parallelRoutes: { [parallelRouterKey: string]: LoaderTree },\n modules: AppDirModules,\n]\n\nexport async function getLayoutOrPageModule(loaderTree: LoaderTree) {\n const { layout, page, defaultPage } = loaderTree[2]\n const isLayout = typeof layout !== 'undefined'\n const isPage = typeof page !== 'undefined'\n const isDefaultPage =\n typeof defaultPage !== 'undefined' && loaderTree[0] === DEFAULT_SEGMENT_KEY\n\n let mod = undefined\n let modType: 'layout' | 'page' | undefined = undefined\n let filePath = undefined\n\n if (isLayout) {\n mod = await layout[0]()\n modType = 'layout'\n filePath = layout[1]\n } else if (isPage) {\n mod = await page[0]()\n modType = 'page'\n filePath = page[1]\n } else if (isDefaultPage) {\n mod = await defaultPage[0]()\n modType = 'page'\n filePath = defaultPage[1]\n }\n\n return { mod, modType, filePath }\n}\n\nexport async function getComponentTypeModule(\n loaderTree: LoaderTree,\n moduleType: 'layout' | 'not-found' | 'forbidden' | 'unauthorized'\n) {\n const { [moduleType]: module } = loaderTree[2]\n if (typeof module !== 'undefined') {\n return await module[0]()\n }\n return undefined\n}\n"],"names":["getComponentTypeModule","getLayoutOrPageModule","loaderTree","layout","page","defaultPage","isLayout","isPage","isDefaultPage","DEFAULT_SEGMENT_KEY","mod","undefined","modType","filePath","moduleType","module"],"mappings":";;;;;;;;;;;;;;;IAwCsBA,sBAAsB;eAAtBA;;IA5BAC,qBAAqB;eAArBA;;;yBAXc;AAW7B,eAAeA,sBAAsBC,UAAsB;IAChE,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGH,UAAU,CAAC,EAAE;IACnD,MAAMI,WAAW,OAAOH,WAAW;IACnC,MAAMI,SAAS,OAAOH,SAAS;IAC/B,MAAMI,gBACJ,OAAOH,gBAAgB,eAAeH,UAAU,CAAC,EAAE,KAAKO,4BAAmB;IAE7E,IAAIC,MAAMC;IACV,IAAIC,UAAyCD;IAC7C,IAAIE,WAAWF;IAEf,IAAIL,UAAU;QACZI,MAAM,MAAMP,MAAM,CAAC,EAAE;QACrBS,UAAU;QACVC,WAAWV,MAAM,CAAC,EAAE;IACtB,OAAO,IAAII,QAAQ;QACjBG,MAAM,MAAMN,IAAI,CAAC,EAAE;QACnBQ,UAAU;QACVC,WAAWT,IAAI,CAAC,EAAE;IACpB,OAAO,IAAII,eAAe;QACxBE,MAAM,MAAML,WAAW,CAAC,EAAE;QAC1BO,UAAU;QACVC,WAAWR,WAAW,CAAC,EAAE;IAC3B;IAEA,OAAO;QAAEK;QAAKE;QAASC;IAAS;AAClC;AAEO,eAAeb,uBACpBE,UAAsB,EACtBY,UAAiE;IAEjE,MAAM,EAAE,CAACA,WAAW,EAAEC,OAAM,EAAE,GAAGb,UAAU,CAAC,EAAE;IAC9C,IAAI,OAAOa,YAAW,aAAa;QACjC,OAAO,MAAMA,OAAM,CAAC,EAAE;IACxB;IACA,OAAOJ;AACT","ignoreList":[0]}

View File

@@ -0,0 +1,18 @@
import { type ConfiguredExperimentalFeature } from '../config';
export declare function logStartInfo({ networkUrl, appUrl, envInfo, experimentalFeatures, logBundler, cacheComponents, }: {
networkUrl: string | null;
appUrl: string | null;
envInfo?: string[];
experimentalFeatures?: ConfiguredExperimentalFeature[];
logBundler: boolean;
cacheComponents?: boolean;
}): void;
export declare function getStartServerInfo({ dir, dev, debugPrerender, }: {
dir: string;
dev: boolean;
debugPrerender?: boolean;
}): Promise<{
envInfo?: string[];
experimentalFeatures?: ConfiguredExperimentalFeature[];
cacheComponents?: boolean;
}>;

View File

@@ -0,0 +1,154 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
getStartServerInfo: null,
logStartInfo: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
getStartServerInfo: function() {
return getStartServerInfo;
},
logStartInfo: function() {
return logStartInfo;
}
});
const _env = require("@next/env");
const _inspector = /*#__PURE__*/ _interop_require_wildcard(require("inspector"));
const _log = /*#__PURE__*/ _interop_require_wildcard(require("../../build/output/log"));
const _picocolors = require("../../lib/picocolors");
const _constants = require("../../shared/lib/constants");
const _config = /*#__PURE__*/ _interop_require_default(require("../config"));
const _configschema = require("../config-schema");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
function logStartInfo({ networkUrl, appUrl, envInfo, experimentalFeatures, logBundler, cacheComponents }) {
let versionSuffix = '';
const parts = [];
if (logBundler) {
if (process.env.TURBOPACK) {
parts.push('Turbopack');
} else if (process.env.NEXT_RSPACK) {
parts.push('Rspack');
} else {
parts.push('webpack');
}
}
if (cacheComponents) {
parts.push('Cache Components');
}
if (parts.length > 0) {
versionSuffix = ` (${parts.join(', ')})`;
}
_log.bootstrap(`${(0, _picocolors.bold)((0, _picocolors.purple)(`${_log.prefixes.ready} Next.js ${"16.1.4"}`))}${versionSuffix}`);
if (appUrl) {
_log.bootstrap(`- Local: ${appUrl}`);
}
if (networkUrl) {
_log.bootstrap(`- Network: ${networkUrl}`);
}
const inspectorUrl = _inspector.url();
if (inspectorUrl) {
// Could also parse this port from the inspector URL.
// process.debugPort will always be defined even if the process is not being inspected.
// The full URL seems noisy as far as I can tell.
// Node.js will print the full URL anyway.
const debugPort = process.debugPort;
_log.bootstrap(`- Debugger port: ${debugPort}`);
}
if (envInfo == null ? void 0 : envInfo.length) _log.bootstrap(`- Environments: ${envInfo.join(', ')}`);
if (experimentalFeatures == null ? void 0 : experimentalFeatures.length) {
_log.bootstrap(`- Experiments (use with caution):`);
for (const exp of experimentalFeatures){
const isValid = Object.prototype.hasOwnProperty.call(_configschema.experimentalSchema, exp.key);
if (isValid) {
const symbol = typeof exp.value === 'boolean' ? exp.value === true ? (0, _picocolors.bold)('✓') : (0, _picocolors.bold)('') : '·';
const suffix = typeof exp.value === 'number' || typeof exp.value === 'string' ? `: ${JSON.stringify(exp.value)}` : '';
const reason = exp.reason ? ` (${exp.reason})` : '';
_log.bootstrap(` ${symbol} ${exp.key}${suffix}${reason}`);
} else {
_log.bootstrap(` ? ${(0, _picocolors.strikethrough)(exp.key)} (invalid experimental key)`);
}
}
}
// New line after the bootstrap info
_log.info('');
}
async function getStartServerInfo({ dir, dev, debugPrerender }) {
let experimentalFeatures = [];
let cacheComponents = false;
const config = await (0, _config.default)(dev ? _constants.PHASE_DEVELOPMENT_SERVER : _constants.PHASE_PRODUCTION_BUILD, dir, {
reportExperimentalFeatures (features) {
experimentalFeatures = features.sort(({ key: a }, { key: b })=>a.localeCompare(b));
},
debugPrerender,
silent: false
});
cacheComponents = !!config.cacheComponents;
// we need to reset env if we are going to create
// the worker process with the esm loader so that the
// initial env state is correct
let envInfo = [];
const { loadedEnvFiles } = (0, _env.loadEnvConfig)(dir, true, console, false);
if (loadedEnvFiles.length > 0) {
envInfo = loadedEnvFiles.map((f)=>f.path);
}
return {
envInfo,
experimentalFeatures,
cacheComponents
};
}
//# sourceMappingURL=app-info-log.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
export declare class AsyncCallbackSet {
private callbacks;
add(callback: () => Promise<void>): void;
runAll(): Promise<void>;
}

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "AsyncCallbackSet", {
enumerable: true,
get: function() {
return AsyncCallbackSet;
}
});
class AsyncCallbackSet {
add(callback) {
this.callbacks.push(callback);
}
async runAll() {
if (!this.callbacks.length) {
return;
}
const callbacks = this.callbacks;
this.callbacks = [];
await Promise.allSettled(callbacks.map(// NOTE: wrapped in an async function to protect against synchronous exceptions
async (f)=>f()));
}
constructor(){
this.callbacks = [];
}
}
//# sourceMappingURL=async-callback-set.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/async-callback-set.ts"],"sourcesContent":["export class AsyncCallbackSet {\n private callbacks: (() => Promise<void>)[] = []\n\n public add(callback: () => Promise<void>) {\n this.callbacks.push(callback)\n }\n\n public async runAll(): Promise<void> {\n if (!this.callbacks.length) {\n return\n }\n const callbacks = this.callbacks\n this.callbacks = []\n await Promise.allSettled(\n callbacks.map(\n // NOTE: wrapped in an async function to protect against synchronous exceptions\n async (f) => f()\n )\n )\n }\n}\n"],"names":["AsyncCallbackSet","add","callback","callbacks","push","runAll","length","Promise","allSettled","map","f"],"mappings":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA;IAGJC,IAAIC,QAA6B,EAAE;QACxC,IAAI,CAACC,SAAS,CAACC,IAAI,CAACF;IACtB;IAEA,MAAaG,SAAwB;QACnC,IAAI,CAAC,IAAI,CAACF,SAAS,CAACG,MAAM,EAAE;YAC1B;QACF;QACA,MAAMH,YAAY,IAAI,CAACA,SAAS;QAChC,IAAI,CAACA,SAAS,GAAG,EAAE;QACnB,MAAMI,QAAQC,UAAU,CACtBL,UAAUM,GAAG,CACX,+EAA+E;QAC/E,OAAOC,IAAMA;IAGnB;;aAlBQP,YAAqC,EAAE;;AAmBjD","ignoreList":[0]}

View File

@@ -0,0 +1,13 @@
/**
* The revalidate option used internally for pages. A value of `false` means
* that the page should not be revalidated. A number means that the page
* should be revalidated after the given number of seconds (this also includes
* `1` which means to revalidate after 1 second). A value of `0` is not a valid
* value for this option.
*/
export type Revalidate = number | false;
export interface CacheControl {
revalidate: Revalidate;
expire: number | undefined;
}
export declare function getCacheControlHeader({ revalidate, expire, }: CacheControl): string;

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getCacheControlHeader", {
enumerable: true,
get: function() {
return getCacheControlHeader;
}
});
const _constants = require("../../lib/constants");
function getCacheControlHeader({ revalidate, expire }) {
const swrHeader = typeof revalidate === 'number' && expire !== undefined && revalidate < expire ? `, stale-while-revalidate=${expire - revalidate}` : '';
if (revalidate === 0) {
return 'private, no-cache, no-store, max-age=0, must-revalidate';
} else if (typeof revalidate === 'number') {
return `s-maxage=${revalidate}${swrHeader}`;
}
return `s-maxage=${_constants.CACHE_ONE_YEAR}${swrHeader}`;
}
//# sourceMappingURL=cache-control.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/cache-control.ts"],"sourcesContent":["import { CACHE_ONE_YEAR } from '../../lib/constants'\n\n/**\n * The revalidate option used internally for pages. A value of `false` means\n * that the page should not be revalidated. A number means that the page\n * should be revalidated after the given number of seconds (this also includes\n * `1` which means to revalidate after 1 second). A value of `0` is not a valid\n * value for this option.\n */\nexport type Revalidate = number | false\n\nexport interface CacheControl {\n revalidate: Revalidate\n expire: number | undefined\n}\n\nexport function getCacheControlHeader({\n revalidate,\n expire,\n}: CacheControl): string {\n const swrHeader =\n typeof revalidate === 'number' &&\n expire !== undefined &&\n revalidate < expire\n ? `, stale-while-revalidate=${expire - revalidate}`\n : ''\n\n if (revalidate === 0) {\n return 'private, no-cache, no-store, max-age=0, must-revalidate'\n } else if (typeof revalidate === 'number') {\n return `s-maxage=${revalidate}${swrHeader}`\n }\n\n return `s-maxage=${CACHE_ONE_YEAR}${swrHeader}`\n}\n"],"names":["getCacheControlHeader","revalidate","expire","swrHeader","undefined","CACHE_ONE_YEAR"],"mappings":";;;;+BAgBgBA;;;eAAAA;;;2BAhBe;AAgBxB,SAASA,sBAAsB,EACpCC,UAAU,EACVC,MAAM,EACO;IACb,MAAMC,YACJ,OAAOF,eAAe,YACtBC,WAAWE,aACXH,aAAaC,SACT,CAAC,yBAAyB,EAAEA,SAASD,YAAY,GACjD;IAEN,IAAIA,eAAe,GAAG;QACpB,OAAO;IACT,OAAO,IAAI,OAAOA,eAAe,UAAU;QACzC,OAAO,CAAC,SAAS,EAAEA,aAAaE,WAAW;IAC7C;IAEA,OAAO,CAAC,SAAS,EAAEE,yBAAc,GAAGF,WAAW;AACjD","ignoreList":[0]}

View File

@@ -0,0 +1,10 @@
/**
* This is the default "use cache" handler it defaults to an in-memory store.
* In-memory caches are fragile and should not use stale-while-revalidate
* semantics on the caches because it's not worth warming up an entry that's
* likely going to get evicted before we get to use it anyway. However, we also
* don't want to reuse a stale entry for too long so stale entries should be
* considered expired/missing in such cache handlers.
*/
import type { CacheHandler } from './types';
export declare function createDefaultCacheHandler(maxSize: number): CacheHandler;

View File

@@ -0,0 +1,7 @@
/**
* Used for edge runtime compatibility.
*
* @deprecated Use createDefaultCacheHandler instead.
*/
declare const _default: import("./types").CacheHandler;
export default _default;

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, /**
* Used for edge runtime compatibility.
*
* @deprecated Use createDefaultCacheHandler instead.
*/ "default", {
enumerable: true,
get: function() {
return _default1;
}
});
const _default = require("./default");
const _default1 = (0, _default.createDefaultCacheHandler)(50 * 1024 * 1024);
//# sourceMappingURL=default.external.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/cache-handlers/default.external.ts"],"sourcesContent":["import { createDefaultCacheHandler } from './default'\n\n/**\n * Used for edge runtime compatibility.\n *\n * @deprecated Use createDefaultCacheHandler instead.\n */\nexport default createDefaultCacheHandler(50 * 1024 * 1024)\n"],"names":["createDefaultCacheHandler"],"mappings":";;;;+BAEA;;;;CAIC,GACD;;;eAAA;;;yBAP0C;MAO1C,YAAeA,IAAAA,kCAAyB,EAAC,KAAK,OAAO","ignoreList":[0]}

View File

@@ -0,0 +1,160 @@
/**
* This is the default "use cache" handler it defaults to an in-memory store.
* In-memory caches are fragile and should not use stale-while-revalidate
* semantics on the caches because it's not worth warming up an entry that's
* likely going to get evicted before we get to use it anyway. However, we also
* don't want to reuse a stale entry for too long so stale entries should be
* considered expired/missing in such cache handlers.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createDefaultCacheHandler", {
enumerable: true,
get: function() {
return createDefaultCacheHandler;
}
});
const _lrucache = require("../lru-cache");
const _tagsmanifestexternal = require("../incremental-cache/tags-manifest.external");
function createDefaultCacheHandler(maxSize) {
// If the max size is 0, return a cache handler that doesn't cache anything,
// this avoids an unnecessary LRUCache instance and potential memory
// allocation.
if (maxSize === 0) {
return {
get: ()=>Promise.resolve(undefined),
set: ()=>Promise.resolve(),
refreshTags: ()=>Promise.resolve(),
getExpiration: ()=>Promise.resolve(0),
updateTags: ()=>Promise.resolve()
};
}
const memoryCache = new _lrucache.LRUCache(maxSize, (entry)=>entry.size);
const pendingSets = new Map();
const debug = process.env.NEXT_PRIVATE_DEBUG_CACHE ? console.debug.bind(console, 'DefaultCacheHandler:') : undefined;
return {
async get (cacheKey) {
const pendingPromise = pendingSets.get(cacheKey);
if (pendingPromise) {
debug == null ? void 0 : debug('get', cacheKey, 'pending');
await pendingPromise;
}
const privateEntry = memoryCache.get(cacheKey);
if (!privateEntry) {
debug == null ? void 0 : debug('get', cacheKey, 'not found');
return undefined;
}
const entry = privateEntry.entry;
if (performance.timeOrigin + performance.now() > entry.timestamp + entry.revalidate * 1000) {
// In-memory caches should expire after revalidate time because it is
// unlikely that a new entry will be able to be used before it is dropped
// from the cache.
debug == null ? void 0 : debug('get', cacheKey, 'expired');
return undefined;
}
let revalidate = entry.revalidate;
if ((0, _tagsmanifestexternal.areTagsExpired)(entry.tags, entry.timestamp)) {
debug == null ? void 0 : debug('get', cacheKey, 'had expired tag');
return undefined;
}
if ((0, _tagsmanifestexternal.areTagsStale)(entry.tags, entry.timestamp)) {
debug == null ? void 0 : debug('get', cacheKey, 'had stale tag');
revalidate = -1;
}
const [returnStream, newSaved] = entry.value.tee();
entry.value = newSaved;
debug == null ? void 0 : debug('get', cacheKey, 'found', {
tags: entry.tags,
timestamp: entry.timestamp,
expire: entry.expire,
revalidate
});
return {
...entry,
revalidate,
value: returnStream
};
},
async set (cacheKey, pendingEntry) {
debug == null ? void 0 : debug('set', cacheKey, 'start');
let resolvePending = ()=>{};
const pendingPromise = new Promise((resolve)=>{
resolvePending = resolve;
});
pendingSets.set(cacheKey, pendingPromise);
const entry = await pendingEntry;
let size = 0;
try {
const [value, clonedValue] = entry.value.tee();
entry.value = value;
const reader = clonedValue.getReader();
for(let chunk; !(chunk = await reader.read()).done;){
size += Buffer.from(chunk.value).byteLength;
}
memoryCache.set(cacheKey, {
entry,
isErrored: false,
errorRetryCount: 0,
size
});
debug == null ? void 0 : debug('set', cacheKey, 'done');
} catch (err) {
// TODO: store partial buffer with error after we retry 3 times
debug == null ? void 0 : debug('set', cacheKey, 'failed', err);
} finally{
resolvePending();
pendingSets.delete(cacheKey);
}
},
async refreshTags () {
// Nothing to do for an in-memory cache handler.
},
async getExpiration (tags) {
const expirations = tags.map((tag)=>{
const entry = _tagsmanifestexternal.tagsManifest.get(tag);
if (!entry) return 0;
// Return the most recent timestamp (either expired or stale)
return entry.expired || 0;
});
const expiration = Math.max(...expirations, 0);
debug == null ? void 0 : debug('getExpiration', {
tags,
expiration
});
return expiration;
},
async updateTags (tags, durations) {
const now = Math.round(performance.timeOrigin + performance.now());
debug == null ? void 0 : debug('updateTags', {
tags,
timestamp: now
});
for (const tag of tags){
// TODO: update file-system-cache?
const existingEntry = _tagsmanifestexternal.tagsManifest.get(tag) || {};
if (durations) {
// Use provided durations directly
const updates = {
...existingEntry
};
// mark as stale immediately
updates.stale = now;
if (durations.expire !== undefined) {
updates.expired = now + durations.expire * 1000 // Convert seconds to ms
;
}
_tagsmanifestexternal.tagsManifest.set(tag, updates);
} else {
// Update expired field for immediate expiration (default behavior when no durations provided)
_tagsmanifestexternal.tagsManifest.set(tag, {
...existingEntry,
expired: now
});
}
}
}
};
}
//# sourceMappingURL=default.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,71 @@
/**
* A timestamp in milliseconds elapsed since the epoch
*/
export type Timestamp = number;
export interface CacheEntry {
/**
* The ReadableStream can error and only have partial data so any cache
* handlers need to handle this case and decide to keep the partial cache
* around or not.
*/
value: ReadableStream<Uint8Array>;
/**
* The tags configured for the entry excluding soft tags
*/
tags: string[];
/**
* This is for the client, not used to calculate cache entry expiration
* [duration in seconds]
*/
stale: number;
/**
* When the cache entry was created [timestamp in milliseconds]
*/
timestamp: Timestamp;
/**
* How long the entry is allowed to be used (should be longer than revalidate)
* [duration in seconds]
*/
expire: number;
/**
* How long until the entry should be revalidated [duration in seconds]
*/
revalidate: number;
}
export interface CacheHandler {
/**
* Retrieve a cache entry for the given cache key, if available. Will return
* undefined if there's no valid entry, or if the given soft tags are stale.
*/
get(cacheKey: string, softTags: string[]): Promise<undefined | CacheEntry>;
/**
* Store a cache entry for the given cache key. When this is called, the entry
* may still be pending, i.e. its value stream may still be written to. So it
* needs to be awaited first. If a `get` for the same cache key is called,
* before the pending entry is complete, the cache handler must wait for the
* `set` operation to finish, before returning the entry, instead of returning
* undefined.
*/
set(cacheKey: string, pendingEntry: Promise<CacheEntry>): Promise<void>;
/**
* This function may be called periodically, but always before starting a new
* request. If applicable, it should communicate with the tags service to
* refresh the local tags manifest accordingly.
*/
refreshTags(): Promise<void>;
/**
* This function is called for each set of soft tags that are relevant at the
* start of a request. The result is the maximum timestamp of a revalidate
* event for the tags. Returns `0` if none of the tags were ever revalidated.
* Returns `Infinity` if the soft tags are supposed to be passed into the
* `get` method instead to be checked for expiration.
*/
getExpiration(tags: string[]): Promise<Timestamp>;
/**
* This function is called when tags are revalidated/expired. If applicable,
* it should update the tags manifest accordingly.
*/
updateTags(tags: string[], durations?: {
expire?: number;
}): Promise<void>;
}

View File

@@ -0,0 +1,8 @@
/**
* A timestamp in milliseconds elapsed since the epoch
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/cache-handlers/types.ts"],"sourcesContent":["/**\n * A timestamp in milliseconds elapsed since the epoch\n */\nexport type Timestamp = number\n\nexport interface CacheEntry {\n /**\n * The ReadableStream can error and only have partial data so any cache\n * handlers need to handle this case and decide to keep the partial cache\n * around or not.\n */\n value: ReadableStream<Uint8Array>\n\n /**\n * The tags configured for the entry excluding soft tags\n */\n tags: string[]\n\n /**\n * This is for the client, not used to calculate cache entry expiration\n * [duration in seconds]\n */\n stale: number\n\n /**\n * When the cache entry was created [timestamp in milliseconds]\n */\n timestamp: Timestamp\n\n /**\n * How long the entry is allowed to be used (should be longer than revalidate)\n * [duration in seconds]\n */\n expire: number\n\n /**\n * How long until the entry should be revalidated [duration in seconds]\n */\n revalidate: number\n}\n\nexport interface CacheHandler {\n /**\n * Retrieve a cache entry for the given cache key, if available. Will return\n * undefined if there's no valid entry, or if the given soft tags are stale.\n */\n get(cacheKey: string, softTags: string[]): Promise<undefined | CacheEntry>\n\n /**\n * Store a cache entry for the given cache key. When this is called, the entry\n * may still be pending, i.e. its value stream may still be written to. So it\n * needs to be awaited first. If a `get` for the same cache key is called,\n * before the pending entry is complete, the cache handler must wait for the\n * `set` operation to finish, before returning the entry, instead of returning\n * undefined.\n */\n set(cacheKey: string, pendingEntry: Promise<CacheEntry>): Promise<void>\n\n /**\n * This function may be called periodically, but always before starting a new\n * request. If applicable, it should communicate with the tags service to\n * refresh the local tags manifest accordingly.\n */\n refreshTags(): Promise<void>\n\n /**\n * This function is called for each set of soft tags that are relevant at the\n * start of a request. The result is the maximum timestamp of a revalidate\n * event for the tags. Returns `0` if none of the tags were ever revalidated.\n * Returns `Infinity` if the soft tags are supposed to be passed into the\n * `get` method instead to be checked for expiration.\n */\n getExpiration(tags: string[]): Promise<Timestamp>\n\n /**\n * This function is called when tags are revalidated/expired. If applicable,\n * it should update the tags manifest accordingly.\n */\n updateTags(tags: string[], durations?: { expire?: number }): Promise<void>\n}\n"],"names":[],"mappings":"AAAA;;CAEC","ignoreList":[0]}

View File

@@ -0,0 +1,6 @@
import type { ServerResponse } from 'http';
import type { NextConfigRuntime } from '../config-shared';
export declare function isChromeDevtoolsWorkspaceUrl(pathname: string | undefined): boolean;
export declare function handleChromeDevtoolsWorkspaceRequest(response: ServerResponse, opts: {
dir: string;
}, config: NextConfigRuntime): Promise<void>;

View File

@@ -0,0 +1,116 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
handleChromeDevtoolsWorkspaceRequest: null,
isChromeDevtoolsWorkspaceUrl: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
handleChromeDevtoolsWorkspaceRequest: function() {
return handleChromeDevtoolsWorkspaceRequest;
},
isChromeDevtoolsWorkspaceUrl: function() {
return isChromeDevtoolsWorkspaceUrl;
}
});
const _crypto = require("crypto");
const _fs = /*#__PURE__*/ _interop_require_wildcard(require("fs"));
const _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
const _cachedir = require("../cache-dir");
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
// Keep the uuid in memory as it should never change during the lifetime of the server.
let workspaceUUID = null;
function isChromeDevtoolsWorkspaceUrl(pathname) {
return pathname === '/.well-known/appspecific/com.chrome.devtools.json';
}
async function handleChromeDevtoolsWorkspaceRequest(response, opts, config) {
response.setHeader('Content-Type', 'application/json');
response.end(JSON.stringify(await getChromeDevtoolsWorkspace(opts.dir, config.distDir), null, 2));
}
/**
* For https://developer.chrome.com/docs/devtools/workspaces
*/ async function getChromeDevtoolsWorkspace(root, configDistDir) {
if (workspaceUUID === null) {
const distDir = _path.join(root, configDistDir);
const cacheBaseDir = (0, _cachedir.getStorageDirectory)(distDir);
if (cacheBaseDir === undefined) {
workspaceUUID = (0, _crypto.randomUUID)();
} else {
const cachedUUIDPath = _path.join(cacheBaseDir, 'chrome-devtools-workspace-uuid');
try {
workspaceUUID = await _fs.promises.readFile(cachedUUIDPath, 'utf8');
} catch {
// TODO: Why does this need to be v4 and not v5?
// With v5 we could base it off of the `distDir` and `root` which would
// allow us to persist the workspace across .next wipes.
workspaceUUID = (0, _crypto.randomUUID)();
try {
await _fs.promises.writeFile(cachedUUIDPath, workspaceUUID, 'utf8');
} catch (cause) {
console.warn(Object.defineProperty(new Error('Failed to persist Chrome DevTools workspace UUID. The Chrome DevTools Workspace needs to be reconnected after the next page reload.', {
cause
}), "__NEXT_ERROR_CODE", {
value: "E708",
enumerable: false,
configurable: true
}));
}
}
}
}
return {
workspace: {
uuid: workspaceUUID,
root
}
};
}
//# sourceMappingURL=chrome-devtools-workspace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/chrome-devtools-workspace.ts"],"sourcesContent":["import type { ServerResponse } from 'http'\nimport type { NextConfigRuntime } from '../config-shared'\n\nimport { randomUUID } from 'crypto'\nimport * as fs from 'fs'\nimport * as path from 'path'\nimport { getStorageDirectory } from '../cache-dir'\n\n// Keep the uuid in memory as it should never change during the lifetime of the server.\nlet workspaceUUID: string | null = null\n\nexport function isChromeDevtoolsWorkspaceUrl(\n pathname: string | undefined\n): boolean {\n return pathname === '/.well-known/appspecific/com.chrome.devtools.json'\n}\n\nexport async function handleChromeDevtoolsWorkspaceRequest(\n response: ServerResponse,\n opts: { dir: string },\n config: NextConfigRuntime\n): Promise<void> {\n response.setHeader('Content-Type', 'application/json')\n response.end(\n JSON.stringify(\n await getChromeDevtoolsWorkspace(opts.dir, config.distDir),\n null,\n 2\n )\n )\n}\n\n/**\n * https://developer.chrome.com/docs/devtools/workspaces#generate-json\n */\ninterface ChromeDevtoolsWorkspace {\n workspace: {\n uuid: string\n root: string\n }\n}\n\n/**\n * For https://developer.chrome.com/docs/devtools/workspaces\n */\nasync function getChromeDevtoolsWorkspace(\n root: string,\n configDistDir: string\n): Promise<ChromeDevtoolsWorkspace> {\n if (workspaceUUID === null) {\n const distDir = path.join(root, configDistDir)\n const cacheBaseDir = getStorageDirectory(distDir)\n\n if (cacheBaseDir === undefined) {\n workspaceUUID = randomUUID()\n } else {\n const cachedUUIDPath = path.join(\n cacheBaseDir,\n 'chrome-devtools-workspace-uuid'\n )\n try {\n workspaceUUID = await fs.promises.readFile(cachedUUIDPath, 'utf8')\n } catch {\n // TODO: Why does this need to be v4 and not v5?\n // With v5 we could base it off of the `distDir` and `root` which would\n // allow us to persist the workspace across .next wipes.\n workspaceUUID = randomUUID()\n\n try {\n await fs.promises.writeFile(cachedUUIDPath, workspaceUUID, 'utf8')\n } catch (cause) {\n console.warn(\n new Error(\n 'Failed to persist Chrome DevTools workspace UUID. The Chrome DevTools Workspace needs to be reconnected after the next page reload.',\n { cause }\n )\n )\n }\n }\n }\n }\n\n return {\n workspace: {\n uuid: workspaceUUID,\n root,\n },\n }\n}\n"],"names":["handleChromeDevtoolsWorkspaceRequest","isChromeDevtoolsWorkspaceUrl","workspaceUUID","pathname","response","opts","config","setHeader","end","JSON","stringify","getChromeDevtoolsWorkspace","dir","distDir","root","configDistDir","path","join","cacheBaseDir","getStorageDirectory","undefined","randomUUID","cachedUUIDPath","fs","promises","readFile","writeFile","cause","console","warn","Error","workspace","uuid"],"mappings":";;;;;;;;;;;;;;;IAiBsBA,oCAAoC;eAApCA;;IANNC,4BAA4B;eAA5BA;;;wBARW;4DACP;8DACE;0BACc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEpC,uFAAuF;AACvF,IAAIC,gBAA+B;AAE5B,SAASD,6BACdE,QAA4B;IAE5B,OAAOA,aAAa;AACtB;AAEO,eAAeH,qCACpBI,QAAwB,EACxBC,IAAqB,EACrBC,MAAyB;IAEzBF,SAASG,SAAS,CAAC,gBAAgB;IACnCH,SAASI,GAAG,CACVC,KAAKC,SAAS,CACZ,MAAMC,2BAA2BN,KAAKO,GAAG,EAAEN,OAAOO,OAAO,GACzD,MACA;AAGN;AAYA;;CAEC,GACD,eAAeF,2BACbG,IAAY,EACZC,aAAqB;IAErB,IAAIb,kBAAkB,MAAM;QAC1B,MAAMW,UAAUG,MAAKC,IAAI,CAACH,MAAMC;QAChC,MAAMG,eAAeC,IAAAA,6BAAmB,EAACN;QAEzC,IAAIK,iBAAiBE,WAAW;YAC9BlB,gBAAgBmB,IAAAA,kBAAU;QAC5B,OAAO;YACL,MAAMC,iBAAiBN,MAAKC,IAAI,CAC9BC,cACA;YAEF,IAAI;gBACFhB,gBAAgB,MAAMqB,IAAGC,QAAQ,CAACC,QAAQ,CAACH,gBAAgB;YAC7D,EAAE,OAAM;gBACN,gDAAgD;gBAChD,uEAAuE;gBACvE,wDAAwD;gBACxDpB,gBAAgBmB,IAAAA,kBAAU;gBAE1B,IAAI;oBACF,MAAME,IAAGC,QAAQ,CAACE,SAAS,CAACJ,gBAAgBpB,eAAe;gBAC7D,EAAE,OAAOyB,OAAO;oBACdC,QAAQC,IAAI,CACV,qBAGC,CAHD,IAAIC,MACF,uIACA;wBAAEH;oBAAM,IAFV,qBAAA;+BAAA;oCAAA;sCAAA;oBAGA;gBAEJ;YACF;QACF;IACF;IAEA,OAAO;QACLI,WAAW;YACTC,MAAM9B;YACNY;QACF;IACF;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,13 @@
/**
* Clones a response by teeing the body so we can return two independent
* ReadableStreams from it. This avoids the bug in the undici library around
* response cloning.
*
* After cloning, the original response's body will be consumed and closed.
*
* @see https://github.com/vercel/next.js/pull/73274
*
* @param original - The original response to clone.
* @returns A tuple containing two independent clones of the original response.
*/
export declare function cloneResponse(original: Response): [Response, Response];

View File

@@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "cloneResponse", {
enumerable: true,
get: function() {
return cloneResponse;
}
});
const noop = ()=>{};
let registry;
if (globalThis.FinalizationRegistry) {
registry = new FinalizationRegistry((weakRef)=>{
const stream = weakRef.deref();
if (stream && !stream.locked) {
stream.cancel('Response object has been garbage collected').then(noop);
}
});
}
function cloneResponse(original) {
// If the response has no body, then we can just return the original response
// twice because it's immutable.
if (!original.body) {
return [
original,
original
];
}
const [body1, body2] = original.body.tee();
const cloned1 = new Response(body1, {
status: original.status,
statusText: original.statusText,
headers: original.headers
});
Object.defineProperty(cloned1, 'url', {
value: original.url,
// How the original response.url behaves
configurable: true,
enumerable: true,
writable: false
});
// The Fetch Standard allows users to skip consuming the response body by
// relying on garbage collection to release connection resources.
// https://github.com/nodejs/undici?tab=readme-ov-file#garbage-collection
//
// To cancel the stream you then need to cancel both resulting branches.
// Teeing a stream will generally lock it for the duration, preventing other
// readers from locking it.
// https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee
// cloned2 is stored in a react cache and cloned for subsequent requests.
// It is the original request, and is is garbage collected by a
// FinalizationRegistry in Undici, but since we're tee-ing the stream
// ourselves, we need to cancel clone1's stream (the response returned from
// our dedupe fetch) when clone1 is reclaimed, otherwise we leak memory.
if (registry && cloned1.body) {
registry.register(cloned1, new WeakRef(cloned1.body));
}
const cloned2 = new Response(body2, {
status: original.status,
statusText: original.statusText,
headers: original.headers
});
Object.defineProperty(cloned2, 'url', {
value: original.url,
// How the original response.url behaves
configurable: true,
enumerable: true,
writable: false
});
return [
cloned1,
cloned2
];
}
//# sourceMappingURL=clone-response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/clone-response.ts"],"sourcesContent":["const noop = () => {}\n\nlet registry: FinalizationRegistry<WeakRef<ReadableStream>> | undefined\n\nif (globalThis.FinalizationRegistry) {\n registry = new FinalizationRegistry((weakRef: WeakRef<ReadableStream>) => {\n const stream = weakRef.deref()\n if (stream && !stream.locked) {\n stream.cancel('Response object has been garbage collected').then(noop)\n }\n })\n}\n\n/**\n * Clones a response by teeing the body so we can return two independent\n * ReadableStreams from it. This avoids the bug in the undici library around\n * response cloning.\n *\n * After cloning, the original response's body will be consumed and closed.\n *\n * @see https://github.com/vercel/next.js/pull/73274\n *\n * @param original - The original response to clone.\n * @returns A tuple containing two independent clones of the original response.\n */\nexport function cloneResponse(original: Response): [Response, Response] {\n // If the response has no body, then we can just return the original response\n // twice because it's immutable.\n if (!original.body) {\n return [original, original]\n }\n\n const [body1, body2] = original.body.tee()\n\n const cloned1 = new Response(body1, {\n status: original.status,\n statusText: original.statusText,\n headers: original.headers,\n })\n\n Object.defineProperty(cloned1, 'url', {\n value: original.url,\n // How the original response.url behaves\n configurable: true,\n enumerable: true,\n writable: false,\n })\n\n // The Fetch Standard allows users to skip consuming the response body by\n // relying on garbage collection to release connection resources.\n // https://github.com/nodejs/undici?tab=readme-ov-file#garbage-collection\n //\n // To cancel the stream you then need to cancel both resulting branches.\n // Teeing a stream will generally lock it for the duration, preventing other\n // readers from locking it.\n // https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee\n\n // cloned2 is stored in a react cache and cloned for subsequent requests.\n // It is the original request, and is is garbage collected by a\n // FinalizationRegistry in Undici, but since we're tee-ing the stream\n // ourselves, we need to cancel clone1's stream (the response returned from\n // our dedupe fetch) when clone1 is reclaimed, otherwise we leak memory.\n if (registry && cloned1.body) {\n registry.register(cloned1, new WeakRef(cloned1.body))\n }\n\n const cloned2 = new Response(body2, {\n status: original.status,\n statusText: original.statusText,\n headers: original.headers,\n })\n\n Object.defineProperty(cloned2, 'url', {\n value: original.url,\n // How the original response.url behaves\n configurable: true,\n enumerable: true,\n writable: false,\n })\n\n return [cloned1, cloned2]\n}\n"],"names":["cloneResponse","noop","registry","globalThis","FinalizationRegistry","weakRef","stream","deref","locked","cancel","then","original","body","body1","body2","tee","cloned1","Response","status","statusText","headers","Object","defineProperty","value","url","configurable","enumerable","writable","register","WeakRef","cloned2"],"mappings":";;;;+BAyBgBA;;;eAAAA;;;AAzBhB,MAAMC,OAAO,KAAO;AAEpB,IAAIC;AAEJ,IAAIC,WAAWC,oBAAoB,EAAE;IACnCF,WAAW,IAAIE,qBAAqB,CAACC;QACnC,MAAMC,SAASD,QAAQE,KAAK;QAC5B,IAAID,UAAU,CAACA,OAAOE,MAAM,EAAE;YAC5BF,OAAOG,MAAM,CAAC,8CAA8CC,IAAI,CAACT;QACnE;IACF;AACF;AAcO,SAASD,cAAcW,QAAkB;IAC9C,6EAA6E;IAC7E,gCAAgC;IAChC,IAAI,CAACA,SAASC,IAAI,EAAE;QAClB,OAAO;YAACD;YAAUA;SAAS;IAC7B;IAEA,MAAM,CAACE,OAAOC,MAAM,GAAGH,SAASC,IAAI,CAACG,GAAG;IAExC,MAAMC,UAAU,IAAIC,SAASJ,OAAO;QAClCK,QAAQP,SAASO,MAAM;QACvBC,YAAYR,SAASQ,UAAU;QAC/BC,SAAST,SAASS,OAAO;IAC3B;IAEAC,OAAOC,cAAc,CAACN,SAAS,OAAO;QACpCO,OAAOZ,SAASa,GAAG;QACnB,wCAAwC;QACxCC,cAAc;QACdC,YAAY;QACZC,UAAU;IACZ;IAEA,yEAAyE;IACzE,iEAAiE;IACjE,yEAAyE;IACzE,EAAE;IACF,wEAAwE;IACxE,4EAA4E;IAC5E,2BAA2B;IAC3B,sEAAsE;IAEtE,yEAAyE;IACzE,+DAA+D;IAC/D,qEAAqE;IACrE,2EAA2E;IAC3E,wEAAwE;IACxE,IAAIzB,YAAYc,QAAQJ,IAAI,EAAE;QAC5BV,SAAS0B,QAAQ,CAACZ,SAAS,IAAIa,QAAQb,QAAQJ,IAAI;IACrD;IAEA,MAAMkB,UAAU,IAAIb,SAASH,OAAO;QAClCI,QAAQP,SAASO,MAAM;QACvBC,YAAYR,SAASQ,UAAU;QAC/BC,SAAST,SAASS,OAAO;IAC3B;IAEAC,OAAOC,cAAc,CAACQ,SAAS,OAAO;QACpCP,OAAOZ,SAASa,GAAG;QACnB,wCAAwC;QACxCC,cAAc;QACdC,YAAY;QACZC,UAAU;IACZ;IAEA,OAAO;QAACX;QAASc;KAAQ;AAC3B","ignoreList":[0]}

View File

@@ -0,0 +1,2 @@
declare const privateCpuProfileName: string | undefined;
declare const isCpuProfileEnabled: string | undefined;

View File

@@ -0,0 +1,28 @@
"use strict";
const privateCpuProfileName = process.env.__NEXT_PRIVATE_CPU_PROFILE;
const isCpuProfileEnabled = process.env.NEXT_CPU_PROF || privateCpuProfileName;
if (isCpuProfileEnabled) {
const { Session } = require('inspector');
const fs = require('fs');
const session = new Session();
session.connect();
session.post('Profiler.enable');
session.post('Profiler.start');
function saveProfile() {
session.post('Profiler.stop', (error, param)=>{
if (error) {
console.error('Cannot generate CPU profiling:', error);
return;
}
// Write profile to disk
const filename = `${privateCpuProfileName || 'CPU.main'}.${Date.now()}.cpuprofile`;
fs.writeFileSync(`./${filename}`, JSON.stringify(param.profile));
process.exit(0);
});
}
process.on('SIGINT', saveProfile);
process.on('SIGTERM', saveProfile);
process.on('exit', saveProfile);
}
//# sourceMappingURL=cpu-profile.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/cpu-profile.ts"],"sourcesContent":["const privateCpuProfileName = process.env.__NEXT_PRIVATE_CPU_PROFILE\nconst isCpuProfileEnabled = process.env.NEXT_CPU_PROF || privateCpuProfileName\n\nif (isCpuProfileEnabled) {\n const { Session } = require('inspector') as typeof import('inspector')\n const fs = require('fs') as typeof import('fs')\n\n const session = new Session()\n session.connect()\n\n session.post('Profiler.enable')\n session.post('Profiler.start')\n\n function saveProfile() {\n session.post('Profiler.stop', (error, param) => {\n if (error) {\n console.error('Cannot generate CPU profiling:', error)\n return\n }\n\n // Write profile to disk\n const filename = `${\n privateCpuProfileName || 'CPU.main'\n }.${Date.now()}.cpuprofile`\n fs.writeFileSync(`./${filename}`, JSON.stringify(param.profile))\n process.exit(0)\n })\n }\n process.on('SIGINT', saveProfile)\n process.on('SIGTERM', saveProfile)\n process.on('exit', saveProfile)\n}\n"],"names":["privateCpuProfileName","process","env","__NEXT_PRIVATE_CPU_PROFILE","isCpuProfileEnabled","NEXT_CPU_PROF","Session","require","fs","session","connect","post","saveProfile","error","param","console","filename","Date","now","writeFileSync","JSON","stringify","profile","exit","on"],"mappings":";AAAA,MAAMA,wBAAwBC,QAAQC,GAAG,CAACC,0BAA0B;AACpE,MAAMC,sBAAsBH,QAAQC,GAAG,CAACG,aAAa,IAAIL;AAEzD,IAAII,qBAAqB;IACvB,MAAM,EAAEE,OAAO,EAAE,GAAGC,QAAQ;IAC5B,MAAMC,KAAKD,QAAQ;IAEnB,MAAME,UAAU,IAAIH;IACpBG,QAAQC,OAAO;IAEfD,QAAQE,IAAI,CAAC;IACbF,QAAQE,IAAI,CAAC;IAEb,SAASC;QACPH,QAAQE,IAAI,CAAC,iBAAiB,CAACE,OAAOC;YACpC,IAAID,OAAO;gBACTE,QAAQF,KAAK,CAAC,kCAAkCA;gBAChD;YACF;YAEA,wBAAwB;YACxB,MAAMG,WAAW,GACfhB,yBAAyB,WAC1B,CAAC,EAAEiB,KAAKC,GAAG,GAAG,WAAW,CAAC;YAC3BV,GAAGW,aAAa,CAAC,CAAC,EAAE,EAAEH,UAAU,EAAEI,KAAKC,SAAS,CAACP,MAAMQ,OAAO;YAC9DrB,QAAQsB,IAAI,CAAC;QACf;IACF;IACAtB,QAAQuB,EAAE,CAAC,UAAUZ;IACrBX,QAAQuB,EAAE,CAAC,WAAWZ;IACtBX,QAAQuB,EAAE,CAAC,QAAQZ;AACrB","ignoreList":[0]}

View File

@@ -0,0 +1,7 @@
/**
* Decodes a query path parameter.
*
* @param value - The value to decode.
* @returns The decoded value.
*/
export declare function decodeQueryPathParameter(value: string): string;

View File

@@ -0,0 +1,26 @@
/**
* Decodes a query path parameter.
*
* @param value - The value to decode.
* @returns The decoded value.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "decodeQueryPathParameter", {
enumerable: true,
get: function() {
return decodeQueryPathParameter;
}
});
function decodeQueryPathParameter(value) {
// When deployed to Vercel, the value may be encoded, so this attempts to
// decode it and returns the original value if it fails.
try {
return decodeURIComponent(value);
} catch {
return value;
}
}
//# sourceMappingURL=decode-query-path-parameter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/decode-query-path-parameter.ts"],"sourcesContent":["/**\n * Decodes a query path parameter.\n *\n * @param value - The value to decode.\n * @returns The decoded value.\n */\nexport function decodeQueryPathParameter(value: string) {\n // When deployed to Vercel, the value may be encoded, so this attempts to\n // decode it and returns the original value if it fails.\n try {\n return decodeURIComponent(value)\n } catch {\n return value\n }\n}\n"],"names":["decodeQueryPathParameter","value","decodeURIComponent"],"mappings":"AAAA;;;;;CAKC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,yBAAyBC,KAAa;IACpD,yEAAyE;IACzE,wDAAwD;IACxD,IAAI;QACF,OAAOC,mBAAmBD;IAC5B,EAAE,OAAM;QACN,OAAOA;IACT;AACF","ignoreList":[0]}

View File

@@ -0,0 +1 @@
export declare function createDedupeFetch(originalFetch: typeof fetch): (resource: URL | RequestInfo, options?: RequestInit) => Promise<Response>;

View File

@@ -0,0 +1,163 @@
/**
* Based on https://github.com/facebook/react/blob/d4e78c42a94be027b4dc7ed2659a5fddfbf9bd4e/packages/react/src/ReactFetch.js
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createDedupeFetch", {
enumerable: true,
get: function() {
return createDedupeFetch;
}
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _cloneresponse = require("./clone-response");
const _invarianterror = require("../../shared/lib/invariant-error");
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
const simpleCacheKey = '["GET",[],null,"follow",null,null,null,null]' // generateCacheKey(new Request('https://blank'));
;
// Headers that should not affect deduplication
// traceparent and tracestate are used for distributed tracing and should not affect cache keys
const headersToExcludeInCacheKey = new Set([
'traceparent',
'tracestate'
]);
function generateCacheKey(request) {
// We pick the fields that goes into the key used to dedupe requests.
// We don't include the `cache` field, because we end up using whatever
// caching resulted from the first request.
// Notably we currently don't consider non-standard (or future) options.
// This might not be safe. TODO: warn for non-standard extensions differing.
// IF YOU CHANGE THIS UPDATE THE simpleCacheKey ABOVE.
const filteredHeaders = Array.from(request.headers.entries()).filter(([key])=>!headersToExcludeInCacheKey.has(key.toLowerCase()));
return JSON.stringify([
request.method,
filteredHeaders,
request.mode,
request.redirect,
request.credentials,
request.referrer,
request.referrerPolicy,
request.integrity
]);
}
function createDedupeFetch(originalFetch) {
const getCacheEntries = _react.cache(// eslint-disable-next-line @typescript-eslint/no-unused-vars -- url is the cache key
(url)=>[]);
return function dedupeFetch(resource, options) {
if (options && options.signal) {
// If we're passed a signal, then we assume that
// someone else controls the lifetime of this object and opts out of
// caching. It's effectively the opt-out mechanism.
// Ideally we should be able to check this on the Request but
// it always gets initialized with its own signal so we don't
// know if it's supposed to override - unless we also override the
// Request constructor.
return originalFetch(resource, options);
}
// Normalize the Request
let url;
let cacheKey;
if (typeof resource === 'string' && !options) {
// Fast path.
cacheKey = simpleCacheKey;
url = resource;
} else {
// Normalize the request.
// if resource is not a string or a URL (its an instance of Request)
// then do not instantiate a new Request but instead
// reuse the request as to not disturb the body in the event it's a ReadableStream.
const request = typeof resource === 'string' || resource instanceof URL ? new Request(resource, options) : resource;
if (request.method !== 'GET' && request.method !== 'HEAD' || request.keepalive) {
// We currently don't dedupe requests that might have side-effects. Those
// have to be explicitly cached. We assume that the request doesn't have a
// body if it's GET or HEAD.
// keepalive gets treated the same as if you passed a custom cache signal.
return originalFetch(resource, options);
}
cacheKey = generateCacheKey(request);
url = request.url;
}
const cacheEntries = getCacheEntries(url);
for(let i = 0, j = cacheEntries.length; i < j; i += 1){
const [key, promise] = cacheEntries[i];
if (key === cacheKey) {
return promise.then(()=>{
const response = cacheEntries[i][2];
if (!response) throw Object.defineProperty(new _invarianterror.InvariantError('No cached response'), "__NEXT_ERROR_CODE", {
value: "E579",
enumerable: false,
configurable: true
});
// We're cloning the response using this utility because there exists
// a bug in the undici library around response cloning. See the
// following pull request for more details:
// https://github.com/vercel/next.js/pull/73274
const [cloned1, cloned2] = (0, _cloneresponse.cloneResponse)(response);
cacheEntries[i][2] = cloned2;
return cloned1;
});
}
}
// We pass the original arguments here in case normalizing the Request
// doesn't include all the options in this environment.
const promise = originalFetch(resource, options);
const entry = [
cacheKey,
promise,
null
];
cacheEntries.push(entry);
return promise.then((response)=>{
// We're cloning the response using this utility because there exists
// a bug in the undici library around response cloning. See the
// following pull request for more details:
// https://github.com/vercel/next.js/pull/73274
const [cloned1, cloned2] = (0, _cloneresponse.cloneResponse)(response);
entry[2] = cloned2;
return cloned1;
});
};
}
//# sourceMappingURL=dedupe-fetch.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,31 @@
import type { IncomingMessage } from 'http';
import type { DevBundler } from './router-utils/setup-dev-bundler';
import type { WorkerRequestHandler } from './types';
import { LRUCache } from './lru-cache';
import { type HmrMessageSentToBrowser, type NextJsHotReloaderInterface } from '../dev/hot-reloader-types';
/**
* The DevBundlerService provides an interface to perform tasks with the
* bundler while in development.
*/
export declare class DevBundlerService {
private readonly bundler;
private readonly handler;
appIsrManifestInner: InstanceType<typeof LRUCache<boolean>>;
close: NextJsHotReloaderInterface['close'];
setCacheStatus: NextJsHotReloaderInterface['setCacheStatus'];
setReactDebugChannel: NextJsHotReloaderInterface['setReactDebugChannel'];
sendErrorsToBrowser: NextJsHotReloaderInterface['sendErrorsToBrowser'];
constructor(bundler: DevBundler, handler: WorkerRequestHandler);
ensurePage: typeof this.bundler.hotReloader.ensurePage;
logErrorWithOriginalStack: (err: unknown, type?: "unhandledRejection" | "uncaughtException" | "warning" | "app-dir") => void;
getFallbackErrorComponents(url?: string): Promise<void>;
getCompilationError(page: string): Promise<any>;
revalidate({ urlPath, revalidateHeaders, opts: revalidateOpts, }: {
urlPath: string;
revalidateHeaders: IncomingMessage['headers'];
opts: any;
}): Promise<{}>;
get appIsrManifest(): Record<string, boolean>;
setIsrStatus(key: string, value: boolean | undefined): void;
sendHmrMessage(message: HmrMessageSentToBrowser): void;
}

View File

@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DevBundlerService", {
enumerable: true,
get: function() {
return DevBundlerService;
}
});
const _lrucache = require("./lru-cache");
const _mockrequest = require("./mock-request");
const _hotreloadertypes = require("../dev/hot-reloader-types");
class DevBundlerService {
constructor(bundler, handler){
this.bundler = bundler;
this.handler = handler;
this.ensurePage = async (definition)=>{
// TODO: remove after ensure is pulled out of server
return await this.bundler.hotReloader.ensurePage(definition);
};
this.logErrorWithOriginalStack = this.bundler.logErrorWithOriginalStack.bind(this.bundler);
this.appIsrManifestInner = new _lrucache.LRUCache(8000, function length() {
return 16;
});
const { hotReloader } = bundler;
this.close = hotReloader.close.bind(hotReloader);
this.setCacheStatus = hotReloader.setCacheStatus.bind(hotReloader);
this.setReactDebugChannel = hotReloader.setReactDebugChannel.bind(hotReloader);
this.sendErrorsToBrowser = hotReloader.sendErrorsToBrowser.bind(hotReloader);
}
async getFallbackErrorComponents(url) {
await this.bundler.hotReloader.buildFallbackError();
// Build the error page to ensure the fallback is built too.
// TODO: See if this can be moved into hotReloader or removed.
await this.bundler.hotReloader.ensurePage({
page: '/_error',
clientOnly: false,
definition: undefined,
url
});
}
async getCompilationError(page) {
const errors = await this.bundler.hotReloader.getCompilationErrors(page);
if (!errors) return;
// Return the very first error we found.
return errors[0];
}
async revalidate({ urlPath, revalidateHeaders, opts: revalidateOpts }) {
const mocked = (0, _mockrequest.createRequestResponseMocks)({
url: urlPath,
headers: revalidateHeaders
});
await this.handler(mocked.req, mocked.res);
await mocked.res.hasStreamed;
if (mocked.res.getHeader('x-nextjs-cache') !== 'REVALIDATED' && mocked.res.statusCode !== 200 && !(mocked.res.statusCode === 404 && revalidateOpts.unstable_onlyGenerated)) {
throw Object.defineProperty(new Error(`Invalid response ${mocked.res.statusCode}`), "__NEXT_ERROR_CODE", {
value: "E175",
enumerable: false,
configurable: true
});
}
return {};
}
get appIsrManifest() {
const serializableManifest = {};
for (const [key, value] of this.appIsrManifestInner){
serializableManifest[key] = value;
}
return serializableManifest;
}
setIsrStatus(key, value) {
var // Only send the ISR manifest to legacy clients, i.e. Pages Router clients,
// or App Router clients that have Cache Components disabled. The ISR
// manifest is only used to inform the static indicator, which currently
// does not provide useful information if Cache Components is enabled due to
// its binary nature (i.e. it does not support showing info for partially
// static pages).
_this_bundler_hotReloader, _this_bundler;
if (value === undefined) {
this.appIsrManifestInner.remove(key);
} else {
this.appIsrManifestInner.set(key, value);
}
(_this_bundler = this.bundler) == null ? void 0 : (_this_bundler_hotReloader = _this_bundler.hotReloader) == null ? void 0 : _this_bundler_hotReloader.sendToLegacyClients({
type: _hotreloadertypes.HMR_MESSAGE_SENT_TO_BROWSER.ISR_MANIFEST,
data: this.appIsrManifest
});
}
sendHmrMessage(message) {
this.bundler.hotReloader.send(message);
}
}
//# sourceMappingURL=dev-bundler-service.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
/**
* FNV-1a Hash implementation
* @author Travis Webb (tjwebb) <me@traviswebb.com>
*
* Ported from https://github.com/tjwebb/fnv-plus/blob/master/index.js
*
* Simplified, optimized and add modified for 52 bit, which provides a larger hash space
* and still making use of Javascript's 53-bit integer space.
*/
export declare const fnv1a52: (str: string) => number;
export declare const generateETag: (payload: string, weak?: boolean) => string;

View File

@@ -0,0 +1,56 @@
/**
* FNV-1a Hash implementation
* @author Travis Webb (tjwebb) <me@traviswebb.com>
*
* Ported from https://github.com/tjwebb/fnv-plus/blob/master/index.js
*
* Simplified, optimized and add modified for 52 bit, which provides a larger hash space
* and still making use of Javascript's 53-bit integer space.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
fnv1a52: null,
generateETag: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
fnv1a52: function() {
return fnv1a52;
},
generateETag: function() {
return generateETag;
}
});
const fnv1a52 = (str)=>{
const len = str.length;
let i = 0, t0 = 0, v0 = 0x2325, t1 = 0, v1 = 0x8422, t2 = 0, v2 = 0x9ce4, t3 = 0, v3 = 0xcbf2;
while(i < len){
v0 ^= str.charCodeAt(i++);
t0 = v0 * 435;
t1 = v1 * 435;
t2 = v2 * 435;
t3 = v3 * 435;
t2 += v0 << 8;
t3 += v1 << 8;
t1 += t0 >>> 16;
v0 = t0 & 65535;
t2 += t1 >>> 16;
v1 = t1 & 65535;
v3 = t3 + (t2 >>> 16) & 65535;
v2 = t2 & 65535;
}
return (v3 & 15) * 281474976710656 + v2 * 4294967296 + v1 * 65536 + (v0 ^ v3 >> 4);
};
const generateETag = (payload, weak = false)=>{
const prefix = weak ? 'W/"' : '"';
return prefix + fnv1a52(payload).toString(36) + payload.length.toString(36) + '"';
};
//# sourceMappingURL=etag.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/etag.ts"],"sourcesContent":["/**\n * FNV-1a Hash implementation\n * @author Travis Webb (tjwebb) <me@traviswebb.com>\n *\n * Ported from https://github.com/tjwebb/fnv-plus/blob/master/index.js\n *\n * Simplified, optimized and add modified for 52 bit, which provides a larger hash space\n * and still making use of Javascript's 53-bit integer space.\n */\nexport const fnv1a52 = (str: string) => {\n const len = str.length\n let i = 0,\n t0 = 0,\n v0 = 0x2325,\n t1 = 0,\n v1 = 0x8422,\n t2 = 0,\n v2 = 0x9ce4,\n t3 = 0,\n v3 = 0xcbf2\n\n while (i < len) {\n v0 ^= str.charCodeAt(i++)\n t0 = v0 * 435\n t1 = v1 * 435\n t2 = v2 * 435\n t3 = v3 * 435\n t2 += v0 << 8\n t3 += v1 << 8\n t1 += t0 >>> 16\n v0 = t0 & 65535\n t2 += t1 >>> 16\n v1 = t1 & 65535\n v3 = (t3 + (t2 >>> 16)) & 65535\n v2 = t2 & 65535\n }\n\n return (\n (v3 & 15) * 281474976710656 +\n v2 * 4294967296 +\n v1 * 65536 +\n (v0 ^ (v3 >> 4))\n )\n}\n\nexport const generateETag = (payload: string, weak = false) => {\n const prefix = weak ? 'W/\"' : '\"'\n return (\n prefix + fnv1a52(payload).toString(36) + payload.length.toString(36) + '\"'\n )\n}\n"],"names":["fnv1a52","generateETag","str","len","length","i","t0","v0","t1","v1","t2","v2","t3","v3","charCodeAt","payload","weak","prefix","toString"],"mappings":"AAAA;;;;;;;;CAQC;;;;;;;;;;;;;;;IACYA,OAAO;eAAPA;;IAoCAC,YAAY;eAAZA;;;AApCN,MAAMD,UAAU,CAACE;IACtB,MAAMC,MAAMD,IAAIE,MAAM;IACtB,IAAIC,IAAI,GACNC,KAAK,GACLC,KAAK,QACLC,KAAK,GACLC,KAAK,QACLC,KAAK,GACLC,KAAK,QACLC,KAAK,GACLC,KAAK;IAEP,MAAOR,IAAIF,IAAK;QACdI,MAAML,IAAIY,UAAU,CAACT;QACrBC,KAAKC,KAAK;QACVC,KAAKC,KAAK;QACVC,KAAKC,KAAK;QACVC,KAAKC,KAAK;QACVH,MAAMH,MAAM;QACZK,MAAMH,MAAM;QACZD,MAAMF,OAAO;QACbC,KAAKD,KAAK;QACVI,MAAMF,OAAO;QACbC,KAAKD,KAAK;QACVK,KAAK,AAACD,KAAMF,CAAAA,OAAO,EAAC,IAAM;QAC1BC,KAAKD,KAAK;IACZ;IAEA,OACE,AAACG,CAAAA,KAAK,EAAC,IAAK,kBACZF,KAAK,aACLF,KAAK,QACJF,CAAAA,KAAMM,MAAM,CAAC;AAElB;AAEO,MAAMZ,eAAe,CAACc,SAAiBC,OAAO,KAAK;IACxD,MAAMC,SAASD,OAAO,QAAQ;IAC9B,OACEC,SAASjB,QAAQe,SAASG,QAAQ,CAAC,MAAMH,QAAQX,MAAM,CAACc,QAAQ,CAAC,MAAM;AAE3E","ignoreList":[0]}

View File

@@ -0,0 +1,5 @@
import type { LoadedEnvFiles } from '@next/env';
export declare function createEnvDefinitions({ distDir, loadedEnvFiles, }: {
distDir: string;
loadedEnvFiles: LoadedEnvFiles;
}): Promise<string | undefined>;

View File

@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createEnvDefinitions", {
enumerable: true,
get: function() {
return createEnvDefinitions;
}
});
const _nodepath = require("node:path");
const _promises = require("node:fs/promises");
async function createEnvDefinitions({ distDir, loadedEnvFiles }) {
const envLines = [];
const seenKeys = new Set();
// env files are in order of priority
for (const { path, env } of loadedEnvFiles){
for(const key in env){
if (!seenKeys.has(key)) {
envLines.push(` /** Loaded from \`${path}\` */`);
envLines.push(` ${key}?: string`);
seenKeys.add(key);
}
}
}
const envStr = envLines.join('\n');
const definitionStr = `// Type definitions for Next.js environment variables
declare global {
namespace NodeJS {
interface ProcessEnv {
${envStr}
}
}
}
export {}`;
if (process.env.NODE_ENV === 'test') {
return definitionStr;
}
try {
// we expect the types directory to already exist
const envDtsPath = (0, _nodepath.join)(distDir, 'types', 'env.d.ts');
await (0, _promises.writeFile)(envDtsPath, definitionStr, 'utf-8');
} catch (e) {
console.error('Failed to write env.d.ts:', e);
}
}
//# sourceMappingURL=create-env-definitions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/experimental/create-env-definitions.ts"],"sourcesContent":["import type { LoadedEnvFiles } from '@next/env'\nimport { join } from 'node:path'\nimport { writeFile } from 'node:fs/promises'\n\nexport async function createEnvDefinitions({\n distDir,\n loadedEnvFiles,\n}: {\n distDir: string\n loadedEnvFiles: LoadedEnvFiles\n}) {\n const envLines = []\n const seenKeys = new Set()\n // env files are in order of priority\n for (const { path, env } of loadedEnvFiles) {\n for (const key in env) {\n if (!seenKeys.has(key)) {\n envLines.push(` /** Loaded from \\`${path}\\` */`)\n envLines.push(` ${key}?: string`)\n seenKeys.add(key)\n }\n }\n }\n const envStr = envLines.join('\\n')\n\n const definitionStr = `// Type definitions for Next.js environment variables\ndeclare global {\n namespace NodeJS {\n interface ProcessEnv {\n${envStr}\n }\n }\n}\nexport {}`\n\n if (process.env.NODE_ENV === 'test') {\n return definitionStr\n }\n\n try {\n // we expect the types directory to already exist\n const envDtsPath = join(distDir, 'types', 'env.d.ts')\n await writeFile(envDtsPath, definitionStr, 'utf-8')\n } catch (e) {\n console.error('Failed to write env.d.ts:', e)\n }\n}\n"],"names":["createEnvDefinitions","distDir","loadedEnvFiles","envLines","seenKeys","Set","path","env","key","has","push","add","envStr","join","definitionStr","process","NODE_ENV","envDtsPath","writeFile","e","console","error"],"mappings":";;;;+BAIsBA;;;eAAAA;;;0BAHD;0BACK;AAEnB,eAAeA,qBAAqB,EACzCC,OAAO,EACPC,cAAc,EAIf;IACC,MAAMC,WAAW,EAAE;IACnB,MAAMC,WAAW,IAAIC;IACrB,qCAAqC;IACrC,KAAK,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,IAAIL,eAAgB;QAC1C,IAAK,MAAMM,OAAOD,IAAK;YACrB,IAAI,CAACH,SAASK,GAAG,CAACD,MAAM;gBACtBL,SAASO,IAAI,CAAC,CAAC,wBAAwB,EAAEJ,KAAK,KAAK,CAAC;gBACpDH,SAASO,IAAI,CAAC,CAAC,MAAM,EAAEF,IAAI,SAAS,CAAC;gBACrCJ,SAASO,GAAG,CAACH;YACf;QACF;IACF;IACA,MAAMI,SAAST,SAASU,IAAI,CAAC;IAE7B,MAAMC,gBAAgB,CAAC;;;;AAIzB,EAAEF,OAAO;;;;SAIA,CAAC;IAER,IAAIG,QAAQR,GAAG,CAACS,QAAQ,KAAK,QAAQ;QACnC,OAAOF;IACT;IAEA,IAAI;QACF,iDAAiD;QACjD,MAAMG,aAAaJ,IAAAA,cAAI,EAACZ,SAAS,SAAS;QAC1C,MAAMiB,IAAAA,mBAAS,EAACD,YAAYH,eAAe;IAC7C,EAAE,OAAOK,GAAG;QACVC,QAAQC,KAAK,CAAC,6BAA6BF;IAC7C;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,25 @@
/**
* If set to `incremental`, only those leaf pages that export
* `experimental_ppr = true` will have partial prerendering enabled. If any
* page exports this value as `false` or does not export it at all will not
* have partial prerendering enabled. If set to a boolean, the options for
* `experimental_ppr` will be ignored.
*/
export type ExperimentalPPRConfig = boolean | 'incremental';
/**
* Returns true if partial prerendering is enabled for the application. It does
* not tell you if a given route has PPR enabled, as that requires analysis of
* the route's configuration.
*
* @see {@link checkIsRoutePPREnabled} - for checking if a specific route has PPR enabled.
*/
export declare function checkIsAppPPREnabled(config: ExperimentalPPRConfig | undefined): boolean;
/**
* Returns true if partial prerendering is supported for the current page with
* the provided app configuration. If the application doesn't have partial
* prerendering enabled, this function will always return false. If you want to
* check if the application has partial prerendering enabled
*
* @see {@link checkIsAppPPREnabled} for checking if the application has PPR enabled.
*/
export declare function checkIsRoutePPREnabled(config: ExperimentalPPRConfig | undefined): boolean;

View File

@@ -0,0 +1,47 @@
/**
* If set to `incremental`, only those leaf pages that export
* `experimental_ppr = true` will have partial prerendering enabled. If any
* page exports this value as `false` or does not export it at all will not
* have partial prerendering enabled. If set to a boolean, the options for
* `experimental_ppr` will be ignored.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
checkIsAppPPREnabled: null,
checkIsRoutePPREnabled: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
checkIsAppPPREnabled: function() {
return checkIsAppPPREnabled;
},
checkIsRoutePPREnabled: function() {
return checkIsRoutePPREnabled;
}
});
function checkIsAppPPREnabled(config) {
// If the config is undefined, partial prerendering is disabled.
if (typeof config === 'undefined') return false;
// If the config is a boolean, use it directly.
if (typeof config === 'boolean') return config;
// If the config is a string, it must be 'incremental' to enable partial
// prerendering.
if (config === 'incremental') return true;
return false;
}
function checkIsRoutePPREnabled(config) {
// If the config is undefined, partial prerendering is disabled.
if (typeof config === 'undefined') return false;
// If the config is a boolean, use it directly.
if (typeof config === 'boolean') return config;
return false;
}
//# sourceMappingURL=ppr.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/experimental/ppr.ts"],"sourcesContent":["/**\n * If set to `incremental`, only those leaf pages that export\n * `experimental_ppr = true` will have partial prerendering enabled. If any\n * page exports this value as `false` or does not export it at all will not\n * have partial prerendering enabled. If set to a boolean, the options for\n * `experimental_ppr` will be ignored.\n */\n\nexport type ExperimentalPPRConfig = boolean | 'incremental'\n\n/**\n * Returns true if partial prerendering is enabled for the application. It does\n * not tell you if a given route has PPR enabled, as that requires analysis of\n * the route's configuration.\n *\n * @see {@link checkIsRoutePPREnabled} - for checking if a specific route has PPR enabled.\n */\nexport function checkIsAppPPREnabled(\n config: ExperimentalPPRConfig | undefined\n): boolean {\n // If the config is undefined, partial prerendering is disabled.\n if (typeof config === 'undefined') return false\n\n // If the config is a boolean, use it directly.\n if (typeof config === 'boolean') return config\n\n // If the config is a string, it must be 'incremental' to enable partial\n // prerendering.\n if (config === 'incremental') return true\n\n return false\n}\n\n/**\n * Returns true if partial prerendering is supported for the current page with\n * the provided app configuration. If the application doesn't have partial\n * prerendering enabled, this function will always return false. If you want to\n * check if the application has partial prerendering enabled\n *\n * @see {@link checkIsAppPPREnabled} for checking if the application has PPR enabled.\n */\nexport function checkIsRoutePPREnabled(\n config: ExperimentalPPRConfig | undefined\n): boolean {\n // If the config is undefined, partial prerendering is disabled.\n if (typeof config === 'undefined') return false\n\n // If the config is a boolean, use it directly.\n if (typeof config === 'boolean') return config\n\n return false\n}\n"],"names":["checkIsAppPPREnabled","checkIsRoutePPREnabled","config"],"mappings":"AAAA;;;;;;CAMC;;;;;;;;;;;;;;;IAWeA,oBAAoB;eAApBA;;IAwBAC,sBAAsB;eAAtBA;;;AAxBT,SAASD,qBACdE,MAAyC;IAEzC,gEAAgE;IAChE,IAAI,OAAOA,WAAW,aAAa,OAAO;IAE1C,+CAA+C;IAC/C,IAAI,OAAOA,WAAW,WAAW,OAAOA;IAExC,wEAAwE;IACxE,gBAAgB;IAChB,IAAIA,WAAW,eAAe,OAAO;IAErC,OAAO;AACT;AAUO,SAASD,uBACdC,MAAyC;IAEzC,gEAAgE;IAChE,IAAI,OAAOA,WAAW,aAAa,OAAO;IAE1C,+CAA+C;IAC/C,IAAI,OAAOA,WAAW,WAAW,OAAOA;IAExC,OAAO;AACT","ignoreList":[0]}

View File

@@ -0,0 +1,27 @@
import type { PageExtensions } from '../../build/page-extensions-type';
/**
* Finds a page file with the given parameters. If the page is duplicated with
* multiple extensions it will throw, otherwise it will return the *relative*
* path to the page file or null if it is not found.
*
* @param pagesDir Absolute path to the pages folder with trailing `/pages`.
* @param normalizedPagePath The page normalized (it will be denormalized).
* @param pageExtensions Array of page extensions.
*/
export declare function findPageFile(pagesDir: string, normalizedPagePath: string, pageExtensions: PageExtensions, isAppDir: boolean): Promise<string | null>;
/**
*
* createValidFileMatcher receives configured page extensions and return helpers to determine:
* `isLayoutsLeafPage`: if a file is a valid page file or routes file under app directory
* `isTrackedFiles`: if it's a tracked file for webpack watcher
*
*/
export declare function createValidFileMatcher(pageExtensions: PageExtensions, appDirPath: string | undefined): {
isPageFile: (filePath: string) => boolean;
isAppRouterPage: (filePath: string) => boolean;
isAppRouterRoute: (filePath: string) => boolean;
isAppLayoutPage: (filePath: string) => boolean;
isAppDefaultPage: (filePath: string) => boolean;
isMetadataFile: (filePath: string) => boolean;
isRootNotFound: (filePath: string) => boolean;
};

View File

@@ -0,0 +1,127 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
createValidFileMatcher: null,
findPageFile: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
createValidFileMatcher: function() {
return createValidFileMatcher;
},
findPageFile: function() {
return findPageFile;
}
});
const _fileexists = require("../../lib/file-exists");
const _getpagepaths = require("../../shared/lib/page-path/get-page-paths");
const _nonnullable = require("../../lib/non-nullable");
const _path = require("path");
const _fs = require("fs");
const _log = require("../../build/output/log");
const _picocolors = require("../../lib/picocolors");
const _ismetadataroute = require("../../lib/metadata/is-metadata-route");
async function isTrueCasePagePath(pagePath, pagesDir) {
const pageSegments = (0, _path.normalize)(pagePath).split(_path.sep).filter(Boolean);
const segmentExistsPromises = pageSegments.map(async (segment, i)=>{
const segmentParentDir = (0, _path.join)(pagesDir, ...pageSegments.slice(0, i));
const parentDirEntries = await _fs.promises.readdir(segmentParentDir);
return parentDirEntries.includes(segment);
});
return (await Promise.all(segmentExistsPromises)).every(Boolean);
}
async function findPageFile(pagesDir, normalizedPagePath, pageExtensions, isAppDir) {
const pagePaths = (0, _getpagepaths.getPagePaths)(normalizedPagePath, pageExtensions, isAppDir);
const [existingPath, ...others] = (await Promise.all(pagePaths.map(async (path)=>{
const filePath = (0, _path.join)(pagesDir, path);
try {
return await (0, _fileexists.fileExists)(filePath) ? path : null;
} catch (err) {
var _err_code;
if (!(err == null ? void 0 : (_err_code = err.code) == null ? void 0 : _err_code.includes('ENOTDIR'))) throw err;
}
return null;
}))).filter(_nonnullable.nonNullable);
if (!existingPath) {
return null;
}
if (!await isTrueCasePagePath(existingPath, pagesDir)) {
return null;
}
if (others.length > 0) {
(0, _log.warn)(`Duplicate page detected. ${(0, _picocolors.cyan)((0, _path.join)('pages', existingPath))} and ${(0, _picocolors.cyan)((0, _path.join)('pages', others[0]))} both resolve to ${(0, _picocolors.cyan)(normalizedPagePath)}.`);
}
return existingPath;
}
function createValidFileMatcher(pageExtensions, appDirPath) {
const getExtensionRegexString = (extensions)=>`(?:${extensions.join('|')})`;
const validExtensionFileRegex = new RegExp('\\.' + getExtensionRegexString(pageExtensions) + '$');
const leafOnlyPageFileRegex = new RegExp(`(^(page|route)|[\\\\/](page|route))\\.${getExtensionRegexString(pageExtensions)}$`);
const leafOnlyRouteFileRegex = new RegExp(`(^route|[\\\\/]route)\\.${getExtensionRegexString(pageExtensions)}$`);
const leafOnlyLayoutFileRegex = new RegExp(`(^(layout)|[\\\\/](layout))\\.${getExtensionRegexString(pageExtensions)}$`);
const rootNotFoundFileRegex = new RegExp(`^not-found\\.${getExtensionRegexString(pageExtensions)}$`);
const leafOnlyDefaultFileRegex = new RegExp(`(^(default)|[\\\\/](default))\\.${getExtensionRegexString(pageExtensions)}$`);
/** TODO-METADATA: support other metadata routes
* regex for:
*
* /robots.txt|<ext>
* /sitemap.xml|<ext>
* /favicon.ico
* /manifest.json|<ext>
* <route>/icon.png|jpg|<ext>
* <route>/apple-touch-icon.png|jpg|<ext>
*
*/ /**
* Match the file if it's a metadata route file, static: if the file is a static metadata file.
* It needs to be a file which doesn't match the custom metadata routes e.g. `app/robots.txt/route.js`
*/ function isMetadataFile(filePath) {
const appDirRelativePath = appDirPath ? filePath.replace(appDirPath, '') : filePath;
return (0, _ismetadataroute.isMetadataRouteFile)(appDirRelativePath, pageExtensions, true);
}
// Determine if the file is leaf node page file or route file under layouts,
// 'page.<extension>' | 'route.<extension>'
function isAppRouterPage(filePath) {
return leafOnlyPageFileRegex.test(filePath) || isMetadataFile(filePath);
}
// Determine if the file is leaf node route file under app directory
function isAppRouterRoute(filePath) {
return leafOnlyRouteFileRegex.test(filePath);
}
function isAppLayoutPage(filePath) {
return leafOnlyLayoutFileRegex.test(filePath);
}
function isAppDefaultPage(filePath) {
return leafOnlyDefaultFileRegex.test(filePath);
}
function isPageFile(filePath) {
return validExtensionFileRegex.test(filePath) || isMetadataFile(filePath);
}
function isRootNotFound(filePath) {
if (!appDirPath) {
return false;
}
if (!filePath.startsWith(appDirPath + _path.sep)) {
return false;
}
const rest = filePath.slice(appDirPath.length + 1);
return rootNotFoundFileRegex.test(rest);
}
return {
isPageFile,
isAppRouterPage,
isAppRouterRoute,
isAppLayoutPage,
isAppDefaultPage,
isMetadataFile,
isRootNotFound
};
}
//# sourceMappingURL=find-page-file.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export declare function fixMojibake(input: string): string;

View File

@@ -0,0 +1,25 @@
// x-matched-path header can be decoded incorrectly
// and should only be utf8 characters so this fixes
// incorrectly encoded values
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "fixMojibake", {
enumerable: true,
get: function() {
return fixMojibake;
}
});
function fixMojibake(input) {
// Convert each character's char code to a byte
const bytes = new Uint8Array(input.length);
for(let i = 0; i < input.length; i++){
bytes[i] = input.charCodeAt(i);
}
// Decode the bytes as proper UTF-8
const decoder = new TextDecoder('utf-8');
return decoder.decode(bytes);
}
//# sourceMappingURL=fix-mojibake.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/fix-mojibake.ts"],"sourcesContent":["// x-matched-path header can be decoded incorrectly\n// and should only be utf8 characters so this fixes\n// incorrectly encoded values\nexport function fixMojibake(input: string): string {\n // Convert each character's char code to a byte\n const bytes = new Uint8Array(input.length)\n for (let i = 0; i < input.length; i++) {\n bytes[i] = input.charCodeAt(i)\n }\n\n // Decode the bytes as proper UTF-8\n const decoder = new TextDecoder('utf-8')\n return decoder.decode(bytes)\n}\n"],"names":["fixMojibake","input","bytes","Uint8Array","length","i","charCodeAt","decoder","TextDecoder","decode"],"mappings":"AAAA,mDAAmD;AACnD,mDAAmD;AACnD,6BAA6B;;;;;+BACbA;;;eAAAA;;;AAAT,SAASA,YAAYC,KAAa;IACvC,+CAA+C;IAC/C,MAAMC,QAAQ,IAAIC,WAAWF,MAAMG,MAAM;IACzC,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,MAAMG,MAAM,EAAEC,IAAK;QACrCH,KAAK,CAACG,EAAE,GAAGJ,MAAMK,UAAU,CAACD;IAC9B;IAEA,mCAAmC;IACnC,MAAME,UAAU,IAAIC,YAAY;IAChC,OAAOD,QAAQE,MAAM,CAACP;AACxB","ignoreList":[0]}

View File

@@ -0,0 +1,7 @@
/**
* Formats a hostname so that it is a valid host that can be fetched by wrapping
* IPv6 hosts with brackets.
* @param hostname
* @returns
*/
export declare function formatHostname(hostname: string): string;

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "formatHostname", {
enumerable: true,
get: function() {
return formatHostname;
}
});
const _isipv6 = require("./is-ipv6");
function formatHostname(hostname) {
return (0, _isipv6.isIPv6)(hostname) ? `[${hostname}]` : hostname;
}
//# sourceMappingURL=format-hostname.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/format-hostname.ts"],"sourcesContent":["import { isIPv6 } from './is-ipv6'\n\n/**\n * Formats a hostname so that it is a valid host that can be fetched by wrapping\n * IPv6 hosts with brackets.\n * @param hostname\n * @returns\n */\nexport function formatHostname(hostname: string): string {\n return isIPv6(hostname) ? `[${hostname}]` : hostname\n}\n"],"names":["formatHostname","hostname","isIPv6"],"mappings":";;;;+BAQgBA;;;eAAAA;;;wBARO;AAQhB,SAASA,eAAeC,QAAgB;IAC7C,OAAOC,IAAAA,cAAM,EAACD,YAAY,CAAC,CAAC,EAAEA,SAAS,CAAC,CAAC,GAAGA;AAC9C","ignoreList":[0]}

View File

@@ -0,0 +1,65 @@
import type { DomainLocale, I18NConfig } from '../config-shared';
import { type NextIncomingMessage } from '../request-meta';
/**
* The result of matching a locale aware route.
*/
export interface LocaleAnalysisResult {
/**
* The pathname without the locale prefix (if any).
*/
pathname: string;
/**
* The detected locale. If no locale was detected, this will be `undefined`.
*/
detectedLocale?: string;
/**
* True if the locale was inferred from the default locale.
*/
inferredFromDefault: boolean;
}
type LocaleAnalysisOptions = {
/**
* When provided, it will be used as the default locale if the locale
* cannot be inferred from the pathname.
*/
defaultLocale?: string;
};
/**
* The I18NProvider is used to match locale aware routes, detect the locale from
* the pathname and hostname and normalize the pathname by removing the locale
* prefix.
*/
export declare class I18NProvider {
readonly config: Readonly<I18NConfig>;
private readonly lowerCaseLocales;
private readonly lowerCaseDomains?;
constructor(config: Readonly<I18NConfig>);
/**
* Detects the domain locale from the hostname and the detected locale if
* provided.
*
* @param hostname The hostname to detect the domain locale from, this must be lowercased.
* @param detectedLocale The detected locale to use if the hostname does not match.
* @returns The domain locale if found, `undefined` otherwise.
*/
detectDomainLocale(hostname?: string, detectedLocale?: string): DomainLocale | undefined;
/**
* Pulls the pre-computed locale and inference results from the query
* object.
*
* @param req the request object
* @param pathname the pathname that could contain a locale prefix
* @returns the locale analysis result
*/
fromRequest(req: NextIncomingMessage, pathname: string): LocaleAnalysisResult;
/**
* Analyzes the pathname for a locale and returns the pathname without it.
*
* @param pathname The pathname that could contain a locale prefix.
* @param options The options to use when matching the locale.
* @returns The matched locale and the pathname without the locale prefix
* (if any).
*/
analyze(pathname: string, options?: LocaleAnalysisOptions): LocaleAnalysisResult;
}
export {};

View File

@@ -0,0 +1,129 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "I18NProvider", {
enumerable: true,
get: function() {
return I18NProvider;
}
});
const _requestmeta = require("../request-meta");
class I18NProvider {
constructor(config){
var _config_domains;
this.config = config;
if (!config.locales.length) {
throw Object.defineProperty(new Error('Invariant: No locales provided'), "__NEXT_ERROR_CODE", {
value: "E510",
enumerable: false,
configurable: true
});
}
this.lowerCaseLocales = config.locales.map((locale)=>locale.toLowerCase());
this.lowerCaseDomains = (_config_domains = config.domains) == null ? void 0 : _config_domains.map((domainLocale)=>{
var _domainLocale_locales;
const domain = domainLocale.domain.toLowerCase();
return {
defaultLocale: domainLocale.defaultLocale.toLowerCase(),
hostname: domain.split(':', 1)[0],
domain,
locales: (_domainLocale_locales = domainLocale.locales) == null ? void 0 : _domainLocale_locales.map((locale)=>locale.toLowerCase()),
http: domainLocale.http
};
});
}
/**
* Detects the domain locale from the hostname and the detected locale if
* provided.
*
* @param hostname The hostname to detect the domain locale from, this must be lowercased.
* @param detectedLocale The detected locale to use if the hostname does not match.
* @returns The domain locale if found, `undefined` otherwise.
*/ detectDomainLocale(hostname, detectedLocale) {
if (!hostname || !this.lowerCaseDomains || !this.config.domains) return;
if (detectedLocale) detectedLocale = detectedLocale.toLowerCase();
for(let i = 0; i < this.lowerCaseDomains.length; i++){
var // Configuration validation ensures that the locale is not repeated in
// other domains locales.
_domainLocale_locales;
const domainLocale = this.lowerCaseDomains[i];
if (// We assume that the hostname is already lowercased.
domainLocale.hostname === hostname || ((_domainLocale_locales = domainLocale.locales) == null ? void 0 : _domainLocale_locales.some((locale)=>locale === detectedLocale))) {
return this.config.domains[i];
}
}
return;
}
/**
* Pulls the pre-computed locale and inference results from the query
* object.
*
* @param req the request object
* @param pathname the pathname that could contain a locale prefix
* @returns the locale analysis result
*/ fromRequest(req, pathname) {
const detectedLocale = (0, _requestmeta.getRequestMeta)(req, 'locale');
// If a locale was detected on the query, analyze the pathname to ensure
// that the locale matches.
if (detectedLocale) {
const analysis = this.analyze(pathname);
// If the analysis contained a locale we should validate it against the
// query and strip it from the pathname.
if (analysis.detectedLocale) {
if (analysis.detectedLocale !== detectedLocale) {
console.warn(`The detected locale does not match the locale in the query. Expected to find '${detectedLocale}' in '${pathname}' but found '${analysis.detectedLocale}'}`);
}
pathname = analysis.pathname;
}
}
return {
pathname,
detectedLocale,
inferredFromDefault: (0, _requestmeta.getRequestMeta)(req, 'localeInferredFromDefault') ?? false
};
}
/**
* Analyzes the pathname for a locale and returns the pathname without it.
*
* @param pathname The pathname that could contain a locale prefix.
* @param options The options to use when matching the locale.
* @returns The matched locale and the pathname without the locale prefix
* (if any).
*/ analyze(pathname, options = {}) {
let detectedLocale = options.defaultLocale;
// By default, we assume that the default locale was inferred if there was
// no detected locale.
let inferredFromDefault = typeof detectedLocale === 'string';
// The first segment will be empty, because it has a leading `/`. If
// there is no further segment, there is no locale (or it's the default).
const segments = pathname.split('/', 2);
if (!segments[1]) return {
detectedLocale,
pathname,
inferredFromDefault
};
// The second segment will contain the locale part if any.
const segment = segments[1].toLowerCase();
// See if the segment matches one of the locales. If it doesn't, there is
// no locale (or it's the default).
const index = this.lowerCaseLocales.indexOf(segment);
if (index < 0) return {
detectedLocale,
pathname,
inferredFromDefault
};
// Return the case-sensitive locale.
detectedLocale = this.config.locales[index];
inferredFromDefault = false;
// Remove the `/${locale}` part of the pathname.
pathname = pathname.slice(detectedLocale.length + 1) || '/';
return {
detectedLocale,
pathname,
inferredFromDefault
};
}
}
//# sourceMappingURL=i18n-provider.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
import type { OpaqueFallbackRouteParams } from '../request/fallback-params';
import { type LazyResult } from './lazy-result';
export interface ImplicitTags {
/**
* For legacy usage, the implicit tags are passed to the incremental cache
* handler in `get` calls.
*/
readonly tags: string[];
/**
* Modern cache handlers don't receive implicit tags. Instead, the implicit
* tags' expirations are stored in the work unit store, and used to compare
* with a cache entry's timestamp.
*
* Note: This map contains lazy results so that we can evaluate them when the
* first cache entry is read. It allows us to skip fetching the expiration
* values if no caches are read at all.
*/
readonly expirationsByCacheKind: Map<string, LazyResult<number>>;
}
export declare function getImplicitTags(page: string, url: {
pathname: string;
search?: string;
}, fallbackRouteParams: null | OpaqueFallbackRouteParams): Promise<ImplicitTags>;

View File

@@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getImplicitTags", {
enumerable: true,
get: function() {
return getImplicitTags;
}
});
const _constants = require("../../lib/constants");
const _handlers = require("../use-cache/handlers");
const _lazyresult = require("./lazy-result");
const getDerivedTags = (pathname)=>{
const derivedTags = [
`/layout`
];
// we automatically add the current path segments as tags
// for revalidatePath handling
if (pathname.startsWith('/')) {
const pathnameParts = pathname.split('/');
for(let i = 1; i < pathnameParts.length + 1; i++){
let curPathname = pathnameParts.slice(0, i).join('/');
if (curPathname) {
// all derived tags other than the page are layout tags
if (!curPathname.endsWith('/page') && !curPathname.endsWith('/route')) {
curPathname = `${curPathname}${!curPathname.endsWith('/') ? '/' : ''}layout`;
}
derivedTags.push(curPathname);
}
}
}
return derivedTags;
};
/**
* Creates a map with lazy results that fetch the expiration value for the given
* tags and respective cache kind when they're awaited for the first time.
*/ function createTagsExpirationsByCacheKind(tags) {
const expirationsByCacheKind = new Map();
const cacheHandlers = (0, _handlers.getCacheHandlerEntries)();
if (cacheHandlers) {
for (const [kind, cacheHandler] of cacheHandlers){
if ('getExpiration' in cacheHandler) {
expirationsByCacheKind.set(kind, (0, _lazyresult.createLazyResult)(async ()=>cacheHandler.getExpiration(tags)));
}
}
}
return expirationsByCacheKind;
}
async function getImplicitTags(page, url, fallbackRouteParams) {
const tags = new Set();
// Add the derived tags from the page.
const derivedTags = getDerivedTags(page);
for (let tag of derivedTags){
tag = `${_constants.NEXT_CACHE_IMPLICIT_TAG_ID}${tag}`;
tags.add(tag);
}
// Add the tags from the pathname. If the route has unknown params, we don't
// want to add the pathname as a tag, as it will be invalid.
if (url.pathname && (!fallbackRouteParams || fallbackRouteParams.size === 0)) {
const tag = `${_constants.NEXT_CACHE_IMPLICIT_TAG_ID}${url.pathname}`;
tags.add(tag);
}
if (tags.has(`${_constants.NEXT_CACHE_IMPLICIT_TAG_ID}/`)) {
tags.add(`${_constants.NEXT_CACHE_IMPLICIT_TAG_ID}/index`);
}
if (tags.has(`${_constants.NEXT_CACHE_IMPLICIT_TAG_ID}/index`)) {
tags.add(`${_constants.NEXT_CACHE_IMPLICIT_TAG_ID}/`);
}
const tagsArray = Array.from(tags);
return {
tags: tagsArray,
expirationsByCacheKind: createTagsExpirationsByCacheKind(tagsArray)
};
}
//# sourceMappingURL=implicit-tags.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
import type { CacheHandler, CacheHandlerContext, CacheHandlerValue } from '.';
import type { CacheFs } from '../../../shared/lib/utils';
import { type IncrementalCacheValue, type SetIncrementalFetchCacheContext, type SetIncrementalResponseCacheContext } from '../../response-cache';
type FileSystemCacheContext = Omit<CacheHandlerContext, 'fs' | 'serverDistDir'> & {
fs: CacheFs;
serverDistDir: string;
};
export default class FileSystemCache implements CacheHandler {
private fs;
private flushToDisk?;
private serverDistDir;
private revalidatedTags;
private static debug;
private static memoryCache;
constructor(ctx: FileSystemCacheContext);
resetRequestCache(): void;
revalidateTag(tags: string | string[], durations?: {
expire?: number;
}): Promise<void>;
get(...args: Parameters<CacheHandler['get']>): Promise<CacheHandlerValue | null>;
set(key: string, data: IncrementalCacheValue | null, ctx: SetIncrementalFetchCacheContext | SetIncrementalResponseCacheContext): Promise<void>;
private getFilePath;
}
export {};

View File

@@ -0,0 +1,333 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return FileSystemCache;
}
});
const _responsecache = require("../../response-cache");
const _path = /*#__PURE__*/ _interop_require_default(require("../../../shared/lib/isomorphic/path"));
const _constants = require("../../../lib/constants");
const _tagsmanifestexternal = require("./tags-manifest.external");
const _multifilewriter = require("../../../lib/multi-file-writer");
const _memorycacheexternal = require("./memory-cache.external");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
class FileSystemCache {
static #_ = this.debug = !!process.env.NEXT_PRIVATE_DEBUG_CACHE;
constructor(ctx){
this.fs = ctx.fs;
this.flushToDisk = ctx.flushToDisk;
this.serverDistDir = ctx.serverDistDir;
this.revalidatedTags = ctx.revalidatedTags;
if (ctx.maxMemoryCacheSize) {
if (!FileSystemCache.memoryCache) {
if (FileSystemCache.debug) {
console.log('FileSystemCache: using memory store for fetch cache');
}
FileSystemCache.memoryCache = (0, _memorycacheexternal.getMemoryCache)(ctx.maxMemoryCacheSize);
} else if (FileSystemCache.debug) {
console.log('FileSystemCache: memory store already initialized');
}
} else if (FileSystemCache.debug) {
console.log('FileSystemCache: not using memory store for fetch cache');
}
}
resetRequestCache() {}
async revalidateTag(tags, durations) {
tags = typeof tags === 'string' ? [
tags
] : tags;
if (FileSystemCache.debug) {
console.log('FileSystemCache: revalidateTag', tags, durations);
}
if (tags.length === 0) {
return;
}
const now = Date.now();
for (const tag of tags){
const existingEntry = _tagsmanifestexternal.tagsManifest.get(tag) || {};
if (durations) {
// Use provided durations directly
const updates = {
...existingEntry
};
// mark as stale immediately
updates.stale = now;
if (durations.expire !== undefined) {
updates.expired = now + durations.expire * 1000 // Convert seconds to ms
;
}
_tagsmanifestexternal.tagsManifest.set(tag, updates);
} else {
// Update expired field for immediate expiration (default behavior when no durations provided)
_tagsmanifestexternal.tagsManifest.set(tag, {
...existingEntry,
expired: now
});
}
}
}
async get(...args) {
var _FileSystemCache_memoryCache, _data_value, _data_value1, _data_value2, _data_value3;
const [key, ctx] = args;
const { kind } = ctx;
let data = (_FileSystemCache_memoryCache = FileSystemCache.memoryCache) == null ? void 0 : _FileSystemCache_memoryCache.get(key);
if (FileSystemCache.debug) {
if (kind === _responsecache.IncrementalCacheKind.FETCH) {
console.log('FileSystemCache: get', key, ctx.tags, kind, !!data);
} else {
console.log('FileSystemCache: get', key, kind, !!data);
}
}
// let's check the disk for seed data
if (!data && process.env.NEXT_RUNTIME !== 'edge') {
try {
if (kind === _responsecache.IncrementalCacheKind.APP_ROUTE) {
const filePath = this.getFilePath(`${key}.body`, _responsecache.IncrementalCacheKind.APP_ROUTE);
const fileData = await this.fs.readFile(filePath);
const { mtime } = await this.fs.stat(filePath);
const meta = JSON.parse(await this.fs.readFile(filePath.replace(/\.body$/, _constants.NEXT_META_SUFFIX), 'utf8'));
data = {
lastModified: mtime.getTime(),
value: {
kind: _responsecache.CachedRouteKind.APP_ROUTE,
body: fileData,
headers: meta.headers,
status: meta.status
}
};
} else {
const filePath = this.getFilePath(kind === _responsecache.IncrementalCacheKind.FETCH ? key : `${key}.html`, kind);
const fileData = await this.fs.readFile(filePath, 'utf8');
const { mtime } = await this.fs.stat(filePath);
if (kind === _responsecache.IncrementalCacheKind.FETCH) {
var _data_value4;
const { tags, fetchIdx, fetchUrl } = ctx;
if (!this.flushToDisk) return null;
const lastModified = mtime.getTime();
const parsedData = JSON.parse(fileData);
data = {
lastModified,
value: parsedData
};
if (((_data_value4 = data.value) == null ? void 0 : _data_value4.kind) === _responsecache.CachedRouteKind.FETCH) {
var _data_value5;
const storedTags = (_data_value5 = data.value) == null ? void 0 : _data_value5.tags;
// update stored tags if a new one is being added
// TODO: remove this when we can send the tags
// via header on GET same as SET
if (!(tags == null ? void 0 : tags.every((tag)=>storedTags == null ? void 0 : storedTags.includes(tag)))) {
if (FileSystemCache.debug) {
console.log('FileSystemCache: tags vs storedTags mismatch', tags, storedTags);
}
await this.set(key, data.value, {
fetchCache: true,
tags,
fetchIdx,
fetchUrl
});
}
}
} else if (kind === _responsecache.IncrementalCacheKind.APP_PAGE) {
// We try to load the metadata file, but if it fails, we don't
// error. We also don't load it if this is a fallback.
let meta;
try {
meta = JSON.parse(await this.fs.readFile(filePath.replace(/\.html$/, _constants.NEXT_META_SUFFIX), 'utf8'));
} catch {}
let maybeSegmentData;
if (meta == null ? void 0 : meta.segmentPaths) {
// Collect all the segment data for this page.
// TODO: To optimize file system reads, we should consider creating
// separate cache entries for each segment, rather than storing them
// all on the page's entry. Though the behavior is
// identical regardless.
const segmentData = new Map();
maybeSegmentData = segmentData;
const segmentsDir = key + _constants.RSC_SEGMENTS_DIR_SUFFIX;
await Promise.all(meta.segmentPaths.map(async (segmentPath)=>{
const segmentDataFilePath = this.getFilePath(segmentsDir + segmentPath + _constants.RSC_SEGMENT_SUFFIX, _responsecache.IncrementalCacheKind.APP_PAGE);
try {
segmentData.set(segmentPath, await this.fs.readFile(segmentDataFilePath));
} catch {
// This shouldn't happen, but if for some reason we fail to
// load a segment from the filesystem, treat it the same as if
// the segment is dynamic and does not have a prefetch.
}
}));
}
let rscData;
if (!ctx.isFallback && !ctx.isRoutePPREnabled) {
rscData = await this.fs.readFile(this.getFilePath(`${key}${_constants.RSC_SUFFIX}`, _responsecache.IncrementalCacheKind.APP_PAGE));
}
data = {
lastModified: mtime.getTime(),
value: {
kind: _responsecache.CachedRouteKind.APP_PAGE,
html: fileData,
rscData,
postponed: meta == null ? void 0 : meta.postponed,
headers: meta == null ? void 0 : meta.headers,
status: meta == null ? void 0 : meta.status,
segmentData: maybeSegmentData
}
};
} else if (kind === _responsecache.IncrementalCacheKind.PAGES) {
let meta;
let pageData = {};
if (!ctx.isFallback) {
pageData = JSON.parse(await this.fs.readFile(this.getFilePath(`${key}${_constants.NEXT_DATA_SUFFIX}`, _responsecache.IncrementalCacheKind.PAGES), 'utf8'));
}
data = {
lastModified: mtime.getTime(),
value: {
kind: _responsecache.CachedRouteKind.PAGES,
html: fileData,
pageData,
headers: meta == null ? void 0 : meta.headers,
status: meta == null ? void 0 : meta.status
}
};
} else {
throw Object.defineProperty(new Error(`Invariant: Unexpected route kind ${kind} in file system cache.`), "__NEXT_ERROR_CODE", {
value: "E445",
enumerable: false,
configurable: true
});
}
}
if (data) {
var _FileSystemCache_memoryCache1;
(_FileSystemCache_memoryCache1 = FileSystemCache.memoryCache) == null ? void 0 : _FileSystemCache_memoryCache1.set(key, data);
}
} catch {
return null;
}
}
if ((data == null ? void 0 : (_data_value = data.value) == null ? void 0 : _data_value.kind) === _responsecache.CachedRouteKind.APP_PAGE || (data == null ? void 0 : (_data_value1 = data.value) == null ? void 0 : _data_value1.kind) === _responsecache.CachedRouteKind.APP_ROUTE || (data == null ? void 0 : (_data_value2 = data.value) == null ? void 0 : _data_value2.kind) === _responsecache.CachedRouteKind.PAGES) {
var _data_value_headers;
const tagsHeader = (_data_value_headers = data.value.headers) == null ? void 0 : _data_value_headers[_constants.NEXT_CACHE_TAGS_HEADER];
if (typeof tagsHeader === 'string') {
const cacheTags = tagsHeader.split(',');
// we trigger a blocking validation if an ISR page
// had a tag revalidated, if we want to be a background
// revalidation instead we return data.lastModified = -1
if (cacheTags.length > 0 && (0, _tagsmanifestexternal.areTagsExpired)(cacheTags, data.lastModified)) {
if (FileSystemCache.debug) {
console.log('FileSystemCache: expired tags', cacheTags);
}
return null;
}
}
} else if ((data == null ? void 0 : (_data_value3 = data.value) == null ? void 0 : _data_value3.kind) === _responsecache.CachedRouteKind.FETCH) {
const combinedTags = ctx.kind === _responsecache.IncrementalCacheKind.FETCH ? [
...ctx.tags || [],
...ctx.softTags || []
] : [];
// When revalidate tag is called we don't return stale data so it's
// updated right away.
if (combinedTags.some((tag)=>this.revalidatedTags.includes(tag))) {
if (FileSystemCache.debug) {
console.log('FileSystemCache: was revalidated', combinedTags);
}
return null;
}
if ((0, _tagsmanifestexternal.areTagsExpired)(combinedTags, data.lastModified)) {
if (FileSystemCache.debug) {
console.log('FileSystemCache: expired tags', combinedTags);
}
return null;
}
}
return data ?? null;
}
async set(key, data, ctx) {
var _FileSystemCache_memoryCache;
(_FileSystemCache_memoryCache = FileSystemCache.memoryCache) == null ? void 0 : _FileSystemCache_memoryCache.set(key, {
value: data,
lastModified: Date.now()
});
if (FileSystemCache.debug) {
console.log('FileSystemCache: set', key);
}
if (!this.flushToDisk || !data) return;
// Create a new writer that will prepare to write all the files to disk
// after their containing directory is created.
const writer = new _multifilewriter.MultiFileWriter(this.fs);
if (data.kind === _responsecache.CachedRouteKind.APP_ROUTE) {
const filePath = this.getFilePath(`${key}.body`, _responsecache.IncrementalCacheKind.APP_ROUTE);
writer.append(filePath, data.body);
const meta = {
headers: data.headers,
status: data.status,
postponed: undefined,
segmentPaths: undefined
};
writer.append(filePath.replace(/\.body$/, _constants.NEXT_META_SUFFIX), JSON.stringify(meta, null, 2));
} else if (data.kind === _responsecache.CachedRouteKind.PAGES || data.kind === _responsecache.CachedRouteKind.APP_PAGE) {
const isAppPath = data.kind === _responsecache.CachedRouteKind.APP_PAGE;
const htmlPath = this.getFilePath(`${key}.html`, isAppPath ? _responsecache.IncrementalCacheKind.APP_PAGE : _responsecache.IncrementalCacheKind.PAGES);
writer.append(htmlPath, data.html);
// Fallbacks don't generate a data file.
if (!ctx.fetchCache && !ctx.isFallback && !ctx.isRoutePPREnabled) {
writer.append(this.getFilePath(`${key}${isAppPath ? _constants.RSC_SUFFIX : _constants.NEXT_DATA_SUFFIX}`, isAppPath ? _responsecache.IncrementalCacheKind.APP_PAGE : _responsecache.IncrementalCacheKind.PAGES), isAppPath ? data.rscData : JSON.stringify(data.pageData));
}
if ((data == null ? void 0 : data.kind) === _responsecache.CachedRouteKind.APP_PAGE) {
let segmentPaths;
if (data.segmentData) {
segmentPaths = [];
const segmentsDir = htmlPath.replace(/\.html$/, _constants.RSC_SEGMENTS_DIR_SUFFIX);
for (const [segmentPath, buffer] of data.segmentData){
segmentPaths.push(segmentPath);
const segmentDataFilePath = segmentsDir + segmentPath + _constants.RSC_SEGMENT_SUFFIX;
writer.append(segmentDataFilePath, buffer);
}
}
const meta = {
headers: data.headers,
status: data.status,
postponed: data.postponed,
segmentPaths
};
writer.append(htmlPath.replace(/\.html$/, _constants.NEXT_META_SUFFIX), JSON.stringify(meta));
}
} else if (data.kind === _responsecache.CachedRouteKind.FETCH) {
const filePath = this.getFilePath(key, _responsecache.IncrementalCacheKind.FETCH);
writer.append(filePath, JSON.stringify({
...data,
tags: ctx.fetchCache ? ctx.tags : []
}));
}
// Wait for all FS operations to complete.
await writer.wait();
}
getFilePath(pathname, kind) {
switch(kind){
case _responsecache.IncrementalCacheKind.FETCH:
// we store in .next/cache/fetch-cache so it can be persisted
// across deploys
return _path.default.join(this.serverDistDir, '..', 'cache', 'fetch-cache', pathname);
case _responsecache.IncrementalCacheKind.PAGES:
return _path.default.join(this.serverDistDir, 'pages', pathname);
case _responsecache.IncrementalCacheKind.IMAGE:
case _responsecache.IncrementalCacheKind.APP_PAGE:
case _responsecache.IncrementalCacheKind.APP_ROUTE:
return _path.default.join(this.serverDistDir, 'app', pathname);
default:
throw Object.defineProperty(new Error(`Unexpected file path kind: ${kind}`), "__NEXT_ERROR_CODE", {
value: "E479",
enumerable: false,
configurable: true
});
}
}
}
//# sourceMappingURL=file-system-cache.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,75 @@
import type { CacheFs } from '../../../shared/lib/utils';
import type { PrerenderManifest } from '../../../build';
import { type IncrementalCacheValue, type IncrementalCache as IncrementalCacheType, type IncrementalResponseCacheEntry, type IncrementalFetchCacheEntry, type GetIncrementalFetchCacheContext, type GetIncrementalResponseCacheContext, type CachedFetchValue, type SetIncrementalFetchCacheContext, type SetIncrementalResponseCacheContext } from '../../response-cache';
import type { DeepReadonly } from '../../../shared/lib/deep-readonly';
export interface CacheHandlerContext {
fs?: CacheFs;
dev?: boolean;
flushToDisk?: boolean;
serverDistDir?: string;
maxMemoryCacheSize?: number;
fetchCacheKeyPrefix?: string;
prerenderManifest?: PrerenderManifest;
revalidatedTags: string[];
_requestHeaders: IncrementalCache['requestHeaders'];
}
export interface CacheHandlerValue {
lastModified: number;
age?: number;
cacheState?: string;
value: IncrementalCacheValue | null;
}
export declare class CacheHandler {
constructor(_ctx: CacheHandlerContext);
get(_cacheKey: string, _ctx: GetIncrementalFetchCacheContext | GetIncrementalResponseCacheContext): Promise<CacheHandlerValue | null>;
set(_cacheKey: string, _data: IncrementalCacheValue | null, _ctx: SetIncrementalFetchCacheContext | SetIncrementalResponseCacheContext): Promise<void>;
revalidateTag(_tags: string | string[], _durations?: {
expire?: number;
}): Promise<void>;
resetRequestCache(): void;
}
export declare class IncrementalCache implements IncrementalCacheType {
readonly dev?: boolean;
readonly disableForTestmode?: boolean;
readonly cacheHandler?: CacheHandler;
readonly hasCustomCacheHandler: boolean;
readonly prerenderManifest: DeepReadonly<PrerenderManifest>;
readonly requestHeaders: Record<string, undefined | string | string[]>;
readonly allowedRevalidateHeaderKeys?: string[];
readonly minimalMode?: boolean;
readonly fetchCacheKeyPrefix?: string;
readonly isOnDemandRevalidate?: boolean;
readonly revalidatedTags?: readonly string[];
private static readonly debug;
private readonly locks;
/**
* The cache controls for routes. This will source the values from the
* prerender manifest until the in-memory cache is updated with new values.
*/
private readonly cacheControls;
constructor({ fs, dev, flushToDisk, minimalMode, serverDistDir, requestHeaders, maxMemoryCacheSize, getPrerenderManifest, fetchCacheKeyPrefix, CurCacheHandler, allowedRevalidateHeaderKeys, }: {
fs?: CacheFs;
dev: boolean;
minimalMode?: boolean;
serverDistDir?: string;
flushToDisk?: boolean;
allowedRevalidateHeaderKeys?: string[];
requestHeaders: IncrementalCache['requestHeaders'];
maxMemoryCacheSize?: number;
getPrerenderManifest: () => DeepReadonly<PrerenderManifest>;
fetchCacheKeyPrefix?: string;
CurCacheHandler?: typeof CacheHandler;
});
private calculateRevalidate;
_getPathname(pathname: string, fetchCache?: boolean): string;
resetRequestCache(): void;
lock(cacheKey: string): Promise<() => Promise<void> | void>;
revalidateTag(tags: string | string[], durations?: {
expire?: number;
}): Promise<void>;
generateCacheKey(url: string, init?: RequestInit | Request): Promise<string>;
get(cacheKey: string, ctx: GetIncrementalFetchCacheContext): Promise<IncrementalFetchCacheEntry | null>;
get(cacheKey: string, ctx: GetIncrementalResponseCacheContext): Promise<IncrementalResponseCacheEntry | null>;
set(pathname: string, data: CachedFetchValue | null, ctx: SetIncrementalFetchCacheContext): Promise<void>;
set(pathname: string, data: Exclude<IncrementalCacheValue, CachedFetchValue> | null, ctx: SetIncrementalResponseCacheContext): Promise<void>;
}

View File

@@ -0,0 +1,479 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
CacheHandler: null,
IncrementalCache: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
CacheHandler: function() {
return CacheHandler;
},
IncrementalCache: function() {
return IncrementalCache;
}
});
const _responsecache = require("../../response-cache");
const _filesystemcache = /*#__PURE__*/ _interop_require_default(require("./file-system-cache"));
const _normalizepagepath = require("../../../shared/lib/page-path/normalize-page-path");
const _constants = require("../../../lib/constants");
const _toroute = require("../to-route");
const _sharedcachecontrolsexternal = require("./shared-cache-controls.external");
const _workunitasyncstorageexternal = require("../../app-render/work-unit-async-storage.external");
const _invarianterror = require("../../../shared/lib/invariant-error");
const _serverutils = require("../../server-utils");
const _workasyncstorageexternal = require("../../app-render/work-async-storage.external");
const _detachedpromise = require("../../../lib/detached-promise");
const _tagsmanifestexternal = require("./tags-manifest.external");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
class CacheHandler {
// eslint-disable-next-line
constructor(_ctx){}
async get(_cacheKey, _ctx) {
return {};
}
async set(_cacheKey, _data, _ctx) {}
async revalidateTag(_tags, _durations) {}
resetRequestCache() {}
}
class IncrementalCache {
static #_ = this.debug = !!process.env.NEXT_PRIVATE_DEBUG_CACHE;
constructor({ fs, dev, flushToDisk, minimalMode, serverDistDir, requestHeaders, maxMemoryCacheSize, getPrerenderManifest, fetchCacheKeyPrefix, CurCacheHandler, allowedRevalidateHeaderKeys }){
var _this_prerenderManifest_preview, _this_prerenderManifest;
this.locks = new Map();
this.hasCustomCacheHandler = Boolean(CurCacheHandler);
const cacheHandlersSymbol = Symbol.for('@next/cache-handlers');
const _globalThis = globalThis;
if (!CurCacheHandler) {
// if we have a global cache handler available leverage it
const globalCacheHandler = _globalThis[cacheHandlersSymbol];
if (globalCacheHandler == null ? void 0 : globalCacheHandler.FetchCache) {
CurCacheHandler = globalCacheHandler.FetchCache;
if (IncrementalCache.debug) {
console.log('IncrementalCache: using global FetchCache cache handler');
}
} else {
if (fs && serverDistDir) {
if (IncrementalCache.debug) {
console.log('IncrementalCache: using filesystem cache handler');
}
CurCacheHandler = _filesystemcache.default;
}
}
} else if (IncrementalCache.debug) {
console.log('IncrementalCache: using custom cache handler', CurCacheHandler.name);
}
if (process.env.__NEXT_TEST_MAX_ISR_CACHE) {
// Allow cache size to be overridden for testing purposes
maxMemoryCacheSize = parseInt(process.env.__NEXT_TEST_MAX_ISR_CACHE, 10);
}
this.dev = dev;
this.disableForTestmode = process.env.NEXT_PRIVATE_TEST_PROXY === 'true';
// this is a hack to avoid Webpack knowing this is equal to this.minimalMode
// because we replace this.minimalMode to true in production bundles.
const minimalModeKey = 'minimalMode';
this[minimalModeKey] = minimalMode;
this.requestHeaders = requestHeaders;
this.allowedRevalidateHeaderKeys = allowedRevalidateHeaderKeys;
this.prerenderManifest = getPrerenderManifest();
this.cacheControls = new _sharedcachecontrolsexternal.SharedCacheControls(this.prerenderManifest);
this.fetchCacheKeyPrefix = fetchCacheKeyPrefix;
let revalidatedTags = [];
if (requestHeaders[_constants.PRERENDER_REVALIDATE_HEADER] === ((_this_prerenderManifest = this.prerenderManifest) == null ? void 0 : (_this_prerenderManifest_preview = _this_prerenderManifest.preview) == null ? void 0 : _this_prerenderManifest_preview.previewModeId)) {
this.isOnDemandRevalidate = true;
}
if (minimalMode) {
var _this_prerenderManifest_preview1, _this_prerenderManifest1;
revalidatedTags = this.revalidatedTags = (0, _serverutils.getPreviouslyRevalidatedTags)(requestHeaders, (_this_prerenderManifest1 = this.prerenderManifest) == null ? void 0 : (_this_prerenderManifest_preview1 = _this_prerenderManifest1.preview) == null ? void 0 : _this_prerenderManifest_preview1.previewModeId);
}
if (CurCacheHandler) {
this.cacheHandler = new CurCacheHandler({
dev,
fs,
flushToDisk,
serverDistDir,
revalidatedTags,
maxMemoryCacheSize,
_requestHeaders: requestHeaders,
fetchCacheKeyPrefix
});
}
}
calculateRevalidate(pathname, fromTime, dev, isFallback) {
// in development we don't have a prerender-manifest
// and default to always revalidating to allow easier debugging
if (dev) return Math.floor(performance.timeOrigin + performance.now() - 1000);
const cacheControl = this.cacheControls.get((0, _toroute.toRoute)(pathname));
// if an entry isn't present in routes we fallback to a default
// of revalidating after 1 second unless it's a fallback request.
const initialRevalidateSeconds = cacheControl ? cacheControl.revalidate : isFallback ? false : 1;
const revalidateAfter = typeof initialRevalidateSeconds === 'number' ? initialRevalidateSeconds * 1000 + fromTime : initialRevalidateSeconds;
return revalidateAfter;
}
_getPathname(pathname, fetchCache) {
return fetchCache ? pathname : (0, _normalizepagepath.normalizePagePath)(pathname);
}
resetRequestCache() {
var _this_cacheHandler_resetRequestCache, _this_cacheHandler;
(_this_cacheHandler = this.cacheHandler) == null ? void 0 : (_this_cacheHandler_resetRequestCache = _this_cacheHandler.resetRequestCache) == null ? void 0 : _this_cacheHandler_resetRequestCache.call(_this_cacheHandler);
}
async lock(cacheKey) {
// Wait for any existing lock on this cache key to be released
// This implements a simple queue-based locking mechanism
while(true){
const lock = this.locks.get(cacheKey);
if (IncrementalCache.debug) {
console.log('IncrementalCache: lock get', cacheKey, !!lock);
}
// If no lock exists, we can proceed to acquire it
if (!lock) break;
// Wait for the existing lock to be released before trying again
await lock;
}
// Create a new detached promise that will represent this lock
// The resolve function (unlock) will be returned to the caller
const { resolve, promise } = new _detachedpromise.DetachedPromise();
if (IncrementalCache.debug) {
console.log('IncrementalCache: successfully locked', cacheKey);
}
// Store the lock promise in the locks map
this.locks.set(cacheKey, promise);
return ()=>{
// Resolve the promise to release the lock.
resolve();
// Remove the lock from the map once it's released so that future gets
// can acquire the lock.
this.locks.delete(cacheKey);
};
}
async revalidateTag(tags, durations) {
var _this_cacheHandler;
return (_this_cacheHandler = this.cacheHandler) == null ? void 0 : _this_cacheHandler.revalidateTag(tags, durations);
}
// x-ref: https://github.com/facebook/react/blob/2655c9354d8e1c54ba888444220f63e836925caa/packages/react/src/ReactFetch.js#L23
async generateCacheKey(url, init = {}) {
// this should be bumped anytime a fix is made to cache entries
// that should bust the cache
const MAIN_KEY_PREFIX = 'v3';
const bodyChunks = [];
const encoder = new TextEncoder();
const decoder = new TextDecoder();
if (init.body) {
// handle Uint8Array body
if (init.body instanceof Uint8Array) {
bodyChunks.push(decoder.decode(init.body));
init._ogBody = init.body;
} else if (typeof init.body.getReader === 'function') {
const readableBody = init.body;
const chunks = [];
try {
await readableBody.pipeTo(new WritableStream({
write (chunk) {
if (typeof chunk === 'string') {
chunks.push(encoder.encode(chunk));
bodyChunks.push(chunk);
} else {
chunks.push(chunk);
bodyChunks.push(decoder.decode(chunk, {
stream: true
}));
}
}
}));
// Flush the decoder.
bodyChunks.push(decoder.decode());
// Create a new buffer with all the chunks.
const length = chunks.reduce((total, arr)=>total + arr.length, 0);
const arrayBuffer = new Uint8Array(length);
// Push each of the chunks into the new array buffer.
let offset = 0;
for (const chunk of chunks){
arrayBuffer.set(chunk, offset);
offset += chunk.length;
}
;
init._ogBody = arrayBuffer;
} catch (err) {
console.error('Problem reading body', err);
}
} else if (typeof init.body.keys === 'function') {
const formData = init.body;
init._ogBody = init.body;
for (const key of new Set([
...formData.keys()
])){
const values = formData.getAll(key);
bodyChunks.push(`${key}=${(await Promise.all(values.map(async (val)=>{
if (typeof val === 'string') {
return val;
} else {
return await val.text();
}
}))).join(',')}`);
}
// handle blob body
} else if (typeof init.body.arrayBuffer === 'function') {
const blob = init.body;
const arrayBuffer = await blob.arrayBuffer();
bodyChunks.push(await blob.text());
init._ogBody = new Blob([
arrayBuffer
], {
type: blob.type
});
} else if (typeof init.body === 'string') {
bodyChunks.push(init.body);
init._ogBody = init.body;
}
}
const headers = typeof (init.headers || {}).keys === 'function' ? Object.fromEntries(init.headers) : Object.assign({}, init.headers);
// w3c trace context headers can break request caching and deduplication
// so we remove them from the cache key
if ('traceparent' in headers) delete headers['traceparent'];
if ('tracestate' in headers) delete headers['tracestate'];
const cacheString = JSON.stringify([
MAIN_KEY_PREFIX,
this.fetchCacheKeyPrefix || '',
url,
init.method,
headers,
init.mode,
init.redirect,
init.credentials,
init.referrer,
init.referrerPolicy,
init.integrity,
init.cache,
bodyChunks
]);
if (process.env.NEXT_RUNTIME === 'edge') {
function bufferToHex(buffer) {
return Array.prototype.map.call(new Uint8Array(buffer), (b)=>b.toString(16).padStart(2, '0')).join('');
}
const buffer = encoder.encode(cacheString);
return bufferToHex(await crypto.subtle.digest('SHA-256', buffer));
} else {
const crypto1 = require('crypto');
return crypto1.createHash('sha256').update(cacheString).digest('hex');
}
}
async get(cacheKey, ctx) {
var _this_cacheHandler, _cacheData_value;
// Unlike other caches if we have a resume data cache, we use it even if
// testmode would normally disable it or if requestHeaders say 'no-cache'.
if (ctx.kind === _responsecache.IncrementalCacheKind.FETCH) {
const workUnitStore = _workunitasyncstorageexternal.workUnitAsyncStorage.getStore();
const resumeDataCache = workUnitStore ? (0, _workunitasyncstorageexternal.getRenderResumeDataCache)(workUnitStore) : null;
if (resumeDataCache) {
const memoryCacheData = resumeDataCache.fetch.get(cacheKey);
if ((memoryCacheData == null ? void 0 : memoryCacheData.kind) === _responsecache.CachedRouteKind.FETCH) {
if (IncrementalCache.debug) {
console.log('IncrementalCache: rdc:hit', cacheKey);
}
return {
isStale: false,
value: memoryCacheData
};
} else if (IncrementalCache.debug) {
console.log('IncrementalCache: rdc:miss', cacheKey);
}
} else {
if (IncrementalCache.debug) {
console.log('IncrementalCache: rdc:no-resume-data');
}
}
}
// we don't leverage the prerender cache in dev mode
// so that getStaticProps is always called for easier debugging
if (this.disableForTestmode || this.dev && (ctx.kind !== _responsecache.IncrementalCacheKind.FETCH || this.requestHeaders['cache-control'] === 'no-cache')) {
return null;
}
cacheKey = this._getPathname(cacheKey, ctx.kind === _responsecache.IncrementalCacheKind.FETCH);
const cacheData = await ((_this_cacheHandler = this.cacheHandler) == null ? void 0 : _this_cacheHandler.get(cacheKey, ctx));
if (ctx.kind === _responsecache.IncrementalCacheKind.FETCH) {
var _cacheData_value1;
if (!cacheData) {
return null;
}
if (((_cacheData_value1 = cacheData.value) == null ? void 0 : _cacheData_value1.kind) !== _responsecache.CachedRouteKind.FETCH) {
var _cacheData_value2;
throw Object.defineProperty(new _invarianterror.InvariantError(`Expected cached value for cache key ${JSON.stringify(cacheKey)} to be a "FETCH" kind, got ${JSON.stringify((_cacheData_value2 = cacheData.value) == null ? void 0 : _cacheData_value2.kind)} instead.`), "__NEXT_ERROR_CODE", {
value: "E653",
enumerable: false,
configurable: true
});
}
const workStore = _workasyncstorageexternal.workAsyncStorage.getStore();
const combinedTags = [
...ctx.tags || [],
...ctx.softTags || []
];
// if a tag was revalidated we don't return stale data
if (combinedTags.some((tag)=>{
var _this_revalidatedTags, _workStore_pendingRevalidatedTags;
return ((_this_revalidatedTags = this.revalidatedTags) == null ? void 0 : _this_revalidatedTags.includes(tag)) || (workStore == null ? void 0 : (_workStore_pendingRevalidatedTags = workStore.pendingRevalidatedTags) == null ? void 0 : _workStore_pendingRevalidatedTags.some((item)=>item.tag === tag));
})) {
if (IncrementalCache.debug) {
console.log('IncrementalCache: expired tag', cacheKey);
}
return null;
}
// As we're able to get the cache entry for this fetch, and the prerender
// resume data cache (RDC) is available, it must have been populated by a
// previous fetch, but was not yet present in the in-memory cache. This
// could be the case when performing multiple renders in parallel during
// build time where we de-duplicate the fetch calls.
//
// We add it to the RDC so that the next fetch call will be able to use it
// and it won't have to reach into the fetch cache implementation.
const workUnitStore = _workunitasyncstorageexternal.workUnitAsyncStorage.getStore();
if (workUnitStore) {
const prerenderResumeDataCache = (0, _workunitasyncstorageexternal.getPrerenderResumeDataCache)(workUnitStore);
if (prerenderResumeDataCache) {
if (IncrementalCache.debug) {
console.log('IncrementalCache: rdc:set', cacheKey);
}
prerenderResumeDataCache.fetch.set(cacheKey, cacheData.value);
}
}
const revalidate = ctx.revalidate || cacheData.value.revalidate;
const age = (performance.timeOrigin + performance.now() - (cacheData.lastModified || 0)) / 1000;
let isStale = age > revalidate;
const data = cacheData.value.data;
if ((0, _tagsmanifestexternal.areTagsExpired)(combinedTags, cacheData.lastModified)) {
return null;
} else if ((0, _tagsmanifestexternal.areTagsStale)(combinedTags, cacheData.lastModified)) {
isStale = true;
}
return {
isStale,
value: {
kind: _responsecache.CachedRouteKind.FETCH,
data,
revalidate
}
};
} else if ((cacheData == null ? void 0 : (_cacheData_value = cacheData.value) == null ? void 0 : _cacheData_value.kind) === _responsecache.CachedRouteKind.FETCH) {
throw Object.defineProperty(new _invarianterror.InvariantError(`Expected cached value for cache key ${JSON.stringify(cacheKey)} not to be a ${JSON.stringify(ctx.kind)} kind, got "FETCH" instead.`), "__NEXT_ERROR_CODE", {
value: "E652",
enumerable: false,
configurable: true
});
}
let entry = null;
const cacheControl = this.cacheControls.get((0, _toroute.toRoute)(cacheKey));
let isStale;
let revalidateAfter;
if ((cacheData == null ? void 0 : cacheData.lastModified) === -1) {
isStale = -1;
revalidateAfter = -1 * _constants.CACHE_ONE_YEAR;
} else {
var _cacheData_value3, _cacheData_value4;
const now = performance.timeOrigin + performance.now();
const lastModified = (cacheData == null ? void 0 : cacheData.lastModified) || now;
revalidateAfter = this.calculateRevalidate(cacheKey, lastModified, this.dev ?? false, ctx.isFallback);
isStale = revalidateAfter !== false && revalidateAfter < now ? true : undefined;
// If the stale time couldn't be determined based on the revalidation
// time, we check if the tags are expired or stale.
if (isStale === undefined && ((cacheData == null ? void 0 : (_cacheData_value3 = cacheData.value) == null ? void 0 : _cacheData_value3.kind) === _responsecache.CachedRouteKind.APP_PAGE || (cacheData == null ? void 0 : (_cacheData_value4 = cacheData.value) == null ? void 0 : _cacheData_value4.kind) === _responsecache.CachedRouteKind.APP_ROUTE)) {
var _cacheData_value_headers;
const tagsHeader = (_cacheData_value_headers = cacheData.value.headers) == null ? void 0 : _cacheData_value_headers[_constants.NEXT_CACHE_TAGS_HEADER];
if (typeof tagsHeader === 'string') {
const cacheTags = tagsHeader.split(',');
if (cacheTags.length > 0) {
if ((0, _tagsmanifestexternal.areTagsExpired)(cacheTags, lastModified)) {
isStale = -1;
} else if ((0, _tagsmanifestexternal.areTagsStale)(cacheTags, lastModified)) {
isStale = true;
}
}
}
}
}
if (cacheData) {
entry = {
isStale,
cacheControl,
revalidateAfter,
value: cacheData.value
};
}
if (!cacheData && this.prerenderManifest.notFoundRoutes.includes(cacheKey)) {
// for the first hit after starting the server the cache
// may not have a way to save notFound: true so if
// the prerender-manifest marks this as notFound then we
// return that entry and trigger a cache set to give it a
// chance to update in-memory entries
entry = {
isStale,
value: null,
cacheControl,
revalidateAfter
};
this.set(cacheKey, entry.value, {
...ctx,
cacheControl
});
}
return entry;
}
async set(pathname, data, ctx) {
// Even if we otherwise disable caching for testMode or if no fetchCache is
// configured we still always stash results in the resume data cache if one
// exists. This is because this is a transient in memory cache that
// populates caches ahead of a dynamic render in dev mode to allow the RSC
// debug info to have the right environment associated to it.
if ((data == null ? void 0 : data.kind) === _responsecache.CachedRouteKind.FETCH) {
const workUnitStore = _workunitasyncstorageexternal.workUnitAsyncStorage.getStore();
const prerenderResumeDataCache = workUnitStore ? (0, _workunitasyncstorageexternal.getPrerenderResumeDataCache)(workUnitStore) : null;
if (prerenderResumeDataCache) {
if (IncrementalCache.debug) {
console.log('IncrementalCache: rdc:set', pathname);
}
prerenderResumeDataCache.fetch.set(pathname, data);
}
}
if (this.disableForTestmode || this.dev && !ctx.fetchCache) return;
pathname = this._getPathname(pathname, ctx.fetchCache);
// FetchCache has upper limit of 2MB per-entry currently
const itemSize = JSON.stringify(data).length;
if (ctx.fetchCache && itemSize > 2 * 1024 * 1024 && // We ignore the size limit when custom cache handler is being used, as it
// might not have this limit
!this.hasCustomCacheHandler && // We also ignore the size limit when it's an implicit build-time-only
// caching that the user isn't even aware of.
!ctx.isImplicitBuildTimeCache) {
const warningText = `Failed to set Next.js data cache for ${ctx.fetchUrl || pathname}, items over 2MB can not be cached (${itemSize} bytes)`;
if (this.dev) {
throw Object.defineProperty(new Error(warningText), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
}
console.warn(warningText);
return;
}
try {
var _this_cacheHandler;
if (!ctx.fetchCache && ctx.cacheControl) {
this.cacheControls.set((0, _toroute.toRoute)(pathname), ctx.cacheControl);
}
await ((_this_cacheHandler = this.cacheHandler) == null ? void 0 : _this_cacheHandler.set(pathname, data, ctx));
} catch (error) {
console.warn('Failed to update prerender cache for', pathname, error);
}
}
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,3 @@
import type { CacheHandlerValue } from '.';
import { LRUCache } from '../lru-cache';
export declare function getMemoryCache(maxMemoryCacheSize: number): LRUCache<CacheHandlerValue>;

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getMemoryCache", {
enumerable: true,
get: function() {
return getMemoryCache;
}
});
const _types = require("../../response-cache/types");
const _lrucache = require("../lru-cache");
let memoryCache;
function getMemoryCache(maxMemoryCacheSize) {
if (!memoryCache) {
memoryCache = new _lrucache.LRUCache(maxMemoryCacheSize, function length({ value }) {
var _JSON_stringify;
if (!value) {
return 25;
} else if (value.kind === _types.CachedRouteKind.REDIRECT) {
return JSON.stringify(value.props).length;
} else if (value.kind === _types.CachedRouteKind.IMAGE) {
throw Object.defineProperty(new Error('invariant image should not be incremental-cache'), "__NEXT_ERROR_CODE", {
value: "E501",
enumerable: false,
configurable: true
});
} else if (value.kind === _types.CachedRouteKind.FETCH) {
return JSON.stringify(value.data || '').length;
} else if (value.kind === _types.CachedRouteKind.APP_ROUTE) {
return value.body.length;
}
// rough estimate of size of cache value
return value.html.length + (((_JSON_stringify = JSON.stringify(value.kind === _types.CachedRouteKind.APP_PAGE ? value.rscData : value.pageData)) == null ? void 0 : _JSON_stringify.length) || 0);
});
}
return memoryCache;
}
//# sourceMappingURL=memory-cache.external.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/incremental-cache/memory-cache.external.ts"],"sourcesContent":["import type { CacheHandlerValue } from '.'\nimport { CachedRouteKind } from '../../response-cache/types'\nimport { LRUCache } from '../lru-cache'\n\nlet memoryCache: LRUCache<CacheHandlerValue> | undefined\n\nexport function getMemoryCache(maxMemoryCacheSize: number) {\n if (!memoryCache) {\n memoryCache = new LRUCache(maxMemoryCacheSize, function length({ value }) {\n if (!value) {\n return 25\n } else if (value.kind === CachedRouteKind.REDIRECT) {\n return JSON.stringify(value.props).length\n } else if (value.kind === CachedRouteKind.IMAGE) {\n throw new Error('invariant image should not be incremental-cache')\n } else if (value.kind === CachedRouteKind.FETCH) {\n return JSON.stringify(value.data || '').length\n } else if (value.kind === CachedRouteKind.APP_ROUTE) {\n return value.body.length\n }\n // rough estimate of size of cache value\n return (\n value.html.length +\n (JSON.stringify(\n value.kind === CachedRouteKind.APP_PAGE\n ? value.rscData\n : value.pageData\n )?.length || 0)\n )\n })\n }\n\n return memoryCache\n}\n"],"names":["getMemoryCache","memoryCache","maxMemoryCacheSize","LRUCache","length","value","JSON","kind","CachedRouteKind","REDIRECT","stringify","props","IMAGE","Error","FETCH","data","APP_ROUTE","body","html","APP_PAGE","rscData","pageData"],"mappings":";;;;+BAMgBA;;;eAAAA;;;uBALgB;0BACP;AAEzB,IAAIC;AAEG,SAASD,eAAeE,kBAA0B;IACvD,IAAI,CAACD,aAAa;QAChBA,cAAc,IAAIE,kBAAQ,CAACD,oBAAoB,SAASE,OAAO,EAAEC,KAAK,EAAE;gBAenEC;YAdH,IAAI,CAACD,OAAO;gBACV,OAAO;YACT,OAAO,IAAIA,MAAME,IAAI,KAAKC,sBAAe,CAACC,QAAQ,EAAE;gBAClD,OAAOH,KAAKI,SAAS,CAACL,MAAMM,KAAK,EAAEP,MAAM;YAC3C,OAAO,IAAIC,MAAME,IAAI,KAAKC,sBAAe,CAACI,KAAK,EAAE;gBAC/C,MAAM,qBAA4D,CAA5D,IAAIC,MAAM,oDAAV,qBAAA;2BAAA;gCAAA;kCAAA;gBAA2D;YACnE,OAAO,IAAIR,MAAME,IAAI,KAAKC,sBAAe,CAACM,KAAK,EAAE;gBAC/C,OAAOR,KAAKI,SAAS,CAACL,MAAMU,IAAI,IAAI,IAAIX,MAAM;YAChD,OAAO,IAAIC,MAAME,IAAI,KAAKC,sBAAe,CAACQ,SAAS,EAAE;gBACnD,OAAOX,MAAMY,IAAI,CAACb,MAAM;YAC1B;YACA,wCAAwC;YACxC,OACEC,MAAMa,IAAI,CAACd,MAAM,GAChBE,CAAAA,EAAAA,kBAAAA,KAAKI,SAAS,CACbL,MAAME,IAAI,KAAKC,sBAAe,CAACW,QAAQ,GACnCd,MAAMe,OAAO,GACbf,MAAMgB,QAAQ,sBAHnBf,gBAIEF,MAAM,KAAI,CAAA;QAEjB;IACF;IAEA,OAAOH;AACT","ignoreList":[0]}

View File

@@ -0,0 +1,47 @@
import type { PrerenderManifest } from '../../../build';
import type { DeepReadonly } from '../../../shared/lib/deep-readonly';
import type { CacheControl } from '../cache-control';
/**
* A shared cache of cache controls for routes. This cache is used so we don't
* have to modify the prerender manifest when we want to update the cache
* control for a route.
*/
export declare class SharedCacheControls {
/**
* The prerender manifest that contains the initial cache controls for
* routes.
*/
private readonly prerenderManifest;
/**
* The in-memory cache of cache lives for routes. This cache is populated when
* the cache is updated with new cache lives.
*/
private static readonly cacheControls;
constructor(
/**
* The prerender manifest that contains the initial cache controls for
* routes.
*/
prerenderManifest: DeepReadonly<Pick<PrerenderManifest, 'routes' | 'dynamicRoutes'>>);
/**
* Try to get the cache control value for a route. This will first try to get
* the value from the in-memory cache. If the value is not present in the
* in-memory cache, it will be sourced from the prerender manifest.
*
* @param route the route to get the cache control for
* @returns the cache control for the route, or undefined if the values
* are not present in the in-memory cache or the prerender manifest
*/
get(route: string): CacheControl | undefined;
/**
* Set the cache control for a route.
*
* @param route the route to set the cache control for
* @param cacheControl the cache control for the route
*/
set(route: string, cacheControl: CacheControl): void;
/**
* Clear the in-memory cache of cache controls for routes.
*/
clear(): void;
}

View File

@@ -0,0 +1,73 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "SharedCacheControls", {
enumerable: true,
get: function() {
return SharedCacheControls;
}
});
class SharedCacheControls {
static #_ = /**
* The in-memory cache of cache lives for routes. This cache is populated when
* the cache is updated with new cache lives.
*/ this.cacheControls = new Map();
constructor(/**
* The prerender manifest that contains the initial cache controls for
* routes.
*/ prerenderManifest){
this.prerenderManifest = prerenderManifest;
}
/**
* Try to get the cache control value for a route. This will first try to get
* the value from the in-memory cache. If the value is not present in the
* in-memory cache, it will be sourced from the prerender manifest.
*
* @param route the route to get the cache control for
* @returns the cache control for the route, or undefined if the values
* are not present in the in-memory cache or the prerender manifest
*/ get(route) {
// This is a copy on write cache that is updated when the cache is updated.
// If the cache is never written to, then the values will be sourced from
// the prerender manifest.
let cacheControl = SharedCacheControls.cacheControls.get(route);
if (cacheControl) return cacheControl;
let prerenderData = this.prerenderManifest.routes[route];
if (prerenderData) {
const { initialRevalidateSeconds, initialExpireSeconds } = prerenderData;
if (typeof initialRevalidateSeconds !== 'undefined') {
return {
revalidate: initialRevalidateSeconds,
expire: initialExpireSeconds
};
}
}
const dynamicPrerenderData = this.prerenderManifest.dynamicRoutes[route];
if (dynamicPrerenderData) {
const { fallbackRevalidate, fallbackExpire } = dynamicPrerenderData;
if (typeof fallbackRevalidate !== 'undefined') {
return {
revalidate: fallbackRevalidate,
expire: fallbackExpire
};
}
}
return undefined;
}
/**
* Set the cache control for a route.
*
* @param route the route to set the cache control for
* @param cacheControl the cache control for the route
*/ set(route, cacheControl) {
SharedCacheControls.cacheControls.set(route, cacheControl);
}
/**
* Clear the in-memory cache of cache controls for routes.
*/ clear() {
SharedCacheControls.cacheControls.clear();
}
}
//# sourceMappingURL=shared-cache-controls.external.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/incremental-cache/shared-cache-controls.external.ts"],"sourcesContent":["import type { PrerenderManifest } from '../../../build'\nimport type { DeepReadonly } from '../../../shared/lib/deep-readonly'\nimport type { CacheControl } from '../cache-control'\n\n/**\n * A shared cache of cache controls for routes. This cache is used so we don't\n * have to modify the prerender manifest when we want to update the cache\n * control for a route.\n */\nexport class SharedCacheControls {\n /**\n * The in-memory cache of cache lives for routes. This cache is populated when\n * the cache is updated with new cache lives.\n */\n private static readonly cacheControls = new Map<string, CacheControl>()\n\n constructor(\n /**\n * The prerender manifest that contains the initial cache controls for\n * routes.\n */\n private readonly prerenderManifest: DeepReadonly<\n Pick<PrerenderManifest, 'routes' | 'dynamicRoutes'>\n >\n ) {}\n\n /**\n * Try to get the cache control value for a route. This will first try to get\n * the value from the in-memory cache. If the value is not present in the\n * in-memory cache, it will be sourced from the prerender manifest.\n *\n * @param route the route to get the cache control for\n * @returns the cache control for the route, or undefined if the values\n * are not present in the in-memory cache or the prerender manifest\n */\n public get(route: string): CacheControl | undefined {\n // This is a copy on write cache that is updated when the cache is updated.\n // If the cache is never written to, then the values will be sourced from\n // the prerender manifest.\n let cacheControl = SharedCacheControls.cacheControls.get(route)\n if (cacheControl) return cacheControl\n\n let prerenderData = this.prerenderManifest.routes[route]\n\n if (prerenderData) {\n const { initialRevalidateSeconds, initialExpireSeconds } = prerenderData\n\n if (typeof initialRevalidateSeconds !== 'undefined') {\n return {\n revalidate: initialRevalidateSeconds,\n expire: initialExpireSeconds,\n }\n }\n }\n\n const dynamicPrerenderData = this.prerenderManifest.dynamicRoutes[route]\n\n if (dynamicPrerenderData) {\n const { fallbackRevalidate, fallbackExpire } = dynamicPrerenderData\n\n if (typeof fallbackRevalidate !== 'undefined') {\n return { revalidate: fallbackRevalidate, expire: fallbackExpire }\n }\n }\n\n return undefined\n }\n\n /**\n * Set the cache control for a route.\n *\n * @param route the route to set the cache control for\n * @param cacheControl the cache control for the route\n */\n public set(route: string, cacheControl: CacheControl) {\n SharedCacheControls.cacheControls.set(route, cacheControl)\n }\n\n /**\n * Clear the in-memory cache of cache controls for routes.\n */\n public clear() {\n SharedCacheControls.cacheControls.clear()\n }\n}\n"],"names":["SharedCacheControls","cacheControls","Map","constructor","prerenderManifest","get","route","cacheControl","prerenderData","routes","initialRevalidateSeconds","initialExpireSeconds","revalidate","expire","dynamicPrerenderData","dynamicRoutes","fallbackRevalidate","fallbackExpire","undefined","set","clear"],"mappings":";;;;+BASaA;;;eAAAA;;;AAAN,MAAMA;gBACX;;;GAGC,QACuBC,gBAAgB,IAAIC;IAE5CC,YACE;;;KAGC,GACD,AAAiBC,iBAEhB,CACD;aAHiBA,oBAAAA;IAGhB;IAEH;;;;;;;;GAQC,GACD,AAAOC,IAAIC,KAAa,EAA4B;QAClD,2EAA2E;QAC3E,yEAAyE;QACzE,0BAA0B;QAC1B,IAAIC,eAAeP,oBAAoBC,aAAa,CAACI,GAAG,CAACC;QACzD,IAAIC,cAAc,OAAOA;QAEzB,IAAIC,gBAAgB,IAAI,CAACJ,iBAAiB,CAACK,MAAM,CAACH,MAAM;QAExD,IAAIE,eAAe;YACjB,MAAM,EAAEE,wBAAwB,EAAEC,oBAAoB,EAAE,GAAGH;YAE3D,IAAI,OAAOE,6BAA6B,aAAa;gBACnD,OAAO;oBACLE,YAAYF;oBACZG,QAAQF;gBACV;YACF;QACF;QAEA,MAAMG,uBAAuB,IAAI,CAACV,iBAAiB,CAACW,aAAa,CAACT,MAAM;QAExE,IAAIQ,sBAAsB;YACxB,MAAM,EAAEE,kBAAkB,EAAEC,cAAc,EAAE,GAAGH;YAE/C,IAAI,OAAOE,uBAAuB,aAAa;gBAC7C,OAAO;oBAAEJ,YAAYI;oBAAoBH,QAAQI;gBAAe;YAClE;QACF;QAEA,OAAOC;IACT;IAEA;;;;;GAKC,GACD,AAAOC,IAAIb,KAAa,EAAEC,YAA0B,EAAE;QACpDP,oBAAoBC,aAAa,CAACkB,GAAG,CAACb,OAAOC;IAC/C;IAEA;;GAEC,GACD,AAAOa,QAAQ;QACbpB,oBAAoBC,aAAa,CAACmB,KAAK;IACzC;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,8 @@
import type { Timestamp } from '../cache-handlers/types';
export interface TagManifestEntry {
stale?: number;
expired?: number;
}
export declare const tagsManifest: Map<string, TagManifestEntry>;
export declare const areTagsExpired: (tags: string[], timestamp: Timestamp) => boolean;
export declare const areTagsStale: (tags: string[], timestamp: Timestamp) => boolean;

View File

@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
areTagsExpired: null,
areTagsStale: null,
tagsManifest: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
areTagsExpired: function() {
return areTagsExpired;
},
areTagsStale: function() {
return areTagsStale;
},
tagsManifest: function() {
return tagsManifest;
}
});
const tagsManifest = new Map();
const areTagsExpired = (tags, timestamp)=>{
for (const tag of tags){
const entry = tagsManifest.get(tag);
const expiredAt = entry == null ? void 0 : entry.expired;
if (typeof expiredAt === 'number') {
const now = Date.now();
// For immediate expiration (expiredAt <= now) and tag was invalidated after entry was created
// OR for future expiration that has now passed (expiredAt > timestamp && expiredAt <= now)
const isImmediatelyExpired = expiredAt <= now && expiredAt > timestamp;
if (isImmediatelyExpired) {
return true;
}
}
}
return false;
};
const areTagsStale = (tags, timestamp)=>{
for (const tag of tags){
const entry = tagsManifest.get(tag);
const staleAt = (entry == null ? void 0 : entry.stale) ?? 0;
if (typeof staleAt === 'number' && staleAt > timestamp) {
return true;
}
}
return false;
};
//# sourceMappingURL=tags-manifest.external.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/incremental-cache/tags-manifest.external.ts"],"sourcesContent":["import type { Timestamp } from '../cache-handlers/types'\n\nexport interface TagManifestEntry {\n stale?: number\n expired?: number\n}\n\n// We share the tags manifest between the \"use cache\" handlers and the previous\n// file-system cache.\nexport const tagsManifest = new Map<string, TagManifestEntry>()\n\nexport const areTagsExpired = (tags: string[], timestamp: Timestamp) => {\n for (const tag of tags) {\n const entry = tagsManifest.get(tag)\n const expiredAt = entry?.expired\n\n if (typeof expiredAt === 'number') {\n const now = Date.now()\n // For immediate expiration (expiredAt <= now) and tag was invalidated after entry was created\n // OR for future expiration that has now passed (expiredAt > timestamp && expiredAt <= now)\n const isImmediatelyExpired = expiredAt <= now && expiredAt > timestamp\n\n if (isImmediatelyExpired) {\n return true\n }\n }\n }\n\n return false\n}\n\nexport const areTagsStale = (tags: string[], timestamp: Timestamp) => {\n for (const tag of tags) {\n const entry = tagsManifest.get(tag)\n const staleAt = entry?.stale ?? 0\n\n if (typeof staleAt === 'number' && staleAt > timestamp) {\n return true\n }\n }\n\n return false\n}\n"],"names":["areTagsExpired","areTagsStale","tagsManifest","Map","tags","timestamp","tag","entry","get","expiredAt","expired","now","Date","isImmediatelyExpired","staleAt","stale"],"mappings":";;;;;;;;;;;;;;;;IAWaA,cAAc;eAAdA;;IAoBAC,YAAY;eAAZA;;IAtBAC,YAAY;eAAZA;;;AAAN,MAAMA,eAAe,IAAIC;AAEzB,MAAMH,iBAAiB,CAACI,MAAgBC;IAC7C,KAAK,MAAMC,OAAOF,KAAM;QACtB,MAAMG,QAAQL,aAAaM,GAAG,CAACF;QAC/B,MAAMG,YAAYF,yBAAAA,MAAOG,OAAO;QAEhC,IAAI,OAAOD,cAAc,UAAU;YACjC,MAAME,MAAMC,KAAKD,GAAG;YACpB,8FAA8F;YAC9F,2FAA2F;YAC3F,MAAME,uBAAuBJ,aAAaE,OAAOF,YAAYJ;YAE7D,IAAIQ,sBAAsB;gBACxB,OAAO;YACT;QACF;IACF;IAEA,OAAO;AACT;AAEO,MAAMZ,eAAe,CAACG,MAAgBC;IAC3C,KAAK,MAAMC,OAAOF,KAAM;QACtB,MAAMG,QAAQL,aAAaM,GAAG,CAACF;QAC/B,MAAMQ,UAAUP,CAAAA,yBAAAA,MAAOQ,KAAK,KAAI;QAEhC,IAAI,OAAOD,YAAY,YAAYA,UAAUT,WAAW;YACtD,OAAO;QACT;IACF;IAEA,OAAO;AACT","ignoreList":[0]}

View File

@@ -0,0 +1 @@
export declare function isIPv6(s: string): boolean;

View File

@@ -0,0 +1,41 @@
// Regex from `node/lib/internal/net.js`: https://github.com/nodejs/node/blob/9fc57006c27564ed7f75eee090eca86786508f51/lib/internal/net.js#L19-L29
// License included below:
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "isIPv6", {
enumerable: true,
get: function() {
return isIPv6;
}
});
const v4Seg = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
const v4Str = `(${v4Seg}[.]){3}${v4Seg}`;
const v6Seg = '(?:[0-9a-fA-F]{1,4})';
const IPv6Reg = new RegExp('^(' + `(?:${v6Seg}:){7}(?:${v6Seg}|:)|` + `(?:${v6Seg}:){6}(?:${v4Str}|:${v6Seg}|:)|` + `(?:${v6Seg}:){5}(?::${v4Str}|(:${v6Seg}){1,2}|:)|` + `(?:${v6Seg}:){4}(?:(:${v6Seg}){0,1}:${v4Str}|(:${v6Seg}){1,3}|:)|` + `(?:${v6Seg}:){3}(?:(:${v6Seg}){0,2}:${v4Str}|(:${v6Seg}){1,4}|:)|` + `(?:${v6Seg}:){2}(?:(:${v6Seg}){0,3}:${v4Str}|(:${v6Seg}){1,5}|:)|` + `(?:${v6Seg}:){1}(?:(:${v6Seg}){0,4}:${v4Str}|(:${v6Seg}){1,6}|:)|` + `(?::((?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:))` + ')(%[0-9a-zA-Z-.:]{1,})?$');
function isIPv6(s) {
return IPv6Reg.test(s);
}
//# sourceMappingURL=is-ipv6.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/is-ipv6.ts"],"sourcesContent":["// Regex from `node/lib/internal/net.js`: https://github.com/nodejs/node/blob/9fc57006c27564ed7f75eee090eca86786508f51/lib/internal/net.js#L19-L29\n// License included below:\n// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nconst v4Seg = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'\nconst v4Str = `(${v4Seg}[.]){3}${v4Seg}`\nconst v6Seg = '(?:[0-9a-fA-F]{1,4})'\nconst IPv6Reg = new RegExp(\n '^(' +\n `(?:${v6Seg}:){7}(?:${v6Seg}|:)|` +\n `(?:${v6Seg}:){6}(?:${v4Str}|:${v6Seg}|:)|` +\n `(?:${v6Seg}:){5}(?::${v4Str}|(:${v6Seg}){1,2}|:)|` +\n `(?:${v6Seg}:){4}(?:(:${v6Seg}){0,1}:${v4Str}|(:${v6Seg}){1,3}|:)|` +\n `(?:${v6Seg}:){3}(?:(:${v6Seg}){0,2}:${v4Str}|(:${v6Seg}){1,4}|:)|` +\n `(?:${v6Seg}:){2}(?:(:${v6Seg}){0,3}:${v4Str}|(:${v6Seg}){1,5}|:)|` +\n `(?:${v6Seg}:){1}(?:(:${v6Seg}){0,4}:${v4Str}|(:${v6Seg}){1,6}|:)|` +\n `(?::((?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:))` +\n ')(%[0-9a-zA-Z-.:]{1,})?$'\n)\n\nexport function isIPv6(s: string) {\n return IPv6Reg.test(s)\n}\n"],"names":["isIPv6","v4Seg","v4Str","v6Seg","IPv6Reg","RegExp","s","test"],"mappings":"AAAA,kJAAkJ;AAClJ,0BAA0B;AAC1B,sDAAsD;AACtD,EAAE;AACF,0EAA0E;AAC1E,gEAAgE;AAChE,sEAAsE;AACtE,sEAAsE;AACtE,4EAA4E;AAC5E,qEAAqE;AACrE,wBAAwB;AACxB,EAAE;AACF,0EAA0E;AAC1E,yDAAyD;AACzD,EAAE;AACF,0EAA0E;AAC1E,6DAA6D;AAC7D,4EAA4E;AAC5E,2EAA2E;AAC3E,wEAAwE;AACxE,4EAA4E;AAC5E,yCAAyC;;;;;+BAkBzBA;;;eAAAA;;;AAhBhB,MAAMC,QAAQ;AACd,MAAMC,QAAQ,CAAC,CAAC,EAAED,MAAM,OAAO,EAAEA,OAAO;AACxC,MAAME,QAAQ;AACd,MAAMC,UAAU,IAAIC,OAClB,OACE,CAAC,GAAG,EAAEF,MAAM,QAAQ,EAAEA,MAAM,IAAI,CAAC,GACjC,CAAC,GAAG,EAAEA,MAAM,QAAQ,EAAED,MAAM,EAAE,EAAEC,MAAM,IAAI,CAAC,GAC3C,CAAC,GAAG,EAAEA,MAAM,SAAS,EAAED,MAAM,GAAG,EAAEC,MAAM,UAAU,CAAC,GACnD,CAAC,GAAG,EAAEA,MAAM,UAAU,EAAEA,MAAM,OAAO,EAAED,MAAM,GAAG,EAAEC,MAAM,UAAU,CAAC,GACnE,CAAC,GAAG,EAAEA,MAAM,UAAU,EAAEA,MAAM,OAAO,EAAED,MAAM,GAAG,EAAEC,MAAM,UAAU,CAAC,GACnE,CAAC,GAAG,EAAEA,MAAM,UAAU,EAAEA,MAAM,OAAO,EAAED,MAAM,GAAG,EAAEC,MAAM,UAAU,CAAC,GACnE,CAAC,GAAG,EAAEA,MAAM,UAAU,EAAEA,MAAM,OAAO,EAAED,MAAM,GAAG,EAAEC,MAAM,UAAU,CAAC,GACnE,CAAC,SAAS,EAAEA,MAAM,OAAO,EAAED,MAAM,KAAK,EAAEC,MAAM,UAAU,CAAC,GACzD;AAGG,SAASH,OAAOM,CAAS;IAC9B,OAAOF,QAAQG,IAAI,CAACD;AACtB","ignoreList":[0]}

View File

@@ -0,0 +1,13 @@
export type LazyResult<TValue> = PromiseLike<TValue> & {
value?: TValue;
};
export type ResolvedLazyResult<TValue> = PromiseLike<TValue> & {
value: TValue;
};
/**
* Calls the given function only when the returned promise-like object is
* awaited. Afterwards, it provides the resolved value synchronously as `value`
* property.
*/
export declare function createLazyResult<TValue>(fn: () => Promise<TValue> | TValue): LazyResult<TValue>;
export declare function isResolvedLazyResult<TValue>(result: LazyResult<TValue>): result is ResolvedLazyResult<TValue>;

View File

@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
createLazyResult: null,
isResolvedLazyResult: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
createLazyResult: function() {
return createLazyResult;
},
isResolvedLazyResult: function() {
return isResolvedLazyResult;
}
});
function createLazyResult(fn) {
let pendingResult;
const result = {
then (onfulfilled, onrejected) {
if (!pendingResult) {
pendingResult = Promise.resolve(fn());
}
pendingResult.then((value)=>{
result.value = value;
}).catch(()=>{
// The externally awaited result will be rejected via `onrejected`. We
// don't need to handle it here. But we do want to avoid an unhandled
// rejection.
});
return pendingResult.then(onfulfilled, onrejected);
}
};
return result;
}
function isResolvedLazyResult(result) {
return result.hasOwnProperty('value');
}
//# sourceMappingURL=lazy-result.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/lazy-result.ts"],"sourcesContent":["export type LazyResult<TValue> = PromiseLike<TValue> & { value?: TValue }\nexport type ResolvedLazyResult<TValue> = PromiseLike<TValue> & { value: TValue }\n\n/**\n * Calls the given function only when the returned promise-like object is\n * awaited. Afterwards, it provides the resolved value synchronously as `value`\n * property.\n */\nexport function createLazyResult<TValue>(\n fn: () => Promise<TValue> | TValue\n): LazyResult<TValue> {\n let pendingResult: Promise<TValue> | undefined\n\n const result: LazyResult<TValue> = {\n then(onfulfilled, onrejected) {\n if (!pendingResult) {\n pendingResult = Promise.resolve(fn())\n }\n\n pendingResult\n .then((value) => {\n result.value = value\n })\n .catch(() => {\n // The externally awaited result will be rejected via `onrejected`. We\n // don't need to handle it here. But we do want to avoid an unhandled\n // rejection.\n })\n\n return pendingResult.then(onfulfilled, onrejected)\n },\n }\n\n return result\n}\n\nexport function isResolvedLazyResult<TValue>(\n result: LazyResult<TValue>\n): result is ResolvedLazyResult<TValue> {\n return result.hasOwnProperty('value')\n}\n"],"names":["createLazyResult","isResolvedLazyResult","fn","pendingResult","result","then","onfulfilled","onrejected","Promise","resolve","value","catch","hasOwnProperty"],"mappings":";;;;;;;;;;;;;;;IAQgBA,gBAAgB;eAAhBA;;IA4BAC,oBAAoB;eAApBA;;;AA5BT,SAASD,iBACdE,EAAkC;IAElC,IAAIC;IAEJ,MAAMC,SAA6B;QACjCC,MAAKC,WAAW,EAAEC,UAAU;YAC1B,IAAI,CAACJ,eAAe;gBAClBA,gBAAgBK,QAAQC,OAAO,CAACP;YAClC;YAEAC,cACGE,IAAI,CAAC,CAACK;gBACLN,OAAOM,KAAK,GAAGA;YACjB,GACCC,KAAK,CAAC;YACL,sEAAsE;YACtE,qEAAqE;YACrE,aAAa;YACf;YAEF,OAAOR,cAAcE,IAAI,CAACC,aAAaC;QACzC;IACF;IAEA,OAAOH;AACT;AAEO,SAASH,qBACdG,MAA0B;IAE1B,OAAOA,OAAOQ,cAAc,CAAC;AAC/B","ignoreList":[0]}

View File

@@ -0,0 +1,95 @@
/**
* LRU (Least Recently Used) Cache implementation using a doubly-linked list
* and hash map for O(1) operations.
*
* Algorithm:
* - Uses a doubly-linked list to maintain access order (most recent at head)
* - Hash map provides O(1) key-to-node lookup
* - Sentinel head/tail nodes simplify edge case handling
* - Size-based eviction supports custom size calculation functions
*
* Data Structure Layout:
* HEAD <-> [most recent] <-> ... <-> [least recent] <-> TAIL
*
* Operations:
* - get(): Move accessed node to head (mark as most recent)
* - set(): Add new node at head, evict from tail if over capacity
* - Eviction: Remove least recent node (tail.prev) when size exceeds limit
*/
export declare class LRUCache<T> {
private readonly cache;
private readonly head;
private readonly tail;
private totalSize;
private readonly maxSize;
private readonly calculateSize;
constructor(maxSize: number, calculateSize?: (value: T) => number);
/**
* Adds a node immediately after the head (marks as most recently used).
* Used when inserting new items or when an item is accessed.
* PRECONDITION: node must be disconnected (prev/next should be null)
*/
private addToHead;
/**
* Removes a node from its current position in the doubly-linked list.
* Updates the prev/next pointers of adjacent nodes to maintain list integrity.
* PRECONDITION: node must be connected (prev/next are non-null)
*/
private removeNode;
/**
* Moves an existing node to the head position (marks as most recently used).
* This is the core LRU operation - accessed items become most recent.
*/
private moveToHead;
/**
* Removes and returns the least recently used node (the one before tail).
* This is called during eviction when the cache exceeds capacity.
* PRECONDITION: cache is not empty (ensured by caller)
*/
private removeTail;
/**
* Sets a key-value pair in the cache.
* If the key exists, updates the value and moves to head.
* If new, adds at head and evicts from tail if necessary.
*
* Time Complexity:
* - O(1) for uniform item sizes
* - O(k) where k is the number of items evicted (can be O(N) for variable sizes)
*/
set(key: string, value: T): void;
/**
* Checks if a key exists in the cache.
* This is a pure query operation - does NOT update LRU order.
*
* Time Complexity: O(1)
*/
has(key: string): boolean;
/**
* Retrieves a value by key and marks it as most recently used.
* Moving to head maintains the LRU property for future evictions.
*
* Time Complexity: O(1)
*/
get(key: string): T | undefined;
/**
* Returns an iterator over the cache entries. The order is outputted in the
* order of most recently used to least recently used.
*/
[Symbol.iterator](): IterableIterator<[string, T]>;
/**
* Removes a specific key from the cache.
* Updates both the hash map and doubly-linked list.
*
* Time Complexity: O(1)
*/
remove(key: string): void;
/**
* Returns the number of items in the cache.
*/
get size(): number;
/**
* Returns the current total size of all cached items.
* This uses the custom size calculation if provided.
*/
get currentSize(): number;
}

View File

@@ -0,0 +1,177 @@
/**
* Node in the doubly-linked list used for LRU tracking.
* Each node represents a cache entry with bidirectional pointers.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "LRUCache", {
enumerable: true,
get: function() {
return LRUCache;
}
});
class LRUNode {
constructor(key, data, size){
this.prev = null;
this.next = null;
this.key = key;
this.data = data;
this.size = size;
}
}
/**
* Sentinel node used for head/tail boundaries.
* These nodes don't contain actual cache data but simplify list operations.
*/ class SentinelNode {
constructor(){
this.prev = null;
this.next = null;
}
}
class LRUCache {
constructor(maxSize, calculateSize){
this.cache = new Map();
this.totalSize = 0;
this.maxSize = maxSize;
this.calculateSize = calculateSize;
// Create sentinel nodes to simplify doubly-linked list operations
// HEAD <-> TAIL (empty list)
this.head = new SentinelNode();
this.tail = new SentinelNode();
this.head.next = this.tail;
this.tail.prev = this.head;
}
/**
* Adds a node immediately after the head (marks as most recently used).
* Used when inserting new items or when an item is accessed.
* PRECONDITION: node must be disconnected (prev/next should be null)
*/ addToHead(node) {
node.prev = this.head;
node.next = this.head.next;
// head.next is always non-null (points to tail or another node)
this.head.next.prev = node;
this.head.next = node;
}
/**
* Removes a node from its current position in the doubly-linked list.
* Updates the prev/next pointers of adjacent nodes to maintain list integrity.
* PRECONDITION: node must be connected (prev/next are non-null)
*/ removeNode(node) {
// Connected nodes always have non-null prev/next
node.prev.next = node.next;
node.next.prev = node.prev;
}
/**
* Moves an existing node to the head position (marks as most recently used).
* This is the core LRU operation - accessed items become most recent.
*/ moveToHead(node) {
this.removeNode(node);
this.addToHead(node);
}
/**
* Removes and returns the least recently used node (the one before tail).
* This is called during eviction when the cache exceeds capacity.
* PRECONDITION: cache is not empty (ensured by caller)
*/ removeTail() {
const lastNode = this.tail.prev;
// tail.prev is always non-null and always LRUNode when cache is not empty
this.removeNode(lastNode);
return lastNode;
}
/**
* Sets a key-value pair in the cache.
* If the key exists, updates the value and moves to head.
* If new, adds at head and evicts from tail if necessary.
*
* Time Complexity:
* - O(1) for uniform item sizes
* - O(k) where k is the number of items evicted (can be O(N) for variable sizes)
*/ set(key, value) {
const size = (this.calculateSize == null ? void 0 : this.calculateSize.call(this, value)) ?? 1;
if (size > this.maxSize) {
console.warn('Single item size exceeds maxSize');
return;
}
const existing = this.cache.get(key);
if (existing) {
// Update existing node: adjust size and move to head (most recent)
existing.data = value;
this.totalSize = this.totalSize - existing.size + size;
existing.size = size;
this.moveToHead(existing);
} else {
// Add new node at head (most recent position)
const newNode = new LRUNode(key, value, size);
this.cache.set(key, newNode);
this.addToHead(newNode);
this.totalSize += size;
}
// Evict least recently used items until under capacity
while(this.totalSize > this.maxSize && this.cache.size > 0){
const tail = this.removeTail();
this.cache.delete(tail.key);
this.totalSize -= tail.size;
}
}
/**
* Checks if a key exists in the cache.
* This is a pure query operation - does NOT update LRU order.
*
* Time Complexity: O(1)
*/ has(key) {
return this.cache.has(key);
}
/**
* Retrieves a value by key and marks it as most recently used.
* Moving to head maintains the LRU property for future evictions.
*
* Time Complexity: O(1)
*/ get(key) {
const node = this.cache.get(key);
if (!node) return undefined;
// Mark as most recently used by moving to head
this.moveToHead(node);
return node.data;
}
/**
* Returns an iterator over the cache entries. The order is outputted in the
* order of most recently used to least recently used.
*/ *[Symbol.iterator]() {
let current = this.head.next;
while(current && current !== this.tail){
// Between head and tail, current is always LRUNode
const node = current;
yield [
node.key,
node.data
];
current = current.next;
}
}
/**
* Removes a specific key from the cache.
* Updates both the hash map and doubly-linked list.
*
* Time Complexity: O(1)
*/ remove(key) {
const node = this.cache.get(key);
if (!node) return;
this.removeNode(node);
this.cache.delete(key);
this.totalSize -= node.size;
}
/**
* Returns the number of items in the cache.
*/ get size() {
return this.cache.size;
}
/**
* Returns the current total size of all cached items.
* This uses the custom size calculation if provided.
*/ get currentSize() {
return this.totalSize;
}
}
//# sourceMappingURL=lru-cache.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export declare function matchNextDataPathname(pathname: string | null | undefined): false | Record<string, any>;

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "matchNextDataPathname", {
enumerable: true,
get: function() {
return matchNextDataPathname;
}
});
const _pathmatch = require("../../shared/lib/router/utils/path-match");
const matcher = (0, _pathmatch.getPathMatch)('/_next/data/:path*');
function matchNextDataPathname(pathname) {
if (typeof pathname !== 'string') return false;
return matcher(pathname);
}
//# sourceMappingURL=match-next-data-pathname.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/lib/match-next-data-pathname.ts"],"sourcesContent":["import { getPathMatch } from '../../shared/lib/router/utils/path-match'\n\nconst matcher = getPathMatch('/_next/data/:path*')\n\nexport function matchNextDataPathname(pathname: string | null | undefined) {\n if (typeof pathname !== 'string') return false\n\n return matcher(pathname)\n}\n"],"names":["matchNextDataPathname","matcher","getPathMatch","pathname"],"mappings":";;;;+BAIgBA;;;eAAAA;;;2BAJa;AAE7B,MAAMC,UAAUC,IAAAA,uBAAY,EAAC;AAEtB,SAASF,sBAAsBG,QAAmC;IACvE,IAAI,OAAOA,aAAa,UAAU,OAAO;IAEzC,OAAOF,QAAQE;AACjB","ignoreList":[0]}

View File

@@ -0,0 +1,110 @@
import type { ServerResponse, OutgoingHttpHeaders, OutgoingHttpHeader, IncomingMessage, IncomingHttpHeaders } from 'http';
import type { Socket } from 'net';
import Stream from 'stream';
interface MockedRequestOptions {
url: string;
headers: IncomingHttpHeaders;
method: string;
readable?: Stream.Readable;
socket?: Socket | null;
}
export declare class MockedRequest extends Stream.Readable implements IncomingMessage {
url: string;
readonly statusCode?: number | undefined;
readonly statusMessage?: string | undefined;
readonly headers: IncomingHttpHeaders;
readonly method: string;
readonly httpVersion = "1.0";
readonly httpVersionMajor = 1;
readonly httpVersionMinor = 0;
private bodyReadable?;
socket: Socket;
constructor({ url, headers, method, socket, readable, }: MockedRequestOptions);
get headersDistinct(): NodeJS.Dict<string[]>;
_read(size: number): void;
/**
* The `connection` property is just an alias for the `socket` property.
*
* @deprecated — since v13.0.0 - Use socket instead.
*/
get connection(): Socket;
get aborted(): boolean;
get complete(): boolean;
get trailers(): NodeJS.Dict<string>;
get trailersDistinct(): NodeJS.Dict<string[]>;
get rawTrailers(): string[];
get rawHeaders(): string[];
setTimeout(): this;
}
export interface MockedResponseOptions {
statusCode?: number;
socket?: Socket | null;
headers?: OutgoingHttpHeaders;
resWriter?: (chunk: Uint8Array | Buffer | string) => boolean;
}
export declare class MockedResponse extends Stream.Writable implements ServerResponse {
statusCode: number;
statusMessage: string;
finished: boolean;
headersSent: boolean;
readonly socket: Socket | null;
private resWriter;
readonly headPromise: Promise<void>;
private headPromiseResolve?;
constructor(res?: MockedResponseOptions);
appendHeader(name: string, value: string | string[]): this;
/**
* The `connection` property is just an alias for the `socket` property.
*
* @deprecated — since v13.0.0 - Use socket instead.
*/
get connection(): Socket | null;
write(chunk: Uint8Array | Buffer | string): boolean;
end(): this;
/**
* This method is a no-op because the `MockedResponse` instance is not
* actually connected to a socket. This method is not specified on the
* interface type for `ServerResponse` but is called by Node.js.
*
* @see https://github.com/nodejs/node/pull/7949
*/
_implicitHeader(): void;
_write(chunk: Buffer | string, _encoding: string, callback: () => void): void;
writeHead(statusCode: number, statusMessage?: string | undefined, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[] | undefined): this;
writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[] | undefined): this;
hasHeader(name: string): boolean;
getHeader(name: string): string | undefined;
getHeaders(): OutgoingHttpHeaders;
getHeaderNames(): string[];
setHeader(name: string, value: OutgoingHttpHeader): this;
removeHeader(name: string): void;
flushHeaders(): void;
get strictContentLength(): boolean;
writeEarlyHints(): void;
get req(): IncomingMessage;
assignSocket(): void;
detachSocket(): void;
writeContinue(): void;
writeProcessing(): void;
get upgrading(): boolean;
get chunkedEncoding(): boolean;
get shouldKeepAlive(): boolean;
get useChunkedEncodingByDefault(): boolean;
get sendDate(): boolean;
setTimeout(): this;
addTrailers(): void;
setHeaders(): this;
}
interface RequestResponseMockerOptions {
url: string;
headers?: IncomingHttpHeaders;
method?: string;
bodyReadable?: Stream.Readable;
resWriter?: (chunk: Uint8Array | Buffer | string) => boolean;
socket?: Socket | null;
}
export declare function createRequestResponseMocks({ url, headers, method, bodyReadable, resWriter, socket, }: RequestResponseMockerOptions): {
req: MockedRequest;
res: MockedResponse;
};
export {};

View File

@@ -0,0 +1,416 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
MockedRequest: null,
MockedResponse: null,
createRequestResponseMocks: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
MockedRequest: function() {
return MockedRequest;
},
MockedResponse: function() {
return MockedResponse;
},
createRequestResponseMocks: function() {
return createRequestResponseMocks;
}
});
const _stream = /*#__PURE__*/ _interop_require_default(require("stream"));
const _utils = require("../web/utils");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
class MockedRequest extends _stream.default.Readable {
constructor({ url, headers, method, socket = null, readable }){
super(), // This is hardcoded for now, but can be updated to be configurable if needed.
this.httpVersion = '1.0', this.httpVersionMajor = 1, this.httpVersionMinor = 0, // If we don't actually have a socket, we'll just use a mock one that
// always returns false for the `encrypted` property and undefined for the
// `remoteAddress` property.
this.socket = new Proxy({}, {
get: (_target, prop)=>{
if (prop !== 'encrypted' && prop !== 'remoteAddress') {
throw Object.defineProperty(new Error('Method not implemented'), "__NEXT_ERROR_CODE", {
value: "E52",
enumerable: false,
configurable: true
});
}
if (prop === 'remoteAddress') return undefined;
// For this mock request, always ensure we just respond with the encrypted
// set to false to ensure there's no odd leakages.
return false;
}
});
this.url = url;
this.headers = headers;
this.method = method;
if (readable) {
this.bodyReadable = readable;
this.bodyReadable.on('end', ()=>this.emit('end'));
this.bodyReadable.on('close', ()=>this.emit('close'));
}
if (socket) {
this.socket = socket;
}
}
get headersDistinct() {
const headers = {};
for (const [key, value] of Object.entries(this.headers)){
if (!value) continue;
headers[key] = Array.isArray(value) ? value : [
value
];
}
return headers;
}
_read(size) {
if (this.bodyReadable) {
return this.bodyReadable._read(size);
} else {
this.emit('end');
this.emit('close');
}
}
/**
* The `connection` property is just an alias for the `socket` property.
*
* @deprecated — since v13.0.0 - Use socket instead.
*/ get connection() {
return this.socket;
}
// The following methods are not implemented as they are not used in the
// Next.js codebase.
get aborted() {
throw Object.defineProperty(new Error('Method not implemented'), "__NEXT_ERROR_CODE", {
value: "E52",
enumerable: false,
configurable: true
});
}
get complete() {
throw Object.defineProperty(new Error('Method not implemented'), "__NEXT_ERROR_CODE", {
value: "E52",
enumerable: false,
configurable: true
});
}
get trailers() {
throw Object.defineProperty(new Error('Method not implemented'), "__NEXT_ERROR_CODE", {
value: "E52",
enumerable: false,
configurable: true
});
}
get trailersDistinct() {
throw Object.defineProperty(new Error('Method not implemented'), "__NEXT_ERROR_CODE", {
value: "E52",
enumerable: false,
configurable: true
});
}
get rawTrailers() {
throw Object.defineProperty(new Error('Method not implemented'), "__NEXT_ERROR_CODE", {
value: "E52",
enumerable: false,
configurable: true
});
}
get rawHeaders() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
setTimeout() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
}
class MockedResponse extends _stream.default.Writable {
constructor(res = {}){
super(), this.statusMessage = '', this.finished = false, this.headersSent = false, /**
* A list of buffers that have been written to the response.
*
* @internal - used internally by Next.js
*/ this.buffers = [];
this.statusCode = res.statusCode ?? 200;
this.socket = res.socket ?? null;
this.headers = res.headers ? (0, _utils.fromNodeOutgoingHttpHeaders)(res.headers) : new Headers();
this.headPromise = new Promise((resolve)=>{
this.headPromiseResolve = resolve;
});
// Attach listeners for the `finish`, `end`, and `error` events to the
// `MockedResponse` instance.
this.hasStreamed = new Promise((resolve, reject)=>{
this.on('finish', ()=>resolve(true));
this.on('end', ()=>resolve(true));
this.on('error', (err)=>reject(err));
}).then((val)=>{
this.headPromiseResolve == null ? void 0 : this.headPromiseResolve.call(this);
return val;
});
if (res.resWriter) {
this.resWriter = res.resWriter;
}
}
appendHeader(name, value) {
const values = Array.isArray(value) ? value : [
value
];
for (const v of values){
this.headers.append(name, v);
}
return this;
}
/**
* Returns true if the response has been sent, false otherwise.
*
* @internal - used internally by Next.js
*/ get isSent() {
return this.finished || this.headersSent;
}
/**
* The `connection` property is just an alias for the `socket` property.
*
* @deprecated — since v13.0.0 - Use socket instead.
*/ get connection() {
return this.socket;
}
write(chunk) {
if (this.resWriter) {
return this.resWriter(chunk);
}
this.buffers.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
return true;
}
end() {
this.finished = true;
return super.end(...arguments);
}
/**
* This method is a no-op because the `MockedResponse` instance is not
* actually connected to a socket. This method is not specified on the
* interface type for `ServerResponse` but is called by Node.js.
*
* @see https://github.com/nodejs/node/pull/7949
*/ _implicitHeader() {}
_write(chunk, _encoding, callback) {
this.write(chunk);
// According to Node.js documentation, the callback MUST be invoked to
// signal that the write completed successfully. If this callback is not
// invoked, the 'finish' event will not be emitted.
//
// https://nodejs.org/docs/latest-v16.x/api/stream.html#writable_writechunk-encoding-callback
callback();
}
writeHead(statusCode, statusMessage, headers) {
if (!headers && typeof statusMessage !== 'string') {
headers = statusMessage;
} else if (typeof statusMessage === 'string' && statusMessage.length > 0) {
this.statusMessage = statusMessage;
}
if (headers) {
// When headers have been set with response.setHeader(), they will be
// merged with any headers passed to response.writeHead(), with the
// headers passed to response.writeHead() given precedence.
//
// https://nodejs.org/api/http.html#responsewriteheadstatuscode-statusmessage-headers
//
// For this reason, we need to only call `set` to ensure that this will
// overwrite any existing headers.
if (Array.isArray(headers)) {
// headers may be an Array where the keys and values are in the same list.
// It is not a list of tuples. So, the even-numbered offsets are key
// values, and the odd-numbered offsets are the associated values. The
// array is in the same format as request.rawHeaders.
for(let i = 0; i < headers.length; i += 2){
// The header key is always a string according to the spec.
this.setHeader(headers[i], headers[i + 1]);
}
} else {
for (const [key, value] of Object.entries(headers)){
// Skip undefined values
if (typeof value === 'undefined') continue;
this.setHeader(key, value);
}
}
}
this.statusCode = statusCode;
this.headersSent = true;
this.headPromiseResolve == null ? void 0 : this.headPromiseResolve.call(this);
return this;
}
hasHeader(name) {
return this.headers.has(name);
}
getHeader(name) {
return this.headers.get(name) ?? undefined;
}
getHeaders() {
return (0, _utils.toNodeOutgoingHttpHeaders)(this.headers);
}
getHeaderNames() {
return Array.from(this.headers.keys());
}
setHeader(name, value) {
if (Array.isArray(value)) {
// Because `set` here should override any existing values, we need to
// delete the existing values before setting the new ones via `append`.
this.headers.delete(name);
for (const v of value){
this.headers.append(name, v);
}
} else if (typeof value === 'number') {
this.headers.set(name, value.toString());
} else {
this.headers.set(name, value);
}
return this;
}
removeHeader(name) {
this.headers.delete(name);
}
flushHeaders() {
// This is a no-op because we don't actually have a socket to flush the
// headers to.
}
// The following methods are not implemented as they are not used in the
// Next.js codebase.
get strictContentLength() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
writeEarlyHints() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
get req() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
assignSocket() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
detachSocket() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
writeContinue() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
writeProcessing() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
get upgrading() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
get chunkedEncoding() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
get shouldKeepAlive() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
get useChunkedEncodingByDefault() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
get sendDate() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
setTimeout() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
addTrailers() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
setHeaders() {
throw Object.defineProperty(new Error('Method not implemented.'), "__NEXT_ERROR_CODE", {
value: "E41",
enumerable: false,
configurable: true
});
}
}
function createRequestResponseMocks({ url, headers = {}, method = 'GET', bodyReadable, resWriter, socket = null }) {
return {
req: new MockedRequest({
url,
headers,
method,
socket,
readable: bodyReadable
}),
res: new MockedResponse({
socket,
resWriter
})
};
}
//# sourceMappingURL=mock-request.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
/**
* Loads a given module for a given ID.
*/
export interface ModuleLoader {
load<M = any>(id: string): Promise<M>;
}

View File

@@ -0,0 +1,8 @@
/**
* Loads a given module for a given ID.
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=module-loader.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/module-loader/module-loader.ts"],"sourcesContent":["/**\n * Loads a given module for a given ID.\n */\nexport interface ModuleLoader {\n load<M = any>(id: string): Promise<M>\n}\n"],"names":[],"mappings":"AAAA;;CAEC","ignoreList":[0]}

View File

@@ -0,0 +1,7 @@
import type { ModuleLoader } from './module-loader';
/**
* Loads a module using `await require(id)`.
*/
export declare class NodeModuleLoader implements ModuleLoader {
load<M>(id: string): Promise<M>;
}

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "NodeModuleLoader", {
enumerable: true,
get: function() {
return NodeModuleLoader;
}
});
class NodeModuleLoader {
async load(id) {
if (process.env.NEXT_RUNTIME !== 'edge') {
// Need to `await` to cover the case that route is marked ESM modules by ESM escalation.
return await (process.env.NEXT_MINIMAL ? __non_webpack_require__(id) : require(id));
}
throw Object.defineProperty(new Error('NodeModuleLoader is not supported in edge runtime.'), "__NEXT_ERROR_CODE", {
value: "E25",
enumerable: false,
configurable: true
});
}
}
//# sourceMappingURL=node-module-loader.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/module-loader/node-module-loader.ts"],"sourcesContent":["import type { ModuleLoader } from './module-loader'\n\n/**\n * Loads a module using `await require(id)`.\n */\nexport class NodeModuleLoader implements ModuleLoader {\n public async load<M>(id: string): Promise<M> {\n if (process.env.NEXT_RUNTIME !== 'edge') {\n // Need to `await` to cover the case that route is marked ESM modules by ESM escalation.\n return await (process.env.NEXT_MINIMAL\n ? // @ts-ignore\n __non_webpack_require__(id)\n : require(id))\n }\n\n throw new Error('NodeModuleLoader is not supported in edge runtime.')\n }\n}\n"],"names":["NodeModuleLoader","load","id","process","env","NEXT_RUNTIME","NEXT_MINIMAL","__non_webpack_require__","require","Error"],"mappings":";;;;+BAKaA;;;eAAAA;;;AAAN,MAAMA;IACX,MAAaC,KAAQC,EAAU,EAAc;QAC3C,IAAIC,QAAQC,GAAG,CAACC,YAAY,KAAK,QAAQ;YACvC,wFAAwF;YACxF,OAAO,MAAOF,CAAAA,QAAQC,GAAG,CAACE,YAAY,GAElCC,wBAAwBL,MACxBM,QAAQN,GAAE;QAChB;QAEA,MAAM,qBAA+D,CAA/D,IAAIO,MAAM,uDAAV,qBAAA;mBAAA;wBAAA;0BAAA;QAA8D;IACtE;AACF","ignoreList":[0]}

View File

@@ -0,0 +1,8 @@
import type { RouteModule } from '../../route-modules/route-module';
import type { ModuleLoader } from './module-loader';
export interface AppLoaderModule<M extends RouteModule = RouteModule> {
routeModule: M;
}
export declare class RouteModuleLoader {
static load<M extends RouteModule>(id: string, loader?: ModuleLoader): Promise<M>;
}

Some files were not shown because too many files have changed in this diff Show More