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,3 @@
export { };
//# sourceMappingURL=async-storage-wrapper.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/server/async-storage/async-storage-wrapper.ts"],"names":[],"mappings":"AAAA,WAoBC"}

View File

@@ -0,0 +1,42 @@
import { COOKIE_NAME_PRERENDER_BYPASS, checkIsOnDemandRevalidate } from "../api-utils";
export 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 && checkIsOnDemandRevalidate(req, previewProps).isOnDemandRevalidate;
const cookieValue = (_cookies_get = cookies.get(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: 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: 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":["COOKIE_NAME_PRERENDER_BYPASS","checkIsOnDemandRevalidate","DraftModeProvider","constructor","previewProps","req","cookies","mutableCookies","isOnDemandRevalidate","cookieValue","get","value","isEnabled","Boolean","previewModeId","_previewModeId","_mutableCookies","enable","Error","set","name","httpOnly","sameSite","process","env","NODE_ENV","secure","path","disable","expires","Date"],"mappings":"AAMA,SACEA,4BAA4B,EAC5BC,yBAAyB,QAEpB,eAAc;AAErB,OAAO,MAAMC;IAaXC,YACEC,YAA2C,EAC3CC,GAA6D,EAC7DC,OAA+B,EAC/BC,cAA+B,CAC/B;YAOoBD;QANpB,mEAAmE;QACnE,4DAA4D;QAC5D,MAAME,uBACJJ,gBACAH,0BAA0BI,KAAKD,cAAcI,oBAAoB;QAEnE,MAAMC,eAAcH,eAAAA,QAAQI,GAAG,CAACV,kDAAZM,aAA2CK,KAAK;QAEpE,IAAI,CAACC,SAAS,GAAGC,QACf,CAACL,wBACCC,eACAL,gBACAK,gBAAgBL,aAAaU,aAAa;QAG9C,IAAI,CAACC,cAAc,GAAGX,gCAAAA,aAAcU,aAAa;QACjD,IAAI,CAACE,eAAe,GAAGT;IACzB;IAEAU,SAAS;QACP,IAAI,CAAC,IAAI,CAACF,cAAc,EAAE;YACxB,MAAM,IAAIG,MACR;QAEJ;QAEA,IAAI,CAACF,eAAe,CAACG,GAAG,CAAC;YACvBC,MAAMpB;YACNW,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,MAAMpB;YACNW,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,76 @@
import { FLIGHT_PARAMETERS } from "../../client/components/app-router-headers";
import { HeadersAdapter } from "../web/spec-extension/adapters/headers";
import { MutableRequestCookiesAdapter, RequestCookiesAdapter } from "../web/spec-extension/adapters/request-cookies";
import { RequestCookies } from "../web/spec-extension/cookies";
import { DraftModeProvider } from "./draft-mode-provider";
function getHeaders(headers) {
const cleaned = HeadersAdapter.from(headers);
for (const param of FLIGHT_PARAMETERS){
cleaned.delete(param.toString().toLowerCase());
}
return HeadersAdapter.seal(cleaned);
}
function getCookies(headers) {
const cookies = new RequestCookies(HeadersAdapter.from(headers));
return RequestCookiesAdapter.seal(cookies);
}
function getMutableCookies(headers, onUpdateCookies) {
const cookies = new RequestCookies(HeadersAdapter.from(headers));
return MutableRequestCookiesAdapter.wrap(cookies, onUpdateCookies);
}
export 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(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":["FLIGHT_PARAMETERS","HeadersAdapter","MutableRequestCookiesAdapter","RequestCookiesAdapter","RequestCookies","DraftModeProvider","getHeaders","headers","cleaned","from","param","delete","toString","toLowerCase","seal","getCookies","cookies","getMutableCookies","onUpdateCookies","wrap","RequestAsyncStorageWrapper","storage","req","res","renderOpts","callback","previewProps","undefined","defaultOnUpdateCookies","setHeader","cache","store","mutableCookies","draftMode","run"],"mappings":"AAQA,SAASA,iBAAiB,QAAQ,6CAA4C;AAC9E,SACEC,cAAc,QAET,yCAAwC;AAC/C,SACEC,4BAA4B,EAC5BC,qBAAqB,QAEhB,iDAAgD;AACvD,SAASC,cAAc,QAAyB,gCAA+B;AAE/E,SAASC,iBAAiB,QAAQ,wBAAuB;AAEzD,SAASC,WAAWC,OAAsC;IACxD,MAAMC,UAAUP,eAAeQ,IAAI,CAACF;IACpC,KAAK,MAAMG,SAASV,kBAAmB;QACrCQ,QAAQG,MAAM,CAACD,MAAME,QAAQ,GAAGC,WAAW;IAC7C;IAEA,OAAOZ,eAAea,IAAI,CAACN;AAC7B;AAEA,SAASO,WACPR,OAAsC;IAEtC,MAAMS,UAAU,IAAIZ,eAAeH,eAAeQ,IAAI,CAACF;IACvD,OAAOJ,sBAAsBW,IAAI,CAACE;AACpC;AAEA,SAASC,kBACPV,OAAsC,EACtCW,eAA6C;IAE7C,MAAMF,UAAU,IAAIZ,eAAeH,eAAeQ,IAAI,CAACF;IACvD,OAAOL,6BAA6BiB,IAAI,CAACH,SAASE;AACpD;AAQ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tC;AACF,EAAC"}

View File

@@ -0,0 +1,39 @@
export 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":"AA+BA,OAAO,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,EAAC"}