added fonts
This commit is contained in:
1 parent
4134e3a234
commit
142d2986b6
9079 files changed
+1498421
-2
No files matched your search
+12
@@ -0,0 +1,12 @@
|
||||
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 type { __ApiPreviewProps } from '../api-utils';
|
||||
export declare class DraftModeProvider {
|
||||
constructor(previewProps: __ApiPreviewProps | undefined, req: IncomingMessage | BaseNextRequest<unknown> | NextRequest, cookies: ReadonlyRequestCookies, mutableCookies: ResponseCookies);
|
||||
get isEnabled(): boolean;
|
||||
enable(): void;
|
||||
disable(): void;
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
"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 || // 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;
|
||||
}
|
||||
get isEnabled() {
|
||||
return this._isEnabled;
|
||||
}
|
||||
enable() {
|
||||
if (!this._previewModeId) {
|
||||
throw Object.defineProperty(new Error('Invariant: previewProps missing previewModeId this should never happen'), "__NEXT_ERROR_CODE", {
|
||||
value: "E93",
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
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: '/'
|
||||
});
|
||||
this._isEnabled = true;
|
||||
}
|
||||
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)
|
||||
});
|
||||
this._isEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=draft-mode-provider.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/server/async-storage/draft-mode-provider.ts"],"sourcesContent":["import type { IncomingMessage } from 'http'\nimport type { ReadonlyRequestCookies } from '../web/spec-extension/adapters/request-cookies'\nimport type { ResponseCookies } from '../web/spec-extension/cookies'\nimport type { BaseNextRequest } from '../base-http'\nimport type { NextRequest } from '../web/spec-extension/request'\n\nimport {\n COOKIE_NAME_PRERENDER_BYPASS,\n checkIsOnDemandRevalidate,\n} from '../api-utils'\nimport type { __ApiPreviewProps } from '../api-utils'\n\nexport class DraftModeProvider {\n /**\n * @internal - this declaration is stripped via `tsc --stripInternal`\n */\n private _isEnabled: boolean\n\n /**\n * @internal - this declaration is stripped via `tsc --stripInternal`\n */\n private readonly _previewModeId: string | undefined\n\n /**\n * @internal - this declaration is stripped via `tsc --stripInternal`\n */\n private readonly _mutableCookies: ResponseCookies\n\n constructor(\n previewProps: __ApiPreviewProps | undefined,\n req: IncomingMessage | BaseNextRequest<unknown> | NextRequest,\n cookies: ReadonlyRequestCookies,\n mutableCookies: ResponseCookies\n ) {\n // The logic for draftMode() is very similar to tryGetPreviewData()\n // but Draft Mode does not have any data associated with it.\n const isOnDemandRevalidate =\n previewProps &&\n checkIsOnDemandRevalidate(req, previewProps).isOnDemandRevalidate\n\n const cookieValue = cookies.get(COOKIE_NAME_PRERENDER_BYPASS)?.value\n\n this._isEnabled = Boolean(\n !isOnDemandRevalidate &&\n cookieValue &&\n previewProps &&\n (cookieValue === previewProps.previewModeId ||\n // In dev mode, the cookie can be actual hash value preview id but the preview props can still be `development-id`.\n (process.env.NODE_ENV !== 'production' &&\n previewProps.previewModeId === 'development-id'))\n )\n\n this._previewModeId = previewProps?.previewModeId\n this._mutableCookies = mutableCookies\n }\n\n get isEnabled() {\n return this._isEnabled\n }\n\n enable() {\n if (!this._previewModeId) {\n throw new Error(\n 'Invariant: previewProps missing previewModeId this should never happen'\n )\n }\n\n this._mutableCookies.set({\n name: COOKIE_NAME_PRERENDER_BYPASS,\n value: this._previewModeId,\n httpOnly: true,\n sameSite: process.env.NODE_ENV !== 'development' ? 'none' : 'lax',\n secure: process.env.NODE_ENV !== 'development',\n path: '/',\n })\n\n this._isEnabled = true\n }\n\n disable() {\n // To delete a cookie, set `expires` to a date in the past:\n // https://tools.ietf.org/html/rfc6265#section-4.1.1\n // `Max-Age: 0` is not valid, thus ignored, and the cookie is persisted.\n this._mutableCookies.set({\n name: COOKIE_NAME_PRERENDER_BYPASS,\n value: '',\n httpOnly: true,\n sameSite: process.env.NODE_ENV !== 'development' ? 'none' : 'lax',\n secure: process.env.NODE_ENV !== 'development',\n path: '/',\n expires: new Date(0),\n })\n\n this._isEnabled = false\n }\n}\n"],"names":["DraftModeProvider","constructor","previewProps","req","cookies","mutableCookies","isOnDemandRevalidate","checkIsOnDemandRevalidate","cookieValue","get","COOKIE_NAME_PRERENDER_BYPASS","value","_isEnabled","Boolean","previewModeId","process","env","NODE_ENV","_previewModeId","_mutableCookies","isEnabled","enable","Error","set","name","httpOnly","sameSite","secure","path","disable","expires","Date"],"mappings":";;;;+BAYaA;;;eAAAA;;;0BAHN;AAGA,MAAMA;IAgBXC,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,UAAU,GAAGC,QAChB,CAACP,wBACCE,eACAN,gBACCM,CAAAA,gBAAgBN,aAAaY,aAAa,IACzC,mHAAmH;QAClHC,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBACxBf,aAAaY,aAAa,KAAK,gBAAgB;QAGvD,IAAI,CAACI,cAAc,GAAGhB,gCAAAA,aAAcY,aAAa;QACjD,IAAI,CAACK,eAAe,GAAGd;IACzB;IAEA,IAAIe,YAAY;QACd,OAAO,IAAI,CAACR,UAAU;IACxB;IAEAS,SAAS;QACP,IAAI,CAAC,IAAI,CAACH,cAAc,EAAE;YACxB,MAAM,qBAEL,CAFK,IAAII,MACR,2EADI,qBAAA;uBAAA;4BAAA;8BAAA;YAEN;QACF;QAEA,IAAI,CAACH,eAAe,CAACI,GAAG,CAAC;YACvBC,MAAMd,sCAA4B;YAClCC,OAAO,IAAI,CAACO,cAAc;YAC1BO,UAAU;YACVC,UAAUX,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAAgB,SAAS;YAC5DU,QAAQZ,QAAQC,GAAG,CAACC,QAAQ,KAAK;YACjCW,MAAM;QACR;QAEA,IAAI,CAAChB,UAAU,GAAG;IACpB;IAEAiB,UAAU;QACR,2DAA2D;QAC3D,oDAAoD;QACpD,wEAAwE;QACxE,IAAI,CAACV,eAAe,CAACI,GAAG,CAAC;YACvBC,MAAMd,sCAA4B;YAClCC,OAAO;YACPc,UAAU;YACVC,UAAUX,QAAQC,GAAG,CAACC,QAAQ,KAAK,gBAAgB,SAAS;YAC5DU,QAAQZ,QAAQC,GAAG,CAACC,QAAQ,KAAK;YACjCW,MAAM;YACNE,SAAS,IAAIC,KAAK;QACpB;QAEA,IAAI,CAACnB,UAAU,GAAG;IACpB;AACF"}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import type { BaseNextRequest, BaseNextResponse } from '../base-http';
|
||||
import type { RequestStore } from '../app-render/work-unit-async-storage.external';
|
||||
import type { RenderOpts } from '../app-render/types';
|
||||
import type { NextRequest } from '../web/spec-extension/request';
|
||||
import type { __ApiPreviewProps } from '../api-utils';
|
||||
import type { ServerComponentsHmrCache } from '../response-cache';
|
||||
import type { RenderResumeDataCache } from '../resume-data-cache/resume-data-cache';
|
||||
import type { Params } from '../request/params';
|
||||
import type { ImplicitTags } from '../lib/implicit-tags';
|
||||
export type WrapperRenderOpts = Partial<Pick<RenderOpts, 'onUpdateCookies'>> & {
|
||||
previewProps?: __ApiPreviewProps;
|
||||
};
|
||||
type RequestContext = RequestResponsePair & {
|
||||
/**
|
||||
* The URL of the request. This only specifies the pathname and the search
|
||||
* part of the URL. This is only undefined when generating static paths (ie,
|
||||
* there is no request in progress, nor do we know one).
|
||||
*/
|
||||
url: {
|
||||
/**
|
||||
* The pathname of the requested URL.
|
||||
*/
|
||||
pathname: string;
|
||||
/**
|
||||
* The search part of the requested URL. If the request did not provide a
|
||||
* search part, this will be an empty string.
|
||||
*/
|
||||
search?: string;
|
||||
};
|
||||
phase: RequestStore['phase'];
|
||||
renderOpts?: WrapperRenderOpts;
|
||||
isHmrRefresh?: boolean;
|
||||
serverComponentsHmrCache?: ServerComponentsHmrCache;
|
||||
implicitTags: ImplicitTags;
|
||||
};
|
||||
type RequestResponsePair = {
|
||||
req: BaseNextRequest;
|
||||
res: BaseNextResponse;
|
||||
} | {
|
||||
req: NextRequest;
|
||||
res: undefined;
|
||||
};
|
||||
export declare function createRequestStoreForRender(req: RequestContext['req'], res: RequestContext['res'], url: RequestContext['url'], rootParams: Params, implicitTags: RequestContext['implicitTags'], onUpdateCookies: RenderOpts['onUpdateCookies'], previewProps: WrapperRenderOpts['previewProps'], isHmrRefresh: RequestContext['isHmrRefresh'], serverComponentsHmrCache: RequestContext['serverComponentsHmrCache'], renderResumeDataCache: RenderResumeDataCache | undefined): RequestStore;
|
||||
export declare function createRequestStoreForAPI(req: RequestContext['req'], url: RequestContext['url'], implicitTags: RequestContext['implicitTags'], onUpdateCookies: RenderOpts['onUpdateCookies'], previewProps: WrapperRenderOpts['previewProps']): RequestStore;
|
||||
export declare function synchronizeMutableCookies(store: RequestStore): void;
|
||||
export {};
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
createRequestStoreForAPI: null,
|
||||
createRequestStoreForRender: null,
|
||||
synchronizeMutableCookies: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
createRequestStoreForAPI: function() {
|
||||
return createRequestStoreForAPI;
|
||||
},
|
||||
createRequestStoreForRender: function() {
|
||||
return createRequestStoreForRender;
|
||||
},
|
||||
synchronizeMutableCookies: function() {
|
||||
return synchronizeMutableCookies;
|
||||
}
|
||||
});
|
||||
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");
|
||||
const _utils = require("../web/utils");
|
||||
function getHeaders(headers) {
|
||||
const cleaned = _headers.HeadersAdapter.from(headers);
|
||||
for (const header of _approuterheaders.FLIGHT_HEADERS){
|
||||
cleaned.delete(header.toLowerCase());
|
||||
}
|
||||
return _headers.HeadersAdapter.seal(cleaned);
|
||||
}
|
||||
function getMutableCookies(headers, onUpdateCookies) {
|
||||
const cookies = new _cookies.RequestCookies(_headers.HeadersAdapter.from(headers));
|
||||
return _requestcookies.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 (0, _utils.splitCookiesString)(setCookieValue)){
|
||||
responseHeaders.append('set-cookie', cookie);
|
||||
}
|
||||
const responseCookies = new _cookies.ResponseCookies(responseHeaders);
|
||||
// Transfer cookies from ResponseCookies to RequestCookies
|
||||
for (const cookie of responseCookies.getAll()){
|
||||
existingCookies.set(cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
function createRequestStoreForRender(req, res, url, rootParams, implicitTags, onUpdateCookies, previewProps, isHmrRefresh, serverComponentsHmrCache, renderResumeDataCache) {
|
||||
return createRequestStoreImpl(// Pages start in render phase by default
|
||||
'render', req, res, url, rootParams, implicitTags, onUpdateCookies, renderResumeDataCache, previewProps, isHmrRefresh, serverComponentsHmrCache);
|
||||
}
|
||||
function createRequestStoreForAPI(req, url, implicitTags, onUpdateCookies, previewProps) {
|
||||
return createRequestStoreImpl(// API routes start in action phase by default
|
||||
'action', req, undefined, url, {}, implicitTags, onUpdateCookies, undefined, previewProps, false, undefined);
|
||||
}
|
||||
function createRequestStoreImpl(phase, req, res, url, rootParams, implicitTags, onUpdateCookies, renderResumeDataCache, previewProps, isHmrRefresh, serverComponentsHmrCache) {
|
||||
function defaultOnUpdateCookies(cookies) {
|
||||
if (res) {
|
||||
res.setHeader('Set-Cookie', cookies);
|
||||
}
|
||||
}
|
||||
const cache = {};
|
||||
return {
|
||||
type: 'request',
|
||||
phase,
|
||||
implicitTags,
|
||||
// Rather than just using the whole `url` here, we pull the parts we want
|
||||
// to ensure we don't use parts of the URL that we shouldn't. This also
|
||||
// lets us avoid requiring an empty string for `search` in the type.
|
||||
url: {
|
||||
pathname: url.pathname,
|
||||
search: url.search ?? ''
|
||||
},
|
||||
rootParams,
|
||||
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 _cookies.RequestCookies(_headers.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 = _requestcookies.RequestCookiesAdapter.seal(requestCookies);
|
||||
}
|
||||
return cache.cookies;
|
||||
},
|
||||
set cookies (value){
|
||||
cache.cookies = value;
|
||||
},
|
||||
get mutableCookies () {
|
||||
if (!cache.mutableCookies) {
|
||||
const mutableCookies = getMutableCookies(req.headers, onUpdateCookies || (res ? defaultOnUpdateCookies : undefined));
|
||||
mergeMiddlewareCookies(req, mutableCookies);
|
||||
cache.mutableCookies = mutableCookies;
|
||||
}
|
||||
return cache.mutableCookies;
|
||||
},
|
||||
get userspaceMutableCookies () {
|
||||
if (!cache.userspaceMutableCookies) {
|
||||
const userspaceMutableCookies = (0, _requestcookies.wrapWithMutableAccessCheck)(this.mutableCookies);
|
||||
cache.userspaceMutableCookies = userspaceMutableCookies;
|
||||
}
|
||||
return cache.userspaceMutableCookies;
|
||||
},
|
||||
get draftMode () {
|
||||
if (!cache.draftMode) {
|
||||
cache.draftMode = new _draftmodeprovider.DraftModeProvider(previewProps, req, this.cookies, this.mutableCookies);
|
||||
}
|
||||
return cache.draftMode;
|
||||
},
|
||||
renderResumeDataCache: renderResumeDataCache ?? null,
|
||||
isHmrRefresh,
|
||||
serverComponentsHmrCache: serverComponentsHmrCache || globalThis.__serverComponentsHmrCache
|
||||
};
|
||||
}
|
||||
function synchronizeMutableCookies(store) {
|
||||
// TODO: does this need to update headers as well?
|
||||
store.cookies = _requestcookies.RequestCookiesAdapter.seal((0, _requestcookies.responseCookiesToRequestCookies)(store.mutableCookies));
|
||||
}
|
||||
|
||||
//# sourceMappingURL=request-store.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/server/async-storage/request-store.ts"],"sourcesContent":["import type { BaseNextRequest, BaseNextResponse } from '../base-http'\nimport type { IncomingHttpHeaders } from 'http'\nimport type { RequestStore } from '../app-render/work-unit-async-storage.external'\nimport type { RenderOpts } from '../app-render/types'\nimport type { NextRequest } from '../web/spec-extension/request'\nimport type { __ApiPreviewProps } from '../api-utils'\n\nimport { FLIGHT_HEADERS } from '../../client/components/app-router-headers'\nimport {\n HeadersAdapter,\n type ReadonlyHeaders,\n} from '../web/spec-extension/adapters/headers'\nimport {\n MutableRequestCookiesAdapter,\n RequestCookiesAdapter,\n responseCookiesToRequestCookies,\n wrapWithMutableAccessCheck,\n type ReadonlyRequestCookies,\n} from '../web/spec-extension/adapters/request-cookies'\nimport { ResponseCookies, RequestCookies } from '../web/spec-extension/cookies'\nimport { DraftModeProvider } from './draft-mode-provider'\nimport { splitCookiesString } from '../web/utils'\nimport type { ServerComponentsHmrCache } from '../response-cache'\nimport type { RenderResumeDataCache } from '../resume-data-cache/resume-data-cache'\nimport type { Params } from '../request/params'\nimport type { ImplicitTags } from '../lib/implicit-tags'\n\nfunction getHeaders(headers: Headers | IncomingHttpHeaders): ReadonlyHeaders {\n const cleaned = HeadersAdapter.from(headers)\n for (const header of FLIGHT_HEADERS) {\n cleaned.delete(header.toLowerCase())\n }\n\n return HeadersAdapter.seal(cleaned)\n}\n\nfunction getMutableCookies(\n headers: Headers | IncomingHttpHeaders,\n onUpdateCookies?: (cookies: string[]) => void\n): ResponseCookies {\n const cookies = new RequestCookies(HeadersAdapter.from(headers))\n return MutableRequestCookiesAdapter.wrap(cookies, onUpdateCookies)\n}\n\nexport type WrapperRenderOpts = Partial<Pick<RenderOpts, 'onUpdateCookies'>> & {\n previewProps?: __ApiPreviewProps\n}\n\ntype RequestContext = RequestResponsePair & {\n /**\n * The URL of the request. This only specifies the pathname and the search\n * part of the URL. This is only undefined when generating static paths (ie,\n * there is no request in progress, nor do we know one).\n */\n url: {\n /**\n * The pathname of the requested URL.\n */\n pathname: string\n\n /**\n * The search part of the requested URL. If the request did not provide a\n * search part, this will be an empty string.\n */\n search?: string\n }\n phase: RequestStore['phase']\n renderOpts?: WrapperRenderOpts\n isHmrRefresh?: boolean\n serverComponentsHmrCache?: ServerComponentsHmrCache\n implicitTags: ImplicitTags\n}\n\ntype RequestResponsePair =\n | { req: BaseNextRequest; res: BaseNextResponse } // for an app page\n | { req: NextRequest; res: undefined } // in an api route or middleware\n\n/**\n * If middleware set cookies in this request (indicated by `x-middleware-set-cookie`),\n * then merge those into the existing cookie object, so that when `cookies()` is accessed\n * it's able to read the newly set cookies.\n */\nfunction mergeMiddlewareCookies(\n req: RequestContext['req'],\n existingCookies: RequestCookies | ResponseCookies\n) {\n if (\n 'x-middleware-set-cookie' in req.headers &&\n typeof req.headers['x-middleware-set-cookie'] === 'string'\n ) {\n const setCookieValue = req.headers['x-middleware-set-cookie']\n const responseHeaders = new Headers()\n\n for (const cookie of splitCookiesString(setCookieValue)) {\n responseHeaders.append('set-cookie', cookie)\n }\n\n const responseCookies = new ResponseCookies(responseHeaders)\n\n // Transfer cookies from ResponseCookies to RequestCookies\n for (const cookie of responseCookies.getAll()) {\n existingCookies.set(cookie)\n }\n }\n}\n\nexport function createRequestStoreForRender(\n req: RequestContext['req'],\n res: RequestContext['res'],\n url: RequestContext['url'],\n rootParams: Params,\n implicitTags: RequestContext['implicitTags'],\n onUpdateCookies: RenderOpts['onUpdateCookies'],\n previewProps: WrapperRenderOpts['previewProps'],\n isHmrRefresh: RequestContext['isHmrRefresh'],\n serverComponentsHmrCache: RequestContext['serverComponentsHmrCache'],\n renderResumeDataCache: RenderResumeDataCache | undefined\n): RequestStore {\n return createRequestStoreImpl(\n // Pages start in render phase by default\n 'render',\n req,\n res,\n url,\n rootParams,\n implicitTags,\n onUpdateCookies,\n renderResumeDataCache,\n previewProps,\n isHmrRefresh,\n serverComponentsHmrCache\n )\n}\n\nexport function createRequestStoreForAPI(\n req: RequestContext['req'],\n url: RequestContext['url'],\n implicitTags: RequestContext['implicitTags'],\n onUpdateCookies: RenderOpts['onUpdateCookies'],\n previewProps: WrapperRenderOpts['previewProps']\n): RequestStore {\n return createRequestStoreImpl(\n // APILine truncated
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
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.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
export type WithStore<Store extends {}, Context extends {}> = <Result>(storage: AsyncLocalStorage<Store>, context: Context, callback: (store: Store) => Result) => Result;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
//# sourceMappingURL=with-store.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":""}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import type { WorkStore } from '../app-render/work-async-storage.external';
|
||||
import type { IncrementalCache } from '../lib/incremental-cache';
|
||||
import type { RenderOpts } from '../app-render/types';
|
||||
import type { FetchMetric } from '../base-http';
|
||||
import type { RequestLifecycleOpts } from '../base-server';
|
||||
import type { FallbackRouteParams } from '../request/fallback-params';
|
||||
import type { AppSegmentConfig } from '../../build/segment-config/app/app-segment-config';
|
||||
import type { CacheLife } from '../use-cache/cache-life';
|
||||
export type WorkStoreContext = {
|
||||
/**
|
||||
* The page that is being rendered. This relates to the path to the page file.
|
||||
*/
|
||||
page: string;
|
||||
/**
|
||||
* The route parameters that are currently unknown.
|
||||
*/
|
||||
fallbackRouteParams: FallbackRouteParams | null;
|
||||
requestEndedState?: {
|
||||
ended?: boolean;
|
||||
};
|
||||
isPrefetchRequest?: boolean;
|
||||
renderOpts: {
|
||||
cacheLifeProfiles?: {
|
||||
[profile: string]: CacheLife;
|
||||
};
|
||||
incrementalCache?: IncrementalCache;
|
||||
isOnDemandRevalidate?: boolean;
|
||||
fetchCache?: AppSegmentConfig['fetchCache'];
|
||||
isPossibleServerAction?: boolean;
|
||||
pendingWaitUntil?: Promise<any>;
|
||||
experimental: Pick<RenderOpts['experimental'], 'isRoutePPREnabled' | 'dynamicIO' | 'authInterrupts'>;
|
||||
/**
|
||||
* Fetch metrics attached in patch-fetch.ts
|
||||
**/
|
||||
fetchMetrics?: FetchMetric[];
|
||||
} & Pick<RenderOpts, 'assetPrefix' | 'supportsDynamicResponse' | 'shouldWaitOnAllReady' | 'isRevalidate' | 'nextExport' | 'isDraftMode' | 'isDebugDynamicAccesses' | 'dev'> & RequestLifecycleOpts & Partial<Pick<RenderOpts, 'reactLoadableManifest'>>;
|
||||
/**
|
||||
* The build ID of the current build.
|
||||
*/
|
||||
buildId: string;
|
||||
previouslyRevalidatedTags: string[];
|
||||
};
|
||||
export declare function createWorkStore({ page, fallbackRouteParams, renderOpts, requestEndedState, isPrefetchRequest, buildId, previouslyRevalidatedTags, }: WorkStoreContext): WorkStore;
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "createWorkStore", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return createWorkStore;
|
||||
}
|
||||
});
|
||||
const _aftercontext = require("../after/after-context");
|
||||
const _apppaths = require("../../shared/lib/router/utils/app-paths");
|
||||
const _lazyresult = require("../lib/lazy-result");
|
||||
const _handlers = require("../use-cache/handlers");
|
||||
function createWorkStore({ page, fallbackRouteParams, renderOpts, requestEndedState, isPrefetchRequest, buildId, previouslyRevalidatedTags }) {
|
||||
/**
|
||||
* 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.shouldWaitOnAllReady && !renderOpts.supportsDynamicResponse && !renderOpts.isDraftMode && !renderOpts.isPossibleServerAction;
|
||||
const store = {
|
||||
isStaticGeneration,
|
||||
page,
|
||||
fallbackRouteParams,
|
||||
route: (0, _apppaths.normalizeAppPath)(page),
|
||||
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,
|
||||
cacheLifeProfiles: renderOpts.cacheLifeProfiles,
|
||||
isRevalidate: renderOpts.isRevalidate,
|
||||
isPrerendering: renderOpts.nextExport,
|
||||
fetchCache: renderOpts.fetchCache,
|
||||
isOnDemandRevalidate: renderOpts.isOnDemandRevalidate,
|
||||
isDraftMode: renderOpts.isDraftMode,
|
||||
requestEndedState,
|
||||
isPrefetchRequest,
|
||||
buildId,
|
||||
reactLoadableManifest: (renderOpts == null ? void 0 : renderOpts.reactLoadableManifest) || {},
|
||||
assetPrefix: (renderOpts == null ? void 0 : renderOpts.assetPrefix) || '',
|
||||
afterContext: createAfterContext(renderOpts),
|
||||
dynamicIOEnabled: renderOpts.experimental.dynamicIO,
|
||||
dev: renderOpts.dev ?? false,
|
||||
previouslyRevalidatedTags,
|
||||
refreshTagsByCacheKind: createRefreshTagsByCacheKind()
|
||||
};
|
||||
// TODO: remove this when we resolve accessing the store outside the execution context
|
||||
renderOpts.store = store;
|
||||
return store;
|
||||
}
|
||||
function createAfterContext(renderOpts) {
|
||||
const { waitUntil, onClose, onAfterTaskError } = renderOpts;
|
||||
return new _aftercontext.AfterContext({
|
||||
waitUntil,
|
||||
onClose,
|
||||
onTaskError: onAfterTaskError
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Creates a map with lazy results that refresh tags for the respective cache
|
||||
* kind when they're awaited for the first time.
|
||||
*/ function createRefreshTagsByCacheKind() {
|
||||
const refreshTagsByCacheKind = new Map();
|
||||
const cacheHandlers = (0, _handlers.getCacheHandlerEntries)();
|
||||
if (cacheHandlers) {
|
||||
for (const [kind, cacheHandler] of cacheHandlers){
|
||||
if ('refreshTags' in cacheHandler) {
|
||||
refreshTagsByCacheKind.set(kind, (0, _lazyresult.createLazyResult)(async ()=>cacheHandler.refreshTags()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return refreshTagsByCacheKind;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=work-store.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/server/async-storage/work-store.ts"],"sourcesContent":["import type { WorkStore } from '../app-render/work-async-storage.external'\nimport type { IncrementalCache } from '../lib/incremental-cache'\nimport type { RenderOpts } from '../app-render/types'\nimport type { FetchMetric } from '../base-http'\nimport type { RequestLifecycleOpts } from '../base-server'\nimport type { FallbackRouteParams } from '../request/fallback-params'\nimport type { AppSegmentConfig } from '../../build/segment-config/app/app-segment-config'\nimport type { CacheLife } from '../use-cache/cache-life'\n\nimport { AfterContext } from '../after/after-context'\n\nimport { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'\nimport { createLazyResult, type LazyResult } from '../lib/lazy-result'\nimport { getCacheHandlerEntries } from '../use-cache/handlers'\n\nexport type WorkStoreContext = {\n /**\n * The page that is being rendered. This relates to the path to the page file.\n */\n page: string\n\n /**\n * The route parameters that are currently unknown.\n */\n fallbackRouteParams: FallbackRouteParams | null\n\n requestEndedState?: { ended?: boolean }\n isPrefetchRequest?: boolean\n renderOpts: {\n cacheLifeProfiles?: { [profile: string]: CacheLife }\n incrementalCache?: IncrementalCache\n isOnDemandRevalidate?: boolean\n fetchCache?: AppSegmentConfig['fetchCache']\n isPossibleServerAction?: boolean\n pendingWaitUntil?: Promise<any>\n experimental: Pick<\n RenderOpts['experimental'],\n 'isRoutePPREnabled' | 'dynamicIO' | 'authInterrupts'\n >\n\n /**\n * Fetch metrics attached in patch-fetch.ts\n **/\n fetchMetrics?: FetchMetric[]\n\n /**\n * A hack around accessing the store value outside the context of the\n * request.\n *\n * @internal\n * @deprecated should only be used as a temporary workaround\n */\n // TODO: remove this when we resolve accessing the store outside the execution context\n store?: WorkStore\n } & Pick<\n // Pull some properties from RenderOpts so that the docs are also\n // mirrored.\n RenderOpts,\n | 'assetPrefix'\n | 'supportsDynamicResponse'\n | 'shouldWaitOnAllReady'\n | 'isRevalidate'\n | 'nextExport'\n | 'isDraftMode'\n | 'isDebugDynamicAccesses'\n | 'dev'\n > &\n RequestLifecycleOpts &\n Partial<Pick<RenderOpts, 'reactLoadableManifest'>>\n\n /**\n * The build ID of the current build.\n */\n buildId: string\n\n // Tags that were previously revalidated (e.g. by a redirecting server action)\n // and have already been sent to cache handlers.\n previouslyRevalidatedTags: string[]\n}\n\nexport function createWorkStore({\n page,\n fallbackRouteParams,\n renderOpts,\n requestEndedState,\n isPrefetchRequest,\n buildId,\n previouslyRevalidatedTags,\n}: WorkStoreContext): WorkStore {\n /**\n * Rules of Static & Dynamic HTML:\n *\n * 1.) We must generate static HTML unless the caller explicitly opts\n * in to dynamic HTML support.\n *\n * 2.) If dynamic HTML support is requested, we must honor that request\n * or throw an error. It is the sole responsibility of the caller to\n * ensure they aren't e.g. requesting dynamic HTML for an AMP page.\n *\n * 3.) If the request is in draft mode, we must generate dynamic HTML.\n *\n * 4.) If the request is a server action, we must generate dynamic HTML.\n *\n * These rules help ensure that other existing features like request caching,\n * coalescing, and ISR continue working as intended.\n */\n const isStaticGeneration =\n !renderOpts.shouldWaitOnAllReady &&\n !renderOpts.supportsDynamicResponse &&\n !renderOpts.isDraftMode &&\n !renderOpts.isPossibleServerAction\n\n const store: WorkStore = {\n isStaticGeneration,\n page,\n fallbackRouteParams,\n route: normalizeAppPath(page),\n incrementalCache:\n // we fallback to a global incremental cache for edge-runtime locally\n // so that it can access the fs cache without mocks\n renderOpts.incrementalCache || (globalThis as any).__incrementalCache,\n cacheLifeProfiles: renderOpts.cacheLifeProfiles,\n isRevalidate: renderOpts.isRevalidate,\n isPrerendering: renderOpts.nextExport,\n fetchCache: renderOpts.fetchCache,\n isOnDemandRevalidate: renderOpts.isOnDemandRevalidate,\n\n isDraftMode: renderOpts.isDraftMode,\n\n requestEndedState,\n isPrefetchRequest,\n buildId,\n reactLoadableManifest: renderOpts?.reactLoadableManifest || {},\n assetPrefix: renderOpts?.assetPrefix || '',\n\n afterContext: createAfterContext(renderOpts),\n dynamicIOEnabled: renderOpts.experimental.dynamicIO,\n dev: renderOpts.dev ?? false,\n previouslyRevalidatedTags,\n refreshTagsByCacheKind: createRefreshTagsByCacheKind(),\n }\n\n // TODO: remove this when we resolve accessing the store outside the executioLine truncated
|
||||
Reference in new issue
Block a user