main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
/// <reference types="node" />
import type { AsyncLocalStorage } from 'async_hooks';
/**
* Implementations provide a wrapping function that will provide the storage to
* async calls derived from the provided callback function.
*/
export interface AsyncStorageWrapper<Store extends {}, Context extends {}> {
/**
* Wraps the callback with the underlying storage.
*
* @param storage underlying storage object
* @param context context used to create the storage object
* @param callback function to call within the scope of the storage
* @returns the result of the callback
*/
wrap<Result>(storage: AsyncLocalStorage<Store>, context: Context, callback: (store: Store) => Result): Result;
}

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=async-storage-wrapper.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,13 @@
/// <reference types="node" />
import type { IncomingMessage } from 'http';
import type { ReadonlyRequestCookies } from '../web/spec-extension/adapters/request-cookies';
import type { ResponseCookies } from '../web/spec-extension/cookies';
import type { BaseNextRequest } from '../base-http';
import type { NextRequest } from '../web/spec-extension/request';
import { __ApiPreviewProps } from '../api-utils';
export declare class DraftModeProvider {
readonly isEnabled: boolean;
constructor(previewProps: __ApiPreviewProps | undefined, req: IncomingMessage | BaseNextRequest<unknown> | NextRequest, cookies: ReadonlyRequestCookies, mutableCookies: ResponseCookies);
enable(): void;
disable(): void;
}

View File

@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DraftModeProvider", {
enumerable: true,
get: function() {
return DraftModeProvider;
}
});
const _apiutils = require("../api-utils");
class DraftModeProvider {
constructor(previewProps, req, cookies, mutableCookies){
var _cookies_get;
// The logic for draftMode() is very similar to tryGetPreviewData()
// but Draft Mode does not have any data associated with it.
const isOnDemandRevalidate = previewProps && (0, _apiutils.checkIsOnDemandRevalidate)(req, previewProps).isOnDemandRevalidate;
const cookieValue = (_cookies_get = cookies.get(_apiutils.COOKIE_NAME_PRERENDER_BYPASS)) == null ? void 0 : _cookies_get.value;
this.isEnabled = Boolean(!isOnDemandRevalidate && cookieValue && previewProps && cookieValue === previewProps.previewModeId);
this._previewModeId = previewProps == null ? void 0 : previewProps.previewModeId;
this._mutableCookies = mutableCookies;
}
enable() {
if (!this._previewModeId) {
throw new Error("Invariant: previewProps missing previewModeId this should never happen");
}
this._mutableCookies.set({
name: _apiutils.COOKIE_NAME_PRERENDER_BYPASS,
value: this._previewModeId,
httpOnly: true,
sameSite: process.env.NODE_ENV !== "development" ? "none" : "lax",
secure: process.env.NODE_ENV !== "development",
path: "/"
});
}
disable() {
// To delete a cookie, set `expires` to a date in the past:
// https://tools.ietf.org/html/rfc6265#section-4.1.1
// `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.
this._mutableCookies.set({
name: _apiutils.COOKIE_NAME_PRERENDER_BYPASS,
value: "",
httpOnly: true,
sameSite: process.env.NODE_ENV !== "development" ? "none" : "lax",
secure: process.env.NODE_ENV !== "development",
path: "/",
expires: new Date(0)
});
}
}
//# sourceMappingURL=draft-mode-provider.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/async-storage/draft-mode-provider.ts"],"names":["DraftModeProvider","constructor","previewProps","req","cookies","mutableCookies","isOnDemandRevalidate","checkIsOnDemandRevalidate","cookieValue","get","COOKIE_NAME_PRERENDER_BYPASS","value","isEnabled","Boolean","previewModeId","_previewModeId","_mutableCookies","enable","Error","set","name","httpOnly","sameSite","process","env","NODE_ENV","secure","path","disable","expires","Date"],"mappings":";;;;+BAYaA;;;eAAAA;;;0BAFN;AAEA,MAAMA;IAaXC,YACEC,YAA2C,EAC3CC,GAA6D,EAC7DC,OAA+B,EAC/BC,cAA+B,CAC/B;YAOoBD;QANpB,mEAAmE;QACnE,4DAA4D;QAC5D,MAAME,uBACJJ,gBACAK,IAAAA,mCAAyB,EAACJ,KAAKD,cAAcI,oBAAoB;QAEnE,MAAME,eAAcJ,eAAAA,QAAQK,GAAG,CAACC,sCAA4B,sBAAxCN,aAA2CO,KAAK;QAEpE,IAAI,CAACC,SAAS,GAAGC,QACf,CAACP,wBACCE,eACAN,gBACAM,gBAAgBN,aAAaY,aAAa;QAG9C,IAAI,CAACC,cAAc,GAAGb,gCAAAA,aAAcY,aAAa;QACjD,IAAI,CAACE,eAAe,GAAGX;IACzB;IAEAY,SAAS;QACP,IAAI,CAAC,IAAI,CAACF,cAAc,EAAE;YACxB,MAAM,IAAIG,MACR;QAEJ;QAEA,IAAI,CAACF,eAAe,CAACG,GAAG,CAAC;YACvBC,MAAMV,sCAA4B;YAClCC,OAAO,IAAI,CAACI,cAAc;YAC1BM,UAAU;YACVC,UAAUC,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAAgB,SAAS;YAC5DC,QAAQH,QAAQC,GAAG,CAACC,QAAQ,KAAK;YACjCE,MAAM;QACR;IACF;IAEAC,UAAU;QACR,2DAA2D;QAC3D,oDAAoD;QACpD,wEAAwE;QACxE,IAAI,CAACZ,eAAe,CAACG,GAAG,CAAC;YACvBC,MAAMV,sCAA4B;YAClCC,OAAO;YACPU,UAAU;YACVC,UAAUC,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAAgB,SAAS;YAC5DC,QAAQH,QAAQC,GAAG,CAACC,QAAQ,KAAK;YACjCE,MAAM;YACNE,SAAS,IAAIC,KAAK;QACpB;IACF;AACF"}

View File

@@ -0,0 +1,13 @@
/// <reference types="node" />
import type { BaseNextRequest, BaseNextResponse } from '../base-http';
import type { IncomingMessage, ServerResponse } from 'http';
import type { RequestStore } from '../../client/components/request-async-storage.external';
import type { RenderOpts } from '../app-render/types';
import type { AsyncStorageWrapper } from './async-storage-wrapper';
import type { NextRequest } from '../web/spec-extension/request';
export type RequestContext = {
req: IncomingMessage | BaseNextRequest | NextRequest;
res?: ServerResponse | BaseNextResponse;
renderOpts?: RenderOpts;
};
export declare const RequestAsyncStorageWrapper: AsyncStorageWrapper<RequestStore, RequestContext>;

View File

@@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "RequestAsyncStorageWrapper", {
enumerable: true,
get: function() {
return RequestAsyncStorageWrapper;
}
});
const _approuterheaders = require("../../client/components/app-router-headers");
const _headers = require("../web/spec-extension/adapters/headers");
const _requestcookies = require("../web/spec-extension/adapters/request-cookies");
const _cookies = require("../web/spec-extension/cookies");
const _draftmodeprovider = require("./draft-mode-provider");
function getHeaders(headers) {
const cleaned = _headers.HeadersAdapter.from(headers);
for (const param of _approuterheaders.FLIGHT_PARAMETERS){
cleaned.delete(param.toString().toLowerCase());
}
return _headers.HeadersAdapter.seal(cleaned);
}
function getCookies(headers) {
const cookies = new _cookies.RequestCookies(_headers.HeadersAdapter.from(headers));
return _requestcookies.RequestCookiesAdapter.seal(cookies);
}
function getMutableCookies(headers, onUpdateCookies) {
const cookies = new _cookies.RequestCookies(_headers.HeadersAdapter.from(headers));
return _requestcookies.MutableRequestCookiesAdapter.wrap(cookies, onUpdateCookies);
}
const RequestAsyncStorageWrapper = {
/**
* Wrap the callback with the given store so it can access the underlying
* store using hooks.
*
* @param storage underlying storage object returned by the module
* @param context context to seed the store
* @param callback function to call within the scope of the context
* @returns the result returned by the callback
*/ wrap (storage, { req, res, renderOpts }, callback) {
let previewProps = undefined;
if (renderOpts && "previewProps" in renderOpts) {
// TODO: investigate why previewProps isn't on RenderOpts
previewProps = renderOpts.previewProps;
}
function defaultOnUpdateCookies(cookies) {
if (res) {
res.setHeader("Set-Cookie", cookies);
}
}
const cache = {};
const store = {
get headers () {
if (!cache.headers) {
// Seal the headers object that'll freeze out any methods that could
// mutate the underlying data.
cache.headers = getHeaders(req.headers);
}
return cache.headers;
},
get cookies () {
if (!cache.cookies) {
// Seal the cookies object that'll freeze out any methods that could
// mutate the underlying data.
cache.cookies = getCookies(req.headers);
}
return cache.cookies;
},
get mutableCookies () {
if (!cache.mutableCookies) {
cache.mutableCookies = getMutableCookies(req.headers, (renderOpts == null ? void 0 : renderOpts.onUpdateCookies) || (res ? defaultOnUpdateCookies : undefined));
}
return cache.mutableCookies;
},
get draftMode () {
if (!cache.draftMode) {
cache.draftMode = new _draftmodeprovider.DraftModeProvider(previewProps, req, this.cookies, this.mutableCookies);
}
return cache.draftMode;
}
};
return storage.run(store, callback, store);
}
};
//# sourceMappingURL=request-async-storage-wrapper.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/async-storage/request-async-storage-wrapper.ts"],"names":["RequestAsyncStorageWrapper","getHeaders","headers","cleaned","HeadersAdapter","from","param","FLIGHT_PARAMETERS","delete","toString","toLowerCase","seal","getCookies","cookies","RequestCookies","RequestCookiesAdapter","getMutableCookies","onUpdateCookies","MutableRequestCookiesAdapter","wrap","storage","req","res","renderOpts","callback","previewProps","undefined","defaultOnUpdateCookies","setHeader","cache","store","mutableCookies","draftMode","DraftModeProvider","run"],"mappings":";;;;+BAoDaA;;;eAAAA;;;kCA5CqB;yBAI3B;gCAKA;yBACyC;mCAEd;AAElC,SAASC,WAAWC,OAAsC;IACxD,MAAMC,UAAUC,uBAAc,CAACC,IAAI,CAACH;IACpC,KAAK,MAAMI,SAASC,mCAAiB,CAAE;QACrCJ,QAAQK,MAAM,CAACF,MAAMG,QAAQ,GAAGC,WAAW;IAC7C;IAEA,OAAON,uBAAc,CAACO,IAAI,CAACR;AAC7B;AAEA,SAASS,WACPV,OAAsC;IAEtC,MAAMW,UAAU,IAAIC,uBAAc,CAACV,uBAAc,CAACC,IAAI,CAACH;IACvD,OAAOa,qCAAqB,CAACJ,IAAI,CAACE;AACpC;AAEA,SAASG,kBACPd,OAAsC,EACtCe,eAA6C;IAE7C,MAAMJ,UAAU,IAAIC,uBAAc,CAACV,uBAAc,CAACC,IAAI,CAACH;IACvD,OAAOgB,4CAA4B,CAACC,IAAI,CAACN,SAASI;AACpD;AAQO,MAAMjB,6BAGT;IACF;;;;;;;;GAQC,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19 @@
import type { AsyncStorageWrapper } from './async-storage-wrapper';
import type { StaticGenerationStore } from '../../client/components/static-generation-async-storage.external';
import type { IncrementalCache } from '../lib/incremental-cache';
export type StaticGenerationContext = {
urlPathname: string;
renderOpts: {
originalPathname?: string;
incrementalCache?: IncrementalCache;
supportsDynamicHTML: boolean;
isRevalidate?: boolean;
isOnDemandRevalidate?: boolean;
isBot?: boolean;
nextExport?: boolean;
fetchCache?: StaticGenerationStore['fetchCache'];
isDraftMode?: boolean;
isServerAction?: boolean;
};
};
export declare const StaticGenerationAsyncStorageWrapper: AsyncStorageWrapper<StaticGenerationStore, StaticGenerationContext>;

View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "StaticGenerationAsyncStorageWrapper", {
enumerable: true,
get: function() {
return StaticGenerationAsyncStorageWrapper;
}
});
const StaticGenerationAsyncStorageWrapper = {
wrap (storage, { urlPathname, renderOpts }, callback) {
/**
* Rules of Static & Dynamic HTML:
*
* 1.) We must generate static HTML unless the caller explicitly opts
* in to dynamic HTML support.
*
* 2.) If dynamic HTML support is requested, we must honor that request
* or throw an error. It is the sole responsibility of the caller to
* ensure they aren't e.g. requesting dynamic HTML for an AMP page.
*
* 3.) If the request is in draft mode, we must generate dynamic HTML.
*
* 4.) If the request is a server action, we must generate dynamic HTML.
*
* These rules help ensure that other existing features like request caching,
* coalescing, and ISR continue working as intended.
*/ const isStaticGeneration = !renderOpts.supportsDynamicHTML && !renderOpts.isDraftMode && !renderOpts.isServerAction;
const store = {
isStaticGeneration,
urlPathname,
pagePath: renderOpts.originalPathname,
incrementalCache: // we fallback to a global incremental cache for edge-runtime locally
// so that it can access the fs cache without mocks
renderOpts.incrementalCache || globalThis.__incrementalCache,
isRevalidate: renderOpts.isRevalidate,
isPrerendering: renderOpts.nextExport,
fetchCache: renderOpts.fetchCache,
isOnDemandRevalidate: renderOpts.isOnDemandRevalidate,
isDraftMode: renderOpts.isDraftMode
};
// TODO: remove this when we resolve accessing the store outside the execution context
renderOpts.store = store;
return storage.run(store, callback, store);
}
};
//# sourceMappingURL=static-generation-async-storage-wrapper.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/async-storage/static-generation-async-storage-wrapper.ts"],"names":["StaticGenerationAsyncStorageWrapper","wrap","storage","urlPathname","renderOpts","callback","isStaticGeneration","supportsDynamicHTML","isDraftMode","isServerAction","store","pagePath","originalPathname","incrementalCache","globalThis","__incrementalCache","isRevalidate","isPrerendering","nextExport","fetchCache","isOnDemandRevalidate","run"],"mappings":";;;;+BA+BaA;;;eAAAA;;;AAAN,MAAMA,sCAGT;IACFC,MACEC,OAAiD,EACjD,EAAEC,WAAW,EAAEC,UAAU,EAA2B,EACpDC,QAAkD;QAElD;;;;;;;;;;;;;;;;KAgBC,GACD,MAAMC,qBACJ,CAACF,WAAWG,mBAAmB,IAC/B,CAACH,WAAWI,WAAW,IACvB,CAACJ,WAAWK,cAAc;QAE5B,MAAMC,QAA+B;YACnCJ;YACAH;YACAQ,UAAUP,WAAWQ,gBAAgB;YACrCC,kBACE,qEAAqE;YACrE,mDAAmD;YACnDT,WAAWS,gBAAgB,IAAI,AAACC,WAAmBC,kBAAkB;YACvEC,cAAcZ,WAAWY,YAAY;YACrCC,gBAAgBb,WAAWc,UAAU;YACrCC,YAAYf,WAAWe,UAAU;YACjCC,sBAAsBhB,WAAWgB,oBAAoB;YAErDZ,aAAaJ,WAAWI,WAAW;QACrC;QAEA,sFAAsF;QACtFJ,WAAWM,KAAK,GAAGA;QAEnB,OAAOR,QAAQmB,GAAG,CAACX,OAAOL,UAAUK;IACtC;AACF"}