.
This commit is contained in:
Generated
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
import type { DynamicPrerenderManifestRoute, PrerenderManifest } from '../../../../build';
|
||||
import type { DeepReadonly } from '../../../../shared/lib/deep-readonly';
|
||||
export type PrerenderManifestMatch = {
|
||||
source: string;
|
||||
route: DeepReadonly<DynamicPrerenderManifestRoute>;
|
||||
};
|
||||
/**
|
||||
* A matcher for the prerender manifest.
|
||||
*
|
||||
* This class is used to match the pathname to the dynamic route.
|
||||
*/
|
||||
export declare class PrerenderManifestMatcher {
|
||||
private readonly matchers;
|
||||
constructor(pathname: string, prerenderManifest: DeepReadonly<PrerenderManifest>);
|
||||
/**
|
||||
* Match the pathname to the dynamic route. If no match is found, an error is
|
||||
* thrown.
|
||||
*
|
||||
* @param pathname - The pathname to match.
|
||||
* @returns The dynamic route that matches the pathname.
|
||||
*/
|
||||
match(pathname: string): PrerenderManifestMatch | null;
|
||||
}
|
||||
Generated
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "PrerenderManifestMatcher", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return PrerenderManifestMatcher;
|
||||
}
|
||||
});
|
||||
const _routematcher = require("../../../../shared/lib/router/utils/route-matcher");
|
||||
const _routeregex = require("../../../../shared/lib/router/utils/route-regex");
|
||||
class PrerenderManifestMatcher {
|
||||
constructor(pathname, prerenderManifest){
|
||||
this.matchers = Object.entries(prerenderManifest.dynamicRoutes).filter(([source, route])=>{
|
||||
// If the pathname is a fallback source route, or the source route is
|
||||
// the same as the pathname, then we should include it in the matchers.
|
||||
return route.fallbackSourceRoute === pathname || source === pathname;
|
||||
}).map(([source, route])=>({
|
||||
source,
|
||||
route
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Match the pathname to the dynamic route. If no match is found, an error is
|
||||
* thrown.
|
||||
*
|
||||
* @param pathname - The pathname to match.
|
||||
* @returns The dynamic route that matches the pathname.
|
||||
*/ match(pathname) {
|
||||
// Iterate over the matchers. They're already in the correct order of
|
||||
// specificity as they were inserted into the prerender manifest that way
|
||||
// and iterating over them with Object.entries guarantees that.
|
||||
for (const matcher of this.matchers){
|
||||
// Lazily create the matcher, this is only done once per matcher.
|
||||
if (!matcher.matcher) {
|
||||
matcher.matcher = (0, _routematcher.getRouteMatcher)((0, _routeregex.getRouteRegex)(matcher.source));
|
||||
}
|
||||
const match = matcher.matcher(pathname);
|
||||
if (match) {
|
||||
return {
|
||||
source: matcher.source,
|
||||
route: matcher.route
|
||||
};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=prerender-manifest-matcher.js.map
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/server/route-modules/app-page/helpers/prerender-manifest-matcher.ts"],"sourcesContent":["import type {\n DynamicPrerenderManifestRoute,\n PrerenderManifest,\n} from '../../../../build'\nimport type { DeepReadonly } from '../../../../shared/lib/deep-readonly'\nimport {\n getRouteMatcher,\n type RouteMatchFn,\n} from '../../../../shared/lib/router/utils/route-matcher'\nimport { getRouteRegex } from '../../../../shared/lib/router/utils/route-regex'\n\n/**\n * A matcher for a dynamic route.\n */\ntype Matcher = {\n /**\n * The matcher for the dynamic route. This is lazily created when the matcher\n * is first used.\n */\n matcher?: RouteMatchFn\n\n /**\n * The source of the dynamic route.\n */\n source: string\n\n /**\n * The route that matches the source.\n */\n route: DeepReadonly<DynamicPrerenderManifestRoute>\n}\n\nexport type PrerenderManifestMatch = {\n source: string\n route: DeepReadonly<DynamicPrerenderManifestRoute>\n}\n\n/**\n * A matcher for the prerender manifest.\n *\n * This class is used to match the pathname to the dynamic route.\n */\nexport class PrerenderManifestMatcher {\n private readonly matchers: Array<Matcher>\n constructor(\n pathname: string,\n prerenderManifest: DeepReadonly<PrerenderManifest>\n ) {\n this.matchers = Object.entries(prerenderManifest.dynamicRoutes)\n .filter(([source, route]) => {\n // If the pathname is a fallback source route, or the source route is\n // the same as the pathname, then we should include it in the matchers.\n return route.fallbackSourceRoute === pathname || source === pathname\n })\n .map(([source, route]) => ({ source, route }))\n }\n\n /**\n * Match the pathname to the dynamic route. If no match is found, an error is\n * thrown.\n *\n * @param pathname - The pathname to match.\n * @returns The dynamic route that matches the pathname.\n */\n public match(pathname: string): PrerenderManifestMatch | null {\n // Iterate over the matchers. They're already in the correct order of\n // specificity as they were inserted into the prerender manifest that way\n // and iterating over them with Object.entries guarantees that.\n for (const matcher of this.matchers) {\n // Lazily create the matcher, this is only done once per matcher.\n if (!matcher.matcher) {\n matcher.matcher = getRouteMatcher(getRouteRegex(matcher.source))\n }\n\n const match = matcher.matcher(pathname)\n if (match) {\n return {\n source: matcher.source,\n route: matcher.route,\n }\n }\n }\n\n return null\n }\n}\n"],"names":["PrerenderManifestMatcher","constructor","pathname","prerenderManifest","matchers","Object","entries","dynamicRoutes","filter","source","route","fallbackSourceRoute","map","match","matcher","getRouteMatcher","getRouteRegex"],"mappings":";;;;+BA0CaA;;;eAAAA;;;8BAlCN;4BACuB;AAiCvB,MAAMA;IAEXC,YACEC,QAAgB,EAChBC,iBAAkD,CAClD;QACA,IAAI,CAACC,QAAQ,GAAGC,OAAOC,OAAO,CAACH,kBAAkBI,aAAa,EAC3DC,MAAM,CAAC,CAAC,CAACC,QAAQC,MAAM;YACtB,qEAAqE;YACrE,uEAAuE;YACvE,OAAOA,MAAMC,mBAAmB,KAAKT,YAAYO,WAAWP;QAC9D,GACCU,GAAG,CAAC,CAAC,CAACH,QAAQC,MAAM,GAAM,CAAA;gBAAED;gBAAQC;YAAM,CAAA;IAC/C;IAEA;;;;;;GAMC,GACD,AAAOG,MAAMX,QAAgB,EAAiC;QAC5D,qEAAqE;QACrE,yEAAyE;QACzE,+DAA+D;QAC/D,KAAK,MAAMY,WAAW,IAAI,CAACV,QAAQ,CAAE;YACnC,iEAAiE;YACjE,IAAI,CAACU,QAAQA,OAAO,EAAE;gBACpBA,QAAQA,OAAO,GAAGC,IAAAA,6BAAe,EAACC,IAAAA,yBAAa,EAACF,QAAQL,MAAM;YAChE;YAEA,MAAMI,QAAQC,QAAQA,OAAO,CAACZ;YAC9B,IAAIW,OAAO;gBACT,OAAO;oBACLJ,QAAQK,QAAQL,MAAM;oBACtBC,OAAOI,QAAQJ,KAAK;gBACtB;YACF;QACF;QAEA,OAAO;IACT;AACF","ignoreList":[0]}
|
||||
Reference in New Issue
Block a user