Initial boiler plate project

This commit is contained in:
2024-09-24 03:52:46 +00:00
parent 6120b2d6c3
commit 154b93e267
10034 changed files with 2079352 additions and 2 deletions

View File

@ -0,0 +1,6 @@
/**
* Implementations provide a wrapping function that will provide the storage to
* async calls derived from the provided callback function.
*/ 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":"AAEA;;;CAGC,GACD,WAcC"}

View File

@ -0,0 +1,43 @@
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 || // In dev mode, the cookie can be actual hash value preview id but the preview props can still be `development-id`.
process.env.NODE_ENV !== "production" && previewProps.previewModeId === "development-id"));
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","process","env","NODE_ENV","_previewModeId","_mutableCookies","enable","Error","set","name","httpOnly","sameSite","secure","path","disable","expires","Date"],"mappings":"AAMA,SACEA,4BAA4B,EAC5BC,yBAAyB,QACpB,eAAc;AAGrB,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,gBACCK,CAAAA,gBAAgBL,aAAaU,aAAa,IACzC,mHAAmH;QAClHC,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBACxBb,aAAaU,aAAa,KAAK,gBAAgB;QAGvD,IAAI,CAACI,cAAc,GAAGd,gCAAAA,aAAcU,aAAa;QACjD,IAAI,CAACK,eAAe,GAAGZ;IACzB;IAEAa,SAAS;QACP,IAAI,CAAC,IAAI,CAACF,cAAc,EAAE;YACxB,MAAM,IAAIG,MACR;QAEJ;QAEA,IAAI,CAACF,eAAe,CAACG,GAAG,CAAC;YACvBC,MAAMvB;YACNW,OAAO,IAAI,CAACO,cAAc;YAC1BM,UAAU;YACVC,UAAUV,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAAgB,SAAS;YAC5DS,QAAQX,QAAQC,GAAG,CAACC,QAAQ,KAAK;YACjCU,MAAM;QACR;IACF;IAEAC,UAAU;QACR,2DAA2D;QAC3D,oDAAoD;QACpD,wEAAwE;QACxE,IAAI,CAACT,eAAe,CAACG,GAAG,CAAC;YACvBC,MAAMvB;YACNW,OAAO;YACPa,UAAU;YACVC,UAAUV,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAAgB,SAAS;YAC5DS,QAAQX,QAAQC,GAAG,CAACC,QAAQ,KAAK;YACjCU,MAAM;YACNE,SAAS,IAAIC,KAAK;QACpB;IACF;AACF"}

View File

@ -0,0 +1,99 @@
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 { ResponseCookies, RequestCookies } from "../web/spec-extension/cookies";
import { DraftModeProvider } from "./draft-mode-provider";
import { splitCookiesString } from "../web/utils";
function getHeaders(headers) {
const cleaned = HeadersAdapter.from(headers);
for (const param of FLIGHT_PARAMETERS){
cleaned.delete(param.toString().toLowerCase());
}
return HeadersAdapter.seal(cleaned);
}
function getMutableCookies(headers, onUpdateCookies) {
const cookies = new RequestCookies(HeadersAdapter.from(headers));
return MutableRequestCookiesAdapter.wrap(cookies, onUpdateCookies);
}
/**
* If middleware set cookies in this request (indicated by `x-middleware-set-cookie`),
* then merge those into the existing cookie object, so that when `cookies()` is accessed
* it's able to read the newly set cookies.
*/ function mergeMiddlewareCookies(req, existingCookies) {
if ("x-middleware-set-cookie" in req.headers && typeof req.headers["x-middleware-set-cookie"] === "string") {
const setCookieValue = req.headers["x-middleware-set-cookie"];
const responseHeaders = new Headers();
for (const cookie of splitCookiesString(setCookieValue)){
responseHeaders.append("set-cookie", cookie);
}
const responseCookies = new ResponseCookies(responseHeaders);
// Transfer cookies from ResponseCookies to RequestCookies
for (const cookie of responseCookies.getAll()){
existingCookies.set(cookie);
}
}
}
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) {
// if middleware is setting cookie(s), then include those in
// the initial cached cookies so they can be read in render
const requestCookies = new RequestCookies(HeadersAdapter.from(req.headers));
mergeMiddlewareCookies(req, requestCookies);
// Seal the cookies object that'll freeze out any methods that could
// mutate the underlying data.
cache.cookies = RequestCookiesAdapter.seal(requestCookies);
}
return cache.cookies;
},
get mutableCookies () {
if (!cache.mutableCookies) {
const mutableCookies = getMutableCookies(req.headers, (renderOpts == null ? void 0 : renderOpts.onUpdateCookies) || (res ? defaultOnUpdateCookies : undefined));
mergeMiddlewareCookies(req, mutableCookies);
cache.mutableCookies = mutableCookies;
}
return cache.mutableCookies;
},
get draftMode () {
if (!cache.draftMode) {
cache.draftMode = new DraftModeProvider(previewProps, req, this.cookies, this.mutableCookies);
}
return cache.draftMode;
},
reactLoadableManifest: (renderOpts == null ? void 0 : renderOpts.reactLoadableManifest) || {},
assetPrefix: (renderOpts == null ? void 0 : renderOpts.assetPrefix) || ""
};
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","ResponseCookies","RequestCookies","DraftModeProvider","splitCookiesString","getHeaders","headers","cleaned","from","param","delete","toString","toLowerCase","seal","getMutableCookies","onUpdateCookies","cookies","wrap","mergeMiddlewareCookies","req","existingCookies","setCookieValue","responseHeaders","Headers","cookie","append","responseCookies","getAll","set","RequestAsyncStorageWrapper","storage","res","renderOpts","callback","previewProps","undefined","defaultOnUpdateCookies","setHeader","cache","store","requestCookies","mutableCookies","draftMode","reactLoadableManifest","assetPrefix","run"],"mappings":"AASA,SAASA,iBAAiB,QAAQ,6CAA4C;AAC9E,SACEC,cAAc,QAET,yCAAwC;AAC/C,SACEC,4BAA4B,EAC5BC,qBAAqB,QAEhB,iDAAgD;AACvD,SAASC,eAAe,EAAEC,cAAc,QAAQ,gCAA+B;AAC/E,SAASC,iBAAiB,QAAQ,wBAAuB;AACzD,SAASC,kBAAkB,QAAQ,eAAc;AAEjD,SAASC,WAAWC,OAAsC;IACxD,MAAMC,UAAUT,eAAeU,IAAI,CAACF;IACpC,KAAK,MAAMG,SAASZ,kBAAmB;QACrCU,QAAQG,MAAM,CAACD,MAAME,QAAQ,GAAGC,WAAW;IAC7C;IAEA,OAAOd,eAAee,IAAI,CAACN;AAC7B;AAEA,SAASO,kBACPR,OAAsC,EACtCS,eAA6C;IAE7C,MAAMC,UAAU,IAAId,eAAeJ,eAAeU,IAAI,CAACF;IACvD,OAAOP,6BAA6BkB,IAAI,CAACD,SAASD;AACpD;AAQA;;;;CAIC,GACD,SAASG,uBACPC,GAA0B,EAC1BC,eAAiD;IAEjD,IACE,6BAA6BD,IAAIb,OAAO,IACxC,OAAOa,IAAIb,OAAO,CAAC,0BAA0B,KAAK,UAClD;QACA,MAAMe,iBAAiBF,IAAIb,OAAO,CAAC,0BAA0B;QAC7D,MAAMgB,kBAAkB,IAAIC;QAE5B,KAAK,MAAMC,UAAUpB,mBAAmBiB,gBAAiB;YACvDC,gBAAgBG,MAAM,CAAC,cAAcD;QACvC;QAEA,MAAME,kBAAkB,IAAIzB,gBAAgBqB;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BAE5BH,MAAMG,cAAc,GAAGA;gBACzB;gBACA,OAAOH,MAAMG,cAAc;YAC7B;YACA,IAAIC,aAAY;gBACd,IAAI,CAACJ,MAAMI,SAAS,EAAE;oBACpBJ,MAAMI,SAAS,GAAG,IAAIvC,kBACpB+B,cACAf,KACA,IAAI,CAACH,OAAO,EACZ,IAAI,CAACyB,cAAc;gBAEvB;gBAEA,OAAOH,MAAMI,SAAS;YACxB;YACAC,uBAAuBX,CAAAA,8BAAAA,WAAYW,qBAAqB,KAAI,CAAC;YAC7DC,aAAaZ,CAAAA,8BAAAA,WAAYY,WAAW,KAAI;QAC1C;QAEA,OAAOd,QAAQe,GAAG,CAACN,OAAON,UAAUM;IACtC;AACF,EAAC"}

View File

@ -0,0 +1,43 @@
import { createPrerenderState } from "../../server/app-render/dynamic-rendering";
export const StaticGenerationAsyncStorageWrapper = {
wrap (storage, { urlPathname, renderOpts, requestEndedState }, 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.supportsDynamicResponse && !renderOpts.isDraftMode && !renderOpts.isServerAction;
const prerenderState = isStaticGeneration && renderOpts.experimental.ppr ? createPrerenderState(renderOpts.isDebugPPRSkeleton) : null;
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,
prerenderState,
requestEndedState
};
// 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":["createPrerenderState","StaticGenerationAsyncStorageWrapper","wrap","storage","urlPathname","renderOpts","requestEndedState","callback","isStaticGeneration","supportsDynamicResponse","isDraftMode","isServerAction","prerenderState","experimental","ppr","isDebugPPRSkeleton","store","pagePath","originalPathname","incrementalCache","globalThis","__incrementalCache","isRevalidate","isPrerendering","nextExport","fetchCache","isOnDemandRevalidate","run"],"mappings":"AAMA,SAASA,oBAAoB,QAAQ,4CAA2C;AAyChF,OAAO,MAAMC,sCAGT;IACFC,MACEC,OAAiD,EACjD,EAAEC,WAAW,EAAEC,UAAU,EAAEC,iBAAiB,EAA2B,EACvEC,QAAkD;QAElD;;;;;;;;;;;;;;;;KAgBC,GACD,MAAMC,qBACJ,CAACH,WAAWI,uBAAuB,IACnC,CAACJ,WAAWK,WAAW,IACvB,CAACL,WAAWM,cAAc;QAE5B,MAAMC,iBACJJ,sBAAsBH,WAAWQ,YAAY,CAACC,GAAG,GAC7Cd,qBAAqBK,WAAWU,kBAAkB,IAClD;QAEN,MAAMC,QAA+B;YACnCR;YACAJ;YACAa,UAAUZ,WAAWa,gBAAgB;YACrCC,kBACE,qEAAqE;YACrE,mDAAmD;YACnDd,WAAWc,gBAAgB,IAAI,AAACC,WAAmBC,kBAAkB;YACvEC,cAAcjB,WAAWiB,YAAY;YACrCC,gBAAgBlB,WAAWmB,UAAU;YACrCC,YAAYpB,WAAWoB,UAAU;YACjCC,sBAAsBrB,WAAWqB,oBAAoB;YAErDhB,aAAaL,WAAWK,WAAW;YAEnCE;YACAN;QACF;QAEA,sFAAsF;QACtFD,WAAWW,KAAK,GAAGA;QAEnB,OAAOb,QAAQwB,GAAG,CAACX,OAAOT,UAAUS;IACtC;AACF,EAAC"}